diff options
author | nokoe <nokoe@mailbox.org> | 2024-06-24 20:12:18 +0200 |
---|---|---|
committer | nokoe <nokoe@mailbox.org> | 2024-06-24 20:12:18 +0200 |
commit | 9e0131dcf5c1d1694fc7d81faba6b3a7251ee71e (patch) | |
tree | f173294ca3cb88a26a9cc1a3d6ccd0884cf49824 /client/multiplayer.gd | |
parent | 3e483fbbc2c7aa5cce7f31adc31d2cba15f9c08a (diff) | |
parent | dbb52c813e64fbe4e733dbfec4e29889d288873e (diff) | |
download | hurrycurry-9e0131dcf5c1d1694fc7d81faba6b3a7251ee71e.tar hurrycurry-9e0131dcf5c1d1694fc7d81faba6b3a7251ee71e.tar.bz2 hurrycurry-9e0131dcf5c1d1694fc7d81faba6b3a7251ee71e.tar.zst |
Merge branch 'master' of ssh://codeberg.org/metamuffin/undercooked
Diffstat (limited to 'client/multiplayer.gd')
-rw-r--r-- | client/multiplayer.gd | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/client/multiplayer.gd b/client/multiplayer.gd index 7ccfd377..2d4b9533 100644 --- a/client/multiplayer.gd +++ b/client/multiplayer.gd @@ -15,6 +15,7 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <https://www.gnu.org/licenses/>. # +class_name Multiplayer extends Node signal init(player_id: int) @@ -46,10 +47,15 @@ var player_id = -1 var tileid_by_pos: Dictionary = {} -var url = "" -func connect_client(): - socket.connect_to_url(url) +func _ready(): + print("Multiplayer connect"); + socket.connect_to_url(Global.server_url) connected = true +func _notification(what): + if what == NOTIFICATION_PREDELETE: + print("Multiplayer disconnect"); + socket.close() + connected = false func _process(_delta): if connected: @@ -135,7 +141,7 @@ func handle_packet(bytes: PackedByteArray): var pos: Array = decoded["pos"] var neighbors: Array = decoded["neighbors"] tileid_by_pos[str(Vector2i(pos[0],pos[1]))] = tile - emit_signal("update_map", pos, tile_names[tile], neighbors) + emit_signal("update_map", pos, tile_names[tile], neighbors.map(func (x): return tile_names[x] if x != null else null)) "communicate": var player = decoded["player"] var message = decoded.get("message") |