An animated or set Z of -1 on a weapon put it behind everything on Z 0, not just behind the player holding it. A child can now opt in to being drawn at its parent's place, so its own Z only orders it against the parent and its siblings. - New property "Sort with parent" on sprites, texts and particle emitters, shown in the inspector right under Z. It is a normal property, set on the asset and overridable per object. - With it on, the rest of the scene sees only the parent's Z and, where the layer sorts by Y, the parent's feet. Below 0 the child is drawn behind the parent, from 0 on in front. - It works across levels: a grandchild with the switch hangs on the top object of the chain. - It has no effect under a parent that is not drawn itself (container, behavior, camera, collider) or under a tilemap. - New assets start with it on, saved ones read as off, so old projects draw unchanged. For that a schema row now has "initial" next to "default". The gold "changed" mark and reset follow "initial", so a fresh sprite is not marked as changed. No load migration is needed. - parentGroups() in drawOrder.ts gives a slot only to the top of a chain and inserts the children there. Editor, play mode and picking all use it, so they agree. Tests: - 10 new unit tests in tests/viewport/sort-with-parent.test.ts. - 8 existing tests list the sprite rows or defaults and got the row. - New e2e check 5b-ii clicks the switch and checks order and undo. - Counter-checks, all originals restored by cmp: switch ignored fails 7, children not sorted by Z fails 6, no chain fails 1, "initial" ignored fails 9, row missing in the inspector fails e2e 5. - ./check.sh: 166 files, 2426 tests, CHECK EXIT 0. - e2e 5: ALL PASSED, 13 checks. Check total 1398, computed only. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
96 lines
4.1 KiB
TypeScript
96 lines
4.1 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
||
import { CreateAssetCommand, CreateTextureCommand } from '../../src/core/commands/assetCommands';
|
||
import { CommandError } from '../../src/core/commands/Command';
|
||
import { findAsset } from '../../src/core/model/Project';
|
||
import { spriteFromTexture } from '../../src/core/properties/aspect';
|
||
import { makeProject } from '../helpers';
|
||
|
||
const FILE = `${'b'.repeat(64)}.webp`;
|
||
|
||
describe('CreateTextureCommand', () => {
|
||
it('adds a texture asset carrying the uploaded image, and removes it again', () => {
|
||
const { project, stack } = makeProject();
|
||
const command = new CreateTextureCommand('Hero', { file: FILE, width: 64, height: 32 });
|
||
stack.execute(command);
|
||
|
||
const asset = findAsset(project, command.asset.id);
|
||
expect(asset).toMatchObject({ type: 'texture', name: 'Hero', file: FILE, width: 64, height: 32 });
|
||
// The schema default comes along, so the new texture is a complete asset – nothing to fill in later.
|
||
expect(asset?.props).toEqual({ filter: 'linear', sliceScale: 1 });
|
||
|
||
stack.undo();
|
||
expect(project.assets).toHaveLength(0);
|
||
stack.redo();
|
||
expect(findAsset(project, command.asset.id)?.name).toBe('Hero');
|
||
});
|
||
|
||
it('keeps the caller’s name even though the upload result carries one of its own', () => {
|
||
const { project, stack } = makeProject();
|
||
// What `TextureStore.upload` actually answers: the file's original name and its byte count
|
||
// ride along. Copied wholesale they would land in the asset and rename it behind the caller.
|
||
const upload = { file: FILE, name: 'hero-idle.png', width: 64, height: 32, bytes: 900 };
|
||
const command = new CreateTextureCommand('Hero', upload);
|
||
stack.execute(command);
|
||
|
||
const asset = findAsset(project, command.asset.id);
|
||
expect(asset?.name).toBe('Hero');
|
||
expect(asset).not.toHaveProperty('bytes');
|
||
});
|
||
|
||
it('rejects a file name the server cannot have produced – in execute, not in the constructor', () => {
|
||
const { project, stack } = makeProject();
|
||
const command = new CreateTextureCommand('Hero', { file: '../secrets.png', width: 1, height: 1 });
|
||
expect(() => stack.execute(command)).toThrow(CommandError);
|
||
expect(project.assets).toHaveLength(0);
|
||
});
|
||
|
||
it('keeps two assets for the same file apart', () => {
|
||
const { project, stack } = makeProject();
|
||
stack.execute(new CreateTextureCommand('Hero', { file: FILE, width: 8, height: 8 }));
|
||
stack.execute(new CreateTextureCommand('Hero copy', { file: FILE, width: 8, height: 8 }));
|
||
expect(project.assets.map((a) => a.id)).toHaveLength(2);
|
||
expect(new Set(project.assets.map((a) => a.id)).size).toBe(2);
|
||
});
|
||
});
|
||
|
||
describe('CreateAssetCommand with starting props', () => {
|
||
it('creates a sprite wearing the texture at its pixel size, and removes it again', () => {
|
||
const { project, stack } = makeProject();
|
||
const texture = new CreateTextureCommand('Hero', { file: FILE, width: 64, height: 32 });
|
||
stack.execute(texture);
|
||
const sprite = new CreateAssetCommand('sprite', 'Hero 2', spriteFromTexture(project, texture.asset.id));
|
||
stack.execute(sprite);
|
||
|
||
expect(findAsset(project, sprite.asset.id)?.props).toEqual({
|
||
enabled: true,
|
||
scale: 1,
|
||
rotation: 0,
|
||
mirrorX: false,
|
||
mirrorY: false,
|
||
sortWithParent: true,
|
||
width: 64,
|
||
height: 32,
|
||
color: 0xffffff,
|
||
texture: texture.asset.id,
|
||
shader: '',
|
||
});
|
||
stack.undo();
|
||
expect(findAsset(project, sprite.asset.id)).toBeUndefined();
|
||
stack.redo();
|
||
expect(findAsset(project, sprite.asset.id)?.props.texture).toBe(texture.asset.id);
|
||
});
|
||
|
||
it('passes each value through the schema', () => {
|
||
const { project, stack } = makeProject();
|
||
const sprite = new CreateAssetCommand('sprite', 'Tiny', { width: -5 });
|
||
stack.execute(sprite);
|
||
expect(findAsset(project, sprite.asset.id)?.props.width).toBe(1);
|
||
});
|
||
|
||
it('rejects a property the type does not have, leaving the project untouched', () => {
|
||
const { project, stack } = makeProject();
|
||
expect(() => stack.execute(new CreateAssetCommand('sprite', 'Odd', { zoom: 2 }))).toThrow(CommandError);
|
||
expect(project.assets).toHaveLength(0);
|
||
});
|
||
});
|