Files
feuerwerk/src/editor/TabButton.ts
T
adminandClaude Opus 5.5 bc688f3efc
game-maker / gate (push) Successful in 3m50s
game-maker / suite (push) Successful in 12m3s
Refactoring round 7: split BehaviorSystem, fewer copies (#85)
Recurring cleanup round over the code since round 6 (056a622), 105
commits. Behaviour is unchanged. Duplicated code in src went from 29
clones with 229 lines (0.32 %) to 14 clones with 109 lines (0.15 %),
measured with jscpd and the same settings as round 6.

- BehaviorSystem.ts shrinks from 941 to 589 lines. Collecting the
  pulses (keys, timers, collisions, animations) moved to
  behaviorPulses.ts. The NodeContext the nodes receive moved to
  behaviorContext.ts. Imports from outside stay the same, TimeScaled
  is still exported from BehaviorSystem.ts.
- PointKindButton and drawPointGrip replace the "Point:" button with
  its menu and the point and handle drawing that the curve and the
  vector art tab each had on their own.
- lerpVec, cubicAt and splitCubic in src/core/util/vec.ts replace four
  copies of the cubic curve and two de Casteljau splits.
- mapNested in Properties.ts is the one walk over lists and structs
  that liveObjects and objectRefs did separately. withFieldRenamed
  and withoutField replace three copies of renaming a struct field
  and two of removing one.
- jsonBody and staleRevision build the JSON body and turn a 409 into
  StaleRevisionError for all stores. The auth store turns a 401 into
  its error in one place.
- Smaller helpers: structAssetFrom for the two "Make struct type"
  commands, shownObject in the inspector, selectedItem for the size
  gizmo and the polygon corners, solidTiles in the tilemap collision,
  requireVariablesAsset and requireBehaviorVariable.
- Left as is on purpose: the plain forwarding from the collision and
  physics systems to Solids, the pointer wiring of the canvases and
  the identical last lines of the two make commands.
- Removed unused code: tilemapTileIds and tilemapsUsing were never
  called since #128 and #131. EditorState.runtimeProject became unused
  with GameRun in #266. The assetId getter of the make commands was
  read only by a test.
- 60 values used only in their own file lost their export. The shader
  and particle node catalogues stay exported as in round 6.
- Five comments that told history now describe the current state. The
  doc comment of BehaviorSystem sits on the class again.
- README lists the struct, clip area and curve assets and mentions the
  game link from #266.

Findings:
- Deleting a tile that is painted on a tilemap leaves its cells in
  place, and they draw nothing. The delete dialog does not mention the
  tilemaps. That was probably the job of the unused tilemapsUsing.
  Left as is, because fixing it changes behaviour.
- The solid filter for tile surfaces was untested. A bent filter
  stayed green. A new test in tests/core/surface.test.ts now fails
  against it.

Tests:
- ./check.sh: 195 files, 2815 tests, exit 0 (one test removed with
  tilemapsUsing, one added for tile surfaces).
- Full e2e run: ALL PASSED, 1580 checks.
- Smokes jumprun, tetris, actor: 24, 19 and 21 checks, all passed.
  The example project files were restored byte for byte afterwards.
- Counter-checks, 12, all fail as expected: 10 in unit tests (among
  them mapNested, splitCubic, cubicAt, staleRevision, the stay pulse,
  the late timer and the time scale), 2 in the browser (Point button
  always enabled fails 47, selectedItem without a hit fails 29).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 16:16:37 +02:00

59 lines
2.2 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 { Button, type ButtonOptions, Theme, type TextStyleToken } from '../ui';
/** The upper corners are rounded, the lower ones square: the card sits on the bar of the strip. */
const RADIUS = 6;
/**
* Inset of icon and name inside a card. Half the theme padding was too tight once the cards got a
* border of their own, so the row keeps its own value instead of `Theme.padding`.
*/
const TAB_PADDING = 6;
/**
* One card of the tab row. It is drawn as a real index card rather than as a toggled button: a
* light grey card for the tab showing, nothing for the others, and never the pressed fill – a
* click on the tab that is already showing must not flash a colour of its own (#176).
*/
export class TabButton extends Button {
constructor(text: string, options: ButtonOptions = {}) {
super(text, { padding: TAB_PADDING, ...options, variant: 'ghost' });
}
/** Plain weight in both states: the fill says which tab is showing, the font does not. */
protected override labelToken(): TextStyleToken {
return this.toggled ? 'body' : 'muted';
}
/** `body` and `muted` differ only in colour, so one width holds for both states. */
protected override measureToken(): TextStyleToken {
return 'body';
}
protected override iconTint(): number {
return this.toggled ? Theme.colors.text : Theme.colors.textMuted;
}
protected override drawBackground(): void {
const c = Theme.colors;
const { w, h } = this;
const fill = this.toggled ? c.tabActive : this.hovered ? c.tabHover : null;
this.bg.clear();
if (fill !== null) {
// Two shapes instead of one rounded rect: the card must meet the bar with square corners.
this.bg.roundRect(0, 0, w, h, RADIUS).fill(fill);
this.bg.rect(0, h - RADIUS, w, RADIUS).fill(fill);
}
const border = this.focused ? c.accent : this.toggled ? c.border : null;
if (border === null) return;
// An open path along the three edges the card has: a closed one would draw a line over the bar.
this.bg
.moveTo(0.5, h)
.lineTo(0.5, RADIUS)
.quadraticCurveTo(0.5, 0.5, RADIUS, 0.5)
.lineTo(w - RADIUS, 0.5)
.quadraticCurveTo(w - 0.5, 0.5, w - 0.5, RADIUS)
.lineTo(w - 0.5, h)
.stroke({ width: 1, color: border });
}
}