Both settings lived in the browser's localStorage, so they did not travel with the project and differed per machine. They now belong to the project like the symbol scale. There is no migration, old projects load with the defaults. - New module src/core/model/playSettings.ts reads playFrom and gameScale on load. Unknown or missing values fall back to the start scene and 100%. - src/editor/settings.ts is gone. - Play starts in the project settings dialog is an undo step (SetPlayFromCommand). It is only recorded on a real change. - The game view scale is saved with the project but is no undo step, so Ctrl+Z never undoes a zoom. A scale picked during play is written to the stored project and survives Stop. - Save states of persistent Variables assets (saves.ts) stay in the browser on purpose. They are runtime data of the game, not settings. Tests: - 6 new unit tests in tests/editor/play-settings.test.ts: defaults, save and load, broken JSON, undo of Play starts, scale without undo step, scale picked during play survives Stop. - e2e 03g checks the value in the project, nothing in localStorage and no new undo step. 35f also checks project.playFrom. No new checks, the sum stays at 1375. - Counter checks: no write to the stored project in play, no read on load, and an undo step for the scale each fail exactly their test. - ./check.sh: 158 files, 2332 tests, CHECK EXIT 0 - e2e 1-17,28,30,35,38-40,46: ALL PASSED, 752 checks Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
61 lines
2.8 KiB
TypeScript
61 lines
2.8 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',
|
|
collisionLayers: ['Default', 'Enemies'],
|
|
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();
|
|
});
|
|
});
|