feat: Implement Nakama serialization, Realtime API, and a comprehensive lobby system with UI and player management.

This commit is contained in:
Yogi Wiguna
2026-02-09 16:46:42 +08:00
parent a68878483f
commit bffa9474e9
7 changed files with 221 additions and 45 deletions
@@ -644,9 +644,7 @@ class UserPresence extends NakamaAsyncResult:
return NakamaSerializer.serialize(self)
func _to_string():
if is_exception(): return get_exception()._to_string()
return "UserPresence<persistence=%s, session_id=%s, status=%s, username=%s, user_id=%s>" % [
persistence, session_id, status, username, user_id]
return "UserPresence"
static func create(p_ns : GDScript, p_dict : Dictionary) -> UserPresence:
return _safe_ret(NakamaSerializer.deserialize(p_ns, "UserPresence", p_dict), UserPresence) as UserPresence
@@ -1,7 +1,20 @@
extends RefCounted
class_name NakamaSerializer
static func serialize(p_obj : Object) -> Dictionary:
static var _global_depth := 0
static func serialize(p_obj : Object, p_depth : int = 0) -> Dictionary:
_global_depth += 1
if _global_depth > 64:
_global_depth -= 1
printerr("NakamaSerializer: Global recursion limit reached!")
return {}
var result = _serialize_impl(p_obj, p_depth)
_global_depth -= 1
return result
static func _serialize_impl(p_obj : Object, p_depth : int) -> Dictionary:
var out = {}
var schema = p_obj.get("_SCHEMA")
if schema == null:
@@ -18,13 +31,13 @@ static func serialize(p_obj : Object) -> Dictionary:
var val_type = typeof(val)
match val_type:
TYPE_OBJECT: # Simple objects
out[k] = serialize(val)
out[k] = serialize(val, p_depth + 1)
TYPE_ARRAY: # Array of objects
var arr = []
for e in val:
if typeof(e) != TYPE_OBJECT:
continue
arr.append(serialize(e))
arr.append(serialize(e, p_depth + 1))
out[k] = arr
TYPE_PACKED_INT32_ARRAY, TYPE_PACKED_STRING_ARRAY: # Array of ints, bools, or strings
var arr = []
@@ -41,7 +54,7 @@ static func serialize(p_obj : Object) -> Dictionary:
for l in val:
if typeof(val[l]) != TYPE_OBJECT:
continue
dict[l] = serialize(val[l])
dict[l] = serialize(val[l], p_depth + 1)
else: # Map of simple types
for l in val:
var e = val[l]