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>
This commit is contained in:
1 parent
42647d309b
commit
ded71a92c9
24 files changed
+777
-34
No files matched your search
@@ -1,5 +1,6 @@
|
||||
import type { KeyClipboard } from '../core/commands/animationCommands';
|
||||
import type { EditorClipboard } from './clipboard';
|
||||
import type { ObjectPick, PickEnd } from './objectPick';
|
||||
import { findKey, findTrack, hasKey, type KeyRef, sameKey } from '../core/model/animation';
|
||||
import { type Command, CommandError } from '../core/commands/Command';
|
||||
import { CommandStack } from '../core/commands/CommandStack';
|
||||
@@ -188,6 +189,8 @@ export type EditorEvent =
|
||||
| 'mode'
|
||||
| 'save'
|
||||
| 'notice'
|
||||
/** The eyedropper of an object's place started, moved its candidate or ended (`objectPick`). */
|
||||
| 'pick'
|
||||
/** The running world advanced a frame (play mode): values may have changed without a command. */
|
||||
| 'runtime';
|
||||
|
||||
@@ -230,6 +233,10 @@ export class EditorState {
|
||||
pingedAssetId: string | null = null;
|
||||
/** Objects the scene view is dragging: a running game holds their bodies to the pointer. */
|
||||
heldObjectIds: ReadonlySet<string> = new Set();
|
||||
/** The eyedropper of an object's place while it runs (#276). */
|
||||
objectPick: ObjectPick | null = null;
|
||||
/** How the last one ended – what a listener of the `pick` event finds once it is gone. */
|
||||
pickEnd: PickEnd | null = null;
|
||||
/** The real (saved) model and its undo stack while `project` is the play-mode copy. */
|
||||
private edit: { project: Project; commands: CommandStack } | null = null;
|
||||
|
||||
@@ -250,6 +257,7 @@ export class EditorState {
|
||||
}
|
||||
|
||||
loadProject(project: Project, revision: number): void {
|
||||
this.endObjectPick('drop');
|
||||
this.edit = null;
|
||||
this.mode = 'edit';
|
||||
this.paused = false;
|
||||
@@ -270,6 +278,7 @@ export class EditorState {
|
||||
/** Returns the runtime copy; the selection survives because ids are identical. */
|
||||
enterPlay(): Project {
|
||||
if (this.mode === 'play') return this.project;
|
||||
this.endObjectPick('drop');
|
||||
const copy = deserializeProject(serializeProject(this.project), this.project.id);
|
||||
this.edit = { project: this.project, commands: this.commands };
|
||||
this.project = copy;
|
||||
@@ -290,6 +299,7 @@ export class EditorState {
|
||||
|
||||
exitPlay(): void {
|
||||
if (this.mode !== 'play') return;
|
||||
this.endObjectPick('drop');
|
||||
if (this.edit) {
|
||||
this.project = this.edit.project;
|
||||
this.commands = this.edit.commands;
|
||||
@@ -357,10 +367,12 @@ export class EditorState {
|
||||
}
|
||||
|
||||
undo(): void {
|
||||
this.endObjectPick('drop');
|
||||
this.runEdit(() => this.commands.undo());
|
||||
}
|
||||
|
||||
redo(): void {
|
||||
this.endObjectPick('drop');
|
||||
this.runEdit(() => this.commands.redo());
|
||||
}
|
||||
|
||||
@@ -472,10 +484,44 @@ export class EditorState {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
selection = trackSelection(selection.assetId, selection.keys ?? [], selection.trackId);
|
||||
if (sameSelection(this.selection, selection)) return;
|
||||
this.endObjectPick('drop');
|
||||
this.selection = selection;
|
||||
this.emit('selection');
|
||||
}
|
||||
|
||||
/** Starts the eyedropper of an object's place (#276); one running already is dropped for it. */
|
||||
startObjectPick(pick: ObjectPick): void {
|
||||
const before = this.objectPick;
|
||||
this.objectPick = pick;
|
||||
this.pickEnd = null;
|
||||
before?.ended();
|
||||
this.emit('pick');
|
||||
}
|
||||
|
||||
/** Moves the eyedropper's candidate; nothing is written until `endObjectPick('take')`. */
|
||||
movePick(candidate: string | null): void {
|
||||
const pick = this.objectPick;
|
||||
if (!pick || pick.candidate === candidate) return;
|
||||
pick.candidate = candidate;
|
||||
this.emit('pick');
|
||||
}
|
||||
|
||||
/**
|
||||
* Ends the eyedropper. Only `take` writes, and only a candidate the dropdown still offers and that
|
||||
* is not the target already – a pick that changes nothing leaves no undo step.
|
||||
*/
|
||||
endObjectPick(how: PickEnd): void {
|
||||
const pick = this.objectPick;
|
||||
if (!pick) return;
|
||||
this.objectPick = null;
|
||||
this.pickEnd = how;
|
||||
pick.ended();
|
||||
this.emit('pick');
|
||||
if (how !== 'take') return;
|
||||
const ref = pick.choices().find((c) => c.objectId === pick.candidate)?.ref;
|
||||
if (ref !== undefined && ref !== pick.current) pick.take(ref);
|
||||
}
|
||||
|
||||
toggleObject(holderId: string, objectId: string): void {
|
||||
const s = this.selection;
|
||||
const current = s?.kind === 'object' && s.holderId === holderId ? s.objectIds : [];
|
||||
|
||||
Reference in new issue
Block a user