Files
feuerwerk/src/editor/graph/Breadcrumb.ts
T
adminandClaude Opus 5 ae3aa7d3bd
game-maker / gate (push) Successful in 2m0s
game-maker / suite (push) Successful in 7m17s
Refactoring round 5 covers the code since round 4 without changing behaviour: four identical copies of dot() and three of "nearest point on a segment" stood in the collision math, in the hit area of the collider outlines and in the polygon handles, so they moved into the new module src/core/util/vec.ts; the warning line, the busy state, info() and the caret reset were written out line by line in both the sign-in screen and the password dialog and are now FormStatus; the closing row "Cancel plus a confirming button, optionally one on the left" was built by hand in FormDialog, FilePicker, OpenProjectDialog and PasswordDialog and is now dialogButtons(); the header bar was drawn by the toolbar, the TabHeader and the Breadcrumb each on its own and is now drawHeaderBar(); AddColliderCommand and AddRigidbodyCommand share a base, each subclass only builds its own asset; Editor.ts derives the panes from assetEditors instead of repeating eight entries and clamps its splitters with clamp(); jscpd over src falls from 0.19 % to 0.14 %; dead code is gone - listScenes() has been orphaned since the Scene picker fell away (#183), DEFAULT_FILTER (#152) was never used, the two test hooks projectPickerRowAt/rowPosition and particleCompiles are read by no tool, and four functions lost an export they did not need; seven comments that told history ("used to", "no longer", "since #...") describe the state of things now, and that this changed nothing was proved by a rebuild - the bundle is md5 identical, b4ad0dfe... before and after; the README said Logout sits at the far right of the toolbar, which has been the Account menu since #182, and wiki/Architecture.md was missing src/core/util/ altogether; 4 new unit tests cover vec.ts, and switching the clamp on the segment off makes exactly one of them fail while none of the 76 neighbouring tests notice, so that clamping was covered nowhere before (#85)
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-20 17:24:42 +02:00

73 lines
2.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { Graphics } from 'pixi.js';
import { Button, drawHeaderBar, HStack, Label, Theme, type Widget } from '../../ui';
/** Past this a crumb cuts its name short, so a deep trail of long names still fits the tab. */
const CRUMB_MAX_WIDTH = 160;
/** "Game › Move › Other": every crumb but the last one leads back; empty hides the bar. */
export class Breadcrumb extends HStack {
private readonly bg = new Graphics();
private crumbs: Widget[] = [];
onPick: (index: number) => void = () => undefined;
constructor() {
super({ gap: 2, padding: 3, align: 'center' });
this.addChild(this.bg);
this.visible = false;
}
/** Returns whether the bar changed, so the caller relayouts only then. */
show(names: readonly string[]): boolean {
if (names.length === this.crumbs.length && names.every((n, i) => crumbText(this.crumbs[i]!) === n))
return false;
for (const widget of this.items) widget.destroy({ children: true });
this.crumbs = names.map((name, i) => {
if (i > 0) this.add(new Label('›', { style: 'muted' }));
const last = i === names.length - 1;
return this.add(
capped((width) =>
last
? new Label(name, { width, padding: Theme.padding })
: new Button(name, { variant: 'ghost', width, onClick: () => this.onPick(i) }),
),
);
});
this.visible = names.length > 0;
// The bar keeps its size across a rebuild, and `resize` lays out only on a new size.
this.relayout();
return true;
}
/** For the check scripts: what each crumb says, where it sits, and whether it leads anywhere. */
crumbsDrawn(): { name: string; x: number; y: number; left: number; right: number; clickable: boolean }[] {
if (!this.visible) return [];
return this.crumbs.map((widget) => {
const at = widget.getGlobalPosition();
return {
name: crumbText(widget),
x: at.x + widget.w / 2,
y: at.y + widget.h / 2,
left: at.x,
right: at.x + widget.w,
clickable: widget instanceof Button,
};
});
}
override redraw(): void {
super.redraw();
drawHeaderBar(this.bg, this.w, this.h);
}
}
function crumbText(widget: Widget): string {
return widget instanceof Button || widget instanceof Label ? widget.text : '';
}
function capped(build: (width?: number) => Widget): Widget {
const natural = build();
if (natural.measure().w <= CRUMB_MAX_WIDTH) return natural;
natural.destroy({ children: true });
return build(CRUMB_MAX_WIDTH);
}