Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GiECd9KMfjthRUnujCGSzZ
92 lines
4.3 KiB
JavaScript
92 lines
4.3 KiB
JavaScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { readFileSync, existsSync } from 'node:fs';
|
|
import { story } from '../src/story/story.js';
|
|
import { Game } from '../src/engine/game.js';
|
|
import { inside } from '../src/engine/geometry.js';
|
|
import { settle } from './helpers.mjs';
|
|
|
|
// I veicoli sono dipinti nel quadro: il Betino in cima alla salita di Via Liguri Magelli e, prima del tramonto, la
|
|
// Ghiacciomobile dentro il muro giallo (Andrea, 29 ottobre). Nessuno è più uno sprite.
|
|
const SPRITES = [];
|
|
const VEHICLES = [['via_liguri_magelli', 'betino'], ['via_liguri_magelli', 'ghiacciomobile']];
|
|
test('i veicoli restano fuori dal percorso e lasciano liberi gli altri hotspot', () => {
|
|
for (const [scene, id, [lo, hi]] of SPRITES) {
|
|
const g = new Game(story);
|
|
g.go(scene);
|
|
settle(g);
|
|
const vehicles = [id];
|
|
{
|
|
const person = g.people().find(p => p.who === id), h = g.hotspot(id);
|
|
const url = new URL('../' + story.characters[id].sprite, import.meta.url);
|
|
const atlas = JSON.parse(readFileSync(url, 'utf8')), frame = atlas.frames.idle;
|
|
assert.ok(existsSync(new URL(atlas.image, url)));
|
|
assert.deepEqual(Object.keys(atlas.frames), ['idle']);
|
|
const k = 62 * g.scaleAt(person.at[1]) * person.size / atlas.height;
|
|
const width = frame.w * k;
|
|
assert.ok(width >= lo && width <= hi, `${id}: ${width}`);
|
|
// Tutto l'ingombro (non soltanto l'ancora) deve restare fuori dall'area calpestabile.
|
|
for (let x = h.box[0]; x <= h.box[0] + h.box[2]; x++)
|
|
for (let y = h.box[1]; y <= h.box[1] + h.box[3]; y++)
|
|
assert.ok(!inside(g.scene.walk, [x, y]), `${id}: invade walk in ${x},${y}`);
|
|
for (const other of g.hotspots().filter(o => !vehicles.includes(o.id))) {
|
|
const [x, y, w, hgt] = h.box, [ox, oy, ow, oh] = other.box;
|
|
assert.ok(x + w <= ox || ox + ow <= x || y + hgt <= oy || oy + oh <= y,
|
|
`${id}: copre ${other.id}`);
|
|
}
|
|
for (const time of [0, 3.9, 4.1, 20]) {
|
|
g.time = time;
|
|
assert.equal(g.personPose(person), 'idle');
|
|
}
|
|
}
|
|
}
|
|
});
|
|
|
|
test('guarda e usa i veicoli: parla solo Andrea e non cambia il progresso', () => {
|
|
for (const [scene, id] of VEHICLES) {
|
|
const g = new Game(story);
|
|
g.go(scene);
|
|
settle(g);
|
|
const flags = { ...g.state.flags }, inventory = [...g.state.inventory];
|
|
{
|
|
const h = g.hotspot(id);
|
|
assert.equal(g.hotspotAt([h.box[0] + h.box[2] / 2, h.box[1] + h.box[3] / 2]).id, id);
|
|
for (const verb of ['look', 'use']) {
|
|
assert.ok(g.act(verb, id));
|
|
const said = settle(g);
|
|
assert.ok(said.length && said.every(s => s.who === 'andrea'));
|
|
assert.deepEqual([g.state.x, g.state.y], h.at);
|
|
assert.deepEqual(g.state.flags, flags);
|
|
assert.deepEqual(g.state.inventory, inventory);
|
|
assert.equal(g.state.scene, scene);
|
|
}
|
|
}
|
|
}
|
|
});
|
|
|
|
test('Via Liguri Magelli: prima la Ghiacciomobile nel muro (senza targa), dal tramonto il muro rifatto con la targa', () => {
|
|
const g = new Game(story);
|
|
g.go('via_liguri_magelli'); settle(g);
|
|
assert.equal(g.backdrop(), 'assets/scenes/via-liguri-magelli-muro.png');
|
|
assert.ok(g.hotspot('ghiacciomobile') && !g.hotspot('targa'));
|
|
assert.ok(!story.scenes.campomigliaio_circolo.hotspots.some(h => h.id === 'ghiacciomobile'), 'al circolino non c\'è più');
|
|
g.state.flags.indizio_regolo = true;
|
|
assert.equal(g.backdrop(), 'assets/scenes/via-liguri-magelli.png');
|
|
assert.ok(g.hotspot('targa') && !g.hotspot('ghiacciomobile'));
|
|
assert.ok(existsSync(new URL('../assets/scenes/via-liguri-magelli-muro.png', import.meta.url)));
|
|
});
|
|
|
|
test('lo zio Mario: davanti alla Ghiacciomobile fino al tramonto, poi nel suo orto', () => {
|
|
const g = new Game(story);
|
|
g.go('via_liguri_magelli'); settle(g);
|
|
assert.ok(g.hotspot('zio_mario'));
|
|
g.go('orti_zio_mario'); settle(g);
|
|
assert.ok(!g.hotspot('zio_mario'));
|
|
g.state.flags.indizio_regolo = true;
|
|
assert.ok(g.hotspot('zio_mario'));
|
|
assert.ok(inside(story.scenes.orti_zio_mario.walk, g.hotspot('zio_mario').at));
|
|
g.act('talk', 'zio_mario'); settle(g);
|
|
g.go('via_liguri_magelli'); settle(g);
|
|
assert.ok(!g.hotspot('zio_mario'));
|
|
});
|