From 911699e9563a8791d72173b46fd8860ce15bb91a Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Thu, 10 Oct 2024 13:16:33 +0200 Subject: intermediate commit --- Towers/Tower.gd | 23 +++++++++++++++-------- Towers/Tower.tscn | 2 -- 2 files changed, 15 insertions(+), 10 deletions(-) (limited to 'Towers') diff --git a/Towers/Tower.gd b/Towers/Tower.gd index 4262af1..8e22c3e 100644 --- a/Towers/Tower.gd +++ b/Towers/Tower.gd @@ -225,10 +225,7 @@ func _on_h_box_container_gui_input(event: InputEvent) -> void: if not found: tower.add_component(preload("res://Towers/Components/FrostComponent.gd").new()) - var data = {"components": []} - for c in tower.components: - data["components"].append(c.name) - Client.update_tower(tower, data) + Client.update_tower(tower.get_path(), tower.to_network_data()) func _on_h_box_container_2_gui_input(event: InputEvent) -> void: @@ -247,24 +244,34 @@ func _on_h_box_container_2_gui_input(event: InputEvent) -> void: if not found: tower.add_component(preload("res://Towers/Components/BurnComponent.gd").new()) - var data = {"components": []} - for c in tower.components: - data["components"].append(c.name) - Client.update_tower(tower, data) + Client.update_tower(tower.get_path(), tower.to_network_data()) class NetworkData extends Resource: var name: String var position: Vector2 + var components: Array func to_network_data() -> NetworkData: var data = NetworkData.new() data.name = name data.position = global_position + data.components = components.map(func(item: TowerComponent): + return item.name + ) return data +func update_with_network_data(data: NetworkData): + for component in components.duplicate(): + remove_component(component.name) + + for component_name in data.components: + add_component( + load("res://Towers/Components/" + component_name + "Component.gd").new() + ) + static func from_network_data(data: NetworkData) -> Tower: var tower: Tower = preload("res://Towers/Tower.tscn").instantiate() diff --git a/Towers/Tower.tscn b/Towers/Tower.tscn index 6bff2e3..43c3c35 100644 --- a/Towers/Tower.tscn +++ b/Towers/Tower.tscn @@ -115,8 +115,6 @@ text = "Burn" replication_config = SubResource("SceneReplicationConfig_spp26") [connection signal="input_event" from="." to="." method="_on_input_event"] -[connection signal="mouse_entered" from="." to="." method="_on_mouse_entered"] -[connection signal="mouse_exited" from="." to="." method="_on_mouse_exited"] [connection signal="tree_exiting" from="." to="." method="_on_tree_exiting"] [connection signal="body_entered" from="Range" to="." method="_on_range_body_entered"] [connection signal="body_exited" from="Range" to="." method="_on_range_body_exited"] -- cgit v1.2.3