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>
158 lines
5.5 KiB
TypeScript
158 lines
5.5 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: '',
|
||
videoClock: 'free',
|
||
videoTime: 0,
|
||
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: '',
|
||
videoClock: 'free',
|
||
videoTime: 0,
|
||
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: '',
|
||
videoClock: 'free',
|
||
videoTime: 0,
|
||
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');
|
||
});
|
||
});
|