Files
leggenda-del-regolo/tests/music.test.mjs
T
manzoloandClaude Opus 5.5 5e6d7d4cfb Musichetta a 8 bit per il cartello «Manzolo (Poca) Art Presents»
tools/jingle.py la sintetizza da zero, a tempo con le scritte: arpeggio su MANZOLO, accordo su
Art, trombone triste sul (Poca), accordo finale su PRESENTS. Suona una volta sola; la musica del
titolo entra quando compare il titolo; saltando il cartello si salta anche lei. Senza un gesto
del giocatore il browser può tenerla muta.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UdeKd62opy9PKgpQXtVctF
2026-10-23 15:30:42 +02:00

45 lines
2.3 KiB
JavaScript

import test from 'node:test';
import assert from 'node:assert/strict';
import { existsSync } from 'node:fs';
import { trackFor, Music } from '../src/engine/music.js';
import { story } from '../src/story/story.js';
test('il brano giusto per titolo, fine e scena', () => {
const s = { music: { title: 't.mp3', game: 'g.mp3', ending: 'e.mp3' }, scenes: { a: {}, b: { music: 'b.mp3' } } };
assert.equal(trackFor(s, { screen: 'splash', scene: 'a' }), null, 'sotto il cartello suona solo la sua musichetta');
assert.equal(trackFor(s, { screen: 'title', scene: 'a' }), 't.mp3');
assert.equal(trackFor(s, { screen: 'intro', scene: 'a' }), 't.mp3');
assert.equal(trackFor(s, { screen: 'ending', scene: 'a' }), 'e.mp3');
assert.equal(trackFor(s, { screen: 'game', scene: 'a' }), 'g.mp3');
assert.equal(trackFor(s, { screen: 'game', scene: 'b' }), 'b.mp3');
assert.equal(trackFor({ scenes: {} }, { screen: 'game', scene: 'x' }), null);
});
test('volume e muto', () => {
const m = new Music({ volume: 0.5, muted: true });
assert.equal(m.setVolume(1.4), 1);
assert.equal(m.muted, false, 'alzare il volume toglie il muto');
assert.equal(m.toggle(), true);
assert.equal(m.setVolume(-1), 0);
assert.deepEqual(m.settings(), { volume: 0, muted: true });
});
test('i brani della storia esistono', () => {
const files = [...Object.values(story.music ?? {}), ...Object.values(story.scenes).map(s => s.music).filter(Boolean)];
assert.ok(files.length);
for (const f of files) assert.ok(existsSync(new URL('../' + f, import.meta.url)), `manca ${f}`);
});
test('mentre parla qualcuno la musica si abbassa, poi risale', () => {
globalThis.Audio ??= class { constructor(src) { this.src = src; this.volume = 0; this.paused = true; } play() { this.paused = false; return Promise.resolve(); } pause() { this.paused = true; } };
const m = new Music({ volume: 0.6 });
for (let i = 0; i < 40; i++) m.update('g.mp3', 0.1);
assert.equal(m.current.audio.volume, 0.6);
m.duck = 0.45;
for (let i = 0; i < 40; i++) m.update('g.mp3', 0.1);
assert.ok(Math.abs(m.current.audio.volume - 0.27) < 1e-9, 'abbassata sotto la voce');
m.duck = 1;
for (let i = 0; i < 40; i++) m.update('g.mp3', 0.1);
assert.equal(m.current.audio.volume, 0.6);
});