From bdbd7b204f1024831c1a816da209919e7bad74c2 Mon Sep 17 00:00:00 2001 From: dingo Date: Mon, 9 Mar 2026 22:38:42 -0400 Subject: [PATCH] Fix: normalise ability JSON keys to lowercase before parsing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Co-Authored-By: Happy --- .../origin-client/scenes/game/game_screen.gd | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/Client/origin-client/scenes/game/game_screen.gd b/Client/origin-client/scenes/game/game_screen.gd index 135e02e..ec42523 100644 --- a/Client/origin-client/scenes/game/game_screen.gd +++ b/Client/origin-client/scenes/game/game_screen.gd @@ -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 })