150 lines
11 KiB
JavaScript
150 lines
11 KiB
JavaScript
// The Drowning Isle: the expedition report, shown when the game ends.
|
|
//
|
|
// ┌ headline + one-line story ──────────────────────────────────────────┐
|
|
// │ tide chart by day │ expedition timeline (key moments) │
|
|
// │ (gauge line, flooded and │ │
|
|
// │ sunk tiles as bars) │ │
|
|
// ├ crew cards: figurine, what each did, the expedition's MVP ──────────┤
|
|
// │ relics · lifetime record · New Expedition / Leave │
|
|
// └─────────────────────────────────────────────────────────────────────┘
|
|
|
|
import { Button } from '../../ui/Button.js';
|
|
import { TREASURE_KEYS, TREASURES, ROLES, MAX_WATER, LAYOUTS, cardFrame } from './IslandData.js';
|
|
import { W, H, DEPTH, DISPLAY_FONT, BODY_FONT, TYPE_FONT, INK } from './IslandLayout.js';
|
|
import { bakeLeather } from './IslandArt.js';
|
|
|
|
const BRASS = { bg: 0x5a3f1a, bgHover: 0xd8b25a, textColor: '#f2e6cc', textHoverColor: '#2b1d08' };
|
|
|
|
// What each crew member did, from the game log.
|
|
export function crewStats(gs) {
|
|
const st = Object.fromEntries(gs.players.map((p) => [p.seat, { shored: 0, gave: 0, relics: 0, moves: 0, specials: 0, guided: 0 }]));
|
|
for (const e of gs.log) {
|
|
const s = st[e.seat]; if (!s) continue;
|
|
if (e.kind === 'shoreUp') s.shored += e.tiles.length;
|
|
else if (e.kind === 'give') s.gave++;
|
|
else if (e.kind === 'capture') s.relics++;
|
|
else if (e.kind === 'move' || e.kind === 'fly') s.moves++;
|
|
else if (e.kind === 'navMove') s.guided++;
|
|
else if (e.kind === 'sandbags' || e.kind === 'helicopter') { s.specials++; if (e.kind === 'sandbags') s.shored++; }
|
|
}
|
|
for (const s of Object.values(st)) s.score = s.relics * 6 + s.shored * 1.5 + s.gave * 2 + s.specials * 2 + s.guided;
|
|
return st;
|
|
}
|
|
|
|
export function showEndScreen(scene, { gs, names, history, moments, result, onAgain, onLeave }) {
|
|
const won = gs.phase === 'won';
|
|
const pw = 1500, ph = 900, cx = W / 2, cy = H / 2;
|
|
const left = cx - pw / 2, top = cy - ph / 2;
|
|
const root = scene.add.container(0, 0).setDepth(DEPTH.banner).setAlpha(0);
|
|
const add = (o) => { root.add(o); return o; };
|
|
add(scene.add.rectangle(0, 0, W, H, 0x020a10, 0.7).setOrigin(0).setInteractive());
|
|
add(scene.add.image(cx, cy, bakeLeather(scene, pw, ph)));
|
|
add(scene.add.text(cx, top + 58, won ? 'The Expedition Is Saved' : 'The Isle Has Drowned', {
|
|
fontFamily: DISPLAY_FONT, fontSize: '52px', color: won ? INK.brassHex : '#e07a5f',
|
|
}).setOrigin(0.5).setShadow(0, 3, '#000', 6));
|
|
const days = gs.round ?? 1;
|
|
add(scene.add.text(cx, top + 110, won
|
|
? `All four relics recovered and the whole crew lifted off on day ${days}.`
|
|
: `${gs.lossReason ?? 'The island is lost.'} Day ${days}.`, {
|
|
fontFamily: BODY_FONT, fontStyle: 'italic', fontSize: '21px', color: INK.cream, align: 'center', wordWrap: { width: pw - 160 },
|
|
}).setOrigin(0.5));
|
|
|
|
// ── tide chart ──────────────────────────────────────────────────────────────
|
|
const chart = { x: left + 70, y: top + 170, w: 640, h: 300 };
|
|
add(scene.add.text(chart.x, chart.y - 4, 'TIDE CHART', { fontFamily: TYPE_FONT, fontSize: '15px', fontStyle: 'bold', color: '#cdb994' }));
|
|
const g = add(scene.add.graphics());
|
|
const px = chart.x + 36, py = chart.y + 30, pw2 = chart.w - 50, ph2 = chart.h - 70;
|
|
g.fillStyle(0xe9dcc0, 0.95); g.fillRoundedRect(chart.x, chart.y + 22, chart.w, chart.h - 22, 8);
|
|
g.lineStyle(1, 0x8a7658, 0.35);
|
|
for (let l = 0; l <= MAX_WATER; l += 2) { const y = py + ph2 - (l / MAX_WATER) * ph2; g.lineBetween(px, y, px + pw2, y); }
|
|
for (let l = 2; l <= MAX_WATER; l += 2) add(scene.add.text(px - 8, py + ph2 - (l / MAX_WATER) * ph2, String(l), { fontFamily: TYPE_FONT, fontSize: '11px', color: INK.inkSoft }).setOrigin(1, 0.5));
|
|
const hist = history.length ? history : [{ day: 1, level: gs.waterLevel, flooded: 0, sunk: 0 }];
|
|
const n = hist.length, step = pw2 / Math.max(1, n);
|
|
hist.forEach((h, i) => {
|
|
const x = px + i * step + step * 0.15, bw = Math.max(2, step * 0.7);
|
|
const sunkH = (h.sunk / 24) * ph2, floodH = (h.flooded / 24) * ph2;
|
|
g.fillStyle(0x2a3a44, 0.7); g.fillRect(x, py + ph2 - sunkH, bw, sunkH);
|
|
g.fillStyle(0x3d8cc4, 0.55); g.fillRect(x, py + ph2 - sunkH - floodH, bw, floodH);
|
|
});
|
|
g.lineStyle(3, 0x8e2a1e, 1); g.beginPath();
|
|
hist.forEach((h, i) => { const x = px + i * step + step / 2, y = py + ph2 - (h.level / MAX_WATER) * ph2; i ? g.lineTo(x, y) : g.moveTo(x, y); });
|
|
g.strokePath();
|
|
hist.forEach((h, i) => { const x = px + i * step + step / 2, y = py + ph2 - (h.level / MAX_WATER) * ph2; g.fillStyle(0x8e2a1e, 1); g.fillCircle(x, y, 3); });
|
|
const every = Math.max(1, Math.ceil(n / 12));
|
|
hist.forEach((h, i) => { if (i % every === 0) add(scene.add.text(px + i * step + step / 2, py + ph2 + 6, String(h.day), { fontFamily: TYPE_FONT, fontSize: '11px', color: INK.inkSoft }).setOrigin(0.5, 0)); });
|
|
// legend: swatch + label, laid out left to right
|
|
let lx = chart.x + 14;
|
|
const ly = chart.y + chart.h - 22;
|
|
for (const [kind, col, text] of [['line', 0x8e2a1e, 'tide gauge'], ['bar', 0x3d8cc4, 'flooded tiles'], ['bar', 0x2a3a44, 'sunk tiles'], [null, 0, '(by day)']]) {
|
|
if (kind === 'line') { g.lineStyle(3, col, 1); g.lineBetween(lx, ly + 7, lx + 14, ly + 7); lx += 20; }
|
|
else if (kind === 'bar') { g.fillStyle(col, 0.85); g.fillRect(lx, ly + 1, 9, 12); lx += 15; }
|
|
const t = add(scene.add.text(lx, ly, text, { fontFamily: TYPE_FONT, fontSize: '11px', color: INK.inkSoft }));
|
|
lx += t.width + 18;
|
|
}
|
|
|
|
// ── timeline ────────────────────────────────────────────────────────────────
|
|
const tl = { x: left + 760, y: top + 170, w: 670 };
|
|
add(scene.add.text(tl.x, tl.y - 4, 'EXPEDITION LOG', { fontFamily: TYPE_FONT, fontSize: '15px', fontStyle: 'bold', color: '#cdb994' }));
|
|
const keyMoments = moments.slice(-11);
|
|
let ty = tl.y + 28;
|
|
if (!keyMoments.length) add(scene.add.text(tl.x, ty, 'A quiet expedition. Too quiet.', { fontFamily: BODY_FONT, fontStyle: 'italic', fontSize: '17px', color: INK.cream }));
|
|
for (const m of keyMoments) {
|
|
const icon = { capture: '★', sink: '▼', rise: '≈', heli: '✈', bags: '▣', escape: '✈', loss: '✖' }[m.kind] ?? '•';
|
|
const col = { capture: '#f0d58c', sink: '#e07a5f', rise: '#8fd0f0', loss: '#e07a5f' }[m.kind] ?? INK.cream;
|
|
add(scene.add.text(tl.x, ty, `DAY ${String(m.day).padStart(2, ' ')}`, { fontFamily: TYPE_FONT, fontSize: '13px', fontStyle: 'bold', color: '#cdb994' }));
|
|
add(scene.add.text(tl.x + 70, ty - 2, icon, { fontFamily: BODY_FONT, fontSize: '16px', color: col }));
|
|
const t = add(scene.add.text(tl.x + 96, ty - 1, m.text, { fontFamily: BODY_FONT, fontSize: '16px', color: INK.cream, wordWrap: { width: tl.w - 100 } }));
|
|
ty += Math.max(26, t.height + 6);
|
|
if (ty > top + 470) break;
|
|
}
|
|
|
|
// ── crew cards ──────────────────────────────────────────────────────────────
|
|
const stats = crewStats(gs);
|
|
const mvp = Object.entries(stats).sort((a, b) => b[1].score - a[1].score)[0]?.[0];
|
|
const cw = 330, cardY = top + 500;
|
|
const n2 = gs.players.length, cx0 = cx - (n2 * cw + (n2 - 1) * 20) / 2;
|
|
gs.players.forEach((p, i) => {
|
|
const x = cx0 + i * (cw + 20), s = stats[p.seat];
|
|
const cg = add(scene.add.graphics());
|
|
cg.fillStyle(0xe9dcc0, 0.95); cg.fillRoundedRect(x, cardY, cw, 170, 10);
|
|
cg.lineStyle(3, String(p.seat) === mvp ? 0xd8b25a : 0x5a4020, 1); cg.strokeRoundedRect(x, cardY, cw, 170, 10);
|
|
add(scene.add.image(x + 46, cardY + 120, `di-pawn-${p.role}`).setOrigin(0.5, 1).setDisplaySize(52, 76));
|
|
add(scene.add.text(x + 90, cardY + 16, names[p.seat] ?? `Seat ${p.seat}`, { fontFamily: BODY_FONT, fontStyle: 'bold', fontSize: '20px', color: INK.ink }));
|
|
add(scene.add.text(x + 90, cardY + 44, ROLES[p.role].name, { fontFamily: TYPE_FONT, fontSize: '13px', fontStyle: 'bold', color: INK.inkSoft }));
|
|
const lines = [
|
|
`${s.relics} relic${s.relics === 1 ? '' : 's'} recovered`,
|
|
`${s.shored} tile${s.shored === 1 ? '' : 's'} shored up`,
|
|
`${s.gave} card${s.gave === 1 ? '' : 's'} given${s.specials ? ` · ${s.specials} special${s.specials === 1 ? '' : 's'}` : ''}`,
|
|
];
|
|
add(scene.add.text(x + 90, cardY + 70, lines.join('\n'), { fontFamily: BODY_FONT, fontSize: '15px', color: INK.inkSoft, lineSpacing: 4 }));
|
|
if (String(p.seat) === mvp) {
|
|
add(scene.add.text(x + cw - 12, cardY + 12, 'MVP', { fontFamily: TYPE_FONT, fontSize: '14px', fontStyle: 'bold', color: '#8e2a1e', backgroundColor: 'rgba(216,178,90,0.6)', padding: { x: 6, y: 2 } }).setOrigin(1, 0).setAngle(6));
|
|
}
|
|
});
|
|
|
|
// ── relics, record, buttons ─────────────────────────────────────────────────
|
|
const ry = top + 752;
|
|
TREASURE_KEYS.forEach((k, i) => {
|
|
const got = gs.players.some((p) => p.captured[k]);
|
|
const x = left + 110 + i * 70;
|
|
if (scene.textures.exists('forbiddenisland-cards')) {
|
|
add(scene.add.image(x, ry, 'forbiddenisland-cards', cardFrame(`treasure:${k}`)).setDisplaySize(54, 71).setAlpha(got ? 1 : 0.3).setTint(got ? 0xffffff : 0x777777));
|
|
} else add(scene.add.circle(x, ry, 20, TREASURES[k].color, got ? 1 : 0.3));
|
|
});
|
|
const r = result?.record;
|
|
if (r) {
|
|
const flags = result.flags ?? {};
|
|
const extra = [flags.bestDays ? 'NEW FASTEST ESCAPE!' : '', flags.bestStreak ? `NEW BEST STREAK (${r.bestStreak})!` : ''].filter(Boolean).join(' ');
|
|
add(scene.add.text(left + 420, ry - 22, `${LAYOUTS[gs.layout]?.name ?? ''}${result.daily ? ` · Daily ${result.daily}` : ''}`, { fontFamily: TYPE_FONT, fontSize: '14px', fontStyle: 'bold', color: '#cdb994' }));
|
|
add(scene.add.text(left + 420, ry + 4, `Expeditions ${r.played} · escaped ${r.won} (${Math.round((r.won / r.played) * 100)}%) · best ${r.bestDays ?? 'n/a'}${r.bestDays ? ' days' : ''} · streak ${r.streak}`, {
|
|
fontFamily: TYPE_FONT, fontSize: '14px', color: INK.cream,
|
|
}));
|
|
if (extra) add(scene.add.text(left + 420, ry + 28, extra, { fontFamily: TYPE_FONT, fontSize: '14px', fontStyle: 'bold', color: '#f0d58c' }));
|
|
}
|
|
const again = add(new Button(scene, cx + 380, top + ph - 70, 'New Expedition', onAgain, { width: 250, height: 56, fontSize: 21, ...BRASS }));
|
|
const leave = add(new Button(scene, cx + 610, top + ph - 70, 'Leave', onLeave, { width: 170, height: 56, fontSize: 21, ...BRASS }));
|
|
again.setDepth(0); leave.setDepth(0);
|
|
scene.tweens.add({ targets: root, alpha: 1, duration: 600 });
|
|
return root;
|
|
}
|