A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
fix(assets): sprite-anim clips play outside the editor — ref identity, not fetch URL
yhh28cc83a3c95b
diff --git a/desktop/src/project/ProjectStore.ts b/desktop/src/project/ProjectStore.tsindex 7347e2d42..6a31762e9 100644--- a/desktop/src/project/ProjectStore.ts+++ b/desktop/src/project/ProjectStore.ts@@ -62,6 +62,19 @@ export interface AssetEntry {const UUID_PREFIX = '@uuid:';+// UUID v4 shape — serialized refs come in three forms: `@uuid:` (canonical),+// a BARE uuid (`.esanim` flipbook frame textures), or a plain path. A bare+// uuid must resolve through the registry like a prefixed one; treating it as+// a path guarantees a 404 (estella://project/<uuid>) and white sprites.+const UUID_SHAPE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;++/** The uuid carried by a ref (`@uuid:` prefixed, any body — explicit intent —+ * or bare-but-uuid-shaped), else null for plain paths. Lower-cased. */+function refUuid(ref: string): string | null {+ if (ref.startsWith(UUID_PREFIX)) return ref.slice(UUID_PREFIX.length).toLowerCase();+ return UUID_SHAPE.test(ref) ? ref.toLowerCase() : null;+}+/** The subset of the engine's SceneAssetResult the Reconciler resolver reads. */interface PreloadResult {textureHandles: Map<string, number>;@@ -423,9 +436,7 @@ class ProjectStoreImpl {/** The texture filter/wrap for a ref (`@uuid:` or path), from its `.meta`* importer — the shape `Assets`'s TextureLoader consumes. Undefined ⇒ defaults. */private textureImportFor(ref: string): ReturnType<typeof readTextureImportSettings> {- const uuid = ref.startsWith(UUID_PREFIX)- ? ref.slice(UUID_PREFIX.length).toLowerCase()- : this.pathToUuid.get(ref);+ const uuid = refUuid(ref) ?? this.pathToUuid.get(ref);return readTextureImportSettings(uuid ? this.uuidToImporter.get(uuid) : undefined);}@@ -445,10 +456,12 @@ class ProjectStoreImpl {}/** Resolve a serialized asset ref to a project-relative path for the engine- * loader: `@uuid:` → path (null if unknown); a plain path passes through. */+ * loader: a uuid ref (`@uuid:` or bare) → path (null if unknown); a plain+ * path passes through. */private resolveRef(ref: string): string | null {- if (!ref.startsWith(UUID_PREFIX)) return ref;- return this.uuidToPath.get(ref.slice(UUID_PREFIX.length).toLowerCase()) ?? null;+ const uuid = refUuid(ref);+ if (uuid === null) return ref;+ return this.uuidToPath.get(uuid) ?? null;}/** The live GL handle for a uuid. Textures read the engine's live cache (so a@@ -456,9 +469,8 @@ class ProjectStoreImpl {private handleForRef(ref: string): number {const tex = EngineHost.getResource(Assets)?.getTexture(ref);if (tex) return tex.handle;- const path = ref.startsWith(UUID_PREFIX)- ? this.uuidToPath.get(ref.slice(UUID_PREFIX.length).toLowerCase())- : ref;+ const uuid = refUuid(ref);+ const path = uuid !== null ? this.uuidToPath.get(uuid) : ref;const r = this.lastAssetResult;if (!path || !r) return 0;return r.materialHandles.get(path) ?? r.fontHandles.get(path) ?? 0;diff --git a/sdk/src/animation/SpriteAnimator.ts b/sdk/src/animation/SpriteAnimator.tsindex acc15efab..4b9c6890b 100644--- a/sdk/src/animation/SpriteAnimator.ts+++ b/sdk/src/animation/SpriteAnimator.ts@@ -71,6 +71,17 @@ export class SpriteAnimationApi {this.clips.set(clip.name, clip);}+ /**+ * Register an EXISTING clip object under an additional lookup name. Loaders+ * register a clip under its resolved load path, which in some realms is an+ * absolute URL — components reference the serialized project-relative ref,+ * so the two must alias to the SAME object (events attached through one+ * name fire for the other).+ */+ aliasClip(name: string, clip: SpriteAnimClip): void {+ this.clips.set(name, clip);+ }+unregisterClip(name: string): void {this.clips.delete(name);}diff --git a/sdk/src/asset/Assets.ts b/sdk/src/asset/Assets.tsindex cf86706f1..9d9ba951b 100644--- a/sdk/src/asset/Assets.ts+++ b/sdk/src/asset/Assets.ts@@ -266,7 +266,20 @@ export class Assets {}async loadAnimClip(ref: string): Promise<AnimClipResult> {- return this.loadTyped('anim-clip', ref);+ const result = await this.loadTyped<AnimClipResult>('anim-clip', ref);+ // The loader registers the clip under its RESOLVED load path (an absolute+ // URL in realms whose ref resolver returns fetchable URLs, e.g. the play+ // realm), but SpriteAnimator/Animator reference clips by the SERIALIZED+ // ref (project-relative path). Alias the raw ref to the same clip object+ // so lookups match in every realm — without this, play mode registered+ // `estella://…/walk.esanim` while components asked for+ // `assets/animations/walk.esanim`, and no clip ever advanced a frame.+ const anim = this.getSpriteAnimation_();+ if (anim && ref !== result.clipId) {+ const clip = anim.getClip(result.clipId);+ if (clip && !anim.getClip(ref)) anim.aliasClip(ref, clip);+ }+ return result;}async loadTilemap(ref: string): Promise<TilemapResult> {@@ -489,7 +502,11 @@ export class Assets {const texturePaths = discovered.byType.get('texture') ?? new Set<string>();const materialPaths = discovered.byType.get('material') ?? new Set<string>();const fontPaths = discovered.byType.get('font') ?? new Set<string>();- const animClipPaths = discovered.byType.get('anim-clip') ?? new Set<string>();+ // Anim clips load by their RAW serialized ref: components (SpriteAnimator.clip,+ // Animator states) look clips up by that ref, and loadAnimClip aliases it to+ // the resolved registration. Feeding the resolved path here (like the handle+ // types) would strip the alias and leave play-realm lookups keyless.+ const animClipPaths = discovered.rawByType.get('anim-clip') ?? new Set<string>();const audioPaths = discovered.byType.get('audio') ?? new Set<string>();const tilemapPaths = discovered.byType.get('tilemap') ?? new Set<string>();const tilesetPaths = discovered.byType.get('tileset') ?? new Set<string>();diff --git a/sdk/src/asset/discoverAssets.ts b/sdk/src/asset/discoverAssets.tsindex 3797fc228..f3ebd0730 100644--- a/sdk/src/asset/discoverAssets.ts+++ b/sdk/src/asset/discoverAssets.ts@@ -28,6 +28,15 @@ export interface SpineAssetRef {export interface SceneAssetRefs {byType: Map<string, Set<string>>;+ /**+ * The same buckets keyed by the RAW serialized ref (pre-resolution).+ * Loaders whose registry is keyed by what the COMPONENT carries (anim+ * clips: `SpriteAnimator.clip` / Animator states hold the serialized ref)+ * must be driven by the raw ref, so load-time aliasing can bind the raw+ * ref to the resolved registration — a realm whose resolver returns+ * absolute URLs would otherwise register under keys no component uses.+ */+ rawByType: Map<string, Set<string>>;spines: SpineAssetRef[];/*** Refs seen during discovery that could not be resolved to a path@@ -45,6 +54,7 @@ export function discoverSceneAssets(refResolver?: RefResolver,): SceneAssetRefs {const byType = new Map<string, Set<string>>();+ const rawByType = new Map<string, Set<string>>();const spines: SpineAssetRef[] = [];const spineKeys = new Set<string>();const unresolved: string[] = [];@@ -58,15 +68,20 @@ export function discoverSceneAssets(return r;};- const addAsset = (type: string, raw: string): void => {- const path = resolve(raw);- if (path == null) return;- let set = byType.get(type);+ const bucket = (map: Map<string, Set<string>>, type: string, value: string): void => {+ let set = map.get(type);if (!set) {set = new Set();- byType.set(type, set);+ map.set(type, set);}- set.add(path);+ set.add(value);+ };++ const addAsset = (type: string, raw: string): void => {+ const path = resolve(raw);+ if (path == null) return;+ bucket(byType, type, path);+ bucket(rawByType, type, raw);};for (const entityData of sceneData.entities) {@@ -111,7 +126,7 @@ export function discoverSceneAssets(}}- return { byType, spines, unresolved };+ return { byType, rawByType, spines, unresolved };}export function getAssetPathsByType(refs: SceneAssetRefs, type: AssetFieldType): Set<string> {diff --git a/sdk/src/playRealmRuntime.ts b/sdk/src/playRealmRuntime.tsindex 599ee6f3b..9c8eb3daf 100644--- a/sdk/src/playRealmRuntime.ts+++ b/sdk/src/playRealmRuntime.ts@@ -25,8 +25,7 @@ import type { AddressableManifest } from './asset/AddressableManifest';import type { SceneData } from './scene';import type { PhysicsPluginConfig } from './physics/PhysicsPlugin';import { fetchDecodePixels } from './asset/imageDecode';--const UUID_PREFIX = '@uuid:';+import { extractUuid, UUID_REF_PREFIX } from './asset/AssetRegistry';export interface PlayRealmRuntimeConfig {app: App;@@ -65,14 +64,21 @@ export interface PlayRealmRuntimeConfig {* editor returns `access-control-allow-origin: *`.*//**- * Resolve a play-realm asset ref to a fetchable URL: `@uuid:` refs go through the- * editor-supplied manifest; any other ref is a project-relative path (spine- * skel/atlas, …) and resolves against the project root, not the `.esengine/play/`- * subdir the realm runs from. Pure.+ * Resolve a play-realm asset ref to a fetchable URL. UUID refs go through the+ * editor-supplied manifest — a `@uuid:` prefix is explicit intent (any body), and+ * a BARE uuid-shaped ref counts too ({@link extractUuid}'s canonical forms):+ * `.esanim` flipbook frames serialize bare uuids, and the old prefix-only check+ * dropped those into the path branch → guaranteed 404s, blank sprite animation+ * in play. Any other ref is a project-relative path (spine skel/atlas, …) and+ * resolves against the project root, not the `.esengine/play/` subdir the realm+ * runs from. Pure.*/export function resolvePlayAssetRef(ref: string, manifest: Record<string, string>, assetBaseUrl?: string): string {- if (ref.startsWith(UUID_PREFIX)) {- const url = manifest[ref.slice(UUID_PREFIX.length).toLowerCase()];+ const uuid = ref.startsWith(UUID_REF_PREFIX)+ ? ref.slice(UUID_REF_PREFIX.length).toLowerCase()+ : extractUuid(ref);+ if (uuid !== null) {+ const url = manifest[uuid];if (!url) throw new Error(`asset not in play manifest: ${ref}`);return url;}diff --git a/sdk/tests/play-asset-ref.test.ts b/sdk/tests/play-asset-ref.test.tsindex 9607d0e95..90028895a 100644--- a/sdk/tests/play-asset-ref.test.ts+++ b/sdk/tests/play-asset-ref.test.ts@@ -30,4 +30,13 @@ describe('resolvePlayAssetRef', () => {it('throws for a uuid ref missing from the manifest', () => {expect(() => resolvePlayAssetRef('@uuid:zzzz', MANIFEST, BASE)).toThrow(/not in play manifest/);});++ // .esanim flipbook frames serialize BARE uuids (no @uuid: prefix); those must+ // hit the manifest, not the path branch (which 404s on a uuid-shaped "path").+ it('resolves a bare uuid-shaped ref through the manifest', () => {+ const uuid = 'e43a0ed9-50e9-46d8-b1db-da1c549590a8';+ const manifest = { [uuid]: 'estella://project/assets/textures/idle_0.png' };+ expect(resolvePlayAssetRef(uuid, manifest, BASE)).toBe('estella://project/assets/textures/idle_0.png');+ expect(resolvePlayAssetRef(uuid.toUpperCase(), manifest, BASE)).toBe('estella://project/assets/textures/idle_0.png');+ });});