162 lines
8.8 KiB
JavaScript
162 lines
8.8 KiB
JavaScript
// FarkelLayout.js — every screen rect for Gerome's Ski Lodge Farkle table, plus
|
|
// the dice-tray projection. Phaser-free (tools/verifyFarkel.js checks overlaps).
|
|
//
|
|
// ┌ opponent seats (top) ─────────────────────┐ ┌ clipboard score pad ──┐
|
|
// │ felt dice tray │ │ (one row per turn) │
|
|
// │ "set aside" rail (kept dice, by throw) │ ├ chalkboard scoring ───┤
|
|
// └ you · cup · risk gauge · status · buttons ┘ └───────────────────────┘
|
|
|
|
export const W = 1920;
|
|
export const H = 1080;
|
|
|
|
// ── Seats ────────────────────────────────────────────────────────────────────
|
|
export const SEAT = { w: 360, h: 150, y: 12, gap: 15, left: 40, span: 1120 };
|
|
export function seatRect(k, nOpp) {
|
|
const total = nOpp * SEAT.w + (nOpp - 1) * SEAT.gap;
|
|
const x0 = SEAT.left + (SEAT.span - total) / 2;
|
|
return { x: x0 + k * (SEAT.w + SEAT.gap), y: SEAT.y, w: SEAT.w, h: SEAT.h };
|
|
}
|
|
export function seatParts(k, nOpp) {
|
|
const r = seatRect(k, nOpp);
|
|
return {
|
|
rect: r,
|
|
portrait: { x: r.x + 70, y: r.y + 75, r: 52 },
|
|
name: { x: r.x + 140, y: r.y + 32 },
|
|
score: { x: r.x + 140, y: r.y + 70 },
|
|
line: { x: r.x + 140, y: r.y + 108 },
|
|
hat: { x: r.x + 112, y: r.y + 26 },
|
|
bubble: { x: r.x + 138, y: r.y + 86, w: 214, h: 58 },
|
|
};
|
|
}
|
|
|
|
// ── Dice tray ────────────────────────────────────────────────────────────────
|
|
export const TRAY = { x: 60, y: 176, w: 1100, h: 470 };
|
|
export const TRAY_WALL = 26;
|
|
export const TRAY_FELT = { x: TRAY.x + TRAY_WALL, y: TRAY.y + TRAY_WALL, w: TRAY.w - TRAY_WALL * 2, h: TRAY.h - TRAY_WALL * 2 };
|
|
export const TRAY_CAM = { sin: 0.62, cos: 0.785 };
|
|
export const TRAY_WORLD = { w: TRAY_FELT.w, h: TRAY_FELT.h / TRAY_CAM.sin };
|
|
export const DIE_SIZE = 64;
|
|
|
|
// One shared ground plane for the tray, the rail and everything between.
|
|
export function ground(u, v) {
|
|
return { x: TRAY_FELT.x + u, y: TRAY_FELT.y + v * TRAY_CAM.sin, s: 1 };
|
|
}
|
|
export function toWorld(x, y) {
|
|
return { u: x - TRAY_FELT.x, v: (y - TRAY_FELT.y) / TRAY_CAM.sin };
|
|
}
|
|
|
|
// Where n dice rest after a throw (tidied into a row).
|
|
const COL_GAP = 134;
|
|
export function columnU(i, n) { return TRAY_FELT.w / 2 + (i - (n - 1) / 2) * COL_GAP; }
|
|
export const REST_V = TRAY_WORLD.h * 0.56;
|
|
|
|
// ── Set-aside rail ───────────────────────────────────────────────────────────
|
|
export const RAIL = { x: 60, y: 656, w: 1100, h: 150 };
|
|
export const RAIL_TOP_H = 84; // the shelf top; the rest is the front face
|
|
export const RAIL_GROUND_Y = 702; // where a kept die sits
|
|
export const RAIL_V = toWorld(0, RAIL_GROUND_Y).v;
|
|
export const RAIL_LABEL_Y = RAIL.y + RAIL_TOP_H + (RAIL.h - RAIL_TOP_H) / 2;
|
|
export const RAIL_START_X = RAIL.x + 250; // left of this: the engraved "SET ASIDE"
|
|
const RAIL_STEP = 86, RAIL_GROUP_GAP = 40;
|
|
|
|
// Slots for the kept dice of this cycle, grouped by throw. sizes = dice per
|
|
// group. Returns { us: [u per die], labels: [{ x, w }] per group }.
|
|
export function railSlots(sizes) {
|
|
const us = [];
|
|
const labels = [];
|
|
let x = RAIL_START_X + RAIL_STEP / 2;
|
|
sizes.forEach((n, g) => {
|
|
if (g > 0) x += RAIL_GROUP_GAP;
|
|
const x0 = x;
|
|
for (let i = 0; i < n; i++) { us.push(x - TRAY_FELT.x); x += RAIL_STEP; }
|
|
labels.push({ x: (x0 + x - RAIL_STEP) / 2, w: n * RAIL_STEP + RAIL_GROUP_GAP - 12 });
|
|
});
|
|
return { us, labels };
|
|
}
|
|
export function railU(k, groups = 6) {
|
|
const sizes = Array.from({ length: groups }, () => 1);
|
|
return railSlots(sizes).us[k];
|
|
}
|
|
export const RAIL_CHIP = { x: RAIL.x + 128, y: RAIL.y + RAIL_TOP_H / 2 + 2 }; // hot-dice carry chip
|
|
|
|
// ── Bottom rail (you) ────────────────────────────────────────────────────────
|
|
export const HUMAN_PORTRAIT = { x: 92, y: 912, r: 56 };
|
|
export const HUMAN_NAME = { x: 92, y: 994 };
|
|
export const HUMAN_SCORE = { x: 92, y: 1034 };
|
|
export const HUMAN_HAT = { x: 52, y: 860 };
|
|
export const CUP = { x: 262, y: 940, w: 130, h: 160 }; // centre
|
|
export const CUP_MOUTH = { x: CUP.x, y: CUP.y - CUP.h / 2 + 18 };
|
|
export const THERMO = { x: 346, y: 826, w: 70, h: 236 };
|
|
export const TURN_TOTAL = { x: 660, y: 852 };
|
|
export const STATUS = { x: 660, y: 906, w: 430 };
|
|
export const SUBLINE = { x: 660, y: 948 };
|
|
export const TICKER = { x: 660, y: 1044 };
|
|
export const BTN_BIG = { w: 236, h: 54 };
|
|
export const BTN_SMALL = { w: 112, h: 42 };
|
|
export const ROLL_BTN = { x: 1040, y: 852 };
|
|
export const BANK_BTN = { x: 1040, y: 914 };
|
|
export const BEST_BTN = { x: 978, y: 976 };
|
|
export const CLEAR_BTN = { x: 1102, y: 976 };
|
|
export const LOG_BTN = { x: 978, y: 1030 };
|
|
export const MENU_BTN = { x: 1102, y: 1030 };
|
|
export const BANNER = { x: TRAY.x + TRAY.w / 2, y: TRAY.y + TRAY.h * 0.44 };
|
|
export const FINAL_RIBBON = { x: TRAY.x + TRAY.w / 2, y: TRAY.y + 8, w: 640, h: 40 };
|
|
export const PIGGY = { x: TRAY.x + TRAY.w / 2, y: TRAY.y + TRAY.h * 0.5 };
|
|
|
|
// Throw origins in tray-world coordinates.
|
|
export function humanOrigin() {
|
|
return { u: CUP.x - TRAY_FELT.x + 40, v: TRAY_WORLD.h + 70, h: 130 };
|
|
}
|
|
export function seatOrigin(portraitX) {
|
|
return { u: portraitX - TRAY_FELT.x, v: -90, h: 110 };
|
|
}
|
|
|
|
// ── Score pad (clipboard) ────────────────────────────────────────────────────
|
|
export const BOARD = { x: 1186, y: 12, w: 716, h: 640 };
|
|
export const CLIP = { x: BOARD.x + BOARD.w / 2 - 110, y: 0, w: 220, h: 70 };
|
|
export const PAPER = { x: BOARD.x + 22, y: 56, w: BOARD.w - 44, h: 580 };
|
|
export const PAD_TITLE = { x: PAPER.x + 30, y: PAPER.y + 50 };
|
|
export const PAD_HEAD = { y: PAPER.y + 98, h: 52 };
|
|
export const PAD_MARGIN = 54; // turn numbers left of the red line
|
|
export const PAD_ROW_H = 34;
|
|
export const PAD_ROWS = Math.floor((PAPER.y + PAPER.h - 12 - (PAD_HEAD.y + PAD_HEAD.h)) / PAD_ROW_H);
|
|
export const PAD_GRID = { x: PAPER.x + 12, y: PAD_HEAD.y, w: PAPER.w - 24 };
|
|
export function padColW(n) { return (PAD_GRID.w - PAD_MARGIN) / n; }
|
|
export function padColX(p, n) { return PAD_GRID.x + PAD_MARGIN + p * padColW(n); }
|
|
export function padRowY(r) { return PAD_HEAD.y + PAD_HEAD.h + r * PAD_ROW_H; } // top of visible row r
|
|
|
|
// ── Scoring chalkboard ───────────────────────────────────────────────────────
|
|
export const CARD = { x: 1186, y: 666, w: 716, h: 402 };
|
|
export const CARD_INNER = { x: CARD.x + 26, y: CARD.y + 26, w: CARD.w - 52, h: CARD.h - 52 };
|
|
export const CARD_ROW_H = 38;
|
|
export const CARD_COLS = [
|
|
{ x: CARD_INNER.x + 18, w: CARD_INNER.w / 2 - 30 },
|
|
{ x: CARD_INNER.x + CARD_INNER.w / 2 + 12, w: CARD_INNER.w / 2 - 30 },
|
|
];
|
|
export const CARD_ROWS_TOP = CARD_INNER.y + 62;
|
|
|
|
// ── Checks ───────────────────────────────────────────────────────────────────
|
|
export function hudFurniture(nOpp) {
|
|
const f = [];
|
|
for (let k = 0; k < nOpp; k++) f.push({ name: `seat${k}`, ...seatRect(k, nOpp) });
|
|
f.push({ name: 'tray', ...TRAY });
|
|
f.push({ name: 'rail', ...RAIL });
|
|
const c = (name, o, w, h) => ({ name, x: o.x - w / 2, y: o.y - h / 2, w, h });
|
|
f.push(c('portrait', HUMAN_PORTRAIT, HUMAN_PORTRAIT.r * 2, HUMAN_PORTRAIT.r * 2));
|
|
f.push({ name: 'humanText', x: 20, y: HUMAN_NAME.y - 16, w: 150, h: HUMAN_SCORE.y + 18 - (HUMAN_NAME.y - 16) });
|
|
f.push(c('cup', CUP, CUP.w, CUP.h));
|
|
f.push({ name: 'thermo', x: THERMO.x, y: THERMO.y, w: THERMO.w, h: THERMO.h });
|
|
f.push({ name: 'status', x: STATUS.x - STATUS.w / 2, y: TURN_TOTAL.y - 26, w: STATUS.w, h: TICKER.y + 30 - (TURN_TOTAL.y - 26) });
|
|
f.push(c('roll', ROLL_BTN, BTN_BIG.w, BTN_BIG.h));
|
|
f.push(c('bank', BANK_BTN, BTN_BIG.w, BTN_BIG.h));
|
|
f.push(c('best', BEST_BTN, BTN_SMALL.w, BTN_SMALL.h));
|
|
f.push(c('clear', CLEAR_BTN, BTN_SMALL.w, BTN_SMALL.h));
|
|
f.push(c('log', LOG_BTN, BTN_SMALL.w, BTN_SMALL.h));
|
|
f.push(c('menu', MENU_BTN, BTN_SMALL.w, BTN_SMALL.h));
|
|
f.push({ name: 'board', ...BOARD });
|
|
f.push({ name: 'card', ...CARD });
|
|
return f;
|
|
}
|
|
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 onScreen = (r) => r.x >= 0 && r.y >= 0 && r.x + r.w <= W && r.y + r.h <= H;
|