class_name TowerComponent extends Node2D var current_tower: Tower: get(): return get_parent() enum ComponentType { Range, Attack, Speed, Frost, Burn, Poison, } @export var type: ComponentType var sprite: TextureRect: get(): @warning_ignore("shadowed_variable") var sprite := $Sprite.duplicate() sprite.name = get_type_name() return sprite var id: String: get(): return get_type_name() signal level_changed var level: int = 1: set(value): level = value level_changed.emit() func set_sprite(texture: Texture2D): sprite = get_node("Sprite") sprite.texture = texture sprite.name = get_type_name() func get_type_name(component_type: ComponentType = type): return ComponentType.keys()[component_type] func on_add(tower: Tower): current_tower = tower class NetworkData extends Resource: var type: ComponentType var level: int func to_network_data() -> NetworkData: var data = NetworkData.new() data.type = type data.level = level return data func update_with_network_data(data: NetworkData): level = data.level static func from_network_data(data: NetworkData) -> TowerComponent: var component = load( "res://Towers/Components/%sComponent.tscn" % [ComponentType.keys()[data.type]] ).instantiate() component.type = data.type component.level = data.level return component