Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GiECdCPptNRwbVzjzHbohi
65 lines
2.9 KiB
JavaScript
65 lines
2.9 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';
|
|
|
|
// La Ghiacciomobile al circolino è uno sprite; il Betino in cima alla salita di Via Liguri Magelli è dipinto nel quadro.
|
|
const SPRITES = [['campomigliaio_circolo', 'ghiacciomobile', [150, 170]]];
|
|
const VEHICLES = [...SPRITES, ['via_liguri_magelli', 'betino']];
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
});
|