fix(multiplayer): replicate per-player avatar loadout and preserve original materials
checkpoint / checkpoint (push) Successful in 5m57s
checkpoint / checkpoint (push) Successful in 5m57s
This commit is contained in:
@@ -65,16 +65,13 @@ func _init() -> void:
|
||||
# Serialization
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
## Create a loadout from a JSON string.
|
||||
static func from_json(json_string: String) -> AvatarLoadout:
|
||||
## Create a loadout from a Dictionary.
|
||||
static func from_dict(root: Dictionary) -> AvatarLoadout:
|
||||
var loadout := _Self.new()
|
||||
var data: Variant = JSON.parse_string(json_string)
|
||||
if not (data is Dictionary):
|
||||
loadout.validation_errors.append("Loadout JSON root is not an object")
|
||||
if root == null:
|
||||
loadout.validation_errors.append("Loadout root is null")
|
||||
return loadout
|
||||
|
||||
var root: Dictionary = data as Dictionary
|
||||
|
||||
# Parse base_body.
|
||||
if root.has("base_body"):
|
||||
var bb = root["base_body"]
|
||||
@@ -111,8 +108,18 @@ static func from_json(json_string: String) -> AvatarLoadout:
|
||||
return loadout
|
||||
|
||||
|
||||
## Serialize this loadout to a JSON string.
|
||||
func to_json() -> String:
|
||||
## Create a loadout from a JSON string.
|
||||
static func from_json(json_string: String) -> AvatarLoadout:
|
||||
var data: Variant = JSON.parse_string(json_string)
|
||||
if not (data is Dictionary):
|
||||
var loadout := _Self.new()
|
||||
loadout.validation_errors.append("Loadout JSON root is not an object")
|
||||
return loadout
|
||||
return from_dict(data as Dictionary)
|
||||
|
||||
|
||||
## Serialize this loadout to a Dictionary.
|
||||
func to_dict() -> Dictionary:
|
||||
var data := {
|
||||
"base_body": base_body,
|
||||
"slots": {},
|
||||
@@ -133,7 +140,12 @@ func to_json() -> String:
|
||||
"a": skin_tone.a,
|
||||
}
|
||||
|
||||
return JSON.stringify(data, " ")
|
||||
return data
|
||||
|
||||
|
||||
## Serialize this loadout to a JSON string.
|
||||
func to_json() -> String:
|
||||
return JSON.stringify(to_dict(), " ")
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user