A trailer needs its music and its clips to come in softly and leave
softly. Until now an item of a composition could only play at one
level, and a video item could not even be turned down on its own.
- Every item with sound gets a grip at its upper left and upper right
corner. Dragging one inwards fades the item in or out. Dragging it
back to the edge removes the fade. Lower down the same edge still
trims as before.
- The fade is drawn as its curve, with the part above it darkened.
The inspector shows Fade in and Fade out in seconds, each with the
curves sound clips already know.
- The model keeps fadeIn and fadeOut in frames plus curveIn and
curveOut on the item. Old projects load unchanged. An item shorter
than its fades plays them cut to its length but keeps the setting.
- Sound, pattern and song items ramp the gain of their own bus. The
scheduler plans the ramps on the audio clock next to the notes.
Starting in the middle of a fade picks it up from there.
- Video items set the new sprite property Video volume each frame.
It multiplies with the fade and is only shown for a driven video.
The player glides to each new level over 15 ms so it does not click
between frames.
Not covered: a container item that carries a video further down gets
no grips. Only a video on the item's own sprite counts.
Tests:
- tsc, eslint, Prettier clean.
- Unit tests for composition, music, song and sound (12 files): 269
passed, 7 of them new.
- e2e 69 on melektaus-atx: ALL PASSED, 21 checks. 69p drags a grip to
a fade in of 10 frames and hears the item bus rise from 0.127 over
0.229 and 0.339 to 1 within one second.
- Counter-checks as unit tests: without the audio ramps, and without
the level on the video sprite in the game, both go red.
- Gate on melektaus-atx: 309 files, 4796 tests passed, 8 more than
at 77ac9d1. The first run failed 14 tests in 6 files that list the
default sprite properties or the bus levels in full. They now
expect videoVolume and the new level field of busLevels.
- Not tried in a browser: video fades, pattern and song items with a
fade.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
161 lines
5.6 KiB
TypeScript
161 lines
5.6 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,
|
||
videoVolume: 1,
|
||
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,
|
||
videoVolume: 1,
|
||
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,
|
||
videoVolume: 1,
|
||
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');
|
||
});
|
||
});
|