diff options
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) |