Fix: Spirit card highlights — emissive material, preserve selection through state updates

- _add_highlight: use emission (emission_energy_multiplier=2) + 75% opaque base
  so tiles glow visibly regardless of depth-sort/transparency ordering; raised
  Y to 0.58 (clear of tile top at 0.50); thicker mesh (0.06 vs 0.02)
- Remove Godot-3-only flags_transparent property (no-op in Godot 4)
- _on_state_updated: preserve CARD_FROM_HAND / TERRAMORPHA_SELECT through server
  state pushes if selected card is still in hand (re-apply highlights after
  _rebuild_hand); only clear UNIT_SELECTED and other transient modes
- Add diagnostic prints to _add_highlight and _on_state_updated to trace when
  state updates arrive relative to card selection

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 12:40:48 -04:00
co-authored by Claude Happy
parent 101e671752
commit b36a644f56
3 changed files with 73 additions and 50 deletions
@@ -96,11 +96,11 @@ func _add_stat(label_text: String, value_text: String) -> void:
var lbl := Label.new() var lbl := Label.new()
lbl.text = label_text lbl.text = label_text
lbl.modulate = Color(0.65, 0.65, 0.72) lbl.modulate = Color(0.65, 0.65, 0.72)
lbl.theme_override_font_sizes["font_size"] = 12 #lbl.theme_override_font_sizes["font_size"] = 12
var val := Label.new() var val := Label.new()
val.text = value_text val.text = value_text
val.theme_override_font_sizes["font_size"] = 13 #val.theme_override_font_sizes["font_size"] = 13
stats_grid.add_child(lbl) stats_grid.add_child(lbl)
stats_grid.add_child(val) stats_grid.add_child(val)
@@ -1,6 +1,6 @@
[gd_scene load_steps=2 format=3 uid="uid://game_screen"] [gd_scene load_steps=2 format=3 uid="uid://b17evi1hw4dqu"]
[ext_resource type="Script" path="res://scenes/game/game_screen.gd" id="1_gscr"] [ext_resource type="Script" uid="uid://b8x84lb58h6gx" path="res://scenes/game/game_screen.gd" id="1_gscr"]
[node name="GameScreen" type="Node3D"] [node name="GameScreen" type="Node3D"]
script = ExtResource("1_gscr") script = ExtResource("1_gscr")
@@ -29,19 +29,15 @@ transform = Transform3D(1, 0, 0, 0, 0.766044, 0.642788, 0, -0.642788, 0.766044,
layer = 10 layer = 10
[node name="TopBar" type="HBoxContainer" parent="HUD"] [node name="TopBar" type="HBoxContainer" parent="HUD"]
layout_mode = 1
anchors_preset = -1 anchors_preset = -1
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 1.0 anchor_right = 1.0
anchor_bottom = 0.0
offset_bottom = 48.0 offset_bottom = 48.0
theme_override_constants/separation = 0 theme_override_constants/separation = 0
[node name="PhaseLabel" type="Label" parent="HUD/TopBar"] [node name="PhaseLabel" type="Label" parent="HUD/TopBar"]
unique_name_in_owner = true unique_name_in_owner = true
layout_mode = 2
custom_minimum_size = Vector2(140, 48) custom_minimum_size = Vector2(140, 48)
layout_mode = 2
theme_override_font_sizes/font_size = 13 theme_override_font_sizes/font_size = 13
text = "Phase: —" text = "Phase: —"
vertical_alignment = 1 vertical_alignment = 1
@@ -57,17 +53,17 @@ vertical_alignment = 1
[node name="OpponentPanel" type="HBoxContainer" parent="HUD/TopBar"] [node name="OpponentPanel" type="HBoxContainer" parent="HUD/TopBar"]
unique_name_in_owner = true unique_name_in_owner = true
layout_mode = 2
custom_minimum_size = Vector2(240, 48) custom_minimum_size = Vector2(240, 48)
layout_mode = 2
theme_override_constants/separation = 8 theme_override_constants/separation = 8
[node name="OppNameLabel" type="Label" parent="HUD/TopBar/OpponentPanel"] [node name="OppNameLabel" type="Label" parent="HUD/TopBar/OpponentPanel"]
unique_name_in_owner = true unique_name_in_owner = true
modulate = Color(1, 0.5, 0.5, 1)
layout_mode = 2 layout_mode = 2
theme_override_font_sizes/font_size = 12 theme_override_font_sizes/font_size = 12
text = "Opponent" text = "Opponent"
vertical_alignment = 1 vertical_alignment = 1
modulate = Color(1, 0.5, 0.5, 1)
[node name="OppHandLabel" type="Label" parent="HUD/TopBar/OpponentPanel"] [node name="OppHandLabel" type="Label" parent="HUD/TopBar/OpponentPanel"]
unique_name_in_owner = true unique_name_in_owner = true
@@ -90,14 +86,11 @@ theme_override_font_sizes/font_size = 11
text = "Discard" text = "Discard"
[node name="HandArea" type="PanelContainer" parent="HUD"] [node name="HandArea" type="PanelContainer" parent="HUD"]
layout_mode = 1
anchors_preset = -1 anchors_preset = -1
anchor_left = 0.0
anchor_top = 1.0 anchor_top = 1.0
anchor_right = 0.75 anchor_right = 0.75
anchor_bottom = 1.0 anchor_bottom = 1.0
offset_top = -220.0 offset_top = -250.0
offset_right = 0.0
[node name="HandScroll" type="ScrollContainer" parent="HUD/HandArea"] [node name="HandScroll" type="ScrollContainer" parent="HUD/HandArea"]
unique_name_in_owner = true unique_name_in_owner = true
@@ -113,19 +106,22 @@ size_flags_vertical = 4
theme_override_constants/separation = 6 theme_override_constants/separation = 6
[node name="RightPanel" type="PanelContainer" parent="HUD"] [node name="RightPanel" type="PanelContainer" parent="HUD"]
layout_mode = 1
anchors_preset = -1 anchors_preset = -1
anchor_left = 0.75 anchor_left = 0.75
anchor_top = 1.0 anchor_top = 1.0
anchor_right = 1.0 anchor_right = 1.0
anchor_bottom = 1.0 anchor_bottom = 1.0
offset_top = -220.0 offset_left = -1.0
offset_top = -241.0
offset_right = -1.0
offset_bottom = 9.0
scale = Vector2(1, 0.96000004)
[node name="RightMargin" type="MarginContainer" parent="HUD/RightPanel"] [node name="RightMargin" type="MarginContainer" parent="HUD/RightPanel"]
layout_mode = 2 layout_mode = 2
theme_override_constants/margin_left = 10 theme_override_constants/margin_left = 10
theme_override_constants/margin_right = 10
theme_override_constants/margin_top = 8 theme_override_constants/margin_top = 8
theme_override_constants/margin_right = 10
theme_override_constants/margin_bottom = 8 theme_override_constants/margin_bottom = 8
[node name="RightVBox" type="VBoxContainer" parent="HUD/RightPanel/RightMargin"] [node name="RightVBox" type="VBoxContainer" parent="HUD/RightPanel/RightMargin"]
@@ -156,21 +152,17 @@ layout_mode = 2
theme_override_font_sizes/font_size = 12 theme_override_font_sizes/font_size = 12
text = "View Discard" text = "View Discard"
[node name="Spacer" type="Control" parent="HUD/RightPanel/RightMargin/RightVBox"]
layout_mode = 2
size_flags_vertical = 3
[node name="DrawBtn" type="Button" parent="HUD/RightPanel/RightMargin/RightVBox"] [node name="DrawBtn" type="Button" parent="HUD/RightPanel/RightMargin/RightVBox"]
unique_name_in_owner = true unique_name_in_owner = true
layout_mode = 2
custom_minimum_size = Vector2(0, 36) custom_minimum_size = Vector2(0, 36)
layout_mode = 2
theme_override_font_sizes/font_size = 13 theme_override_font_sizes/font_size = 13
text = "Draw Card" text = "Draw Card"
[node name="EndTurnBtn" type="Button" parent="HUD/RightPanel/RightMargin/RightVBox"] [node name="EndTurnBtn" type="Button" parent="HUD/RightPanel/RightMargin/RightVBox"]
unique_name_in_owner = true unique_name_in_owner = true
layout_mode = 2
custom_minimum_size = Vector2(0, 36) custom_minimum_size = Vector2(0, 36)
layout_mode = 2
theme_override_font_sizes/font_size = 13 theme_override_font_sizes/font_size = 13
text = "End Turn" text = "End Turn"
@@ -182,7 +174,7 @@ text = "Concede"
[node name="ContextPopup" type="PanelContainer" parent="HUD"] [node name="ContextPopup" type="PanelContainer" parent="HUD"]
unique_name_in_owner = true unique_name_in_owner = true
layout_mode = 1 visible = false
anchors_preset = -1 anchors_preset = -1
anchor_left = 0.5 anchor_left = 0.5
anchor_top = 0.5 anchor_top = 0.5
@@ -192,13 +184,12 @@ offset_left = -160.0
offset_top = -120.0 offset_top = -120.0
offset_right = 160.0 offset_right = 160.0
offset_bottom = 120.0 offset_bottom = 120.0
visible = false
[node name="ContextMargin" type="MarginContainer" parent="HUD/ContextPopup"] [node name="ContextMargin" type="MarginContainer" parent="HUD/ContextPopup"]
layout_mode = 2 layout_mode = 2
theme_override_constants/margin_left = 12 theme_override_constants/margin_left = 12
theme_override_constants/margin_right = 12
theme_override_constants/margin_top = 8 theme_override_constants/margin_top = 8
theme_override_constants/margin_right = 12
theme_override_constants/margin_bottom = 8 theme_override_constants/margin_bottom = 8
[node name="ContextVBox" type="VBoxContainer" parent="HUD/ContextPopup/ContextMargin"] [node name="ContextVBox" type="VBoxContainer" parent="HUD/ContextPopup/ContextMargin"]
@@ -215,16 +206,14 @@ text = "Tile (0,0) — Void"
unique_name_in_owner = true unique_name_in_owner = true
layout_mode = 2 layout_mode = 2
theme_override_font_sizes/font_size = 12 theme_override_font_sizes/font_size = 12
text = ""
autowrap_mode = 3 autowrap_mode = 3
[node name="ContextAbilitiesLabel" type="Label" parent="HUD/ContextPopup/ContextMargin/ContextVBox"] [node name="ContextAbilitiesLabel" type="Label" parent="HUD/ContextPopup/ContextMargin/ContextVBox"]
unique_name_in_owner = true unique_name_in_owner = true
modulate = Color(0.7, 0.7, 0.85, 1)
layout_mode = 2 layout_mode = 2
theme_override_font_sizes/font_size = 11 theme_override_font_sizes/font_size = 11
text = ""
autowrap_mode = 3 autowrap_mode = 3
modulate = Color(0.7, 0.7, 0.85, 1)
[node name="ContextClose" type="Button" parent="HUD/ContextPopup/ContextMargin/ContextVBox"] [node name="ContextClose" type="Button" parent="HUD/ContextPopup/ContextMargin/ContextVBox"]
unique_name_in_owner = true unique_name_in_owner = true
@@ -234,18 +223,18 @@ text = "Close"
[node name="DiscardViewer" type="PanelContainer" parent="HUD"] [node name="DiscardViewer" type="PanelContainer" parent="HUD"]
unique_name_in_owner = true unique_name_in_owner = true
layout_mode = 1 visible = false
anchors_preset = -1
anchor_left = 0.1 anchor_left = 0.1
anchor_top = 0.05 anchor_top = 0.05
anchor_right = 0.9 anchor_right = 0.9
anchor_bottom = 0.95 anchor_bottom = 0.95
visible = false
[node name="DVMargin" type="MarginContainer" parent="HUD/DiscardViewer"] [node name="DVMargin" type="MarginContainer" parent="HUD/DiscardViewer"]
layout_mode = 2 layout_mode = 2
theme_override_constants/margin_left = 16 theme_override_constants/margin_left = 16
theme_override_constants/margin_right = 16
theme_override_constants/margin_top = 12 theme_override_constants/margin_top = 12
theme_override_constants/margin_right = 16
theme_override_constants/margin_bottom = 12 theme_override_constants/margin_bottom = 12
[node name="DVVBox" type="VBoxContainer" parent="HUD/DiscardViewer/DVMargin"] [node name="DVVBox" type="VBoxContainer" parent="HUD/DiscardViewer/DVMargin"]
@@ -271,25 +260,25 @@ theme_override_constants/separation = 4
[node name="DVCloseBtn" type="Button" parent="HUD/DiscardViewer/DVMargin/DVVBox"] [node name="DVCloseBtn" type="Button" parent="HUD/DiscardViewer/DVMargin/DVVBox"]
unique_name_in_owner = true unique_name_in_owner = true
layout_mode = 2
custom_minimum_size = Vector2(0, 36) custom_minimum_size = Vector2(0, 36)
layout_mode = 2
theme_override_font_sizes/font_size = 13 theme_override_font_sizes/font_size = 13
text = "Close" text = "Close"
[node name="GameOverOverlay" type="PanelContainer" parent="HUD"] [node name="GameOverOverlay" type="PanelContainer" parent="HUD"]
unique_name_in_owner = true unique_name_in_owner = true
layout_mode = 1 visible = false
anchors_preset = -1
anchor_left = 0.25 anchor_left = 0.25
anchor_top = 0.25 anchor_top = 0.25
anchor_right = 0.75 anchor_right = 0.75
anchor_bottom = 0.75 anchor_bottom = 0.75
visible = false
[node name="GOMargin" type="MarginContainer" parent="HUD/GameOverOverlay"] [node name="GOMargin" type="MarginContainer" parent="HUD/GameOverOverlay"]
layout_mode = 2 layout_mode = 2
theme_override_constants/margin_left = 24 theme_override_constants/margin_left = 24
theme_override_constants/margin_right = 24
theme_override_constants/margin_top = 24 theme_override_constants/margin_top = 24
theme_override_constants/margin_right = 24
theme_override_constants/margin_bottom = 24 theme_override_constants/margin_bottom = 24
[node name="GOVBox" type="VBoxContainer" parent="HUD/GameOverOverlay/GOMargin"] [node name="GOVBox" type="VBoxContainer" parent="HUD/GameOverOverlay/GOMargin"]
@@ -307,13 +296,12 @@ horizontal_alignment = 1
unique_name_in_owner = true unique_name_in_owner = true
layout_mode = 2 layout_mode = 2
theme_override_font_sizes/font_size = 15 theme_override_font_sizes/font_size = 15
text = ""
horizontal_alignment = 1 horizontal_alignment = 1
[node name="GOMainMenuBtn" type="Button" parent="HUD/GameOverOverlay/GOMargin/GOVBox"] [node name="GOMainMenuBtn" type="Button" parent="HUD/GameOverOverlay/GOMargin/GOVBox"]
unique_name_in_owner = true unique_name_in_owner = true
layout_mode = 2
custom_minimum_size = Vector2(0, 44) custom_minimum_size = Vector2(0, 44)
layout_mode = 2
theme_override_font_sizes/font_size = 15 theme_override_font_sizes/font_size = 15
text = "Return to Main Menu" text = "Return to Main Menu"
+46 -11
View File
@@ -493,15 +493,23 @@ func _clear_highlights() -> void:
func _add_highlight(x: int, y: int, color: Color) -> void: func _add_highlight(x: int, y: int, color: Color) -> void:
var mi := MeshInstance3D.new() var mi := MeshInstance3D.new()
var bm := BoxMesh.new() var bm := BoxMesh.new()
bm.size = Vector3(0.98, 0.02, 0.98) bm.size = Vector3(0.96, 0.06, 0.96)
mi.mesh = bm mi.mesh = bm
var mat := StandardMaterial3D.new() var mat := StandardMaterial3D.new()
mat.albedo_color = color # Use a solid opaque base + emission so the highlight is always visible
mat.transparency = BaseMaterial3D.TRANSPARENCY_ALPHA # regardless of depth-sort or transparency ordering.
mat.flags_transparent = true mat.albedo_color = Color(color.r, color.g, color.b, 1.0)
mi.material_override = mat mat.emission_enabled = true
mi.position = _coord_to_world(x, y) + Vector3(0, 0.52, 0) mat.emission = Color(color.r, color.g, color.b)
mat.emission_energy_multiplier = 2.0
# Keep a mild transparency so the tile below is still readable.
mat.transparency = BaseMaterial3D.TRANSPARENCY_ALPHA
mat.albedo_color.a = 0.75
mi.material_override = mat
# Position clearly above the tile top (tile top = Y 0.50).
mi.position = _coord_to_world(x, y) + Vector3(0, 0.58, 0)
_hi_root.add_child(mi) _hi_root.add_child(mi)
print("[Highlight] added (%d,%d) hi_root children=%d" % [x, y, _hi_root.get_child_count()])
func _highlight_tiles(coords: Array, color: Color) -> void: func _highlight_tiles(coords: Array, color: Color) -> void:
@@ -536,13 +544,15 @@ func _valid_play_tiles(card: Dictionary) -> Array:
var raw_min = arch.get("minChannelRange") var raw_min = arch.get("minChannelRange")
var raw_max = arch.get("maxChannelRange") var raw_max = arch.get("maxChannelRange")
var min_r : int = 1 if raw_min == null else int(raw_min) var min_r : int = 1 if raw_min == null else int(raw_min)
var max_r : int = 2 if raw_max == null else int(raw_max) var max_r : int = 1 if raw_max == null else int(raw_max)
for tx in range(bw): for tx in range(bw):
for ty in range(bh): for ty in range(bh):
var dist : int = abs(tx - ax) + abs(ty - ay) var dist : int = abs(tx - ax) + abs(ty - ay)
if dist < min_r or dist > max_r: continue if dist < min_r or dist > max_r: continue
if Game.get_tile(tx, ty).get("occupantId"): continue if Game.get_tile(tx, ty).get("occupantId"): continue
print("Adding tiles")
results.append(Vector2i(tx, ty)) results.append(Vector2i(tx, ty))
print("results: ", results)
"Terramorpha": "Terramorpha":
for tx in range(bw): for tx in range(bw):
@@ -718,9 +728,10 @@ func _handle_board_click(mouse_pos: Vector2) -> void:
if abs(coord.x - last.x) + abs(coord.y - last.y) != 1: if abs(coord.x - last.x) + abs(coord.y - last.y) != 1:
return # must be adjacent return # must be adjacent
# Avoid duplicates. # Avoid duplicates.
print("Handle Board Click: terra targets: ", _terra_targets)
if _terra_targets.has(coord): return if _terra_targets.has(coord): return
_terra_targets.append(coord) _terra_targets.append(coord)
print("Added Target")
if _terra_targets.size() >= _terra_count: if _terra_targets.size() >= _terra_count:
# All tiles selected — send play. # All tiles selected — send play.
var targets := _terra_targets.map(func(v: Vector2i) -> Dictionary: var targets := _terra_targets.map(func(v: Vector2i) -> Dictionary:
@@ -1265,6 +1276,9 @@ func _on_game_over(winner_id: String, win_condition: String,
# ── State → scene ───────────────────────────────────────────────────────────── # ── State → scene ─────────────────────────────────────────────────────────────
func _on_state_updated(state: Dictionary) -> void: func _on_state_updated(state: Dictionary) -> void:
print("[StateUpdate] phase=", state.get("phase","?"),
" mode=", _mode, " sel_card=",
_sel_card_id.substr(0, 8) if not _sel_card_id.is_empty() else "none")
_rebuild_ownership(state) _rebuild_ownership(state)
# Orient camera behind the local player's row on the first state with playerOneAccountId. # Orient camera behind the local player's row on the first state with playerOneAccountId.
@@ -1305,9 +1319,30 @@ func _on_state_updated(state: Dictionary) -> void:
_rebuild_hand(hand) _rebuild_hand(hand)
_update_hud(state) _update_hud(state)
# Clear non-PLACEMENT selection after state change. # After a state update, preserve hand-card and unit selections where possible.
if _mode not in [Mode.NONE, Mode.PLACEMENT]: # A state push from the server (e.g. opponent action, draw echo) must not
_set_mode(Mode.NONE) # silently clear tile highlights that the player just set up.
match _mode:
Mode.NONE, Mode.PLACEMENT:
pass # placement highlights are managed in _update_hud above
Mode.CARD_FROM_HAND, Mode.TERRAMORPHA_SELECT:
# Keep selection only if the card is still in our hand.
var sel_card := _find_hand_card(_sel_card_id)
if sel_card.is_empty():
print("[StateUpdate] selected card gone — clearing mode")
_set_mode(Mode.NONE)
else:
# Re-apply highlights: board/units may have changed.
print("[StateUpdate] preserving CARD_FROM_HAND, re-highlighting")
_clear_highlights()
_highlight_tiles(_valid_play_tiles(sel_card), HI_GREEN)
_refresh_hand_selection() # mark the (new) widget as selected
_:
# Unit selected, sacrifice, ability — clear these on any state change
# because unit positions / health / eligibility may have changed.
_set_mode(Mode.NONE)
# Auto-draw. # Auto-draw.
if state.get("phase", "") == "Draw" and Game.is_my_turn(): if state.get("phase", "") == "Draw" and Game.is_my_turn():