Files
feuerwerk/src/editor/animation/AnimationEditor.ts
T
adminandClaude Opus 5.5 0e8585665a
game-maker / gate (push) Successful in 2m47s
game-maker / suite (push) Successful in 8m41s
Load the 500 weight and draw missing glyphs as SVG icons (#214)
The theme asks for Source Sans 3 at weight 500, but fonts.ts only
loaded 400, 600 and 700. The browser synthesised the 500 text. The
issue comment also asked for the symbols the font lacks to become SVG
icons. A scan of src/ against the font's cmap found 20 such characters
in 30 places.

- fonts.ts loads source-sans-3-latin-500-normal.woff2 as well.
- Menus draw their ticks and the "current" dot as icons. The dot is a
  new MenuItem.current field and no longer part of the label text.
- Inspector action buttons (reset, apply, fit width/height) are
  icons. The menu arrow behind them is the drawn Dropdown chevron.
- Kind marks come from a table in markIcons.ts. Picture kinds use an
  icon, # and Aa stay text because the font has them.
- Scene marks in the asset panel, sound play/stop and the transition
  arrows are icons too.
- Apply is an icon although the font has the arrow. It sits next to
  the reset icon and would look different as a glyph.
- A new Icon widget draws on redraw like Button, so Node tests need no
  DOMParser.
- Tests find icons through the SVG id. The new hook
  __gm.locateIcons(id) and the harness helpers findIcon/clickIcon
  replace locate() on the old characters.

Findings:
- Weight 700 is loaded but the theme never uses it. Left as is.
- The old scene-mark check in module 35 accepted any play glyph on
  screen. It now checks the mark on the start scene's row.
- Module 44 needs the textures from module 37 and fails without it.

Tests:
- ./check.sh: 145 files, 2187 tests, exit 0 (before 144 / 2143).
- New tests/ui/fonts.test.ts: every theme weight is loaded, and every
  character in src/ exists in every shipped face. The cmap reader
  matches fontTools (231 characters).
- Icon tests cover the 19 new files. Each kind mark is either an
  icon or text, never both.
- e2e 1-16,22,30,34,35,43,44: 586 green, 0 FAIL, then 44 stopped
  for lack of module 37. e2e 1-16,37,44,47,48: 618 green.
  e2e 1-14 on the final build: 454 green.
- Two new e2e checks: loaded weights in 14, a reset icon pixel in 04.
- Counter-probes all fail as expected: 500 removed, a play glyph put
  back, the struct icon removed (one unit test each). In the browser,
  500 removed and reset icon hidden fail exactly the two new checks.
- Editor-suite check sum 1312 (1310 measured by CI at 056a622, +2).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-23 08:13:22 +02:00

139 lines
5.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 { SetAnimationRootCommand } from '../../core/commands/animationCommands';
import { ANIMATION_ROOT_TYPES, animationDuration, fpsOf, frameCount } from '../../core/model/animation';
import type { AnimationAsset, Asset } from '../../core/model/Asset';
import { findAsset } from '../../core/model/Project';
import { Button, Dropdown, formatNumber, Menu, type MenuItem, VStack, type Widget } from '../../ui';
import { AssetTabEditor } from '../AssetTabEditor';
import type { EditorState } from '../state';
import { PreviewCanvas } from './PreviewCanvas';
import { openRowDialog, RowDialog } from './RowDialog';
import { TimelineCanvas } from './TimelineCanvas';
/** Room kept for the "3 rows · 24 frames · 10 fps · 2.4 s" readout. */
const INFO_WIDTH = 220;
const ROOT_WIDTH = 160;
/**
* The Animation tab (#97): the header picks what the animation animates and adds rows, below it
* the preview shows the root at the playhead (#99) and the timeline under that edits the rows.
* `fps` and `playback` are properties of the asset, edited in the inspector like any other.
*/
export class AnimationEditor extends AssetTabEditor<AnimationAsset, TimelineCanvas> {
/** Public for the check scripts. */
readonly rootPicker: Dropdown;
readonly addRowButton: Button;
readonly playButton: Button;
readonly preview: PreviewCanvas;
constructor(state: EditorState) {
super(state, { infoWidth: INFO_WIDTH });
this.rootPicker = new Dropdown('—', { width: ROOT_WIDTH, onClick: () => this.openRootPicker() });
this.addRowButton = new Button('+ Row', { onClick: () => this.openRowDialog() });
this.playButton = new Button('Play', { width: 64, onClick: () => this.togglePlay() });
const timeline = new TimelineCanvas(state);
this.preview = new PreviewCanvas(state, () => ({
frame: timeline.playhead,
reverse: timeline.playheadReverse,
}));
timeline.onPlayhead = () => this.preview.redraw();
this.mount(timeline, [this.rootPicker, this.addRowButton, this.playButton]);
}
/** Fit frames the preview; the timeline keeps its own zoom and scroll. */
protected override fit(): void {
this.preview.fit();
}
protected override saveView(): unknown {
return { timeline: this.canvas.saveView(), preview: this.preview.saveView() };
}
protected override restoreView(view: unknown): void {
const saved = view as { timeline: unknown; preview: unknown };
this.canvas.restoreView(saved.timeline);
// Pointed at the document first: `syncExtras` would do it later and fit it over the restored view.
this.preview.show(this.currentAssetId);
this.preview.restoreView(saved.preview);
}
/** The preview above, the timeline below, each taking half. */
protected override body(canvas: TimelineCanvas): Widget {
const stack = new VStack();
stack.add(this.preview, 1);
stack.add(canvas, 1);
return stack;
}
/** Only called while the tab is visible. */
tick(dt: number): void {
if (!this.canvas.isPlaying) return;
this.canvas.tick(dt);
// A finished `once` pass pauses the canvas; the button has to say so.
this.syncPlayButton();
}
/** Whether the preview is running – a moving picture needs a frame without an event. */
get isPlaying(): boolean {
return this.canvas.isPlaying;
}
override selectedId(): string {
return this.state.selectedAnimationId ?? '';
}
override isMine(asset: Asset): asset is AnimationAsset {
return asset.type === 'animation';
}
protected override infoText(asset: AnimationAsset): string {
const rows = asset.tracks.length;
const frames = Math.max(0, frameCount(asset));
const seconds = formatNumber(animationDuration(asset), 1);
const fps = Number(fpsOf(asset).toFixed(2));
return `${rows} ${rows === 1 ? 'row' : 'rows'} · ${frames} ${frames === 1 ? 'frame' : 'frames'} · ${fps} fps · ${seconds} s`;
}
protected override syncExtras(asset: AnimationAsset | null): void {
const root = asset ? findAsset(this.state.project, asset.root) : undefined;
this.preview.show(asset?.id ?? '');
this.fitButton.setEnabled(Boolean(root));
this.rootPicker.setText(root ? root.name : asset ? 'Animates…' : '—');
this.rootPicker.setEnabled(asset !== null);
// A row needs something to aim at.
this.addRowButton.setEnabled(Boolean(root));
this.playButton.setEnabled(Boolean(asset && frameCount(asset) > 0));
this.syncPlayButton();
}
private syncPlayButton(): void {
this.playButton.setText(this.canvas.isPlaying ? 'Pause' : 'Play');
}
private togglePlay(): void {
if (this.canvas.isPlaying) this.canvas.pause();
else this.canvas.play();
this.syncPlayButton();
}
/** What may be animated: a sprite, text, container or scene – never another animation. */
private openRootPicker(): void {
const asset = this.asset();
if (!asset) return;
const items: MenuItem[] = this.state.project.assets
.filter((a) => ANIMATION_ROOT_TYPES.includes(a.type))
.sort((a, b) => a.name.localeCompare(b.name))
.map((candidate) => ({
label: `${candidate.name} (${candidate.type})`,
current: candidate.id === asset.root,
onSelect: () => this.state.execute(new SetAnimationRootCommand(asset.id, candidate.id)),
}));
if (items.length === 0) items.push({ label: 'Nothing to animate yet', onSelect: () => undefined });
new Menu(items, { searchable: true }).openBelow(this.rootPicker);
}
private openRowDialog(): void {
const asset = this.asset();
if (asset) openRowDialog(new RowDialog(this.state, asset));
}
}