A video used to run on its own clock as soon as a sprite wore it. An animation could switch the sprite on and off, but never say which picture shows at which frame. Cutting a video in an animation needs the opposite: the animation sets the time and the video follows. - Sprites wearing a video or a clip get two rows, Video clock and Video time. They show only while the texture holds a video. - With Video clock on Driven the video does not play by itself. It shows the picture at Video time, counted from the clip's start. Past the end it goes round with Loop and holds the last picture without. - Video time is a number like any other, so keys, step, easing and curves give stills, slow motion and ramps. - A driven sprite gets a player of its own, keyed by the wearer's name. The same clip can run twice at different times. - Following has two ways (`videoFollow.ts`). Running forward at 0.25x to 4x the video plays at that rate and is nudged. A still, a scrub or a step backwards seeks, and only the newest seek counts. - Sound is heard only near 1x. The animation tab now plays it too, so a cut can follow the sound. Scrubbing is silent. - Scene, game view, the inspector's PREVIEW and the shader preview show the driven picture. In a running game Play animation sets it. Found on the way: - After a scrub the video in the animation tab kept running. The preview redrew only while the playhead moved, so nobody asked for the video once it stood. `AnimationEditor.tick` now redraws it every frame while it shows a video. - Every sprite has two more defaults (`videoClock: 'free'`, `videoTime: 0`). Eight tests in five files pinned the old list and are updated. Tests: - Unit: video-clock and video-follow new, 4 files with 42 tests green. - e2e 66 (melektaus-atx): ALL PASSED, 22 checks, 3 new. 66i: two sprites on one clip stand at 0.2 s red and 0.7 s green. 66j: a scrub to frames 2, 7, 12 and 3 shows red, green, blue, red, and each colour still stands 0.7 s later. 66k: playing runs 10-30 ms behind at rate 1.00-1.03 and is not muted. - Counterchecks: a seek that keeps the rate turns the seek test red. Not seeing Driven turns 66i, 66j and 66k red. - Gate (melektaus-atx): exit 0, 297 files, 4546 tests. - Not tested in the browser: Play animation in a running game. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
100 lines
4.2 KiB
TypeScript
100 lines
4.2 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,
|
||
keepOnSceneLoad: false,
|
||
scale: 1,
|
||
rotation: 0,
|
||
mirrorX: false,
|
||
mirrorY: false,
|
||
sortWithParent: true,
|
||
renderLayer: -1,
|
||
width: 64,
|
||
height: 32,
|
||
color: 0xffffff,
|
||
texture: texture.asset.id,
|
||
videoClock: 'free',
|
||
videoTime: 0,
|
||
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);
|
||
});
|
||
});
|