Feature: GLB animation playback, model facing, CDN animation preview

Server:
- CardAnimationBinding.AnimationTrackName: nullable override for GLB track name
  (blank = case-insensitive convention match; Idle/Attack/Damaged/Moving/Dying)
- CardAnimationBindingDto: includes AnimationTrackName in content sync
- CardEditor: GLB Track Name column in animation bindings table
- CdnBrowser: model-viewer animation list + playback (JS interop on load event)
- Migration: AddAnimationTrackName applied to production

Client:
- ContentCache.get_anim_track(): resolves GLB track name from binding override
  or falls back to convention with case-insensitive aliases
- game_screen.gd:
  - _find_animation_player(): recursive search in loaded GLB scene tree
  - _resolve_anim_track(): case-insensitive + alias resolution
  - _play_unit_anim(): plays track, returns to Idle when one-shot finishes
  - _play_damage_animations(): detects HP drops and unit deaths before rebuild
  - Model facing: P1 units rotated 180deg Y to face opponent across board
  - Idle loop starts automatically after real model loads
  - Attack animation fires immediately on attack input (before ACK)

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-15 14:06:55 -04:00
co-authored by Claude Happy
parent dfafe89e79
commit c4999c953a
12 changed files with 747 additions and 28 deletions
@@ -323,7 +323,7 @@ else
<h6 class="text-muted mb-3">Animation Bindings</h6>
<table class="table table-sm">
<thead><tr><th>Action</th><th>Animation CDN URL</th><th>Cast Sound URL</th><th>Impact Sound URL</th><th>AI</th><th>Upload</th><th></th></tr></thead>
<thead><tr><th>Action</th><th>GLB Track Name</th><th>Animation CDN URL</th><th>Cast Sound URL</th><th>Impact Sound URL</th><th>AI</th><th>Upload</th><th></th></tr></thead>
<tbody>
@foreach (var anim in _card.AnimationBindings)
{
@@ -333,6 +333,10 @@ else
<input @bind="anim.ActionName" class="form-control form-control-sm"
placeholder="e.g. attack" />
</td>
<td style="width:140px">
<input @bind="anim.AnimationTrackName" class="form-control form-control-sm"
placeholder="e.g. Attack (blank=auto)" />
</td>
<td>
<input @bind="anim.AnimationCdnUrl" class="form-control form-control-sm"
placeholder="https://cdn.sor.gg/anims/…" />
@@ -1,5 +1,6 @@
@page "/content/cdn"
@attribute [Authorize(Roles = "Admin,SuperAdmin")]
@implements IDisposable
@using Amazon.S3
@using Amazon.S3.Model
@using Microsoft.AspNetCore.Components.Forms
@@ -283,10 +284,11 @@
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title"><i class="bi bi-box me-2"></i>3D Preview</h5>
<button type="button" class="btn-close" @onclick="() => _previewUrl = null"></button>
<button type="button" class="btn-close" @onclick="ClosePreview"></button>
</div>
<div class="modal-body p-0" style="background:#f0f0f0">
<model-viewer src="@_previewUrl"
<model-viewer id="mv-preview"
src="@_previewUrl"
camera-controls
auto-rotate
auto-rotate-delay="1000"
@@ -295,13 +297,29 @@
style="width:100%;height:520px;background:#f5f5f5">
</model-viewer>
</div>
<div class="modal-footer py-2">
<div class="modal-footer py-2 flex-wrap gap-2">
<span class="text-muted small font-monospace me-auto text-break">@_previewUrl</span>
@if (_previewAnimations.Count > 0)
{
<select class="form-select form-select-sm" style="width:auto"
value="@_selectedAnimation"
@onchange="OnAnimationSelected">
<option value="">— No animation —</option>
@foreach (var name in _previewAnimations)
{
<option value="@name">@name</option>
}
</select>
}
else if (_previewUrl is not null)
{
<span class="text-muted small fst-italic">Loading animations…</span>
}
<button class="btn btn-sm btn-outline-secondary"
@onclick="() => CopyUrlAsync(_previewUrl)">
@onclick="() => CopyUrlAsync(_previewUrl!)">
<i class="bi bi-clipboard me-1"></i>Copy URL
</button>
<button class="btn btn-sm btn-secondary" @onclick="() => _previewUrl = null">Close</button>
<button class="btn btn-sm btn-secondary" @onclick="ClosePreview">Close</button>
</div>
</div>
</div>
@@ -309,6 +327,24 @@
}
<script type="module" src="https://ajax.googleapis.com/ajax/libs/model-viewer/3.5.0/model-viewer.min.js"></script>
<script>
window.sorCdn = {
initModelViewerAnimations: function (elementId, dotnetRef) {
const el = document.getElementById(elementId);
if (!el) { dotnetRef.invokeMethodAsync('OnAnimationsLoaded', []); return; }
const report = () =>
dotnetRef.invokeMethodAsync('OnAnimationsLoaded', Array.from(el.availableAnimations ?? []));
if (el.loaded) { report(); }
else { el.addEventListener('load', report, { once: true }); }
},
setModelAnimation: function (elementId, animName) {
const el = document.getElementById(elementId);
if (!el) return;
if (animName) { el.setAttribute('animation-name', animName); el.setAttribute('autoplay', ''); }
else { el.removeAttribute('animation-name'); el.removeAttribute('autoplay'); }
}
};
</script>
@code {
private readonly List<CdnObjectRow> _items = new();
@@ -345,6 +381,10 @@
// 3D preview
private string? _previewUrl;
private List<string> _previewAnimations = new();
private string _selectedAnimation = "";
private DotNetObjectReference<CdnBrowser>? _dotNetRef;
private bool _animWatcherActive;
private string _activePrefixDisplay => string.IsNullOrEmpty(_activePrefix) ? "/" : $"/{_activePrefix}";
@@ -384,8 +424,45 @@
private void OpenPreview(string url)
{
_previewUrl = url;
_previewAnimations.Clear();
_selectedAnimation = "";
_animWatcherActive = false;
}
private void ClosePreview()
{
_previewUrl = null;
_previewAnimations.Clear();
_selectedAnimation = "";
_animWatcherActive = false;
}
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (_previewUrl is not null && !_animWatcherActive)
{
_animWatcherActive = true;
_dotNetRef ??= DotNetObjectReference.Create(this);
await Js.InvokeVoidAsync("sorCdn.initModelViewerAnimations", "mv-preview", _dotNetRef);
}
}
[JSInvokable]
public void OnAnimationsLoaded(string[] animations)
{
_previewAnimations = animations.ToList();
_selectedAnimation = "";
StateHasChanged();
}
private async Task OnAnimationSelected(ChangeEventArgs e)
{
_selectedAnimation = e.Value?.ToString() ?? "";
await Js.InvokeVoidAsync("sorCdn.setModelAnimation", "mv-preview", _selectedAnimation);
}
public void Dispose() => _dotNetRef?.Dispose();
protected override async Task OnInitializedAsync()
{
var options = CdnOptionsAccessor.Value;