Let the game view show the picture at a chosen scale (#225)
The game view always stretched the camera picture to fit the pane.
Pixel art came out blurred at odd factors, and there was no way to
see the game at its real size. The view now has a header with a
scale drop-down, and 100 % is the default.
- The header of the new GamePane offers Auto, Fit, 25 %, 50 %,
100 %, 200 % and 400 %. Auto and Fit show the factor they land
on, e.g. "Auto · 100%", and follow the pane when it resizes.
- 100 % means one screen pixel per pixel of the camera resolution
(width x height). The camera zoom scales the world on top of
that, so a zoomed camera still fills the same frame.
- Auto takes the largest fixed step that fits the whole picture
and falls back to 25 % when nothing fits. Fit keeps the old
behaviour.
- A picture larger than the pane is cropped around the camera
centre. Fixed steps start on a whole pixel so pixel art stays
sharp at 100 %.
- The choice is kept in the browser like "Play starts". Nothing
is written into the project.
Found on the way: the first draft applied the step to the world
instead of the camera resolution. The camera zoom then had no
effect at 100 %, which the existing check 12c caught (zoom 1.37
measured as scale 1).
The CI smokes were not run locally, because that would reseed
projects the user works in. All three smoke cameras are 640x360
and fit the 670x383 harness view at 100 %.
Tests:
- ./check.sh: 156 files, 2298 tests, CHECK EXIT 0 (before 2290).
- 8 unit tests in tests/viewport/view.test.ts for whole-pixel
steps, cropping, Auto and Fit with fallback, and zoomed cameras.
- 7 e2e checks in 03g. e2e 1-17,28,30,38-40: ALL PASSED, 727
checks.
- Counter-checks: no cropping, no rounding, no factor reported to
the header, and no zoom share each fail their own tests.
- Check total: 1367 (CI at c1a702b) + 7 = 1374, computed only.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c1a702bc39
commit
9ef360ba1b
10 files changed
+291
-21
No files matched your search
@@ -291,6 +291,72 @@ export async function play(t) {
|
||||
info.rendering && info.camera === 'o3' && (await json(`__gm.locate('No active camera')`)) === null,
|
||||
JSON.stringify(info),
|
||||
);
|
||||
|
||||
// 3g. Game view scale (#225): 100% by default, picked in the header. A fixed step draws that
|
||||
// many pixels per unit whatever the view's size, a frame larger than the view is cut to it,
|
||||
// fit fills the tighter side and auto takes the largest step that still fits.
|
||||
const scale = () => json('__gm.gameScale()');
|
||||
const pickScale = async (label) => {
|
||||
const { picker } = await scale();
|
||||
await click(picker.x, picker.y);
|
||||
await clickText(label);
|
||||
return scale();
|
||||
};
|
||||
const centred = ({ frame, view }) =>
|
||||
Math.abs(frame.x + frame.w / 2 - (view.x + view.w / 2)) <= 1 &&
|
||||
Math.abs(frame.y + frame.h / 2 - (view.y + view.h / 2)) <= 1;
|
||||
let g = await scale();
|
||||
const crateAt100 = (await json(`__gm.gameRect('o1')`)).w;
|
||||
check(
|
||||
'the game view starts at 100%, one pixel per world unit',
|
||||
g.mode === 1 && g.scale === 1 && g.label === '100%',
|
||||
JSON.stringify(g),
|
||||
);
|
||||
g = await pickScale('25%');
|
||||
const crateAt25 = (await json(`__gm.gameRect('o1')`)).w;
|
||||
check(
|
||||
'at 25% the 640x360 frame is 160x90, centred on a whole pixel, and the crate a quarter as wide',
|
||||
g.scale === 0.25 &&
|
||||
g.frame.w === 160 &&
|
||||
g.frame.h === 90 &&
|
||||
Number.isInteger(g.frame.x - g.view.x) &&
|
||||
centred(g) &&
|
||||
Math.abs(crateAt25 * 4 - crateAt100) < 0.01,
|
||||
JSON.stringify({ g, crateAt25, crateAt100 }),
|
||||
);
|
||||
await shot('10e-game-scale-25');
|
||||
g = await pickScale('400%');
|
||||
check(
|
||||
'at 400% the frame is larger than the view and cut to it, the camera still in the middle',
|
||||
g.scale === 4 &&
|
||||
JSON.stringify(g.frame) === JSON.stringify(g.view) &&
|
||||
(await json(`__gm.gameRect('o1')`)).w === crateAt100 * 4,
|
||||
JSON.stringify(g),
|
||||
);
|
||||
g = await pickScale('Fit');
|
||||
const fit = Math.min(g.view.w / 640, g.view.h / 360);
|
||||
check(
|
||||
'fit fills the tighter side exactly and names the factor it came to',
|
||||
g.mode === 'fit' &&
|
||||
Math.abs(g.factor - fit) < 1e-9 &&
|
||||
g.label === `Fit · ${Math.round(fit * 100)}%` &&
|
||||
centred(g),
|
||||
JSON.stringify(g),
|
||||
);
|
||||
g = await pickScale('Auto');
|
||||
const auto = Math.max(0.25, ...[0.25, 0.5, 1, 2, 4].filter((step) => step <= fit));
|
||||
check(
|
||||
'auto takes the largest step that still fits',
|
||||
g.mode === 'auto' && g.factor === auto && g.label === `Auto · ${auto * 100}%` && g.frame.w === 640 * auto,
|
||||
JSON.stringify({ g, fit }),
|
||||
);
|
||||
check(
|
||||
'the scale is remembered in this browser, not in the project',
|
||||
(await evaluate(`JSON.parse(localStorage.getItem('game-maker.editor')).gameScale`)) === 'auto' &&
|
||||
!(await evaluate(`JSON.stringify(__gm.state.project).includes('gameScale')`)),
|
||||
);
|
||||
g = await pickScale('100%');
|
||||
check('and 100% can be picked back', g.mode === 1 && g.scale === 1, JSON.stringify(g));
|
||||
await showTab('scene');
|
||||
check(
|
||||
'the fixture is left as it was found',
|
||||
|
||||
Reference in new issue
Block a user