@holtjs/stage 0.9.0 → 0.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +24 -0
- package/README.md +12 -11
- package/dist/{anims-ClNi6zZQ.d.ts → anims-D9N8w6IM.d.ts} +30 -4
- package/dist/anims.d.ts +1 -1
- package/dist/anims.js +103 -27
- package/dist/{display-C_NPwPrE.js → display-DU4edtH-.js} +273 -56
- package/dist/{game-DnJYRLZP.d.ts → game-B7w2sF5C.d.ts} +76 -14
- package/dist/{game-C-yXzyAX.js → game-CnGm5bly.js} +84 -7
- package/dist/headless.d.ts +1 -1
- package/dist/headless.js +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -2
- package/dist/joystick.d.ts +1 -1
- package/dist/kernel.d.ts +1 -1
- package/dist/lighting.d.ts +1 -1
- package/dist/lighting.js +1 -1
- package/dist/projection.d.ts +1 -1
- package/dist/projection.js +7 -1
- package/dist/renderer-webgpu.d.ts +1 -1
- package/dist/rig2d.d.ts +2 -2
- package/dist/tilemap.d.ts +1 -1
- package/dist/trace.d.ts +1 -1
- package/llms.txt +12 -11
- package/package.json +1 -1
- package/skills/stage/SKILL.md +9 -6
- package/skills/stage/references/subpaths.md +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,30 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [0.10.1] - 2026-12-04
|
|
10
|
+
|
|
11
|
+
### Added & Fixed
|
|
12
|
+
- **Multi-Atlas Collision Diagnostics & Namespace `prefix` (`AnimationManager.createFromAtlas` / `create`, `src/anims.ts`)**:
|
|
13
|
+
- `AnimationManager.createFromAtlas()` and `AnimationManager.create()` now emit a concise `console.warn` when overwriting an existing animation clip key from an earlier atlas (and refresh bare actor/group aliases in lockstep so `survivor/walk` never split-brains across textures).
|
|
14
|
+
- Added `{ prefix?: string, overwrite?: boolean }` to `AtlasAutoAnimOptions` (e.g. `createFromAtlas('npc_sheet', { prefix: 'npc' })`) and `{ overwrite?: boolean }` to `AnimationConfig`.
|
|
15
|
+
- **Occluded `bindEquipment` Transform Parity & `<=64x64` Empty-Placeholder Detection (`src/display.ts`, `src/texture.ts`)**:
|
|
16
|
+
- `SpriteObject.bindEquipment()` now synchronizes `x`, `y`, `flipX`, `flipY`, `scale`, `rotation`, `skew`, `alpha`, and `zIndex` even when the bound layer is hidden on an occluded/missing frame (`visible = false`), ensuring callers reading `toolImage.x/y` always see exact coordinates.
|
|
17
|
+
- Extended `TextureManager.addAtlas()` lazy transparent-placeholder probing from `<=4x4` up to `<=64x64` (`5x5`, `8x8`, `16x16`, `32x32`, `64x64` all-alpha-zero cells automatically set `Frame.empty = true`, memoized per rect).
|
|
18
|
+
|
|
19
|
+
## [0.10.0] - 2026-12-04
|
|
20
|
+
|
|
21
|
+
### Added
|
|
22
|
+
- **Lockstep 3D Z-Holdout Equipment Binding & Auto-Empty Placeholder Detection (`SpriteObject.bindEquipment`, `Frame.empty`, `src/display.ts`, `src/texture.ts`, `src/game.ts`, `src/projection.ts`)**:
|
|
23
|
+
- Added `SpriteObject.bindEquipment(target, prefix, opts?)` returning an `EquipmentBinding` handle (`setPrefix(nextPrefix)`, `sync()`, `destroy()`), paired directly with `@holtjs/craft/three` `baker.bakeEquipment()`.
|
|
24
|
+
- Automatically resolves `<prefix>/<clip>/d<dir>/f<frame>` (or non-directional `<prefix>/<clip>/f<frame>`) on every animation frame & direction turn, aligns ground-origin `ax/ay` pivots via `useFramePivot()`, locks `x/y`, `flipX/flipY`, `scale`, `rotation`, `skew`, and `zIndex + zOffset` in both `stepSimOnly` (post-`update`) and `step` (pre-render, eliminating any 1-frame lag after `hero.x += ...` movement!), and hides occluded or missing frames (`0` wasted GPU/Canvas2D draw calls or stray `mountStage25D` shadow quads).
|
|
25
|
+
- `TextureManager.addAtlas()` now populates `Frame.empty` automatically across `1x1` Craft holdout cells, `<=4x4` all-transparent placeholder frames (e.g. `2x2` transparent cells preserving directional frame counts), and explicit `empty: true` entries.
|
|
26
|
+
- **2x2 Projected Basis Sockets & 6-DOF Affine `syncAttachment` with Per-Clip `clipAngles` (`src/texture.ts`, `src/display.ts`)**:
|
|
27
|
+
- Extended `FrameAnchorTuple` & `ImageObject.getAnchorPose()` to support 8-tuple sockets `[x, y, angleRad, zBias, ux, uy, vx, vy]` (from `@holtjs/craft/three` `charKit.handBasisSocket`), transforming both shaft `(ux, uy)` and blade `(vx, vy)` vectors through `flip -> scale -> rotate/skew -> parentContainer`.
|
|
28
|
+
- Upgraded `ImageObject.syncAttachment(child, anchorName, opts?)` with exact closed-form 2x2 polar decomposition into `(scaleX, scaleY, rotation, skewY)` (including reflected `det < 0` chirality), simultaneously solving perspective shaft foreshortening (`||u|| < 1`), `45°/30°` non-orthogonal isometric blade shear (`u · v != 0`), and per-clip 3D grip-plane wrist angles (`clipAngles: { walk: 0.66, thrust: 0 }`).
|
|
29
|
+
- **`playDirectional` `startFrame` Forwarding & `createFromAtlas` Cross-Actor Rule Inheritance (`src/display.ts`, `src/anims.ts`)**:
|
|
30
|
+
- Added `startFrame?: number` to `DirectionalPlayOptions` (`SpriteObject.playDirectional`), forwarding directly to `play()` (and restarting cleanly even when already playing the same direction).
|
|
31
|
+
- Added `inheritFrom?: Readonly<Record<string, string>>` (supporting exact keys and prefix globs such as `{ 'held/*': 'survivor' }`) plus automatic `Frame.baseActor` (`baseChar` from `@holtjs/craft/three` `bakeEquipment`) inheritance in `AnimationManager.createFromAtlas()` so secondary equipment/overlay actors inherit `frameRate`, `duration`, `repeat`, `yoyo`, and `events` without duplicating clip rules.
|
|
32
|
+
|
|
9
33
|
## [0.9.0] - 2026-12-04
|
|
10
34
|
|
|
11
35
|
### Added
|
package/README.md
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
[](https://www.npmjs.com/package/@holtjs/stage)
|
|
4
4
|
[](LICENSE)
|
|
5
5
|
[](package.json)
|
|
6
|
-
[](scripts/size.mjs)
|
|
7
7
|
|
|
8
|
-
A zero-dependency, tracing-first **WebGPU / WebGL2 / Canvas2D** 2D & 2.5D game, UI, and 60 FPS programmable video engine written in strict TypeScript — covering GPU SDF panels, `StageKernel` plugins & unified `InputTimeline` automation, Flex/Wrap layout, damped springs, `SurfaceTree` barriers, zero-GC SoA ECS, FlowField/A* navigation, procedural foley audio, 2D cutout skeletal rigs, Dual-Grid chunked tilemaps, rotatable 2.5D camera projection, 2D normal-map lighting, and world delta saves.
|
|
8
|
+
A zero-dependency, tracing-first **WebGPU / WebGL2 / Canvas2D** 2D & 2.5D game, UI, and 60 FPS programmable video engine written in strict TypeScript — covering GPU SDF panels & shapes, 4/8-directional `SpriteObject` & `AnimationManager` (`bindEquipment` 3D Z-holdout layering + 6-DOF affine `syncAttachment`), `StageKernel` plugins & unified `InputTimeline` automation, Flex/Wrap layout, damped springs, `SurfaceTree` barriers, zero-GC SoA ECS, FlowField/A* navigation, procedural foley audio, 2D cutout skeletal rigs, Dual-Grid chunked tilemaps, rotatable 2.5D camera projection + oblique sun shadows, 2D normal-map & emissive lighting, and world delta saves.
|
|
9
9
|
|
|
10
10
|
- **Official Docs & Playground**: https://holt.js.org
|
|
11
11
|
- **npm**: https://www.npmjs.com/package/@holtjs/stage
|
|
@@ -16,7 +16,7 @@ A zero-dependency, tracing-first **WebGPU / WebGL2 / Canvas2D** 2D & 2.5D game,
|
|
|
16
16
|
|
|
17
17
|
## Highlights
|
|
18
18
|
|
|
19
|
-
- **Zero runtime dependencies &
|
|
19
|
+
- **Zero runtime dependencies & 21 tree-shakeable subpaths**: Pure ESM TypeScript (`sideEffects: false`); individual subpaths range from **1.1 kB to 15.9 kB gzipped**.
|
|
20
20
|
- **WebGPU + WebGL2 + Isomorphic Canvas2D + Node 60 FPS Headless**:
|
|
21
21
|
- **Native WebGPU (`@holtjs/stage/webgpu`)**: Zero-dependency `RendererWebGpu` + `requestWebGpuDevice()` with WGSL quad/polygon batching and WGSL analytical rounded/stepped-pixel SDF `PanelObject` pipelines across `NORMAL`, `ADD`, `MULTIPLY`, and `SCREEN` blends.
|
|
22
22
|
- **WebGL2 Primary (`RendererGl`)**: 1-sampler zero-branch shader + 8-unit multi-texture uber-batcher, `InstancedBatchObject` (`drawElementsInstanced`), offscreen `StageRenderTarget` FBOs, GPU SDF panels, Sharp-Bilinear Pixel-AA, MTSDF vector icons, and state-isolated `CustomPassObject`.
|
|
@@ -39,18 +39,19 @@ A zero-dependency, tracing-first **WebGPU / WebGL2 / Canvas2D** 2D & 2.5D game,
|
|
|
39
39
|
pnpm add @holtjs/stage
|
|
40
40
|
```
|
|
41
41
|
|
|
42
|
-
##
|
|
42
|
+
## 21 Subpath Exports
|
|
43
43
|
|
|
44
44
|
| Import Path | Gzip | Description | DOM Required? |
|
|
45
45
|
|---|---|---|---|
|
|
46
|
-
| `@holtjs/stage` | `
|
|
47
|
-
| `@holtjs/stage/
|
|
48
|
-
| `@holtjs/stage/
|
|
49
|
-
| `@holtjs/stage/
|
|
46
|
+
| `@holtjs/stage` | `71.3 kB` | Full engine barrel (`Stage`, `Game`, `Scene`, `SpriteObject` + `bindEquipment` + 6-DOF `syncAttachment`, `AnimationManager`, renderers, `ShapeBatch`, `InstancedBatch`, `Panel`, `StageKernel`, layout, tweens, tracing, surfaces) | Browser (`Game`/renderers) |
|
|
47
|
+
| `@holtjs/stage/anims` | `2.9 kB` | 4/8-directional & sprite-sheet `AnimationManager` (`createFromAtlas` with `inheritFrom` + `baseChar`, bare aliases, phase-preserving `playDirectional`) | No |
|
|
48
|
+
| `@holtjs/stage/webgpu` | `15.9 kB` | Native WebGPU WGSL batch & analytical SDF `PanelObject` / `ShapeBatch` renderer (`RendererWebGpu`, `requestWebGpuDevice`) | Browser WebGPU |
|
|
49
|
+
| `@holtjs/stage/kernel` | `4.9 kB` | `StageKernel`, `StagePlugin`, `ActionMap`, `createInputTimeline` (`trackId` clicks + cursor), recorder/replay | No |
|
|
50
|
+
| `@holtjs/stage/headless` | `50.4 kB` | Zero-browser 60 FPS `createHeadlessStage`, `fastForward`, `toRgbaInto`, `renderStoryboard`, `createAudioTimeline` WAV mixer | No (`@napi-rs/canvas`) |
|
|
50
51
|
| `@holtjs/stage/rig2d` | `5.7 kB` | 2D cutout skeletal rig (`defineRig2DSkeleton`, `Rig2DInstance`, `mountRig2D`, `bakeCutoutAtlas`), O(1) slot swap & 2-layer mixer | No |
|
|
51
|
-
| `@holtjs/stage/tilemap` | `
|
|
52
|
-
| `@holtjs/stage/projection` | `
|
|
53
|
-
| `@holtjs/stage/lighting` | `
|
|
52
|
+
| `@holtjs/stage/tilemap` | `4.0 kB` | Sparse `ChunkedTilemap`, 16-tile Dual-Grid & 47-tile Blob autotilers, biome generator, chunk-cached `mountChunkedTilemap` | No |
|
|
53
|
+
| `@holtjs/stage/projection` | `2.8 kB` | Rotatable 2.5D `Camera25D` (`worldToScreen` ↔ `screenToGround`) + `mountStage25D` upright cylindrical billboards & oblique sun shadows | No |
|
|
54
|
+
| `@holtjs/stage/lighting` | `9.2 kB` | `DayNightCycle`, 3×3 Sobel normal-map baker, `Lighting2DSystem` (smooth radial glow + `bindEmissive`), batched `createSceneNormalLitPass` | No |
|
|
54
55
|
| `@holtjs/stage/world` | `2.8 kB` | `ItemRegistry`, `InventoryContainer` (spoilage), `RecipeRegistry`, `WorkstationScheduler`, `HWLD` binary `WorldDeltaSave` | No |
|
|
55
56
|
| `@holtjs/stage/flex` | `2.3 kB` | Pure 1D Flex & Wrap layout solvers (`computeFlexLayout`, `computeWrapLayout`, `resolvePadding`) | No |
|
|
56
57
|
| `@holtjs/stage/tween` | `1.4 kB` | Deterministic `TweenManager`, `Easings`, and damped springs | No |
|
|
@@ -98,8 +98,13 @@ interface SpriteSheetConfig {
|
|
|
98
98
|
margin?: number;
|
|
99
99
|
spacing?: number;
|
|
100
100
|
}
|
|
101
|
-
/**
|
|
102
|
-
|
|
101
|
+
/**
|
|
102
|
+
* Frame-space socket tuple:
|
|
103
|
+
* - `[x, y]` point
|
|
104
|
+
* - `[x, y, angleRad, zBias]` oriented shaft (`zBias = +1` front, `-1` behind)
|
|
105
|
+
* - `[x, y, angleRad, zBias, ux, uy, vx, vy]` full 2x2 projected 3D->2D basis (`u` = foreshortened shaft, `v` = sheared blade axis)
|
|
106
|
+
*/
|
|
107
|
+
type FrameAnchorTuple = readonly [number, number] | readonly [number, number, number, number] | readonly [number, number, number, number, number, number, number, number];
|
|
103
108
|
interface FrameExtraMeta {
|
|
104
109
|
/** Exact pixel pivot X from trimmed frame top-left `(0, 0)` (takes precedence over `pivotX` to avoid float drift). */
|
|
105
110
|
ax?: number;
|
|
@@ -118,6 +123,9 @@ interface FrameExtraMeta {
|
|
|
118
123
|
/** Optional character/actor identifier from offline baker metadata (e.g. `'chars/survivor'` or `'survivor'`). */
|
|
119
124
|
char?: string;
|
|
120
125
|
actor?: string;
|
|
126
|
+
/** Optional parent/base character identifier (`@holtjs/craft/three` `bakeEquipment` sets `baseChar` so `createFromAtlas` inherits clip rules!). */
|
|
127
|
+
baseChar?: string;
|
|
128
|
+
baseActor?: string;
|
|
121
129
|
/** Optional animation clip name from offline baker metadata (e.g. `'walk'`, `'idle'`, `'attack'`). */
|
|
122
130
|
clip?: string;
|
|
123
131
|
/** Optional discrete direction index (`0 .. dirs - 1`) or label (`'down'`, `'right'`, ...). */
|
|
@@ -128,6 +136,8 @@ interface FrameExtraMeta {
|
|
|
128
136
|
frames?: number;
|
|
129
137
|
/** Optional loop hint from offline baker (`true` for locomotion/idle, `false` for one-shot actions). */
|
|
130
138
|
loop?: boolean;
|
|
139
|
+
/** True when this frame is an all-transparent occlusion placeholder (`1x1` cell, `2x2` transparent placeholder, or explicit `empty: true`). */
|
|
140
|
+
empty?: boolean;
|
|
131
141
|
}
|
|
132
142
|
interface AtlasJsonLike {
|
|
133
143
|
readonly yaw?: number;
|
|
@@ -207,18 +217,21 @@ declare class Frame {
|
|
|
207
217
|
emissiveCenter: readonly [number, number] | null;
|
|
208
218
|
emissivePower: number;
|
|
209
219
|
actor: string | null;
|
|
220
|
+
baseActor: string | null;
|
|
210
221
|
clip: string | null;
|
|
211
222
|
dir: number | string | null;
|
|
212
223
|
animFrameIndex: number | null;
|
|
213
224
|
animLoop: boolean | undefined;
|
|
225
|
+
/** True when the frame contains zero visible pixels (`1x1` cell, `<=4x4` all-transparent placeholder, or explicit `empty: true`). */
|
|
226
|
+
empty: boolean;
|
|
214
227
|
constructor(texture: Texture, name: string | number, sourceIndex: number, x: number, y: number, w: number, h: number, meta?: FrameExtraMeta);
|
|
215
228
|
setSize(width: number, height: number, x?: number, y?: number): this;
|
|
216
229
|
/** Set normalized `[0..1]` per-frame pivot (marks `customPivot = true`). */
|
|
217
230
|
setPivot(pivotX: number, pivotY: number): this;
|
|
218
231
|
/** Set exact pixel pivot `(ax, ay)` from trimmed frame top-left `(0, 0)` (avoids float rounding drift). */
|
|
219
232
|
setPixelPivot(ax: number, ay: number): this;
|
|
220
|
-
/** Attach or update a named pixel socket `(x, y)` (with optional
|
|
221
|
-
setAnchor(name: string, x: number, y: number, angleRad?: number, zBias?: number): this;
|
|
233
|
+
/** Attach or update a named pixel socket `(x, y)` (with optional `angleRad`, `zBias`, and 2x2 projected basis `[ux, uy, vx, vy]`). */
|
|
234
|
+
setAnchor(name: string, x: number, y: number, angleRad?: number, zBias?: number, ux?: number, uy?: number, vx?: number, vy?: number): this;
|
|
222
235
|
/** Read a named pixel socket `[x, y]` or `[x, y, angleRad, zBias]` (falls back to `emissiveCenter` when `name === 'emissive'`). */
|
|
223
236
|
getAnchor(name: string): FrameAnchorTuple | null;
|
|
224
237
|
applyMeta(meta: FrameExtraMeta): this;
|
|
@@ -304,6 +317,8 @@ interface AnimationConfig {
|
|
|
304
317
|
readonly yoyo?: boolean;
|
|
305
318
|
/** Declarative map from 0-based frame index to event name(s), e.g. `{ 1: 'footstep', 4: 'footstep' }`. */
|
|
306
319
|
readonly events?: Readonly<Record<number, string | readonly string[]>>;
|
|
320
|
+
/** Silence duplicate-key overwrite warning when intentionally replacing an existing animation (`default = false`). */
|
|
321
|
+
readonly overwrite?: boolean;
|
|
307
322
|
}
|
|
308
323
|
interface StageAnimation {
|
|
309
324
|
readonly key: string;
|
|
@@ -343,6 +358,16 @@ interface AtlasAutoAnimOptions {
|
|
|
343
358
|
readonly defaultRepeat?: number;
|
|
344
359
|
/** Per-clip or per-`actor/clip` overrides, e.g. `{ walk: { frameRate: 10, events: { 1: 'footstep', 4: 'footstep' } } }`. */
|
|
345
360
|
readonly clips?: Readonly<Record<string, AtlasClipRule>>;
|
|
361
|
+
/**
|
|
362
|
+
* Inherit clip rules (`frameRate`, `duration`, `repeat`, `yoyo`, `events`) across secondary/equipment actors.
|
|
363
|
+
* Supports exact actor keys (`{ 'held/axe': 'survivor' }`) and prefix globs (`{ 'held/*': 'survivor', 'equip/*': 'chars/survivor' }`).
|
|
364
|
+
* Frames baked via `@holtjs/craft/three` `bakeEquipment` also inherit automatically via frame `baseChar` metadata!
|
|
365
|
+
*/
|
|
366
|
+
readonly inheritFrom?: Readonly<Record<string, string>>;
|
|
367
|
+
/** Optional namespace prefix prepended to generated clip & directional group keys (e.g. `'npc'` -> `'npc/chars/survivor/walk/d0'`) when loading multiple atlases with overlapping actor/clip names. */
|
|
368
|
+
readonly prefix?: string;
|
|
369
|
+
/** Silence duplicate-key overwrite warning when intentionally replacing animations from an earlier `createFromAtlas` call (`default = false`). */
|
|
370
|
+
readonly overwrite?: boolean;
|
|
346
371
|
}
|
|
347
372
|
interface DirectionalAnimGroup {
|
|
348
373
|
readonly baseKey: string;
|
|
@@ -371,6 +396,7 @@ declare class AnimationManager {
|
|
|
371
396
|
listKeys(): string[];
|
|
372
397
|
listDirectionalGroups(): string[];
|
|
373
398
|
create(config: AnimationConfig): StageAnimation;
|
|
399
|
+
private _createInternal;
|
|
374
400
|
/** Register an alias key pointing to an existing `StageAnimation` (does not overwrite explicit primary keys). */
|
|
375
401
|
registerAlias(aliasKey: string, target: StageAnimation): void;
|
|
376
402
|
/** Register a directional animation group (and optional alias keys such as bare `'survivor/walk'` & `'survivor_walk'`). */
|
package/dist/anims.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as AtlasClipRule, c as GenerateFrameNamesConfig, i as AtlasAutoAnimOptions, l as GenerateFrameNumbersConfig, n as AnimationFrameInput, o as CompiledAnimationFrame, r as AnimationManager, s as DirectionalAnimGroup, t as AnimationConfig, u as StageAnimation } from "./anims-
|
|
1
|
+
import { a as AtlasClipRule, c as GenerateFrameNamesConfig, i as AtlasAutoAnimOptions, l as GenerateFrameNumbersConfig, n as AnimationFrameInput, o as CompiledAnimationFrame, r as AnimationManager, s as DirectionalAnimGroup, t as AnimationConfig, u as StageAnimation } from "./anims-D9N8w6IM.js";
|
|
2
2
|
export { AnimationConfig, AnimationFrameInput, AnimationManager, AtlasAutoAnimOptions, AtlasClipRule, CompiledAnimationFrame, DirectionalAnimGroup, GenerateFrameNamesConfig, GenerateFrameNumbersConfig, StageAnimation };
|
package/dist/anims.js
CHANGED
|
@@ -74,12 +74,30 @@ function actorBasename(actor) {
|
|
|
74
74
|
const slash = actor.lastIndexOf("/");
|
|
75
75
|
return slash >= 0 ? actor.slice(slash + 1) : actor;
|
|
76
76
|
}
|
|
77
|
+
function matchInheritActor(actor, inheritFrom) {
|
|
78
|
+
if (!actor || !inheritFrom) return null;
|
|
79
|
+
if (Object.prototype.hasOwnProperty.call(inheritFrom, actor)) return inheritFrom[actor];
|
|
80
|
+
const bare = actorBasename(actor);
|
|
81
|
+
if (bare !== actor && Object.prototype.hasOwnProperty.call(inheritFrom, bare)) return inheritFrom[bare];
|
|
82
|
+
let bestTarget = null;
|
|
83
|
+
let bestLen = -1;
|
|
84
|
+
for (const [pattern, target] of Object.entries(inheritFrom)) {
|
|
85
|
+
if (!pattern.endsWith("*")) continue;
|
|
86
|
+
const prefix = pattern.slice(0, -1);
|
|
87
|
+
if (actor.startsWith(prefix) && prefix.length > bestLen) {
|
|
88
|
+
bestLen = prefix.length;
|
|
89
|
+
bestTarget = target;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return bestTarget;
|
|
93
|
+
}
|
|
77
94
|
function parseFrameConvention(frame) {
|
|
78
95
|
const name = String(frame.name);
|
|
79
96
|
if (name === "__BASE") return null;
|
|
80
97
|
if (frame.clip && frame.animFrameIndex !== null) return {
|
|
81
98
|
frameName: name,
|
|
82
99
|
actor: frame.actor ?? "",
|
|
100
|
+
baseActor: frame.baseActor,
|
|
83
101
|
clip: frame.clip,
|
|
84
102
|
dir: frame.dir,
|
|
85
103
|
frameIdx: frame.animFrameIndex,
|
|
@@ -92,6 +110,7 @@ function parseFrameConvention(frame) {
|
|
|
92
110
|
return {
|
|
93
111
|
frameName: name,
|
|
94
112
|
actor: slashDir[1],
|
|
113
|
+
baseActor: frame.baseActor,
|
|
95
114
|
clip: slashDir[2],
|
|
96
115
|
dir,
|
|
97
116
|
frameIdx: Number(slashDir[4])
|
|
@@ -101,6 +120,7 @@ function parseFrameConvention(frame) {
|
|
|
101
120
|
if (slashFlat) return {
|
|
102
121
|
frameName: name,
|
|
103
122
|
actor: slashFlat[1],
|
|
123
|
+
baseActor: frame.baseActor,
|
|
104
124
|
clip: slashFlat[2],
|
|
105
125
|
dir: null,
|
|
106
126
|
frameIdx: Number(slashFlat[3])
|
|
@@ -112,6 +132,7 @@ function parseFrameConvention(frame) {
|
|
|
112
132
|
return {
|
|
113
133
|
frameName: name,
|
|
114
134
|
actor: underDir[1],
|
|
135
|
+
baseActor: frame.baseActor,
|
|
115
136
|
clip: underDir[2],
|
|
116
137
|
dir,
|
|
117
138
|
frameIdx: Number(underDir[4])
|
|
@@ -121,6 +142,7 @@ function parseFrameConvention(frame) {
|
|
|
121
142
|
if (underTwo) return {
|
|
122
143
|
frameName: name,
|
|
123
144
|
actor: underTwo[1],
|
|
145
|
+
baseActor: frame.baseActor,
|
|
124
146
|
clip: underTwo[2],
|
|
125
147
|
dir: null,
|
|
126
148
|
frameIdx: Number(underTwo[3])
|
|
@@ -129,6 +151,7 @@ function parseFrameConvention(frame) {
|
|
|
129
151
|
if (underOne) return {
|
|
130
152
|
frameName: name,
|
|
131
153
|
actor: "",
|
|
154
|
+
baseActor: frame.baseActor,
|
|
132
155
|
clip: underOne[1],
|
|
133
156
|
dir: null,
|
|
134
157
|
frameIdx: Number(underOne[2])
|
|
@@ -180,7 +203,15 @@ var AnimationManager = class {
|
|
|
180
203
|
return out;
|
|
181
204
|
}
|
|
182
205
|
create(config) {
|
|
206
|
+
return this._createInternal(config, false);
|
|
207
|
+
}
|
|
208
|
+
_createInternal(config, suppressCollisionWarn) {
|
|
183
209
|
if (!config.frames || config.frames.length === 0) throw new Error(`Stage anims.create("${config.key}"): frames array must not be empty`);
|
|
210
|
+
if (!suppressCollisionWarn && !config.overwrite && this.anims.has(config.key)) {
|
|
211
|
+
const prevTex = this.anims.get(config.key).frames[0]?.textureKey ?? "unknown";
|
|
212
|
+
const nextTex = config.frames[0]?.key ?? config.defaultTextureKey ?? "unknown";
|
|
213
|
+
console.warn(`Stage anims.create("${config.key}"): overwriting existing clip from texture "${prevTex}" with "${nextTex}" (pass { overwrite: true } to silence)`);
|
|
214
|
+
}
|
|
184
215
|
const count = config.frames.length;
|
|
185
216
|
const frameRate = config.frameRate !== void 0 && config.frameRate > 0 ? config.frameRate : config.duration !== void 0 && config.duration > 0 ? count * 1e3 / config.duration : 10;
|
|
186
217
|
const baseMsPerFrame = 1e3 / frameRate;
|
|
@@ -220,8 +251,12 @@ var AnimationManager = class {
|
|
|
220
251
|
}
|
|
221
252
|
/** Register a directional animation group (and optional alias keys such as bare `'survivor/walk'` & `'survivor_walk'`). */
|
|
222
253
|
registerDirectionalGroup(group, aliases = []) {
|
|
254
|
+
const prevGroup = this.dirGroups.get(group.baseKey);
|
|
223
255
|
this.dirGroups.set(group.baseKey, group);
|
|
224
|
-
for (const a of aliases)
|
|
256
|
+
for (const a of aliases) {
|
|
257
|
+
const existing = this.dirGroups.get(a);
|
|
258
|
+
if (!existing || existing === prevGroup) this.dirGroups.set(a, group);
|
|
259
|
+
}
|
|
225
260
|
}
|
|
226
261
|
remove(key) {
|
|
227
262
|
this.aliases.delete(key);
|
|
@@ -302,9 +337,26 @@ var AnimationManager = class {
|
|
|
302
337
|
}
|
|
303
338
|
set.add(p.actor);
|
|
304
339
|
}
|
|
305
|
-
const
|
|
306
|
-
|
|
307
|
-
|
|
340
|
+
const lookupActorRule = (act, clip) => {
|
|
341
|
+
if (!act) return void 0;
|
|
342
|
+
const bare = actorBasename(act);
|
|
343
|
+
const direct = rules[`${act}/${clip}`] ?? rules[`${act}_${clip}`] ?? (bare && bare !== act ? rules[`${bare}/${clip}`] ?? rules[`${bare}_${clip}`] : void 0);
|
|
344
|
+
if (direct) return direct;
|
|
345
|
+
const fullSet = actorsByBase.get(bare);
|
|
346
|
+
if (fullSet && fullSet.size === 1) {
|
|
347
|
+
const fullAct = Array.from(fullSet)[0];
|
|
348
|
+
if (fullAct !== act) return rules[`${fullAct}/${clip}`] ?? rules[`${fullAct}_${clip}`];
|
|
349
|
+
}
|
|
350
|
+
};
|
|
351
|
+
const resolveRule = (actor, clip, baseActorHint) => {
|
|
352
|
+
const own = lookupActorRule(actor, clip);
|
|
353
|
+
if (own) return own;
|
|
354
|
+
const parentActor = matchInheritActor(actor, options.inheritFrom) ?? baseActorHint;
|
|
355
|
+
if (parentActor && parentActor !== actor) {
|
|
356
|
+
const inherited = lookupActorRule(parentActor, clip);
|
|
357
|
+
if (inherited) return inherited;
|
|
358
|
+
}
|
|
359
|
+
return rules[clip];
|
|
308
360
|
};
|
|
309
361
|
const buckets = /* @__PURE__ */ new Map();
|
|
310
362
|
for (const p of parsed) {
|
|
@@ -313,12 +365,16 @@ var AnimationManager = class {
|
|
|
313
365
|
if (!b) {
|
|
314
366
|
b = {
|
|
315
367
|
actor: p.actor,
|
|
368
|
+
baseActor: p.baseActor,
|
|
316
369
|
clip: p.clip,
|
|
317
370
|
byDir: /* @__PURE__ */ new Map(),
|
|
318
371
|
loopHint: p.loop
|
|
319
372
|
};
|
|
320
373
|
buckets.set(bKey, b);
|
|
321
|
-
} else
|
|
374
|
+
} else {
|
|
375
|
+
if (b.loopHint === void 0 && p.loop !== void 0) b.loopHint = p.loop;
|
|
376
|
+
if (b.baseActor === null && p.baseActor !== null) b.baseActor = p.baseActor;
|
|
377
|
+
}
|
|
322
378
|
let arr = b.byDir.get(p.dir);
|
|
323
379
|
if (!arr) {
|
|
324
380
|
arr = [];
|
|
@@ -328,17 +384,32 @@ var AnimationManager = class {
|
|
|
328
384
|
}
|
|
329
385
|
const created = [];
|
|
330
386
|
const atlasYaw = tex.atlasYaw ?? 0;
|
|
387
|
+
const nsPrefix = options.prefix ? options.prefix.replace(/\/+$/, "") : "";
|
|
388
|
+
const withNs = (k) => nsPrefix ? `${nsPrefix}/${k}` : k;
|
|
389
|
+
const overwrittenKeys = [];
|
|
390
|
+
let overwrittenFromTex = null;
|
|
391
|
+
const createClip = (cfg) => {
|
|
392
|
+
const existing = this.anims.get(cfg.key);
|
|
393
|
+
if (existing && !options.overwrite) {
|
|
394
|
+
overwrittenKeys.push(cfg.key);
|
|
395
|
+
if (!overwrittenFromTex) overwrittenFromTex = existing.frames[0]?.textureKey ?? "unknown";
|
|
396
|
+
}
|
|
397
|
+
const anim = this._createInternal(cfg, true);
|
|
398
|
+
if (existing) {
|
|
399
|
+
for (const [ak, target] of this.aliases.entries()) if (target === existing) this.aliases.set(ak, anim);
|
|
400
|
+
}
|
|
401
|
+
return anim;
|
|
402
|
+
};
|
|
331
403
|
for (const b of buckets.values()) {
|
|
332
|
-
const rule = resolveRule(b.actor, b.clip);
|
|
404
|
+
const rule = resolveRule(b.actor, b.clip, b.baseActor);
|
|
333
405
|
const repeat = rule?.repeat !== void 0 ? rule.repeat : options.defaultRepeat !== void 0 ? options.defaultRepeat : b.loopHint !== void 0 ? b.loopHint ? -1 : 0 : LOOP_CLIP_RE.test(b.clip) ? -1 : 0;
|
|
334
406
|
const fps = rule?.frameRate ?? defaultFps;
|
|
335
407
|
const bare = b.actor ? actorBasename(b.actor) : "";
|
|
336
408
|
const canBareAlias = Boolean(bare && bare !== b.actor && (actorsByBase.get(bare)?.size ?? 0) === 1);
|
|
337
409
|
if (b.byDir.size === 1 && b.byDir.has(null)) {
|
|
338
410
|
const seq = b.byDir.get(null).sort((a, c) => a.frameIdx - c.frameIdx);
|
|
339
|
-
const
|
|
340
|
-
|
|
341
|
-
key: primaryKey,
|
|
411
|
+
const anim = createClip({
|
|
412
|
+
key: withNs(b.actor ? `${b.actor}/${b.clip}` : b.clip),
|
|
342
413
|
defaultTextureKey: textureKey,
|
|
343
414
|
frames: seq.map((s) => ({
|
|
344
415
|
key: textureKey,
|
|
@@ -348,13 +419,14 @@ var AnimationManager = class {
|
|
|
348
419
|
duration: rule?.duration,
|
|
349
420
|
repeat,
|
|
350
421
|
yoyo: rule?.yoyo,
|
|
351
|
-
events: rule?.events
|
|
422
|
+
events: rule?.events,
|
|
423
|
+
overwrite: options.overwrite
|
|
352
424
|
});
|
|
353
425
|
created.push(anim);
|
|
354
|
-
if (b.actor) this.registerAlias(`${b.actor}_${b.clip}
|
|
426
|
+
if (b.actor) this.registerAlias(withNs(`${b.actor}_${b.clip}`), anim);
|
|
355
427
|
if (canBareAlias) {
|
|
356
|
-
this.registerAlias(`${bare}/${b.clip}
|
|
357
|
-
this.registerAlias(`${bare}_${b.clip}
|
|
428
|
+
this.registerAlias(withNs(`${bare}/${b.clip}`), anim);
|
|
429
|
+
this.registerAlias(withNs(`${bare}_${b.clip}`), anim);
|
|
358
430
|
}
|
|
359
431
|
continue;
|
|
360
432
|
}
|
|
@@ -378,11 +450,10 @@ var AnimationManager = class {
|
|
|
378
450
|
indexedDirs.sort((a, c) => a.dirIdx - c.dirIdx);
|
|
379
451
|
const dirClips = [];
|
|
380
452
|
for (const item of indexedDirs) {
|
|
381
|
-
const prefixSlash = b.actor ? `${b.actor}/${b.clip}` : b.clip;
|
|
382
|
-
const prefixUnder = b.actor ? `${b.actor}_${b.clip}` : b.clip;
|
|
383
|
-
const
|
|
384
|
-
|
|
385
|
-
key: primaryKey,
|
|
453
|
+
const prefixSlash = withNs(b.actor ? `${b.actor}/${b.clip}` : b.clip);
|
|
454
|
+
const prefixUnder = withNs(b.actor ? `${b.actor}_${b.clip}` : b.clip);
|
|
455
|
+
const anim = createClip({
|
|
456
|
+
key: `${prefixSlash}/d${item.dirIdx}`,
|
|
386
457
|
defaultTextureKey: textureKey,
|
|
387
458
|
frames: item.frames.map((s) => ({
|
|
388
459
|
key: textureKey,
|
|
@@ -392,7 +463,8 @@ var AnimationManager = class {
|
|
|
392
463
|
duration: rule?.duration,
|
|
393
464
|
repeat,
|
|
394
465
|
yoyo: rule?.yoyo,
|
|
395
|
-
events: rule?.events
|
|
466
|
+
events: rule?.events,
|
|
467
|
+
overwrite: options.overwrite
|
|
396
468
|
});
|
|
397
469
|
created.push(anim);
|
|
398
470
|
dirClips.push(anim);
|
|
@@ -403,21 +475,21 @@ var AnimationManager = class {
|
|
|
403
475
|
this.registerAlias(`${prefixUnder}_${item.label}`, anim);
|
|
404
476
|
}
|
|
405
477
|
if (canBareAlias) {
|
|
406
|
-
this.registerAlias(`${bare}/${b.clip}/d${item.dirIdx}
|
|
407
|
-
this.registerAlias(`${bare}/${b.clip}/${item.dirIdx}
|
|
408
|
-
this.registerAlias(`${bare}_${b.clip}_${item.dirIdx}
|
|
478
|
+
this.registerAlias(withNs(`${bare}/${b.clip}/d${item.dirIdx}`), anim);
|
|
479
|
+
this.registerAlias(withNs(`${bare}/${b.clip}/${item.dirIdx}`), anim);
|
|
480
|
+
this.registerAlias(withNs(`${bare}_${b.clip}_${item.dirIdx}`), anim);
|
|
409
481
|
}
|
|
410
482
|
}
|
|
411
483
|
if (dirClips.length > 0) {
|
|
412
|
-
const baseSlash = b.actor ? `${b.actor}/${b.clip}` : b.clip;
|
|
413
|
-
const baseUnder = b.actor ? `${b.actor}_${b.clip}` : b.clip;
|
|
484
|
+
const baseSlash = withNs(b.actor ? `${b.actor}/${b.clip}` : b.clip);
|
|
485
|
+
const baseUnder = withNs(b.actor ? `${b.actor}_${b.clip}` : b.clip);
|
|
414
486
|
const aliases = [baseUnder];
|
|
415
|
-
if (canBareAlias) aliases.push(`${bare}/${b.clip}
|
|
487
|
+
if (canBareAlias) aliases.push(withNs(`${bare}/${b.clip}`), withNs(`${bare}_${b.clip}`));
|
|
416
488
|
this.registerAlias(baseSlash, dirClips[0]);
|
|
417
489
|
this.registerAlias(baseUnder, dirClips[0]);
|
|
418
490
|
if (canBareAlias) {
|
|
419
|
-
this.registerAlias(`${bare}/${b.clip}
|
|
420
|
-
this.registerAlias(`${bare}_${b.clip}
|
|
491
|
+
this.registerAlias(withNs(`${bare}/${b.clip}`), dirClips[0]);
|
|
492
|
+
this.registerAlias(withNs(`${bare}_${b.clip}`), dirClips[0]);
|
|
421
493
|
}
|
|
422
494
|
this.registerDirectionalGroup({
|
|
423
495
|
baseKey: baseSlash,
|
|
@@ -430,6 +502,10 @@ var AnimationManager = class {
|
|
|
430
502
|
}, aliases);
|
|
431
503
|
}
|
|
432
504
|
}
|
|
505
|
+
if (overwrittenKeys.length > 0 && !options.overwrite) {
|
|
506
|
+
const sample = overwrittenKeys.slice(0, 3).join(", ");
|
|
507
|
+
console.warn(`Stage anims.createFromAtlas("${textureKey}"): overwrote ${overwrittenKeys.length} existing animation key(s) from "${overwrittenFromTex ?? "unknown"}" (${sample}${overwrittenKeys.length > 3 ? ", ..." : ""}); pass { prefix } to namespace or { overwrite: true } to silence.`);
|
|
508
|
+
}
|
|
433
509
|
return created;
|
|
434
510
|
}
|
|
435
511
|
};
|