mirror of
https://github.com/got-feedBack/feedBack.git
synced 2026-09-11 18:44:29 +00:00
Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
95d721b795 | ||
|
|
de7ced6429 | ||
|
|
6f433d9cea | ||
|
|
35742c4fae |
@@ -48,6 +48,17 @@ jobs:
|
||||
python -m pip install --upgrade pip
|
||||
pip install -r requirements.txt -r requirements-test.txt
|
||||
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: '20'
|
||||
cache: 'npm'
|
||||
|
||||
- name: Install Node dependencies
|
||||
run: npm ci
|
||||
|
||||
- name: Typecheck (tsc --noEmit)
|
||||
run: npm run typecheck
|
||||
|
||||
- name: Run pytest
|
||||
run: pytest
|
||||
|
||||
|
||||
@@ -41,12 +41,17 @@ is Tailwind CSS, served as a prebuilt static stylesheet
|
||||
(`static/tailwind.min.css`, regenerated by `scripts/build-tailwind.sh`)
|
||||
— never the runtime Play CDN, whose on-the-fly JIT rescans the DOM on
|
||||
the main thread and caused sustained frame drops with the 3D highway
|
||||
(slopsmith-desktop#110). No React, Vue, Svelte, bundler, transpiler, or
|
||||
TypeScript appears in the core static tree, and no build step runs on
|
||||
the serve path: the Tailwind build is a maintainer-only one-shot whose
|
||||
output is committed, so Docker / desktop / end users never build. New
|
||||
features extend `app.js` and the existing globals (`window.playSong`,
|
||||
`window.showScreen`, `window.createHighway`, `window.slopsmith`).
|
||||
(slopsmith-desktop#110). No React, Vue, Svelte, bundler, or transpiler
|
||||
appears in the core static tree, and no build step runs on the serve
|
||||
path: the Tailwind build is a maintainer-only one-shot whose output is
|
||||
committed, so Docker / desktop / end users never build. `tsc --noEmit`
|
||||
with `allowJs` / `checkJs` is permitted as a CI / dev-time type check
|
||||
— JSDoc type annotations and `// @ts-check` directives in core `.js`
|
||||
files are encouraged. TypeScript stays a dev-only devDependency; emit
|
||||
-mode TypeScript, `.ts` / `.tsx` source, JSX, frameworks, and bundlers
|
||||
remain forbidden in core. New features extend `app.js` and the existing
|
||||
globals (`window.playSong`, `window.showScreen`,
|
||||
`window.createHighway`, `window.slopsmith`).
|
||||
|
||||
**Non-negotiable rules**
|
||||
|
||||
@@ -63,6 +68,11 @@ features extend `app.js` and the existing globals (`window.playSong`,
|
||||
and does not re-apply the base reset core already provides. Plugins
|
||||
MUST NOT load the Tailwind Play CDN (or any runtime CSS JIT) — the
|
||||
same no-CDN, build-free-at-serve rule that binds core binds plugins.
|
||||
- `tsc --noEmit` with `allowJs` / `checkJs` is permitted as a CI /
|
||||
dev-time type check. JSDoc type annotations and `// @ts-check`
|
||||
directives in core `.js` files are encouraged. TypeScript stays a
|
||||
dev-only devDependency — emit-mode TypeScript, `.ts` / `.tsx` source,
|
||||
JSX, frameworks, and bundlers remain forbidden in core.
|
||||
- New UI state lives in `localStorage` (or a backend endpoint), not in a
|
||||
framework store.
|
||||
- Naming: camelCase JS, kebab-case CSS, snake_case plugin IDs. Player
|
||||
@@ -117,6 +127,12 @@ format. Both must keep playing across releases.
|
||||
- Existing arrangement IDs, sloppak manifests, and the highway
|
||||
WebSocket message shape are stable contracts. Breaking changes
|
||||
require a CHANGELOG entry under "Migration notes".
|
||||
- The plugin-facing JS contracts — `window.slopsmith`, `window.highway`,
|
||||
the highway WebSocket message shape, and the `setRenderer`
|
||||
visualization contract — are declared in `static/slopsmith.d.ts` and
|
||||
form part of this stable-contract surface. The `.d.ts` is the typed
|
||||
source of truth; a breaking change to it requires the same CHANGELOG
|
||||
entry under "Migration notes".
|
||||
|
||||
### V. Pure-Function Core Libraries, Tested
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
- **Perf**: reduce per-frame allocations in the 2D highway chord + lyric render paths. `_ensureChordRenderCache` now also caches `sortedNotes` / `nonZeroNotes` / `nonZeroFrets` / `allMuted` / `hasMultipleNotes` (computed once per chord, invalidated on `src` / `_inverted` / `chordTemplates` change — the third key catches a stale `isOpen`-derived classification when the WS `chord_templates` message lands after the final `chords` chunk), so `drawChords` no longer re-sorts / re-filters / spreads min-max per visible chord per frame. The in-chord unison bend classification is folded inline (no `chordPositions.filter` × 2 per frame). `drawLyrics` memoizes `ctx.measureText` results in a two-level `Map<fontSize, Map<text, width>>` so cache hits don't allocate a composite string key. Lit-sustain shimmer in `drawSustains` swaps the 4 per-note-per-frame `Math.random()` calls for a 64-entry precomputed jitter LUT (xorshift32-seeded — the LUT contents are reload-stable and test-reproducible; rendered shimmer is deterministic per `createHighway()` instance, since the seed includes that instance's `_frameIdx`) indexed by `(frameIdx + n.s + ⌊n.t·60⌋)`, visually indistinguishable and allocation-free.
|
||||
|
||||
### Added
|
||||
- Optional JS type checking via `tsc --noEmit`. Added a `static/slopsmith.d.ts` ambient declaration file — the typed source of truth for the plugin-facing contract (`window.slopsmith`, `window.highway`, the highway WebSocket message shape, the `setRenderer` visualization contract, the keyboard-shortcut API) — plus a `tsconfig.json`, a `typecheck` npm script, and a CI step. TypeScript is a dev-only devDependency: no build/emit step, no runtime dependency, every shipped `.js` file stays byte-identical. Core `.js` files opt in individually with a `// @ts-check` directive (currently `static/app.js` and `static/highway.js`); files without it are unaffected.
|
||||
- **Player progression: Mastery Rank, instrument-path challenges, daily/weekly quests, Decibels currency, cosmetics shop (spec 010).** Onboarding gains two steps: pick one or more **instrument paths** (Guitar / Bass / Drums — data-driven, more can ship as content) and a **calibration challenge** offer (play the bundled Slopsmith Diagnostic with note detection at 100% accuracy — or skip; either way you reach **Mastery Rank 1**, and a skipped calibration can still be completed later from the Progress screen). Each path levels by completing a content-defined number of **challenges** (any order) from that level's set; Mastery Rank = onboarding rank + the sum of path levels, starting at 0 on a fresh install. The existing unified XP backend is untouched but the frontend renames it to **Decibels (dB)** — a spendable currency earned ONLY by playing (songs, FeedBarcade rounds, quest rewards; no real-money path exists or may be added) — with spend tracked in a separate wallet so lifetime earnings stay monotonic. Rotating **daily/weekly quests** (deterministic per period, lazy instantiation, local-midnight / Monday resets) award dB and feed `quest_completed` challenges. A new **Progress** screen (rank hero, per-path checklists, quest countdowns, add-a-path) and **Shop** screen (themes via CSS-variable swaps under `html[data-fb-theme]`, avatar frames; atomic balance-checked purchases — 402 on insufficient dB, 409 on re-buy) join the v3 nav, and the topbar badge now shows Rank + challenge-set progress + dB balance. All definitions live in `data/progression/` JSON (paths/levels/challenges, quest pools, shop catalog) — adding a rank, challenge, quest, or cosmetic is a content edit + restart, never code; invalid content degrades to logged warnings. New tables (additive + idempotent): `progression_state`, `player_paths`, `challenge_progress`, `quest_state`, `wallet`, `shop_owned`, `shop_equipped`. New endpoints: `GET /api/progression`, `POST /api/progression/paths|onboarding|events` (events whitelists `minigame_run`; `song_completed` stays server-derived inside `POST /api/stats`, which now resolves the instrument server-side and reports an additive `progression` outcome key), `GET /api/shop`, `POST /api/shop/buy|equip`; equipped cosmetics ride along on `GET /api/profile`. A new **`progression` capability domain** (core-owned, kind: command, safety: safe — `inspect`, `record-event`, `list-shop`, `buy-item`/`equip-item` gated on user action) emits `challenge-completed`/`quest-completed`/`path-level-up`/`rank-changed`/`db-changed`/`calibration-completed`/`cosmetic-equipped`, mirrored as `progression:*` window events, with a redaction-safe diagnostics contributor; backend plugins get the symmetric `record_progression_event` context hook (the bundled minigames hub reports runs through it, guarded for standalone). Spec: `specs/010-progression-domain/`. Tests: `tests/test_progression.py`, `tests/test_progression_api.py`. **Migration notes:** existing XP totals carry over as lifetime dB (balance = lifetime − spent); resetting a per-source XP contribution (e.g. a minigames profile reset) after spending can clamp the spendable balance to 0 until new dB is earned; drums-path v1 content uses currently-satisfiable goals (arcade rounds, quests, any-instrument plays) until drums scoring lands.
|
||||
- **3D highway score FX (notedetect game-scoring layer).** The bundled `highway_3d` renderer now visualizes the scoring layer shipped in slopsmith-plugin-notedetect ≥1.13: floating **"+N" score pops** above each judged gem (sourced from the note-state provider's new `{ points, mult, popKey }` verdict fields — chord members share the chord-level `popKey`, so a chord pops once, not once per string), plus session-level FX from the new `notedetect:fx` event — a particle burst at the strike line on streak milestones (25/50/every 100), an expanding ring pulse on multiplier tier-ups (×2/×3/×4), and a brief red wash when a ≥10 streak breaks. Colors and the pop font follow the user's notedetect scoring-UI skin (`slopsmith_notedetect_skin`: neon/esports/metal, refreshed live on the `notedetect:skin` bus event). Everything renders on the existing 2D overlay canvas from fixed-size slot pools — no Three.js geometry, no text-sprite cache traffic, near-zero cost when idle — and degrades to a silent no-op with older notedetect builds (the new fields/events simply never arrive). Splitscreen panels scope FX to their own detector instance via the bubbling per-panel `notedetect:fx` dispatch. `plugins/highway_3d` v3.24.1.
|
||||
- **3D highway: slide direction arrows + gem-follow animation.** Slide notes now show a ›/‹ arrow indicating which way the slide goes — on the note/gem itself, as an early preview on the neck before the note arrives, and (optionally) chained further ahead for multi-leg slides — each independently toggleable in Settings → 3D Highway (`slideArrowApproachVisible`, `slideArrowNeckVisible`, `slideArrowChainPreviewVisible`). The note gem also now visually glides from its starting fret to the slide's destination over the note's sustain and holds there through the brief post-sustain linger, instead of snapping back to the starting fret — most noticeable on unpitched "slide to nothing" notes. `plugins/highway_3d` v3.25.2.
|
||||
|
||||
@@ -547,6 +547,7 @@ Sloppak is the preferred format for new features. The [Stems plugin](https://git
|
||||
- **Styling** — Tailwind CSS utility classes, dark theme (`bg-dark-600`, `text-gray-300`, accent `#4080e0`, gold `#e8c040`). Tailwind is served as a **prebuilt** stylesheet (`static/tailwind.min.css`, regenerated by `bash scripts/build-tailwind.sh`), **never** the runtime Play CDN — the CDN's on-the-fly JIT rescanned the DOM on the main thread and dropped ~26% of frames with the 3D highway (slopsmith-desktop#110). The committed CSS only contains classes the build scanner saw, so CI (`tailwind-fresh`) rebuilds and diffs it; run the build script and commit when you add new classes. A plugin that uses classes not guaranteed in core (notably arbitrary values like `w-[37px]`) MUST ship its own compiled stylesheet via the `styles` manifest key, built with `corePlugins.preflight = false` (utilities only — core ships the one base reset). Plugins MUST NOT load the Tailwind Play CDN or any runtime CSS JIT. See constitution Principle II.
|
||||
- **Naming** — camelCase for JS functions, kebab-case for CSS classes, snake_case for plugin IDs
|
||||
- **Player layout** — `#player` is `display:flex; flex-direction:column; position:fixed; inset:0`. `#highway` is `flex:1`. `#player-controls` sits at the bottom. Hiding the highway collapses the layout — use `margin-top: auto` on controls if you need to hide it.
|
||||
- **Plugin contract types** — the plugin-facing JS surface (`window.slopsmith`, `window.highway`, the highway WebSocket message shape, the `setRenderer` contract, the keyboard-shortcut API) is declared in `static/slopsmith.d.ts`. That file is the typed source of truth — consult it for exact signatures, and update it when you change a contract. Core `.js` files opt into checking with a `// @ts-check` directive on line 1; `npm run typecheck` (`tsc --noEmit`, dev/CI-only) verifies them. No build or emit step — the shipped files are plain JS.
|
||||
|
||||
## Backend Conventions
|
||||
|
||||
|
||||
Generated
+16
-1
@@ -9,7 +9,8 @@
|
||||
"version": "1.0.0",
|
||||
"license": "AGPL-3.0-only",
|
||||
"devDependencies": {
|
||||
"@playwright/test": "^1.59.1"
|
||||
"@playwright/test": "^1.59.1",
|
||||
"typescript": "^5.4"
|
||||
}
|
||||
},
|
||||
"node_modules/@playwright/test": {
|
||||
@@ -74,6 +75,20 @@
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
}
|
||||
},
|
||||
"node_modules/typescript": {
|
||||
"version": "5.9.3",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz",
|
||||
"integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==",
|
||||
"dev": true,
|
||||
"license": "Apache-2.0",
|
||||
"bin": {
|
||||
"tsc": "bin/tsc",
|
||||
"tsserver": "bin/tsserver"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=14.17"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+5
-3
@@ -8,9 +8,11 @@
|
||||
"test:headed": "playwright test --headed",
|
||||
"test:debug": "playwright test --debug",
|
||||
"test:js": "node --test tests/js/*.test.js 'tests/plugins/*/js/*.test.js'",
|
||||
"install:playwright": "playwright install chromium"
|
||||
"install:playwright": "playwright install chromium",
|
||||
"typecheck": "tsc --noEmit"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@playwright/test": "^1.59.1"
|
||||
"@playwright/test": "^1.59.1",
|
||||
"typescript": "^5.4"
|
||||
}
|
||||
}
|
||||
}
|
||||
Vendored
+403
@@ -0,0 +1,403 @@
|
||||
/**
|
||||
* Slopsmith core — ambient plugin-contract declarations.
|
||||
*
|
||||
* This file is the typed source of truth for the plugin-facing JS surface:
|
||||
* `window.slopsmith`, `window.highway`, the highway WebSocket message shape,
|
||||
* and the `setRenderer` visualization contract. It is loaded into the `tsc`
|
||||
* program (see `tsconfig.json` `include`) as ambient types — core files that
|
||||
* carry `// @ts-check` pick these globals up without any `import`.
|
||||
*
|
||||
* Per the Constitution (Principle IV) these contracts are stable: a breaking
|
||||
* change here requires a CHANGELOG entry under "Migration notes".
|
||||
*
|
||||
* Hand-maintained — keep in sync with the live source. The runtime files
|
||||
* (`static/diagnostics.js`, `audio-mixer.js`, `tour-engine.js`,
|
||||
* `lottie-api.js`) are declared here but not themselves `@ts-check`'d yet.
|
||||
*/
|
||||
|
||||
// ─── Chart data wire shapes ─────────────────────────────────────────────────
|
||||
|
||||
/** A single fretted note as streamed over the highway WebSocket. */
|
||||
interface SlopsmithNote {
|
||||
/** Time, seconds. */
|
||||
t: number;
|
||||
/** String index (0 = lowest). */
|
||||
s: number;
|
||||
/** Fret number (0 = open). */
|
||||
f: number;
|
||||
/** Sustain length, seconds. */
|
||||
sus?: number;
|
||||
/** Hammer-on flag. */
|
||||
ho?: number;
|
||||
/** Pull-off flag. */
|
||||
po?: number;
|
||||
/** Slide-to fret. */
|
||||
sl?: number;
|
||||
/** Bend flag / amount. */
|
||||
bn?: number;
|
||||
[key: string]: unknown;
|
||||
}
|
||||
|
||||
/** A chord event: a cluster of notes sharing a time. */
|
||||
interface SlopsmithChord {
|
||||
/** Time, seconds. */
|
||||
t: number;
|
||||
/** Component notes (string/fret/sustain, no own `t`). */
|
||||
notes: Array<Omit<SlopsmithNote, 't'> & { t?: number }>;
|
||||
/** Index into the chord-templates table. */
|
||||
id?: number;
|
||||
[key: string]: unknown;
|
||||
}
|
||||
|
||||
interface SlopsmithBeat { time: number; measure: number; }
|
||||
interface SlopsmithSection { time: number; name: string; }
|
||||
interface SlopsmithAnchor { time: number; fret: number; width: number; }
|
||||
interface SlopsmithChordTemplate { name: string; frets: number[]; fingers?: number[]; }
|
||||
interface SlopsmithLyric { w: string; t: number; d: number; }
|
||||
interface SlopsmithToneChange { time: number; name: string; }
|
||||
|
||||
/** Per-note scoring judgment published via `highway.setNoteStateProvider`. */
|
||||
interface SlopsmithNoteState {
|
||||
state: 'hit' | 'active' | 'miss';
|
||||
alpha: number;
|
||||
color: string | null;
|
||||
}
|
||||
|
||||
/** A scorer callback: returns a judgment for a chart note, or nullish. */
|
||||
type SlopsmithNoteStateProvider = (
|
||||
note: SlopsmithNote,
|
||||
chartTime: number,
|
||||
) => SlopsmithNoteState | 'hit' | 'active' | 'miss' | null | undefined;
|
||||
|
||||
// ─── Highway WebSocket protocol ─────────────────────────────────────────────
|
||||
|
||||
/** `song_info` — song metadata frame. */
|
||||
interface SlopsmithSongInfo {
|
||||
type: 'song_info';
|
||||
title: string;
|
||||
artist: string;
|
||||
arrangement: string;
|
||||
arrangement_index: number;
|
||||
arrangements: Array<{ name: string; index: number }>;
|
||||
duration: number;
|
||||
/** Tuning offsets — length 6 for guitar, 4 for bass. */
|
||||
tuning: number[];
|
||||
capo: number;
|
||||
format: 'sloppak' | 'loose' | string;
|
||||
/** `null` when audio is unavailable. */
|
||||
audio_url: string | null;
|
||||
/** Non-null only when `audio_url` is null. */
|
||||
audio_error: string | null;
|
||||
/** Always present; empty array when there are no split stems. */
|
||||
stems: string[];
|
||||
/** Chart `<offset>`, seconds. Absent for sources without one. */
|
||||
offset?: number;
|
||||
/** Active-arrangement string count, when the server emits it. */
|
||||
stringCount?: number;
|
||||
[key: string]: unknown;
|
||||
}
|
||||
|
||||
/**
|
||||
* A frame streamed over `/ws/highway/{filename}`. Discriminated on `type`;
|
||||
* the case set is the `switch (msg.type)` in `highway.js`.
|
||||
*/
|
||||
type SlopsmithHighwayMessage =
|
||||
| { type: 'loading'; stage: string }
|
||||
| SlopsmithSongInfo
|
||||
| { type: 'beats'; data: SlopsmithBeat[] }
|
||||
| { type: 'sections'; data: SlopsmithSection[] }
|
||||
| { type: 'anchors'; data: SlopsmithAnchor[] }
|
||||
| { type: 'chord_templates'; data: SlopsmithChordTemplate[] }
|
||||
| { type: 'lyrics'; data: SlopsmithLyric[] }
|
||||
| { type: 'tone_changes'; base: string; data: SlopsmithToneChange[] }
|
||||
| { type: 'notes'; data: SlopsmithNote[] }
|
||||
| { type: 'chords'; data: SlopsmithChord[] }
|
||||
| { type: 'handshapes'; data: unknown[] }
|
||||
| { type: 'phrases'; data: unknown[]; total: number }
|
||||
| { type: 'ready' };
|
||||
|
||||
// ─── Visualization renderer (setRenderer) contract ──────────────────────────
|
||||
|
||||
/**
|
||||
* Per-frame snapshot handed to a renderer's `draw()` / `init()`. All chart
|
||||
* arrays are difficulty-filter-aware.
|
||||
*/
|
||||
interface SlopsmithRenderBundle {
|
||||
currentTime: number;
|
||||
songInfo: SlopsmithSongInfo | Record<string, never>;
|
||||
isReady: boolean;
|
||||
notes: SlopsmithNote[];
|
||||
chords: SlopsmithChord[];
|
||||
anchors: SlopsmithAnchor[];
|
||||
beats: SlopsmithBeat[];
|
||||
sections: SlopsmithSection[];
|
||||
chordTemplates: SlopsmithChordTemplate[];
|
||||
stringCount: number;
|
||||
lyrics: SlopsmithLyric[];
|
||||
toneChanges: SlopsmithToneChange[];
|
||||
toneBase: string;
|
||||
mastery: number;
|
||||
hasPhraseData: boolean;
|
||||
inverted: boolean;
|
||||
lefty: boolean;
|
||||
renderScale: number;
|
||||
lyricsVisible: boolean;
|
||||
/** 2D-highway depth projection for a time offset. */
|
||||
project: (tOffset: number) => { x: number; y: number; scale: number };
|
||||
/** 2D-highway horizontal fret position. */
|
||||
fretX: (fret: number, scale: number, w: number) => number;
|
||||
/** Per-note scoring state, or null when no provider is registered. */
|
||||
getNoteState: (note: SlopsmithNote, chartTime: number) => SlopsmithNoteState | null;
|
||||
}
|
||||
|
||||
/**
|
||||
* A renderer instance returned by a `window.slopsmithViz_<id>` factory.
|
||||
* Subject to multiple `init() … destroy()` cycles on one instance.
|
||||
*/
|
||||
interface SlopsmithRenderer {
|
||||
/** Required canvas context type; defaults to `'2d'` when omitted. */
|
||||
contextType?: '2d' | 'webgl2';
|
||||
init(canvas: HTMLCanvasElement, bundle: SlopsmithRenderBundle): void;
|
||||
draw(bundle: SlopsmithRenderBundle): void;
|
||||
resize?(w: number, h: number): void;
|
||||
destroy?(): void;
|
||||
}
|
||||
|
||||
/** A `window.slopsmithViz_<id>` factory: fresh renderer per call. */
|
||||
interface SlopsmithVizFactory {
|
||||
(): SlopsmithRenderer;
|
||||
/** Auto-mode predicate; static on the factory, not the instance. */
|
||||
matchesArrangement?: (songInfo: SlopsmithSongInfo | Record<string, never>) => unknown;
|
||||
/** Optional static mirror of the instance `contextType`. */
|
||||
contextType?: '2d' | 'webgl2';
|
||||
}
|
||||
|
||||
// ─── window.highway — the renderer API ──────────────────────────────────────
|
||||
|
||||
/** The object returned by `createHighway()` and exposed as `window.highway`. */
|
||||
interface SlopsmithHighway {
|
||||
init(canvas: HTMLCanvasElement, container?: HTMLElement | null): void;
|
||||
resize(): void;
|
||||
connect(wsUrl: string, opts?: {
|
||||
onError?: (err: string) => void;
|
||||
onReady?: () => void;
|
||||
[key: string]: unknown;
|
||||
}): void;
|
||||
reconnect(filename: string, arrangement: number): void;
|
||||
stop(): void;
|
||||
|
||||
setRenderScale(scale: number): void;
|
||||
getRenderScale(): number;
|
||||
getInverted(): boolean;
|
||||
setInverted(v: boolean): void;
|
||||
getLefty(): boolean;
|
||||
setLefty(on: boolean): void;
|
||||
|
||||
setMastery(fraction: number): void;
|
||||
getMastery(): number;
|
||||
hasPhraseData(): boolean;
|
||||
|
||||
setTime(t: number): void;
|
||||
getTime(): number;
|
||||
setAvOffset(ms: number): void;
|
||||
getAvOffset(): number;
|
||||
getBPM(t: number): number;
|
||||
getBeats(): SlopsmithBeat[];
|
||||
getAudioElement(): HTMLAudioElement | null;
|
||||
|
||||
setVisible(v: boolean | null): void;
|
||||
isVisible(): boolean;
|
||||
|
||||
getNotes(): SlopsmithNote[];
|
||||
getChords(): SlopsmithChord[];
|
||||
getChordTemplates(): SlopsmithChordTemplate[];
|
||||
getToneChanges(): SlopsmithToneChange[];
|
||||
getToneBase(): string;
|
||||
getSections(): SlopsmithSection[];
|
||||
getSongInfo(): SlopsmithSongInfo | Record<string, never>;
|
||||
getStringCount(): number;
|
||||
|
||||
addDrawHook(fn: (ctx: CanvasRenderingContext2D, w: number, h: number) => void): void;
|
||||
removeDrawHook(fn: (ctx: CanvasRenderingContext2D, w: number, h: number) => void): void;
|
||||
fireDrawHooks(ctx: CanvasRenderingContext2D, w: number, h: number): void;
|
||||
|
||||
setNoteStateProvider(fn: SlopsmithNoteStateProvider | null): void;
|
||||
getNoteStateProvider(): SlopsmithNoteStateProvider | null;
|
||||
getNoteState(note: SlopsmithNote, chartTime: number): SlopsmithNoteState | null;
|
||||
|
||||
project(tOffset: number): { x: number; y: number; scale: number };
|
||||
fretX(fret: number, scale: number, w: number): number;
|
||||
fillTextUnmirrored(text: string, x: number, y: number): void;
|
||||
|
||||
toggleLyrics(): void;
|
||||
getLyricsVisible(): boolean;
|
||||
setLyricsVisible(v: boolean): void;
|
||||
setOnLyricsChange(fn: (visible: boolean) => void): void;
|
||||
|
||||
setRenderer(r: SlopsmithRenderer | null | undefined): void;
|
||||
isDefaultRenderer(): boolean;
|
||||
}
|
||||
|
||||
// ─── window.slopsmith — event bus + namespaces ──────────────────────────────
|
||||
|
||||
/** Named event payloads carried on `window.slopsmith` CustomEvents (`event.detail`). */
|
||||
interface SlopsmithEventMap {
|
||||
'song:ready': { songInfo: SlopsmithSongInfo };
|
||||
'song:play': unknown;
|
||||
'song:pause': unknown;
|
||||
'song:seek': { from: number; to: number; reason: string | null };
|
||||
'highway:visibility': { visible: boolean; canvas: HTMLCanvasElement };
|
||||
'highway:canvas-replaced': {
|
||||
oldCanvas: HTMLCanvasElement;
|
||||
newCanvas: HTMLCanvasElement;
|
||||
contextType: '2d' | 'webgl2';
|
||||
};
|
||||
'viz:reverted': unknown;
|
||||
[event: string]: unknown;
|
||||
}
|
||||
|
||||
/** A labeled audio fader registered with the mixer (slopsmith#87). */
|
||||
interface SlopsmithFaderSpec {
|
||||
id: string;
|
||||
label: string;
|
||||
unit?: string;
|
||||
min: number;
|
||||
max: number;
|
||||
step: number;
|
||||
defaultValue: number;
|
||||
getValue: () => number;
|
||||
setValue: (v: number) => void;
|
||||
}
|
||||
|
||||
/** `window.slopsmith.audio` — mixer + song-volume surface (audio-mixer.js). */
|
||||
interface SlopsmithAudioApi {
|
||||
registerFader(spec: SlopsmithFaderSpec): void;
|
||||
unregisterFader(id: string): void;
|
||||
getFaders(): SlopsmithFaderSpec[];
|
||||
openMixer(): void;
|
||||
closeMixer(restoreFocus?: boolean): void;
|
||||
toggleMixer(): void;
|
||||
applySongVolume(v?: number | null): Promise<number>;
|
||||
readSongVolume(): number;
|
||||
}
|
||||
|
||||
/** `window.slopsmith.diagnostics` — client diagnostics surface (diagnostics.js). */
|
||||
interface SlopsmithDiagnosticsApi {
|
||||
contribute(pluginId: string, payload: unknown): void;
|
||||
snapshot(): unknown;
|
||||
snapshotConsole(): unknown;
|
||||
snapshotHardware(): Promise<unknown>;
|
||||
snapshotUa(): unknown;
|
||||
snapshotLocalStorage(): unknown;
|
||||
snapshotContributions(): unknown;
|
||||
}
|
||||
|
||||
/** `window.slopsmith` — the plugin event bus (an `EventTarget`). */
|
||||
interface SlopsmithApi extends EventTarget {
|
||||
currentSong: unknown;
|
||||
isPlaying: boolean;
|
||||
navigate(screenId: string, params?: Record<string, unknown>): void;
|
||||
getNavParams(): Record<string, unknown>;
|
||||
emit<K extends keyof SlopsmithEventMap>(event: K, detail: SlopsmithEventMap[K]): void;
|
||||
emit(event: string, detail?: unknown): void;
|
||||
on(event: string, fn: (e: Event) => void, options?: AddEventListenerOptions | boolean): void;
|
||||
off(event: string, fn: (e: Event) => void, options?: EventListenerOptions | boolean): void;
|
||||
setLoop(a: number, b: number): unknown;
|
||||
clearLoop(): void;
|
||||
getLoop(): { loopA: number | null; loopB: number | null };
|
||||
/** Attached by audio-mixer.js after it loads. */
|
||||
audio?: SlopsmithAudioApi;
|
||||
/** Attached by diagnostics.js early in `<head>`. */
|
||||
diagnostics?: SlopsmithDiagnosticsApi;
|
||||
/** Per-session map of loaded plugin screen.js versions. Owned by app.js. */
|
||||
_loadedPluginScripts?: Map<string, string>;
|
||||
[key: string]: unknown;
|
||||
}
|
||||
|
||||
// ─── Keyboard-shortcut API ──────────────────────────────────────────────────
|
||||
|
||||
/** A keyboard shortcut registration (see `window.registerShortcut`). */
|
||||
interface SlopsmithShortcutSpec {
|
||||
/** `e.key` value or `e.code`. */
|
||||
key: string;
|
||||
description: string;
|
||||
scope?: 'global' | 'player' | 'library' | 'settings' | string;
|
||||
condition?: () => boolean;
|
||||
handler: (e: KeyboardEvent) => void;
|
||||
/** Optional modifier-key requirements (ctrl/alt/shift/meta). */
|
||||
modifiers?: { ctrl?: boolean; alt?: boolean; shift?: boolean; meta?: boolean } | null;
|
||||
}
|
||||
|
||||
/** A panel-scoped shortcut registry returned by `createShortcutPanel`. */
|
||||
interface SlopsmithShortcutPanel {
|
||||
registerShortcut(spec: SlopsmithShortcutSpec): void;
|
||||
unregisterShortcut(key: string, scope?: string): boolean;
|
||||
clearShortcuts(): void;
|
||||
}
|
||||
|
||||
// ─── Global augmentations ───────────────────────────────────────────────────
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
/** Plugin event bus + namespaces. Owned by app.js. */
|
||||
slopsmith: SlopsmithApi;
|
||||
/** The shared highway renderer instance. */
|
||||
highway: SlopsmithHighway;
|
||||
/** Factory for additional highway instances (splitscreen panels). */
|
||||
createHighway(): SlopsmithHighway;
|
||||
/** Loads and plays a song into the player. */
|
||||
playSong(filename: string, arrangement?: number): Promise<void>;
|
||||
/** Switches the active single-page-app screen. */
|
||||
showScreen(id: string): Promise<void>;
|
||||
|
||||
/** Keyboard-shortcut registry. */
|
||||
registerShortcut(options: SlopsmithShortcutSpec): void;
|
||||
unregisterShortcut(key: string, scope?: string): boolean;
|
||||
createShortcutPanel(id: string): SlopsmithShortcutPanel;
|
||||
setActiveShortcutPanel(id: string): void;
|
||||
getActiveShortcutPanel(): string;
|
||||
clearWindowShortcuts(windowId: string): number;
|
||||
getShortcutWindowId(): string;
|
||||
isInShortcutPanel(): boolean;
|
||||
getGlobalShortcutContext(): unknown;
|
||||
_setDebugShortcuts(enabled: boolean): void;
|
||||
_listShortcuts(): void;
|
||||
_testShortcut(key: string, scope?: string): unknown;
|
||||
/** Debug-only internals exposed by app.js. */
|
||||
_panels?: unknown;
|
||||
_getCurrentContext?: () => unknown;
|
||||
_isShortcutActive?: (shortcut: unknown, ctx: unknown) => boolean;
|
||||
|
||||
/** Desktop JUCE audio bridge — present only in slopsmith-desktop. */
|
||||
jucePlayer?: unknown;
|
||||
_juceMode?: boolean;
|
||||
_juceAudioUrl?: string | null;
|
||||
|
||||
/** Native desktop bridge — present only when running inside slopsmith-desktop. */
|
||||
slopsmithDesktop?: any;
|
||||
/** Demo analytics hook — real impl set by demo.js, else null. */
|
||||
slopsmithDemoTrack?: ((event: string, props?: unknown) => void) | null;
|
||||
|
||||
/** Lottie animation helper (lottie-api.js). */
|
||||
slopsmithLottie?: unknown;
|
||||
/** Guided-tour engine (tour-engine.js). */
|
||||
slopsmithTour?: unknown;
|
||||
|
||||
/**
|
||||
* Visualization factories — one per `type: "visualization"` plugin,
|
||||
* keyed `slopsmithViz_<id>`. Indexed access is intentionally loose.
|
||||
*/
|
||||
[vizFactory: `slopsmithViz_${string}`]: SlopsmithVizFactory;
|
||||
}
|
||||
|
||||
/** Bare global — assigned via `window.registerShortcut =` in app.js. */
|
||||
function registerShortcut(options: SlopsmithShortcutSpec): void;
|
||||
/** Bare global — assigned via `window.unregisterShortcut =` in app.js. */
|
||||
function unregisterShortcut(key: string, scope?: string): boolean;
|
||||
/** Bare global — assigned via `window.createShortcutPanel =` in app.js. */
|
||||
function createShortcutPanel(id: string): SlopsmithShortcutPanel;
|
||||
/** Bare global — assigned via `window.setActiveShortcutPanel =` in app.js. */
|
||||
function setActiveShortcutPanel(id: string): void;
|
||||
}
|
||||
|
||||
export {};
|
||||
+10
-59
@@ -16,18 +16,7 @@ const APP_JS = path.join(__dirname, '..', '..', 'static', 'app.js');
|
||||
function extractFunction(src, signature) {
|
||||
const start = src.indexOf(signature);
|
||||
if (start === -1) throw new Error(`extractFunction: '${signature}' not found in app.js`);
|
||||
let scan = start + signature.length;
|
||||
if (src[scan] === '(') {
|
||||
let parenDepth = 1;
|
||||
scan++;
|
||||
while (scan < src.length && parenDepth > 0) {
|
||||
const ch = src[scan];
|
||||
if (ch === '(') parenDepth++;
|
||||
else if (ch === ')') parenDepth--;
|
||||
scan++;
|
||||
}
|
||||
}
|
||||
const openBrace = src.indexOf('{', scan);
|
||||
const openBrace = src.indexOf('{', start);
|
||||
let depth = 1;
|
||||
let i = openBrace + 1;
|
||||
while (i < src.length && depth > 0) {
|
||||
@@ -42,12 +31,8 @@ function extractFunction(src, signature) {
|
||||
|
||||
function buildSandbox() {
|
||||
const seekCalls = [];
|
||||
const sectionPracticeModeCalls = [];
|
||||
const transportEvents = [];
|
||||
const sandbox = {
|
||||
seekCalls,
|
||||
sectionPracticeModeCalls,
|
||||
transportEvents,
|
||||
// Mutable state (declared as `var` in eval prelude so it lives on
|
||||
// the sandbox global and the extracted functions can read/write).
|
||||
// The actual values are set below.
|
||||
@@ -81,13 +66,6 @@ function buildSandbox() {
|
||||
// updateLoopUI references formatTime for the label; we don't
|
||||
// assert on the label text in these tests, so a stub is enough.
|
||||
formatTime: (s) => String(s),
|
||||
window: {
|
||||
slopsmith: {
|
||||
playback: {
|
||||
transportEvent: (...args) => transportEvents.push(args),
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
vm.createContext(sandbox);
|
||||
return sandbox;
|
||||
@@ -99,15 +77,7 @@ function loadFunctions(sandbox, src) {
|
||||
const code = `
|
||||
var loopA = null;
|
||||
var loopB = null;
|
||||
var _loopMutationGen = 0;
|
||||
var _sectionPracticeSelected = -1;
|
||||
var _sectionPracticeWholeSection = false;
|
||||
var _sectionPracticeSavedPartIndex = 0;
|
||||
function _setSectionPracticeMode(on, opts) {
|
||||
sectionPracticeModeCalls.push({ on, opts: opts || {} });
|
||||
}
|
||||
function _updateSectionPracticeHighlight(ct) {}
|
||||
${extractFunction(src, 'function clearLoop(')}
|
||||
${extractFunction(src, 'function clearLoop()')}
|
||||
${extractFunction(src, 'function _syncSavedLoopSelection()')}
|
||||
${extractFunction(src, 'async function setLoop(')}
|
||||
${extractFunction(src, 'function updateLoopUI()')}
|
||||
@@ -210,30 +180,6 @@ test('clearLoop resets loopA/loopB to null', async () => {
|
||||
const { loopA, loopB } = sandbox.__getLoop();
|
||||
assert.equal(loopA, null);
|
||||
assert.equal(loopB, null);
|
||||
assert.equal(sandbox.sectionPracticeModeCalls.length, 1);
|
||||
assert.equal(sandbox.sectionPracticeModeCalls[0].on, false);
|
||||
// Field-wise: vm-context objects break deepStrictEqual across realms.
|
||||
assert.equal(sandbox.sectionPracticeModeCalls[0].opts.skipClearLoop, true);
|
||||
});
|
||||
|
||||
test('loop helpers emit transport snapshots by default and can suppress adapter echoes', async () => {
|
||||
const src = fs.readFileSync(APP_JS, 'utf8');
|
||||
const sandbox = buildSandbox();
|
||||
loadFunctions(sandbox, src);
|
||||
|
||||
await sandbox.__setLoop(5, 10);
|
||||
sandbox.__clearLoop();
|
||||
|
||||
assert.equal(sandbox.transportEvents.length, 2);
|
||||
assert.equal(sandbox.transportEvents[0][0], 'loop-set');
|
||||
assert.equal(JSON.stringify(sandbox.transportEvents[0][1].loop), JSON.stringify({ startTime: 5, endTime: 10, enabled: true, state: 'active' }));
|
||||
assert.equal(sandbox.transportEvents[1][0], 'loop-cleared');
|
||||
assert.equal(JSON.stringify(sandbox.transportEvents[1][1].loop), JSON.stringify({ enabled: false, state: 'inactive' }));
|
||||
|
||||
sandbox.transportEvents.length = 0;
|
||||
await sandbox.__setLoop(7, 11, { emitTransportEvent: false });
|
||||
sandbox.__clearLoop({ emitTransportEvent: false });
|
||||
assert.equal(sandbox.transportEvents.length, 0);
|
||||
});
|
||||
|
||||
test('window.slopsmith API surface declares setLoop/clearLoop/getLoop', () => {
|
||||
@@ -242,9 +188,14 @@ test('window.slopsmith API surface declares setLoop/clearLoop/getLoop', () => {
|
||||
// renaming silently.
|
||||
const src = fs.readFileSync(APP_JS, 'utf8');
|
||||
// Find the slopsmith Object.assign block and check method presence.
|
||||
const m = src.match(/window\.slopsmith\s*=\s*Object\.assign\(_slopsmithBus,\s*\{([\s\S]*?)\}\);\s*if \(_slopsmithExisting/);
|
||||
assert.ok(m, 'slopsmith Object.assign block not found');
|
||||
const block = m[1];
|
||||
// Tolerates an optional `/** @type {...} */ (` JSDoc cast prefix on the
|
||||
// assignment (added when app.js opted into `// @ts-check`).
|
||||
const startMatch = src.match(
|
||||
/window\.slopsmith\s*=\s*(?:\/\*\*[\s\S]*?\*\/\s*\(\s*)?Object\.assign\((?:new EventTarget\(\)|_\w+),\s*\{/);
|
||||
assert.ok(startMatch, 'slopsmith Object.assign block not found');
|
||||
// The setLoop/clearLoop/getLoop methods live within the literal that
|
||||
// follows; a bounded slice is robust against `})`-containing bodies.
|
||||
const block = src.slice(startMatch.index, startMatch.index + 2000);
|
||||
assert.match(block, /setLoop\s*\(/, 'setLoop method missing from slopsmith API');
|
||||
assert.match(block, /clearLoop\s*\(/, 'clearLoop method missing from slopsmith API');
|
||||
assert.match(block, /getLoop\s*\(/, 'getLoop method missing from slopsmith API');
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"allowJs": true,
|
||||
"checkJs": false,
|
||||
"noEmit": true,
|
||||
"strict": true,
|
||||
"target": "es2022",
|
||||
"lib": ["es2022", "dom", "dom.iterable"],
|
||||
"skipLibCheck": true
|
||||
},
|
||||
"include": ["static/**/*.js", "static/**/*.d.ts"],
|
||||
"exclude": ["static/vendor/**", "node_modules"]
|
||||
}
|
||||
Reference in New Issue
Block a user