feat: Adding audio player + music to play

This commit is contained in:
gauvainboiche
2026-10-25 22:35:53 +01:00
parent 7a525d084a
commit dd4714f499
39 changed files with 850 additions and 81 deletions
+21 -4
View File
@@ -414,11 +414,11 @@ assert.equal(E.advanceDay(s, bal).blocked, "over");
mem.set(KEYS.slot(2), "{not json"); assert.equal(readSave(store, KEYS.slot(2)), null, "corrupt slot reads as empty");
mem.set(KEYS.slot(3), JSON.stringify({ nope: 1 })); assert.equal(readSave(store, KEYS.slot(3)), null);
assert.deepEqual(loadSettings(store), { lang: null, slow: false, sound: true, volume: 0.6 });
saveSettings(store, { lang: "fr", slow: true, sound: false, volume: 0.25 });
assert.deepEqual(loadSettings(store), { lang: "fr", slow: true, sound: false, volume: 0.25 });
assert.deepEqual(loadSettings(store), { lang: null, slow: false, sound: true, volume: 0.6, mix: { stamp: 1, paper: 1, page: 1, sign: 1, telegram: 1, alert: 1, chime: 1, tick: 1, countdown: 1, click: 1, ending: 1, music: 0.5 }, musicOn: true });
saveSettings(store, { lang: "fr", slow: true, sound: false, volume: 0.25, mix: { stamp: 0.3, paper: 2, music: 0.8 }, musicOn: false });
assert.deepEqual(loadSettings(store), { lang: "fr", slow: true, sound: false, volume: 0.25, mix: { stamp: 0.3, paper: 1, page: 1, sign: 1, telegram: 1, alert: 1, chime: 1, tick: 1, countdown: 1, click: 1, ending: 1, music: 0.8 }, musicOn: false }, "levels in range are kept, out-of-range ones fall back");
mem.set(KEYS.settings, JSON.stringify({ lang: "de", slow: "yes" }));
assert.deepEqual(loadSettings(store), { lang: null, slow: false, sound: true, volume: 0.6 }, "unknown values are ignored");
assert.deepEqual(loadSettings(store), { lang: null, slow: false, sound: true, volume: 0.6, mix: { stamp: 1, paper: 1, page: 1, sign: 1, telegram: 1, alert: 1, chime: 1, tick: 1, countdown: 1, click: 1, ending: 1, music: 0.5 }, musicOn: true }, "unknown values are ignored");
mem.set(KEYS.settings, JSON.stringify({ volume: 7, sound: "no" }));
assert.equal(loadSettings(store).volume, 0.6, "an out-of-range volume falls back to the default");
@@ -496,6 +496,23 @@ assert.equal(E.advanceDay(s, bal).blocked, "over");
assert.equal(E.consumeClock(E.createClock(), -50, 10000, 1, 60000), 0);
}
// 14. sound mixer keys and cassette titles
{
const { MIX_GROUPS, createAudio } = await import("../web/js/ui/audio.js");
const { prettyTitle } = await import("../web/js/ui/music.js");
const { MIX_KEYS, DEFAULT_MIX } = await import("../web/js/save/storage.js");
assert.deepEqual([...MIX_GROUPS, "music"], MIX_KEYS, "the mixer groups of audio.js and the saved levels list the same keys");
assert.equal(DEFAULT_MIX.music, 0.5);
// every sound belongs to a mixer group
const names = ["stampYes", "stampNo", "paper", "page", "sign", "telegram", "alert", "chime", "tick", "tock", "clockTick", "clockTock", "click", "fall", "fanfare"];
const { groupOf } = (() => { globalThis.document ??= { addEventListener() {} }; return createAudio(); })();
for (const n of names) assert.ok(MIX_GROUPS.includes(groupOf(n)), n + " has a mixer group");
assert.equal(prettyTitle("03_Evening_Report.mp3"), "Evening Report");
assert.equal(prettyTitle("Second-Tune.MP3"), "Second-Tune");
assert.equal(prettyTitle("12 - Night Train.mp3"), "Night Train");
assert.equal(prettyTitle("007.mp3"), "007", "a title made only of digits is kept");
}
// M8: world cycle, growing needs, card conditions on choices, coup from neglect, v1 saves
{
// the world cycle moves, stays within bounds and is part of the saved state