Fix: abilitiesJson null crash, battlefield popup, ExactSelf ability filter

Client (game_screen.gd):
- Fix crash when clicking a unit with null abilitiesJson: server sends the key
  with a null value, so dict.get(key,default) returns null — guard both uses
  (_show_ability_panel and _on_hold_timer_fired) with explicit null check.
- Add double-click on battlefield units to open a full CardDetailPopup showing
  name, affinity, stats, and ability descriptions. Popup is instantiated once
  in _ready() and reused; aliases movementPoints/abilities keys as expected.

Server (Filters.cs / AbilitySystem.cs):
- IsSelf filter now matches by CardDefinitionId (definition-level: any copy of
  the same card). This is the appropriate semantic for "self" as a type scope.
- IsExactSelf filter added: matches by InstanceId (instance-level: only this
  specific unit on the battlefield). Use this to prevent duplicate-instance
  trigger bleed where two copies of a card both fire when only one acted.
- TriggerMatches now accepts the evaluating FieldCard and forwards its
  InstanceId to Own() for all ownership checks.
- Own() gains "ExactSelf" scope: fires only when occ.Data.SourceId matches the
  evaluating unit's InstanceId — eliminating the definition-level bleed bug.

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:
dingo
2026-03-08 16:28:06 -04:00
co-authored by Claude Happy
parent 94f39be8a7
commit 11ebdc40d7
3 changed files with 93 additions and 33 deletions
@@ -64,6 +64,7 @@ enum Mode {
var count : int = 0
var _last_click_frame : int = -1
var _last_click_iid : String = ""
var _card_detail_popup : Control = null
# ── Affinity colors ───────────────────────────────────────────────────────────
const AFFINITY_COLORS : Dictionary = {
@@ -92,7 +93,8 @@ const AFFINITY_COLORS : Dictionary = {
"GatewayField": Color(0.52, 0.60, 0.22),
}
const _CARD_WIDGET_SCENE := preload("res://scenes/collection/components/CardWidget.tscn")
const _CARD_WIDGET_SCENE := preload("res://scenes/collection/components/CardWidget.tscn")
const _CARD_DETAIL_POPUP_SCENE := preload("res://scenes/collection/components/CardDetailPopup.tscn")
const HI_GREEN := Color(0.20, 0.90, 0.20, 0.40)
const HI_RED := Color(1.00, 0.25, 0.25, 0.50)
@@ -159,6 +161,11 @@ func _ready() -> void:
get_tree().change_scene_to_file("res://scenes/main/MainScreen.tscn"))
_hold_timer.timeout.connect(_on_hold_timer_fired)
# Card detail popup (shared overlay — reused across multiple unit clicks).
_card_detail_popup = _CARD_DETAIL_POPUP_SCENE.instantiate()
_hud.add_child(_card_detail_popup)
_card_detail_popup.hide()
Game.state_updated.connect(_on_state_updated)
Game.game_over.connect(_on_game_over)
@@ -221,6 +228,12 @@ func _unhandled_input(event: InputEvent) -> void:
_last_mouse = mb.position
elif mb.button_index == MOUSE_BUTTON_LEFT:
if mb.pressed:
# Double-click on a battlefield unit → show full card detail popup.
if mb.double_click:
var dbl_unit_id := _mouse_to_unit_id(mb.position)
if not dbl_unit_id.is_empty():
_show_unit_detail_popup(dbl_unit_id)
return
_last_mouse = mb.position
_drag_active = false
_press_was_on_board = true # unhandled press = board area, not a UI card
@@ -986,7 +999,10 @@ func _show_card_picker(title: String, cards: Array, on_pick: Callable) -> void:
func _show_ability_panel(unit_id: String, unit: Dictionary) -> void:
_hide_ability_panel()
var abil_json : String = unit.get("abilitiesJson", "")
# Null trap: server sends "abilitiesJson": null for units with no abilities.
# dict.get(key, default) returns null when key exists with null value.
var _raw_abil_ap = unit.get("abilitiesJson")
var abil_json : String = "" if _raw_abil_ap == null else str(_raw_abil_ap)
if abil_json.is_empty(): return
var parsed = JSON.parse_string(abil_json)
if not parsed is Array: return
@@ -1038,6 +1054,18 @@ func _hide_ability_panel() -> void:
_ability_panel.queue_free()
_ability_panel = null
func _show_unit_detail_popup(unit_id: String) -> void:
var unit := Game.get_unit_by_id(unit_id)
if unit.is_empty(): return
# Build a dict with the aliases card_detail_popup expects.
var data := unit.duplicate()
data["movementPoints"] = unit.get("maxMp", null)
# Null-safe abilitiesJson → abilities alias (popup reads "abilities" key).
var _raw_abil_udp = unit.get("abilitiesJson")
data["abilities"] = "" if _raw_abil_udp == null else str(_raw_abil_udp)
_card_detail_popup.show_card(data, data)
# ── Hand card ArchSpirit routing ──────────────────────────────────────────────
func _on_hand_card_clicked(iid: String, _panel: PanelContainer) -> void:
@@ -1291,7 +1319,8 @@ func _on_hold_timer_fired() -> void:
int(unit.get("currentDefense", 0)), int(unit.get("maxDefense", 0)),
int(unit.get("damage", 0))]
var abil_str := ""
var parsed = JSON.parse_string(unit.get("abilitiesJson", "[]"))
var _raw_abil_hud = unit.get("abilitiesJson")
var parsed = JSON.parse_string("[]" if _raw_abil_hud == null else str(_raw_abil_hud))
if parsed is Array:
for ab: Dictionary in parsed:
abil_str += "• %s\n" % str(ab.get("name", ""))