Paint an asset's name gold while any of its values deviates
The inspector already marked an asset value that differs from its schema default, but the Assets panel gave no hint, so a changed asset looked like an untouched one until you opened it. The rule sits next to the existing objectDeviates as a pure function: assetDeviates asks whether any marked property differs, markedAssetSchema says which rows the inspector marks at all. buildAssetSection now builds its rows from that same list, replacing the behavior/rest split it used to carry, so the list cannot claim a deviation the inspector then fails to show. A behavior's variables are deliberately not in it. Their default is declared on the variable itself, which means the asset value *is* that default; counting them would paint the fixture's Mover gold while the inspector beside it marks nothing.
This commit is contained in:
1 parent
e0d43e12aa
commit
e9634f0f0d
10 files changed
+166
-15
No files matched your search
@@ -1,5 +1,11 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import {
|
||||
CreateAssetCommand,
|
||||
ResetAssetPropertyCommand,
|
||||
SetAssetPropertyCommand,
|
||||
} from '../../src/core/commands/assetCommands';
|
||||
import { CreateContainerCommand } from '../../src/core/commands/containerCommands';
|
||||
import { AddVariableCommand } from '../../src/core/commands/variableCommands';
|
||||
import {
|
||||
ClearOverrideCommand,
|
||||
SetOverrideCommand,
|
||||
@@ -8,8 +14,8 @@ import {
|
||||
import { instanceChildId } from '../../src/core/model/instance';
|
||||
import { findAsset } from '../../src/core/model/Project';
|
||||
import type { ContainerAsset } from '../../src/core/model/Asset';
|
||||
import { deviationMarks, objectDeviates } from '../../src/core/properties/deviation';
|
||||
import { makeSpriteScene, place } from '../helpers';
|
||||
import { assetDeviates, deviationMarks, objectDeviates } from '../../src/core/properties/deviation';
|
||||
import { makeProject, makeSpriteScene, place } from '../helpers';
|
||||
|
||||
describe('deviation marks', () => {
|
||||
it('marks an object only once an override really deviates', () => {
|
||||
@@ -48,3 +54,37 @@ describe('deviation marks', () => {
|
||||
expect([...deviationMarks(f.project, f.sceneOf())].sort()).toEqual([content, create.objectId].sort());
|
||||
});
|
||||
});
|
||||
|
||||
describe('asset deviation', () => {
|
||||
const makeAsset = (type: 'sprite' | 'behavior', name: string) => {
|
||||
const f = makeProject();
|
||||
const create = new CreateAssetCommand(type, name);
|
||||
f.stack.execute(create);
|
||||
const asset = () => findAsset(f.project, create.asset.id)!;
|
||||
expect(asset().type).toBe(type);
|
||||
return { ...f, asset, assetId: create.asset.id };
|
||||
};
|
||||
|
||||
it('marks an asset only once a property really differs from its default', () => {
|
||||
const f = makeAsset('sprite', 'Box');
|
||||
expect(assetDeviates(f.asset())).toBe(false);
|
||||
// Written, but the default value – the inspector shows no gold, so neither does the list.
|
||||
f.stack.execute(new SetAssetPropertyCommand(f.assetId, 'width', 100));
|
||||
expect(f.asset().props.width).toBe(100);
|
||||
expect(assetDeviates(f.asset())).toBe(false);
|
||||
f.stack.execute(new SetAssetPropertyCommand(f.assetId, 'width', 250));
|
||||
expect(assetDeviates(f.asset())).toBe(true);
|
||||
f.stack.execute(new ResetAssetPropertyCommand(f.assetId, 'width'));
|
||||
expect(assetDeviates(f.asset())).toBe(false);
|
||||
});
|
||||
|
||||
it('leaves a behavior unmarked for its variables, which the inspector does not mark either', () => {
|
||||
const f = makeAsset('behavior', 'Mover');
|
||||
f.stack.execute(new AddVariableCommand(f.assetId, 'speed', 'number'));
|
||||
f.stack.execute(new SetAssetPropertyCommand(f.assetId, 'speed', 42));
|
||||
expect(f.asset().props.speed).toBe(42);
|
||||
expect(assetDeviates(f.asset())).toBe(false);
|
||||
f.stack.execute(new SetAssetPropertyCommand(f.assetId, 'enabled', false));
|
||||
expect(assetDeviates(f.asset())).toBe(true);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user