Class tree requires use of multiple inits
Foo is a base class and assigns its own sprite with its _init. Its extension, bar, has additional data necessary for its extensions, which need to assign variables with their _init. However, this means that two _init calls must be made, which seems like it's impossible. Is there a way to refactor this to be possible without just duplicating the sprite-assignment code across every extension with a custom _init call?
@abstract
class_name Foo
extends Node
var sprite: Sprite2D;
var spriteImage: String;
func _init():
add_child(sprite);
sprite.texture = ImageTexture.create_from_image(Image.load_from_file(spriteImage));
@abstract
class_name Bar
extends Foo
enum placeholder {
A,
B,
C
};
var whichFromPlaceholder: int;
@abstract
class_name Child_of_Bar
extends Bar
func _init():
whichFromPlaceholder = A
u/Supperboy2012 — 4 days ago