diff options
author | Daniel Weipert <git@mail.dweipert.de> | 2024-10-09 17:20:55 +0200 |
---|---|---|
committer | Daniel Weipert <git@mail.dweipert.de> | 2024-10-09 17:20:55 +0200 |
commit | 1aac583cee47d232ef22d8c5df97b888f689ab96 (patch) | |
tree | 7ef0796e4f01272fc68d199e1b0dc1812aaad1e0 /Game/Network.gd | |
parent | b96e384d8299473b14edcbf885fa914a9308d18f (diff) |
intermediate commit
Diffstat (limited to 'Game/Network.gd')
-rw-r--r-- | Game/Network.gd | 51 |
1 files changed, 39 insertions, 12 deletions
diff --git a/Game/Network.gd b/Game/Network.gd index 9349245..48558ce 100644 --- a/Game/Network.gd +++ b/Game/Network.gd @@ -156,35 +156,55 @@ func get_nested_node_and_property(node: Node, property: String) -> Dictionary: @rpc("any_peer") -func place_tower(remote_tower: Dictionary, position: Vector2): +#func place_tower(remote_tower: Dictionary, position: Vector2): +func place_tower(remote_data: Dictionary): + var data: Tower.NetworkData = dict_to_inst(remote_data) var remote_player_id = multiplayer.get_remote_sender_id() - var tower = from_rpc_object(remote_tower, "res://Towers/Tower.tscn") + var tower = Tower.from_network_data(data) tower.owner_id = remote_player_id players[remote_player_id].towers[tower.global_position] = tower - Client.stage.place_tower(tower, position) + Client.stage.place_tower(tower, tower.global_position) @rpc("any_peer") -func destroy_tower(remote_tower: Dictionary): - var player = players[remote_tower.owner_id] as Player - var tower = player.towers.get(remote_tower.global_position) +#func destroy_tower(remote_tower: Dictionary): +func destroy_tower(position: Vector2): + var owner_id = multiplayer.get_remote_sender_id() + var player = players[owner_id] as Player + var tower = player.towers.get(position) Client.stage.destroy_tower(tower) @rpc("any_peer") -func spawn_unit(remote_unit: Dictionary, remote_spawn: Dictionary): - var unit = from_rpc_object(remote_unit, "res://Units/Unit.tscn") - var spawn = from_rpc_object(remote_spawn, "res://Stages/Paths/Spawn.tscn") +func update_tower(remote_tower_node_path, data): + var tower: Tower = get_tree().current_scene.get_node_or_null(remote_tower_node_path) + if tower: + if "components" in data: + for c in tower.components.duplicate(): + tower.remove_component(c.name) + for c in data.components: + tower.add_component( + load("res://Towers/Components/" + c + "Component.gd").new() + ) + + +@rpc("any_peer") +func spawn_unit(remote_data: Dictionary):#, _remote_spawn: Dictionary): + #print(remote_data) + var data: Unit.NetworkData = dict_to_inst(remote_data) + var unit := Unit.from_network_data(data) + #var spawn = from_rpc_object(remote_spawn, "res://Stages/Paths/Spawn.tscn") var remote_id = multiplayer.get_remote_sender_id() unit.owner_id = remote_id - unit.set_multiplayer_authority(remote_id) + #unit.set_multiplayer_authority(remote_id) - Client.stage.spawn_unit(unit, spawn) + Client.stage.spawn_unit(unit) + @rpc("any_peer") func remove_unit(remote_unit_node_path): @@ -192,13 +212,20 @@ func remove_unit(remote_unit_node_path): if unit: unit.queue_free() + @rpc("any_peer") func update_unit(remote_unit_node_path, data): var unit: Unit = get_tree().current_scene.get_node_or_null(remote_unit_node_path) if unit: + if "hp" in data: + unit.hp = data.hp if "position" in data: unit.position = data.position - unit.hp = data.hp if "sprite" in data: unit.get_node("Sprite2D").self_modulate = data.sprite.self_modulate + if "current_path" in data: + unit.current_path = data.current_path + unit.line.points = PackedVector2Array(data.current_path) + if "current_path_idx" in data: + unit.current_path_idx = data.current_path_idx |