WIP checkpoint: Implement avatar loader and customization UI in Godot

This commit is contained in:
2026-08-18 13:01:14 +00:00
parent 689c51e179
commit 4c0af03573
2 changed files with 79 additions and 1 deletions
+29 -1
View File
@@ -22,6 +22,9 @@ var slots: Dictionary = {}
## Validation errors found during the last validate() call.
var validation_errors: Array[String] = []
## Skin tone color override (default: transparent = use asset colors).
var skin_tone: Color = Color.TRANSPARENT
func _init() -> void:
validation_errors = []
@@ -55,6 +58,17 @@ static func from_json(json_string: String) -> AvatarLoadout:
else:
loadout.validation_errors.append("Missing 'slots' in loadout JSON")
# Parse skin_tone
if root.has("skin_tone"):
var st = root["skin_tone"]
if typeof(st) == TYPE_DICTIONARY:
loadout.skin_tone = Color(
st.get("r", 0.0),
st.get("g", 0.0),
st.get("b", 0.0),
st.get("a", 1.0)
)
return loadout
@@ -62,7 +76,7 @@ static func from_json(json_string: String) -> AvatarLoadout:
func to_json() -> String:
var data := {
"base_body": base_body,
"slots": {}
"slots": {},
}
for slot_id in AvatarSlotRegistry.SLOT_IDS:
@@ -71,6 +85,15 @@ func to_json() -> String:
else:
data.slots[slot_id] = slots.get(slot_id, null)
# Include skin_tone if set
if skin_tone != Color.TRANSPARENT:
data["skin_tone"] = {
"r": skin_tone.r,
"g": skin_tone.g,
"b": skin_tone.b,
"a": skin_tone.a,
}
return JSON.stringify(data, " ")
@@ -132,6 +155,11 @@ func validate() -> bool:
return validation_errors.is_empty()
## Convenience alias for validate().
func is_valid() -> bool:
return validate()
## Check if a specific slot is equipped with a non-null item.
func is_equipped(slot_id: String) -> bool:
if not AvatarSlotRegistry.has_slot(slot_id):