Files
feuerwerk/tools/e2e/01-hierarchy.mjs
T
adminandClaude Opus 5.5 25084f8576
game-maker / gate (push) Successful in 4m3s
game-maker / suite (push) Successful in 14m52s
Refactoring round 10: split SoundLibrary, fold sound duplicates (#85)
Refactoring round 10 covers everything since round 9 (808e1ee): 110
commits with about 47 000 new lines, nearly all of them sound, sound
FX, instruments, patterns and songs. Behaviour is unchanged.

Duplicate code (jscpd over src, 50 tokens, TypeScript only, measured
on 808e1ee and here alike: 47 clones / 426 lines before, 33 / 245
after; round 9 itself ended at 22 / 160 by this count):

- PreviewParams (new, editor/soundfx) is the header's parameter bar
  of the Sound FX and the Instrument tab: values, defaults, fields
  and the voices a moved field reaches. Both tabs had it line for
  line.
- fxWorklet: an Effect base runs the bit crusher, phaser, flanger,
  limiter, LFO and bus shifter, a Source base the pitch player and
  the Chip. Start is the one wait for a voice's first sample, which
  four processors wrote out each.
- nodes/shared has checkPort, detachedPort, fxParamsPort and
  letRingPort. The Play and Stop nodes of sounds, notes, patterns and
  songs spelled each port out, up to five times.
- parameterValues builds both Sound FX parameters and Instrument
  parameters, which differed in name and text only.
- SetLoopCommand sets the ruler loop of a pattern or a song. It
  replaces SetPatternLoopCommand and SetSongLoopCommand.
- addLink in music/routing is the one rule for a link that both the
  song routing and the Master routing keep.
- eqCurves works out each band and their sum for the EQ tab, which
  did that in its drawing code. It replaces eqCurveDb, which only a
  test called.
- Smaller ones: the eight neighbour directions of a tile cell, and
  drawFloatingBox for the shadowed box of Popup and FloatWindow.
- Left on purpose: Play pattern and Play song stay two parallel node
  definitions, and the smaller clones under ten lines stay.

Architecture:

- SoundLibrary.ts goes from 2897 to 2188 lines. What a stage of a
  sound FX becomes as Web Audio nodes, and how the knobs of a playing
  voice move, is now viewport/fxNodes.ts. None of it keeps state of
  the library.

Dead code (TS language service, references per export and member):

- soundRefIds, LFO_SHAPE_INDEX, TREMOLO_ROWS, VIBRATO_ROWS and
  REVERB_ROWS had no reader. The four routing node defs are
  registered without an unused exported name.
- soundFileOf and portTypeOf were called by tests only. The tests
  now ask findSound and portOf, which the editor uses. DRY moves
  from src into the one test that uses it.
- 51 values used only in their own file lose their `export`. Types
  and the node catalogues stay exported.
- Kept on purpose: neighboursOf is the cell by cell reading the
  indexed neighboursIn is checked against, and PitchShifter.latency
  is the test's one view of how late the shifter is.

Comments and docs:

- Seven comments told history ("no longer", "any more", "as
  before", "of before #354"). Nine comment blocks ran far past the
  line width. Proof that this changed no code: the bundle was md5
  identical, and the touched tests and e2e modules were identical
  after esbuild.
- README: sound FX, instrument, pattern, song and bus in the asset
  list, the pages Instruments, Patterns and Songs, 1919 checks.
- Wiki: see its own commit.

Tests:

  Gate (melektaus-atx)    274 files, 4236 tests, CHECK EXIT 0
  e2e 34, 64, 65          ALL PASSED, 180 checks
  Unit, touched areas     16 files, 804 tests

No check was added, the e2e sum stays at 1919. Counter-checks, each
put back by copy and compared with cmp:

- addLink without the loop rule: 2 tests fail, one per routing.
- eqCurves with the sum of the last band only: 1 test fails.
- Start in the worklet never waiting: e2e 34 fails in exactly the
  four checks that hang on a voice's first sample (Flanger, Tremolo,
  Chip, a pitched note planned ahead).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-09 15:31:33 +02:00

119 lines
5.3 KiB
JavaScript
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 { same } from '../lib/harness.mjs';
/**
* Hierarchy folding. A freshly opened scene is fully collapsed, so only its top-level objects
* are listed (o4/oc1 hang under o1, oc2 under o2). The chevron folds a row open and shut
* without touching the selection, and selecting a nested object unfolds the way down to it.
* A click on the selected row pings the object's asset, a double-click opens it (#353).
*/
export async function hierarchy(t) {
const { check, evaluate, json, click, clickText, doubleClick, press, select, sleep, state, shot } = t;
const rowIds = () => json('__gm.hierarchyOrder()');
const rows = async () => JSON.stringify(await rowIds());
const selectionBefore = (await state()).selection;
check(
'hierarchy starts collapsed – only top-level objects are listed',
same(await rowIds(), ['o1', 'o2', 'o3', 'o5']),
await rows(),
);
check('a leaf row offers no chevron', (await evaluate(`__gm.hierarchyChevron('o3')`)) === null);
const chevron = await json(`__gm.hierarchyChevron('o2')`);
await click(chevron.x, chevron.y);
check(
'clicking the chevron unfolds the row, leaving the selection alone',
same(await rowIds(), ['o1', 'o2', 'oc2', 'o3', 'o5']) && same((await state()).selection, selectionBefore),
await rows(),
);
await shot('01a-hierarchy-unfolded');
await click(chevron.x, chevron.y);
check(
'clicking it again folds the subtree away',
same(await rowIds(), ['o1', 'o2', 'o3', 'o5']),
await rows(),
);
// 01b (#353). A click on the row that is selected already pings the object's asset in the asset
// panel, as one on the asset link in the inspector does; the first click only selects.
const assetOf = (id) =>
json(`__gm.state.activeScene.objects.find((o) => o.id === ${JSON.stringify(id)}).assetId`);
const o3Asset = await assetOf('o3');
await evaluate('__gm.state.pingedAssetId = null');
const o3Row = await json(`__gm.hierarchyRow('o3')`);
await click(o3Row.x, o3Row.y);
const afterFirst = await json('__gm.state.pingedAssetId');
// Past the double-click window, which goes by time: two quick clicks would open the asset.
await sleep(500);
await click(o3Row.x, o3Row.y);
const ping = await json('__gm.assetPing()');
const pingSelection = (await state()).selection;
check(
'a click on the selected row pings its asset and keeps the selection, the first click only selects',
afterFirst === null &&
ping?.id === o3Asset &&
pingSelection?.kind === 'object' &&
same(pingSelection.objectIds, ['o3']),
JSON.stringify({ afterFirst, ping, o3Asset, pingSelection }),
);
// A double-click opens the asset, selected or not, and leaves the row folded as it was.
const o2Asset = await assetOf('o2');
const row = await json(`__gm.hierarchyRow('o2')`);
await doubleClick(row.x, row.y);
const o2Selection = (await state()).selection;
check(
'double-clicking a row selects its asset and leaves the row folded',
o2Selection?.kind === 'asset' &&
o2Selection.assetId === o2Asset &&
same(await rowIds(), ['o1', 'o2', 'o3', 'o5']),
JSON.stringify({ o2Selection, o2Asset, rows: await rowIds() }),
);
await select({ kind: 'object', holderId: 'scene1', objectId: 'o5' });
const o5Row = await json(`__gm.hierarchyRow('o5')`);
await doubleClick(o5Row.x, o5Row.y);
const openedByRow = await json('__gm.documents()');
check(
'double-clicking a selected row opens the tab of its asset',
openedByRow.active === 'asset:spawner',
JSON.stringify(openedByRow),
);
await evaluate(`__gm.closeDocument('asset:spawner'); __gm.state.select(null)`);
await select({ kind: 'object', holderId: 'scene1', objectId: 'oc1' });
check(
'selecting a nested object unfolds its ancestors',
same(await rowIds(), ['o1', 'o4', 'oc1', 'o2', 'o3', 'o5']),
await rows(),
);
await evaluate('__gm.state.select(null); __gm.hierarchyCollapseAll()');
check('Collapse all folds everything back', same(await rowIds(), ['o1', 'o2', 'o3', 'o5']), await rows());
// Open asset in the row's menu does what a double-click in the asset panel does.
const spawnerRow = await json(`__gm.hierarchyRow('o5')`);
await click(spawnerRow.x, spawnerRow.y, 'right');
await clickText('Open asset');
const opened = await json('__gm.documents()');
const openedSelection = (await state()).selection;
check(
'Open asset in the row menu selects the asset and opens its tab',
opened.active === 'asset:spawner' &&
opened.docs.includes('asset:spawner') &&
openedSelection?.kind === 'asset' &&
openedSelection.assetId === 'spawner',
JSON.stringify({ opened, openedSelection }),
);
await evaluate(`__gm.closeDocument('asset:spawner'); __gm.state.select(null)`);
// A sprite has no editor of its own, so the entry that promises to open one is greyed out.
const crateRow = await json(`__gm.hierarchyRow('o1')`);
await click(crateRow.x, crateRow.y, 'right');
const menuRows = await json('__gm.menuRows()');
const menuEnabled = await json('__gm.menuEnabled()');
check(
'Open asset is greyed out for a kind without an editor, Select asset stays on',
menuEnabled[menuRows.indexOf('Open asset')] === false &&
menuEnabled[menuRows.indexOf('Select asset')] === true,
JSON.stringify({ menuRows, menuEnabled }),
);
await press('Escape');
await evaluate('__gm.state.select(null)');
}