diff options
Diffstat (limited to 'Game/Network.gd')
-rw-r--r-- | Game/Network.gd | 29 |
1 files changed, 10 insertions, 19 deletions
diff --git a/Game/Network.gd b/Game/Network.gd index 5dcb074..23542e2 100644 --- a/Game/Network.gd +++ b/Game/Network.gd @@ -32,6 +32,14 @@ func join_game(ip, port): Client.player.id = multiplayer.get_unique_id() +func close_game(): + multiplayer.multiplayer_peer.close() + multiplayer.multiplayer_peer = OfflineMultiplayerPeer.new() + reset_players() + + await Client.request(Client.game_lobby_url, [], HTTPClient.METHOD_POST, JSON.stringify({"close": Client.current_game_id})) + Client.current_game_id = "" + func _on_connected_to_server(): print(multiplayer.get_unique_id(), ": connected to server") @@ -39,8 +47,7 @@ func _on_connected_to_server(): func _on_disconnected_from_server(): print("disconnected from server") - multiplayer.multiplayer_peer = OfflineMultiplayerPeer.new() - reset_players() + close_game() func _on_peer_connected(id: int): print(multiplayer.get_unique_id(), ": peer connected: ", id) @@ -52,16 +59,12 @@ func _on_peer_connected(id: int): elif is_running: get_tree().change_scene_to_file("res://UI/Start.tscn") ) - - # TODO: add existing towers to new peers func _on_peer_disconnected(id: int): print(multiplayer.get_unique_id(), ": peer disconnected: ", id) remove_player(id) - # TODO: move towers owned by peer to host - if id == 1: # if host disconnected go back to Start get_tree().change_scene_to_file("res://UI/Start.tscn") @@ -139,10 +142,10 @@ func update_player(id: int, remote_data: Dictionary): @rpc("any_peer") -#func destroy_tower(remote_tower: Dictionary): func destroy_tower(remote_data: Dictionary): var data: Tower.NetworkData = dict_to_inst(remote_data) var remote_tower = Tower.from_network_data(data) + var player = get_player(remote_tower.owner_id) var tower = player.towers.get(remote_tower.global_position) @@ -172,15 +175,3 @@ func update_unit(remote_unit_node_path: NodePath, remote_data: Dictionary): if unit: unit.update_with_network_data(data) - #if "hp" in data: - #unit.hp = data.hp - #if "position" in data: - #unit.position = data.position - #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 - |