Until now every sound went straight to the speakers. There was no point where all of them came together, so nothing could turn the music down against the effects, and a compressor or a shared echo over everything had nowhere to sit. The bus technique of #346 was there already, only the end of the chain was missing. - Bus asset (Audio): Volume, Sound FX and Into. Into is empty for the master and never offers the bus itself nor a bus that already goes into it. The list is worked out when the menu opens, so a change made meanwhile counts. A loop that is in a project anyway sends the buses on it into the master. - The master is no asset. Its volume and sound FX are two new rows under Master in Project settings, one undo step each. A project written before has 1 and none, which is how it sounded. - Sound, instrument, pattern and song have a row Bus, empty for the master. Play sound, Play note, Play pattern and Play song have an input bus: From the asset, Master or a bus. Inside a song or a pattern only the bus of the song or pattern counts. - Set bus volume (bus, volume, time, easing) and Bus volume. An empty bus is the master. The volume set holds for the whole run, across scenes, over that of the asset. GameRun resets it at start and end. Set sound FX parameters without a voice now reaches the sound FX of the bus picked in its new bus input. - SoundLibrary: the master is the bus "mix", each bus "mix:<id>". Every bus, the playing masters of #346 included, ends there, and only the master is heard. setMix sets them up once a context exists, so an editor nobody listened to opens no audio device. The same mix again changes nothing, which lets the editor hand it over on every change of the project. - The tabs play as the game does: Sound, Sound FX, Instrument, Pattern and Song tab through the bus of their asset and the master. - Pause game does nothing to the buses (the user's answer 4b). A game that wants quiet in its pause menu sets a bus volume itself. - Streaming long music files is #349, split off as asked. Finding on the way: the Into menu first worked from a list made when the inspector row was built. After another bus was sent into the open one, e2e 34 saw it still offered. It is now asked on open. The SoundLibrary tests expected voices to end at the destination. They now end in the master, which adds its input, level and pan to every wiring and two gains to every list. Those expectations are updated, nothing else in them changed. Tests: - Unit buses (new): 15 green. Ten counter-checks, each red on its own: loop check, bus picked, reset at run start, bus of Set sound FX parameters, master volume in the settings, and in SoundLibrary default into the master, voices into the master, run volume over the mix, no context before a play, a playing on its bus. - Unit sound-library: 90 green (5 new). Node catalog: 416 green (9 new cases). - e2e 34 (melektaus-atx): ALL PASSED, 75 checks (3 new). The voice of the Sound tab was heard on mix:<bus>, that bus into the other, that one at 0.5 into the master. Master volume 0.6 via the dialog, undo back to 1. - Gate (melektaus-atx): CHECK EXIT 0, 262 files, 4072 tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
182 lines
7.0 KiB
TypeScript
182 lines
7.0 KiB
TypeScript
/**
|
|
* Container assets hold placed objects just like scenes do, so anything that walks "all placed
|
|
* objects" has to cover both. Plus: a rejected undo leaves the stacks usable.
|
|
*/
|
|
import { describe, expect, it } from 'vitest';
|
|
import { type Command, CommandError } from '../../src/core/commands/Command';
|
|
import { CommandStack } from '../../src/core/commands/CommandStack';
|
|
import { CreateContainerCommand } from '../../src/core/commands/containerCommands';
|
|
import { SetOverrideCommand } from '../../src/core/commands/sceneObjectCommands';
|
|
import { RemoveVariableCommand, RenameVariableCommand } from '../../src/core/commands/variableCommands';
|
|
import type { ContainerAsset } from '../../src/core/model/Asset';
|
|
import { findAsset, findObjectHolder, objectHolders } from '../../src/core/model/Project';
|
|
import { defaultSceneVisibility } from '../../src/core/model/sceneVisibility';
|
|
import { instanceChildId } from '../../src/core/model/instance';
|
|
import { findUsages } from '../../src/core/model/usages';
|
|
import { makeBehavior, makeSpriteScene, place } from '../helpers';
|
|
|
|
/** A behavior with a `speed` variable, placed and overridden to 42, then wrapped in a container. */
|
|
function containerWithOverride() {
|
|
const f = makeSpriteScene();
|
|
const behavior = makeBehavior(f, 'B', ['speed']);
|
|
const objectId = place(f, behavior.id, { x: 0, y: 0 });
|
|
f.stack.execute(new SetOverrideCommand(f.sceneId, objectId, 'speed', 42));
|
|
const container = new CreateContainerCommand(f.sceneId, [objectId]);
|
|
f.stack.execute(container);
|
|
const template = () => (findAsset(f.project, container.assetId) as ContainerAsset).objects[0]!;
|
|
// The object moved into the template; what the scene shows is resolved from it.
|
|
const placed = () => f.object(instanceChildId(container.objectId, template().id));
|
|
return { ...f, behaviorId: behavior.id, containerId: container.assetId, objectId, template, placed };
|
|
}
|
|
|
|
describe('object holders', () => {
|
|
it('counts scenes and container assets alike', () => {
|
|
const { project } = containerWithOverride();
|
|
expect(
|
|
objectHolders(project)
|
|
.map((h) => h.type)
|
|
.sort(),
|
|
).toEqual(['container', 'scene']);
|
|
});
|
|
|
|
it('resolves a scene or a container by id, but no other asset', () => {
|
|
const { project, sceneId, containerId, spriteId, behaviorId } = containerWithOverride();
|
|
expect(findObjectHolder(project, sceneId)?.type).toBe('scene');
|
|
expect(findObjectHolder(project, containerId)?.type).toBe('container');
|
|
expect(findObjectHolder(project, spriteId)).toBeUndefined();
|
|
expect(findObjectHolder(project, behaviorId)).toBeUndefined();
|
|
expect(findObjectHolder(project, 'nope')).toBeUndefined();
|
|
});
|
|
|
|
it('finds usages inside container templates, not just in scenes', () => {
|
|
const { project, behaviorId, containerId, template } = containerWithOverride();
|
|
// Only the template: what the scene shows is resolved from it, never stored.
|
|
const usages = findUsages(project, behaviorId);
|
|
expect(usages).toHaveLength(1);
|
|
expect(usages[0]!.holder.id).toBe(containerId);
|
|
expect(template().overrides.speed).toBe(42);
|
|
});
|
|
});
|
|
|
|
describe('RemoveVariableCommand', () => {
|
|
it('clears the override on container templates too, and puts it back on undo', () => {
|
|
const { stack, behaviorId, template, placed } = containerWithOverride();
|
|
|
|
stack.execute(new RemoveVariableCommand(behaviorId, 'speed'));
|
|
expect(placed().overrides.speed).toBeUndefined();
|
|
expect(template().overrides.speed).toBeUndefined();
|
|
|
|
stack.undo();
|
|
expect(placed().overrides.speed).toBe(42);
|
|
expect(template().overrides.speed).toBe(42);
|
|
});
|
|
});
|
|
|
|
/**
|
|
* A behavior inside a placed container is not stored in the scene, and a value changed on it lives
|
|
* in the instance's `instanceEdits`. Anything rewriting overrides project-wide has to reach in
|
|
* there, or renaming a variable silently drops the value.
|
|
*/
|
|
describe('variables overridden on container content', () => {
|
|
function withInstanceEdit() {
|
|
const f = containerWithOverride();
|
|
f.stack.execute(new SetOverrideCommand(f.sceneId, f.placed().id, 'speed', 7));
|
|
const edits = () =>
|
|
f.sceneOf().objects.find((o) => o.id !== f.objectId)!.instanceEdits[f.template().id]!.overrides;
|
|
return { ...f, edits };
|
|
}
|
|
|
|
it('renames the key kept on the instance', () => {
|
|
const { stack, behaviorId, edits, placed } = withInstanceEdit();
|
|
expect(edits().speed).toBe(7);
|
|
stack.execute(new RenameVariableCommand(behaviorId, 'speed', 'velocity'));
|
|
expect(edits().speed).toBeUndefined();
|
|
expect(edits().velocity).toBe(7);
|
|
expect(placed().overrides.velocity).toBe(7);
|
|
stack.undo();
|
|
expect(edits().speed).toBe(7);
|
|
});
|
|
|
|
it('removes the value kept on the instance, and puts it back on undo', () => {
|
|
const { stack, behaviorId, edits } = withInstanceEdit();
|
|
stack.execute(new RemoveVariableCommand(behaviorId, 'speed'));
|
|
expect(edits().speed).toBeUndefined();
|
|
stack.undo();
|
|
expect(edits().speed).toBe(7);
|
|
});
|
|
});
|
|
|
|
describe('RenameVariableCommand', () => {
|
|
it('renames the override on container templates too', () => {
|
|
const { stack, behaviorId, template } = containerWithOverride();
|
|
stack.execute(new RenameVariableCommand(behaviorId, 'speed', 'velocity'));
|
|
expect(template().overrides.speed).toBeUndefined();
|
|
expect(template().overrides.velocity).toBe(42);
|
|
|
|
stack.undo();
|
|
expect(template().overrides.speed).toBe(42);
|
|
expect(template().overrides.velocity).toBeUndefined();
|
|
});
|
|
});
|
|
|
|
class RefusingUndo implements Command {
|
|
readonly label = 'Refusing';
|
|
execute(project: { name: string }): void {
|
|
project.name = 'executed';
|
|
}
|
|
undo(): void {
|
|
throw new CommandError('target is gone');
|
|
}
|
|
}
|
|
|
|
describe('CommandStack', () => {
|
|
it('keeps a command on the undo stack when its undo is rejected', () => {
|
|
const { project, stack } = makeSpriteScene();
|
|
stack.execute(new RefusingUndo());
|
|
expect(stack.canUndo).toBe(true);
|
|
|
|
expect(() => stack.undo()).toThrow(CommandError);
|
|
// Not swallowed by the history: still undoable, and not queued for redo.
|
|
expect(stack.canUndo).toBe(true);
|
|
expect(stack.canRedo).toBe(false);
|
|
expect(project.name).toBe('executed');
|
|
});
|
|
|
|
it('keeps a command on the redo stack when its redo is rejected', () => {
|
|
const project = {
|
|
formatVersion: 1,
|
|
id: 'p',
|
|
name: 'P',
|
|
assets: [],
|
|
activeSceneId: '',
|
|
startSceneId: '',
|
|
plugins: [],
|
|
collisionLayers: ['Default'],
|
|
renderLayers: ['Default'],
|
|
masterVolume: 1,
|
|
masterFx: '',
|
|
symbolScale: 1,
|
|
playFrom: 'start' as const,
|
|
whilePlaying: 'live' as const,
|
|
gameScale: 1,
|
|
gameLinkZoom: 'auto' as const,
|
|
sceneVisibility: defaultSceneVisibility(),
|
|
};
|
|
const stack = new CommandStack(project);
|
|
let failing = false;
|
|
stack.execute({
|
|
label: 'Toggle',
|
|
execute: () => {
|
|
if (failing) throw new CommandError('nope');
|
|
},
|
|
undo: () => {},
|
|
});
|
|
stack.undo();
|
|
failing = true;
|
|
|
|
expect(() => stack.redo()).toThrow(CommandError);
|
|
expect(stack.canRedo).toBe(true);
|
|
expect(stack.canUndo).toBe(false);
|
|
});
|
|
});
|