Files
adminandClaude Opus 5.5 ded71a92c9
game-maker / gate (push) Successful in 2m32s
game-maker / suite (push) Failing after 10m45s
Pick the target of an object variable in the Scene View (#276)
Choosing the target of an object variable meant finding its name in
a dropdown. With many objects, or several with the same sprite, the
name alone does not say which one it is. The eyedropper lets you
click the object where you see it instead.

- Every object dropdown gets an eyedropper button next to it. This
  covers variables, struct fields and list entries, in the Inspector
  and in the Variables tab.
- The button opens the Scene View or the container tab the object
  lives in. A strip above the view names the field and the current
  candidate and offers Take and Cancel. The cursor is a crosshair.
- A click picks a candidate and writes nothing yet. The candidate
  gets its own cyan frame, the selection stays on the object with
  the variable.
- Clicking follows the selection rule. `pickOn` in
  `src/viewport/pick.ts` uses `pressOn` and only counts objects the
  dropdown offers. A click on empty space keeps the candidate.
- Enter or Take writes through the same handlers as the dropdown.
  That is one undo step, or none if nothing changes.
- Esc, Cancel, a right click in the view or a second click on the
  button cancel without writing. So do a tab switch, another
  selection, undo, redo, play and loading a project.
- After Take or Cancel the editor goes back to the tab the pick came
  from.
- While the eyedropper runs, the view does not drag, marquee, paint,
  show handles or open its context menu. Panning and zooming stay.

Found on the way:

- Started from the Variables tab, the click missed the object. The
  Scene View is hidden while that tab is open, and the layout skips
  hidden children. The strip appeared then, the view moved down by
  32 px but kept its old height. `Editor.display()` now lays the row
  out again after showing it.

Tests (on melektaus-atx):

- unit pick and object-pick: 27 passed, 13 new
- gate: 196 files, 2844 tests, CHECK EXIT 0. Two more come from
  svg-icons, which checks every icon twice.
- e2e 57: ALL PASSED, 12 checks, 5 new (57e to 57g)
- Counter-checks work. Without the layout fix 57g fails. Picking
  objects the dropdown does not offer fails 2 tests. Writing on
  cancel fails 2 more.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-30 06:31:41 +02:00

162 lines
5.4 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import type { DrawItem } from '../../src/viewport/items';
import { menuTargetOf, pickOn, pressOn, stackAt } from '../../src/viewport/pick';
/** Only what the pick order reads: the type, the `z`, and a map's layers with their own `z`. */
function item(
id: string,
type: DrawItem['type'],
z: number,
layers: { id: string; z: number }[] = [],
): DrawItem {
return {
id,
type,
z,
tilemap: type === 'tilemap' ? { layers: layers.map((l) => ({ ...l, tiles: [] })) } : null,
} as unknown as DrawItem;
}
describe('what lies under the pointer (#203)', () => {
const map = item('map', 'tilemap', 0, [
{ id: 'ground', z: -5 },
{ id: 'roofs', z: 5 },
]);
const hero = item('hero', 'sprite', -1);
it('puts a sprite in front of a map whose only tile there is on a layer below it', () => {
expect(
stackAt(
[map, hero],
[
{ id: 'map', layers: ['ground'] },
{ id: 'hero', layers: null },
],
),
).toEqual(['hero', 'map']);
});
it('puts the map in front where a layer above the sprite has a tile', () => {
expect(
stackAt(
[map, hero],
[
{ id: 'map', layers: ['ground', 'roofs'] },
{ id: 'hero', layers: null },
],
),
).toEqual(['map', 'hero']);
});
it('leaves out a map without a tile under the pointer', () => {
expect(
stackAt(
[map, hero],
[
{ id: 'map', layers: [] },
{ id: 'hero', layers: null },
],
),
).toEqual(['hero']);
});
it('orders sprites by z, ties in hierarchy order, with symbols in front of all', () => {
const items = [
item('a', 'sprite', 2),
item('b', 'sprite', 0),
item('c', 'sprite', 2),
item('box', 'collider', -9),
];
const hits = items.map((i) => ({ id: i.id, layers: null }));
expect(stackAt(items, hits)).toEqual(['box', 'c', 'a', 'b']);
});
});
describe('what a press picks (#203)', () => {
const stack = ['top', 'middle', 'bottom'];
it('selects the topmost when nothing selected is under the pointer', () => {
expect(pressOn(stack, ['elsewhere'], 'elsewhere')).toEqual({ select: 'top', onClick: null });
});
it('keeps a selection hidden under others, so a drag moves it', () => {
expect(pressOn(stack, ['bottom'], 'bottom')?.select).toBeNull();
});
it('passes a click on to the next one below, and round to the top again', () => {
expect(pressOn(stack, ['top'], 'top')?.onClick).toBe('middle');
expect(pressOn(stack, ['middle'], 'middle')?.onClick).toBe('bottom');
expect(pressOn(stack, ['bottom'], 'bottom')?.onClick).toBe('top');
});
it('goes on from the primary one of a group', () => {
expect(pressOn(stack, ['top', 'middle'], 'middle')).toEqual({ select: null, onClick: 'bottom' });
});
it('changes nothing on a click when the selected object is alone there', () => {
expect(pressOn(['only'], ['only'], 'only')).toEqual({ select: null, onClick: null });
});
it('is nothing on empty space', () => {
expect(pressOn([], ['top'], 'top')).toBeNull();
});
});
describe('where a click of the eyedropper moves its candidate (#276)', () => {
const stack = ['top', 'middle', 'bottom'];
const all = () => true;
it('takes the topmost when the candidate is not under the pointer', () => {
expect(pickOn(stack, all, null)).toEqual({ candidate: 'top', refused: false });
expect(pickOn(stack, all, 'elsewhere')).toEqual({ candidate: 'top', refused: false });
});
it('passes a click on the candidate on to the next one below, and round to the top again', () => {
expect(pickOn(stack, all, 'top').candidate).toBe('middle');
expect(pickOn(stack, all, 'middle').candidate).toBe('bottom');
expect(pickOn(stack, all, 'bottom').candidate).toBe('top');
});
it('goes over what may be picked only', () => {
const offered = (id: string) => id !== 'middle';
expect(pickOn(stack, offered, 'top').candidate).toBe('bottom');
expect(pickOn(['middle', 'bottom'], offered, null).candidate).toBe('bottom');
});
it('keeps the candidate on empty space, without a word', () => {
expect(pickOn([], all, 'top')).toEqual({ candidate: 'top', refused: false });
expect(pickOn([], all, null)).toEqual({ candidate: null, refused: false });
});
it('keeps the candidate where nothing may be picked, and says so', () => {
expect(pickOn(['middle'], (id) => id !== 'middle', 'top')).toEqual({ candidate: 'top', refused: true });
});
it('stays on the candidate when it is all that may be picked there', () => {
expect(pickOn(['only'], all, 'only').candidate).toBe('only');
});
});
describe('what a right-click opens the menu for (#204)', () => {
const stack = ['top', 'middle', 'bottom'];
it('selects the topmost first when nothing selected is under the pointer', () => {
expect(menuTargetOf(stack, ['elsewhere'], 'elsewhere')).toEqual({ id: 'top', select: true });
});
it('keeps a selection hidden under others and opens on it', () => {
expect(menuTargetOf(stack, ['elsewhere', 'bottom'], 'elsewhere')).toEqual({
id: 'bottom',
select: false,
});
});
it('prefers the primary one of a group', () => {
expect(menuTargetOf(stack, ['top', 'middle'], 'middle')).toEqual({ id: 'middle', select: false });
});
it('opens none on empty space', () => {
expect(menuTargetOf([], ['top'], 'top')).toBeNull();
});
});