Files
feuerwerk/tests/editor/project-settings.test.ts
T
adminandClaude Opus 5.5 b2326085ed
game-maker / gate (push) Successful in 3m2s
game-maker / suite (push) Successful in 14m26s
Show each camera only its layers and lay overlay cameras on top (#302)
A camera could only show the whole scene, so a HUD drawn in the world
would run through a camera shader (#299) with everything else. Render
layers say which cameras see an object, and overlay cameras draw their
own picture over the main one.

- The project has a list of up to 16 render layers, edited in Project
  settings next to the collision layers. It is a list of its own, read
  by the same rules (`layerNamesOf`).
- Sprites, texts, tilemaps, particle sources and containers carry a row
  `Render layer` under their switches. Its default `Inherit` takes the
  parent's layer, at the top the first one.
- A camera has `Sees` (all layers by default) and `Overlay`. The main
  camera is the first one switched on without Overlay, so two plain
  cameras still draw through the first one only.
- Every view through a camera keeps only what that camera sees and lays
  one see-through view per overlay camera over itself. That view is a
  `WorldViewport` of its own, handed its view and frame from below.
- An overlay is fitted into the main camera's whole picture without
  distortion. One of the same size and zoom covers it exactly.
- `z` sorts within one camera only. The pictures lie on top of each
  other as a whole, which is what a shader per camera (#299) needs.
- The Game tab's preview now collects the scene once per redraw. Before
  it collected it twice, with the cameras it would have been five times.
- `SetCollisionLayersCommand` became `SetLayerNamesCommand`, which
  takes the list it sets.

Follow-ups: #304 (the mouse through a chosen camera) and #305 (change
the render layer at run time).

Tests:
- Gate: 226 files, 3487 tests (3480 + 7)
- e2e 63 (new): 4 checks. A green overlay sprite at z -10 covers a
  red main sprite at z 1000, in the preview and in the running game.
  A `UI` sprite in front of the main camera and a `Default` one in
  front of the overlay stay away. Without Overlay the second camera
  draws nothing. The settings dialog adds a render layer at the end.
- Counter-checks: inheriting from parents switched off fails 1 unit
  test. Overlays never drawn fails the two overlay checks in e2e 63.
- e2e total 1720 (1716 + 4), computed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-03 15:32:52 +02:00

74 lines
3.4 KiB
TypeScript

/**
* What "Apply" in the Project settings dialog (#183) actually carries out. The dialog itself is a
* widget and needs a canvas; the rule behind it is a pure function and is tested here.
*/
import { describe, expect, it } from 'vitest';
import { settingsChanges, type ProjectSettings } from '../../src/editor/ProjectSettingsDialog';
const before: ProjectSettings = {
name: 'Demo project',
playFrom: 'start',
whilePlaying: 'balanced',
gameLinkZoom: 'auto',
collisionLayers: ['Default', 'Enemies'],
renderLayers: ['Default'],
symbolScale: 1,
};
describe('project settings', () => {
it('reports nothing to do when nothing was touched', () => {
expect(settingsChanges(before, { ...before, collisionLayers: ['Default', 'Enemies'] })).toEqual({});
});
it('renames only when the name really differs', () => {
expect(settingsChanges(before, { ...before, name: 'Tetris' }).name).toBe('Tetris');
expect(settingsChanges(before, { ...before, name: 'Demo project' }).name).toBeUndefined();
});
it('trims the name and keeps the old one when only blanks are left', () => {
expect(settingsChanges(before, { ...before, name: ' Tetris ' }).name).toBe('Tetris');
expect(settingsChanges(before, { ...before, name: ' ' }).name).toBeUndefined();
});
it('writes the layers when one was added, renamed or dropped', () => {
const changed = (layers: string[]) => settingsChanges(before, { ...before, collisionLayers: layers });
expect(changed(['Default', 'Enemies', 'Pickups']).collisionLayers).toEqual([
'Default',
'Enemies',
'Pickups',
]);
expect(changed(['Default', 'Foes']).collisionLayers).toEqual(['Default', 'Foes']);
expect(changed(['Default']).collisionLayers).toEqual(['Default']);
});
it('hands back a copy of the layers, not the array the dialog goes on editing', () => {
const edited = ['Default', 'Foes'];
const change = settingsChanges(before, { ...before, collisionLayers: edited });
edited.push('Later');
expect(change.collisionLayers).toEqual(['Default', 'Foes']);
});
it('writes the symbol scale only when it changed, kept inside 0.1 to 4', () => {
expect(settingsChanges(before, { ...before, symbolScale: 1 }).symbolScale).toBeUndefined();
expect(settingsChanges(before, { ...before, symbolScale: 0.5 }).symbolScale).toBe(0.5);
expect(settingsChanges(before, { ...before, symbolScale: 0.01 }).symbolScale).toBe(0.1);
expect(settingsChanges(before, { ...before, symbolScale: 9 }).symbolScale).toBe(4);
expect(settingsChanges(before, { ...before, symbolScale: Number.NaN }).symbolScale).toBeUndefined();
});
it('writes the start-scene switch only when it changed (#226)', () => {
expect(settingsChanges(before, { ...before, playFrom: 'active' }).playFrom).toBe('active');
expect(settingsChanges(before, { ...before, playFrom: 'start' }).playFrom).toBeUndefined();
});
it('writes the While playing preset only when it changed (#265)', () => {
expect(settingsChanges(before, { ...before, whilePlaying: 'live' }).whilePlaying).toBe('live');
expect(settingsChanges(before, { ...before, whilePlaying: 'balanced' }).whilePlaying).toBeUndefined();
});
it('writes the zoom of the game link only when it changed (#279)', () => {
expect(settingsChanges(before, { ...before, gameLinkZoom: 'fit' }).gameLinkZoom).toBe('fit');
expect(settingsChanges(before, { ...before, gameLinkZoom: 'auto' }).gameLinkZoom).toBeUndefined();
});
});