Pixel art projects draw at very different sizes, so the fixed 18 px icons of behaviors, containers and rigidbodies were too big in some projects and too small in others. The size now lives in the project settings and travels with the project. - New field Symbol scale in the project settings dialog, below Play starts. It takes 0.1 to 4 with two decimals and defaults to 1. - The value is stored as project.symbolScale. Older projects load with 1, and values out of range are clamped on load. - Every change is its own undo step through a project command. - The factor scales the icon size, the spacing of icons that share a spot, the label offset and the selection frame of icon-only symbols. - The footprints in bounds.ts that Fit uses stay as they were. The hit area follows the icon, so clicks match what is drawn. - uiHooks reports the icon size so e2e can measure it. The e2e sum in the README is 1375. That is 1374 plus one new check, and 1374 itself has not been confirmed by CI yet. Tests: - ./check.sh: 157 files, 2326 tests, CHECK EXIT 0 (before 2320). - New tests/core/symbol-scale.test.ts with 5 tests (default, save and load, clamping, undo, icon frame), one more in project-settings.test.ts. - e2e 46f: dialog opens with 1, 0.5 plus Apply gives a 9 px icon, undo gives 18 again. Module 46: ALL PASSED, 13 checks. - Counter checks: without loading the value the save and load test fails. With the icon ignoring the factor exactly 46f fails. Both originals restored per cmp. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
52 lines
2.3 KiB
TypeScript
52 lines
2.3 KiB
TypeScript
/**
|
|
* The project's symbol scale: how large the scene view draws its icons, 0.1 to 4, default 1.
|
|
*/
|
|
import { describe, expect, it } from 'vitest';
|
|
import { SetSymbolScaleCommand } from '../../src/core/commands/projectCommands';
|
|
import { createEmptyProject } from '../../src/core/model/Project';
|
|
import { symbolScaleOf } from '../../src/core/model/symbolScale';
|
|
import { footprintOf, iconCorners } from '../../src/core/properties/bounds';
|
|
import { deserializeProject, serializeProject } from '../../src/core/store/serialize';
|
|
|
|
describe('symbol scale', () => {
|
|
it('is 1 in a new project and in one written before there was any', () => {
|
|
expect(createEmptyProject('p', 'P').symbolScale).toBe(1);
|
|
expect(deserializeProject({ id: 'p', name: 'P', assets: [] }).symbolScale).toBe(1);
|
|
});
|
|
|
|
it('survives a save and a load', () => {
|
|
const project = { ...createEmptyProject('p', 'P'), symbolScale: 0.25 };
|
|
expect(deserializeProject(serializeProject(project)).symbolScale).toBe(0.25);
|
|
});
|
|
|
|
it('reads untrusted JSON into the range 0.1 to 4', () => {
|
|
expect(symbolScaleOf({ symbolScale: 0.05 })).toBe(0.1);
|
|
expect(symbolScaleOf({ symbolScale: 12 })).toBe(4);
|
|
expect(symbolScaleOf({ symbolScale: 2.5 })).toBe(2.5);
|
|
expect(symbolScaleOf({ symbolScale: '2' })).toBe(1);
|
|
expect(symbolScaleOf({ symbolScale: Number.NaN })).toBe(1);
|
|
expect(symbolScaleOf(null)).toBe(1);
|
|
});
|
|
|
|
it('is one undo step, clamped like a loaded project', () => {
|
|
const project = createEmptyProject('p', 'P');
|
|
const command = new SetSymbolScaleCommand(7);
|
|
command.execute(project);
|
|
expect(project.symbolScale).toBe(4);
|
|
command.undo(project);
|
|
expect(project.symbolScale).toBe(1);
|
|
});
|
|
|
|
it('grows the outline of an icon-only symbol with the icon, the padding stays', () => {
|
|
const { w } = footprintOf('behavior', {});
|
|
const at = { x: 100, y: 50 };
|
|
const half = (corners: { x: number }[]) => (corners[1]!.x - corners[0]!.x) / 2;
|
|
expect(half(iconCorners('behavior', {}, at, 1))).toBe(w / 2);
|
|
expect(half(iconCorners('behavior', {}, at, 0.5))).toBe(w / 4);
|
|
expect(half(iconCorners('behavior', {}, at, 2, 3))).toBe(w + 3);
|
|
const corners = iconCorners('behavior', {}, at, 0.5);
|
|
expect((corners[0]!.x + corners[2]!.x) / 2).toBe(100);
|
|
expect((corners[0]!.y + corners[2]!.y) / 2).toBe(50);
|
|
});
|
|
});
|