mirror of
https://github.com/got-feedBack/feedBack.git
synced 2026-09-12 20:28:32 +00:00
Moves 7 exports from screen.js to a new ES module src/geometry.js: geoFretX (was fretX, now 2-arg), dZ, slideTrailEnd, camBaseDistU, camLowFretPullbackU, computeBPM, _makeGaussTex. Internal helpers _fretXLog / _fretXUniStep / _fretXUni are module-private inside geometry.js. Module-level constants (SCALE, K, FRET_SCALE, NFRETS, FRET_SPACING_*, TS) are duplicated at geometry.js module scope — values are compile-time and never vary at runtime. screen.js keeps a 1-arg delegator (1 beyond-subst): const fretX = f => geoFretX(f, _h3dFretUniform); No call site changes; fretMid / fretColumnWorldW / slideOffsetWorldX / _recomputeFretSpacingDerived stay in screen.js and use the delegator. Tests: - highway_3d_geometry.test.js: class-killer via import() with 9 known-answer assertions (geoFretX uniform/log invariants, dZ linearity, slideTrailEnd, computeBPM BPM estimate). - highway_3d_fret_spacing: test updated to match delegator pattern + adds GEOMETRY_JS read to verify geoFretX export. - highway_3d_sustain_bloom: retargeted _makeGaussTex check to GEOMETRY_JS (definition moved); call-site check stays on SCREEN_JS. - highway_3d_panel_controls: vm loader strips ES import line and injects geometry stubs; all factory-statics tests unaffected. Suite: 169/169 pass node --test tests/js/highway_3d*.test.js plugins/highway_3d/tests/*.test.js Version bump: 3.35.0 -> 3.36.0 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014uZ169yfoFYArXz962g7KW
86 lines
3.9 KiB
JavaScript
86 lines
3.9 KiB
JavaScript
// Pins the fret-spacing setting in plugins/highway_3d/screen.js (PR #329).
|
|
// The board can render fret columns either Uniform (equal width, the chart
|
|
// Remastered style) or Logarithmic (real instrument geometry), switchable at
|
|
// runtime via window.h3dSetFretSpacing and persisted in localStorage. A
|
|
// refactor that renames the storage key, drops the delegator in fretX, or
|
|
// stops validating the mode would silently regress the setting.
|
|
//
|
|
// Since h3d-carve-1, the uniform/log branch lives in src/geometry.js
|
|
// (geoFretX); screen.js keeps a 1-arg delegator:
|
|
// const fretX = f => geoFretX(f, _h3dFretUniform);
|
|
//
|
|
// Source-level only — same strategy as the other tests/js/ files.
|
|
|
|
const { test } = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const fs = require('node:fs');
|
|
const path = require('node:path');
|
|
|
|
const SCREEN_JS = path.join(__dirname, '..', '..', 'plugins', 'highway_3d', 'screen.js');
|
|
const GEOMETRY_JS = path.join(__dirname, '..', '..', 'plugins', 'highway_3d', 'src', 'geometry.js');
|
|
|
|
test('fret-spacing mode is read from the highway_3d.fretSpacing localStorage key', () => {
|
|
const src = fs.readFileSync(SCREEN_JS, 'utf8');
|
|
assert.match(
|
|
src,
|
|
/_h3dFretUniform\s*=\s*localStorage\.getItem\(\s*'highway_3d\.fretSpacing'\s*\)\s*!==\s*'logarithmic'/,
|
|
'startup must read highway_3d.fretSpacing and treat anything but "logarithmic" as uniform',
|
|
);
|
|
});
|
|
|
|
test('fretX is a 1-arg delegator to geoFretX in screen.js (h3d-carve-1)', () => {
|
|
const src = fs.readFileSync(SCREEN_JS, 'utf8');
|
|
assert.match(
|
|
src,
|
|
/const\s+fretX\s*=\s*f\s*=>\s*geoFretX\(\s*f\s*,\s*_h3dFretUniform\s*\)/,
|
|
'screen.js fretX must delegate to geoFretX(f, _h3dFretUniform) from geometry.js',
|
|
);
|
|
const geo = fs.readFileSync(GEOMETRY_JS, 'utf8');
|
|
assert.match(
|
|
geo,
|
|
/export\s+const\s+geoFretX\s*=\s*\(\s*f\s*,\s*uniform\s*\)\s*=>/,
|
|
'geometry.js must export geoFretX as a 2-arg function (fret, uniform)',
|
|
);
|
|
});
|
|
|
|
test('h3dSetFretSpacing validates the mode against the two supported values', () => {
|
|
// An unexpected input must not be persisted verbatim — it is coerced to
|
|
// one of 'logarithmic' | 'uniform' before writing to localStorage.
|
|
const src = fs.readFileSync(SCREEN_JS, 'utf8');
|
|
assert.match(
|
|
src,
|
|
/window\.h3dSetFretSpacing\s*=\s*mode\s*=>\s*\{[\s\S]*?mode\s*===\s*'logarithmic'\s*\?\s*'logarithmic'\s*:\s*'uniform'[\s\S]*?localStorage\.setItem\(\s*'highway_3d\.fretSpacing'/,
|
|
'h3dSetFretSpacing must coerce mode to a supported value before persisting',
|
|
);
|
|
});
|
|
|
|
test('h3dSetFretSpacing applies the change live, not via a page reload', () => {
|
|
// A reload reboots the SPA to the home screen, ejecting the user from
|
|
// Settings. The setter must instead rebind the spacing flag and broadcast
|
|
// a 'fretSpacing' change so mounted panels rebuild in place — same path as
|
|
// every other 3D-highway setting. Reintroducing location.reload() here is
|
|
// the regression this guards against.
|
|
const src = fs.readFileSync(SCREEN_JS, 'utf8');
|
|
const setter = src.match(/window\.h3dSetFretSpacing\s*=\s*mode\s*=>\s*\{[\s\S]*?\n \};/);
|
|
assert.ok(setter, 'h3dSetFretSpacing assignment must be present');
|
|
assert.doesNotMatch(
|
|
setter[0],
|
|
/location\.reload/,
|
|
'h3dSetFretSpacing must not reload the page (it ejects the user from Settings)',
|
|
);
|
|
assert.match(
|
|
setter[0],
|
|
/_bgEmitChange\(\s*'fretSpacing'\s*\)/,
|
|
'h3dSetFretSpacing must broadcast a live fretSpacing change',
|
|
);
|
|
});
|
|
|
|
test('the fretSpacing change rebuilds a mounted board live', () => {
|
|
const src = fs.readFileSync(SCREEN_JS, 'utf8');
|
|
assert.match(
|
|
src,
|
|
/changedKey\s*===\s*'fretSpacing'[\s\S]*?if\s*\(fretG\)\s*buildBoard\(\)/,
|
|
'the panel bg listener must rebuild the board when fretSpacing changes',
|
|
);
|
|
});
|