50 lines
2.3 KiB
JavaScript
50 lines
2.3 KiB
JavaScript
// Per-game music soundtrack overrides. Empty by default — every game plays
|
|
// the shared `default` soundtrack (data/music.json's `tracks` array),
|
|
// preloaded eagerly in PreloadScene exactly as before. To give a specific
|
|
// game its own soundtrack instead:
|
|
// 1. Add data/<name>-music.json: { "tracks": [{file, artist, title}, ...],
|
|
// "volume": 0.15 } — "volume" is optional (0-1, MusicPlayer's own
|
|
// default applies if omitted) and only affects this named soundtrack;
|
|
// the default soundtrack's volume is never touched by this mechanism.
|
|
// Actual mp3 files go at assets/music/<name>/...
|
|
// 2. Eager-load that JSON in PreloadScene (tiny metadata, mirrors the
|
|
// existing *-artwork.json convention) under cache key `<name>-music`.
|
|
// 3. In src/data/assetManifest.js, add `musicFrom(scene, '<name>-music')`
|
|
// to that game's MANIFEST entry so its audio bytes lazy-load only when
|
|
// the game is entered — never part of the shared default preload.
|
|
// 4. Add `<slug>: '<name>'` to GAME_SOUNDTRACK_OVERRIDES below.
|
|
// 5. In that game's scene, swap its MusicPlayer track-source line for:
|
|
// const { tracks, volume } = getGameSoundtrack(this);
|
|
// if (tracks.length) this.music = new MusicPlayer(this, tracks, volume);
|
|
export const GAME_SOUNDTRACK_OVERRIDES = {
|
|
superkart: 'nintendo',
|
|
advancewars: 'nintendo',
|
|
tetrisattack: 'nintendo',
|
|
excitebike: 'nintendo',
|
|
totalannihilation: 'hacker',
|
|
coloradodefense: 'arcadedark',
|
|
tempest: 'arcadedark',
|
|
defender: 'arcadedark',
|
|
mastermind: 'hacker',
|
|
balatro: 'hacker',
|
|
hexsweeper: 'hacker',
|
|
dotlink: 'hacker',
|
|
'2048': 'hacker',
|
|
swdbg: 'adventure',
|
|
spireclimb: 'adventure',
|
|
mahjong: 'chinese',
|
|
mahjongmatch: 'chinese',
|
|
zuma: 'zuma',
|
|
mastervega: 'masterofvega',
|
|
};
|
|
|
|
// Resolve the track list (and optional volume override) a game scene's
|
|
// MusicPlayer should shuffle through. `volume` is undefined for the default
|
|
// soundtrack, so MusicPlayer's own default kicks in unchanged.
|
|
export function getGameSoundtrack(scene) {
|
|
const name = GAME_SOUNDTRACK_OVERRIDES[scene.gameDef?.slug];
|
|
if (!name) return { tracks: scene.cache.json.get('music')?.tracks ?? [], volume: undefined };
|
|
const data = scene.cache.json.get(`${name}-music`);
|
|
return { tracks: data?.tracks ?? [], volume: data?.volume };
|
|
}
|