summaryrefslogtreecommitdiff
path: root/Towers
diff options
context:
space:
mode:
Diffstat (limited to 'Towers')
-rw-r--r--Towers/Tower.gd23
-rw-r--r--Towers/Tower.tscn2
2 files changed, 15 insertions, 10 deletions
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"]