Fix: normalise ability JSON keys to lowercase before parsing
Server serialises AbilityDefinition with PascalCase property names (Type, Actions, Target, Scope, Ownership, Count, All…). The client was checking for lowercase keys (\"type\", \"actions\", etc.) so ab.get(\"type\") always returned null, actives stayed empty, and the panel was silently skipped. Added _normalize_keys() which recursively lowercases all Dictionary keys after JSON.parse_string(), making every subsequent lookup case-insensitive without needing dual-key fallbacks throughout. Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude <noreply@anthropic.com> Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
@@ -1163,6 +1163,22 @@ func _show_card_picker(title: String, cards: Array, on_pick: Callable) -> void:
|
||||
|
||||
# ── Ability panel ─────────────────────────────────────────────────────────────
|
||||
|
||||
## Recursively normalise all Dictionary keys to lowercase so ability JSON can
|
||||
## be read with consistent lowercase lookups regardless of server casing.
|
||||
func _normalize_keys(value: Variant) -> Variant:
|
||||
if value is Dictionary:
|
||||
var result := {}
|
||||
for k in (value as Dictionary):
|
||||
result[str(k).to_lower()] = _normalize_keys((value as Dictionary)[k])
|
||||
return result
|
||||
elif value is Array:
|
||||
var result : Array = []
|
||||
for item in (value as Array):
|
||||
result.append(_normalize_keys(item))
|
||||
return result
|
||||
return value
|
||||
|
||||
|
||||
func _show_ability_panel(unit_id: String, unit: Dictionary) -> void:
|
||||
_hide_ability_panel()
|
||||
# Null trap: server sends "abilitiesJson": null for units with no abilities.
|
||||
@@ -1172,14 +1188,16 @@ func _show_ability_panel(unit_id: String, unit: Dictionary) -> void:
|
||||
if abil_json.is_empty(): return
|
||||
var parsed = JSON.parse_string(abil_json)
|
||||
if not parsed is Array: return
|
||||
# Server may serialise with PascalCase keys — normalise to lowercase.
|
||||
var abilities : Array = _normalize_keys(parsed) as Array
|
||||
|
||||
# Collect Active abilities.
|
||||
var actives : Array = []
|
||||
for i in parsed.size():
|
||||
var ab : Dictionary = parsed[i] as Dictionary
|
||||
for i in abilities.size():
|
||||
var ab : Dictionary = abilities[i] as Dictionary
|
||||
if ab.get("type", "") == "Active":
|
||||
actives.append({ "index": i,
|
||||
"name": ab.get("name", "Ability %d" % i),
|
||||
"name": ab.get("name", "Ability %d" % i),
|
||||
"desc": ab.get("description", ""),
|
||||
"def": ab })
|
||||
|
||||
|
||||
Reference in New Issue
Block a user