feat(keys_highway_3d): foundation for guitar-highway visual parity (K1) (#696)

- setPixelRatio at last: DPR (cap 2; 1.25 when >1 instance) x host
  adaptive bundle.renderScale — HiDPI displays were rendering at CSS
  resolution and upscaling (soft/aliased)
- Bloom: port _bloomEnsure/_bloomDispose (UnrealBloomPass 0.65/0.5/0.82,
  MSAA HalfFloat target, ACES<->None switch); hit-line, flames and
  consume-glow benefit immediately; direct render is the degrade path
- First settings panel: settings.html (graphics category) with a live
  Glow (bloom) toggle; FX scaffold (FX_DEFAULTS/readFxSettings/
  window.keys3dSetFx, keys3d_bg_* keys, keys3d:settings event)
- Combo/accuracy/best-streak DOM HUD (drum_highway_3d pattern), gated on
  a live MIDI session
- tests/fx_settings.test.js (3 tests; vm harness)

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Byron Gamatos
2026-07-02 00:53:12 +02:00
committed by GitHub
co-authored by Claude Fable 5
parent a7ea719652
commit beefd7bc09
6 changed files with 464 additions and 4 deletions
@@ -0,0 +1,82 @@
// FX-settings scaffold tests (guitar-highway parity controls). Same bare-vm
// harness as data_layer.test.js — no DOM, no localStorage — which doubles as
// a lint that the new module-scope FX code stays side-effect safe.
const { test } = require('node:test');
const assert = require('node:assert/strict');
const fs = require('node:fs');
const path = require('node:path');
const vm = require('node:vm');
function load(extraWindow) {
const window = {
console,
location: { protocol: 'http:', host: 'localhost' },
slopsmith: {},
...extraWindow,
};
window.window = window;
window.globalThis = window;
const context = vm.createContext(window);
const src = fs.readFileSync(path.join(__dirname, '..', 'screen.js'), 'utf8');
vm.runInContext(src, context, { filename: 'screen.js' });
return window;
}
test('readFxSettings: defaults survive a localStorage-less environment', () => {
const { readFxSettings, FX_DEFAULTS } = load().slopsmithViz_keys_highway_3d.__test;
assert.deepEqual(readFxSettings(), FX_DEFAULTS);
assert.equal(FX_DEFAULTS.bloom, true); // effects on by default
});
test('readFxSettings: reads keys3d_bg_* overrides and coerces types', () => {
const store = { keys3d_bg_bloom: '0' };
const win = load({
localStorage: {
getItem: (k) => (k in store ? store[k] : null),
setItem: (k, v) => { store[k] = v; },
},
});
const { readFxSettings } = win.slopsmithViz_keys_highway_3d.__test;
assert.equal(readFxSettings().bloom, false);
store.keys3d_bg_bloom = 'true';
assert.equal(readFxSettings().bloom, true);
store.keys3d_bg_bloom = 'false';
assert.equal(readFxSettings().bloom, false);
// Corrupt/foreign value → keep the default rather than silently
// disabling the effect.
store.keys3d_bg_bloom = 'banana';
assert.equal(readFxSettings().bloom, true);
});
test('keys3dSetFx: persists, coerces, and ignores unknown keys', () => {
const store = {};
const events = [];
const win = load({
localStorage: {
getItem: (k) => (k in store ? store[k] : null),
setItem: (k, v) => { store[k] = v; },
},
dispatchEvent: (ev) => { events.push(ev); return true; },
CustomEvent: class CustomEvent {
constructor(type, opts) { this.type = type; this.detail = opts && opts.detail; }
},
});
win.keys3dSetFx('bloom', false);
assert.equal(store.keys3d_bg_bloom, '0');
// String forms round-trip like the reader's accepted representations.
win.keys3dSetFx('bloom', 'false');
assert.equal(store.keys3d_bg_bloom, '0');
win.keys3dSetFx('bloom', 'true');
assert.equal(store.keys3d_bg_bloom, '1');
win.keys3dSetFx('bloom', false);
assert.equal(events.length, 4);
assert.equal(events[0].type, 'keys3d:settings');
// Field-wise (the detail object was built inside the vm realm, so a
// deep-strict compare would trip on its foreign Object.prototype).
assert.equal(events[0].detail.fx.bloom, false);
assert.deepEqual(Object.keys(events[0].detail.fx), ['bloom']);
// Unknown key: no write, no event.
win.keys3dSetFx('nonsense', 1);
assert.equal(events.length, 4);
assert.ok(!('keys3d_bg_nonsense' in store));
});