Refactoring round 9 covers everything since round 8 (14972d0): 62 commits with about 29 000 new lines in src, api, tools and tests. Behaviour is unchanged. The one fix is in a check: e2e 04 counted 25 asset types, and the shader function from #303 makes 26, so the run ofa526e1bfailed there. Duplicate code (jscpd over src, 50 tokens, without the two licence texts: 35 clones / 289 lines before, 29 / 232 after): - ShaderPicture (new, viewport/shaderPicture.ts) is the picture a camera's shader and a particle field's shader are laid over. It keeps the render texture while its size holds and frees the replaced one once the shader holds the new one. CameraShade and ParticleField.shadeField drew it the same way, line for line. - CameraShade builds its mesh on the first draw. Before, every redraw of a view without a camera shader built a mesh and threw it away. - emptyHost in inspector/host.ts builds the empty host the Inspector, the Variables tab and the Tilemap panel start from. - paddedQuad(null) is the plain unit quad. symbols.ts and shaderPasses.ts each wrote it out by hand. - In graph/nested.ts, calls of shader functions and On behavior nodes are followed by one walk, `reaches`, over ids `namedBy` a node type. Dead code: - ShaderEditor.colorFieldOf and the getter CurveCanvas.snapping had no reader. - 22 values used only in their own file lose their `export`. Types and the node catalogues of shaders and particles stay exported. - Kept on purpose: PhysicsSystem.holdsJoint is read by tests only, but it is their one view of whether a joint holds. - A pass with stricter lint rules over every file changed since round 8 found no bug. PixelArtEditor.started is now readonly. Comments and docs: - Ten comments told history ("since #190", "used to", "any more"). They now describe what is. The bundle is md5-identical before and after, and the four e2e files minify to the same bytes. - README: joint and shader function in the asset list, joints on the Physics row, what the Shaders page covers, two CI runners. - e2e 04 keeps the number of asset types once, as ASSET_TYPE_COUNT. - screenshot.png in the README is a new picture of the editor (3840x2160 instead of 1825x1140), taken by the user. Tests: - Gate on melektaus-atx: 229 files, 3514 tests, CHECK EXIT 0 (+3 for emptyHost, +1 for the unit quad). - e2e 1-4, 31, 63 on melektaus-atx: ALL PASSED, 195 checks. That is the + menu of 04, the field shader of 31 and the camera shader of 63, both through ShaderPicture. - No new e2e check, so the sum stays 1728. - Counter-checks, each put back and compared with cmp: reaches that never goes on fails 1 test, listensTo reading the wrong parameter fails 1, emptyHost dropping what a panel hands in fails 1, folding without a relayout fails 1. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
106 lines
4.4 KiB
JavaScript
106 lines
4.4 KiB
JavaScript
/**
|
|
* The interface on a screen scaled to 150 %: the one thing every other step is blind to, since the
|
|
* harness runs at 100 %, where a layout pixel is a device pixel. Text has to come out as hard as it
|
|
* does at 100 %, and a hairline has to be one device pixel of its own colour, not one and a half
|
|
* with the half mixed. Reloads the page twice, so the steps after it start from a fresh editor.
|
|
*/
|
|
export async function devicePixels(t) {
|
|
const { check, json, cdp, navigate, select, storedObjects, wheel, exceptions } = t;
|
|
const size = { width: await json('innerWidth'), height: await json('innerHeight') };
|
|
const scale = (deviceScaleFactor) =>
|
|
cdp.send('Emulation.setDeviceMetricsOverride', { ...size, deviceScaleFactor, mobile: false });
|
|
// The toolbar: captions on a plain ground, read at 100 % and at 150 %.
|
|
const textEdges = () => json(`__gm.edgeContrast(0, 0, innerWidth, 30)`);
|
|
const pickFirst = async () => {
|
|
const holderId = await json('__gm.state.activeScene.id');
|
|
const first = (await storedObjects())[0];
|
|
await select({ kind: 'object', holderId, objectId: first.id, objectIds: [first.id] });
|
|
};
|
|
|
|
await pickFirst();
|
|
const plain = { grid: await json('__gm.pixelGrid()'), edges: await textEdges() };
|
|
|
|
await scale(1.5);
|
|
await navigate();
|
|
await pickFirst();
|
|
|
|
// 62a. The editor knows the grid it draws on.
|
|
const grid = await json('__gm.pixelGrid()');
|
|
check(
|
|
'at 150 % a hairline is one device pixel wide',
|
|
plain.grid.resolution === 1 &&
|
|
plain.grid.hairline === 1 &&
|
|
grid.resolution === 1.5 &&
|
|
Math.abs(grid.hairline * 1.5 - 1) < 1e-9,
|
|
JSON.stringify({ plain: plain.grid, grid }),
|
|
);
|
|
|
|
// 62b. Both lines of every band of the inspector, read down a column of device pixels: one row
|
|
// each, in the border's own colour, and only the band's colour between them. A band on an odd
|
|
// layout pixel starts half-way between two device pixels, which is the case that blurs.
|
|
const colours = {
|
|
border: await json(`__gm.themeColor('border')`),
|
|
header: await json(`__gm.themeColor('panelHeader')`),
|
|
};
|
|
// One pixel of scroll flips every band between even and odd, so both are read. The window is made
|
|
// too low for the inspector's rows first: one that shows them all has nothing to scroll.
|
|
await cdp.send('Emulation.setDeviceMetricsOverride', {
|
|
width: size.width,
|
|
height: 420,
|
|
deviceScaleFactor: 1.5,
|
|
mobile: false,
|
|
});
|
|
await t.settle();
|
|
const inspector = await json('__gm.inspectorRect()');
|
|
const bands = [];
|
|
for (const scrolled of [0, 1]) {
|
|
if (scrolled) await wheel(inspector.x + inspector.w / 2, inspector.y + inspector.h / 2, 1);
|
|
for (const title of ['SWITCHES', 'POSITION', 'TRANSFORM', 'PROPERTIES']) {
|
|
const band = await json(`__gm.section(${JSON.stringify(title)})`);
|
|
if (!band) continue;
|
|
const { x, y, w, h } = band.rect;
|
|
// A band cut off by the edge of the panel has no second line to read.
|
|
if (y < inspector.y || y + h > inspector.y + inspector.h) continue;
|
|
const column = await json(`__gm.deviceColumn(${x + w - 40}, ${y}, ${h})`);
|
|
const runs = [];
|
|
for (const colour of column) {
|
|
if (runs.at(-1)?.colour === colour) runs.at(-1).rows += 1;
|
|
else runs.push({ colour, rows: 1 });
|
|
}
|
|
bands.push({ title, y, runs: runs.map((run) => `${run.colour}*${run.rows}`) });
|
|
}
|
|
}
|
|
const crisp = (band) =>
|
|
band.runs.length === 3 &&
|
|
band.runs[0] === `${colours.border}*1` &&
|
|
band.runs[1].startsWith(`${colours.header}*`) &&
|
|
band.runs[2] === `${colours.border}*1`;
|
|
const odd = (band) => Math.round(band.y) % 2 === 1;
|
|
check(
|
|
'the lines of a band are one device pixel each, in the unmixed colour',
|
|
bands.every(crisp) && bands.some(odd) && bands.some((band) => !odd(band)),
|
|
JSON.stringify({ bands, colours }),
|
|
);
|
|
await scale(1.5);
|
|
await t.settle();
|
|
|
|
// 62c. Text keeps its edges: against the same captions at 100 %, where nothing can sit between pixels.
|
|
const edges = await textEdges();
|
|
const kept = edges / plain.edges;
|
|
check(
|
|
'text is as hard-edged at 150 % as at 100 %',
|
|
kept > 0.96,
|
|
JSON.stringify({ plain: plain.edges, edges, kept }),
|
|
);
|
|
await t.shot('62-device-pixels');
|
|
|
|
await scale(1);
|
|
await navigate();
|
|
const back = await json('__gm.pixelGrid()');
|
|
check(
|
|
'back at 100 % without exceptions',
|
|
back.resolution === 1 && exceptions().length === 0,
|
|
JSON.stringify({ back, exceptions: exceptions() }),
|
|
);
|
|
}
|