La macchina del tempo da fuori: la partenza giù per Via Liguri Magelli col fulmine e le sgommate di fuoco, e l'arrivo al ritorno dal 1997 (macchina da dietro e davanti di Codex) (Andrea)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GiECd9KMfjthRUnujCGSzZ
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { existsSync } from 'node:fs';
|
||||
import * as C from '../src/engine/corsa.js';
|
||||
import { story } from '../src/story/story.js';
|
||||
|
||||
const run = (def, until) => { const c = C.newCorsa('x'); while (c.t < until) C.updateCorsa(c, def, 1 / 60); return c; };
|
||||
|
||||
test('la partenza: accelera giù per la strada, il fulmine la prende e sparisce; restano le sgommate', () => {
|
||||
const def = story.closeups.partenza;
|
||||
assert.equal(def.mode, 'parti');
|
||||
for (const src of Object.values(def.frames)) assert.ok(existsSync(src), src);
|
||||
const at = t => C.progress({ t }, def);
|
||||
assert.equal(at(0), 0);
|
||||
assert.ok(at(1.2) > 0 && at(1.6) - at(1.2) > at(1.2) - at(0.8), 'accelera');
|
||||
assert.ok(C.carShown({ t: 2 }, def) && !C.carShown({ t: C.PARTI.bolt + 0.2 }, def));
|
||||
const c = run(def, C.PARTI.bolt + 0.1);
|
||||
assert.ok(c.events.some(e => e.kind === 'corsa-tuono') && c.events.some(e => e.kind === 'corsa-fuoco'));
|
||||
assert.ok(!C.updateCorsa(c, def, 0.01));
|
||||
assert.ok(C.updateCorsa(run(def, C.PARTI.end - 0.01), def, 0.05), 'finita');
|
||||
});
|
||||
|
||||
test('l\'arrivo: il fulmine in fondo, poi viene avanti e ci passa accanto, fuori dal quadro', () => {
|
||||
const def = story.closeups.arrivo;
|
||||
const at = t => C.progress({ t }, def);
|
||||
assert.equal(at(0), 1); assert.equal(at(C.ARRIVA.bolt + C.ARRIVA.run + 0.1), 0);
|
||||
assert.ok(!C.carShown({ t: 0.1 }, def) && C.carShown({ t: 1 }, def));
|
||||
assert.ok(!C.carShown({ t: C.ARRIVA.bolt + C.ARRIVA.run + 0.1 }, def), 'passata');
|
||||
assert.ok(at(1.2) < at(0.8));
|
||||
});
|
||||
|
||||
test('il disegno della corsa non cambia lo stato e usa lo sfondo e i fotogrammi', () => {
|
||||
const calls = [], ctx = new Proxy({}, { get: (o, k) => k in o ? o[k] : (...args) => calls.push([k, ...args]) });
|
||||
const bg = { width: 640, height: 360 }, frames = { dietro: { width: 220, height: 190 }, lampi: { width: 220, height: 190 }, davanti: { width: 220, height: 190 } };
|
||||
for (const [id, t] of [['partenza', 1.4], ['partenza', 3.5], ['arrivo', 1.2], ['arrivo', 2.5]]) {
|
||||
const c = { ...C.newCorsa(id), t }, before = structuredClone(c);
|
||||
calls.length = 0;
|
||||
C.drawCorsa(ctx, c, story.closeups[id], { bg, frames, tint: null });
|
||||
assert.deepEqual(c, before);
|
||||
assert.ok(calls.some(([op, img]) => op === 'drawImage' && img === bg));
|
||||
assert.equal(calls.some(([op, img]) => op === 'drawImage' && Object.values(frames).includes(img)), t < 2.4, 'dopo il fulmine (o passata) la macchina non c\'è');
|
||||
assert.ok(calls.filter(([op]) => op === 'fillRect').length > 20, 'le fiamme');
|
||||
}
|
||||
});
|
||||
+17
-6
@@ -5,6 +5,18 @@ import { drawPoker, cardAt, HAND } from '../src/engine/poker-render.js';
|
||||
import { Game, MINIGAMES, TRIP } from '../src/engine/game.js';
|
||||
import { story } from '../src/story/story.js';
|
||||
import { settle } from './helpers.mjs';
|
||||
import { PARTI, ARRIVA } from '../src/engine/corsa.js';
|
||||
|
||||
// I primi piani che vanno da soli (il cruscotto, la partenza, l'arrivo): si lascia scorrere il tempo finché finiscono.
|
||||
function ride(g, seen = []) {
|
||||
for (let t = 0; t < TRIP.end + PARTI.end + ARRIVA.end + 2; t += 0.05) {
|
||||
if (g.closeup && seen.at(-1) !== g.closeup.id) seen.push(g.closeup.id);
|
||||
if (!g.closeup && !g.queue.length && !g.speech) break;
|
||||
if (g.speech) g.skip(); else g.update(0.05);
|
||||
}
|
||||
settle(g);
|
||||
return seen;
|
||||
}
|
||||
|
||||
const card = s => ({ rank: s.slice(0, -1), suit: { c: 'cuori', q: 'quadri', f: 'fiori', p: 'picche' }[s.at(-1)] });
|
||||
const hand = s => s.split(' ').map(card);
|
||||
@@ -71,8 +83,7 @@ test('la macchina del tempo: l\'Arcu la fa comparire, il viaggio porta al Barret
|
||||
assert.ok(!g.dialogue, 'finito il discorso, si è pronti a partire');
|
||||
g.act('use', 'macchina_tempo'); settle(g);
|
||||
assert.equal(g.closeup?.id, 'viaggio');
|
||||
for (let t = 0; t < TRIP.end + 0.5 && g.closeup; t += 0.05) g.update(0.05);
|
||||
settle(g);
|
||||
assert.deepEqual(ride(g), ['viaggio', 'partenza'], 'il cruscotto, poi la partenza da fuori');
|
||||
assert.equal(g.state.scene, 'barrettino_1997');
|
||||
g.act('talk', 'tavola'); settle(g);
|
||||
g.choose(g.options().findIndex(o => o.text.startsWith('C\'è posto'))); settle(g);
|
||||
@@ -82,7 +93,8 @@ test('la macchina del tempo: l\'Arcu la fa comparire, il viaggio porta al Barret
|
||||
g.closeupClose(); settle(g);
|
||||
assert.ok(g.state.flags.poker_vinto);
|
||||
assert.ok(g.hotspot('arcu'), 'l\'Arcu è venuto anche lui');
|
||||
g.act('walk', 'porta'); settle(g);
|
||||
g.act('walk', 'porta');
|
||||
assert.deepEqual(ride(g), ['arrivo'], 'al ritorno, l\'arrivo col fulmine');
|
||||
assert.equal(g.state.scene, 'via_liguri_magelli');
|
||||
assert.ok(!g.state.flags.macchina_trappola && !g.hotspot('macchina_tempo'), 'tornati, la macchina sparisce');
|
||||
assert.equal(g.goBack(), false, 'nel 2007 il pulsante non c\'è');
|
||||
@@ -91,11 +103,10 @@ test('la macchina del tempo: l\'Arcu la fa comparire, il viaggio porta al Barret
|
||||
g.choose(g.options().findIndex(o => o.text.startsWith('Bei tempi'))); settle(g);
|
||||
assert.ok(!g.dialogue, 'finito il discorso, si è pronti a partire');
|
||||
g.act('use', 'macchina_tempo'); settle(g);
|
||||
for (let t = 0; t < TRIP.end + 0.5 && g.closeup; t += 0.05) g.update(0.05);
|
||||
settle(g);
|
||||
ride(g);
|
||||
assert.equal(g.state.scene, 'barrettino_1997');
|
||||
assert.equal(g.scene.back.label, 'Torna al 2007');
|
||||
assert.ok(g.goBack()); settle(g);
|
||||
assert.ok(g.goBack()); ride(g);
|
||||
assert.equal(g.state.scene, 'via_liguri_magelli');
|
||||
assert.ok(!g.hotspot('macchina_tempo'));
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user