Files
feuerwerk/tools/e2e/04-assets.mjs
T
rootandClaude Opus 5 5a6af74e44 Add textures for sprites
Images are uploaded to a content-addressed blob endpoint and stored as
data/textures/<sha256>.<ext>; the project only keeps the file name. The
sprite points at a texture asset through an ordinary property of the new
kind `asset`, so instance overrides, "Apply to container", "Reset to
asset", undo and `Set property` work without any extra code. The new kind
also replaces the ad-hoc asset picker the graph nodes faked as an enum.

Import goes through + -> Texture, drag & drop onto the canvas or Ctrl+V.
Images wider than 2048px are downscaled client-side and re-encoded to
WebP if needed, because nginx caps uploads at 1MB; an image that already
fits is uploaded byte for byte so pixel art is never resampled.

The sprite colour default changes from red to white, since colour tints
the texture multiplicatively and a tint of white shows an image as it is.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-08 13:43:08 +02:00

65 lines
2.8 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/** The asset panel: placing from the context menu, creating through "+", and resetting an asset value. */
export async function assets(t) {
const { check, sleep, evaluate, json, shot, click, clickText, undo, select, objects, asset } = t;
// 8. Context menu on the Crate asset → menu shows "Place in scene".
await clickText('Crate', 'right');
check('asset context menu opens', Boolean(await evaluate(`__gm.locate('Place in scene')`)));
await shot('11-context-menu');
await clickText('Place in scene');
await sleep(100);
const count = (await objects()).length;
check('placing from the menu adds an object', count === 8, `objects=${count}`);
// 9. Create a new asset through the + menu.
await clickText('+');
await clickText('Sprite');
await sleep(100);
const names = await json('__gm.state.project.assets.map(a => a.name)');
check('+ menu creates a sprite asset', names.includes('Sprite'), JSON.stringify(names));
await shot('12-new-asset');
// 12. Asset defaults: the Crate asset deviates in two properties – height 60 (schema default
// 100) and its red colour (the sprite default is white, i.e. "no tint") – so the rows
// carry two resets. Resetting height puts it back to 100 and removes *its* button while
// the colour keeps one; undo brings 60 back. Rows run Enabled, Width, Height, Color,
// Texture, so height's reset is the first and colour's the last.
await select({ kind: 'asset', assetId: 'crate' });
await sleep(200);
const heightReset = await evaluate(`__gm.locate('↺')`);
const colorReset = await evaluate(`__gm.locate('↺', true)`);
check('asset inspector shows a reset per deviating property', Boolean(heightReset));
check(
'the two deviations have two separate resets',
Boolean(colorReset) && colorReset.y > heightReset.y,
JSON.stringify({ heightReset, colorReset }),
);
await click(heightReset.x, heightReset.y);
await sleep(100);
check(
'reset puts the asset property back to its default',
(await asset('crate')).props.height === 100,
`height=${(await asset('crate')).props.height}`,
);
const remaining = await evaluate(`__gm.locate('↺')`);
check(
'the reset of the property now at its default is gone, the other one stays',
Boolean(remaining) &&
remaining.y === colorReset.y &&
remaining.y === (await evaluate(`__gm.locate('↺', true)`)).y,
JSON.stringify({ remaining, colorReset }),
);
await shot('15-asset-reset');
await undo();
check(
'undo restores the asset value',
(await asset('crate')).props.height === 60,
`height=${(await asset('crate')).props.height}`,
);
check(
'the height reset is back after undo',
(await evaluate(`__gm.locate('↺')`))?.y === heightReset.y,
JSON.stringify(await evaluate(`__gm.locate('↺')`)),
);
}