diff options
| author | tpart <tpart120@proton.me> | 2026-02-26 20:30:49 +0100 |
|---|---|---|
| committer | tpart <tpart120@proton.me> | 2026-02-26 20:49:54 +0100 |
| commit | 04dd47d13a8da9224e7f9ea8ccacf64129717ec1 (patch) | |
| tree | 2a88e646d1b8dfbcd5973092655bf9a0ebc1c625 /client/multiplayer.gd | |
| parent | b91eb2a9bdf4167c69a4d82f2a44855138f58b94 (diff) | |
| download | hurrycurry-04dd47d13a8da9224e7f9ea8ccacf64129717ec1.tar hurrycurry-04dd47d13a8da9224e7f9ea8ccacf64129717ec1.tar.bz2 hurrycurry-04dd47d13a8da9224e7f9ea8ccacf64129717ec1.tar.zst | |
Implement tile stacks in client; Upgrade to Godot 4.6
Diffstat (limited to 'client/multiplayer.gd')
| -rw-r--r-- | client/multiplayer.gd | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/client/multiplayer.gd b/client/multiplayer.gd index a0260df5..9b5b30b9 100644 --- a/client/multiplayer.gd +++ b/client/multiplayer.gd @@ -96,25 +96,23 @@ func _process(_delta): connection_closed.emit("c.error.connection_closed") connected = false -func fix_packet_types(val): +func fix_packet_types(val: Variant): match typeof(val): TYPE_FLOAT: return val TYPE_STRING: return val TYPE_BOOL: return val TYPE_ARRAY: return val.map(fix_packet_types) TYPE_DICTIONARY: - var newval = {} + var new_dict = {} for k in val.keys(): - if typeof(val[k]) == TYPE_ARRAY and val[k].size() == 2 and typeof(val[k][0]) == TYPE_FLOAT and typeof(val[k][1]) == TYPE_FLOAT: - if k in ["tile"]: newval[k] = Vector2i(val[k][0], val[k][1]) - elif k in ["pos", "position", "dir"]: newval[k] = Vector2(val[k][0], val[k][1]) - else: newval[k] = val[k] - # TODO reenable when fixed - # elif k in ["player", "id"] and typeof(val[k]) == TYPE_FLOAT: - # newval[k] = int(val[k]) - else: - newval[k] = fix_packet_types(val[k]) - return newval + if val[k] is Array and val[k].size() == 2: + # A Vector2 is represented as an array with 2 elements in our protocol. + # We need to convert it to Godot's Vector2 type for easier handling. + if k in ["tile"]: new_dict[k] = Vector2i(val[k][0], val[k][1]) # TODO: Are these still necessary? + elif k in ["pos", "position", "dir"]: new_dict[k] = Vector2(val[k][0], val[k][1]) + else: new_dict[k] = fix_packet_types(val[k]) + else: new_dict[k] = fix_packet_types(val[k]) + return new_dict func handle_packet(coded): var p = decode_packet(coded) |