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>
152 lines
5.4 KiB
TypeScript
152 lines
5.4 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
||
import { buildAsset } from '../../src/core/commands/assetCommands';
|
||
import { createEmptyProject } from '../../src/core/model/Project';
|
||
import { createSceneObject } from '../../src/core/model/SceneObject';
|
||
import { coerceValue, defaultsFor, schemaFor } from '../../src/core/properties/PropertySchema';
|
||
import {
|
||
deviatesFromAsset,
|
||
deviatesFromTemplate,
|
||
inheritedValue,
|
||
isModified,
|
||
resolveAssetProps,
|
||
resolveSceneObjectProps,
|
||
} from '../../src/core/properties/resolve';
|
||
|
||
describe('PropertySchema', () => {
|
||
it('has no position on any asset type', () => {
|
||
for (const type of ['scene', 'camera', 'sprite'] as const) {
|
||
const keys = schemaFor(type).map((d) => d.key);
|
||
expect(keys).not.toContain('x');
|
||
expect(keys).not.toContain('y');
|
||
expect(keys).not.toContain('position');
|
||
}
|
||
});
|
||
|
||
it('provides defaults for every key', () => {
|
||
expect(defaultsFor('sprite')).toEqual({
|
||
enabled: true,
|
||
keepOnSceneLoad: false,
|
||
scale: 1,
|
||
rotation: 0,
|
||
mirrorX: false,
|
||
mirrorY: false,
|
||
sortWithParent: false,
|
||
renderLayer: -1,
|
||
width: 100,
|
||
height: 100,
|
||
color: 0xffffff,
|
||
texture: '',
|
||
shader: '',
|
||
});
|
||
});
|
||
|
||
it('coerces values against the definition', () => {
|
||
const width = schemaFor('sprite').find((d) => d.key === 'width')!;
|
||
expect(coerceValue(width, -5)).toBe(1);
|
||
expect(coerceValue(width, '42')).toBe(42);
|
||
expect(coerceValue(width, 'abc')).toBe(100);
|
||
const color = schemaFor('sprite').find((d) => d.key === 'color')!;
|
||
expect(coerceValue(color, '#ff0000')).toBe(0xff0000);
|
||
expect(coerceValue(color, 0x1ffffff)).toBe(0xffffff);
|
||
});
|
||
});
|
||
|
||
describe('resolve', () => {
|
||
const project = createEmptyProject('p', 'P');
|
||
it('fills asset props with defaults and ignores unknown keys', () => {
|
||
const sprite = buildAsset('sprite', 'Box');
|
||
sprite.props = { width: 50, bogus: 1 };
|
||
expect(resolveAssetProps(project, sprite)).toEqual({
|
||
enabled: true,
|
||
keepOnSceneLoad: false,
|
||
scale: 1,
|
||
rotation: 0,
|
||
mirrorX: false,
|
||
mirrorY: false,
|
||
sortWithParent: false,
|
||
renderLayer: -1,
|
||
width: 50,
|
||
height: 100,
|
||
color: 0xffffff,
|
||
texture: '',
|
||
shader: '',
|
||
});
|
||
});
|
||
|
||
it('applies sparse overrides on top of asset values', () => {
|
||
const sprite = buildAsset('sprite', 'Box');
|
||
sprite.props.color = 0x00ff00;
|
||
const object = createSceneObject('o1', sprite.id, { x: 10, y: 20 });
|
||
expect(resolveSceneObjectProps(project, sprite, object)).toEqual({
|
||
enabled: true,
|
||
keepOnSceneLoad: false,
|
||
scale: 1,
|
||
rotation: 0,
|
||
mirrorX: false,
|
||
mirrorY: false,
|
||
sortWithParent: true,
|
||
renderLayer: -1,
|
||
width: 100,
|
||
height: 100,
|
||
color: 0x00ff00,
|
||
texture: '',
|
||
shader: '',
|
||
});
|
||
|
||
object.overrides.color = 0x0000ff;
|
||
expect(resolveSceneObjectProps(project, sprite, object).color).toBe(0x0000ff);
|
||
expect(inheritedValue(project, sprite, 'color')).toBe(0x00ff00);
|
||
});
|
||
|
||
it('detects asset values that differ from the schema default', () => {
|
||
const sprite = buildAsset('sprite', 'Box');
|
||
expect(isModified(project, sprite, 'width')).toBe(false); // explicit default counts as unmodified
|
||
sprite.props.width = 250;
|
||
expect(isModified(project, sprite, 'width')).toBe(true);
|
||
delete sprite.props.height; // missing → resolved from default → unmodified
|
||
expect(isModified(project, sprite, 'height')).toBe(false);
|
||
expect(isModified(project, sprite, 'bogus')).toBe(false);
|
||
});
|
||
|
||
it('ignores an override that carries the asset value – nothing to reset or apply', () => {
|
||
const sprite = buildAsset('sprite', 'Box');
|
||
sprite.props.width = 250;
|
||
const object = createSceneObject('o1', sprite.id, { x: 0, y: 0 });
|
||
expect(deviatesFromAsset(project, object, sprite, 'width')).toBe(false); // no override at all
|
||
|
||
object.overrides.width = 250; // same value as the asset → not a deviation
|
||
expect(deviatesFromAsset(project, object, sprite, 'width')).toBe(false);
|
||
|
||
object.overrides.width = 300;
|
||
expect(deviatesFromAsset(project, object, sprite, 'width')).toBe(true);
|
||
|
||
// The asset moving to the object's value settles the difference again.
|
||
sprite.props.width = 300;
|
||
expect(deviatesFromAsset(project, object, sprite, 'width')).toBe(false);
|
||
});
|
||
|
||
it('compares an instance against its template as overrides, not as values', () => {
|
||
const sprite = buildAsset('sprite', 'Box');
|
||
const template = createSceneObject('t1', sprite.id, { x: 0, y: 0 });
|
||
const object = createSceneObject('o1', sprite.id, { x: 0, y: 0 });
|
||
expect(deviatesFromTemplate(object, template, 'width')).toBe(false); // neither overrides
|
||
|
||
template.overrides.width = 140;
|
||
expect(deviatesFromTemplate(object, template, 'width')).toBe(true);
|
||
|
||
object.overrides.width = 140;
|
||
expect(deviatesFromTemplate(object, template, 'width')).toBe(false);
|
||
|
||
object.overrides.width = 77;
|
||
expect(deviatesFromTemplate(object, template, 'width')).toBe(true);
|
||
});
|
||
|
||
it('keeps position on the scene object only', () => {
|
||
const sprite = buildAsset('sprite', 'Box');
|
||
const object = createSceneObject('o1', sprite.id, { x: 10, y: 20 });
|
||
expect(object.position).toEqual({ x: 10, y: 20, z: 0 });
|
||
expect('position' in sprite).toBe(false);
|
||
expect(resolveSceneObjectProps(project, sprite, object)).not.toHaveProperty('x');
|
||
});
|
||
});
|