Measure a deviation against the base, not the innermost template

An instance edit was dropped as soon as its value matched the template
object. With nested containers the template is not what the value falls
back to: the outer container holds an edit for the object below it, and
that one wins. If the inner template happened to carry the same value the
user typed, the edit was thrown away and the value jumped to whatever the
container in between says.

Reported against the Jump-and-Run project: a coin narrowed to 8 inside
"level", then set back to the sprite's own 24 in the scene, snapped back
to 8. Reproduced through the inspector before touching anything.

InstanceTarget now offers `base`: the template with the edits of every
container in between woven in. Everything that judges deviation uses it -
setOverride/setName/setPosition, both Revert commands, and the gold marks
in the inspector. Writing still goes into the real template, which is
where "apply to container" belongs.

`base` is built on every read. Apply writes into the template and then
asks whether the edit still deviates, so a base captured beforehand would
answer for the template as it was - the e2e suite caught exactly that.

Also in here, because it corrects the commit before it: placing an asset
by double-clicking its row is gone, as asked for in asset-doppelklick.md.
Dragging is the only way to place now. That took AssetPanel.place, the
PlacementTarget interface, Editor.placementTarget and the two worldCenter()
methods that existed only to feed it. A double-click on a scene asset still
makes it the active scene.
This commit is contained in:
root committed 2026-09-09 13:45:27 +02:00
1 parent 75d377af39
commit d7c8d3e579
16 files changed
+180 -77

No files matched your search

+58 -1
View File
@@ -107,12 +107,15 @@ describe('position apply / revert', () => {
describe('override apply / revert', () => {
it('applies an override to the container template and to instances that had no own value', () => {
const { stack, sceneId, a, a2, object, templateOfA } = setup();
const { stack, sceneId, a, a2, object, templateOfA, sceneOf, instanceId } = setup();
stack.execute(new SetOverrideCommand(sceneId, a, 'width', 77));
stack.execute(new ApplyOverrideToContainerCommand(sceneId, a, 'width'));
expect(templateOfA().overrides.width).toBe(77);
expect(object(a2).overrides.width).toBe(77);
expect(object(a).overrides.width).toBe(77);
// The template carries it now, so nothing is left to deviate – the edit has to be gone, not
// merely equal. It is dropped by comparing against a base read *after* the write.
expect(sceneOf().objects.find((o) => o.id === instanceId)!.instanceEdits).toEqual({});
stack.undo();
expect(templateOfA().overrides.width).toBeUndefined();
expect(object(a2).overrides.width).toBeUndefined();
@@ -173,3 +176,57 @@ describe('override apply / revert', () => {
expect(object(a2).overrides.height).toBe(9);
});
});
/**
* A container inside a container: the value a scene edit falls back to is the template *plus* the
* edits of every container in between – not the innermost template alone.
*/
function nested() {
const f = makeSpriteScene();
const inner = new CreateContainerCommand(f.sceneId, [place(f, f.spriteId, { x: 0, y: 0 })]);
f.stack.execute(inner);
const innerAsset = () => findAsset(f.project, inner.assetId) as ContainerAsset;
const leaf = innerAsset().objects[0]!.id;
// The sprite is 100 wide anyway: an override carrying the asset's own value, the way putting a
// value back by hand in a container editor leaves one behind.
f.stack.execute(new SetOverrideCommand(inner.assetId, leaf, 'width', 100));
const outer = new CreateContainerCommand(f.sceneId, [inner.objectId]);
f.stack.execute(outer);
const outerAsset = () => findAsset(f.project, outer.assetId) as ContainerAsset;
const middle = outerAsset().objects[0]!.id;
// Inside the outer container, that one sprite is narrowed to 8.
f.stack.execute(new SetOverrideCommand(outer.assetId, instanceChildId(middle, leaf), 'width', 8));
return { ...f, leaf, deep: instanceChildId(outer.objectId, `${middle}/${leaf}`) };
}
describe('a base two levels up', () => {
it('keeps a scene value that equals the inner template but not the container in between', () => {
const { stack, sceneId, deep, object } = nested();
expect(object(deep).overrides.width).toBe(8);
stack.execute(new SetOverrideCommand(sceneId, deep, 'width', 10));
expect(object(deep).overrides.width).toBe(10);
// 100 is what the innermost template says – but the container in between says 8, so this is
// a deviation and has to be kept. Comparing against the template alone dropped it.
stack.execute(new SetOverrideCommand(sceneId, deep, 'width', 100));
expect(object(deep).overrides.width).toBe(100);
stack.undo();
expect(object(deep).overrides.width).toBe(10);
});
it('resets to the value the container in between gives, not to the inner template', () => {
const { stack, sceneId, deep, object } = nested();
stack.execute(new SetOverrideCommand(sceneId, deep, 'width', 100));
stack.execute(new RevertOverrideToTemplateCommand(sceneId, deep, 'width'));
expect(object(deep).overrides.width).toBe(8);
});
it('drops an edit that matches the base, so the value follows again', () => {
const { stack, sceneId, deep, object, sceneOf } = nested();
stack.execute(new SetOverrideCommand(sceneId, deep, 'width', 8));
const instance = sceneOf().objects.find((o) => o.id === deep.split('~')[0])!;
expect(instance.instanceEdits).toEqual({});
expect(object(deep).overrides.width).toBe(8);
});
});