Skip to content

fix(battle-scene): animate counterattack + auto-preload GLBs + click-to-reset#360

Merged
mokn merged 2 commits intodevfrom
feat/audio-zones
Apr 14, 2026
Merged

fix(battle-scene): animate counterattack + auto-preload GLBs + click-to-reset#360
mokn merged 2 commits intodevfrom
feat/audio-zones

Conversation

@mokn
Copy link
Copy Markdown
Collaborator

@mokn mokn commented Apr 14, 2026

Summary

  • Battle scene auto-discovers every GLB-backed monster from MONSTER_TEMPLATES_REDUX instead of a hardcoded preload list — fixes the "old spider refreshes" delay where giant-spider, hook-horror, and basilisk were lazy-loading mid-battle.
  • Monster counterattacks now actually animate: GLB creatures play the attack clip, ASCII-only creatures (Ooze, Carrion Crawler) run a new 3-phase computeAnimParams curve (windup +X → strike -X → recover) since monsters face LEFT.
  • Click-to-reset: a new player attack splices any in-flight same-side attacks out of the RAF queue so the player isn't visually queued behind stale animations.
  • playClip now restarts LoopOnce clips when called with the same action, so rapid consecutive attacks replay instead of silently no-op'ing.
  • glbItemLoader: fix Three.js warning from emissive: undefined at zero intensity.
  • Also picks up the zone-unlock hotfix (573a7ad1) via merge-forward.

Test plan

  • glbCreatureLoader.test.ts (5) — asGLBDrawFn duck-typing
  • BattleSceneCanvas.test.ts (6) — spliceSameSideAttacks backwards iteration, same-side splicing, counter-side leave-alone
  • MonsterAsciiRenderer.test.ts (8) — 3-phase attack curve, durationOverride, windup→strike boundary continuity
  • monsterTemplatesRedux.test.ts (+3) — every dynamic template exposes glbUrl (guards the silent-preload-skip bug class)
  • Typecheck clean on touched files
  • Manual beta smoke: spawn in dark cave, engage giant spider, confirm GLB renders immediately (no ASCII fallback flash), attack rapidly to verify click-to-reset, watch Ooze/Carrion Crawler counterattack for 3-phase ASCII lunge
  • Ranged/spell weapons — verify durationOverride honors WEAPON_SPEED instead of the 600 ms melee default

🤖 Generated with Claude Code

mokn and others added 2 commits April 14, 2026 06:22
…to-reset

Battle flow fixes from Cricket QA session:

- BattleSceneCanvas: replace hardcoded preload list (missing giant-spider,
  hook-horror, basilisk) with auto-discovery over MONSTER_TEMPLATES_REDUX
  via the new asGLBDrawFn narrower. Fixes the "old spider refreshes"
  delay where the procedural fallback was shown until the GLB lazily
  loaded mid-battle.
- triggerAttack: splice in-flight same-side attacks before pushing a new
  one (click-to-reset so the player isn't queued behind a stale RAF).
  Pushed out via spliceSameSideAttacks helper for unit testing.
- triggerAttack: monster counterattack now actually animates — looks up
  the monster template via templateRef, calls playClip('attack') for GLB
  creatures, or sets state.monsterAnim for ASCII-only (Ooze, Crawler).
  Cleanup block in RAF loop clears monsterAnim once the duration window
  elapses so the next attack starts from idle.
- MonsterAsciiRenderer: add 'attack' action to AnimAction with a 3-phase
  windup/strike/recover curve. Monsters face LEFT, so windup pulls to
  +X and strike lunges to -X. durationOverride support so ranged/spell
  attacks honor WEAPON_SPEED instead of the 600ms melee default.
- glbCreatureLoader: export GLBDrawFn type + asGLBDrawFn narrower.
  makeGLBDrawFn attaches glbUrl/glbGridW/glbGridH/glbYaw so the preload
  loop can discover GLBs without a hardcoded list. playClip now restarts
  LoopOnce clips when called with the same action (required so rapid
  consecutive attacks replay instead of silently no-op'ing).
- glbItemLoader: fix Three.js warning from `emissive: undefined` — pass
  a black Color when emissiveIntensity is 0.

Tests: +22 new tests across 4 files
- glbCreatureLoader.test.ts (5): asGLBDrawFn duck-typing
- BattleSceneCanvas.test.ts (6): spliceSameSideAttacks semantics
- MonsterAsciiRenderer.test.ts (8): 3-phase attack curve + boundaries
- monsterTemplatesRedux.test.ts (+3): glbUrl contract on every dynamic
  template (guards the "silent preload skip" class of bug)

All 71 tests pass across the 8 touched test files.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 14, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
blog Building Building Preview, Comment Apr 14, 2026 0:23am
ud Building Building Preview, Comment Apr 14, 2026 0:23am
ud-api Building Building Preview, Comment Apr 14, 2026 0:23am
ud-api-beta Building Building Preview, Comment Apr 14, 2026 0:23am

Request Review

@mokn mokn merged commit 40dfc80 into dev Apr 14, 2026
2 of 6 checks passed
@mokn mokn deleted the feat/audio-zones branch April 14, 2026 12:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant