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(gates): a check of what the game drew measures the game, not the window
yhh944f88b1e60b
diff --git a/desktop/electron/surfaceDriver.ts b/desktop/electron/surfaceDriver.tsindex 8f8ed7115..deec71eb0 100644--- a/desktop/electron/surfaceDriver.ts+++ b/desktop/electron/surfaceDriver.ts@@ -121,26 +121,29 @@ function nearestInk(r: number, g: number, b: number): string {return best;}+/** The capture, reduced to the game surface the rect names — or whole, when there+ * is no usable rect. */+function cropToGame(image: Electron.NativeImage, rect: GameRect | null): Electron.NativeImage {+ const full = image.getSize();+ if (!rect || !(rect.windowWidth > 0)) return image;+ // capturePage is in device pixels and the rect is in CSS pixels.+ const scale = full.width / rect.windowWidth;+ const crop = {+ x: Math.max(0, Math.round(rect.x * scale)),+ y: Math.max(0, Math.round(rect.y * scale)),+ width: Math.min(full.width, Math.round(rect.width * scale)),+ height: Math.min(full.height, Math.round(rect.height * scale)),+ };+ return crop.width > 8 && crop.height > 8 ? image.crop(crop) : image;+}+function colorGrid(image: Electron.NativeImage, rect: GameRect | null, cols: number, rows: number): string {const w = Math.max(8, Math.min(160, Math.round(cols)));const h = Math.max(4, Math.min(90, Math.round(rows)));- const full = image.getSize();- let shot = image;- let what = 'the whole editor window';- if (rect && rect.windowWidth > 0) {- // capturePage is in device pixels and the rect is in CSS pixels.- const scale = full.width / rect.windowWidth;- const crop = {- x: Math.max(0, Math.round(rect.x * scale)),- y: Math.max(0, Math.round(rect.y * scale)),- width: Math.min(full.width, Math.round(rect.width * scale)),- height: Math.min(full.height, Math.round(rect.height * scale)),- };- if (crop.width > 8 && crop.height > 8) {- shot = image.crop(crop);- what = rect.playing ? 'the RUNNING GAME' : 'the edit viewport';- }- }+ const shot = cropToGame(image, rect);+ const what = shot === image+ ? 'the whole editor window'+ : (rect?.playing ? 'the RUNNING GAME' : 'the edit viewport');// BGRA, row-major. Electron 42's own typings declare this `void`; it returns the// buffer the docs promise, so the cast is over their declaration, not over reality.const src = shot.getSize();@@ -292,10 +295,15 @@ export function createSurfaceDriver(// The composited window, not the viewport canvas: this is the only way to// see the play realm, which renders in its own frame.const image = await requireWin().webContents.capturePage();- if (input.format !== 'grid') return image.toPNG().toString('base64');+ const cropped = input.format === 'grid' || input.crop === 'game';+ const rect = cropped+ ? await exec('window.__estellaEditor.gameRect()') as GameRect | null+ : null;// The same picture, in the only form a caller without vision can read.- const rect = await exec('window.__estellaEditor.gameRect()') as GameRect | null;- return colorGrid(image, rect, Number(input.cols ?? 64), Number(input.rows ?? 32));+ if (input.format === 'grid') {+ return colorGrid(image, rect, Number(input.cols ?? 64), Number(input.rows ?? 32));+ }+ return cropToGame(image, rect).toPNG().toString('base64');}case 'play_probe': {return unwrap(await playFrame(input).executeJavaScript(diff --git a/desktop/scripts/editor-checks/physics3d-debug-draw.mjs b/desktop/scripts/editor-checks/physics3d-debug-draw.mjsindex a01842a91..96962bbba 100644--- a/desktop/scripts/editor-checks/physics3d-debug-draw.mjs+++ b/desktop/scripts/editor-checks/physics3d-debug-draw.mjs@@ -49,12 +49,8 @@ export const describes = 'a running 3D game draws its own collider shapes when a* other channels. Nothing else in a play viewport of an empty scene is. */function shapeBox(png) {let minX = Infinity, minY = Infinity, maxX = -1, maxY = -1, count = 0;- // The viewport only: the content browser below it has blue folder icons, and a- // window-wide sweep counts those as a wireframe.- const x0 = Math.round(png.w * 0.04), x1 = Math.round(png.w * 0.72);- const y0 = Math.round(png.h * 0.12), y1 = Math.round(png.h * 0.62);- for (let y = y0; y < y1; y++) {- for (let x = x0; x < x1; x++) {+ for (let y = 0; y < png.h; y++) {+ for (let x = 0; x < png.w; x++) {const p = png.px(x, y);if (p[2] < 140 || p[2] - p[0] < 90 || p[2] - p[1] < 60) continue;count++;@@ -99,7 +95,7 @@ export async function run(ed) {await ed.call('play_probe', { code: 'await step(3); return true;' }, 60000);await ed.sleep(600);- const before = shapeBox(await ed.screenshot('debug3d-off'));+ const before = shapeBox(await ed.screenshot('debug3d-off', { crop: 'game' }));if (!check((before?.count ?? 0) < 40,`${before?.count} shape-coloured pixels before anything asked for them — the overlay `+ 'is drawing itself, or an editor gizmo is still on screen in play')) {@@ -116,7 +112,7 @@ export async function run(ed) {}await ed.sleep(600);- const shot = await ed.screenshot('debug3d-on');+ const shot = await ed.screenshot('debug3d-on', { crop: 'game' });const box = shapeBox(shot);if (!check(box != null && box.count > 100,`only ${box?.count ?? 0} wireframe pixels after turning the overlay on`)) {diff --git a/desktop/scripts/lib/editorDriver.mjs b/desktop/scripts/lib/editorDriver.mjsindex 88c6dfe90..3126cf1e2 100644--- a/desktop/scripts/lib/editorDriver.mjs+++ b/desktop/scripts/lib/editorDriver.mjs@@ -177,8 +177,8 @@ export async function withEditor(body, opts = {}) {return readPNG(png);},/** The composited window (the only way to see gizmo overlays or the play realm). */- screenshot: async (label) => {- const block = await call('screenshot', {}, 60000);+ screenshot: async (label, args = {}) => {+ const block = await call('screenshot', args, 60000);const png = Buffer.from(block.data ?? '', 'base64');if (out) await writeFile(path.join(out, `${label}.png`), png);return readPNG(png);diff --git a/desktop/shared/toolCatalog.mjs b/desktop/shared/toolCatalog.mjsindex 8ebdbe835..74c7765a8 100644--- a/desktop/shared/toolCatalog.mjs+++ b/desktop/shared/toolCatalog.mjs@@ -595,8 +595,12 @@ const ATOMS = [{ name: 'screenshot',description: 'Capture the composited editor window — the only capture that includes the play realm, so this is how you SEE gameplay (capture_viewport sees the edit viewport only). '+ "`format: 'grid'` returns the same picture as TEXT instead of a PNG: a coarse colour grid, cropped to the running game (or the edit viewport when nothing is playing), one letter per cell from a fixed 16-colour palette. "- + 'That is the form to ask for if you cannot receive images — it still answers the questions no amount of reading fields back can (did anything draw at all, is it on camera, what colour did it come out, did the picture change after that input). `cols`/`rows` set the resolution (default 64x32).',- schema: obj({ format: { type: 'string' }, cols: { type: 'number' }, rows: { type: 'number' } }),+ + 'That is the form to ask for if you cannot receive images — it still answers the questions no amount of reading fields back can (did anything draw at all, is it on camera, what colour did it come out, did the picture change after that input). `cols`/`rows` set the resolution (default 64x32). '+ + "`crop: 'game'` gives the PNG that same crop, so a measurement of what the game drew is not at the mercy of where the panels are.",+ schema: obj({+ format: { type: 'string' }, cols: { type: 'number' }, rows: { type: 'number' },+ crop: { type: 'string' },+ }),op: 'screenshot', image: (i) => i.format !== 'grid' },// — The editor's OWN agent, for a driver that wants to run it: an eval harness,// a dogfood session, a regression over its behaviour. `driverOnly` keeps these