fertig-classic-games/src/games/tickettoride/TicketToRideLayout.js

143 lines
7.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// TicketToRideLayout.js — every screen rect for the Ticket to Ride table.
// Phaser-free so tools/verifyTicketToRide.js can check on-screen + overlaps.
//
// ┌──────────────── map sheet (parchment, score track border) ─┬─ desk pad ──┐
// │ │ buttons │
// │ cities / routes in canvas coords │ opponents │
// │ │ card rack │
// │ │ piles │
// │ │ longest/log │
// ├──────── bottom rail: portrait · info · hand piles · tickets · actions ───┤
export const W = 1920, H = 1080;
// The parchment map. City/route coordinates (TicketToRideBoard) are absolute
// canvas coords that sit inside this sheet.
export const SHEET = { x: 8, y: 6, w: 1456, h: 906 };
export const TRACK = { inset: 10, band: 26 }; // score-track band inside the sheet edge
export const TRACK_SQUARES = 100;
// Right-hand desk pad.
export const PAD = { x: 1474, y: 6, w: 438, h: 906 };
export const TOPBAR = { x: 1486, y: 16, w: 414, h: 42 };
export const MENU_BTN = { x: 1486, y: 16, w: 130, h: 42 };
export const LOG_BTN = { x: 1626, y: 16, w: 130, h: 42 };
export const HELP_BTN = { x: 1766, y: 16, w: 134, h: 42 };
// Opponent plaques: up to 4 in a 2×2 grid.
export const OPP = { x0: 1484, y0: 68, w: 206, h: 116, gapX: 12, gapY: 10 };
export function oppRect(i) {
const col = i % 2, row = Math.floor(i / 2);
return { x: OPP.x0 + col * (OPP.w + OPP.gapX), y: OPP.y0 + row * (OPP.h + OPP.gapY), w: OPP.w, h: OPP.h };
}
export function oppRects(n) { return Array.from({ length: n }, (_, i) => oppRect(i)); }
// Face-up market: a wooden rack holding 5 upright cards.
export const CARD = { w: 74, h: 106 }; // table-size card (sheet frames are 270×390)
export const RACK = { x: 1484, y: 322, w: 418, h: 150 };
export const MARKET_Y = 392;
export function marketPos(i) { return { x: RACK.x + 46 + i * 81.5, y: MARKET_Y }; }
// Draw pile, discard, destination-ticket box.
export const PILES_Y = 560;
export const DECK = { x: 1548, y: PILES_Y };
export const DISCARD = { x: 1664, y: PILES_Y };
export const TICKET_BOX = { x: 1806, y: PILES_Y, w: 124, h: 76 };
export const PILES = { x: 1484, y: 486, w: 418, h: 150 };
export const DRAW_PIPS = { x: 1548, y: 636 };
// Longest-route tracker + dispatch log notepad.
export const LONGEST = { x: 1484, y: 650, w: 418, h: 52 };
export const NOTEPAD = { x: 1484, y: 712, w: 418, h: 190 };
// Bottom rail.
export const RAIL = { x: 0, y: 916, w: 1920, h: 164 };
export const PORTRAIT = { x: 66, y: 990, r: 42 };
export const HUMAN_INFO = { x: 120, y: 928, w: 178, h: 140 };
export const HAND = { x: 306, y: 924, w: 846, h: 150 };
export const HAND_CARD = { w: 80, h: 115 };
export function handPilePos(i) { return { x: HAND.x + 47 + i * 94, y: HAND.y + 82 }; }
export const TICKETS_RAIL = { x: 1164, y: 924, w: 584, h: 150 };
export const TICKET_MINI = { w: 136, h: 66 };
export function ticketMiniPos(i, n) {
const perRow = Math.max(4, Math.ceil(n / 2));
const row = Math.floor(i / perRow), col = i % perRow;
const span = TICKETS_RAIL.w - TICKET_MINI.w - 8;
const step = perRow > 1 ? Math.min(TICKET_MINI.w + 8, span / (perRow - 1)) : 0;
return {
x: TICKETS_RAIL.x + 4 + TICKET_MINI.w / 2 + col * step,
y: TICKETS_RAIL.y + 38 + row * (TICKET_MINI.h + 10),
};
}
export const ACTIONS = { x: 1760, y: 924, w: 150, h: 150 };
export const ROUTES_BTN = { x: 1835, y: 958, w: 146, h: 44 };
export const PASS_BTN = { x: 1835, y: 1032, w: 146, h: 48 };
// Status ribbon pinned to the top of the map (over the sea, clear of labels).
export const STATUS = { x: 736, y: 72 };
// ── score track ────────────────────────────────────────────────────────────────
// Squares 0..99 run clockwise around the sheet's border band, starting at the
// top-left corner. trackPos(n) → { x, y, side } (centre of square n % 100).
const TR = {
x0: SHEET.x + TRACK.inset + TRACK.band / 2,
y0: SHEET.y + TRACK.inset + TRACK.band / 2,
x1: SHEET.x + SHEET.w - TRACK.inset - TRACK.band / 2,
y1: SHEET.y + SHEET.h - TRACK.inset - TRACK.band / 2,
};
const TR_W = TR.x1 - TR.x0, TR_H = TR.y1 - TR.y0;
export const TRACK_PERIM = 2 * (TR_W + TR_H);
export const TRACK_STEP = TRACK_PERIM / TRACK_SQUARES;
export const TRACK_RECT = TR;
export function trackPos(n) {
let d = (((n % TRACK_SQUARES) + TRACK_SQUARES) % TRACK_SQUARES) * TRACK_STEP;
if (d < TR_W) return { x: TR.x0 + d, y: TR.y0, side: 'top' };
d -= TR_W;
if (d < TR_H) return { x: TR.x1, y: TR.y0 + d, side: 'right' };
d -= TR_H;
if (d < TR_W) return { x: TR.x1 - d, y: TR.y1, side: 'bottom' };
d -= TR_W;
return { x: TR.x0, y: TR.y1 - d, side: 'left' };
}
// ── helpers for verify / hit tests ─────────────────────────────────────────────
const centred = (c, w, h, name) => ({ name, x: c.x - w / 2, y: c.y - h / 2, w, h });
export function hudFurniture({ opponents = 3 } = {}) {
return [
{ name: 'menu', ...MENU_BTN },
{ name: 'log', ...LOG_BTN },
{ name: 'help', ...HELP_BTN },
...oppRects(opponents).map((r, i) => ({ name: `opp${i + 1}`, ...r })),
{ name: 'rack', ...RACK },
{ name: 'piles', ...PILES },
{ name: 'longest', ...LONGEST },
{ name: 'notepad', ...NOTEPAD },
{ name: 'humanInfo', ...HUMAN_INFO },
{ name: 'hand', ...HAND },
{ name: 'tickets', ...TICKETS_RAIL },
{ name: 'actions', ...ACTIONS },
];
}
// Things that live inside a furniture rect (each must sit within its parent).
export function furnitureChildren() {
const kids = [];
for (let i = 0; i < 5; i++) kids.push({ parent: 'rack', ...centred(marketPos(i), CARD.w, CARD.h, `market${i}`) });
kids.push({ parent: 'piles', ...centred(DECK, CARD.w, CARD.h, 'deck') });
kids.push({ parent: 'piles', ...centred(DISCARD, CARD.w, CARD.h, 'discard') });
kids.push({ parent: 'piles', ...centred(TICKET_BOX, TICKET_BOX.w, TICKET_BOX.h, 'ticketBox') });
for (let i = 0; i < 9; i++) kids.push({ parent: 'hand', ...centred(handPilePos(i), HAND_CARD.w, HAND_CARD.h, `pile${i}`) });
for (const n of [1, 4, 8, 12]) {
for (let i = 0; i < n; i++) kids.push({ parent: 'tickets', ...centred(ticketMiniPos(i, n), TICKET_MINI.w, TICKET_MINI.h, `ticket${i}/${n}`) });
}
kids.push({ parent: 'actions', ...centred(ROUTES_BTN, ROUTES_BTN.w, ROUTES_BTN.h, 'routesBtn') });
kids.push({ parent: 'actions', ...centred(PASS_BTN, PASS_BTN.w, PASS_BTN.h, 'passBtn') });
return kids;
}
export const onScreen = (r) => r.x >= 0 && r.y >= 0 && r.x + r.w <= W && r.y + r.h <= H;
export const rectsOverlap = (a, b) => a.x < b.x + b.w && b.x < a.x + a.w && a.y < b.y + b.h && b.y < a.y + a.h;
export const inside = (k, p) => k.x >= p.x - 0.5 && k.y >= p.y - 0.5 && k.x + k.w <= p.x + p.w + 0.5 && k.y + k.h <= p.y + p.h + 0.5;