Skip to content

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.

feat(ci): a notch the HUD has to come out from under

esengine3b7f9cf1e287
diff --git a/tools/check-golden.mjs b/tools/check-golden.mjs
index 091c2d8cb..5c062418d 100644
--- a/tools/check-golden.mjs
+++ b/tools/check-golden.mjs
@@ -22,6 +22,9 @@ import {
const problems = [];
const fail = (msg) => problems.push(msg);
+/** Capabilities a packaged frame cannot show, and the declaration whose run reads them. */
+const NEEDS_RUN = { 'safe-area': 'safeArea', 'pause-resume': 'suspend' };
+
// 1. Every golden id is a project that exists and declares a scene to open.
const seen = new Set();
for (const g of GOLDEN) {
@@ -79,6 +82,21 @@ for (const g of GOLDEN) {
if (!g.certifies?.length) fail(`"${g.id}" certifies nothing — say what it is in the suite for`);
for (const c of g.certifies ?? []) {
if (!CAPABILITIES.includes(c)) fail(`"${g.id}" certifies "${c}", which is not a declared capability`);
+ // Packaging and parity come free with being in the corpus; these do not.
+ // Claiming one without declaring the run that reads it is how a capability
+ // ends up "covered" by a project that never exercises it.
+ const block = NEEDS_RUN[c];
+ if (block && !g[block]) {
+ fail(`"${g.id}" certifies "${c}" but declares no ${block} — a claim only a run can settle needs that run`);
+ }
+ }
+ const sa = g.safeArea;
+ if (sa) {
+ if (!sa.entity || !sa.reference) fail(`"${g.id}" declares safeArea without both an entity and a reference`);
+ if (sa.entity === sa.reference) fail(`"${g.id}" reads safeArea against itself — the reference must be a second node`);
+ // Equal insets would let a run that moves the node by one fixed amount pass.
+ if (!(sa.top > 0) || !(sa.left > 0)) fail(`"${g.id}" declares safeArea without a positive top and left inset`);
+ else if (sa.top === sa.left) fail(`"${g.id}" gives safeArea the same inset on both edges — then the run cannot see scaling`);
}
}
diff --git a/tools/goldenProjects.mjs b/tools/goldenProjects.mjs
index 4c82588f5..19b298a34 100644
--- a/tools/goldenProjects.mjs
+++ b/tools/goldenProjects.mjs
@@ -71,7 +71,6 @@ export const CAPABILITIES = [
* coverage — the same bargain check-project-settings strikes.
*/
export const KNOWN_GAPS = {
- 'safe-area': 'safe-area insets are exercised by the UI mode viewport, not by a project — Celestial Heights P5',
rollback: 'hot-update-demo swaps forward; nothing exercises a failed manifest rolling back',
// Present in the engine and shown by non-golden samples, but never carried
// through the chain by a project the release argues from.
@@ -170,7 +169,7 @@ export const GOLDEN = [
'tilemap', 'tile-collision', 'navigation', 'behavior-tree',
'scene-transition', 'y-sort', 'localization', 'ui-layout', 'text',
'persistence', 'ui-inventory', 'achievements', 'touch', 'controller',
- 'pause-resume',
+ 'pause-resume', 'safe-area',
],
targets: ['web', 'desktop'],
// Nightly, not pr: a project earns the release gate by having run, and this
@@ -192,6 +191,10 @@ export const GOLDEN = [
// Lyra got to, because a frame comparison saturates the moment her sprite
// stops overlapping itself and cannot tell 30 frames from 60.
suspend: { entity: 'Lyra_Player', keys: ['KeyD'], frames: 80, hideFrom: 20, hideTo: 50, moves: 60 },
+ // The HUD has to come out from UNDER a notch, on the axis it came from. The
+ // two edges carry different insets on purpose, so the run also says the move
+ // scales with the inset instead of being one hardcoded nudge.
+ safeArea: { entity: 'HUD', reference: 'Canvas', top: 44, left: 88, moves: 40 },
},
{
id: 'input-actions',
@@ -291,6 +294,23 @@ export function suspendFor(g) {
};
}
+/**
+ * What a project asks of a screen with a notch, or null when it claims nothing.
+ * `entity` is a node anchored top-left, read against a `reference` that rides the
+ * camera so the game's own drift cancels. `moves`: measured 88 world units on a
+ * 540-tall surface, 103 on a 461-tall one — 40 is under both, over an ignored 0.
+ */
+export function safeAreaFor(g) {
+ if (!g.safeArea) return null;
+ return {
+ entity: g.safeArea.entity,
+ reference: g.safeArea.reference,
+ top: g.safeArea.top,
+ left: g.safeArea.left,
+ moves: g.safeArea.moves ?? 40,
+ };
+}
+
/** Absolute path to a golden project's directory. */
export function projectDir(id) {
return path.join(EXAMPLES, id);
diff --git a/tools/verify-golden.mjs b/tools/verify-golden.mjs
index cb1832647..c942fefa7 100644
--- a/tools/verify-golden.mjs
+++ b/tools/verify-golden.mjs
@@ -19,7 +19,7 @@
import { spawnSync } from 'node:child_process';
import { mkdirSync, rmSync, readFileSync, existsSync } from 'node:fs';
import path from 'node:path';
-import { atTier, projectDir, parityFor, interactFor, suspendFor, ROOT } from './goldenProjects.mjs';
+import { atTier, projectDir, parityFor, interactFor, suspendFor, safeAreaFor, ROOT } from './goldenProjects.mjs';
import { frameDistance, frameCellMax, readPNG } from './frameCompare.mjs';
const argv = process.argv.slice(2);
@@ -106,6 +106,20 @@ function captureEditorFrame(id, out) {
return { ok: true, w: png.w, h: png.h };
}
+/** Where a packaged run says the named entities are, or null if it never said. */
+function probePositions(target, dir, w, h, names, extra = []) {
+ const r = spawnSync('npx', [
+ 'electron', path.join('scripts', LAUNCHER(target)),
+ '--dir', dir, '--w', String(w), '--h', String(h),
+ '--probe', names.join(','), ...extra,
+ ], { encoding: 'utf8', cwd: DESKTOP });
+ const line = (r.stdout || '').split('\n').find((l) => l.includes('probe:'));
+ if (!line) return null;
+ try {
+ return JSON.parse(line.slice(line.indexOf('{'))).at ?? null;
+ } catch { return null; }
+}
+
const results = [];
for (const { id, target } of pairs) {
const out = path.join(WORK, `${id}-${target}`);
@@ -249,19 +263,9 @@ for (const { id, target } of pairs) {
// the same drive, read as how far the same entity got.
const suspend = suspendFor(golden);
if (suspend) {
- const where = (hidden) => {
- const r = spawnSync('npx', [
- 'electron', path.join('scripts', LAUNCHER(target)),
- '--dir', out, '--w', String(editor.w), '--h', String(editor.h),
- '--probe', suspend.entity,
- '--input', JSON.stringify({ keys: suspend.keys, frames: suspend.frames, hidden }),
- ], { encoding: 'utf8', cwd: DESKTOP });
- const line = (r.stdout || '').split('\n').find((l) => l.includes('probe:'));
- if (!line) return null;
- try {
- return JSON.parse(line.slice(line.indexOf('{'))).at?.[suspend.entity]?.x ?? null;
- } catch { return null; }
- };
+ const where = (hidden) => probePositions(target, out, editor.w, editor.h, [suspend.entity], [
+ '--input', JSON.stringify({ keys: suspend.keys, frames: suspend.frames, hidden }),
+ ])?.[suspend.entity]?.x ?? null;
const never = where([]);
const stayed = where([{ from: suspend.hideFrom, to: suspend.frames - 1 }]);
@@ -286,6 +290,50 @@ for (const { id, target } of pairs) {
+ `${stayed.toFixed(0)} hidden, ${back.toFixed(0)} back, ${never.toFixed(0)} never stopped`);
}
}
+
+ // A notch takes screen away from one edge, and the HUD has to come out from
+ // under it. Read as an offset from a node that rides the camera: a live game
+ // is somewhere slightly different each run, and that cancels.
+ const safe = safeAreaFor(golden);
+ if (safe) {
+ const names = [safe.entity, safe.reference];
+ const offset = (insets) => {
+ const at = probePositions(target, out, editor.w, editor.h, names,
+ insets ? ['--safe-area', insets] : []);
+ const node = at?.[safe.entity];
+ const ref = at?.[safe.reference];
+ return node && ref ? { x: node.x - ref.x, y: node.y - ref.y } : null;
+ };
+
+ const flat = offset(null);
+ const notched = offset(`${safe.top},0,0,0`);
+ const sided = offset(`0,0,0,${safe.left}`);
+
+ if (!flat || !notched || !sided) {
+ results.push({ id, target, stage: 'safe-area', ok: false, why: `could not read ${safe.entity} against ${safe.reference}` });
+ console.log(`✗ ${id} ${target} — safe-area: could not read ${safe.entity} against ${safe.reference} in all three runs`);
+ } else {
+ // World y is up, so a notch at the top pushes the HUD DOWN. The axis the
+ // inset did not come from must not move at all — swapped edges are the
+ // failure this catches, and they move the right distance the wrong way.
+ const down = flat.y - notched.y;
+ const right = sided.x - flat.x;
+ const QUIET = 1;
+ const fellUnderNotch = down >= safe.moves && Math.abs(notched.x - flat.x) <= QUIET;
+ const clearedSide = right >= safe.moves && Math.abs(sided.y - flat.y) <= QUIET;
+ // The two edges carry different insets, so their moves must carry the same
+ // ratio. One hardcoded nudge satisfies everything above and fails here.
+ const scaled = down > 0 && Math.abs(right / down - safe.left / safe.top) <= 0.05;
+ const ok = fellUnderNotch && clearedSide && scaled;
+ results.push({
+ id, target, stage: 'safe-area', ok,
+ why: ok ? '' : `top ${safe.top} moved it (${(notched.x - flat.x).toFixed(1)}, ${(-down).toFixed(1)}), `
+ + `left ${safe.left} moved it (${right.toFixed(1)}, ${(sided.y - flat.y).toFixed(1)})`,
+ });
+ console.log(`${ok ? '✓' : '✗'} ${id} ${target} — safe-area: ${safe.entity} drops ${down.toFixed(1)} under a `
+ + `${safe.top} notch, clears ${right.toFixed(1)} past a ${safe.left} edge`);
+ }
+ }
}
const bad = results.filter((r) => !r.ok);