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(playable): inline video through the embedded asset map
yhh17f3c3e71880
diff --git a/desktop/electron/exportPlayable.ts b/desktop/electron/exportPlayable.tsindex 2eec474ea..a122a23d6 100644--- a/desktop/electron/exportPlayable.ts+++ b/desktop/electron/exportPlayable.ts@@ -46,6 +46,7 @@ const MIME: Record<string, string> = {svg: 'image/svg+xml', ktx2: 'image/ktx2', json: 'application/json', esscene: 'application/json',fnt: 'text/plain', txt: 'text/plain', ogg: 'audio/ogg', mp3: 'audio/mpeg', wav: 'audio/wav',m4a: 'audio/mp4', aac: 'audio/aac', ttf: 'font/ttf', woff: 'font/woff', woff2: 'font/woff2',+ mp4: 'video/mp4', m4v: 'video/mp4', mov: 'video/quicktime', webm: 'video/webm',};const mimeOf = (p: string): string => MIME[path.extname(p).slice(1).toLowerCase()] ?? 'application/octet-stream';diff --git a/sdk/src/playableRuntime.ts b/sdk/src/playableRuntime.tsindex 61932fc56..4ca1e4ef6 100644--- a/sdk/src/playableRuntime.ts+++ b/sdk/src/playableRuntime.ts@@ -20,6 +20,7 @@ import type { AddressableManifest } from './asset/AddressableManifest';import type { Vec2 } from './types';import type { SceneData } from './scene';import { Audio } from './audio/Audio';+import { VideoPlayer } from './video/VideoAPI';export interface PlayableRuntimeConfig {app: App;@@ -107,6 +108,14 @@ export async function initPlayableRuntime(config: PlayableRuntimeConfig): Promis});}+ // Video source refs resolve through the SAME embedded map — the Video+ // component's clip and VideoPlayer.play() both get the inlined data URL, so+ // the single-file playable never fetches an external file (a `file://` page+ // is a null origin and its sibling requests are CORS-blocked).+ if (app.hasResource(VideoPlayer)) {+ app.getResource(VideoPlayer).setRefResolver((ref) => assets[ref] ?? ref);+ }+await initRuntime({app,module,diff --git a/sdk/tests/playableRuntime.test.ts b/sdk/tests/playableRuntime.test.tsindex 1568438f7..ef41d015a 100644--- a/sdk/tests/playableRuntime.test.ts+++ b/sdk/tests/playableRuntime.test.ts@@ -21,7 +21,8 @@ function createMockConfig(overrides?: Partial<PlayableRuntimeConfig>): PlayableRgetResource: vi.fn().mockReturnValue({registerEmbeddedAssets: vi.fn(),setEmbeddedOnly: vi.fn(),- setAssetResolver: vi.fn(),+ setAssetResolver: vi.fn(), // Audio+ setRefResolver: vi.fn(), // VideoPlayer}),hasResource: vi.fn().mockReturnValue(true),run: vi.fn(),@@ -98,4 +99,21 @@ describe('initPlayableRuntime', () => {// The original key still resolves; unknown targets alias nothing.expect(backend.resolveUrl('@uuid:aaaa')).toBe('data:text/plain;base64,QQ==');});++ // A single-file playable makes NO external requests — its `file://` page is a+ // null origin whose sibling fetches are CORS-blocked. Video is the newest+ // asset channel, so it must resolve through the SAME embedded map as every+ // other subsystem: the clip ref maps to its inlined data URL.+ it('wires the video ref resolver to the embedded data-URL map', async () => {+ const config = createMockConfig({+ assets: { 'assets/video/clip.mp4': 'data:video/mp4;base64,AAAA' },+ });++ await initPlayableRuntime(config);++ const resolver = (config.app.getResource() as { setRefResolver: ReturnType<typeof vi.fn> })+ .setRefResolver.mock.calls[0][0] as (ref: string) => string;+ expect(resolver('assets/video/clip.mp4')).toBe('data:video/mp4;base64,AAAA');+ expect(resolver('assets/nope.mp4')).toBe('assets/nope.mp4'); // passthrough, no external fetch key+ });});