A Load scene destroyed every object of the old scene. A player, a HUD or a music object had to be built again in each scene, with its state pushed through shared variables. A top-level object with the new switch Keep on scene load now travels into the next scene as the same entity, with everything below it. - The switch is a common property right under Enabled, off by default, on the asset and on a placed object. The inspector shows the row on top-level objects of a scene only, as answered in the issue. - runtime/keptObjects.ts holds the rules as pure functions. keptEntities picks what travels, objectsToBring copies the stored objects as the run parents them, and bringObjects puts them into the next scene. - World.instantiate takes a handed entity as it is instead of making one. The next syncToModel then writes the run's values into the scene. - BehaviorSystem.release takes the running instances out before the old world is destroyed, and the next system adopts them. They hear no On destroy and no second On start, and their sounds play on. - PhysicsSystem.resume gives a dynamic body the velocity and spin it had. - Duplicates: the object brought along wins. The next scene does not build its own object with the same id, which is the way back into the scene the object came from. - Decided here: the next scene does not build a top-level object of the same asset that is kept itself either. The issue only names the id. With the id alone a level that places its own player would hold two after a swap. - Decided here: kept objects land behind the scene's own, the switch is no animation row, and collisions are found anew. A finding, fixed along with it: Load scene did not build a scene as it is stored, but as the run had left it. A moved object stayed moved and a destroyed one stayed gone. The way back into a scene needs a clean build. - GameRun copies a scene's objects and groups before it first builds it and puts them back before it builds it again. - GameRun.end puts every such scene back. The player calls it on stop, so spawned objects no longer stay for "Click to play again". - The consequence: an edit made in a scene during Play is gone the next time that scene is loaded. Tests: - Gate: 199 files, 2944 tests (2929 + 15), exit 0 - e2e, full run: 1625 checks passed (1619 + 6), exit 0 - Smokes: 24 / 19 / 21, exit 0 - 15 unit tests in tests/core/keep-on-scene-load.test.ts - Six e2e checks in module 35: the switch is set with a real mouse, the child has no row, the object is in the new scene, its counter still reads 1, its sound plays on, and the stored scenes are unchanged after Stop - Eleven tests with fixed row lists only count the new schema row - 16 unit counter-probes all fail tests, run on stein2. One did not fail at first (same id not left out), it has its own test now. - The browser counter-probe fails 4 of the 6 new checks - Not looked at in the browser: the switch as a port of the Properties node, and a released game with a kept object Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
157 lines
5.6 KiB
TypeScript
157 lines
5.6 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import {
|
|
CreateAssetCommand,
|
|
DeleteAssetCommand,
|
|
RenameAssetCommand,
|
|
ResetAssetPropertyCommand,
|
|
SetActiveSceneCommand,
|
|
SetAssetPropertyCommand,
|
|
} from '../../src/core/commands/assetCommands';
|
|
import {
|
|
ClearOverrideCommand,
|
|
MoveSceneObjectCommand,
|
|
PlaceAssetCommand,
|
|
RemoveSceneObjectsCommand,
|
|
SetOverrideCommand,
|
|
} from '../../src/core/commands/sceneObjectCommands';
|
|
import { findAsset } from '../../src/core/model/Project';
|
|
import { makeSpriteScene, place } from '../helpers';
|
|
|
|
describe('asset commands', () => {
|
|
it('creates assets with defaults and activates the first scene', () => {
|
|
const { project, sceneId, spriteId } = makeSpriteScene();
|
|
expect(project.assets).toHaveLength(2);
|
|
expect(project.activeSceneId).toBe(sceneId);
|
|
expect(findAsset(project, spriteId)?.props).toEqual({
|
|
enabled: true,
|
|
keepOnSceneLoad: false,
|
|
scale: 1,
|
|
rotation: 0,
|
|
mirrorX: false,
|
|
mirrorY: false,
|
|
sortWithParent: true,
|
|
width: 100,
|
|
height: 100,
|
|
color: 0xffffff,
|
|
texture: '',
|
|
shader: '',
|
|
});
|
|
});
|
|
|
|
it('renames and sets properties with undo/redo', () => {
|
|
const { project, stack, spriteId } = makeSpriteScene();
|
|
const sprite = () => findAsset(project, spriteId)!;
|
|
stack.execute(new RenameAssetCommand(spriteId, 'Crate'));
|
|
stack.execute(new SetAssetPropertyCommand(spriteId, 'width', 250));
|
|
expect(sprite().name).toBe('Crate');
|
|
expect(sprite().props.width).toBe(250);
|
|
stack.undo();
|
|
expect(sprite().props.width).toBe(100);
|
|
stack.undo();
|
|
expect(sprite().name).toBe('Box');
|
|
stack.redo();
|
|
stack.redo();
|
|
expect(sprite().name).toBe('Crate');
|
|
expect(sprite().props.width).toBe(250);
|
|
});
|
|
|
|
it('rejects unknown properties', () => {
|
|
const { stack, spriteId } = makeSpriteScene();
|
|
expect(() => stack.execute(new SetAssetPropertyCommand(spriteId, 'x', 5))).toThrow(/not defined/);
|
|
expect(() => stack.execute(new ResetAssetPropertyCommand(spriteId, 'x'))).toThrow(/not defined/);
|
|
});
|
|
|
|
it('resets a property to its schema default with undo', () => {
|
|
const { project, stack, spriteId } = makeSpriteScene();
|
|
const sprite = () => findAsset(project, spriteId)!;
|
|
stack.execute(new SetAssetPropertyCommand(spriteId, 'height', 60));
|
|
stack.execute(new ResetAssetPropertyCommand(spriteId, 'height'));
|
|
expect(sprite().props.height).toBe(100);
|
|
stack.undo();
|
|
expect(sprite().props.height).toBe(60);
|
|
stack.redo();
|
|
expect(sprite().props.height).toBe(100);
|
|
});
|
|
|
|
it('deletes an asset together with its scene objects and restores both on undo', () => {
|
|
const f = makeSpriteScene();
|
|
const { project, stack, spriteId, sceneOf } = f;
|
|
place(f, spriteId, { x: 1, y: 2 });
|
|
place(f, spriteId, { x: 3, y: 4 });
|
|
expect(sceneOf().objects).toHaveLength(2);
|
|
stack.execute(new DeleteAssetCommand(spriteId));
|
|
expect(project.assets).toHaveLength(1);
|
|
expect(sceneOf().objects).toHaveLength(0);
|
|
stack.undo();
|
|
expect(project.assets).toHaveLength(2);
|
|
expect(sceneOf().objects.map((o) => o.position)).toEqual([
|
|
{ x: 1, y: 2, z: 0 },
|
|
{ x: 3, y: 4, z: 0 },
|
|
]);
|
|
});
|
|
|
|
it('switches the active scene when the active one is deleted', () => {
|
|
const { project, stack, sceneId } = makeSpriteScene();
|
|
const second = new CreateAssetCommand('scene', 'Level 2');
|
|
stack.execute(second);
|
|
stack.execute(new SetActiveSceneCommand(second.asset.id));
|
|
stack.execute(new DeleteAssetCommand(second.asset.id));
|
|
expect(project.activeSceneId).toBe(sceneId);
|
|
stack.undo();
|
|
expect(project.activeSceneId).toBe(second.asset.id);
|
|
});
|
|
});
|
|
|
|
describe('scene object commands', () => {
|
|
it('places assets and refuses scenes', () => {
|
|
const f = makeSpriteScene();
|
|
const { stack, sceneId, spriteId, sceneOf } = f;
|
|
const box = place(f, spriteId, { x: 5, y: 6 });
|
|
const object = sceneOf().objects[0]!;
|
|
expect(object.id).toBe(box);
|
|
expect(object.assetId).toBe(spriteId);
|
|
expect(object.position).toEqual({ x: 5, y: 6, z: 0 });
|
|
expect(object.overrides).toEqual({});
|
|
|
|
expect(() => stack.execute(new PlaceAssetCommand(sceneId, sceneId, { x: 0, y: 0 }))).toThrow(
|
|
/cannot be placed/,
|
|
);
|
|
expect(sceneOf().objects).toHaveLength(1);
|
|
});
|
|
|
|
it('moves, overrides, clears and removes with undo', () => {
|
|
const f = makeSpriteScene();
|
|
const { stack, sceneId, spriteId, sceneOf, object } = f;
|
|
const box = place(f, spriteId, { x: 0, y: 0 });
|
|
|
|
stack.execute(new MoveSceneObjectCommand(sceneId, box, { x: 40, y: 50, z: 3 }));
|
|
expect(object(box).position).toEqual({ x: 40, y: 50, z: 3 });
|
|
stack.undo();
|
|
expect(object(box).position).toEqual({ x: 0, y: 0, z: 0 });
|
|
stack.redo();
|
|
|
|
stack.execute(new SetOverrideCommand(sceneId, box, 'color', 0x123456));
|
|
expect(object(box).overrides).toEqual({ color: 0x123456 });
|
|
expect(() => stack.execute(new SetOverrideCommand(sceneId, box, 'nope', 1))).toThrow();
|
|
|
|
stack.execute(new ClearOverrideCommand(sceneId, box, 'color'));
|
|
expect(object(box).overrides).toEqual({});
|
|
stack.undo();
|
|
expect(object(box).overrides).toEqual({ color: 0x123456 });
|
|
|
|
stack.execute(new RemoveSceneObjectsCommand(sceneId, [box]));
|
|
expect(sceneOf().objects).toHaveLength(0);
|
|
stack.undo();
|
|
expect(object(box).position).toEqual({ x: 40, y: 50, z: 3 });
|
|
});
|
|
|
|
it('clears the redo stack on a new command', () => {
|
|
const f = makeSpriteScene();
|
|
place(f, f.spriteId, { x: 0, y: 0 });
|
|
f.stack.undo();
|
|
expect(f.stack.canRedo).toBe(true);
|
|
place(f, f.spriteId, { x: 1, y: 1 });
|
|
expect(f.stack.canRedo).toBe(false);
|
|
});
|
|
});
|