diff --git a/Client/origin-client/autoloads/ContentCache.gd b/Client/origin-client/autoloads/ContentCache.gd
index 3851bfe..f3daf46 100644
--- a/Client/origin-client/autoloads/ContentCache.gd
+++ b/Client/origin-client/autoloads/ContentCache.gd
@@ -83,6 +83,25 @@ func start_sync() -> void:
fetch_tile_models()
+## Return the GLB animation track name for a card action.
+##
+## Looks for an animationBinding with the given action_name (case-insensitive).
+## If found and the binding has a non-empty animationTrackName, returns that.
+## Otherwise returns the action_name itself so the caller can do its own
+## case-insensitive fuzzy match against the AnimationPlayer's track list.
+##
+## card_def_id: card definition GUID string
+## action_name: e.g. "attack", "idle", "death", "move"
+func get_anim_track(card_def_id: String, action_name: String) -> String:
+ var def := get_definition(card_def_id)
+ var action_lower := action_name.to_lower()
+ for binding: Dictionary in def.get("animationBindings", []):
+ if str(binding.get("actionName", "")).to_lower() == action_lower:
+ var track := str(binding.get("animationTrackName", ""))
+ return track if not track.is_empty() else action_name
+ return action_name
+
+
## Return the CDN URL for a tile's 3D model, or "" if not assigned.
## affinity: e.g. "Forest" shape: "Square" or "Hex"
func get_tile_model_url(affinity: String, shape: String) -> String:
diff --git a/Client/origin-client/autoloads/Music.gd.uid b/Client/origin-client/autoloads/Music.gd.uid
new file mode 100644
index 0000000..76d80fc
--- /dev/null
+++ b/Client/origin-client/autoloads/Music.gd.uid
@@ -0,0 +1 @@
+uid://c8lby4cq8hsco
diff --git a/Client/origin-client/scenes/game/game_screen.gd b/Client/origin-client/scenes/game/game_screen.gd
index 772f9ee..62e71fa 100644
--- a/Client/origin-client/scenes/game/game_screen.gd
+++ b/Client/origin-client/scenes/game/game_screen.gd
@@ -149,8 +149,24 @@ var _friendly_unit_ids: Dictionary = {} # instanceId → true
# ── Scene refs ────────────────────────────────────────────────────────────────
var _tile_bodies : Dictionary = {} # "x,y" → StaticBody3D
-var _unit_meshes : Dictionary = {} # instanceId → MeshInstance3D (placeholder)
+var _unit_meshes : Dictionary = {} # instanceId → Node3D (placeholder or real model)
var _unit_bodies : Dictionary = {} # instanceId → StaticBody3D
+var _anim_players : Dictionary = {} # instanceId → AnimationPlayer (null if none)
+var _unit_def_ids : Dictionary = {} # instanceId → card definition ID string
+
+# ── Animation / facing state ───────────────────────────────────────────────────
+var _local_is_p1 : bool = false # true when Auth.user_id == playerOneAccountId
+var _prev_unit_hp : Dictionary = {} # instanceId → int, HP from last rebuild
+
+## Animation name aliases: maps the canonical lower-case action to fallback track names.
+## The AnimationPlayer track list is matched case-insensitively against each entry.
+const ANIM_ALIASES : Dictionary = {
+ "idle": ["idle", "idle_a", "idle1", "idle_loop"],
+ "attack": ["attack", "attack_a", "attack1", "attack_b", "strike"],
+ "damaged": ["damaged", "attacked", "hit", "hurt", "flinch"],
+ "dying": ["dying", "death", "die", "dead"],
+ "moving": ["moving", "move", "walk", "run", "walk_cycle"],
+}
# ── Lifecycle ─────────────────────────────────────────────────────────────────
@@ -520,19 +536,28 @@ func _rebuild_units(state: Dictionary) -> void:
for c in _units_root.get_children(): c.queue_free()
_unit_meshes.clear()
_unit_bodies.clear()
+ _anim_players.clear()
+ _unit_def_ids.clear()
+ _prev_unit_hp.clear()
var my_id := Auth.user_id
for player: Dictionary in state.get("players", []):
var is_mine : bool = str(player.get("accountId", "")).to_lower() == my_id.to_lower()
var color : Color = Color(0.3, 0.5, 1.0) if is_mine else Color(1.0, 0.35, 0.35)
var arch : Dictionary = player.get("archSpirit", {})
if not arch.is_empty() and arch.get("position") != null:
- _add_unit_mesh(arch, color)
+ _add_unit_mesh(arch, color, not is_mine)
for unit: Dictionary in player.get("field", []):
if unit.get("position") != null:
- _add_unit_mesh(unit, color)
+ _add_unit_mesh(unit, color, not is_mine)
+ # Store HP for damage detection on next state update.
+ for unit: Dictionary in ([arch] + player.get("field", [])):
+ if unit.is_empty(): continue
+ var iid := str(unit.get("instanceId", ""))
+ if not iid.is_empty():
+ _prev_unit_hp[iid] = int(unit.get("currentHealth", 0))
-func _add_unit_mesh(unit: Dictionary, team_color: Color) -> void:
+func _add_unit_mesh(unit: Dictionary, team_color: Color, is_enemy: bool = false) -> void:
var pd : Dictionary = unit.get("position", {})
if pd.is_empty(): return
var wp := _coord_to_world(pd.get("x", 0), pd.get("y", 0))
@@ -593,6 +618,8 @@ func _add_unit_mesh(unit: Dictionary, team_color: Color) -> void:
# ── Try to load the real 3D model from the card definition ──────────────
var def_id : String = str(unit.get("cardDefinitionId", ""))
+ if not def_id.is_empty():
+ _unit_def_ids[iid] = def_id
if def_id.is_empty():
return
var def := ContentCache.get_definition(def_id)
@@ -601,6 +628,10 @@ func _add_unit_mesh(unit: Dictionary, team_color: Color) -> void:
return
var body_ref : Variant = weakref(body)
+ # Capture facing flag: P1 units face +Z (rotate 180° Y); P2 units face -Z (default).
+ # Convention: GLB models exported facing -Z. P1 is at -Z side of the board.
+ # Rotate if: (local is P1 AND friendly) OR (local is P2 AND enemy).
+ var needs_face_rotation : bool = _local_is_p1 != is_enemy
ModelCache.load_model(model_url, func(model_node: Node3D) -> void:
# Guard: body may have been freed by a state rebuild before load finished.
var b := body_ref.get_ref() as StaticBody3D
@@ -616,12 +647,22 @@ func _add_unit_mesh(unit: Dictionary, team_color: Color) -> void:
if child is MeshInstance3D:
child.queue_free()
+ # Apply facing rotation so units face their opponent across the board.
+ if needs_face_rotation:
+ model_node.rotation_degrees = Vector3(0, 180, 0)
+
# Position model so its local origin sits at the body's position.
# Models should be authored with their base (foot) at y = 0.
# Adjust the body back down so the model base lands on the tile surface.
b.position = wp + Vector3(0, 0.5, 0)
b.add_child(model_node)
_unit_meshes[iid] = model_node
+
+ # Find and store the AnimationPlayer, then start the Idle loop.
+ var ap := _find_animation_player(model_node)
+ _anim_players[iid] = ap
+ if ap != null:
+ _play_unit_anim(iid, "idle", true)
)
@@ -633,6 +674,87 @@ func _find_model3d_url(def: Dictionary) -> String:
return str(d.get("cdnUrl", ""))
return ""
+
+## Recursively find the first AnimationPlayer in a model subtree.
+func _find_animation_player(node: Node) -> AnimationPlayer:
+ if node is AnimationPlayer:
+ return node as AnimationPlayer
+ for child in node.get_children():
+ var found := _find_animation_player(child)
+ if found != null:
+ return found
+ return null
+
+
+## Case-insensitive track name resolver with fallback aliases.
+## Returns the exact track name in the AnimationPlayer, or "" if not found.
+func _resolve_anim_track(ap: AnimationPlayer, action_lower: String) -> String:
+ # Strip library prefix (e.g. "model/Idle" → "idle") for comparison.
+ for full_name: String in ap.get_animation_list():
+ var short := full_name.get_slice("/", full_name.get_slice_count("/") - 1)
+ if short.to_lower() == action_lower:
+ return full_name
+ # Try known aliases.
+ for alias: String in ANIM_ALIASES.get(action_lower, []):
+ for full_name: String in ap.get_animation_list():
+ var short := full_name.get_slice("/", full_name.get_slice_count("/") - 1)
+ if short.to_lower() == alias:
+ return full_name
+ return ""
+
+
+## Play an animation on a unit by action name. Uses card's AnimationTrackName
+## override when set, then falls back to case-insensitive convention matching.
+## Pass loop=true for looping animations (e.g. Idle).
+func _play_unit_anim(iid: String, action: String, loop: bool = false) -> void:
+ var ap : AnimationPlayer = _anim_players.get(iid, null)
+ if ap == null or not is_instance_valid(ap):
+ return
+ # Resolve via CardAnimationBinding override first.
+ var def_id : String = _unit_def_ids.get(iid, "")
+ var desired := action
+ if not def_id.is_empty():
+ var override := ContentCache.get_anim_track(def_id, action)
+ if not override.is_empty():
+ desired = override
+ var track := _resolve_anim_track(ap, desired.to_lower())
+ if track.is_empty():
+ return
+ var anim := ap.get_animation(track)
+ if anim == null:
+ return
+ anim.loop_mode = Animation.LOOP_LINEAR if loop else Animation.LOOP_NONE
+ if not loop and ap.current_animation == track and ap.is_playing():
+ return # Don't restart the same one-shot animation mid-play.
+ ap.play(track)
+ # Return to Idle after one-shot animations finish.
+ if not loop:
+ ap.animation_finished.connect(
+ func(_n: String) -> void: _play_unit_anim(iid, "idle", true),
+ CONNECT_ONE_SHOT)
+
+
+## Detect HP decreases and unit deaths vs previous state, and fire animations.
+## Called just before _rebuild_units so animations play on the existing nodes.
+func _play_damage_animations(state: Dictionary) -> void:
+ if _prev_unit_hp.is_empty():
+ return
+ var seen_iids : Dictionary = {}
+ for player: Dictionary in state.get("players", []):
+ for unit: Dictionary in ([player.get("archSpirit", {})] + player.get("field", [])):
+ if unit.is_empty(): continue
+ var iid := str(unit.get("instanceId", ""))
+ var new_hp := int(unit.get("currentHealth", 0))
+ var old_hp : int = _prev_unit_hp.get(iid, new_hp)
+ seen_iids[iid] = true
+ if new_hp < old_hp:
+ _play_unit_anim(iid, "damaged")
+ # Units that vanished this update → play dying.
+ for iid: String in _prev_unit_hp:
+ if not seen_iids.has(iid):
+ _play_unit_anim(iid, "dying")
+
+
# ── Highlights ────────────────────────────────────────────────────────────────
func _clear_highlights() -> void:
@@ -912,6 +1034,7 @@ func _handle_board_click(mouse_pos: Vector2) -> void:
Mode.UNIT_SELECTED:
if not unit_id.is_empty():
if _is_enemy_unit(unit_id):
+ _play_unit_anim(_sel_unit_id, "attack")
Game.send_attack(_sel_unit_id, unit_id)
_set_mode(Mode.NONE)
elif unit_id == _sel_unit_id:
@@ -1816,24 +1939,26 @@ func _on_state_updated(state: Dictionary) -> void:
_rebuild_ownership(state)
# Orient camera behind the local player's row on the first state with playerOneAccountId.
- if not _camera_oriented:
- var p1_id : String = str(state.get("playerOneAccountId", ""))
- if not p1_id.is_empty():
- _camera_oriented = true
- var bh := float(Game.board_height())
- # Shift cam_pivot toward the opponent's side (30 % of board half-length)
- # so the player's own row appears in the lower-middle of the screen,
- # above the hand panel — not hidden behind it.
- var pivot_offset := (bh - 1.0) * 0.3
- if Auth.user_id.to_lower() == p1_id.to_lower():
- # P1 row is at world -Z. Camera looks from -Z toward +Z → yaw=180°.
- # Shift pivot toward world -Z so P1's row is NOT at the very bottom.
- _cam_yaw = 180.0
- _cam_pivot = Vector3(0.0, 0.0, -pivot_offset)
- else:
- # P2 row is at world +Z (default yaw=0°).
- _cam_pivot = Vector3(0.0, 0.0, pivot_offset)
- _apply_camera()
+ var p1_id : String = str(state.get("playerOneAccountId", ""))
+ if not p1_id.is_empty():
+ # Update P1/P2 flag every time — used for model facing on full rebuild.
+ _local_is_p1 = Auth.user_id.to_lower() == p1_id.to_lower()
+ if not _camera_oriented and not p1_id.is_empty():
+ _camera_oriented = true
+ var bh := float(Game.board_height())
+ # Shift cam_pivot toward the opponent's side (30 % of board half-length)
+ # so the player's own row appears in the lower-middle of the screen,
+ # above the hand panel — not hidden behind it.
+ var pivot_offset := (bh - 1.0) * 0.3
+ if _local_is_p1:
+ # P1 row is at world -Z. Camera looks from -Z toward +Z → yaw=180°.
+ # Shift pivot toward world -Z so P1's row is NOT at the very bottom.
+ _cam_yaw = 180.0
+ _cam_pivot = Vector3(0.0, 0.0, -pivot_offset)
+ else:
+ # P2 row is at world +Z (default yaw=0°).
+ _cam_pivot = Vector3(0.0, 0.0, pivot_offset)
+ _apply_camera()
var board : Dictionary = state.get("board", {})
if _tile_bodies.is_empty() and not board.is_empty():
@@ -1844,6 +1969,10 @@ func _on_state_updated(state: Dictionary) -> void:
_update_tile_affinity(c.get("x", 0), c.get("y", 0),
tile.get("resolvedAffinity", "Void"))
+ # Play damage/death animations on existing unit nodes before the rebuild
+ # destroys them. These play for one frame — enough for a flash effect and
+ # as a foundation for a future deferred-rebuild architecture.
+ _play_damage_animations(state)
_rebuild_units(state)
var hand := Game.get_hand()
print("[GameScreen] state phase=", state.get("phase","?"),
diff --git a/Client/origin-client/scenes/game/in_game_settings.gd.uid b/Client/origin-client/scenes/game/in_game_settings.gd.uid
new file mode 100644
index 0000000..2c968aa
--- /dev/null
+++ b/Client/origin-client/scenes/game/in_game_settings.gd.uid
@@ -0,0 +1 @@
+uid://02h6fbskf8bq
diff --git a/Server/src/SOR.Admin/Components/Pages/Cards/CardEditor.razor b/Server/src/SOR.Admin/Components/Pages/Cards/CardEditor.razor
index c1e9792..75db9aa 100644
--- a/Server/src/SOR.Admin/Components/Pages/Cards/CardEditor.razor
+++ b/Server/src/SOR.Admin/Components/Pages/Cards/CardEditor.razor
@@ -323,7 +323,7 @@ else