I nomi del «?» non si sovrappongono più: ognuno cerca un posto libero vicino al suo segno
placeLabels prova sopra, sotto, più lontano e di lato, con un po' d'aria fra un nome e l'altro; una lineetta collega il nome al segno quando finisce lontano. Un test controlla tutte le scene, con tutti gli oggetti accesi. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ApqNBvNbNCwXqR2RLo8QJh
This commit is contained in:
@@ -41,3 +41,18 @@ test('uno sfondo che non c\'è proprio si lascia stare dopo pochi tentativi', as
|
||||
delete globalThis.Image;
|
||||
}
|
||||
});
|
||||
|
||||
test('i nomi del «?» non si sovrappongono, in nessuna scena', async () => {
|
||||
const { placeLabels } = await import('../src/engine/render.js');
|
||||
const { story } = await import('../src/story/story.js');
|
||||
const H = 8, W = 6; // Press Start 2P a 6 px: 6 px a lettera
|
||||
for (const [id, sc] of Object.entries(story.scenes)) {
|
||||
const spots = (sc.hotspots ?? []).map(h => ({ x: Math.round(h.box[0] + h.box[2] / 2), y: Math.round(h.box[1] + h.box[3] / 2), w: h.name.length * W, name: h.name }));
|
||||
const boxes = placeLabels(spots).map((p, i) => ({ l: p.x - spots[i].w / 2 - 1, r: p.x + spots[i].w / 2 + 1, t: p.y - H, b: p.y, name: spots[i].name }));
|
||||
for (const [i, a] of boxes.entries()) {
|
||||
assert.ok(a.l >= 0 && a.r <= 640 && a.t >= 0 && a.b <= 360, `${id}: «${a.name}» esce dalla scena`);
|
||||
for (const b of boxes.slice(i + 1))
|
||||
assert.ok(!(a.l < b.r && b.l < a.r && a.t < b.b && b.t < a.b), `${id}: «${a.name}» e «${b.name}» si sovrappongono`);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user