mirror of
https://github.com/jparkerweb/plan2code.git
synced 2026-11-16 20:45:33 -08:00
Play recorded songs in Light Trails and add lives and power-ups
AI Assisted
This commit is contained in:
1 parent
cc97161a23
commit
cc02631ab5
21 files changed
+1094
-786
No files matched your search
@@ -2090,7 +2090,7 @@ function racing(round) {
|
||||
|
||||
const trailsEvents = (round, type) => round.events.filter((e) => e.type === type);
|
||||
|
||||
test("Light Trails: a round starts at level 1 with three lives, two boosts and one rival, everyone on the grid", () => {
|
||||
test("Light Trails: a round starts at level 1 with five lives, two boosts and one rival, everyone on the grid", () => {
|
||||
const round = trails.newRound(still);
|
||||
assert.equal(round.level, 1);
|
||||
assert.equal(round.lives, trails.START_LIVES);
|
||||
@@ -2323,6 +2323,190 @@ test("Light Trails: pads turn up from level 2, never at level 1", () => {
|
||||
assert.ok(Object.hasOwn(trails.POWERS, two.items[0].kind));
|
||||
});
|
||||
|
||||
test("Light Trails: five lives to start, a life back every LIFE_SCORE points, never past MAX_LIVES", () => {
|
||||
const round = racing(trails.newRound(still));
|
||||
assert.equal(trails.START_LIVES, 5);
|
||||
assert.equal(round.lives, 5);
|
||||
round.score = trails.LIFE_SCORE - 1;
|
||||
trails.awardLives(round);
|
||||
assert.equal(round.lives, 5, "not yet");
|
||||
round.score = trails.LIFE_SCORE;
|
||||
trails.awardLives(round);
|
||||
assert.equal(round.lives, 6, "one life at the mark");
|
||||
assert.deepEqual(trailsEvents(round, "bonusLife").map((e) => e.lives), [6]);
|
||||
round.score = trails.LIFE_SCORE * 3 + 10;
|
||||
trails.awardLives(round);
|
||||
assert.equal(round.lives, 8, "one for each mark passed");
|
||||
round.lives = trails.MAX_LIVES;
|
||||
round.score = trails.LIFE_SCORE * 10;
|
||||
trails.awardLives(round);
|
||||
assert.equal(round.lives, trails.MAX_LIVES, "capped");
|
||||
assert.equal(round.nextLifeAt, trails.LIFE_SCORE * 11, "and the mark moves on, so none is saved up");
|
||||
});
|
||||
|
||||
test("Light Trails: every pad turns up only from its own arena, a Heart only while there is room for a life, and a Mystery never becomes another", () => {
|
||||
const round = trails.newRound(still);
|
||||
let n = 1;
|
||||
const random = () => (n = (n * 1664525 + 1013904223) % 4294967296) / 4294967296;
|
||||
for (let level = 2; level <= trails.MAX_LEVEL; level++) {
|
||||
round.level = level;
|
||||
const seen = new Set(Array.from({ length: 3000 }, () => trails.pickPower(round, random)));
|
||||
const due = Object.keys(trails.POWERS).filter((k) => trails.POWERS[k].from <= level);
|
||||
assert.deepEqual([...seen].sort(), due.sort(), `level ${level} offers exactly the pads due by then`);
|
||||
}
|
||||
assert.equal(trails.POWERS.life.from, 2, "a Heart from the first arena with pads");
|
||||
round.lives = trails.MAX_LIVES;
|
||||
assert.ok(Array.from({ length: 2000 }, () => trails.pickPower(round, random)).every((k) => k !== "life"), "no Heart at full lives");
|
||||
round.lives = 3;
|
||||
assert.ok(Array.from({ length: 2000 }, () => trails.pickPower(round, random, true)).every((k) => k !== "mystery"));
|
||||
});
|
||||
|
||||
test("Light Trails: a Heart pad gives a life", () => {
|
||||
const round = racing(trails.newRound(still));
|
||||
trails.applyPower(round, "life");
|
||||
assert.equal(round.lives, trails.START_LIVES + 1);
|
||||
});
|
||||
|
||||
test("Light Trails: a Shield takes your next crash, wiping the trails round you and riding on, and is held from heat to heat until then", () => {
|
||||
const round = racing(trails.newRound(still));
|
||||
const you = round.riders[0];
|
||||
trails.applyPower(round, "shield");
|
||||
assert.equal(round.shield, true);
|
||||
park(round, you, 10, 15, "right");
|
||||
round.grid[15 * trails.COLS + 11] = 2;
|
||||
round.grid[14 * trails.COLS + 10] = 2;
|
||||
round.grid[16 * trails.COLS + 10] = 2;
|
||||
trails.advance(round, trails.STEP_MS + trails.GRACE_MS + 8, still);
|
||||
assert.equal(you.alive, true, "boxed in on three sides, and the Shield saved you");
|
||||
assert.equal(round.shield, false, "it is used up");
|
||||
assert.equal(trailsEvents(round, "shield").length, 1);
|
||||
assert.equal(round.grid[15 * trails.COLS + 11] === 2, false, "the trail ahead was wiped");
|
||||
assert.equal(round.lives, trails.START_LIVES);
|
||||
// Held through a heat won.
|
||||
const two = racing(trails.newRound(still));
|
||||
trails.applyPower(two, "shield");
|
||||
trails.newHeat(two, still);
|
||||
assert.equal(two.shield, true, "a new heat keeps it");
|
||||
// A wall all round is still a crash.
|
||||
const three = racing(trails.newRound(still));
|
||||
trails.applyPower(three, "shield");
|
||||
park(three, three.riders[0], 0, 0, "left");
|
||||
three.grid[1] = trails.WALL;
|
||||
three.grid[trails.COLS] = trails.WALL;
|
||||
trails.advance(three, trails.STEP_MS + trails.GRACE_MS + 8, still);
|
||||
assert.equal(three.riders[0].alive, false, "nowhere to go");
|
||||
});
|
||||
|
||||
test("Light Trails: a Laser zaps a rival head in your line through trails, scoring the cut, but holds fire behind a crystal", () => {
|
||||
const round = racing(trails.newRound(still));
|
||||
const [you, rival] = round.riders;
|
||||
park(round, you, 5, 15, "right");
|
||||
park(round, rival, 15, 15, "up");
|
||||
round.grid[15 * trails.COLS + 9] = 2;
|
||||
trails.applyPower(round, "laser");
|
||||
assert.equal(rival.alive, false, "zapped at once");
|
||||
assert.equal(rival.by, "laser");
|
||||
assert.equal(round.grid[15 * trails.COLS + 9], 0, "the trail in the beam is cut");
|
||||
assert.equal(round.shots, trails.LASER_SHOTS - 1);
|
||||
const [out] = trailsEvents(round, "out");
|
||||
assert.equal(out.points, trails.OUT_POINTS + trails.CUT_POINTS, "a laser out pays the cut");
|
||||
assert.equal(trailsEvents(round, "laser").length, 1);
|
||||
|
||||
const two = trails.newRound(still);
|
||||
two.level = 3;
|
||||
racing(trails.newHeat(two, still));
|
||||
const [me, foe] = two.riders;
|
||||
park(two, me, 5, 15, "right");
|
||||
park(two, foe, 15, 15, "up");
|
||||
two.grid[15 * trails.COLS + 10] = trails.BLOCK;
|
||||
trails.applyPower(two, "laser");
|
||||
assert.equal(foe.alive, true, "a crystal in the way holds the shot");
|
||||
assert.equal(two.shots, trails.LASER_SHOTS);
|
||||
park(two, foe, 3, 15, "up");
|
||||
assert.equal(trails.fireLaser(two), false, "and it only fires ahead");
|
||||
});
|
||||
|
||||
test("Light Trails: Score x2 doubles every point while it runs", () => {
|
||||
const round = racing(trails.newRound(still));
|
||||
round.level = 2;
|
||||
trails.applyPower(round, "coin");
|
||||
const single = round.score;
|
||||
trails.applyPower(round, "double");
|
||||
trails.applyPower(round, "coin");
|
||||
assert.equal(round.score - single, single * 2);
|
||||
});
|
||||
|
||||
test("Light Trails: a Wide Trail lays your wall three cells wide, and the cells go with the trail", () => {
|
||||
const round = racing(trails.newRound(still));
|
||||
const you = round.riders[0];
|
||||
park(round, you, 10, 15, "right");
|
||||
trails.applyPower(round, "wide");
|
||||
trails.advance(round, trails.STEP_MS, still);
|
||||
assert.equal(you.x, 11);
|
||||
assert.equal(round.grid[14 * trails.COLS + 11], 1, "above");
|
||||
assert.equal(round.grid[16 * trails.COLS + 11], 1, "and below");
|
||||
assert.equal(you.wide.length, 2);
|
||||
trails.applyPower(round, "eraser");
|
||||
assert.equal(you.wide.length, 0, "wiped cells leave the list");
|
||||
});
|
||||
|
||||
test("Light Trails: Hyperjump moves you to an open cell clear of everyone, facing open space", () => {
|
||||
const round = racing(trails.newRound(still));
|
||||
const you = round.riders[0];
|
||||
let n = 9;
|
||||
const random = () => (n = (n * 1664525 + 1013904223) % 4294967296) / 4294967296;
|
||||
// Fill the left half with trail, so the jump has to take you right.
|
||||
for (let y = 0; y < trails.ROWS; y++) for (let x = 0; x < 18; x++) if (!(x === you.x && y === you.y)) round.grid[y * trails.COLS + x] = 2;
|
||||
assert.equal(trails.hyperjump(round, random), true);
|
||||
assert.ok(you.x >= 18, "out in the open half");
|
||||
assert.equal(round.grid[you.y * trails.COLS + you.x], 1, "on a cell of your own");
|
||||
for (const r of round.riders.slice(1)) assert.ok(Math.abs(r.x - you.x) + Math.abs(r.y - you.y) >= 4, "clear of the rivals");
|
||||
const d = { up: [0, -1], down: [0, 1], left: [-1, 0], right: [1, 0] }[you.dir];
|
||||
assert.equal(round.grid[(you.y + d[1]) * trails.COLS + you.x + d[0]], 0, "facing an open cell");
|
||||
assert.equal(trailsEvents(round, "jump").length, 1);
|
||||
});
|
||||
|
||||
test("Light Trails: Coin Rain drops coins all over that never hold back the pads", () => {
|
||||
const round = trails.newRound(still);
|
||||
round.level = 4;
|
||||
racing(trails.newHeat(round, still));
|
||||
let n = 4;
|
||||
const random = () => (n = (n * 1664525 + 1013904223) % 4294967296) / 4294967296;
|
||||
trails.applyPower(round, "rain", random);
|
||||
const coins = round.items.filter((it) => it.kind === "coin" && it.rain);
|
||||
assert.equal(coins.length, trails.RAIN_COINS);
|
||||
round.nextItem = 1;
|
||||
trails.advance(round, 8, random);
|
||||
assert.equal(round.items.filter((it) => !it.rain).length, 1, "a pad still turns up");
|
||||
});
|
||||
|
||||
test("Light Trails: a Mystery pad turns into another pad and says which", () => {
|
||||
const round = trails.newRound(still);
|
||||
round.level = 9;
|
||||
racing(trails.newHeat(round, still));
|
||||
trails.applyPower(round, "mystery", () => 0.1);
|
||||
const [m] = trailsEvents(round, "mystery");
|
||||
assert.ok(m && m.kind !== "mystery" && Object.hasOwn(trails.POWERS, m.kind));
|
||||
assert.deepEqual(trailsEvents(round, "power").map((e) => e.kind), [m.kind], "the pad it became is applied");
|
||||
});
|
||||
|
||||
test("Light Trails game: every new pad, its effects and its events draw and sound without throwing", () => {
|
||||
const { canvas } = stubCanvas();
|
||||
const tones = [];
|
||||
const g = trails.default.create({ canvas, tone: (n) => tones.push(n) });
|
||||
g.resize(800, 600);
|
||||
g.start();
|
||||
g.cheat(true);
|
||||
const round = g.round;
|
||||
round.level = 9;
|
||||
trails.newHeat(round, still);
|
||||
g.tick(2000);
|
||||
for (const kind of Object.keys(trails.POWERS)) trails.spawnItem(round, kind);
|
||||
for (const kind of ["shield", "laser", "double", "wide", "jump", "rain", "mystery", "life"]) trails.applyPower(round, kind);
|
||||
for (let i = 0; i < 60; i++) g.tick(50);
|
||||
for (const name of ["trailsHeart", "shieldUp", "trailsJump", "mystery"]) assert.ok(tones.includes(name), `${name} played`);
|
||||
});
|
||||
|
||||
test("Light Trails: from level 5 the walls close in a ring at a time, warning first, and catch anyone on the ring", () => {
|
||||
const round = trails.newRound(still);
|
||||
round.level = 5;
|
||||
@@ -2354,45 +2538,85 @@ test("Light Trails: the start screen reads the furthest arena from the memo and
|
||||
|
||||
test("Light Trails: every pill's text reads at 4.5:1 on its backing and its timer's tint, lives and running effects included, in light and dark under every highlight", () => {
|
||||
checkPills(trails.default, {
|
||||
setup: (r) => Object.assign(r.effects, { boost: trails.BOOST_MS / 2, phase: 1500, slow: 2000 }),
|
||||
expect: ["LV 1", "♥", "~BOOST", "~PHASE", "~SLOW-MO", "1 RIVAL"],
|
||||
setup: (r) => {
|
||||
Object.assign(r.effects, { boost: trails.BOOST_MS / 2, phase: 1500, slow: 2000, laser: 3000, double: 4000, wide: 2000 });
|
||||
Object.assign(r, { shield: true, shots: 2 });
|
||||
},
|
||||
expect: ["LV 1", "♥", "~BOOST", "~PHASE", "~SLOW-MO", "1 RIVAL", "SHIELD", "~LASER", "x2 SCORE", "WIDE"],
|
||||
});
|
||||
});
|
||||
|
||||
test("Light Trails: a round deals every track once, never opens on the last opener, and gives each arena its own", () => {
|
||||
test("Light Trails: its sounds play SFX_LOUDER times as loud, but for the engine drones, left low under the songs", () => {
|
||||
const { canvas } = stubCanvas();
|
||||
const tones = [];
|
||||
const hums = [];
|
||||
const g = trails.default.create({ canvas, tone: (...a) => tones.push(a), hum: (...a) => hums.push(a) });
|
||||
g.resize(800, 600);
|
||||
g.start();
|
||||
g.cheat(true);
|
||||
for (let i = 0; i < 200; i++) g.tick(50);
|
||||
assert.ok(trails.SFX_LOUDER > 1, "louder than made");
|
||||
assert.ok(tones.length && tones.every((a) => a[3] === trails.SFX_LOUDER), "every tone lifted");
|
||||
const drones = hums.filter((a) => a[0] === "trails:you" || a[0] === "trails:rival");
|
||||
assert.ok(drones.length && drones.every((a) => a[4] === 1), "the drones are not");
|
||||
assert.ok(hums.filter((a) => !drones.includes(a)).every((a) => a[4] === trails.SFX_LOUDER), "every other hum is");
|
||||
});
|
||||
|
||||
test("Light Trails: a deal holds every song once and never opens on the last song", () => {
|
||||
let n = 11;
|
||||
const random = () => (n = (n * 1664525 + 1013904223) % 4294967296) / 4294967296;
|
||||
for (let i = 0; i < 20; i++) {
|
||||
const last = trails.MUSIC_TRACKS[i % trails.MUSIC_TRACKS.length];
|
||||
const deck = trails.dealMusic(random, last);
|
||||
assert.deepEqual([...deck].sort(), [...trails.MUSIC_TRACKS].sort(), "every track once");
|
||||
assert.notEqual(deck[0], last, "never opens on the last opener");
|
||||
assert.deepEqual([...deck].sort(), [...trails.MUSIC_TRACKS].sort(), "every song once");
|
||||
assert.notEqual(deck[0], last, "never opens on the last song");
|
||||
}
|
||||
const deck = trails.dealMusic(random, null);
|
||||
const heard = Array.from({ length: trails.MAX_LEVEL }, (_, i) => trails.trackFor(deck, i + 1));
|
||||
assert.equal(new Set(heard).size, trails.MAX_LEVEL, "nine arenas hear nine different tracks");
|
||||
assert.equal(trails.trackFor(deck, 0), deck[0], "a level below one hears the first");
|
||||
assert.notDeepEqual(trails.dealMusic(random, null), trails.dealMusic(random, null), "a new deal is a new order");
|
||||
});
|
||||
|
||||
test("Light Trails: the music's heat is low while a heat lines up, rises once the riders go, more so down to the last rival, and is full on a boost", () => {
|
||||
const round = trails.newRound(() => 0.5);
|
||||
assert.equal(round.phase, "ready");
|
||||
const waiting = trails.heat(round);
|
||||
assert.ok(waiting < 0.5, "lining up: no lead yet");
|
||||
round.level = 2;
|
||||
trails.newHeat(round, () => 0.5);
|
||||
round.phase = "race";
|
||||
assert.ok(round.riders.filter((r) => r.id !== 0).length >= 2, "two rivals at level 2");
|
||||
const racing = trails.heat(round);
|
||||
assert.ok(racing >= 0.5 && racing < 1, "racing with rivals left: the lead is in");
|
||||
for (const r of round.riders.filter((r) => r.id !== 0).slice(1)) r.alive = false;
|
||||
assert.ok(trails.heat(round) > racing && trails.heat(round) < 1, "down to the last rival it climbs");
|
||||
round.effects = { ...round.effects, boost: trails.BOOST_MS };
|
||||
assert.equal(trails.heat(round), 1, "a boost pushes it all the way");
|
||||
test("Light Trails: a run plays each song in full from the top, moves on only when one ends, and deals again after the last", () => {
|
||||
const { canvas } = stubCanvas();
|
||||
const asked = [];
|
||||
let reply = "playing";
|
||||
const g = trails.default.create({ canvas, music: (name, intensity, options) => (asked.push({ name, restart: Boolean(options && options.restart) }), reply) });
|
||||
g.resize(800, 600);
|
||||
g.start();
|
||||
g.cheat(true);
|
||||
g.tick(16);
|
||||
g.tick(16);
|
||||
assert.deepEqual(asked.map((a) => a.restart), [true, false], "the first song starts from the top, then plays on");
|
||||
assert.equal(asked[1].name, asked[0].name, "the same song until it ends");
|
||||
const heard = [asked[0].name];
|
||||
for (let i = 0; i < trails.MUSIC_TRACKS.length; i++) {
|
||||
reply = "ended";
|
||||
g.tick(16);
|
||||
reply = "playing";
|
||||
g.tick(16);
|
||||
const next = asked.at(-1);
|
||||
assert.ok(next.restart, "the next song starts from the top");
|
||||
assert.notEqual(next.name, heard.at(-1), "and is another song");
|
||||
heard.push(next.name);
|
||||
}
|
||||
assert.deepEqual(heard.slice(0, trails.MUSIC_TRACKS.length).sort(), [...trails.MUSIC_TRACKS].sort(), "every song once before any plays again");
|
||||
});
|
||||
|
||||
test("Light Trails: it asks for the deal's track while a round runs, silent before and after, and the next round opens on another", () => {
|
||||
test("Light Trails: a song the music could not play yet still starts from the top once it can", () => {
|
||||
const { canvas } = stubCanvas();
|
||||
const asked = [];
|
||||
let reply;
|
||||
const g = trails.default.create({ canvas, music: (name, intensity, options) => (asked.push(Boolean(options && options.restart)), reply) });
|
||||
g.resize(800, 600);
|
||||
g.start();
|
||||
g.cheat(true);
|
||||
g.tick(16);
|
||||
g.tick(16);
|
||||
reply = "playing";
|
||||
g.tick(16);
|
||||
g.tick(16);
|
||||
assert.deepEqual(asked, [true, true, true, false], "the restart is asked for until the music takes it");
|
||||
});
|
||||
|
||||
test("Light Trails: it asks for the deal's song while a round runs, silent before and after, and the next round opens on another", () => {
|
||||
const { canvas } = stubCanvas();
|
||||
const asked = [];
|
||||
const g = trails.default.create({ canvas, music: (name, level) => asked.push([name, level]) });
|
||||
@@ -2403,7 +2627,7 @@ test("Light Trails: it asks for the deal's track while a round runs, silent befo
|
||||
g.tick(16);
|
||||
assert.equal(asked.length, 1, "asked once a tick");
|
||||
const [first] = asked[0];
|
||||
assert.ok(trails.MUSIC_TRACKS.includes(first), "a track the game has");
|
||||
assert.ok(trails.MUSIC_TRACKS.includes(first), "a song the game has");
|
||||
g.round.lives = 1;
|
||||
for (let i = 0; i < 2000 && g.state === "running"; i++) g.tick(50);
|
||||
assert.equal(g.state, "over", "riding straight ends the round");
|
||||
|
||||
@@ -2516,7 +2516,7 @@ test("Ghoul Rush plays in the real window: its board's shape and Planny big enou
|
||||
test("the server serves the activities' scripts, golf's seventeen, Light Trails, Bug Hunt, Sunset Drive, Stack Deploy, Bumper Ring's two, Rapids Run's two, Hot Potato's two, Crossing Rush's two, Bounce Road's seven, Ghoul Rush's ninety-five, every game's sound effects and the shared pills included", () => {
|
||||
const server = fs.readFileSync(new URL("../src/web-console/static.mjs", import.meta.url), "utf8");
|
||||
const servable = server.slice(server.indexOf("const SERVABLE = new Set(["), server.indexOf("]);", server.indexOf("const SERVABLE = new Set([")));
|
||||
for (const file of ["activities.js", "tones.js", "music.js", "activities/snake.js", "activities/snake-music.js", "activities/trails-music.js", "screens/activities.js", "activities/golf.js", "activities/golf-holes.js", "activities/golf-draw.js", "activities/golf-decor.js", "activities/golf-kit.js", "activities/golf-paint.js", "activities/golf-looks.js", "activities/golf-course-pirate.js", "activities/golf-course-cave.js", "activities/golf-course-dino.js", "activities/golf-course-candy.js", "activities/golf-course-space.js", "activities/golf-course-frost.js", "activities/golf-look-dino.js", "activities/golf-look-candy.js", "activities/golf-look-space.js", "activities/golf-look-frost.js", "activities/trails.js", "activities/bugs.js", "activities/drive.js", "activities/stack.js", "activities/bumper.js", "activities/bumper-draw.js", "activities/rapids.js", "activities/rapids-draw.js", "activities/fuse.js", "activities/fuse-draw.js", "activities/hop.js", "activities/hop-draw.js", "activities/bounce.js", "activities/bounce-draw.js", "activities/bounce-roads.js", "activities/bounce-road.js", "activities/bounce-rivals.js", "activities/bounce-scenery.js", "activities/bounce-cars.js", "activities/ghoul-rush/ghoul.js", "activities/ghoul-rush/draw/ghoul-draw.js", "activities/ghoul-rush/core/ghoul-rooms.js", "activities/ghoul-rush/stages/wing/ghoul-bones.js", "activities/ghoul-rush/stages/wing/ghoul-bones-draw.js", "activities/ghoul-rush/stages/graveyard/ghoul-graveyard.js", "activities/ghoul-rush/stages/graveyard/ghoul-graveyard-draw.js", "activities/ghoul-rush/stages/grounds/ghoul-grounds.js", "activities/ghoul-rush/stages/grounds/ghoul-grounds-draw.js", "activities/ghoul-rush/stages/chapel/ghoul-chapel.js", "activities/ghoul-rush/stages/chapel/ghoul-chapel-draw.js", "activities/ghoul-rush/stages/sanatorium/ghoul-sanatorium.js", "activities/ghoul-rush/stages/sanatorium/ghoul-sanatorium-draw.js", "activities/ghoul-rush/stages/village/ghoul-village.js", "activities/ghoul-rush/stages/village/ghoul-village-draw.js", "activities/ghoul-rush/stages/village/ghoul-village-world.js", "activities/ghoul-rush/stages/village/ghoul-village-wolf.js", "activities/ghoul-rush/stages/mine/ghoul-mine.js", "activities/ghoul-rush/stages/mine/ghoul-mine-draw.js", "activities/ghoul-rush/stages/mine/ghoul-mine-world.js", "activities/ghoul-rush/stages/mine/ghoul-mine-tommy.js", "activities/ghoul-rush/rides/cart/ghoul-cart.js", "activities/ghoul-rush/rides/cart/ghoul-cart-draw.js", "activities/ghoul-rush/rides/sled/ghoul-sled.js", "activities/ghoul-rush/rides/sled/ghoul-sled-draw.js", "activities/ghoul-rush/rides/gurney/ghoul-gurney.js", "activities/ghoul-rush/rides/gurney/ghoul-gurney-draw.js", "activities/ghoul-rush/rides/banister/ghoul-banister.js", "activities/ghoul-rush/rides/banister/ghoul-banister-draw.js", "activities/ghoul-rush/rides/banister/ghoul-sfx-banister.js", "activities/ghoul-rush/rides/hearse/ghoul-hearse.js", "activities/ghoul-rush/rides/hearse/ghoul-hearse-draw.js", "activities/ghoul-rush/rides/wagon/ghoul-wagon.js", "activities/ghoul-rush/rides/wagon/ghoul-wagon-draw.js", "activities/ghoul-rush/rides/pew/ghoul-pew.js", "activities/ghoul-rush/rides/pew/ghoul-pew-draw.js", "activities/ghoul-rush/rides/pew/ghoul-pew-course.js", "activities/ghoul-rush/rides/pew/ghoul-pew-world.js", "activities/ghoul-rush/rides/mower/ghoul-mower.js", "activities/ghoul-rush/rides/mower/ghoul-mower-draw.js", "activities/ghoul-rush/rides/tray/ghoul-tray.js", "activities/ghoul-rush/rides/tray/ghoul-tray-draw.js", "activities/ghoul-rush/stages/carnival/ghoul-carnival.js", "activities/ghoul-rush/stages/carnival/ghoul-carnival-draw.js", "activities/ghoul-rush/stages/carnival/ghoul-carnival-world.js", "activities/ghoul-rush/stages/frozen/ghoul-frozen.js", "activities/ghoul-rush/stages/frozen/ghoul-frozen-draw.js", "activities/ghoul-rush/stages/frozen/ghoul-frozen-world.js", "activities/ghoul-rush/arms/ghoul-flare.js", "activities/ghoul-rush/stages/bog/ghoul-bog.js", "activities/ghoul-rush/stages/bog/ghoul-bog-draw.js", "activities/ghoul-rush/stages/marrow/ghoul-marrow.js", "activities/ghoul-rush/stages/marrow/ghoul-marrow-draw.js", "activities/ghoul-rush/rides/mat/ghoul-mat-room.js", "activities/ghoul-rush/rides/mat/ghoul-mat.js", "activities/ghoul-rush/rides/mat/ghoul-mat-draw.js", "activities/ghoul-rush/stages/marrow/ghoul-dollhouse-room.js", "activities/ghoul-rush/stages/marrow/ghoul-marrow-eye.js", "activities/ghoul-rush/stages/marrow/ghoul-marrow-eye-draw.js", "activities/ghoul-rush/rides/bonestair/ghoul-bonestair-room.js", "activities/ghoul-rush/rides/bonestair/ghoul-bonestair.js", "activities/ghoul-rush/rides/bonestair/ghoul-bonestair-draw.js", "activities/ghoul-rush/stages/marrow/ghoul-pit-room.js", "activities/ghoul-rush/stages/marrow/ghoul-marrow-heart.js", "activities/ghoul-rush/stages/marrow/ghoul-marrow-heart-draw.js", "activities/ghoul-rush/story/ghoul-ending.js", "activities/ghoul-rush/story/ghoul-ending-draw.js", "activities/ghoul-rush/Line truncated
|
||||
for (const file of ["activities.js", "tones.js", "music.js", "activities/snake.js", "activities/snake-music.js", "screens/activities.js", "activities/golf.js", "activities/golf-holes.js", "activities/golf-draw.js", "activities/golf-decor.js", "activities/golf-kit.js", "activities/golf-paint.js", "activities/golf-looks.js", "activities/golf-course-pirate.js", "activities/golf-course-cave.js", "activities/golf-course-dino.js", "activities/golf-course-candy.js", "activities/golf-course-space.js", "activities/golf-course-frost.js", "activities/golf-look-dino.js", "activities/golf-look-candy.js", "activities/golf-look-space.js", "activities/golf-look-frost.js", "activities/trails.js", "activities/bugs.js", "activities/drive.js", "activities/stack.js", "activities/bumper.js", "activities/bumper-draw.js", "activities/rapids.js", "activities/rapids-draw.js", "activities/fuse.js", "activities/fuse-draw.js", "activities/hop.js", "activities/hop-draw.js", "activities/bounce.js", "activities/bounce-draw.js", "activities/bounce-roads.js", "activities/bounce-road.js", "activities/bounce-rivals.js", "activities/bounce-scenery.js", "activities/bounce-cars.js", "activities/ghoul-rush/ghoul.js", "activities/ghoul-rush/draw/ghoul-draw.js", "activities/ghoul-rush/core/ghoul-rooms.js", "activities/ghoul-rush/stages/wing/ghoul-bones.js", "activities/ghoul-rush/stages/wing/ghoul-bones-draw.js", "activities/ghoul-rush/stages/graveyard/ghoul-graveyard.js", "activities/ghoul-rush/stages/graveyard/ghoul-graveyard-draw.js", "activities/ghoul-rush/stages/grounds/ghoul-grounds.js", "activities/ghoul-rush/stages/grounds/ghoul-grounds-draw.js", "activities/ghoul-rush/stages/chapel/ghoul-chapel.js", "activities/ghoul-rush/stages/chapel/ghoul-chapel-draw.js", "activities/ghoul-rush/stages/sanatorium/ghoul-sanatorium.js", "activities/ghoul-rush/stages/sanatorium/ghoul-sanatorium-draw.js", "activities/ghoul-rush/stages/village/ghoul-village.js", "activities/ghoul-rush/stages/village/ghoul-village-draw.js", "activities/ghoul-rush/stages/village/ghoul-village-world.js", "activities/ghoul-rush/stages/village/ghoul-village-wolf.js", "activities/ghoul-rush/stages/mine/ghoul-mine.js", "activities/ghoul-rush/stages/mine/ghoul-mine-draw.js", "activities/ghoul-rush/stages/mine/ghoul-mine-world.js", "activities/ghoul-rush/stages/mine/ghoul-mine-tommy.js", "activities/ghoul-rush/rides/cart/ghoul-cart.js", "activities/ghoul-rush/rides/cart/ghoul-cart-draw.js", "activities/ghoul-rush/rides/sled/ghoul-sled.js", "activities/ghoul-rush/rides/sled/ghoul-sled-draw.js", "activities/ghoul-rush/rides/gurney/ghoul-gurney.js", "activities/ghoul-rush/rides/gurney/ghoul-gurney-draw.js", "activities/ghoul-rush/rides/banister/ghoul-banister.js", "activities/ghoul-rush/rides/banister/ghoul-banister-draw.js", "activities/ghoul-rush/rides/banister/ghoul-sfx-banister.js", "activities/ghoul-rush/rides/hearse/ghoul-hearse.js", "activities/ghoul-rush/rides/hearse/ghoul-hearse-draw.js", "activities/ghoul-rush/rides/wagon/ghoul-wagon.js", "activities/ghoul-rush/rides/wagon/ghoul-wagon-draw.js", "activities/ghoul-rush/rides/pew/ghoul-pew.js", "activities/ghoul-rush/rides/pew/ghoul-pew-draw.js", "activities/ghoul-rush/rides/pew/ghoul-pew-course.js", "activities/ghoul-rush/rides/pew/ghoul-pew-world.js", "activities/ghoul-rush/rides/mower/ghoul-mower.js", "activities/ghoul-rush/rides/mower/ghoul-mower-draw.js", "activities/ghoul-rush/rides/tray/ghoul-tray.js", "activities/ghoul-rush/rides/tray/ghoul-tray-draw.js", "activities/ghoul-rush/stages/carnival/ghoul-carnival.js", "activities/ghoul-rush/stages/carnival/ghoul-carnival-draw.js", "activities/ghoul-rush/stages/carnival/ghoul-carnival-world.js", "activities/ghoul-rush/stages/frozen/ghoul-frozen.js", "activities/ghoul-rush/stages/frozen/ghoul-frozen-draw.js", "activities/ghoul-rush/stages/frozen/ghoul-frozen-world.js", "activities/ghoul-rush/arms/ghoul-flare.js", "activities/ghoul-rush/stages/bog/ghoul-bog.js", "activities/ghoul-rush/stages/bog/ghoul-bog-draw.js", "activities/ghoul-rush/stages/marrow/ghoul-marrow.js", "activities/ghoul-rush/stages/marrow/ghoul-marrow-draw.js", "activities/ghoul-rush/rides/mat/ghoul-mat-room.js", "activities/ghoul-rush/rides/mat/ghoul-mat.js", "activities/ghoul-rush/rides/mat/ghoul-mat-draw.js", "activities/ghoul-rush/stages/marrow/ghoul-dollhouse-room.js", "activities/ghoul-rush/stages/marrow/ghoul-marrow-eye.js", "activities/ghoul-rush/stages/marrow/ghoul-marrow-eye-draw.js", "activities/ghoul-rush/rides/bonestair/ghoul-bonestair-room.js", "activities/ghoul-rush/rides/bonestair/ghoul-bonestair.js", "activities/ghoul-rush/rides/bonestair/ghoul-bonestair-draw.js", "activities/ghoul-rush/stages/marrow/ghoul-pit-room.js", "activities/ghoul-rush/stages/marrow/ghoul-marrow-heart.js", "activities/ghoul-rush/stages/marrow/ghoul-marrow-heart-draw.js", "activities/ghoul-rush/story/ghoul-ending.js", "activities/ghoul-rush/story/ghoul-ending-draw.js", "activities/ghoul-rush/draw/ghoul-picker-draw.js", "aLine truncated
|
||||
assert.ok(servable.includes(`"${file}"`), `SERVABLE includes ${file}`);
|
||||
}
|
||||
});
|
||||
@@ -8,10 +8,11 @@ import assert from "node:assert/strict";
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { HUM_TABLES, TONE_TABLES, hum, humNames, hushTones, tone, toneNames } from "../src/web-console/public/tones.js";
|
||||
import { HUM_TABLES, LOUDER_MAX, TONE_TABLES, hum, humNames, hushTones, tone, toneNames } from "../src/web-console/public/tones.js";
|
||||
import { looks } from "../src/web-console/public/looks.js";
|
||||
import { compileTrack, hushMusic, music, musicNames, noteFreq } from "../src/web-console/public/music.js";
|
||||
import { MUSIC_TABLES } from "../src/web-console/public/tones.js";
|
||||
import { SONG_PEAK, compileTrack, hushMusic, music, musicNames, noteFreq, songNames } from "../src/web-console/public/music.js";
|
||||
import { MUSIC_TABLES, SONG_TABLES } from "../src/web-console/public/tones.js";
|
||||
import { SERVABLE } from "../src/web-console/static.mjs";
|
||||
import { REGIONS, ROAD_MUSIC } from "../src/web-console/public/activities/drive.js";
|
||||
import { MUSIC_TRACKS } from "../src/web-console/public/activities/snake.js";
|
||||
import snakeSfx from "../src/web-console/public/activities/snake-sfx.js";
|
||||
@@ -168,6 +169,35 @@ test("a hum starts once, follows each call without starting more, and goes quiet
|
||||
}
|
||||
});
|
||||
|
||||
test("a game's `louder` lifts a tone and a hum past their usual loudness, never past LOUDER_MAX", () => {
|
||||
const saved = { sound: looks.sound, ctor: globalThis.AudioContext };
|
||||
const { Ctx, made } = AUDIO;
|
||||
globalThis.AudioContext = Ctx;
|
||||
try {
|
||||
looks.sound = true;
|
||||
hushTones();
|
||||
const tonePeak = (louder) => {
|
||||
const mark = made.gains.length;
|
||||
tone("coin", 1, 1, louder);
|
||||
return Math.max(...made.gains.slice(mark).flatMap((g) => g.gain.ramps.map((r) => r.v)));
|
||||
};
|
||||
const base = tonePeak(undefined);
|
||||
assert.ok(Math.abs(tonePeak(1.4) - base * 1.4) < 1e-9, "a tone 1.4 times as loud");
|
||||
assert.ok(Math.abs(tonePeak(9) - base * LOUDER_MAX) < 1e-9, "capped at LOUDER_MAX");
|
||||
const humLevel = (id, louder) => {
|
||||
const mark = made.gains.length;
|
||||
hum(id, "wind", 1, 1, louder);
|
||||
return made.gains.slice(mark).flatMap((g) => g.gain.ramps).filter((r) => r.kind === "target").at(-1).v;
|
||||
};
|
||||
const plain = humLevel("plain", undefined);
|
||||
assert.ok(Math.abs(humLevel("lifted", 1.4) - plain * 1.4) < 1e-9, "a hum 1.4 times as loud");
|
||||
} finally {
|
||||
hushTones();
|
||||
looks.sound = saved.sound;
|
||||
globalThis.AudioContext = saved.ctor;
|
||||
}
|
||||
});
|
||||
|
||||
test("every tone or hum a game's source names is one the engine has", () => {
|
||||
const tones = new Set(toneNames());
|
||||
const hums = new Set(humNames());
|
||||
@@ -358,16 +388,110 @@ test("music: Snake lists exactly the tracks it has, each a real track that no ot
|
||||
}
|
||||
});
|
||||
|
||||
test("music: Light Trails lists exactly the tracks it has, each a real track that no other game defines, enough for every arena", () => {
|
||||
const tracks = new Set(musicNames());
|
||||
assert.deepEqual([...TRAILS_TRACKS].sort(), Object.keys(trailsSfx.music).sort(), "the game lists the tracks its sound file has");
|
||||
assert.ok(TRAILS_TRACKS.length >= 9, "nine arenas, none hearing a track twice");
|
||||
test("music: Light Trails lists exactly the songs it has, each an mp3 on disk the server serves, and no chiptune tracks", () => {
|
||||
const songs = new Set(songNames());
|
||||
assert.equal(trailsSfx.music, undefined, "its music is the songs, not note data");
|
||||
assert.deepEqual([...TRAILS_TRACKS].sort(), Object.keys(trailsSfx.songs).sort(), "the game lists the songs its sound file has");
|
||||
for (const name of TRAILS_TRACKS) {
|
||||
assert.ok(tracks.has(name), `track "${name}" exists`);
|
||||
assert.equal(MUSIC_TABLES.filter((t) => Object.hasOwn(t, name)).length, 1, `${name} is defined once`);
|
||||
assert.ok(songs.has(name), `song "${name}" exists`);
|
||||
assert.equal(SONG_TABLES.filter((t) => Object.hasOwn(t, name)).length, 1, `${name} is defined once`);
|
||||
assert.ok(!musicNames().includes(name), `${name} is not also a chiptune track`);
|
||||
const file = trailsSfx.songs[name];
|
||||
assert.ok(SERVABLE.has(file), `${file} is servable`);
|
||||
assert.ok(fs.statSync(path.join(ROOT, "src/web-console/public", file)).size > 0, `${file} is on disk`);
|
||||
}
|
||||
});
|
||||
|
||||
// A stand-in <audio>: records what music.js asks of it.
|
||||
class FakeAudio {
|
||||
static made = [];
|
||||
constructor(src) {
|
||||
Object.assign(this, { src, volume: 1, paused: true, ended: false, currentTime: 0, plays: 0, loads: 0 });
|
||||
FakeAudio.made.push(this);
|
||||
}
|
||||
play() {
|
||||
this.paused = false;
|
||||
this.plays += 1;
|
||||
return Promise.resolve();
|
||||
}
|
||||
pause() {
|
||||
this.paused = true;
|
||||
}
|
||||
load() {
|
||||
Object.assign(this, { paused: true, ended: false, currentTime: 0, loads: this.loads + 1 });
|
||||
}
|
||||
}
|
||||
|
||||
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
||||
|
||||
async function withSongs(fn) {
|
||||
const saved = { sound: looks.sound, Audio: globalThis.Audio };
|
||||
globalThis.Audio = FakeAudio;
|
||||
looks.sound = true;
|
||||
hushMusic();
|
||||
try {
|
||||
await fn();
|
||||
} finally {
|
||||
hushMusic();
|
||||
looks.sound = saved.sound;
|
||||
globalThis.Audio = saved.Audio;
|
||||
}
|
||||
}
|
||||
|
||||
test("music: a song plays from its file, fades in toward its level, says when it has ended, and starts from the top again when asked", () =>
|
||||
withSongs(async () => {
|
||||
const [name] = TRAILS_TRACKS;
|
||||
assert.equal(music(name, 1, 1, { restart: true }), "playing");
|
||||
const el = FakeAudio.made.find((a) => a.src === `/${trailsSfx.songs[name]}`);
|
||||
assert.ok(el, "an element for the song's file");
|
||||
assert.ok(!el.paused && el.plays === 1, "it plays");
|
||||
for (let i = 0; i < 20; i++) {
|
||||
music(name, 1, 1);
|
||||
await sleep(30);
|
||||
}
|
||||
assert.ok(Math.abs(el.volume - SONG_PEAK) < 1e-9, "glided up to its level");
|
||||
assert.equal(el.plays, 1, "asked for again, it is not started again");
|
||||
el.currentTime = 100;
|
||||
el.ended = true;
|
||||
el.paused = true;
|
||||
assert.equal(music(name, 1, 1), "ended", "a song played through says so");
|
||||
assert.equal(el.plays, 1, "and is not looped");
|
||||
assert.equal(music(name, 1, 1, { restart: true }), "playing", "a restart plays it again");
|
||||
assert.equal(el.loads, 1, "from the top");
|
||||
assert.equal(el.currentTime, 0);
|
||||
}));
|
||||
|
||||
test("music: a song no longer asked for fades out and pauses where it was, and another song replaces it at once", () =>
|
||||
withSongs(async () => {
|
||||
const [first, second] = TRAILS_TRACKS;
|
||||
music(first, 1, 0.5);
|
||||
const el = FakeAudio.made.findLast((a) => a.src === `/${trailsSfx.songs[first]}`);
|
||||
const loads = el.loads;
|
||||
await sleep(800);
|
||||
assert.ok(el.paused, "paused once it stops being asked for");
|
||||
assert.equal(el.volume, 0, "faded to silence");
|
||||
assert.equal(el.loads, loads, "kept where it was, so it picks up again mid-song");
|
||||
music(first, 1, 0.5);
|
||||
assert.ok(!el.paused, "asked for again, it plays on");
|
||||
music(second, 1, 0.5);
|
||||
assert.ok(el.paused, "another song stops it");
|
||||
assert.ok(!FakeAudio.made.at(-1).paused, "and plays");
|
||||
hushMusic();
|
||||
assert.ok(FakeAudio.made.every((a) => a.paused), "a hush pauses every song");
|
||||
}));
|
||||
|
||||
test("music: a song plays nothing while Play sounds is off, at a volume of 0, or with no audio", () =>
|
||||
withSongs(async () => {
|
||||
const [name] = TRAILS_TRACKS;
|
||||
looks.sound = false;
|
||||
assert.equal(music(name, 1, 1), undefined);
|
||||
looks.sound = true;
|
||||
assert.equal(music(name, 1, 0), undefined);
|
||||
globalThis.Audio = undefined;
|
||||
assert.equal(music(name, 1, 1), undefined);
|
||||
assert.ok(FakeAudio.made.filter((a) => a.src === `/${trailsSfx.songs[name]}`).every((a) => a.paused), "nothing plays");
|
||||
}));
|
||||
|
||||
test("music: every Sunset Drive road has a song, and every song is a real track", () => {
|
||||
const tracks = new Set(musicNames());
|
||||
assert.deepEqual(Object.keys(ROAD_MUSIC).sort(), Object.keys(REGIONS).sort(), "a song for every road");
|
||||
|
||||
Reference in new issue
Block a user