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
test(camera): cover project camera-fit schema + export plumbing
yhh210d50adffdd
diff --git a/desktop/tests/export-game.test.ts b/desktop/tests/export-game.test.tsindex ffcbf455c..7d88de5d1 100644--- a/desktop/tests/export-game.test.ts+++ b/desktop/tests/export-game.test.ts@@ -104,6 +104,27 @@ describe('exportGame', () => {expect(JSON.parse(readFileSync(path.join(out, 'game.config.json'), 'utf8')).entryScene).toBe('scenes/main.esscene');}, 60_000);+ it('writes the project camera fit into game.config.json (only when opted in)', async () => {+ const fitOut = path.join(root, 'dist-game-fit');+ const res = await exportGame({+ root, entryScene: 'scenes/main.esscene', gameHostEntry: GAME_HOST, scriptsEntry: 'src/main.ts',+ sdkDistDir: path.join(root, '_sdk'), wasmDir: path.join(root, '_wasm'), outDir: fitOut, title: 'Fit Game',+ screenFit: { designWidth: 1080, designHeight: 1920, scaleMode: 2, matchWidthOrHeight: 0.5 },+ });+ expect(res.ok).toBe(true);+ const cfg = JSON.parse(readFileSync(path.join(fitOut, 'game.config.json'), 'utf8'));+ expect(cfg.screenFit).toEqual({ designWidth: 1080, designHeight: 1920, scaleMode: 2, matchWidthOrHeight: 0.5 });++ // Off (scaleMode -1) ⇒ no screenFit key, so an unconfigured game's config is unchanged.+ const offOut = path.join(root, 'dist-game-fitoff');+ await exportGame({+ root, entryScene: 'scenes/main.esscene', gameHostEntry: GAME_HOST, scriptsEntry: 'src/main.ts',+ sdkDistDir: path.join(root, '_sdk'), wasmDir: path.join(root, '_wasm'), outDir: offOut,+ screenFit: { designWidth: 1920, designHeight: 1080, scaleMode: -1, matchWidthOrHeight: 0.5 },+ });+ expect(JSON.parse(readFileSync(path.join(offOut, 'game.config.json'), 'utf8')).screenFit).toBeUndefined();+ }, 60_000);+it('content-addresses + KTX2-compresses cooked assets when opted in', async () => {const out2 = path.join(root, 'dist-game-ca');const res = await exportGame({diff --git a/desktop/tests/export-playable.test.ts b/desktop/tests/export-playable.test.tsindex 4b136d0ac..721e6df77 100644--- a/desktop/tests/export-playable.test.ts+++ b/desktop/tests/export-playable.test.ts@@ -99,6 +99,21 @@ describe('exportGame (playable)', () => {expect(html).toMatch(/screen\.orientation[\s\S]*lock\("landscape"\)/);}, 60_000);+ it('inlines the project camera fit as __GAME_SCREENFIT__ (only when opted in)', async () => {+ const o = path.join(root, 'dist-playable-fit');+ const res = await exportGame({+ root, entryScene: 'scenes/main.esscene', gameHostEntry: 'unused-for-playable',+ playableHostEntry: PLAYABLE_HOST, scriptsEntry: 'src/main.ts',+ sdkDistDir: path.join(root, '_sdk'), wasmDir: path.join(root, '_wasm'),+ outDir: o, platform: 'playable', screenFit: { designWidth: 750, designHeight: 1334, scaleMode: 1, matchWidthOrHeight: 0.5 },+ });+ expect(res.ok).toBe(true);+ const html = readFileSync(path.join(o, 'index.html'), 'utf8');+ expect(html).toContain('__GAME_SCREENFIT__');+ expect(html).toMatch(/"scaleMode":1/);+ expect(html).toMatch(/"designWidth":750/);+ }, 60_000);+it('pins the single file to an explicit portrait orientation', async () => {const o = path.join(root, 'dist-playable-portrait');const res = await exportGame({diff --git a/desktop/tests/project-rendering.test.ts b/desktop/tests/project-rendering.test.tsindex a3990e5f3..240e57a12 100644--- a/desktop/tests/project-rendering.test.ts+++ b/desktop/tests/project-rendering.test.ts@@ -6,7 +6,7 @@* by absence, and junk values are dropped.*/import { describe, it, expect } from 'vitest';-import { parseManifest } from '../src/project/format';+import { parseManifest, cameraScaleModeValue, resolveScreenFit } from '../src/project/format';describe('parseManifest — rendering.colorSpace', () => {it("keeps 'linear'", () => {@@ -33,3 +33,46 @@ describe('parseManifest — rendering.colorSpace', () => {});});});++describe('parseManifest — rendering.cameraScaleMode', () => {+ it('keeps every real fit mode + clamps cameraMatch to 0..1', () => {+ for (const mode of ['fixed-width', 'fixed-height', 'expand', 'shrink', 'match'] as const) {+ expect(parseManifest({ name: 'X', features: { rendering: { cameraScaleMode: mode } } })+ .features?.rendering?.cameraScaleMode).toBe(mode);+ }+ expect(parseManifest({ name: 'X', features: { rendering: { cameraMatch: 5 } } })+ .features?.rendering?.cameraMatch).toBe(1);+ expect(parseManifest({ name: 'X', features: { rendering: { cameraMatch: -2 } } })+ .features?.rendering?.cameraMatch).toBe(0);+ });++ it("drops 'none' (default = absence) and junk", () => {+ for (const v of ['none', 'diagonal', 42, true]) {+ expect(parseManifest({ name: 'X', features: { rendering: { cameraScaleMode: v } } })+ .features?.rendering?.cameraScaleMode).toBeUndefined();+ }+ });+});++describe('cameraScaleModeValue / resolveScreenFit', () => {+ it('maps names to the engine CanvasScaleMode value (-1 = off)', () => {+ expect(cameraScaleModeValue('fixed-width')).toBe(0);+ expect(cameraScaleModeValue('fixed-height')).toBe(1);+ expect(cameraScaleModeValue('expand')).toBe(2);+ expect(cameraScaleModeValue('shrink')).toBe(3);+ expect(cameraScaleModeValue('match')).toBe(4);+ expect(cameraScaleModeValue('none')).toBe(-1);+ expect(cameraScaleModeValue(undefined)).toBe(-1);+ });++ it('builds the runtime screenFit from design resolution + fit; off by default', () => {+ expect(resolveScreenFit({ designResolution: { width: 1280, height: 720 } }))+ .toEqual({ designWidth: 1280, designHeight: 720, scaleMode: -1, matchWidthOrHeight: 0.5 });+ expect(resolveScreenFit({+ designResolution: { width: 1080, height: 1920 },+ features: { rendering: { cameraScaleMode: 'expand', cameraMatch: 0.25 } },+ })).toEqual({ designWidth: 1080, designHeight: 1920, scaleMode: 2, matchWidthOrHeight: 0.25 });+ // No design resolution ⇒ the engine default, still off.+ expect(resolveScreenFit({})).toEqual({ designWidth: 1920, designHeight: 1080, scaleMode: -1, matchWidthOrHeight: 0.5 });+ });+});