Let the project set the size of scene view symbols
game-maker / gate (push) Successful in 3m0s
game-maker / suite (push) Failing after 9m27s

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>
This commit is contained in:
adminandClaude Opus 5.5 committed 2026-09-24 10:55:42 +02:00
1 parent 5399ef17e5
commit 5afb70a92e
14 files changed
+233 -23

No files matched your search

+12 -4
View File
@@ -1,7 +1,11 @@
/**
* Loading, creating, switching and deleting projects, plus the top bar's menu that triggers it.
*/
import { RenameProjectCommand, SetCollisionLayersCommand } from '../core/commands/projectCommands';
import {
RenameProjectCommand,
SetCollisionLayersCommand,
SetSymbolScaleCommand,
} from '../core/commands/projectCommands';
import type { ProjectStore } from '../core/store/ProjectStore';
import { Dialog, Menu, type MenuEntry, type Widget } from '../ui';
import { dialogSlot } from './FormDialog';
@@ -137,9 +141,10 @@ export class ProjectSession {
}
/**
* Name, the scene Play starts and the collision layers (#152) in one dialog (#183). The name and
* the layers are undo steps of their own – one each, and only for what actually changed; which
* scene Play starts is a preference of this browser, not of the project (see `settings.ts`).
* Name, the scene Play starts, the symbol scale and the collision layers (#152) in one dialog
* (#183). Name, symbol scale and layers are undo steps of their own – one each, and only for what
* actually changed; which scene Play starts is a preference of this browser, not of the project
* (see `settings.ts`).
*/
openProjectSettings(): ProjectSettingsDialog {
const { project } = this.state;
@@ -147,6 +152,7 @@ export class ProjectSession {
name: project.name,
playFrom: this.state.playFrom,
collisionLayers: [...project.collisionLayers],
symbolScale: project.symbolScale,
};
return this.settingsDialog.open(
new ProjectSettingsDialog(before, (settings) => {
@@ -154,6 +160,8 @@ export class ProjectSession {
if (change.name !== undefined) this.state.execute(new RenameProjectCommand(change.name));
if (change.collisionLayers !== undefined)
this.state.execute(new SetCollisionLayersCommand(change.collisionLayers));
if (change.symbolScale !== undefined)
this.state.execute(new SetSymbolScaleCommand(change.symbolScale));
this.state.setPlayFrom(change.playFrom);
}),
);
+41 -8
View File
@@ -1,5 +1,6 @@
import { layerFallback, MAX_COLLISION_LAYERS } from '../core/model/collisionLayers';
import { Button, HStack, Label, Menu, TextField, Theme, VStack } from '../ui';
import { clampSymbolScale, SYMBOL_SCALE_MAX, SYMBOL_SCALE_MIN } from '../core/model/symbolScale';
import { Button, HStack, Label, Menu, NumberField, TextField, Theme, VStack } from '../ui';
import type { PlayFrom } from './settings';
import { FormDialog } from './FormDialog';
@@ -8,6 +9,7 @@ export interface ProjectSettings {
name: string;
playFrom: PlayFrom;
collisionLayers: string[];
symbolScale: number;
}
/**
@@ -21,13 +23,15 @@ export interface ProjectSettings {
export function settingsChanges(
before: ProjectSettings,
after: ProjectSettings,
): { name?: string; collisionLayers?: string[]; playFrom: PlayFrom } {
): { name?: string; collisionLayers?: string[]; symbolScale?: number; playFrom: PlayFrom } {
const name = after.name.trim() || before.name;
const symbolScale = clampSymbolScale(after.symbolScale);
return {
...(name === before.name ? {} : { name }),
...(JSON.stringify(after.collisionLayers) === JSON.stringify(before.collisionLayers)
? {}
: { collisionLayers: [...after.collisionLayers] }),
...(symbolScale === before.symbolScale ? {} : { symbolScale }),
playFrom: after.playFrom,
};
}
@@ -38,9 +42,9 @@ const PLAY_FROM_LABEL: Record<PlayFrom, string> = {
};
/**
* Everything about the project that is not an asset (#183): its name, which scene Play starts, and
* the collision layers (#152). The top bar carries icons only, so this is the one place the three
* are edited.
* Everything about the project that is not an asset (#183): its name, which scene Play starts, the
* size of the scene view's symbol icons, and the collision layers (#152). The top bar carries icons
* only, so this is the one place they are edited.
*
* Colliders name a layer by its *number*, so a layer taken out of the middle would silently move
* every collider below it onto another one; only the last layer can be removed, and the list is
@@ -50,8 +54,10 @@ export class ProjectSettingsDialog extends FormDialog {
private projectName: string;
private playFrom: PlayFrom;
private layers: string[];
private symbolScale: number;
private readonly nameField: TextField;
private readonly playFromButton: Button;
private readonly symbolScaleField: NumberField;
private readonly rows = new VStack({ gap: Theme.gap });
private readonly addButton: Button;
@@ -60,6 +66,7 @@ export class ProjectSettingsDialog extends FormDialog {
this.projectName = settings.name;
this.playFrom = settings.playFrom;
this.layers = [...settings.collisionLayers];
this.symbolScale = clampSymbolScale(settings.symbolScale);
this.nameField = new TextField(this.projectName, {
placeholder: 'Project name',
@@ -82,6 +89,26 @@ export class ProjectSettingsDialog extends FormDialog {
}),
);
this.symbolScaleField = new NumberField(this.symbolScale, {
width: 150,
min: SYMBOL_SCALE_MIN,
max: SYMBOL_SCALE_MAX,
step: 0.01,
decimals: 2,
onInput: (value) => {
this.symbolScale = value;
},
onChange: (value) => {
this.symbolScale = value;
},
});
this.content.add(this.formRow(this.fieldLabel('Symbol scale'), this.symbolScaleField));
this.content.add(
new Label(`Size of the icons in the scene view, ${SYMBOL_SCALE_MIN} to ${SYMBOL_SCALE_MAX}.`, {
style: 'muted',
}),
);
this.content.add(new Label('Collision layers', { style: 'bodyBold' }));
this.content.add(
new Label('Two colliders meet only when each one names the layer of the other.', {
@@ -97,6 +124,7 @@ export class ProjectSettingsDialog extends FormDialog {
name: this.projectName,
playFrom: this.playFrom,
collisionLayers: this.layers,
symbolScale: this.symbolScale,
}),
);
this.buildLayers();
@@ -107,9 +135,9 @@ export class ProjectSettingsDialog extends FormDialog {
return [...this.layers];
}
/** Name and start-scene switch as they stand (test hook). */
values(): { name: string; playFrom: PlayFrom } {
return { name: this.projectName, playFrom: this.playFrom };
/** Name, start-scene switch and symbol scale as they stand (test hook). */
values(): { name: string; playFrom: PlayFrom; symbolScale: number } {
return { name: this.projectName, playFrom: this.playFrom, symbolScale: this.symbolScale };
}
/** The start-scene switch itself, so a check can click it. */
@@ -117,6 +145,11 @@ export class ProjectSettingsDialog extends FormDialog {
return this.playFromButton;
}
/** The symbol scale field, so a check can type into it. */
get symbolScaleControl(): NumberField {
return this.symbolScaleField;
}
/** A label and a field that takes the rest of the row – the layer rows are built the same way. */
private labelledRow(text: string, field: TextField): HStack {
const row = new HStack({ gap: Theme.gap, align: 'center' });
+6 -1
View File
@@ -220,13 +220,18 @@ export function uiHooks({ app, state, editor }: HookContext) {
project: [...state.project.collisionLayers],
dialog: editor.projectSettingsDialog()?.layerNames() ?? null,
}),
/** The "Project settings" dialog (#183): name and start-scene switch as its fields stand. */
/** The "Project settings" dialog (#183): name, start-scene switch and symbol scale as its fields stand. */
projectSettings: () => editor.projectSettingsDialog()?.values() ?? null,
/** Where to click the start-scene switch inside that dialog. */
projectSettingsPlayFromAt: () => {
const dialog = editor.projectSettingsDialog();
return dialog ? centreOf(dialog.playFromControl) : null;
},
/** Where to click the symbol scale field inside that dialog. */
projectSettingsSymbolScaleAt: () => {
const dialog = editor.projectSettingsDialog();
return dialog ? centreOf(dialog.symbolScaleControl) : null;
},
/** The "Open project" dialog (#183): the projects it lists and the row picked. */
projectPicker: () => editor.projectPickerDialog()?.info() ?? null,
/** The dividers left and right of the centre column – dragging them narrows the tab row. */
+17 -9
View File
@@ -16,13 +16,12 @@ import {
invert,
linearOf,
type Mat,
translation,
} from '../../core/model/matrix';
import { placementRejection } from '../../core/model/placement';
import type { Position, Vec2 } from '../../core/model/Properties';
import { findAsset, type ObjectHolder } from '../../core/model/Project';
import { cellAtPoint } from '../../core/model/tilemap';
import { footprintCorners } from '../../core/properties/bounds';
import { footprintCorners, iconCorners } from '../../core/properties/bounds';
import { localMatrixOf, parentTransform, transformOf } from '../../core/properties/transform';
import { FramePreview } from '../framePreview';
import { type EditorState, objectSelection } from '../state';
@@ -582,7 +581,7 @@ export class SceneViewport extends FreeViewport {
return this.solids.info(this.lastItems.find((i) => i.id === id));
}
/** The icon of a symbol in world units, the name beside it and whether it hangs off its owner (test hook). */
/** The icon of a symbol in world units (its side as `size`), the name beside it and whether it hangs off its owner (test hook). */
iconInfo(id: string): {
layer: string;
visible: boolean;
@@ -592,6 +591,7 @@ export class SceneViewport extends FreeViewport {
y: number;
screen: Vec2;
clickable: boolean;
size: number;
} | null {
const icon = this.icons.get(id);
if (!icon) return null;
@@ -606,6 +606,7 @@ export class SceneViewport extends FreeViewport {
y: icon.position.y,
screen: { x: screen.x, y: screen.y },
clickable: icon.eventMode !== 'none',
size: icon.scale.x * SYMBOL_GRID,
};
}
@@ -628,7 +629,6 @@ export class SceneViewport extends FreeViewport {
if (!icon) {
icon = new Graphics();
drawSymbolIcon(icon, item.type as SymbolIcon);
icon.scale.set(SYMBOL_SIZE / SYMBOL_GRID);
const half = SYMBOL_GRID / 2 + SYMBOL_OUTLINE;
icon.hitArea = new Rectangle(-half, -half, half * 2, half * 2);
icon.cursor = 'move';
@@ -636,10 +636,16 @@ export class SceneViewport extends FreeViewport {
this.icons.set(item.id, icon);
this.iconLayer.addChild(icon);
}
icon.scale.set((SYMBOL_SIZE * this.symbolScale()) / SYMBOL_GRID);
icon.visible = true;
icon.eventMode = 'static';
}
/** The project's factor for icon size, spacing and the outline of an icon-only symbol. */
private symbolScale(): number {
return this.state.project.symbolScale;
}
/**
* Puts every icon where `layoutSymbols` says – on its object, or on a ring round a spot several
* want – and each name beside its icon, on the outer side of a ring. Switched-off objects draw no
@@ -652,8 +658,8 @@ export class SceneViewport extends FreeViewport {
const anchors = items
.filter((item) => item.enabled && hasSceneIcon(item.type))
.map((item) => ({ id: item.id, x: item.x, y: item.y }));
this.spots = layoutSymbols(anchors, SYMBOL_SPACING);
const gap = SYMBOL_SIZE / 2 + 4 / scale;
this.spots = layoutSymbols(anchors, SYMBOL_SPACING * this.symbolScale());
const gap = (SYMBOL_SIZE * this.symbolScale()) / 2 + 4 / scale;
for (const [id, spot] of this.spots) {
this.icons.get(id)?.position.set(spot.x, spot.y);
const label = this.labels.get(id);
@@ -756,11 +762,13 @@ export class SceneViewport extends FreeViewport {
const item = items.find((i) => i.id === id);
if (!item) continue;
// Two screen pixels outside the footprint, whichever way it is turned. A symbol that is
// only its icon is outlined where the icon stands, which need not be its position.
// only its icon is outlined where the icon stands, which need not be its position, and
// at the icon's size.
const spot = ICON_ONLY.has(item.type) ? this.spots.get(id) : undefined;
const m = spot ? translation(spot.x, spot.y) : item.m;
const corners = this.screenCorners(
footprintCorners(item.type, item.props, m, 2 / view.scale, item.frame),
spot
? iconCorners(item.type, item.props, spot, this.symbolScale(), 2 / view.scale)
: footprintCorners(item.type, item.props, item.m, 2 / view.scale, item.frame),
view,
);
// A switched-off object draws nothing, so its outline is the only way to see where it