Refactor casino tables to shared perspective geometry and art kit
- Extract table layout into Phaser-free *Table.js modules so headless verify scripts can test projection, hit-testing, payouts, and scoreboard roads - Add shared casino art pipeline (CasinoArt/CasinoCards/CasinoChips/CasinoDock) that bakes felt, rail, cards, chips, and HUD dock from one perspective model - Replace per-game hand-drawn tables, betting UI, and chip rendering in Baccarat, Blackjack, and Pai Gow with the shared kit plus game-specific markings - Add keyboard shortcuts, rebet controls, and a Baccarat bead plate/big road scoreboard - Extend verifyBaccarat/verifyBlackjack/verifyPaiGowPoker with layout, overlap, and source-lint checks
This commit is contained in:
parent
b2df177bf3
commit
a103c9ed74
|
|
@ -0,0 +1,83 @@
|
|||
// Baccarat table art: burgundy felt, three curved betting boxes per seat
|
||||
// (PLAYER / BANKER / TIE), and the dealer's PLAYER and BANKER card boxes.
|
||||
|
||||
import { prepareCasinoArt, bakeCasinoTable, poly, rr, drawArcText } from '../../ui/casino/CasinoArt.js';
|
||||
import {
|
||||
VIEW, SEAT_ANGLES, BANDS, BET_TYPES, BET_META, boxOutline, handBoxRect, handCardPose,
|
||||
CARD_W, CARD_H, FELT_TEXT, TRAY, SHOE, DISCARD, PLACARD,
|
||||
} from './BaccaratTable.js';
|
||||
|
||||
function hexToRgba(hex, a) {
|
||||
const n = parseInt(hex.slice(1), 16);
|
||||
return `rgba(${(n >> 16) & 255},${(n >> 8) & 255},${n & 255},${a})`;
|
||||
}
|
||||
|
||||
function drawMarkings(ctx) {
|
||||
SEAT_ANGLES.forEach((theta, seat) => {
|
||||
for (const type of BET_TYPES) {
|
||||
const meta = BET_META[type];
|
||||
poly(ctx, boxOutline(seat, type));
|
||||
ctx.fillStyle = hexToRgba(meta.felt, 0.09);
|
||||
ctx.fill();
|
||||
ctx.lineWidth = 2.5;
|
||||
ctx.strokeStyle = hexToRgba(meta.felt, 0.85);
|
||||
ctx.stroke();
|
||||
poly(ctx, boxOutline(seat, type, 0.012));
|
||||
ctx.lineWidth = 1;
|
||||
ctx.strokeStyle = 'rgba(242,234,216,0.22)';
|
||||
ctx.stroke();
|
||||
const { r0, r1 } = BANDS[type];
|
||||
drawArcText(ctx, {
|
||||
text: meta.label, r: (r0 + r1) / 2, size: type === 'tie' ? 15 : 16, color: meta.felt,
|
||||
alpha: 0.9, spacing: 1.08, bold: true, centerDeg: theta,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
for (const side of ['player', 'banker']) {
|
||||
const meta = BET_META[side];
|
||||
const b = handBoxRect(side);
|
||||
rr(ctx, b.x - b.w / 2, b.y - b.h / 2, b.w, b.h, 12 * b.s);
|
||||
ctx.fillStyle = hexToRgba(meta.felt, 0.08);
|
||||
ctx.fill();
|
||||
ctx.lineWidth = 2.5;
|
||||
ctx.strokeStyle = hexToRgba(meta.felt, 0.8);
|
||||
ctx.stroke();
|
||||
ctx.save();
|
||||
ctx.translate(b.x, b.y);
|
||||
ctx.scale(b.s, b.s * VIEW.squash);
|
||||
ctx.font = 'bold 30px "Julius Sans One", sans-serif';
|
||||
ctx.textAlign = 'center';
|
||||
ctx.textBaseline = 'middle';
|
||||
ctx.fillStyle = hexToRgba(meta.felt, 0.55);
|
||||
ctx.fillText(meta.label, 0, 0);
|
||||
ctx.restore();
|
||||
|
||||
// third-card spot (sideways)
|
||||
const t = handCardPose(side, 2);
|
||||
ctx.save();
|
||||
ctx.translate(t.x, t.y);
|
||||
ctx.rotate(t.rot);
|
||||
ctx.scale(t.s, t.s * VIEW.squash);
|
||||
ctx.setLineDash([8, 6]);
|
||||
rr(ctx, -CARD_W / 2 - 6, -CARD_H / 2 - 6, CARD_W + 12, CARD_H + 12, 10);
|
||||
ctx.lineWidth = 2 / t.s;
|
||||
ctx.strokeStyle = hexToRgba(meta.felt, 0.6);
|
||||
ctx.stroke();
|
||||
ctx.setLineDash([]);
|
||||
ctx.restore();
|
||||
}
|
||||
}
|
||||
|
||||
export async function prepareBaccaratArt(scene) {
|
||||
await prepareCasinoArt(scene);
|
||||
bakeCasinoTable(scene, 'bac-table', {
|
||||
felt: '#5c1020',
|
||||
markings: drawMarkings,
|
||||
text: FELT_TEXT,
|
||||
tray: TRAY,
|
||||
shoe: SHOE,
|
||||
discard: DISCARD,
|
||||
placard: PLACARD,
|
||||
});
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,68 @@
|
|||
// Baccarat scoreboard "roads" — pure, so tools/verifyBaccarat.js can test them.
|
||||
//
|
||||
// history: array of coup outcomes, oldest first: 'player' | 'banker' | 'tie'.
|
||||
//
|
||||
// Bead plate: every coup in order, filling columns top-to-bottom (6 rows),
|
||||
// showing only the most recent whole columns that fit.
|
||||
// Big road: one column per streak of the same winner (P or B). Ties don't
|
||||
// take a cell — they mark the latest cell (a green slash). A streak
|
||||
// longer than the column turns right along its last row ("dragon tail").
|
||||
// Each new streak starts in the column after the previous streak began.
|
||||
|
||||
export function counts(history) {
|
||||
const c = { player: 0, banker: 0, tie: 0 };
|
||||
for (const h of history) c[h]++;
|
||||
return c;
|
||||
}
|
||||
|
||||
export function beadPlate(history, rows = 6, cols = 10) {
|
||||
const usedCols = Math.ceil(history.length / rows);
|
||||
const dropCols = Math.max(0, usedCols - cols);
|
||||
const start = dropCols * rows;
|
||||
return history.slice(start).map((outcome, k) => ({ col: Math.floor(k / rows), row: k % rows, outcome }));
|
||||
}
|
||||
|
||||
export function bigRoad(history, rows = 6) {
|
||||
const cells = [];
|
||||
const taken = new Set();
|
||||
const key = (c, r) => `${c},${r}`;
|
||||
let last = null; // last placed cell
|
||||
let streakCol = -1; // column where the current streak started
|
||||
let pendingTies = 0; // ties before the first P/B
|
||||
for (const outcome of history) {
|
||||
if (outcome === 'tie') {
|
||||
if (last) last.ties++;
|
||||
else pendingTies++;
|
||||
continue;
|
||||
}
|
||||
let col, row;
|
||||
if (last && last.outcome === outcome) {
|
||||
// continue the streak: down if free, otherwise turn right
|
||||
if (!last.tail && last.row + 1 < rows && !taken.has(key(last.col, last.row + 1))) {
|
||||
col = last.col; row = last.row + 1;
|
||||
} else {
|
||||
col = last.col + 1; row = last.row;
|
||||
while (taken.has(key(col, row))) col++;
|
||||
}
|
||||
} else {
|
||||
streakCol += 1;
|
||||
col = streakCol; row = 0;
|
||||
while (taken.has(key(col, row))) { streakCol++; col = streakCol; }
|
||||
}
|
||||
const cell = { col, row, outcome, ties: pendingTies, tail: last && last.outcome === outcome && col !== last.col };
|
||||
if (last && last.outcome === outcome && last.tail) cell.tail = true;
|
||||
pendingTies = 0;
|
||||
taken.add(key(col, row));
|
||||
cells.push(cell);
|
||||
last = cell;
|
||||
}
|
||||
return cells;
|
||||
}
|
||||
|
||||
// The big-road cells that fit in a window of `cols` columns (most recent).
|
||||
export function bigRoadWindow(history, rows = 6, cols = 18) {
|
||||
const cells = bigRoad(history, rows);
|
||||
const maxCol = cells.reduce((m, c) => Math.max(m, c.col), -1);
|
||||
const offset = Math.max(0, maxCol + 1 - cols);
|
||||
return cells.filter(c => c.col >= offset).map(c => ({ ...c, col: c.col - offset }));
|
||||
}
|
||||
|
|
@ -0,0 +1,116 @@
|
|||
// Baccarat table layout — Phaser-free so tools/verifyBaccarat.js can test it.
|
||||
//
|
||||
// Shared perspective + rail geometry come from src/ui/casino/CasinoGeometry.js
|
||||
// (re-exported). Every seat has three curved betting boxes in concentric bands —
|
||||
// PLAYER nearest the rail, then BANKER, then TIE — and the dealer row holds the
|
||||
// PLAYER and BANKER card boxes.
|
||||
|
||||
import { polar, project, toPolar, feltSector } from '../../ui/casino/CasinoGeometry.js';
|
||||
import { BET } from './BaccaratLogic.js';
|
||||
|
||||
export * from '../../ui/casino/CasinoGeometry.js';
|
||||
|
||||
export const CARD_W = 96;
|
||||
export const CARD_H = 134;
|
||||
|
||||
// Same seating as Blackjack: 0 = human bottom-centre, then outward-alternating.
|
||||
export const SEAT_ANGLES = [0, 25, -25, 49, -49, 71, -71];
|
||||
export const DISPLAY_ORDER = [5, 3, 1, 0, 2, 4, 6];
|
||||
|
||||
// Concentric betting bands (table-space radii) and each box's half-width in degrees.
|
||||
export const BANDS = {
|
||||
[BET.PLAYER]: { r0: 0.846, r1: 0.952 },
|
||||
[BET.BANKER]: { r0: 0.732, r1: 0.836 },
|
||||
[BET.TIE]: { r0: 0.632, r1: 0.722 },
|
||||
};
|
||||
export const BOX_HALF_DEG = 10;
|
||||
export const BET_TYPES = [BET.PLAYER, BET.BANKER, BET.TIE];
|
||||
|
||||
export const BET_META = {
|
||||
[BET.PLAYER]: { label: 'PLAYER', short: 'P', color: 0x3d7fd6, hex: '#4a90d9', felt: '#5d9be6' },
|
||||
[BET.BANKER]: { label: 'BANKER', short: 'B', color: 0xd64545, hex: '#e05c5c', felt: '#ee6a6a' },
|
||||
[BET.TIE]: { label: 'TIE 8:1', short: 'T', color: 0x3aa35c, hex: '#5cb85c', felt: '#6cd08a' },
|
||||
};
|
||||
|
||||
const PORTRAITS = [
|
||||
{ x: 160, y: 1013, r: 50 }, // 0 human — in the dock
|
||||
{ x: 1556, y: 812, r: 56 }, // 1 right-bottom
|
||||
{ x: 364, y: 812, r: 56 }, // 2 left-bottom
|
||||
{ x: 1786, y: 640, r: 56 }, // 3 right-mid
|
||||
{ x: 134, y: 640, r: 56 }, // 4 left-mid
|
||||
{ x: 1810, y: 330, r: 56 }, // 5 right-top
|
||||
{ x: 110, y: 330, r: 56 }, // 6 left-top
|
||||
];
|
||||
|
||||
export function seatPortrait(seat) {
|
||||
return { ...PORTRAITS[seat] };
|
||||
}
|
||||
|
||||
// Centre of a seat's betting box (where its chips stack).
|
||||
export function boxCenter(seat, type) {
|
||||
const { r0, r1 } = BANDS[type];
|
||||
return polar((r0 + r1) / 2, SEAT_ANGLES[seat]);
|
||||
}
|
||||
|
||||
// Projected outline of a seat's betting box.
|
||||
export function boxOutline(seat, type, inset = 0) {
|
||||
const { r0, r1 } = BANDS[type];
|
||||
const th = SEAT_ANGLES[seat];
|
||||
return feltSector(r0 + inset, r1 - inset, th - BOX_HALF_DEG + inset * 40, th + BOX_HALF_DEG - inset * 40);
|
||||
}
|
||||
|
||||
// Which betting box (if any) is under a screen point? → { seat, type } | null
|
||||
export function hitBox(x, y) {
|
||||
const { r, theta, v } = toPolar(x, y);
|
||||
if (v < 0) return null;
|
||||
const type = BET_TYPES.find(t => r >= BANDS[t].r0 && r <= BANDS[t].r1);
|
||||
if (!type) return null;
|
||||
const seat = SEAT_ANGLES.findIndex(a => Math.abs(theta - a) <= BOX_HALF_DEG);
|
||||
return seat === -1 ? null : { seat, type };
|
||||
}
|
||||
|
||||
// ── Dealer row: PLAYER (left) and BANKER (right) card boxes ──────────────────
|
||||
export const HAND_V = 0.245;
|
||||
export const HAND_U = 0.21;
|
||||
export const HAND_BOOST = 1.12;
|
||||
export const CARD_GAP = 46; // px @ s between the first two cards
|
||||
|
||||
export function handCenter(side) {
|
||||
const p = project(side === 'player' ? -HAND_U : HAND_U, HAND_V);
|
||||
return { ...p, s: p.s * HAND_BOOST };
|
||||
}
|
||||
|
||||
// Pose of card i (0, 1 = the first two; 2 = the sideways third card).
|
||||
export function handCardPose(side, i) {
|
||||
const c = handCenter(side);
|
||||
const out = side === 'player' ? -1 : 1; // third card sits on the outer side
|
||||
if (i < 2) return { x: c.x + (i - 0.5) * CARD_GAP * c.s, y: c.y, rot: 0, s: c.s };
|
||||
return { x: c.x + out * (CARD_GAP / 2 + CARD_W * 0.5 + CARD_H * 0.45) * c.s, y: c.y + 4, rot: Math.PI / 2, s: c.s };
|
||||
}
|
||||
|
||||
// The printed card box around both first cards (+ the third-card spot).
|
||||
export function handBoxRect(side) {
|
||||
const c = handCenter(side);
|
||||
return { x: c.x, y: c.y, w: (CARD_W + CARD_GAP + 26) * c.s, h: (CARD_H + 18) * c.s * 0.9, s: c.s };
|
||||
}
|
||||
|
||||
export const TOTAL_BADGE_DY = 92; // px @ s below the hand centre (just under the card box)
|
||||
|
||||
// ── Furniture ────────────────────────────────────────────────────────────────
|
||||
export const SHOE = { u: 0.47, v: 0.085 };
|
||||
export const DISCARD = { u: -0.47, v: 0.085 };
|
||||
export const PLACARD = { u: -0.335, v: 0.035, lines: ['TABLE LIMITS', '$5 – $500'] };
|
||||
|
||||
export const FELT_TEXT = [
|
||||
{ text: 'BANKER PAYS 19 TO 20 · TIE PAYS 8 TO 1', r: 0.565, size: 18, color: '#f2ead8', alpha: 0.75, spacing: 0.96 },
|
||||
];
|
||||
|
||||
// The tally readout panel (Equation Ribbon) sits between the hands and the seats.
|
||||
export const READOUT = { x: 960, y: 430, w: 300, h: 110 };
|
||||
|
||||
// ── Scoreboard (standing LED board above the dealer edge, top-right) ─────────
|
||||
export const BOARD = { x: 1342, y: 10, cell: 18, rows: 6, beadCols: 10, roadCols: 18, pad: 12, header: 28 };
|
||||
export function boardSize() {
|
||||
const { cell, rows, beadCols, roadCols, pad, header } = BOARD;
|
||||
return { w: pad * 3 + (beadCols + roadCols) * cell, h: header + rows * cell + pad * 2 };
|
||||
}
|
||||
|
|
@ -0,0 +1,65 @@
|
|||
// Blackjack table art. The shared casino kit (src/ui/casino/CasinoArt.js) bakes
|
||||
// the rail, felt, lighting, cards, chips and dock; this file only supplies
|
||||
// Blackjack's felt colour, markings, lettering and furniture.
|
||||
|
||||
import { feltCircle } from '../../ui/casino/CasinoGeometry.js';
|
||||
import { prepareCasinoArt, bakeCasinoTable, poly, rr, CARD_W, CARD_H } from '../../ui/casino/CasinoArt.js';
|
||||
import {
|
||||
polar, SEAT_ANGLES, BET_R, BET_SPOT_R, cardPose, VIEW,
|
||||
FELT_TEXT, INSURANCE_LINES, TRAY, SHOE, DISCARD, PLACARD,
|
||||
} from './BlackjackTable.js';
|
||||
|
||||
export { CARD_W, CARD_H, ensureCardBack } from '../../ui/casino/CasinoArt.js';
|
||||
|
||||
function drawMarkings(ctx) {
|
||||
// Card spots + betting circles for all seven seats
|
||||
SEAT_ANGLES.forEach((theta, seat) => {
|
||||
const t = (theta * Math.PI) / 180;
|
||||
const u = BET_R * Math.sin(t), v = BET_R * Math.cos(t);
|
||||
poly(ctx, feltCircle(u, v, BET_SPOT_R));
|
||||
ctx.fillStyle = 'rgba(0,0,0,0.13)';
|
||||
ctx.fill();
|
||||
ctx.lineWidth = 3;
|
||||
ctx.strokeStyle = 'rgba(217,180,90,0.85)';
|
||||
ctx.stroke();
|
||||
poly(ctx, feltCircle(u, v, BET_SPOT_R * 0.8));
|
||||
ctx.lineWidth = 1.5;
|
||||
ctx.strokeStyle = 'rgba(242,234,216,0.4)';
|
||||
ctx.stroke();
|
||||
|
||||
const pose = cardPose(seat, 0, 1, null, CARD_W);
|
||||
ctx.save();
|
||||
ctx.translate(pose.x, pose.y);
|
||||
ctx.rotate(pose.rot);
|
||||
ctx.scale(pose.s, pose.s * VIEW.squash);
|
||||
rr(ctx, -CARD_W / 2 - 14, -CARD_H / 2 - 8, CARD_W + 28, CARD_H + 16, 12);
|
||||
ctx.lineWidth = 2 / pose.s;
|
||||
ctx.strokeStyle = 'rgba(242,234,216,0.32)';
|
||||
ctx.stroke();
|
||||
ctx.restore();
|
||||
});
|
||||
|
||||
// Insurance band
|
||||
const { r0, r1, span } = INSURANCE_LINES;
|
||||
for (const r of [r0, r1]) {
|
||||
const pts = [];
|
||||
for (let d = -span; d <= span; d += 1) pts.push(polar(r, d));
|
||||
poly(ctx, pts, false);
|
||||
ctx.lineWidth = 2.5;
|
||||
ctx.strokeStyle = 'rgba(242,234,216,0.5)';
|
||||
ctx.stroke();
|
||||
}
|
||||
}
|
||||
|
||||
export async function prepareBlackjackArt(scene) {
|
||||
await prepareCasinoArt(scene);
|
||||
bakeCasinoTable(scene, 'bj-table', {
|
||||
felt: '#0d5a2c',
|
||||
markings: drawMarkings,
|
||||
text: FELT_TEXT,
|
||||
tray: TRAY,
|
||||
shoe: SHOE,
|
||||
discard: DISCARD,
|
||||
placard: { ...PLACARD, lines: ['TABLE LIMITS', '$5 – $100'] },
|
||||
});
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,109 @@
|
|||
// Blackjack table layout — Phaser-free so tools/verifyBlackjack.js can test it.
|
||||
//
|
||||
// The perspective projection and rail geometry are shared by every casino table
|
||||
// (src/ui/casino/CasinoGeometry.js) and re-exported here; this file only adds
|
||||
// Blackjack's seats, card spots, bet circles and felt lettering.
|
||||
|
||||
import { polar, project, radialRotation } from '../../ui/casino/CasinoGeometry.js';
|
||||
|
||||
export * from '../../ui/casino/CasinoGeometry.js';
|
||||
|
||||
// ── Seats ────────────────────────────────────────────────────────────────────
|
||||
// Seat 0 is the human (bottom-centre); 1/2 bottom-right/left, 3/4 mid, 5/6 top.
|
||||
// Order is outward-alternating so the table stays balanced with few opponents.
|
||||
export const SEAT_ANGLES = [0, 25, -25, 49, -49, 71, -71];
|
||||
|
||||
// Turn order: dealer's left ("first base", screen-right top) clockwise.
|
||||
export const PLAY_ORDER = [5, 3, 1, 0, 2, 4, 6];
|
||||
|
||||
export const CARD_R = 0.655; // radius of each seat's card spot
|
||||
export const BET_R = 0.885; // radius of each seat's betting circle
|
||||
export const BET_SPOT_R = 0.058;
|
||||
export const BADGE_R = 0.772; // hand-total badge, between the cards and the bet circle
|
||||
export const CARD_ROT_DAMP = 0.62; // how much cards turn to face their seat
|
||||
|
||||
// Portrait centres sit outside the rail. Bottom seats are pushed sideways
|
||||
// because the HUD dock owns the bottom of the screen. Seat 0 (the human)
|
||||
// lives in the dock.
|
||||
const PORTRAITS = [
|
||||
{ x: 160, y: 1013, r: 50 }, // 0 human — in the dock, bottom-left
|
||||
{ x: 1556, y: 812, r: 56 }, // 1 right-bottom
|
||||
{ x: 364, y: 812, r: 56 }, // 2 left-bottom
|
||||
{ x: 1786, y: 640, r: 56 }, // 3 right-mid
|
||||
{ x: 134, y: 640, r: 56 }, // 4 left-mid
|
||||
{ x: 1810, y: 330, r: 56 }, // 5 right-top
|
||||
{ x: 110, y: 330, r: 56 }, // 6 left-top
|
||||
];
|
||||
|
||||
// Screen rotation for a seat's cards: their bottom edge turns toward the seat.
|
||||
function cardRotation(theta) {
|
||||
return radialRotation(CARD_R, theta, CARD_ROT_DAMP);
|
||||
}
|
||||
|
||||
export function seatLayout(seat) {
|
||||
const theta = SEAT_ANGLES[seat];
|
||||
const card = { ...polar(CARD_R, theta), rot: cardRotation(theta) };
|
||||
const bet = polar(BET_R, theta);
|
||||
const badge = polar(BADGE_R, theta);
|
||||
return { seat, theta, card, bet, badge, portrait: { ...PORTRAITS[seat] } };
|
||||
}
|
||||
|
||||
// Where a hand's cards go. `hand` is 0/1 for split hands (null = unsplit);
|
||||
// returns the screen pose of card `idx` of `total`.
|
||||
export const CARD_FAN = { dx: 27, dy: -7 }; // per-card offset in the card's own frame (px @ s=1)
|
||||
export const SPLIT_GAP = 0.74; // split hands sit ±this many card-widths apart
|
||||
|
||||
export function cardPose(seat, idx, total, hand = null, cardW = 96) {
|
||||
const { card } = seatLayout(seat);
|
||||
const s = card.s;
|
||||
const cos = Math.cos(card.rot), sin = Math.sin(card.rot);
|
||||
let lx = (idx - (total - 1) / 2) * CARD_FAN.dx * s;
|
||||
let ly = (idx - (total - 1) / 2) * CARD_FAN.dy * s;
|
||||
if (hand !== null) lx += (hand === 0 ? -1 : 1) * SPLIT_GAP * cardW * s;
|
||||
return {
|
||||
x: card.x + lx * cos - ly * sin,
|
||||
y: card.y + lx * sin + ly * cos,
|
||||
rot: card.rot,
|
||||
s,
|
||||
};
|
||||
}
|
||||
|
||||
// Split hands put their bets / badges a few degrees either side of the seat line.
|
||||
export const SPLIT_DEG = 6;
|
||||
|
||||
export function betPose(seat, hand = null) {
|
||||
const theta = SEAT_ANGLES[seat] + (hand === null ? 0 : (hand === 0 ? -SPLIT_DEG : SPLIT_DEG));
|
||||
return polar(BET_R, theta);
|
||||
}
|
||||
|
||||
export function badgePose(seat, hand = null) {
|
||||
const theta = SEAT_ANGLES[seat] + (hand === null ? 0 : (hand === 0 ? -SPLIT_DEG * 1.15 : SPLIT_DEG * 1.15));
|
||||
return polar(BADGE_R, theta);
|
||||
}
|
||||
|
||||
// Insurance bets sit on the insurance line in front of the seat.
|
||||
export const INSURANCE_R = 0.348;
|
||||
export function insurancePose(seat) {
|
||||
return polar(INSURANCE_R, SEAT_ANGLES[seat] * 0.55);
|
||||
}
|
||||
|
||||
// ── Felt lettering (table-space arcs) ────────────────────────────────────────
|
||||
export const INSURANCE_LINES = { r0: 0.312, r1: 0.386, span: 34 };
|
||||
export const FELT_TEXT = [
|
||||
{ text: 'INSURANCE PAYS 2 TO 1', r: 0.349, size: 21, color: '#f2ead8', alpha: 0.82, spacing: 1.0 },
|
||||
{ text: 'BLACKJACK PAYS 3 TO 2', r: 0.452, size: 36, color: '#e8c15a', alpha: 0.95, spacing: 1.02, bold: true },
|
||||
{ text: 'DEALER MUST STAND ON ALL 17s \u00b7 DRAW TO 16', r: 0.525, size: 19, color: '#f2ead8', alpha: 0.7, spacing: 0.94 },
|
||||
];
|
||||
|
||||
// ── Dealer side ──────────────────────────────────────────────────────────────
|
||||
export const DEALER_V = 0.205; // dealer hand row
|
||||
export const DEALER_SCALE_BOOST = 1.1; // far cards read a little bigger than strict perspective
|
||||
export const SHOE = { u: 0.47, v: 0.085 };
|
||||
export const DISCARD = { u: -0.47, v: 0.085 };
|
||||
export const PLACARD = { u: -0.335, v: 0.035 };
|
||||
|
||||
export function dealerCardPose(idx, total) {
|
||||
const p = project(0, DEALER_V);
|
||||
const s = p.s * DEALER_SCALE_BOOST;
|
||||
return { x: p.x + (idx - (total - 1) / 2) * 40 * s, y: p.y, rot: 0, s };
|
||||
}
|
||||
|
|
@ -0,0 +1,70 @@
|
|||
// Pai Gow Poker table art: royal-blue felt, a bet circle + HIGH / LOW boxes per
|
||||
// seat, dealer HIGH / LOW boxes. The shared kit bakes everything else.
|
||||
|
||||
import { prepareCasinoArt, bakeCasinoTable, poly, rr } from '../../ui/casino/CasinoArt.js';
|
||||
import {
|
||||
VIEW, feltCircle, seatLayout, dealerHighBox, dealerLowBox,
|
||||
BET_R, BET_SPOT_R, SEAT_ANGLES, FAN_DX, CARD_W, CARD_H,
|
||||
FELT_TEXT, TRAY, DISCARD, PLACARD,
|
||||
} from './PaiGowTable.js';
|
||||
|
||||
const MARKED_SEATS = [0, 1, 2, 3, 4];
|
||||
|
||||
function box(ctx, pose, n, label) {
|
||||
const w = CARD_W + (n - 1) * FAN_DX + 26;
|
||||
const h = CARD_H + 16;
|
||||
ctx.save();
|
||||
ctx.translate(pose.x, pose.y);
|
||||
ctx.rotate(pose.rot);
|
||||
ctx.scale(pose.s, pose.s * VIEW.squash);
|
||||
rr(ctx, -w / 2, -h / 2, w, h, 12);
|
||||
ctx.fillStyle = 'rgba(0,0,0,0.12)';
|
||||
ctx.fill();
|
||||
ctx.lineWidth = 2.2 / pose.s;
|
||||
ctx.strokeStyle = 'rgba(242,234,216,0.42)';
|
||||
ctx.stroke();
|
||||
ctx.fillStyle = 'rgba(232,193,90,0.75)';
|
||||
ctx.font = 'bold 20px "Julius Sans One", sans-serif';
|
||||
ctx.textAlign = 'center';
|
||||
ctx.textBaseline = 'middle';
|
||||
ctx.fillText(label, 0, 0);
|
||||
ctx.font = '13px "Julius Sans One", sans-serif';
|
||||
ctx.fillStyle = 'rgba(242,234,216,0.5)';
|
||||
ctx.fillText(n === 5 ? '5 CARDS' : '2 CARDS', 0, 24);
|
||||
ctx.restore();
|
||||
}
|
||||
|
||||
function drawMarkings(ctx) {
|
||||
for (const seat of MARKED_SEATS) {
|
||||
const t = (SEAT_ANGLES[seat] * Math.PI) / 180;
|
||||
const u = BET_R * Math.sin(t), v = BET_R * Math.cos(t);
|
||||
poly(ctx, feltCircle(u, v, BET_SPOT_R));
|
||||
ctx.fillStyle = 'rgba(0,0,0,0.14)';
|
||||
ctx.fill();
|
||||
ctx.lineWidth = 3;
|
||||
ctx.strokeStyle = 'rgba(217,180,90,0.85)';
|
||||
ctx.stroke();
|
||||
poly(ctx, feltCircle(u, v, BET_SPOT_R * 0.8));
|
||||
ctx.lineWidth = 1.5;
|
||||
ctx.strokeStyle = 'rgba(242,234,216,0.4)';
|
||||
ctx.stroke();
|
||||
|
||||
const L = seatLayout(seat);
|
||||
box(ctx, L.high, 5, 'HIGH');
|
||||
box(ctx, L.low, 2, 'LOW');
|
||||
}
|
||||
box(ctx, dealerHighBox(), 5, 'HIGH');
|
||||
box(ctx, dealerLowBox(), 2, 'LOW');
|
||||
}
|
||||
|
||||
export async function preparePaiGowArt(scene) {
|
||||
await prepareCasinoArt(scene);
|
||||
bakeCasinoTable(scene, 'pg-table', {
|
||||
felt: '#123c78',
|
||||
markings: drawMarkings,
|
||||
text: FELT_TEXT,
|
||||
tray: TRAY,
|
||||
discard: DISCARD,
|
||||
placard: PLACARD,
|
||||
});
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,134 @@
|
|||
// Pai Gow Poker table layout — Phaser-free so tools/verifyPaiGowPoker.js can test it.
|
||||
//
|
||||
// Shared perspective + rail geometry come from src/ui/casino/CasinoGeometry.js
|
||||
// (re-exported). Each seat has a bet circle near the rail, a HIGH box (5 cards)
|
||||
// and, inboard toward the dealer, a LOW box (2 cards).
|
||||
|
||||
import { polar, project, radialRotation, VIEW } from '../../ui/casino/CasinoGeometry.js';
|
||||
|
||||
export * from '../../ui/casino/CasinoGeometry.js';
|
||||
|
||||
export const CARD_W = 96;
|
||||
export const CARD_H = 134;
|
||||
|
||||
// Seat 0 = human (bottom-centre); 1/2 bottom-right/left; 3/4 upper-right/left.
|
||||
// The registry caps the table at 4 opponents; seat 5 only exists so the logic's
|
||||
// sixth player slot always has somewhere to sit.
|
||||
export const SEAT_ANGLES = [0, 28, -28, 56, -56, 78];
|
||||
export const PLAY_ORDER = [5, 3, 1, 0, 2, 4];
|
||||
|
||||
export const BET_R = 0.89;
|
||||
export const HIGH_R = 0.72;
|
||||
export const LOW_R = 0.528;
|
||||
export const BET_SPOT_R = 0.058;
|
||||
export const FAN_DX = 17; // px @ s=1 between fanned cards in a set hand
|
||||
export const STACK_DX = 2.2; // px between cards in an unset 7-card stack
|
||||
export const ROT_DAMP = 0.62;
|
||||
|
||||
const PORTRAITS = [
|
||||
{ x: 160, y: 1013, r: 50 }, // 0 human — in the dock
|
||||
{ x: 1584, y: 800, r: 56 }, // 1 right-bottom
|
||||
{ x: 336, y: 800, r: 56 }, // 2 left-bottom
|
||||
{ x: 1800, y: 560, r: 56 }, // 3 right-upper
|
||||
{ x: 120, y: 560, r: 56 }, // 4 left-upper
|
||||
{ x: 1810, y: 300, r: 56 }, // 5 right-top (unused at 4 opponents)
|
||||
];
|
||||
|
||||
export function seatLayout(seat) {
|
||||
const theta = SEAT_ANGLES[seat];
|
||||
const high = { ...polar(HIGH_R, theta), rot: radialRotation(HIGH_R, theta, ROT_DAMP) };
|
||||
const low = { ...polar(LOW_R, theta), rot: radialRotation(LOW_R, theta, ROT_DAMP) };
|
||||
const bet = polar(BET_R, theta);
|
||||
return { seat, theta, high, low, bet, portrait: { ...PORTRAITS[seat] } };
|
||||
}
|
||||
|
||||
// Offset a box pose along its own (rotated) x/y axes.
|
||||
function along(box, lx, ly) {
|
||||
const cos = Math.cos(box.rot), sin = Math.sin(box.rot);
|
||||
return { x: box.x + lx * cos - ly * sin, y: box.y + lx * sin + ly * cos, rot: box.rot, s: box.s };
|
||||
}
|
||||
|
||||
// Card i of n fanned inside a box.
|
||||
export function fanPose(box, i, n) {
|
||||
return along(box, (i - (n - 1) / 2) * FAN_DX * box.s, 0);
|
||||
}
|
||||
|
||||
// Unset 7-card stack sitting in the HIGH box.
|
||||
export function stackPose(box, i) {
|
||||
return along(box, (i - 3) * STACK_DX * box.s, -i * 0.6 * box.s);
|
||||
}
|
||||
|
||||
// Corner of a box (for the ✓ / ✗ markers), n = cards in the box.
|
||||
export function boxCorner(box, n) {
|
||||
const halfW = ((CARD_W + (n - 1) * FAN_DX) / 2) * box.s;
|
||||
const halfH = (CARD_H / 2) * box.s * VIEW.squash;
|
||||
return along(box, halfW + 4, -halfH + 4);
|
||||
}
|
||||
|
||||
// Where the hand-name badge goes: over the bottom of the cards.
|
||||
export function boxBadge(box) {
|
||||
return along(box, 0, (CARD_H / 2) * box.s * VIEW.squash - 14);
|
||||
}
|
||||
|
||||
// ── Dealer ───────────────────────────────────────────────────────────────────
|
||||
export const DEALER_V = 0.205;
|
||||
export const DEALER_BOOST = 1.08;
|
||||
export const DEALER_HIGH = { u: -0.15, v: DEALER_V };
|
||||
export const DEALER_LOW = { u: 0.16, v: DEALER_V };
|
||||
|
||||
function dealerBox(spot) {
|
||||
const p = project(spot.u, spot.v);
|
||||
return { ...p, s: p.s * DEALER_BOOST, rot: 0 };
|
||||
}
|
||||
export const dealerHighBox = () => dealerBox(DEALER_HIGH);
|
||||
export const dealerLowBox = () => dealerBox(DEALER_LOW);
|
||||
|
||||
// Dealer's 7 face-down cards before the reveal, in a row.
|
||||
export function dealerRowPose(i) {
|
||||
const p = project(0, DEALER_V);
|
||||
const s = p.s * DEALER_BOOST;
|
||||
return { x: p.x + (i - 3) * 30 * s, y: p.y, rot: 0, s };
|
||||
}
|
||||
|
||||
// ── Furniture ────────────────────────────────────────────────────────────────
|
||||
export const DICE_CUP = { u: 0.47, v: 0.085 };
|
||||
export const DICE_LAND = { u: 0.3, v: 0.16 }; // where the dice come to rest
|
||||
export const DECK = { u: 0.36, v: 0.07 }; // deck in the dealer's hands
|
||||
export const DISCARD = { u: -0.47, v: 0.085 };
|
||||
export const PLACARD = { u: -0.335, v: 0.035, lines: ['5% COMMISSION', '$5 – $100'] };
|
||||
|
||||
// Felt lettering
|
||||
export const FELT_TEXT = [
|
||||
{ text: 'PAI GOW POKER', r: 0.41, size: 30, color: '#e8c15a', alpha: 0.95, spacing: 1.06, bold: true },
|
||||
{ text: 'COPIES GO TO THE BANKER', r: 0.345, size: 15, color: '#f2ead8', alpha: 0.72, spacing: 0.95 },
|
||||
];
|
||||
|
||||
// ── Dice → first seat ────────────────────────────────────────────────────────
|
||||
// Real tables count the dice total counter-clockwise from the dealer (position 1).
|
||||
// `positions` is the list starting with 'dealer' then the seats in deal order.
|
||||
export function diceStartIndex(total, positionCount) {
|
||||
return (((total - 1) % positionCount) + positionCount) % positionCount;
|
||||
}
|
||||
|
||||
export function rotateFrom(arr, idx) {
|
||||
return [...arr.slice(idx), ...arr.slice(0, idx)];
|
||||
}
|
||||
|
||||
// ── Setting tray (expands up out of the dock) ────────────────────────────────
|
||||
export const SET_TRAY = { x0: 400, x1: 1520, y0: 778, y1: 1080 };
|
||||
export const TRAY_CARD_Y = 902;
|
||||
export const TRAY_SCALE = 0.95;
|
||||
export const TRAY_HIGH = { x0: 430, x1: 1040 }; // HIGH zone (holds up to 7 cards)
|
||||
export const TRAY_LOW = { x0: 1066, x1: 1266 }; // LOW zone (2 cards)
|
||||
export const TRAY_HIGH_DX = 82;
|
||||
export const TRAY_LOW_DX = 98;
|
||||
|
||||
export function trayHighX(i, n) {
|
||||
const mid = (TRAY_HIGH.x0 + TRAY_HIGH.x1) / 2;
|
||||
return mid + (i - (n - 1) / 2) * TRAY_HIGH_DX;
|
||||
}
|
||||
|
||||
export function trayLowX(i) {
|
||||
const mid = (TRAY_LOW.x0 + TRAY_LOW.x1) / 2;
|
||||
return mid + (i - 0.5) * TRAY_LOW_DX;
|
||||
}
|
||||
|
|
@ -0,0 +1,398 @@
|
|||
// Casino poker chips — shared, procedurally baked chip art.
|
||||
//
|
||||
// Textures (baked once into the global TextureManager, so they survive scene changes):
|
||||
// chip-face-<d> 128×128 top-down chip (buttons, thrown chips)
|
||||
// chip-slice-<d> one chip seen at a tilt (top face + edge band) — stack these
|
||||
// bottom-up, each one SLICE_T px higher, to build a 3D stack.
|
||||
//
|
||||
// breakdown() is pure so verify scripts can import this file under Node; the
|
||||
// bakers only touch `document` when called.
|
||||
//
|
||||
// Usage:
|
||||
// ensureChipTextures(scene); // after fonts are loaded
|
||||
// makeChip(scene, x, y, 25, { size: 72 }); // flat face image
|
||||
// makeChipStack(scene, x, y, 135, { scale: 0.9 }); // container, bottom chip centred on (x, y)
|
||||
|
||||
export const CHIP_DEFS = {
|
||||
1: { base: '#ebe6da', insert: '#2b5fb4', accent: '#c3242b', text: '#2b5fb4' },
|
||||
5: { base: '#c1222a', insert: '#f4efe4', accent: '#1f4fa0', text: '#a51c22' },
|
||||
25: { base: '#1d7d3a', insert: '#f4efe4', accent: '#e2b93b', text: '#17652f' },
|
||||
50: { base: '#1f5bb8', insert: '#f4efe4', accent: '#f08a1c', text: '#1a4c9a' },
|
||||
100: { base: '#1b1b20', insert: '#f4efe4', accent: '#d4a017', text: '#1b1b20' },
|
||||
};
|
||||
export const DENOMS = [100, 50, 25, 5, 1];
|
||||
|
||||
// Greedy denomination breakdown, largest first (= bottom of the stack).
|
||||
export function breakdown(amount) {
|
||||
const out = [];
|
||||
let rest = Math.max(0, Math.floor(amount));
|
||||
for (const d of DENOMS) {
|
||||
while (rest >= d) { out.push(d); rest -= d; }
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
export function chipColor(denom) {
|
||||
return parseInt((CHIP_DEFS[denom]?.base ?? '#888888').slice(1), 16);
|
||||
}
|
||||
|
||||
// ── Geometry of the baked art ────────────────────────────────────────────────
|
||||
export const FACE = 128; // face texture size
|
||||
const R = 62; // chip radius inside the face texture
|
||||
export const SLICE_RY = 25; // vertical radius of the tilted top ellipse
|
||||
export const SLICE_T = 11; // edge thickness (texture px)
|
||||
export const SLICE_H = SLICE_RY * 2 + SLICE_T + 4;
|
||||
const SLICE_CY_TOP = SLICE_RY + 2;
|
||||
const SLICE_CY_BOT = SLICE_CY_TOP + SLICE_T;
|
||||
const INSERT_ANGLES = [30, 90, 150, 210, 270, 330];
|
||||
const INSERT_HALF = 13; // degrees
|
||||
|
||||
// ── Colour helpers ───────────────────────────────────────────────────────────
|
||||
function shade(hex, amt) {
|
||||
// amt −1 … +1: darken toward black / lighten toward white
|
||||
const n = parseInt(hex.slice(1), 16);
|
||||
let r = (n >> 16) & 255, g = (n >> 8) & 255, b = n & 255;
|
||||
const t = amt < 0 ? 0 : 255, p = Math.abs(amt);
|
||||
r = Math.round((t - r) * p + r); g = Math.round((t - g) * p + g); b = Math.round((t - b) * p + b);
|
||||
return `rgb(${r},${g},${b})`;
|
||||
}
|
||||
|
||||
function annularSector(ctx, cx, cy, r0, r1, a0, a1) {
|
||||
ctx.beginPath();
|
||||
ctx.arc(cx, cy, r1, a0, a1, false);
|
||||
ctx.arc(cx, cy, r0, a1, a0, true);
|
||||
ctx.closePath();
|
||||
}
|
||||
|
||||
const DEG = Math.PI / 180;
|
||||
|
||||
// ── Face ─────────────────────────────────────────────────────────────────────
|
||||
function drawFace(ctx, denom) {
|
||||
const def = CHIP_DEFS[denom];
|
||||
const cx = FACE / 2, cy = FACE / 2;
|
||||
|
||||
// Body
|
||||
const body = ctx.createRadialGradient(cx - R * 0.35, cy - R * 0.4, R * 0.1, cx, cy, R);
|
||||
body.addColorStop(0, shade(def.base, 0.22));
|
||||
body.addColorStop(0.6, def.base);
|
||||
body.addColorStop(1, shade(def.base, -0.35));
|
||||
ctx.fillStyle = body;
|
||||
ctx.beginPath(); ctx.arc(cx, cy, R, 0, Math.PI * 2); ctx.fill();
|
||||
|
||||
// Edge inserts with thin accent stripes
|
||||
for (const a of INSERT_ANGLES) {
|
||||
ctx.fillStyle = def.insert;
|
||||
annularSector(ctx, cx, cy, R * 0.74, R * 0.985, (a - INSERT_HALF) * DEG, (a + INSERT_HALF) * DEG);
|
||||
ctx.fill();
|
||||
ctx.fillStyle = def.accent;
|
||||
for (const off of [-6.5, 6.5]) {
|
||||
annularSector(ctx, cx, cy, R * 0.74, R * 0.985, (a + off - 1.6) * DEG, (a + off + 1.6) * DEG);
|
||||
ctx.fill();
|
||||
}
|
||||
}
|
||||
|
||||
// Bevel: dark outer edge + a top-left highlight
|
||||
ctx.lineWidth = 3;
|
||||
ctx.strokeStyle = 'rgba(0,0,0,0.45)';
|
||||
ctx.beginPath(); ctx.arc(cx, cy, R - 1.5, 0, Math.PI * 2); ctx.stroke();
|
||||
ctx.lineWidth = 2;
|
||||
ctx.strokeStyle = 'rgba(255,255,255,0.35)';
|
||||
ctx.beginPath(); ctx.arc(cx, cy, R - 4, 195 * DEG, 290 * DEG); ctx.stroke();
|
||||
|
||||
// Dashed inner ring
|
||||
ctx.save();
|
||||
ctx.setLineDash([7, 5]);
|
||||
ctx.lineWidth = 2.5;
|
||||
ctx.strokeStyle = 'rgba(255,255,255,0.85)';
|
||||
if (denom === 1) ctx.strokeStyle = def.insert;
|
||||
ctx.beginPath(); ctx.arc(cx, cy, R * 0.67, 0, Math.PI * 2); ctx.stroke();
|
||||
ctx.restore();
|
||||
|
||||
// Inlay
|
||||
const inR = R * 0.56;
|
||||
const inlay = ctx.createLinearGradient(cx - inR, cy - inR, cx + inR, cy + inR);
|
||||
inlay.addColorStop(0, '#fdf9ef');
|
||||
inlay.addColorStop(1, '#e3d6bb');
|
||||
ctx.fillStyle = inlay;
|
||||
ctx.beginPath(); ctx.arc(cx, cy, inR, 0, Math.PI * 2); ctx.fill();
|
||||
ctx.lineWidth = 2.5;
|
||||
ctx.strokeStyle = '#c9a24a';
|
||||
ctx.beginPath(); ctx.arc(cx, cy, inR, 0, Math.PI * 2); ctx.stroke();
|
||||
ctx.lineWidth = 1;
|
||||
ctx.strokeStyle = def.text;
|
||||
ctx.globalAlpha = 0.55;
|
||||
ctx.beginPath(); ctx.arc(cx, cy, inR - 5, 0, Math.PI * 2); ctx.stroke();
|
||||
// ring of engraved dots
|
||||
ctx.fillStyle = def.text;
|
||||
for (let i = 0; i < 16; i++) {
|
||||
const a = (i / 16) * Math.PI * 2;
|
||||
ctx.beginPath(); ctx.arc(cx + Math.cos(a) * (inR - 10), cy + Math.sin(a) * (inR - 10), 1.3, 0, Math.PI * 2); ctx.fill();
|
||||
}
|
||||
ctx.globalAlpha = 1;
|
||||
|
||||
// Denomination (embossed)
|
||||
const label = String(denom);
|
||||
const size = label.length === 1 ? 44 : label.length === 2 ? 38 : 30;
|
||||
ctx.font = `${size}px Righteous, "Julius Sans One", sans-serif`;
|
||||
ctx.textAlign = 'center';
|
||||
ctx.textBaseline = 'middle';
|
||||
ctx.fillStyle = 'rgba(255,255,255,0.8)';
|
||||
ctx.fillText(label, cx + 1, cy + 3);
|
||||
ctx.fillStyle = def.text;
|
||||
ctx.fillText(label, cx, cy + 2);
|
||||
|
||||
// Gloss
|
||||
const gloss = ctx.createRadialGradient(cx - R * 0.45, cy - R * 0.5, 0, cx - R * 0.3, cy - R * 0.35, R * 1.05);
|
||||
gloss.addColorStop(0, 'rgba(255,255,255,0.32)');
|
||||
gloss.addColorStop(0.45, 'rgba(255,255,255,0.06)');
|
||||
gloss.addColorStop(1, 'rgba(255,255,255,0)');
|
||||
ctx.fillStyle = gloss;
|
||||
ctx.beginPath(); ctx.arc(cx, cy, R, 0, Math.PI * 2); ctx.fill();
|
||||
}
|
||||
|
||||
// ── Tilted slice (edge band + squashed face) ─────────────────────────────────
|
||||
function drawSlice(ctx, faceCanvas, denom) {
|
||||
const def = CHIP_DEFS[denom];
|
||||
const cx = FACE / 2, rx = R, ry = SLICE_RY;
|
||||
const yT = SLICE_CY_TOP, yB = SLICE_CY_BOT;
|
||||
|
||||
// Edge band
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(cx - rx, yT);
|
||||
ctx.lineTo(cx - rx, yB);
|
||||
ctx.ellipse(cx, yB, rx, ry, 0, Math.PI, 0, true);
|
||||
ctx.lineTo(cx + rx, yT);
|
||||
ctx.ellipse(cx, yT, rx, ry, 0, 0, Math.PI, false);
|
||||
ctx.closePath();
|
||||
ctx.fillStyle = shade(def.base, -0.1);
|
||||
ctx.fill();
|
||||
|
||||
// Edge inserts visible on the front half of the band
|
||||
ctx.fillStyle = def.insert;
|
||||
for (const a of INSERT_ANGLES) {
|
||||
const a0 = (a - INSERT_HALF) * DEG, a1 = (a + INSERT_HALF) * DEG;
|
||||
if (Math.sin(a0) <= 0 && Math.sin(a1) <= 0) continue;
|
||||
ctx.beginPath();
|
||||
const steps = 8;
|
||||
for (let i = 0; i <= steps; i++) {
|
||||
const t = a0 + ((a1 - a0) * i) / steps;
|
||||
const y = yT + Math.max(0, Math.sin(t)) * ry;
|
||||
ctx[i ? 'lineTo' : 'moveTo'](cx + Math.cos(t) * rx, y);
|
||||
}
|
||||
for (let i = steps; i >= 0; i--) {
|
||||
const t = a0 + ((a1 - a0) * i) / steps;
|
||||
ctx.lineTo(cx + Math.cos(t) * rx, yB + Math.max(0, Math.sin(t)) * ry);
|
||||
}
|
||||
ctx.closePath();
|
||||
ctx.fill();
|
||||
}
|
||||
|
||||
// Cylindrical shading over the band
|
||||
ctx.save();
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(cx - rx, yT);
|
||||
ctx.lineTo(cx - rx, yB);
|
||||
ctx.ellipse(cx, yB, rx, ry, 0, Math.PI, 0, true);
|
||||
ctx.lineTo(cx + rx, yT);
|
||||
ctx.closePath();
|
||||
ctx.clip();
|
||||
const cyl = ctx.createLinearGradient(cx - rx, 0, cx + rx, 0);
|
||||
cyl.addColorStop(0, 'rgba(0,0,0,0.55)');
|
||||
cyl.addColorStop(0.32, 'rgba(255,255,255,0.18)');
|
||||
cyl.addColorStop(0.55, 'rgba(0,0,0,0.05)');
|
||||
cyl.addColorStop(1, 'rgba(0,0,0,0.6)');
|
||||
ctx.fillStyle = cyl;
|
||||
ctx.fillRect(0, 0, FACE, SLICE_H);
|
||||
ctx.restore();
|
||||
|
||||
// Seam between stacked chips
|
||||
ctx.lineWidth = 1.5;
|
||||
ctx.strokeStyle = 'rgba(0,0,0,0.45)';
|
||||
ctx.beginPath(); ctx.ellipse(cx, yB, rx, ry, 0, 0, Math.PI, false); ctx.stroke();
|
||||
|
||||
// Top face, squashed into the ellipse
|
||||
const pad = (FACE / 2 - R);
|
||||
ctx.drawImage(faceCanvas, pad, pad, R * 2, R * 2, cx - rx, yT - ry, rx * 2, ry * 2);
|
||||
}
|
||||
|
||||
function makeCanvas(w, h) {
|
||||
const c = document.createElement('canvas');
|
||||
c.width = w; c.height = h;
|
||||
return c;
|
||||
}
|
||||
|
||||
export function ensureChipTextures(scene) {
|
||||
for (const d of DENOMS) {
|
||||
const faceKey = `chip-face-${d}`;
|
||||
const sliceKey = `chip-slice-${d}`;
|
||||
if (scene.textures.exists(faceKey) && scene.textures.exists(sliceKey)) continue;
|
||||
const face = makeCanvas(FACE, FACE);
|
||||
drawFace(face.getContext('2d'), d);
|
||||
if (!scene.textures.exists(faceKey)) scene.textures.addCanvas(faceKey, face);
|
||||
const slice = makeCanvas(FACE, SLICE_H);
|
||||
drawSlice(slice.getContext('2d'), face, d);
|
||||
if (!scene.textures.exists(sliceKey)) scene.textures.addCanvas(sliceKey, slice);
|
||||
}
|
||||
}
|
||||
|
||||
// ── Game objects ─────────────────────────────────────────────────────────────
|
||||
|
||||
// Flat top-down chip (an Image, so its hit area can be set in texture space:
|
||||
// img.setInteractive(new Phaser.Geom.Circle(64, 64, 62), Phaser.Geom.Circle.Contains)).
|
||||
export function makeChip(scene, x, y, denom, { size = 64, depth } = {}) {
|
||||
const img = scene.add.image(x, y, `chip-face-${denom}`).setDisplaySize(size, size);
|
||||
if (depth !== undefined) img.setDepth(depth);
|
||||
return img;
|
||||
}
|
||||
|
||||
// A single tilted chip (for chips in flight over the felt).
|
||||
export function makeChipSlice(scene, x, y, denom, { size = 52, depth } = {}) {
|
||||
const img = scene.add.image(x, y, `chip-slice-${denom}`)
|
||||
.setOrigin(0.5, SLICE_CY_BOT / SLICE_H)
|
||||
.setScale(size / FACE);
|
||||
if (depth !== undefined) img.setDepth(depth);
|
||||
return img;
|
||||
}
|
||||
|
||||
// Deterministic tiny jitter so stacks look hand-placed but don't shimmer on redraw.
|
||||
function jitter(i, seed) {
|
||||
const s = Math.sin((i + 1) * 12.9898 + seed * 78.233) * 43758.5453;
|
||||
return (s - Math.floor(s)) * 2 - 1;
|
||||
}
|
||||
|
||||
// A 3D stack for `amount`. The container's origin is the felt contact point of
|
||||
// the bottom chip. Children are added bottom-up (containers ignore child depth).
|
||||
export function makeChipStack(scene, x, y, amount, {
|
||||
size = 52, depth, label = true, seed = 0, maxChips = 14,
|
||||
} = {}) {
|
||||
const cont = scene.add.container(x, y);
|
||||
if (depth !== undefined) cont.setDepth(depth);
|
||||
let chips = breakdown(amount);
|
||||
if (chips.length > maxChips) chips = chips.slice(0, maxChips);
|
||||
const k = size / FACE;
|
||||
const step = SLICE_T * k;
|
||||
|
||||
const shadow = scene.add.graphics();
|
||||
shadow.fillStyle(0x000000, 0.38);
|
||||
shadow.fillEllipse(size * 0.08, size * 0.06, size * 1.12, SLICE_RY * 2 * k * 1.15);
|
||||
cont.add(shadow);
|
||||
|
||||
chips.forEach((d, i) => {
|
||||
const img = scene.add.image(jitter(i, seed) * 1.4 * k * 2, -i * step, `chip-slice-${d}`)
|
||||
.setOrigin(0.5, SLICE_CY_BOT / SLICE_H)
|
||||
.setScale(k);
|
||||
cont.add(img);
|
||||
});
|
||||
|
||||
const topY = -(Math.max(1, chips.length) - 1) * step - (SLICE_T + SLICE_RY) * k;
|
||||
cont.stackTopY = topY;
|
||||
|
||||
if (label && amount > 0) {
|
||||
const txt = scene.add.text(size * 0.62, -SLICE_RY * k * 0.2, `$${amount.toLocaleString()}`, {
|
||||
fontFamily: '"Julius Sans One"', fontSize: `${Math.round(15 * Math.max(0.8, size / 52))}px`,
|
||||
color: '#f7ecd0', fontStyle: 'bold',
|
||||
}).setOrigin(0, 0.5);
|
||||
const pill = scene.add.graphics();
|
||||
pill.fillStyle(0x0b0806, 0.78);
|
||||
pill.fillRoundedRect(txt.x - 6, txt.y - txt.height / 2 - 2, txt.width + 12, txt.height + 4, 6);
|
||||
pill.lineStyle(1, 0xc8a84b, 0.7);
|
||||
pill.strokeRoundedRect(txt.x - 6, txt.y - txt.height / 2 - 2, txt.width + 12, txt.height + 4, 6);
|
||||
cont.add([pill, txt]);
|
||||
}
|
||||
return cont;
|
||||
}
|
||||
|
||||
// ── Chip flights (scene-agnostic; callers own their stack bookkeeping) ───────
|
||||
const lerpN = (a, b, t) => a + (b - a) * t;
|
||||
|
||||
function tweenP(scene, cfg) {
|
||||
return new Promise(res => scene.tweens.add({ ...cfg, onComplete: () => res() }));
|
||||
}
|
||||
|
||||
// One chip arcs from `from` to `to` ({x, y, s}) and vanishes on landing.
|
||||
export function throwChip(scene, denom, from, to, { delay = 0, size = 54, depth = 22, sound } = {}) {
|
||||
const chip = makeChipSlice(scene, from.x, from.y, denom, { size: 64, depth });
|
||||
const k0 = chip.scaleX;
|
||||
const k1 = (size * (to.s ?? 1)) / FACE;
|
||||
const prox = { t: 0 };
|
||||
return new Promise(res => {
|
||||
scene.tweens.add({
|
||||
targets: prox, t: 1, duration: 360, delay, ease: 'Cubic.easeOut',
|
||||
onUpdate: () => {
|
||||
const t = prox.t;
|
||||
chip.x = lerpN(from.x, to.x, t);
|
||||
chip.y = lerpN(from.y, to.y, t) - Math.sin(Math.PI * t) * 90;
|
||||
chip.setScale(lerpN(k0, k1, t));
|
||||
chip.rotation = (1 - t) * 0.6;
|
||||
},
|
||||
onComplete: () => { chip.destroy(); sound?.(); res(); },
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// A whole stack slides from `from` to `pose`; the caller redraws the real stack after.
|
||||
export async function throwStack(scene, from, pose, amount, { delay = 0, size = 54, depth = 22, sound } = {}) {
|
||||
const st = makeChipStack(scene, from.x, from.y, amount, { size: size * (pose.s ?? 1), depth, label: false });
|
||||
st.setAlpha(0).setScale(0.8);
|
||||
await tweenP(scene, {
|
||||
targets: st, x: pose.x, y: pose.y, alpha: 1, scale: 1, duration: 380, delay, ease: 'Cubic.easeOut',
|
||||
});
|
||||
sound?.();
|
||||
st.destroy();
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve a bet stack that is already on the felt.
|
||||
* outcome 'lose' → swept to the tray
|
||||
* outcome 'push' → slides back to the player
|
||||
* outcome 'win' → the dealer stacks `payout + commission` beside it; the
|
||||
* commission (if any) peels off back to the tray with a
|
||||
* "−5%" tag; then everything slides to the player.
|
||||
* opts: { payout, commission, tray: {x,y}, dest: {x,y}, depth, sound, tag }
|
||||
*/
|
||||
export async function settleStack(scene, st, outcome, {
|
||||
payout = 0, commission = 0, tray, dest, depth = 12, sound, tag = '−5%',
|
||||
} = {}) {
|
||||
if (!st) return;
|
||||
if (outcome === 'lose') {
|
||||
await tweenP(scene, {
|
||||
targets: st, x: tray.x + (Math.random() - 0.5) * 120, y: tray.y,
|
||||
scale: 0.7, alpha: { value: 0, ease: 'Expo.easeIn' }, duration: 520, ease: 'Cubic.easeInOut',
|
||||
});
|
||||
st.destroy();
|
||||
return;
|
||||
}
|
||||
const size = st.chipSize ?? 54;
|
||||
const sweepOut = [st];
|
||||
if (outcome === 'win' && payout > 0) {
|
||||
const gross = payout + commission;
|
||||
let pay = makeChipStack(scene, tray.x, tray.y, gross, { size, depth: depth + 1, seed: gross + 7 });
|
||||
pay.setScale(0.75);
|
||||
const px = st.x + size * 1.05, py = st.y + 2;
|
||||
await tweenP(scene, { targets: pay, x: px, y: py, scale: 1, duration: 440, ease: 'Cubic.easeOut' });
|
||||
sound?.();
|
||||
if (commission > 0) {
|
||||
await new Promise(r => scene.time.delayedCall(380, r));
|
||||
pay.destroy();
|
||||
pay = makeChipStack(scene, px, py, payout, { size, depth: depth + 1, seed: payout + 7 });
|
||||
const cut = makeChipStack(scene, px, py - 4, commission, { size: size * 0.85, depth: depth + 2, label: false });
|
||||
const t = scene.add.text(px, py - size * 0.9, tag, {
|
||||
fontFamily: '"Julius Sans One"', fontSize: '18px', color: '#ff8a80', fontStyle: 'bold',
|
||||
stroke: '#000000', strokeThickness: 4,
|
||||
}).setOrigin(0.5).setDepth(depth + 3);
|
||||
scene.tweens.add({ targets: t, y: t.y - 30, alpha: { value: 0, ease: 'Expo.easeIn' }, duration: 1100, onComplete: () => t.destroy() });
|
||||
await tweenP(scene, {
|
||||
targets: cut, x: tray.x, y: tray.y, scale: 0.6,
|
||||
alpha: { value: 0, ease: 'Expo.easeIn' }, duration: 560, ease: 'Cubic.easeInOut',
|
||||
});
|
||||
cut.destroy();
|
||||
}
|
||||
sweepOut.push(pay);
|
||||
await new Promise(r => scene.time.delayedCall(420, r));
|
||||
}
|
||||
await tweenP(scene, {
|
||||
targets: sweepOut, x: dest.x, y: dest.y, scale: 0.6,
|
||||
alpha: { value: 0, ease: 'Expo.easeIn' }, duration: 520, ease: 'Cubic.easeIn',
|
||||
});
|
||||
sweepOut.forEach(o => o.destroy());
|
||||
}
|
||||
|
|
@ -0,0 +1,996 @@
|
|||
// Shared casino art — everything is baked once into canvas textures (no image files).
|
||||
//
|
||||
// casino-cards atlas, one frame per card key ('As', 'Td', …, 'JK') at 2× resolution
|
||||
// casino-back-<hex> fallback card back in the player's chosen colour
|
||||
// casino-card-shadow soft drop shadow sized for a card (same 2× scale)
|
||||
// casino-dock leather/wood control strip along the bottom
|
||||
// casino-die-<1..6> casino dice faces; casino-dice-cup leather shaker cup
|
||||
// <table key> a full-screen 1920×1080 table baked by bakeCasinoTable(spec)
|
||||
//
|
||||
// Table specs come from each game (felt colour, markings callback, lettering,
|
||||
// furniture). All geometry is CasinoGeometry.js, so markings line up with
|
||||
// where the game places cards and chips.
|
||||
|
||||
import {
|
||||
VIEW, project, polar, arcTangent, arcPoints,
|
||||
FELT_R, RAIL_IN, RAIL_OUT, RAIL_FACE_PX, DOCK,
|
||||
} from './CasinoGeometry.js';
|
||||
import { CHIP_DEFS, ensureChipTextures } from '../CasinoChips.js';
|
||||
import { SUITS, RANKS } from '../../games/cards/Deck.js';
|
||||
|
||||
export const CARD_W = 96;
|
||||
export const CARD_H = 134;
|
||||
const RES = 2;
|
||||
const CW = CARD_W * RES;
|
||||
const CH = CARD_H * RES;
|
||||
const CR = 14; // corner radius (texture px)
|
||||
export const SHADOW_PAD = 40; // texture px around the card in casino-card-shadow
|
||||
|
||||
const W = 1920, H = 1080;
|
||||
const RED = '#c0182a';
|
||||
const BLACK = '#16161d';
|
||||
const SERIF = 'Georgia, "Times New Roman", serif';
|
||||
|
||||
// ── Entry point ──────────────────────────────────────────────────────────────
|
||||
export async function prepareCasinoArt(scene) {
|
||||
try {
|
||||
await Promise.all([
|
||||
document.fonts?.load('36px "Julius Sans One"'),
|
||||
document.fonts?.load('40px Righteous'),
|
||||
]);
|
||||
} catch { /* fall back to whatever is available */ }
|
||||
ensureChipTextures(scene);
|
||||
if (!scene.textures.exists('casino-cards')) bakeCards(scene);
|
||||
if (!scene.textures.exists('casino-card-shadow')) bakeCardShadow(scene);
|
||||
if (!scene.textures.exists('casino-dock')) bakeDock(scene);
|
||||
ensureDiceArt(scene);
|
||||
}
|
||||
|
||||
export function ensureCardBack(scene, fallbackColor) {
|
||||
const hex = (fallbackColor ?? '#1a3a6b').replace('#', '').toLowerCase();
|
||||
const key = `casino-back-${hex}`;
|
||||
if (scene.textures.exists(key)) return key;
|
||||
const c = canvas(CW, CH);
|
||||
drawCardBack(c.getContext('2d'), 0, 0, `#${hex}`);
|
||||
scene.textures.addCanvas(key, c);
|
||||
return key;
|
||||
}
|
||||
|
||||
// ── Helpers (exported for game-specific markings) ────────────────────────────
|
||||
export function canvas(w, h) {
|
||||
const c = document.createElement('canvas');
|
||||
c.width = w; c.height = h;
|
||||
return c;
|
||||
}
|
||||
|
||||
export function rr(ctx, x, y, w, h, r) {
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(x + r, y);
|
||||
ctx.lineTo(x + w - r, y);
|
||||
ctx.quadraticCurveTo(x + w, y, x + w, y + r);
|
||||
ctx.lineTo(x + w, y + h - r);
|
||||
ctx.quadraticCurveTo(x + w, y + h, x + w - r, y + h);
|
||||
ctx.lineTo(x + r, y + h);
|
||||
ctx.quadraticCurveTo(x, y + h, x, y + h - r);
|
||||
ctx.lineTo(x, y + r);
|
||||
ctx.quadraticCurveTo(x, y, x + r, y);
|
||||
ctx.closePath();
|
||||
}
|
||||
|
||||
export function poly(ctx, pts, close = true) {
|
||||
ctx.beginPath();
|
||||
pts.forEach((p, i) => (i ? ctx.lineTo(p.x, p.y) : ctx.moveTo(p.x, p.y)));
|
||||
if (close) ctx.closePath();
|
||||
}
|
||||
|
||||
export function lerp(a, b, t) { return a + (b - a) * t; }
|
||||
|
||||
export function mix(c1, c2, t) {
|
||||
const a = parseInt(c1.slice(1), 16), b = parseInt(c2.slice(1), 16);
|
||||
const r = Math.round(lerp((a >> 16) & 255, (b >> 16) & 255, t));
|
||||
const g = Math.round(lerp((a >> 8) & 255, (b >> 8) & 255, t));
|
||||
const bl = Math.round(lerp(a & 255, b & 255, t));
|
||||
return `rgb(${r},${g},${bl})`;
|
||||
}
|
||||
|
||||
export function noisePattern(ctx, size, alpha) {
|
||||
const c = canvas(size, size);
|
||||
const n = c.getContext('2d');
|
||||
const img = n.createImageData(size, size);
|
||||
for (let i = 0; i < img.data.length; i += 4) {
|
||||
const v = Math.random() < 0.5 ? 0 : 255;
|
||||
img.data[i] = img.data[i + 1] = img.data[i + 2] = v;
|
||||
img.data[i + 3] = Math.random() * alpha;
|
||||
}
|
||||
n.putImageData(img, 0, 0);
|
||||
return ctx.createPattern(c, 'repeat');
|
||||
}
|
||||
|
||||
// Text along a table-space arc of radius r, centred on θ = centerDeg.
|
||||
export function drawArcText(ctx, spec) {
|
||||
const { text, r, size, color, alpha = 1, spacing = 1, bold, centerDeg = 0 } = spec;
|
||||
ctx.font = `${bold ? 'bold ' : ''}${size}px "Julius Sans One", sans-serif`;
|
||||
ctx.textAlign = 'center';
|
||||
ctx.textBaseline = 'middle';
|
||||
const s0 = polar(r, centerDeg).s;
|
||||
const pxPerRad = VIEW.halfW * s0 * r;
|
||||
const widths = [...text].map(ch => ctx.measureText(ch).width * spacing);
|
||||
const total = widths.reduce((a, b) => a + b, 0);
|
||||
let a = (centerDeg * Math.PI) / 180 - total / 2 / pxPerRad;
|
||||
ctx.save();
|
||||
ctx.globalAlpha = alpha;
|
||||
ctx.fillStyle = color;
|
||||
ctx.shadowColor = 'rgba(0,0,0,0.35)';
|
||||
ctx.shadowBlur = 2;
|
||||
ctx.shadowOffsetY = 1;
|
||||
[...text].forEach((ch, i) => {
|
||||
const mid = a + widths[i] / 2 / pxPerRad;
|
||||
a += widths[i] / pxPerRad;
|
||||
if (ch === ' ') return;
|
||||
const deg = (mid * 180) / Math.PI;
|
||||
const p = polar(r, deg);
|
||||
const k = p.s / s0;
|
||||
ctx.save();
|
||||
ctx.translate(p.x, p.y);
|
||||
ctx.rotate(arcTangent(r, deg));
|
||||
ctx.scale(k, k * VIEW.squash);
|
||||
ctx.fillText(ch, 0, 0);
|
||||
ctx.restore();
|
||||
});
|
||||
ctx.restore();
|
||||
}
|
||||
|
||||
// ── Suits ────────────────────────────────────────────────────────────────────
|
||||
function heartPath(ctx, x, y, size) {
|
||||
const s = size / 2;
|
||||
ctx.moveTo(x, y + s);
|
||||
ctx.bezierCurveTo(x - s * 1.3, y - s * 0.05, x - s * 0.72, y - s * 1.18, x, y - s * 0.42);
|
||||
ctx.bezierCurveTo(x + s * 0.72, y - s * 1.18, x + s * 1.3, y - s * 0.05, x, y + s);
|
||||
ctx.closePath();
|
||||
}
|
||||
|
||||
function stemPath(ctx, x, y, s) {
|
||||
ctx.moveTo(x, y + s * 0.05);
|
||||
ctx.quadraticCurveTo(x - s * 0.08, y + s * 0.75, x - s * 0.42, y + s);
|
||||
ctx.lineTo(x + s * 0.42, y + s);
|
||||
ctx.quadraticCurveTo(x + s * 0.08, y + s * 0.75, x, y + s * 0.05);
|
||||
ctx.closePath();
|
||||
}
|
||||
|
||||
export function drawSuit(ctx, suit, x, y, size, color) {
|
||||
const s = size / 2;
|
||||
ctx.fillStyle = color ?? (suit === 'h' || suit === 'd' ? RED : BLACK);
|
||||
ctx.beginPath();
|
||||
if (suit === 'h') {
|
||||
heartPath(ctx, x, y, size);
|
||||
} else if (suit === 'd') {
|
||||
ctx.moveTo(x, y - s);
|
||||
ctx.quadraticCurveTo(x + s * 0.28, y - s * 0.3, x + s * 0.74, y);
|
||||
ctx.quadraticCurveTo(x + s * 0.28, y + s * 0.3, x, y + s);
|
||||
ctx.quadraticCurveTo(x - s * 0.28, y + s * 0.3, x - s * 0.74, y);
|
||||
ctx.quadraticCurveTo(x - s * 0.28, y - s * 0.3, x, y - s);
|
||||
ctx.closePath();
|
||||
} else if (suit === 's') {
|
||||
ctx.save();
|
||||
ctx.translate(x, y - s * 0.16);
|
||||
ctx.scale(1, -1);
|
||||
heartPath(ctx, 0, 0, size * 0.84);
|
||||
ctx.restore();
|
||||
stemPath(ctx, x, y, s);
|
||||
} else {
|
||||
const r = s * 0.36;
|
||||
ctx.arc(x, y - s * 0.44, r, 0, Math.PI * 2);
|
||||
ctx.moveTo(x - s * 0.4 + r, y + s * 0.06);
|
||||
ctx.arc(x - s * 0.4, y + s * 0.06, r, 0, Math.PI * 2);
|
||||
ctx.moveTo(x + s * 0.4 + r, y + s * 0.06);
|
||||
ctx.arc(x + s * 0.4, y + s * 0.06, r, 0, Math.PI * 2);
|
||||
ctx.moveTo(x + s * 0.2, y - s * 0.05);
|
||||
ctx.arc(x, y - s * 0.05, s * 0.2, 0, Math.PI * 2);
|
||||
stemPath(ctx, x, y, s);
|
||||
}
|
||||
ctx.fill();
|
||||
}
|
||||
|
||||
// ── Cards ────────────────────────────────────────────────────────────────────
|
||||
const L = 0.3, M = 0.5, R = 0.7, T = 0.21, B = 0.79;
|
||||
const PIPS = {
|
||||
2: [[M, T], [M, B]],
|
||||
3: [[M, T], [M, 0.5], [M, B]],
|
||||
4: [[L, T], [R, T], [L, B], [R, B]],
|
||||
5: [[L, T], [R, T], [M, 0.5], [L, B], [R, B]],
|
||||
6: [[L, T], [R, T], [L, 0.5], [R, 0.5], [L, B], [R, B]],
|
||||
7: [[L, T], [R, T], [M, 0.355], [L, 0.5], [R, 0.5], [L, B], [R, B]],
|
||||
8: [[L, T], [R, T], [M, 0.355], [L, 0.5], [R, 0.5], [M, 0.645], [L, B], [R, B]],
|
||||
9: [[L, T], [R, T], [L, 0.405], [R, 0.405], [M, 0.5], [L, 0.595], [R, 0.595], [L, B], [R, B]],
|
||||
10: [[L, T], [R, T], [M, 0.31], [L, 0.405], [R, 0.405], [L, 0.595], [R, 0.595], [M, 0.69], [L, B], [R, B]],
|
||||
};
|
||||
|
||||
function cardBase(ctx, x, y) {
|
||||
rr(ctx, x + 1, y + 1, CW - 2, CH - 2, CR);
|
||||
const g = ctx.createLinearGradient(x, y, x + CW, y + CH);
|
||||
g.addColorStop(0, '#fffdf7');
|
||||
g.addColorStop(1, '#efe7d6');
|
||||
ctx.fillStyle = g;
|
||||
ctx.fill();
|
||||
ctx.lineWidth = 2;
|
||||
ctx.strokeStyle = '#cbbfa6';
|
||||
ctx.stroke();
|
||||
rr(ctx, x + 6, y + 6, CW - 12, CH - 12, CR - 5);
|
||||
ctx.lineWidth = 1;
|
||||
ctx.strokeStyle = 'rgba(0,0,0,0.05)';
|
||||
ctx.stroke();
|
||||
}
|
||||
|
||||
function cornerIndex(ctx, label, suit, color) {
|
||||
ctx.fillStyle = color;
|
||||
ctx.textAlign = 'center';
|
||||
ctx.textBaseline = 'middle';
|
||||
ctx.font = `bold 40px ${SERIF}`;
|
||||
ctx.save();
|
||||
ctx.translate(24, 32);
|
||||
if (label.length > 1) ctx.scale(0.72, 1);
|
||||
ctx.fillText(label, 0, 0);
|
||||
ctx.restore();
|
||||
drawSuit(ctx, suit, 24, 68, 26, color);
|
||||
}
|
||||
|
||||
function crown(ctx, cx, cy, w, h, points, color) {
|
||||
const left = cx - w / 2, top = cy - h / 2, base = cy + h / 2;
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(left, base);
|
||||
ctx.lineTo(left, top);
|
||||
for (let i = 1; i < points; i++) {
|
||||
const px = left + (w * i) / (points - 1);
|
||||
const vx = px - w / (points - 1) / 2;
|
||||
ctx.lineTo(vx, cy + h * 0.08);
|
||||
ctx.lineTo(px, top);
|
||||
}
|
||||
ctx.lineTo(left + w, base);
|
||||
ctx.closePath();
|
||||
ctx.fillStyle = '#dcae35';
|
||||
ctx.fill();
|
||||
ctx.lineWidth = 2;
|
||||
ctx.strokeStyle = '#7c5a12';
|
||||
ctx.stroke();
|
||||
for (let i = 0; i < points; i++) {
|
||||
ctx.beginPath();
|
||||
ctx.arc(left + (w * i) / (points - 1), top - 3, 4.5, 0, Math.PI * 2);
|
||||
ctx.fillStyle = color;
|
||||
ctx.fill();
|
||||
}
|
||||
ctx.fillStyle = color;
|
||||
ctx.fillRect(left, base - 8, w, 8);
|
||||
ctx.fillStyle = '#f5d76e';
|
||||
for (let i = 0; i < 3; i++) {
|
||||
ctx.beginPath();
|
||||
ctx.arc(cx + (i - 1) * w * 0.3, base - 4, 2.4, 0, Math.PI * 2);
|
||||
ctx.fill();
|
||||
}
|
||||
}
|
||||
|
||||
function jackCap(ctx, cx, cy, color) {
|
||||
ctx.beginPath();
|
||||
ctx.ellipse(cx, cy + 10, 30, 22, 0, Math.PI, 0);
|
||||
ctx.closePath();
|
||||
ctx.fillStyle = color;
|
||||
ctx.fill();
|
||||
ctx.fillStyle = '#dcae35';
|
||||
ctx.fillRect(cx - 32, cy + 8, 64, 8);
|
||||
ctx.strokeStyle = '#7c5a12';
|
||||
ctx.lineWidth = 2;
|
||||
ctx.strokeRect(cx - 32, cy + 8, 64, 8);
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(cx + 14, cy - 6);
|
||||
ctx.bezierCurveTo(cx + 34, cy - 34, cx + 52, cy - 22, cx + 46, cy - 6);
|
||||
ctx.bezierCurveTo(cx + 40, cy - 18, cx + 28, cy - 18, cx + 14, cy - 6);
|
||||
ctx.fillStyle = '#dcae35';
|
||||
ctx.fill();
|
||||
ctx.stroke();
|
||||
}
|
||||
|
||||
function courtPanel(ctx) {
|
||||
const px = 46, py = 40, pw = CW - 92, ph = CH - 80;
|
||||
rr(ctx, px, py, pw, ph, 8);
|
||||
const g = ctx.createLinearGradient(px, py, px + pw, py + ph);
|
||||
g.addColorStop(0, '#fbf1d9');
|
||||
g.addColorStop(1, '#ecd29c');
|
||||
ctx.fillStyle = g;
|
||||
ctx.fill();
|
||||
return { px, py, pw, ph };
|
||||
}
|
||||
|
||||
function hatch(ctx, px, py, pw, ph) {
|
||||
ctx.save();
|
||||
rr(ctx, px + 5, py + 5, pw - 10, ph - 10, 5);
|
||||
ctx.clip();
|
||||
ctx.strokeStyle = 'rgba(160,120,40,0.12)';
|
||||
ctx.lineWidth = 1;
|
||||
for (let k = -ph; k < pw + ph; k += 7) {
|
||||
ctx.beginPath(); ctx.moveTo(px + k, py); ctx.lineTo(px + k - ph, py + ph); ctx.stroke();
|
||||
}
|
||||
ctx.restore();
|
||||
}
|
||||
|
||||
function drawCourt(ctx, rank, suit, color) {
|
||||
const { px, py, pw, ph } = courtPanel(ctx);
|
||||
ctx.lineWidth = 3;
|
||||
ctx.strokeStyle = color;
|
||||
ctx.stroke();
|
||||
rr(ctx, px + 5, py + 5, pw - 10, ph - 10, 5);
|
||||
ctx.lineWidth = 1.5;
|
||||
ctx.strokeStyle = '#c9a24a';
|
||||
ctx.stroke();
|
||||
hatch(ctx, px, py, pw, ph);
|
||||
|
||||
const cx = CW / 2;
|
||||
if (rank === 'K') crown(ctx, cx, 86, 62, 34, 5, color);
|
||||
else if (rank === 'Q') crown(ctx, cx, 88, 50, 28, 3, color);
|
||||
else jackCap(ctx, cx, 84, color);
|
||||
|
||||
ctx.font = `bold 84px ${SERIF}`;
|
||||
ctx.textAlign = 'center';
|
||||
ctx.textBaseline = 'middle';
|
||||
ctx.lineWidth = 3;
|
||||
ctx.strokeStyle = '#c9a24a';
|
||||
ctx.strokeText(rank, cx, 150);
|
||||
ctx.fillStyle = color;
|
||||
ctx.fillText(rank, cx, 150);
|
||||
|
||||
drawSuit(ctx, suit, cx, 204, 30, color);
|
||||
drawSuit(ctx, suit, px + 16, py + 18, 16, color);
|
||||
ctx.save();
|
||||
ctx.translate(px + pw - 16, py + ph - 18);
|
||||
ctx.rotate(Math.PI);
|
||||
drawSuit(ctx, suit, 0, 0, 16, color);
|
||||
ctx.restore();
|
||||
}
|
||||
|
||||
// Joker — an original jester's cap with bells over a ruffled collar.
|
||||
function drawJoker(ctx) {
|
||||
cardBase(ctx, 0, 0);
|
||||
const PURPLE = '#5b2a86', GOLD = '#d4a017';
|
||||
const stackIndex = () => {
|
||||
ctx.fillStyle = PURPLE;
|
||||
ctx.font = `bold 22px ${SERIF}`;
|
||||
ctx.textAlign = 'center';
|
||||
ctx.textBaseline = 'middle';
|
||||
[...'JOKER'].forEach((ch, i) => ctx.fillText(ch, 22, 26 + i * 22));
|
||||
};
|
||||
stackIndex();
|
||||
ctx.save();
|
||||
ctx.translate(CW, CH);
|
||||
ctx.rotate(Math.PI);
|
||||
stackIndex();
|
||||
ctx.restore();
|
||||
|
||||
const { px, py, pw, ph } = courtPanel(ctx);
|
||||
ctx.lineWidth = 3;
|
||||
ctx.strokeStyle = PURPLE;
|
||||
ctx.stroke();
|
||||
hatch(ctx, px, py, pw, ph);
|
||||
|
||||
const cx = CW / 2, base = 150;
|
||||
// three floppy points of the cap
|
||||
const tips = [{ x: cx - 46, y: 74, c: RED }, { x: cx, y: 56, c: PURPLE }, { x: cx + 46, y: 74, c: '#1f7a3a' }];
|
||||
for (const t of tips) {
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(cx - 30, base);
|
||||
ctx.quadraticCurveTo((t.x + cx) / 2 - 8, t.y + 20, t.x, t.y);
|
||||
ctx.quadraticCurveTo((t.x + cx) / 2 + 14, t.y + 34, cx + 30, base);
|
||||
ctx.closePath();
|
||||
ctx.fillStyle = t.c;
|
||||
ctx.fill();
|
||||
ctx.lineWidth = 2;
|
||||
ctx.strokeStyle = 'rgba(0,0,0,0.35)';
|
||||
ctx.stroke();
|
||||
}
|
||||
for (const t of tips) {
|
||||
ctx.beginPath();
|
||||
ctx.arc(t.x, t.y, 7, 0, Math.PI * 2);
|
||||
ctx.fillStyle = GOLD;
|
||||
ctx.fill();
|
||||
ctx.strokeStyle = '#7c5a12';
|
||||
ctx.lineWidth = 1.5;
|
||||
ctx.stroke();
|
||||
}
|
||||
// band + ruffled collar
|
||||
ctx.fillStyle = GOLD;
|
||||
ctx.fillRect(cx - 34, base - 4, 68, 10);
|
||||
for (let i = 0; i < 6; i++) {
|
||||
ctx.beginPath();
|
||||
ctx.arc(cx - 30 + i * 12, base + 16, 8, 0, Math.PI);
|
||||
ctx.fillStyle = i % 2 ? '#f6ecd3' : '#e7d3a5';
|
||||
ctx.fill();
|
||||
ctx.strokeStyle = 'rgba(0,0,0,0.25)';
|
||||
ctx.stroke();
|
||||
}
|
||||
// ribbon
|
||||
rr(ctx, cx - 52, 190, 104, 26, 6);
|
||||
ctx.fillStyle = PURPLE;
|
||||
ctx.fill();
|
||||
ctx.font = `bold 18px ${SERIF}`;
|
||||
ctx.fillStyle = '#f5d76e';
|
||||
ctx.textAlign = 'center';
|
||||
ctx.textBaseline = 'middle';
|
||||
ctx.fillText('JOKER', cx, 204);
|
||||
}
|
||||
|
||||
function drawCardFace(ctx, rank, suit) {
|
||||
const color = suit === 'h' || suit === 'd' ? RED : BLACK;
|
||||
const label = rank === 'T' ? '10' : rank;
|
||||
cardBase(ctx, 0, 0);
|
||||
cornerIndex(ctx, label, suit, color);
|
||||
ctx.save();
|
||||
ctx.translate(CW, CH);
|
||||
ctx.rotate(Math.PI);
|
||||
cornerIndex(ctx, label, suit, color);
|
||||
ctx.restore();
|
||||
|
||||
if (rank === 'A') {
|
||||
const big = suit === 's' ? 112 : 92;
|
||||
if (suit === 's') {
|
||||
ctx.beginPath();
|
||||
ctx.arc(CW / 2, CH / 2, 72, 0, Math.PI * 2);
|
||||
ctx.lineWidth = 2; ctx.strokeStyle = '#c9a24a'; ctx.stroke();
|
||||
ctx.beginPath();
|
||||
ctx.arc(CW / 2, CH / 2, 66, 0, Math.PI * 2);
|
||||
ctx.lineWidth = 1; ctx.strokeStyle = 'rgba(0,0,0,0.25)'; ctx.stroke();
|
||||
}
|
||||
drawSuit(ctx, suit, CW / 2, CH / 2, big, color);
|
||||
return;
|
||||
}
|
||||
if (rank === 'J' || rank === 'Q' || rank === 'K') { drawCourt(ctx, rank, suit, color); return; }
|
||||
|
||||
const n = rank === 'T' ? 10 : Number(rank);
|
||||
for (const [fx, fy] of PIPS[n]) {
|
||||
const x = fx * CW, y = fy * CH;
|
||||
if (fy > 0.5) {
|
||||
ctx.save(); ctx.translate(x, y); ctx.rotate(Math.PI);
|
||||
drawSuit(ctx, suit, 0, 0, 42, color);
|
||||
ctx.restore();
|
||||
} else {
|
||||
drawSuit(ctx, suit, x, y, 42, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function drawCardBack(ctx, x, y, base) {
|
||||
rr(ctx, x + 1, y + 1, CW - 2, CH - 2, CR);
|
||||
const g = ctx.createLinearGradient(x, y, x + CW, y + CH);
|
||||
g.addColorStop(0, mix(base, '#ffffff', 0.12));
|
||||
g.addColorStop(1, mix(base, '#000000', 0.25));
|
||||
ctx.fillStyle = g;
|
||||
ctx.fill();
|
||||
ctx.lineWidth = 2; ctx.strokeStyle = 'rgba(0,0,0,0.4)'; ctx.stroke();
|
||||
|
||||
rr(ctx, x + 10, y + 10, CW - 20, CH - 20, CR - 6);
|
||||
ctx.lineWidth = 4; ctx.strokeStyle = 'rgba(255,255,255,0.85)'; ctx.stroke();
|
||||
|
||||
ctx.save();
|
||||
rr(ctx, x + 16, y + 16, CW - 32, CH - 32, CR - 8);
|
||||
ctx.clip();
|
||||
ctx.strokeStyle = 'rgba(255,255,255,0.16)';
|
||||
ctx.lineWidth = 2;
|
||||
for (let k = -CH; k < CW + CH; k += 13) {
|
||||
ctx.beginPath(); ctx.moveTo(x + k, y); ctx.lineTo(x + k + CH, y + CH); ctx.stroke();
|
||||
ctx.beginPath(); ctx.moveTo(x + k, y + CH); ctx.lineTo(x + k + CH, y); ctx.stroke();
|
||||
}
|
||||
ctx.restore();
|
||||
|
||||
const cx = x + CW / 2, cy = y + CH / 2;
|
||||
ctx.beginPath(); ctx.arc(cx, cy, 30, 0, Math.PI * 2);
|
||||
ctx.fillStyle = mix(base, '#000000', 0.35); ctx.fill();
|
||||
ctx.lineWidth = 3; ctx.strokeStyle = '#d9b45a'; ctx.stroke();
|
||||
drawSuit(ctx, 's', cx, cy, 32, '#d9b45a');
|
||||
}
|
||||
|
||||
function bakeCards(scene) {
|
||||
const GAP = 4;
|
||||
const c = canvas(13 * (CW + GAP), 5 * (CH + GAP));
|
||||
const ctx = c.getContext('2d');
|
||||
const frames = [];
|
||||
SUITS.forEach((suit, row) => {
|
||||
RANKS.forEach((rank, col) => {
|
||||
const fx = col * (CW + GAP), fy = row * (CH + GAP);
|
||||
ctx.save();
|
||||
ctx.translate(fx, fy);
|
||||
drawCardFace(ctx, rank, suit);
|
||||
ctx.restore();
|
||||
frames.push([`${rank}${suit}`, fx, fy]);
|
||||
});
|
||||
});
|
||||
const jy = 4 * (CH + GAP);
|
||||
ctx.save();
|
||||
ctx.translate(0, jy);
|
||||
drawJoker(ctx);
|
||||
ctx.restore();
|
||||
frames.push(['JK', 0, jy]);
|
||||
const tex = scene.textures.addCanvas('casino-cards', c);
|
||||
for (const [name, fx, fy] of frames) tex.add(name, 0, fx, fy, CW, CH);
|
||||
}
|
||||
|
||||
function bakeCardShadow(scene) {
|
||||
const c = canvas(CW + SHADOW_PAD * 2, CH + SHADOW_PAD * 2);
|
||||
const ctx = c.getContext('2d');
|
||||
const OFF = 4000;
|
||||
ctx.shadowColor = 'rgba(0,0,0,0.75)';
|
||||
ctx.shadowBlur = 20;
|
||||
ctx.shadowOffsetX = OFF;
|
||||
rr(ctx, SHADOW_PAD - OFF, SHADOW_PAD, CW, CH, CR);
|
||||
ctx.fillStyle = '#000';
|
||||
ctx.fill();
|
||||
scene.textures.addCanvas('casino-card-shadow', c);
|
||||
}
|
||||
|
||||
// ── Dice ─────────────────────────────────────────────────────────────────────
|
||||
export const DIE_PX = 64;
|
||||
const DIE_PIPS = {
|
||||
1: [[0.5, 0.5]],
|
||||
2: [[0.27, 0.27], [0.73, 0.73]],
|
||||
3: [[0.27, 0.27], [0.5, 0.5], [0.73, 0.73]],
|
||||
4: [[0.27, 0.27], [0.73, 0.27], [0.27, 0.73], [0.73, 0.73]],
|
||||
5: [[0.27, 0.27], [0.73, 0.27], [0.5, 0.5], [0.27, 0.73], [0.73, 0.73]],
|
||||
6: [[0.27, 0.25], [0.73, 0.25], [0.27, 0.5], [0.73, 0.5], [0.27, 0.75], [0.73, 0.75]],
|
||||
};
|
||||
|
||||
function ensureDiceArt(scene) {
|
||||
for (let n = 1; n <= 6; n++) {
|
||||
const key = `casino-die-${n}`;
|
||||
if (scene.textures.exists(key)) continue;
|
||||
const c = canvas(DIE_PX, DIE_PX);
|
||||
const ctx = c.getContext('2d');
|
||||
rr(ctx, 2, 2, DIE_PX - 4, DIE_PX - 4, 11);
|
||||
const g = ctx.createLinearGradient(0, 0, DIE_PX, DIE_PX);
|
||||
g.addColorStop(0, '#e2333c');
|
||||
g.addColorStop(1, '#8e0f17');
|
||||
ctx.fillStyle = g;
|
||||
ctx.fill();
|
||||
ctx.lineWidth = 2;
|
||||
ctx.strokeStyle = 'rgba(255,255,255,0.35)';
|
||||
ctx.stroke();
|
||||
ctx.fillStyle = 'rgba(255,255,255,0.18)';
|
||||
rr(ctx, 7, 6, DIE_PX - 24, 12, 6);
|
||||
ctx.fill();
|
||||
for (const [fx, fy] of DIE_PIPS[n]) {
|
||||
ctx.beginPath();
|
||||
ctx.arc(fx * DIE_PX, fy * DIE_PX, 5.6, 0, Math.PI * 2);
|
||||
ctx.fillStyle = '#fdf6e6';
|
||||
ctx.fill();
|
||||
}
|
||||
scene.textures.addCanvas(key, c);
|
||||
}
|
||||
if (!scene.textures.exists('casino-dice-cup')) {
|
||||
const w = 120, h = 130;
|
||||
const c = canvas(w, h);
|
||||
const ctx = c.getContext('2d');
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(18, 22); ctx.lineTo(w - 18, 22); ctx.lineTo(w - 30, h - 16); ctx.lineTo(30, h - 16); ctx.closePath();
|
||||
const g = ctx.createLinearGradient(0, 0, w, 0);
|
||||
g.addColorStop(0, '#1d0f08');
|
||||
g.addColorStop(0.4, '#5a3522');
|
||||
g.addColorStop(1, '#140a05');
|
||||
ctx.fillStyle = g;
|
||||
ctx.fill();
|
||||
ctx.beginPath(); ctx.ellipse(w / 2, h - 16, w / 2 - 30, 9, 0, 0, Math.PI); ctx.fillStyle = '#140a05'; ctx.fill();
|
||||
ctx.beginPath(); ctx.ellipse(w / 2, 22, w / 2 - 18, 12, 0, 0, Math.PI * 2);
|
||||
ctx.fillStyle = '#0a0503'; ctx.fill();
|
||||
ctx.lineWidth = 4; ctx.strokeStyle = '#c9a24a'; ctx.stroke();
|
||||
ctx.setLineDash([5, 4]);
|
||||
ctx.lineWidth = 1.5; ctx.strokeStyle = 'rgba(214,174,120,0.55)';
|
||||
ctx.beginPath(); ctx.moveTo(24, 40); ctx.lineTo(w - 24, 40); ctx.stroke();
|
||||
ctx.setLineDash([]);
|
||||
scene.textures.addCanvas('casino-dice-cup', c);
|
||||
}
|
||||
}
|
||||
|
||||
// ── Table ────────────────────────────────────────────────────────────────────
|
||||
const LEATHER_DARK = '#0f0806';
|
||||
const LEATHER_MID = '#2c1a12';
|
||||
const LEATHER_HI = '#5e3e2b';
|
||||
|
||||
function railProfile(f) {
|
||||
// padded cylinder lit from above-front: bright ridge a little inboard of centre
|
||||
const ridge = Math.max(0, Math.cos((f - 0.42) * Math.PI * 1.05));
|
||||
const c1 = mix(LEATHER_DARK, LEATHER_MID, Math.min(1, ridge * 1.4));
|
||||
return ridge > 0.72 ? mix(LEATHER_MID, LEATHER_HI, (ridge - 0.72) / 0.28) : c1;
|
||||
}
|
||||
|
||||
function drawRailFace(ctx) {
|
||||
const top = arcPoints(RAIL_OUT, 160);
|
||||
const bottom = top.map(p => ({ x: p.x, y: p.y + RAIL_FACE_PX * p.s }));
|
||||
poly(ctx, [...top, ...bottom.reverse()]);
|
||||
ctx.fillStyle = LEATHER_DARK;
|
||||
ctx.fill();
|
||||
ctx.save();
|
||||
ctx.clip();
|
||||
const steps = 14;
|
||||
for (let i = 0; i <= steps; i++) {
|
||||
const f = i / steps;
|
||||
const pts = top.map(p => ({ x: p.x, y: p.y + RAIL_FACE_PX * p.s * f }));
|
||||
poly(ctx, pts, false);
|
||||
ctx.lineWidth = 4;
|
||||
ctx.strokeStyle = mix(LEATHER_MID, LEATHER_DARK, Math.min(1, f * 1.25));
|
||||
ctx.stroke();
|
||||
}
|
||||
ctx.restore();
|
||||
poly(ctx, top.map(p => ({ x: p.x, y: p.y + RAIL_FACE_PX * p.s })), false);
|
||||
ctx.lineWidth = 2;
|
||||
ctx.strokeStyle = 'rgba(0,0,0,0.8)';
|
||||
ctx.stroke();
|
||||
}
|
||||
|
||||
function drawRailTop(ctx) {
|
||||
const outer = arcPoints(RAIL_OUT, 160);
|
||||
const inner = arcPoints(RAIL_IN, 160);
|
||||
poly(ctx, [...outer, ...inner.slice().reverse()]);
|
||||
ctx.fillStyle = LEATHER_MID;
|
||||
ctx.fill();
|
||||
ctx.save();
|
||||
ctx.clip();
|
||||
const steps = 26;
|
||||
for (let i = 0; i <= steps; i++) {
|
||||
const f = i / steps;
|
||||
poly(ctx, arcPoints(lerp(RAIL_IN, RAIL_OUT, f), 160), false);
|
||||
ctx.lineWidth = 6;
|
||||
ctx.strokeStyle = railProfile(f);
|
||||
ctx.stroke();
|
||||
}
|
||||
ctx.fillStyle = noisePattern(ctx, 128, 26);
|
||||
ctx.fillRect(0, 0, W, H);
|
||||
poly(ctx, arcPoints(lerp(RAIL_IN, RAIL_OUT, 0.4), 160), false);
|
||||
ctx.lineWidth = 3;
|
||||
ctx.strokeStyle = 'rgba(255,230,200,0.13)';
|
||||
ctx.stroke();
|
||||
ctx.setLineDash([7, 5]);
|
||||
for (const f of [0.1, 0.9]) {
|
||||
poly(ctx, arcPoints(lerp(RAIL_IN, RAIL_OUT, f), 160), false);
|
||||
ctx.lineWidth = 1.5;
|
||||
ctx.strokeStyle = 'rgba(214,174,120,0.42)';
|
||||
ctx.stroke();
|
||||
}
|
||||
ctx.setLineDash([]);
|
||||
ctx.restore();
|
||||
}
|
||||
|
||||
function drawWood(ctx) {
|
||||
const outer = arcPoints(RAIL_IN, 160);
|
||||
const inner = arcPoints(FELT_R, 160);
|
||||
poly(ctx, [...outer, ...inner.slice().reverse()]);
|
||||
ctx.fillStyle = '#7a4520';
|
||||
ctx.fill();
|
||||
poly(ctx, arcPoints(lerp(FELT_R, RAIL_IN, 0.45), 160), false);
|
||||
ctx.lineWidth = 3;
|
||||
ctx.strokeStyle = 'rgba(214,150,80,0.55)';
|
||||
ctx.stroke();
|
||||
poly(ctx, inner, false);
|
||||
ctx.lineWidth = 1.5;
|
||||
ctx.strokeStyle = 'rgba(0,0,0,0.55)';
|
||||
ctx.stroke();
|
||||
|
||||
const a = project(-RAIL_OUT, 0), b = project(RAIL_OUT, 0);
|
||||
const c = project(RAIL_OUT, -0.04), d = project(-RAIL_OUT, -0.04);
|
||||
poly(ctx, [a, b, c, d]);
|
||||
const g = ctx.createLinearGradient(0, d.y, 0, a.y);
|
||||
g.addColorStop(0, '#9b5f2a');
|
||||
g.addColorStop(0.5, '#6e3d1a');
|
||||
g.addColorStop(1, '#3e200c');
|
||||
ctx.fillStyle = g;
|
||||
ctx.fill();
|
||||
ctx.beginPath(); ctx.moveTo(d.x, d.y); ctx.lineTo(c.x, c.y);
|
||||
ctx.lineWidth = 1.5; ctx.strokeStyle = 'rgba(255,210,150,0.45)'; ctx.stroke();
|
||||
}
|
||||
|
||||
function drawFelt(ctx, spec) {
|
||||
ctx.save();
|
||||
poly(ctx, arcPoints(FELT_R, 160));
|
||||
ctx.clip();
|
||||
ctx.fillStyle = spec.felt ?? '#0d5a2c';
|
||||
ctx.fillRect(0, 0, W, H);
|
||||
ctx.fillStyle = noisePattern(ctx, 256, 22);
|
||||
ctx.fillRect(0, 0, W, H);
|
||||
|
||||
spec.markings?.(ctx);
|
||||
for (const t of spec.text ?? []) drawArcText(ctx, t);
|
||||
|
||||
const c = project(0, 0.45);
|
||||
const lamp = ctx.createRadialGradient(c.x, c.y, 40, c.x, c.y, 900);
|
||||
lamp.addColorStop(0, 'rgba(255,248,210,0.20)');
|
||||
lamp.addColorStop(0.45, 'rgba(255,248,210,0.07)');
|
||||
lamp.addColorStop(1, 'rgba(255,248,210,0)');
|
||||
ctx.fillStyle = lamp;
|
||||
ctx.fillRect(0, 0, W, H);
|
||||
const vig = ctx.createRadialGradient(c.x, c.y, 380, c.x, c.y, 1050);
|
||||
vig.addColorStop(0, 'rgba(0,0,0,0)');
|
||||
vig.addColorStop(1, 'rgba(0,0,0,0.5)');
|
||||
ctx.fillStyle = vig;
|
||||
ctx.fillRect(0, 0, W, H);
|
||||
|
||||
for (let i = 0; i < 10; i++) {
|
||||
poly(ctx, arcPoints(FELT_R - i * 0.004, 160), false);
|
||||
ctx.lineWidth = 4;
|
||||
ctx.strokeStyle = `rgba(0,0,0,${0.32 * (1 - i / 10)})`;
|
||||
ctx.stroke();
|
||||
}
|
||||
const e = ctx.createLinearGradient(0, VIEW.yFar, 0, VIEW.yFar + 18);
|
||||
e.addColorStop(0, 'rgba(0,0,0,0.4)');
|
||||
e.addColorStop(1, 'rgba(0,0,0,0)');
|
||||
ctx.fillStyle = e;
|
||||
ctx.fillRect(0, VIEW.yFar, W, 18);
|
||||
ctx.restore();
|
||||
}
|
||||
|
||||
const DEFAULT_TRAY_COLS = [1, 5, 25, 50, 100, 100, 50, 25, 5, 1];
|
||||
|
||||
function drawTray(ctx, tray, cols = DEFAULT_TRAY_COLS) {
|
||||
const pad = 0.012;
|
||||
const frame = [
|
||||
project(tray.u0 - pad, tray.v0 - 0.006), project(tray.u1 + pad, tray.v0 - 0.006),
|
||||
project(tray.u1 + pad, tray.v1 + pad), project(tray.u0 - pad, tray.v1 + pad),
|
||||
];
|
||||
poly(ctx, frame);
|
||||
ctx.fillStyle = '#17110c';
|
||||
ctx.fill();
|
||||
ctx.lineWidth = 2;
|
||||
ctx.strokeStyle = 'rgba(214,174,120,0.5)';
|
||||
ctx.stroke();
|
||||
|
||||
const n = cols.length;
|
||||
const gap = 0.006;
|
||||
const colW = (tray.u1 - tray.u0 - gap * (n - 1)) / n;
|
||||
cols.forEach((denom, i) => {
|
||||
const def = CHIP_DEFS[denom];
|
||||
const ua = tray.u0 + i * (colW + gap), ub = ua + colW;
|
||||
const tl = project(ua, tray.v0), tr = project(ub, tray.v0);
|
||||
const bl = project(ua, tray.v1), br = project(ub, tray.v1);
|
||||
const stripes = 9;
|
||||
for (let k = 0; k < stripes; k++) {
|
||||
const f0 = k / stripes, f1 = (k + 0.82) / stripes;
|
||||
const q = [
|
||||
{ x: lerp(tl.x, bl.x, f0), y: lerp(tl.y, bl.y, f0) },
|
||||
{ x: lerp(tr.x, br.x, f0), y: lerp(tr.y, br.y, f0) },
|
||||
{ x: lerp(tr.x, br.x, f1), y: lerp(tr.y, br.y, f1) },
|
||||
{ x: lerp(tl.x, bl.x, f1), y: lerp(tl.y, bl.y, f1) },
|
||||
];
|
||||
poly(ctx, q);
|
||||
ctx.fillStyle = k % 2 ? def.base : mix(def.base, '#000000', 0.15);
|
||||
ctx.fill();
|
||||
if (k % 3 === 1) {
|
||||
const mx = (q[0].x + q[1].x) / 2, my = (q[0].y + q[3].y) / 2;
|
||||
ctx.fillStyle = def.insert;
|
||||
ctx.fillRect(mx - 2, my - 1, 4, 2);
|
||||
}
|
||||
}
|
||||
const g = ctx.createLinearGradient(tl.x, 0, tr.x, 0);
|
||||
g.addColorStop(0, 'rgba(0,0,0,0.55)');
|
||||
g.addColorStop(0.4, 'rgba(255,255,255,0.18)');
|
||||
g.addColorStop(1, 'rgba(0,0,0,0.55)');
|
||||
poly(ctx, [tl, tr, br, bl]);
|
||||
ctx.fillStyle = g;
|
||||
ctx.fill();
|
||||
});
|
||||
}
|
||||
|
||||
function drawShoe(ctx, spot) {
|
||||
const p = project(spot.u, spot.v);
|
||||
const s = p.s;
|
||||
const w = 132 * s, d = 54 * s, h = 30 * s;
|
||||
const x0 = p.x - w / 2, y0 = p.y - d / 2;
|
||||
|
||||
ctx.save();
|
||||
ctx.shadowColor = 'rgba(0,0,0,0.6)';
|
||||
ctx.shadowBlur = 14;
|
||||
ctx.shadowOffsetY = 8;
|
||||
ctx.fillStyle = '#000';
|
||||
ctx.fillRect(x0 + 4, y0 + 6, w - 8, d + h - 8);
|
||||
ctx.restore();
|
||||
|
||||
const fg = ctx.createLinearGradient(0, y0 + d, 0, y0 + d + h);
|
||||
fg.addColorStop(0, '#3d0b10');
|
||||
fg.addColorStop(1, '#1c0407');
|
||||
ctx.fillStyle = fg;
|
||||
ctx.fillRect(x0, y0 + d, w, h);
|
||||
const tg = ctx.createLinearGradient(x0, y0, x0, y0 + d);
|
||||
tg.addColorStop(0, '#6b1720');
|
||||
tg.addColorStop(1, '#4a0e15');
|
||||
ctx.fillStyle = tg;
|
||||
ctx.fillRect(x0, y0, w, d);
|
||||
ctx.fillStyle = '#ede4cf';
|
||||
ctx.fillRect(x0 + 26 * s, y0 + 10 * s, w - 40 * s, d - 20 * s);
|
||||
ctx.strokeStyle = 'rgba(0,0,0,0.18)';
|
||||
ctx.lineWidth = 1;
|
||||
for (let k = 0; k < 18; k++) {
|
||||
const yy = y0 + 10 * s + ((d - 20 * s) * k) / 18;
|
||||
ctx.beginPath(); ctx.moveTo(x0 + 26 * s, yy); ctx.lineTo(x0 + w - 14 * s, yy); ctx.stroke();
|
||||
}
|
||||
ctx.fillStyle = '#2a070b';
|
||||
ctx.fillRect(x0 + w - 22 * s, y0 + 6 * s, 14 * s, d - 12 * s);
|
||||
ctx.fillStyle = '#1a3a6b';
|
||||
ctx.fillRect(x0 - 6 * s, y0 + 12 * s, 30 * s, d - 24 * s);
|
||||
ctx.strokeStyle = 'rgba(255,255,255,0.8)';
|
||||
ctx.lineWidth = 1.5;
|
||||
ctx.strokeRect(x0 - 3 * s, y0 + 15 * s, 24 * s, d - 30 * s);
|
||||
ctx.fillStyle = 'rgba(30,8,10,0.85)';
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(x0, y0); ctx.lineTo(x0 + 20 * s, y0); ctx.lineTo(x0 + 20 * s, y0 + d + h);
|
||||
ctx.lineTo(x0 - 10 * s, y0 + d + h); ctx.closePath();
|
||||
ctx.fill();
|
||||
ctx.beginPath();
|
||||
ctx.arc(x0 + 6 * s, y0 + d / 2, 7 * s, 0, Math.PI * 2);
|
||||
ctx.fillStyle = '#0d0204';
|
||||
ctx.fill();
|
||||
ctx.strokeStyle = 'rgba(255,200,200,0.35)';
|
||||
ctx.lineWidth = 1.5;
|
||||
ctx.beginPath(); ctx.moveTo(x0 + 2, y0 + 1); ctx.lineTo(x0 + w - 2, y0 + 1); ctx.stroke();
|
||||
ctx.strokeStyle = 'rgba(255,255,255,0.12)';
|
||||
ctx.beginPath(); ctx.moveTo(x0, y0 + d); ctx.lineTo(x0 + w, y0 + d); ctx.stroke();
|
||||
}
|
||||
|
||||
function drawDiscard(ctx, spot) {
|
||||
const p = project(spot.u, spot.v);
|
||||
const s = p.s;
|
||||
const w = 108 * s, d = 48 * s, h = 26 * s;
|
||||
const x0 = p.x - w / 2, y0 = p.y - d / 2;
|
||||
ctx.save();
|
||||
ctx.shadowColor = 'rgba(0,0,0,0.5)';
|
||||
ctx.shadowBlur = 12;
|
||||
ctx.shadowOffsetY = 6;
|
||||
ctx.fillStyle = 'rgba(0,0,0,0.6)';
|
||||
ctx.fillRect(x0 + 4, y0 + 6, w - 8, d + h - 8);
|
||||
ctx.restore();
|
||||
ctx.fillStyle = '#e8dfc9';
|
||||
ctx.fillRect(x0 + 10 * s, y0 + d - 16 * s, w - 20 * s, 14 * s);
|
||||
ctx.strokeStyle = 'rgba(0,0,0,0.2)';
|
||||
for (let k = 0; k < 6; k++) {
|
||||
const yy = y0 + d - 16 * s + k * 2.4 * s;
|
||||
ctx.beginPath(); ctx.moveTo(x0 + 10 * s, yy); ctx.lineTo(x0 + w - 10 * s, yy); ctx.stroke();
|
||||
}
|
||||
ctx.fillStyle = 'rgba(40,40,48,0.42)';
|
||||
ctx.fillRect(x0, y0, w, d);
|
||||
ctx.fillStyle = 'rgba(20,20,26,0.7)';
|
||||
ctx.fillRect(x0, y0 + d, w, h);
|
||||
ctx.strokeStyle = 'rgba(255,255,255,0.3)';
|
||||
ctx.lineWidth = 1.5;
|
||||
ctx.strokeRect(x0, y0, w, d + h);
|
||||
ctx.beginPath(); ctx.moveTo(x0, y0 + d); ctx.lineTo(x0 + w, y0 + d); ctx.stroke();
|
||||
}
|
||||
|
||||
function drawPlacard(ctx, spot) {
|
||||
const p = project(spot.u, spot.v);
|
||||
const s = p.s;
|
||||
const w = 104 * s, h = 54 * s;
|
||||
const x0 = p.x - w / 2, yb = p.y;
|
||||
const [line1 = 'TABLE LIMITS', line2 = ''] = spot.lines ?? [];
|
||||
ctx.fillStyle = '#111';
|
||||
ctx.fillRect(x0 + 8 * s, yb - 5 * s, w - 16 * s, 8 * s);
|
||||
rr(ctx, x0, yb - h - 4 * s, w, h, 5 * s);
|
||||
const g = ctx.createLinearGradient(0, yb - h, 0, yb);
|
||||
g.addColorStop(0, '#1d1913');
|
||||
g.addColorStop(1, '#0a0806');
|
||||
ctx.fillStyle = g;
|
||||
ctx.fill();
|
||||
ctx.lineWidth = 2;
|
||||
ctx.strokeStyle = '#c9a24a';
|
||||
ctx.stroke();
|
||||
ctx.textAlign = 'center';
|
||||
ctx.textBaseline = 'middle';
|
||||
ctx.fillStyle = '#d9b45a';
|
||||
ctx.font = `${Math.round(11 * s * 1.3)}px "Julius Sans One", sans-serif`;
|
||||
ctx.fillText(line1, p.x, yb - h + 12 * s);
|
||||
ctx.fillStyle = '#f2ead8';
|
||||
ctx.font = `bold ${Math.round(17 * s * 1.3)}px "Julius Sans One", sans-serif`;
|
||||
ctx.fillText(line2, p.x, yb - h + 33 * s);
|
||||
}
|
||||
|
||||
/**
|
||||
* Bake a full-screen half-moon table.
|
||||
* spec = {
|
||||
* felt: '#0d5a2c', felt base colour
|
||||
* markings(ctx), game markings, drawn on the felt (clipped) before the lighting
|
||||
* text: [arc text specs], felt lettering (see drawArcText)
|
||||
* tray: {u0,u1,v0,v1}|null, trayCols: [denoms]
|
||||
* shoe, discard: {u,v}|null
|
||||
* placard: {u, v, lines: [small, big]}|null
|
||||
* extras(ctx) anything else drawn on top (unclipped)
|
||||
* }
|
||||
*/
|
||||
export function bakeCasinoTable(scene, key, spec) {
|
||||
if (scene.textures.exists(key)) return;
|
||||
const c = canvas(W, H);
|
||||
const ctx = c.getContext('2d');
|
||||
|
||||
const outline = arcPoints(RAIL_OUT, 120).map(p => ({ x: p.x, y: p.y + RAIL_FACE_PX * p.s }));
|
||||
const back = [project(RAIL_OUT, -0.04), project(-RAIL_OUT, -0.04)];
|
||||
const OFF = 6000;
|
||||
ctx.save();
|
||||
ctx.shadowColor = 'rgba(0,0,0,0.7)';
|
||||
ctx.shadowBlur = 60;
|
||||
ctx.shadowOffsetX = OFF;
|
||||
ctx.shadowOffsetY = 26;
|
||||
poly(ctx, [...outline, ...back].map(p => ({ x: p.x - OFF, y: p.y })));
|
||||
ctx.fillStyle = '#000';
|
||||
ctx.fill();
|
||||
ctx.restore();
|
||||
|
||||
drawRailFace(ctx);
|
||||
drawWood(ctx);
|
||||
drawRailTop(ctx);
|
||||
drawFelt(ctx, spec);
|
||||
if (spec.tray) drawTray(ctx, spec.tray, spec.trayCols);
|
||||
if (spec.discard) drawDiscard(ctx, spec.discard);
|
||||
if (spec.shoe) drawShoe(ctx, spec.shoe);
|
||||
if (spec.placard) drawPlacard(ctx, spec.placard);
|
||||
spec.extras?.(ctx);
|
||||
|
||||
scene.textures.addCanvas(key, c);
|
||||
}
|
||||
|
||||
// ── HUD dock ─────────────────────────────────────────────────────────────────
|
||||
function bakeDock(scene) {
|
||||
const c = canvas(W, DOCK.h);
|
||||
const ctx = c.getContext('2d');
|
||||
const g = ctx.createLinearGradient(0, 0, 0, DOCK.h);
|
||||
g.addColorStop(0, '#22160f');
|
||||
g.addColorStop(1, '#0b0705');
|
||||
ctx.fillStyle = g;
|
||||
ctx.fillRect(0, 0, W, DOCK.h);
|
||||
ctx.fillStyle = noisePattern(ctx, 128, 20);
|
||||
ctx.fillRect(0, 0, W, DOCK.h);
|
||||
const wg = ctx.createLinearGradient(0, 0, 0, 10);
|
||||
wg.addColorStop(0, '#a8692f');
|
||||
wg.addColorStop(1, '#4e2a10');
|
||||
ctx.fillStyle = wg;
|
||||
ctx.fillRect(0, 0, W, 10);
|
||||
ctx.fillStyle = 'rgba(200,168,75,0.9)';
|
||||
ctx.fillRect(0, 10, W, 1.5);
|
||||
ctx.setLineDash([7, 5]);
|
||||
ctx.strokeStyle = 'rgba(214,174,120,0.3)';
|
||||
ctx.lineWidth = 1.5;
|
||||
ctx.beginPath(); ctx.moveTo(0, 18); ctx.lineTo(W, 18); ctx.stroke();
|
||||
ctx.setLineDash([]);
|
||||
scene.textures.addCanvas('casino-dock', c);
|
||||
}
|
||||
|
||||
// A leather panel texture of any size (setting tray, close-up panels).
|
||||
export function ensureLeatherPanel(scene, key, w, h, { radius = 18, felt = null } = {}) {
|
||||
if (scene.textures.exists(key)) return key;
|
||||
const c = canvas(w, h);
|
||||
const ctx = c.getContext('2d');
|
||||
rr(ctx, 2, 2, w - 4, h - 4, radius);
|
||||
const g = ctx.createLinearGradient(0, 0, 0, h);
|
||||
g.addColorStop(0, '#24170f');
|
||||
g.addColorStop(1, '#0c0705');
|
||||
ctx.fillStyle = g;
|
||||
ctx.fill();
|
||||
ctx.save();
|
||||
ctx.clip();
|
||||
ctx.fillStyle = noisePattern(ctx, 128, 20);
|
||||
ctx.fillRect(0, 0, w, h);
|
||||
if (felt) {
|
||||
rr(ctx, 16, 16, w - 32, h - 32, radius - 6);
|
||||
ctx.fillStyle = felt;
|
||||
ctx.fill();
|
||||
ctx.fillStyle = noisePattern(ctx, 128, 22);
|
||||
ctx.fill();
|
||||
const v = ctx.createRadialGradient(w / 2, h / 2, Math.min(w, h) * 0.2, w / 2, h / 2, Math.max(w, h) * 0.7);
|
||||
v.addColorStop(0, 'rgba(255,248,210,0.08)');
|
||||
v.addColorStop(1, 'rgba(0,0,0,0.45)');
|
||||
ctx.fillStyle = v;
|
||||
ctx.fill();
|
||||
ctx.lineWidth = 2;
|
||||
ctx.strokeStyle = 'rgba(0,0,0,0.6)';
|
||||
ctx.stroke();
|
||||
}
|
||||
ctx.restore();
|
||||
rr(ctx, 2, 2, w - 4, h - 4, radius);
|
||||
ctx.lineWidth = 3;
|
||||
ctx.strokeStyle = '#c8a84b';
|
||||
ctx.stroke();
|
||||
ctx.setLineDash([7, 5]);
|
||||
rr(ctx, 8, 8, w - 16, h - 16, radius - 4);
|
||||
ctx.lineWidth = 1.5;
|
||||
ctx.strokeStyle = 'rgba(214,174,120,0.35)';
|
||||
ctx.stroke();
|
||||
ctx.setLineDash([]);
|
||||
scene.textures.addCanvas(key, c);
|
||||
return key;
|
||||
}
|
||||
|
|
@ -0,0 +1,184 @@
|
|||
// Shared casino card sprites: a card is a Container [shadow, face] scaled by its
|
||||
// perspective pose (s, s × squash). Flights, flips and the baccarat squeeze all
|
||||
// animate that container.
|
||||
|
||||
import { VIEW } from './CasinoGeometry.js';
|
||||
import { CARD_W, CARD_H, ensureCardBack } from './CasinoArt.js';
|
||||
|
||||
const SQ = VIEW.squash;
|
||||
const lerp = (a, b, t) => a + (b - a) * t;
|
||||
|
||||
// Deterministic per-card jitter so cards look tossed but don't wobble on relayout.
|
||||
export function jitterFor(key) {
|
||||
let h = 2166136261;
|
||||
for (let i = 0; i < key.length; i++) h = Math.imul(h ^ key.charCodeAt(i), 16777619);
|
||||
const r = (n) => (((h >>> n) & 255) / 255) * 2 - 1;
|
||||
return { rot: r(0) * 0.035, x: r(8) * 2, y: r(16) * 2 };
|
||||
}
|
||||
|
||||
export function withJitter(pose, key) {
|
||||
const j = jitterFor(key);
|
||||
return { ...pose, x: pose.x + j.x, y: pose.y + j.y, rot: pose.rot + j.rot };
|
||||
}
|
||||
|
||||
// The card skin knows which back to show (player's chosen sprite-sheet back, or
|
||||
// a baked fallback in their colour). Call after prepareCasinoArt().
|
||||
export class CardSkin {
|
||||
constructor(scene, cardBack, { depth = 10 } = {}) {
|
||||
this.scene = scene;
|
||||
this.cardBack = cardBack ?? null;
|
||||
this.backKey = ensureCardBack(scene, cardBack?.fallbackColor);
|
||||
this.depth = depth;
|
||||
}
|
||||
|
||||
make(card, faceUp, x, y, s, rot = 0) {
|
||||
const scene = this.scene;
|
||||
const c = scene.add.container(x, y).setDepth(this.depth);
|
||||
const sh = scene.add.image(5, 8, 'casino-card-shadow').setScale(0.5).setAlpha(0.6);
|
||||
const back = scene.add.image(0, 0, this.backKey);
|
||||
c.add([sh, back]);
|
||||
c.shadowImg = sh;
|
||||
c.faceImg = back;
|
||||
c.card = card;
|
||||
this.setFace(c, faceUp);
|
||||
c.setRotation(rot);
|
||||
c.setScale(s, s * SQ);
|
||||
return c;
|
||||
}
|
||||
|
||||
setFace(c, faceUp) {
|
||||
c.faceUp = faceUp;
|
||||
if (faceUp && c.card) {
|
||||
c.faceImg.setTexture('casino-cards', c.card.key).setScale(0.5);
|
||||
} else {
|
||||
this.applyBack(c.faceImg);
|
||||
}
|
||||
}
|
||||
|
||||
applyBack(img) {
|
||||
if (this.cardBack?.spriteIndex !== undefined && this.scene.textures.exists('cardbacks')) {
|
||||
img.setTexture('cardbacks', this.cardBack.spriteIndex).setDisplaySize(CARD_W, CARD_H);
|
||||
} else {
|
||||
img.setTexture(this.backKey).setScale(0.5);
|
||||
}
|
||||
}
|
||||
|
||||
// A card flies from `from` to `pose` with a lift, flipping face-up mid-air if asked.
|
||||
// Resolves with the container once it has landed.
|
||||
deal(card, faceUp, from, pose, { duration = 320, flyingDepth = this.depth + 12, sound } = {}) {
|
||||
const scene = this.scene;
|
||||
const c = this.make(card, false, from.x, from.y, from.s, -0.3);
|
||||
c.setDepth(flyingDepth);
|
||||
c.flying = true;
|
||||
const prox = { t: 0 };
|
||||
let flipped = false;
|
||||
const promise = new Promise(res => {
|
||||
scene.tweens.add({
|
||||
targets: prox, t: 1, duration, ease: 'Cubic.easeOut',
|
||||
onUpdate: () => {
|
||||
const t = prox.t;
|
||||
const lift = Math.sin(Math.PI * t);
|
||||
c.x = lerp(from.x, pose.x, t);
|
||||
c.y = lerp(from.y, pose.y, t) - lift * 22;
|
||||
c.rotation = lerp(-0.3, pose.rot, t);
|
||||
const s = lerp(from.s, pose.s, t) * (1 + 0.09 * lift);
|
||||
let sx = s;
|
||||
if (faceUp) {
|
||||
if (!flipped && t >= 0.5) { flipped = true; this.setFace(c, true); }
|
||||
sx = s * Math.max(0.03, Math.abs(Math.cos(Math.PI * t)));
|
||||
}
|
||||
c.setScale(sx, s * SQ);
|
||||
c.shadowImg.setPosition(5 + lift * 16, 8 + lift * 26).setAlpha(0.6 - lift * 0.3);
|
||||
},
|
||||
onComplete: () => {
|
||||
c.flying = false;
|
||||
c.setDepth(this.depth);
|
||||
if (faceUp && !flipped) this.setFace(c, true);
|
||||
c.setPosition(pose.x, pose.y).setRotation(pose.rot).setScale(pose.s, pose.s * SQ);
|
||||
c.shadowImg.setPosition(5, 8).setAlpha(0.6);
|
||||
if (sound) sound();
|
||||
res(c);
|
||||
},
|
||||
});
|
||||
});
|
||||
return { c, promise };
|
||||
}
|
||||
|
||||
// Flip in place with a small lift.
|
||||
flip(c, faceUp, duration = 300) {
|
||||
const scene = this.scene;
|
||||
const base = { x: c.scaleX, y: c.scaleY, py: c.y };
|
||||
const prox = { t: 0 };
|
||||
let flipped = false;
|
||||
return new Promise(res => {
|
||||
scene.tweens.add({
|
||||
targets: prox, t: 1, duration, ease: 'Sine.easeInOut',
|
||||
onUpdate: () => {
|
||||
const t = prox.t;
|
||||
const lift = Math.sin(Math.PI * t);
|
||||
if (!flipped && t >= 0.5) { flipped = true; this.setFace(c, faceUp); }
|
||||
c.setScale(base.x * Math.max(0.03, Math.abs(Math.cos(Math.PI * t))) * (1 + 0.08 * lift), base.y * (1 + 0.08 * lift));
|
||||
c.y = base.py - lift * 14;
|
||||
c.shadowImg.setPosition(5 + lift * 10, 8 + lift * 18).setAlpha(0.6 - lift * 0.25);
|
||||
},
|
||||
onComplete: () => {
|
||||
if (!flipped) this.setFace(c, faceUp);
|
||||
c.setScale(base.x, base.y);
|
||||
c.y = base.py;
|
||||
c.shadowImg.setPosition(5, 8).setAlpha(0.6);
|
||||
res();
|
||||
},
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Baccarat squeeze: the card lifts and grows a little, then the back peels away
|
||||
// from the bottom edge (face showing underneath) — a slow corner peek, a beat,
|
||||
// then the full peel. A pale "fold" strip rides the peel edge.
|
||||
async peel(c, { lift = 1.32, peekMs = 650, holdMs = 450, peelMs = 700, onPeek } = {}) {
|
||||
const scene = this.scene;
|
||||
const base = { sx: c.scaleX, sy: c.scaleY, y: c.y, depth: c.depth };
|
||||
c.setDepth(base.depth + 20);
|
||||
await new Promise(res => scene.tweens.add({
|
||||
targets: c, scaleX: base.sx * lift, scaleY: base.sy * lift, y: base.y - 18,
|
||||
duration: 220, ease: 'Cubic.easeOut', onComplete: res,
|
||||
}));
|
||||
|
||||
// Face image underneath the back.
|
||||
const face = scene.add.image(0, 0, 'casino-cards', c.card.key).setScale(0.5);
|
||||
c.addAt(face, 1);
|
||||
const back = c.faceImg;
|
||||
const fold = scene.add.rectangle(0, 0, CARD_W, 8, 0xfffbef, 0.9);
|
||||
c.add(fold);
|
||||
const fw = back.frame.realWidth, fh = back.frame.realHeight;
|
||||
const dispH = back.displayHeight;
|
||||
const setPeel = (f) => {
|
||||
// f = fraction of the card uncovered, from the bottom edge up
|
||||
back.setCrop(0, 0, fw, fh * (1 - f));
|
||||
fold.setPosition(0, CARD_H / 2 - f * dispH + 3).setAlpha(f > 0.001 && f < 0.999 ? 0.85 : 0);
|
||||
};
|
||||
setPeel(0);
|
||||
const prox = { f: 0 };
|
||||
await new Promise(res => scene.tweens.add({
|
||||
targets: prox, f: 0.26, duration: peekMs, ease: 'Sine.easeInOut',
|
||||
onUpdate: () => setPeel(prox.f), onComplete: res,
|
||||
}));
|
||||
onPeek?.();
|
||||
await new Promise(res => scene.time.delayedCall(holdMs, res));
|
||||
await new Promise(res => scene.tweens.add({
|
||||
targets: prox, f: 1, duration: peelMs, ease: 'Cubic.easeIn',
|
||||
onUpdate: () => setPeel(prox.f), onComplete: res,
|
||||
}));
|
||||
|
||||
// Swap to the regular single-image face and settle back onto the felt.
|
||||
face.destroy();
|
||||
fold.destroy();
|
||||
back.setCrop();
|
||||
this.setFace(c, true);
|
||||
await new Promise(res => scene.tweens.add({
|
||||
targets: c, scaleX: base.sx, scaleY: base.sy, y: base.y,
|
||||
duration: 240, ease: 'Cubic.easeOut', onComplete: res,
|
||||
}));
|
||||
c.setDepth(base.depth);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,164 @@
|
|||
// Shared casino HUD dock: the leather strip along the bottom with the player's
|
||||
// portrait + balance, the chip tray, a bet pill, a status line and a key legend.
|
||||
// Games add their own buttons into named mode groups and switch with setMode().
|
||||
|
||||
import * as Phaser from 'phaser';
|
||||
import { COLORS } from '../../config.js';
|
||||
import { createPlayerPortrait } from '../Portrait.js';
|
||||
import { makeChip } from '../CasinoChips.js';
|
||||
import { DOCK } from './CasinoGeometry.js';
|
||||
|
||||
export class CasinoDock {
|
||||
constructor(scene, {
|
||||
sceneName,
|
||||
portrait = { x: 160, y: 1013, r: 50 },
|
||||
depth = { dock: 26, ui: 30, dockUi: 32, prompt: 38 },
|
||||
chipAmounts = [5, 25, 50, 100],
|
||||
chipX0 = 470, chipDX = 88, chipSize = 74,
|
||||
betPillX = 850,
|
||||
keys = {},
|
||||
canChip = () => true,
|
||||
onChip = () => {},
|
||||
}) {
|
||||
this.scene = scene;
|
||||
this.depth = depth;
|
||||
this.keys = keys;
|
||||
this.y = DOCK.y + DOCK.h / 2;
|
||||
this.groups = {};
|
||||
this.transient = [];
|
||||
this.mode = null;
|
||||
this.promptGroup = [];
|
||||
this.promptTimer = null;
|
||||
this.pulseTweens = [];
|
||||
const y = this.y;
|
||||
|
||||
this.bg = scene.add.image(0, DOCK.y, 'casino-dock').setOrigin(0, 0).setDepth(depth.dock);
|
||||
|
||||
this.portrait = createPlayerPortrait(scene, portrait.x, portrait.y, portrait.r, depth.ui, sceneName);
|
||||
this.portraitPos = portrait;
|
||||
this.nameTxt = scene.add.text(portrait.x + portrait.r + 22, y - 18, 'You', {
|
||||
fontFamily: '"Julius Sans One"', fontSize: '20px', color: COLORS.textHex,
|
||||
}).setOrigin(0, 0.5).setDepth(depth.dockUi);
|
||||
this.balanceTxt = scene.add.text(portrait.x + portrait.r + 22, y + 14, '', {
|
||||
fontFamily: '"Julius Sans One"', fontSize: '24px', color: COLORS.goldHex, fontStyle: 'bold',
|
||||
}).setOrigin(0, 0.5).setDepth(depth.dockUi);
|
||||
|
||||
// Chip tray — Images (not Containers) so the circular hit area is in texture space.
|
||||
this.chipBtns = chipAmounts.map((amt, i) => {
|
||||
const x = chipX0 + i * chipDX;
|
||||
const sh = scene.add.ellipse(x + 3, y + 6, chipSize, chipSize, 0x000000, 0.5).setDepth(depth.dockUi);
|
||||
const img = makeChip(scene, x, y, amt, { size: chipSize, depth: depth.dockUi + 1 });
|
||||
img.baseScale = img.scaleX;
|
||||
img._dockReenable = true;
|
||||
img.setInteractive({
|
||||
hitArea: new Phaser.Geom.Circle(64, 64, 62),
|
||||
hitAreaCallback: Phaser.Geom.Circle.Contains,
|
||||
useHandCursor: true,
|
||||
});
|
||||
img.on('pointerover', () => { if (canChip(amt)) scene.tweens.add({ targets: img, y: y - 8, duration: 110 }); });
|
||||
img.on('pointerout', () => scene.tweens.add({ targets: img, y, duration: 110 }));
|
||||
img.on('pointerdown', () => onChip(amt));
|
||||
return { amt, img, sh };
|
||||
});
|
||||
this.chipCenterX = chipX0 + (chipAmounts.length - 1) * chipDX / 2;
|
||||
|
||||
this.betPill = scene.add.text(betPillX, y, '', {
|
||||
fontFamily: '"Julius Sans One"', fontSize: '24px', color: COLORS.textHex,
|
||||
}).setOrigin(0, 0.5).setDepth(depth.dockUi);
|
||||
|
||||
this.addToGroup('bet', ...this.chipBtns.flatMap(c => [c.sh, c.img]), this.betPill);
|
||||
|
||||
this.statusTxt = scene.add.text(scene.scale.width / 2, y, '', {
|
||||
fontFamily: '"Julius Sans One"', fontSize: '24px', color: COLORS.mutedHex,
|
||||
}).setOrigin(0.5).setDepth(depth.dockUi);
|
||||
this.keysTxt = scene.add.text(scene.scale.width / 2, DOCK.y + DOCK.h - 12, '', {
|
||||
fontFamily: '"Julius Sans One"', fontSize: '13px', color: COLORS.mutedHex,
|
||||
}).setOrigin(0.5).setDepth(depth.dockUi).setAlpha(0.8);
|
||||
}
|
||||
|
||||
chipButton(denom) { return this.chipBtns.find(c => c.amt === denom); }
|
||||
|
||||
// Where chips come from / return to for the human.
|
||||
sourcePos() { return { x: this.balanceTxt.x + 40, y: this.balanceTxt.y, s: 1 }; }
|
||||
|
||||
addToGroup(mode, ...objs) {
|
||||
(this.groups[mode] ??= []).push(...objs);
|
||||
for (const o of objs) {
|
||||
const show = this.mode === mode;
|
||||
o.setVisible(show);
|
||||
if (!show) o.disableInteractive?.();
|
||||
}
|
||||
}
|
||||
|
||||
addTransient(...objs) { this.transient.push(...objs); }
|
||||
|
||||
clearTransient() {
|
||||
for (const o of this.transient) {
|
||||
this.scene.tweens.killTweensOf(o);
|
||||
o.destroy();
|
||||
}
|
||||
this.transient = [];
|
||||
}
|
||||
|
||||
// Show `mode`'s group, hide the rest, clear transient widgets, set the status
|
||||
// line (wait-style modes) and the key legend.
|
||||
setMode(mode, status = '') {
|
||||
this.mode = mode;
|
||||
this.clearTransient();
|
||||
for (const [key, objs] of Object.entries(this.groups)) {
|
||||
const show = key === mode;
|
||||
for (const o of objs) {
|
||||
o.setVisible(show);
|
||||
if (!show) o.disableInteractive?.();
|
||||
else if (o._dockReenable) o.setInteractive();
|
||||
}
|
||||
}
|
||||
if (mode !== 'bet') this.hidePrompts();
|
||||
this.statusTxt.setText(status);
|
||||
this.keysTxt.setText(this.keys[mode] ?? '');
|
||||
}
|
||||
|
||||
setChipStates(affordable) {
|
||||
for (const c of this.chipBtns) c.img.setAlpha(affordable(c.amt) ? 1 : 0.35);
|
||||
}
|
||||
|
||||
// After 5s with no bet, pulse the chips and show a hint above the dock.
|
||||
startPrompts(message, stillIdle) {
|
||||
this.hidePrompts();
|
||||
this.promptTimer = this.scene.time.delayedCall(5000, () => {
|
||||
if (this.mode !== 'bet' || !stillIdle()) return;
|
||||
this.chipBtns.forEach((c, index) => {
|
||||
this.pulseTweens.push(this.scene.tweens.add({
|
||||
targets: c.img, scale: c.img.baseScale * 1.14,
|
||||
duration: 1100, ease: 'Sine.easeInOut', yoyo: true, repeat: -1, delay: index * 180,
|
||||
}));
|
||||
});
|
||||
const scene = this.scene;
|
||||
const cx = scene.scale.width / 2, y = DOCK.y - 34;
|
||||
const msg = typeof message === 'function' ? message() : message;
|
||||
const text = scene.add.text(cx, y, msg, {
|
||||
fontFamily: '"Julius Sans One"', fontSize: '18px', color: '#ffffff',
|
||||
}).setOrigin(0.5).setDepth(this.depth.prompt + 1).setAlpha(0);
|
||||
const bg = scene.add.rectangle(cx, y, text.width + 48, 46, 0x000000, 0.75)
|
||||
.setDepth(this.depth.prompt).setAlpha(0);
|
||||
this.promptGroup = [bg, text];
|
||||
scene.tweens.add({ targets: this.promptGroup, alpha: 1, duration: 300, ease: 'Power2' });
|
||||
});
|
||||
}
|
||||
|
||||
hidePrompts() {
|
||||
const group = this.promptGroup;
|
||||
this.promptGroup = [];
|
||||
if (group.length) {
|
||||
this.scene.tweens.add({
|
||||
targets: group, alpha: 0, duration: 200, ease: 'Power2',
|
||||
onComplete: () => group.forEach(o => o.destroy()),
|
||||
});
|
||||
}
|
||||
this.pulseTweens.forEach(t => t.remove());
|
||||
this.pulseTweens = [];
|
||||
this.chipBtns.forEach(c => c.img.setScale(c.img.baseScale));
|
||||
this.promptTimer?.remove();
|
||||
this.promptTimer = null;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,122 @@
|
|||
// Shared casino-table geometry — Phaser-free so verify scripts can import it.
|
||||
//
|
||||
// Every half-moon casino table (Blackjack, Baccarat, Pai Gow) uses the SAME
|
||||
// perspective: things on the felt are described in flat "table space" and
|
||||
// pushed through project(). The dealer's straight edge is far away (small,
|
||||
// narrow), the curved player rail near (large, wide). Cards, chips, betting
|
||||
// spots and felt lettering all take their screen position AND scale from it.
|
||||
//
|
||||
// Table space: the felt is the half-disc u² + v² ≤ 1, v ≥ 0.
|
||||
// u = left/right (−1 … +1), +u is screen-right
|
||||
// v = depth from the dealer's straight edge (0) toward the players (1)
|
||||
// polar(r, θ): θ = 0 points straight at the bottom-centre seat, +θ swings
|
||||
// toward screen-right.
|
||||
|
||||
export const VIEW = {
|
||||
cx: 960,
|
||||
yFar: 168, // screen y of the dealer's straight edge (v = 0)
|
||||
yNear: 800, // screen y of the felt's nearest point (v = 1)
|
||||
sFar: 0.70, // scale at the dealer edge (1.0 at the near point)
|
||||
halfW: 905, // half-width in px of the unit circle at scale 1
|
||||
squash: 0.9, // extra vertical squash for things lying flat on the felt
|
||||
};
|
||||
|
||||
const A = 1 / VIEW.sFar - 1;
|
||||
const K = (VIEW.yNear - VIEW.yFar) / (1 - VIEW.sFar);
|
||||
const Y_HORIZON = VIEW.yFar - VIEW.sFar * K;
|
||||
const RAD = Math.PI / 180;
|
||||
|
||||
export function depthScale(v) {
|
||||
return 1 / (1 + A * (1 - v));
|
||||
}
|
||||
|
||||
export function project(u, v) {
|
||||
const s = depthScale(v);
|
||||
return { x: VIEW.cx + u * VIEW.halfW * s, y: Y_HORIZON + K * s, s };
|
||||
}
|
||||
|
||||
export function polar(r, thetaDeg) {
|
||||
const t = thetaDeg * RAD;
|
||||
return project(r * Math.sin(t), r * Math.cos(t));
|
||||
}
|
||||
|
||||
// Inverse of project() for a screen point.
|
||||
export function unproject(x, y) {
|
||||
const s = (y - Y_HORIZON) / K;
|
||||
const v = 1 - (1 / s - 1) / A;
|
||||
const u = (x - VIEW.cx) / (VIEW.halfW * s);
|
||||
return { u, v, s };
|
||||
}
|
||||
|
||||
// Screen point → table-space polar (r, θ in degrees). Used for felt hit-testing.
|
||||
export function toPolar(x, y) {
|
||||
const { u, v } = unproject(x, y);
|
||||
return { r: Math.hypot(u, v), theta: Math.atan2(u, v) / RAD, u, v };
|
||||
}
|
||||
|
||||
// Screen-space angle (radians, Phaser convention: +ve = clockwise) of the arc of
|
||||
// radius r at θ, travelling toward +θ. Used to rotate felt lettering.
|
||||
export function arcTangent(r, thetaDeg) {
|
||||
const a = polar(r, thetaDeg - 0.25);
|
||||
const b = polar(r, thetaDeg + 0.25);
|
||||
return Math.atan2(b.y - a.y, b.x - a.x);
|
||||
}
|
||||
|
||||
// Screen rotation that turns a card's bottom edge toward a seat at θ (radius r),
|
||||
// damped so outer seats don't spin a full 90°.
|
||||
export function radialRotation(r, thetaDeg, damp = 0.62) {
|
||||
const a = polar(r, thetaDeg);
|
||||
const b = polar(r + 0.05, thetaDeg);
|
||||
return Math.atan2(-(b.x - a.x), b.y - a.y) * damp;
|
||||
}
|
||||
|
||||
// ── Rail / outline ───────────────────────────────────────────────────────────
|
||||
export const FELT_R = 0.985; // felt ends here, wood lip to 1.0
|
||||
export const RAIL_IN = 1.0;
|
||||
export const RAIL_OUT = 1.105;
|
||||
export const RAIL_FACE_PX = 34; // visible thickness of the rail's front face at s = 1
|
||||
|
||||
// Points along an arc of radius r from θ0 to θ1 (default the whole half-moon, left → right).
|
||||
export function arcPoints(r, steps = 120, th0 = -90, th1 = 90) {
|
||||
const pts = [];
|
||||
for (let i = 0; i <= steps; i++) pts.push(polar(r, th0 + ((th1 - th0) * i) / steps));
|
||||
return pts;
|
||||
}
|
||||
|
||||
// Projected outline of a flat circle on the felt (bet circles, chip shadows).
|
||||
export function feltCircle(u, v, radius, steps = 48) {
|
||||
const pts = [];
|
||||
for (let i = 0; i < steps; i++) {
|
||||
const a = (i / steps) * Math.PI * 2;
|
||||
pts.push(project(u + Math.cos(a) * radius, v + Math.sin(a) * radius));
|
||||
}
|
||||
return pts;
|
||||
}
|
||||
|
||||
// Projected outline of an annular sector (a curved betting box) r0…r1, θ0…θ1.
|
||||
export function feltSector(r0, r1, th0, th1, steps = 24) {
|
||||
return [...arcPoints(r1, steps, th0, th1), ...arcPoints(r0, steps, th0, th1).reverse()];
|
||||
}
|
||||
|
||||
// Projected outline of a flat rectangle centred at (u, v) with table-space size (w, h).
|
||||
export function feltRect(u, v, w, h) {
|
||||
return [
|
||||
project(u - w / 2, v - h / 2), project(u + w / 2, v - h / 2),
|
||||
project(u + w / 2, v + h / 2), project(u - w / 2, v + h / 2),
|
||||
];
|
||||
}
|
||||
|
||||
export function onFelt(u, v) {
|
||||
return v >= 0 && u * u + v * v <= FELT_R * FELT_R;
|
||||
}
|
||||
|
||||
export function screenOnFelt(pt) {
|
||||
const { u, v } = unproject(pt.x, pt.y);
|
||||
return onFelt(u, v);
|
||||
}
|
||||
|
||||
// ── Shared furniture spots (games may override) ──────────────────────────────
|
||||
export const TRAY = { u0: -0.26, u1: 0.26, v0: 0.012, v1: 0.078 };
|
||||
|
||||
// ── HUD dock ─────────────────────────────────────────────────────────────────
|
||||
export const DOCK = { y: 948, h: 132 }; // top edge + height (to the bottom of the 1080 canvas)
|
||||
|
|
@ -0,0 +1,169 @@
|
|||
#!/usr/bin/env node
|
||||
// verifyBaccarat.js — headless checks for the Baccarat table layout, felt
|
||||
// hit-testing, payouts as chip stacks, and the scoreboard roads.
|
||||
|
||||
import { readFileSync } from 'node:fs';
|
||||
import { BET, betPayout } from '../src/games/baccarat/BaccaratLogic.js';
|
||||
import {
|
||||
VIEW, unproject, onFelt, SEAT_ANGLES, DISPLAY_ORDER, BANDS, BET_TYPES, BOX_HALF_DEG,
|
||||
boxCenter, boxOutline, hitBox, seatPortrait, handCenter, handCardPose, handBoxRect,
|
||||
SHOE, DISCARD, PLACARD, TRAY, DOCK, READOUT, BOARD, boardSize, FELT_TEXT, polar, project,
|
||||
FELT_R, CARD_W, CARD_H, TOTAL_BADGE_DY,
|
||||
} from '../src/games/baccarat/BaccaratTable.js';
|
||||
import { counts, beadPlate, bigRoad, bigRoadWindow } from '../src/games/baccarat/BaccaratRoads.js';
|
||||
import { breakdown } from '../src/ui/CasinoChips.js';
|
||||
|
||||
let pass = 0, fail = 0;
|
||||
function ok(label, cond, detail = '') {
|
||||
if (cond) pass++;
|
||||
else { console.error(` ✗ ${label}${detail ? ` — ${detail}` : ''}`); fail++; }
|
||||
}
|
||||
const section = (n) => console.log(`\n${n}`);
|
||||
const onFeltPt = (p) => { const q = unproject(p.x, p.y); return onFelt(q.u, q.v); };
|
||||
const sum = (a) => a.reduce((x, y) => x + y, 0);
|
||||
const inRect = (p, r) => p.x > r.x - r.w / 2 && p.x < r.x + r.w / 2 && p.y > r.y - r.h / 2 && p.y < r.y + r.h / 2;
|
||||
|
||||
// ── Payouts → chips ──────────────────────────────────────────────────────────
|
||||
section('Payouts');
|
||||
for (let bet = 5; bet <= 500; bet += 5) {
|
||||
for (const outcome of ['player', 'banker', 'tie']) {
|
||||
for (const type of BET_TYPES) {
|
||||
const net = betPayout(type, bet, outcome);
|
||||
if (net > 0) {
|
||||
ok(`$${bet} ${type} on ${outcome}: payout stack sums`, sum(breakdown(net)) === net);
|
||||
if (type === BET.BANKER) {
|
||||
const commission = bet - net;
|
||||
ok(`$${bet} banker: commission is 5% floored`, commission === Math.floor(bet * 0.05));
|
||||
ok(`$${bet} banker: gross stack = bet`, sum(breakdown(net + commission)) === bet);
|
||||
}
|
||||
if (type === BET.TIE) ok(`$${bet} tie pays 8:1`, net === bet * 8);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ok('player/banker push on a tie', betPayout(BET.PLAYER, 25, 'tie') === 0 && betPayout(BET.BANKER, 25, 'tie') === 0);
|
||||
|
||||
// ── Betting boxes ────────────────────────────────────────────────────────────
|
||||
section('Betting boxes');
|
||||
ok('7 seats', SEAT_ANGLES.length === 7);
|
||||
ok('display order covers every seat once', [...DISPLAY_ORDER].sort().join() === '0,1,2,3,4,5,6');
|
||||
const sorted = [...SEAT_ANGLES].sort((a, b) => a - b);
|
||||
ok('neighbouring seats\' boxes don\'t overlap',
|
||||
sorted.every((a, i) => i === 0 || a - sorted[i - 1] > 2 * BOX_HALF_DEG), sorted.join(','));
|
||||
ok('bands are disjoint, PLAYER outermost',
|
||||
BANDS.player.r0 > BANDS.banker.r1 && BANDS.banker.r0 > BANDS.tie.r1);
|
||||
ok('PLAYER band inside the felt', BANDS.player.r1 < FELT_R);
|
||||
for (let seat = 0; seat < 7; seat++) {
|
||||
for (const type of BET_TYPES) {
|
||||
const c = boxCenter(seat, type);
|
||||
const hit = hitBox(c.x, c.y);
|
||||
ok(`seat ${seat} ${type}: centre hit-tests to itself`, hit && hit.seat === seat && hit.type === type, JSON.stringify(hit));
|
||||
ok(`seat ${seat} ${type}: outline on the felt`, boxOutline(seat, type).every(onFeltPt));
|
||||
const inner = boxOutline(seat, type, 0.01);
|
||||
ok(`seat ${seat} ${type}: inset outline hit-tests to itself`,
|
||||
inner.every(p => { const h = hitBox(p.x, p.y); return h && h.seat === seat && h.type === type; }));
|
||||
ok(`seat ${seat} ${type}: stack well above the dock`, c.y + 40 < DOCK.y);
|
||||
}
|
||||
}
|
||||
ok('gap between bands hits nothing', hitBox(polar((BANDS.banker.r1 + BANDS.player.r0) / 2, 0).x, polar((BANDS.banker.r1 + BANDS.player.r0) / 2, 0).y) === null);
|
||||
ok('between seats hits nothing', hitBox(polar(0.9, 12.5).x, polar(0.9, 12.5).y) === null);
|
||||
ok('the dealer row hits nothing', hitBox(handCenter('player').x, handCenter('player').y) === null);
|
||||
ok('off the felt hits nothing', hitBox(960, 1050) === null && hitBox(960, 100) === null);
|
||||
|
||||
// ── Dealer side ──────────────────────────────────────────────────────────────
|
||||
section('Dealer side');
|
||||
const halfCard = (p, sideways) => sideways
|
||||
? { w: (CARD_H / 2) * p.s, h: (CARD_W / 2) * p.s * VIEW.squash }
|
||||
: { w: (CARD_W / 2) * p.s, h: (CARD_H / 2) * p.s * VIEW.squash };
|
||||
for (const side of ['player', 'banker']) {
|
||||
for (let i = 0; i < 3; i++) ok(`${side} card ${i} on the felt`, onFeltPt(handCardPose(side, i)));
|
||||
const third = handCardPose(side, 2), hc = halfCard(third, true);
|
||||
const shoe = project(SHOE.u, SHOE.v), disc = project(DISCARD.u, DISCARD.v);
|
||||
const furn = side === 'player' ? disc : shoe;
|
||||
ok(`${side} third card clear of the ${side === 'player' ? 'discard' : 'shoe'}`, third.y - hc.h > furn.y + 40 * furn.s,
|
||||
`card top ${(third.y - hc.h).toFixed(0)} furniture bottom ${(furn.y + 40 * furn.s).toFixed(0)}`);
|
||||
const first = handCardPose(side, 0), h1 = halfCard(first, false);
|
||||
ok(`${side} cards clear of the chip tray`, first.y - h1.h > project(0, TRAY.v1).y);
|
||||
const box = handBoxRect(side);
|
||||
ok(`${side} box doesn't overlap the readout`, box.y + box.h / 2 < READOUT.y - READOUT.h / 2 + 4);
|
||||
const badgeY = handCenter(side).y + TOTAL_BADGE_DY * handCenter(side).s;
|
||||
ok(`${side} total badge between box and readout`, badgeY > box.y + box.h / 2 && badgeY + 17 < READOUT.y - READOUT.h / 2 + 18,
|
||||
`badge ${badgeY.toFixed(0)}`);
|
||||
for (let seat = 0; seat < 7; seat++) {
|
||||
ok(`${side} third card clear of seat ${seat}'s boxes`,
|
||||
BET_TYPES.every(t => boxOutline(seat, t).every(p => Math.abs(p.x - third.x) > hc.w || Math.abs(p.y - third.y) > hc.h)));
|
||||
}
|
||||
}
|
||||
ok('the hands sit either side of centre', handCenter('player').x < 960 && handCenter('banker').x > 960);
|
||||
for (let seat = 0; seat < 7; seat++) {
|
||||
ok(`readout clear of seat ${seat}'s boxes`, BET_TYPES.every(t => !boxOutline(seat, t).some(p => inRect(p, READOUT))));
|
||||
}
|
||||
ok('felt lettering clear of every box', FELT_TEXT.every(t => t.r < BANDS.tie.r0 - 0.03));
|
||||
ok('placard / shoe / discard on the felt', [SHOE, DISCARD, PLACARD].every(p => onFelt(p.u, p.v)));
|
||||
|
||||
// ── Portraits / scoreboard ───────────────────────────────────────────────────
|
||||
section('Portraits + scoreboard');
|
||||
for (let seat = 1; seat < 7; seat++) {
|
||||
const pt = seatPortrait(seat);
|
||||
ok(`seat ${seat}: portrait + labels clear of the dock`, pt.y + pt.r + 60 < DOCK.y);
|
||||
const q = unproject(pt.x, pt.y);
|
||||
ok(`seat ${seat}: portrait off the felt`, Math.hypot(q.u, q.v) > FELT_R);
|
||||
}
|
||||
const { w: bw, h: bh } = boardSize();
|
||||
ok('scoreboard on screen', BOARD.x + bw <= 1910 && BOARD.y >= 0);
|
||||
ok('scoreboard clear of the title', BOARD.x > 960 + 160);
|
||||
ok('scoreboard above the shoe and the dealer edge', BOARD.y + bh < project(SHOE.u, SHOE.v).y - 20 && BOARD.y + bh < VIEW.yFar + 8);
|
||||
ok('scoreboard clear of the top-right portrait', BOARD.y + bh < seatPortrait(5).y - seatPortrait(5).r);
|
||||
|
||||
// ── Roads ────────────────────────────────────────────────────────────────────
|
||||
section('Roads');
|
||||
const P = 'player', B = 'banker', T = 'tie';
|
||||
ok('counts', JSON.stringify(counts([P, B, B, T])) === JSON.stringify({ player: 1, banker: 2, tie: 1 }));
|
||||
{
|
||||
const bp = beadPlate(Array(7).fill(P));
|
||||
ok('bead plate fills columns top-down', bp[5].col === 0 && bp[5].row === 5 && bp[6].col === 1 && bp[6].row === 0);
|
||||
const long = beadPlate(Array.from({ length: 75 }, (_, i) => (i % 2 ? P : B)), 6, 10);
|
||||
ok('bead plate keeps the last whole columns', long.length <= 60 && long.every(c => c.col < 10) && long[long.length - 1].outcome === B);
|
||||
ok('bead plate drops whole columns', long[0].row === 0);
|
||||
}
|
||||
{
|
||||
const r = bigRoad([B, B, B, P, P, B]);
|
||||
ok('big road: streak goes down', r[0].col === 0 && r[2].row === 2 && r[2].col === 0);
|
||||
ok('big road: new winner → next column, top row', r[3].col === 1 && r[3].row === 0 && r[4].row === 1);
|
||||
ok('big road: third streak starts in column 2', r[5].col === 2 && r[5].row === 0);
|
||||
}
|
||||
{
|
||||
const r = bigRoad([P, T, T, B]);
|
||||
ok('big road: ties mark the last cell instead of taking one', r.length === 2 && r[0].ties === 2 && r[1].ties === 0);
|
||||
const lead = bigRoad([T, P]);
|
||||
ok('big road: leading ties attach to the first cell', lead.length === 1 && lead[0].ties === 1);
|
||||
}
|
||||
{
|
||||
const r = bigRoad(Array(9).fill(B));
|
||||
ok('big road: dragon tail turns right at the bottom row', r[5].row === 5 && r[6].col === 1 && r[6].row === 5 && r[8].col === 3);
|
||||
const after = bigRoad([...Array(9).fill(B), P]);
|
||||
ok('big road: next streak starts after the tail\'s first column', after[9].col === 1 && after[9].row === 0);
|
||||
const blocked = bigRoad([...Array(8).fill(B), ...Array(7).fill(P)]);
|
||||
const pCells = blocked.filter(c => c.outcome === P);
|
||||
ok('big road: a streak blocked by an earlier tail turns right early',
|
||||
pCells[0].col === 1 && pCells[4].row === 4 && pCells[5].row === 4 && pCells[5].col === 2);
|
||||
const keys = new Set(blocked.map(c => `${c.col},${c.row}`));
|
||||
ok('big road: no two cells share a spot', keys.size === blocked.length);
|
||||
}
|
||||
{
|
||||
const hist = Array.from({ length: 80 }, (_, i) => (i % 3 === 0 ? P : B));
|
||||
const win = bigRoadWindow(hist, 6, 18);
|
||||
ok('big road window fits 18 columns', win.every(c => c.col >= 0 && c.col < 18));
|
||||
ok('big road window ends on the latest coup', win[win.length - 1].outcome === hist[hist.length - 1]);
|
||||
}
|
||||
|
||||
// ── Source lint ──────────────────────────────────────────────────────────────
|
||||
section('Source lint');
|
||||
const src = readFileSync(new URL('../src/games/baccarat/BaccaratGame.js', import.meta.url), 'utf8');
|
||||
ok('no hand-built Rectangle hit areas', !/new Phaser\.Geom\.Rectangle\(/.test(src));
|
||||
ok('no setInteractive on containers', !/add\.container\([^)]*\)[^;]*setInteractive/.test(src));
|
||||
ok('felt clicks go through hitBox', /hitBox\(p\.worldX, p\.worldY\)/.test(src));
|
||||
ok('uses the shared dock + card skin', /new CasinoDock\(/.test(src) && /new CardSkin\(/.test(src));
|
||||
|
||||
console.log(`\n${pass} passed, ${fail} failed`);
|
||||
process.exit(fail ? 1 : 0);
|
||||
|
|
@ -0,0 +1,163 @@
|
|||
#!/usr/bin/env node
|
||||
// verifyBlackjack.js — headless checks for the Blackjack table geometry and chip maths.
|
||||
// The art/scene code needs a browser; this covers the pure parts it is built on.
|
||||
|
||||
import { readFileSync } from 'node:fs';
|
||||
import {
|
||||
VIEW, project, unproject, depthScale, polar, onFelt, seatLayout, cardPose, dealerCardPose,
|
||||
betPose, badgePose, insurancePose, SEAT_ANGLES, PLAY_ORDER, RAIL_OUT, RAIL_FACE_PX, FELT_R,
|
||||
BET_SPOT_R, INSURANCE_LINES, FELT_TEXT, TRAY, SHOE, DISCARD, PLACARD, DOCK, DEALER_V,
|
||||
} from '../src/games/blackjack/BlackjackTable.js';
|
||||
import { breakdown, DENOMS, CHIP_DEFS } from '../src/ui/CasinoChips.js';
|
||||
|
||||
let pass = 0, fail = 0;
|
||||
function ok(label, cond, detail = '') {
|
||||
if (cond) { pass++; }
|
||||
else { console.error(` ✗ ${label}${detail ? ` — ${detail}` : ''}`); fail++; }
|
||||
}
|
||||
function section(name) { console.log(`\n${name}`); }
|
||||
|
||||
const CARD_W = 96, CARD_H = 134;
|
||||
const dist = (a, b) => Math.hypot(a.x - b.x, a.y - b.y);
|
||||
const feltR = (pt) => { const { u, v } = unproject(pt.x, pt.y); return Math.hypot(u, v); };
|
||||
const isOnFelt = (pt) => { const { u, v } = unproject(pt.x, pt.y); return onFelt(u, v); };
|
||||
|
||||
// ── Chips ────────────────────────────────────────────────────────────────────
|
||||
section('Chip breakdown');
|
||||
for (let amt = 0; amt <= 400; amt++) {
|
||||
const b = breakdown(amt);
|
||||
ok(`breakdown(${amt}) sums`, b.reduce((a, d) => a + d, 0) === amt);
|
||||
ok(`breakdown(${amt}) uses known denoms`, b.every(d => DENOMS.includes(d)));
|
||||
ok(`breakdown(${amt}) is largest-first`, b.every((d, i) => i === 0 || b[i - 1] >= d));
|
||||
}
|
||||
// Every amount the game can put on the felt: bets 5–100 (AI 10/15 too),
|
||||
// doubles/splits up to 200, 3:2 payouts (floored), insurance (floor bet/2) and its 2:1 pay.
|
||||
const amounts = new Set();
|
||||
for (let bet = 5; bet <= 100; bet += 5) {
|
||||
amounts.add(bet); amounts.add(bet * 2); amounts.add(Math.floor(bet * 1.5));
|
||||
amounts.add(Math.floor(bet / 2)); amounts.add(Math.floor(bet / 2) * 2);
|
||||
}
|
||||
for (const a of amounts) ok(`game amount ${a} representable`, breakdown(a).reduce((x, d) => x + d, 0) === a);
|
||||
ok('every denom has a colour definition', DENOMS.every(d => CHIP_DEFS[d]?.base && CHIP_DEFS[d]?.insert));
|
||||
ok('largest game stack fits the 14-chip cap', Math.max(...[...amounts].map(a => breakdown(a).length)) <= 14,
|
||||
`max ${Math.max(...[...amounts].map(a => breakdown(a).length))}`);
|
||||
|
||||
// ── Projection ───────────────────────────────────────────────────────────────
|
||||
section('Projection');
|
||||
let prev = null;
|
||||
for (let v = -0.05; v <= 1.15; v += 0.01) {
|
||||
const p = project(0, v);
|
||||
if (prev) {
|
||||
ok(`scale grows toward the player (v=${v.toFixed(2)})`, p.s > prev.s);
|
||||
ok(`screen y grows toward the player (v=${v.toFixed(2)})`, p.y > prev.y);
|
||||
}
|
||||
prev = p;
|
||||
}
|
||||
ok('far edge at yFar', Math.abs(project(0, 0).y - VIEW.yFar) < 1e-6);
|
||||
ok('near point at yNear', Math.abs(project(0, 1).y - VIEW.yNear) < 1e-6);
|
||||
ok('scale 1 at the near point', Math.abs(depthScale(1) - 1) < 1e-9);
|
||||
for (const [u, v] of [[0, 0.3], [0.7, 0.2], [-0.5, 0.8], [0.9, 0.05]]) {
|
||||
const p = project(u, v), q = unproject(p.x, p.y);
|
||||
ok(`unproject round-trips (${u},${v})`, Math.abs(q.u - u) < 1e-9 && Math.abs(q.v - v) < 1e-9);
|
||||
}
|
||||
ok('table is symmetric', Math.abs(project(0.6, 0.4).x - VIEW.cx - (VIEW.cx - project(-0.6, 0.4).x)) < 1e-9);
|
||||
|
||||
// ── Seats ────────────────────────────────────────────────────────────────────
|
||||
section('Seat layout');
|
||||
ok('7 seats', SEAT_ANGLES.length === 7);
|
||||
ok('play order covers every seat once', [...PLAY_ORDER].sort().join() === '0,1,2,3,4,5,6');
|
||||
ok('seat 0 is bottom-centre', SEAT_ANGLES[0] === 0);
|
||||
ok('play order starts at screen-right (first base)', SEAT_ANGLES[PLAY_ORDER[0]] > 0);
|
||||
|
||||
// Approximate a hand of n cards by a bounding circle.
|
||||
function handRadius(seat, n, split = false) {
|
||||
const { s } = seatLayout(seat).card;
|
||||
const card = 0.5 * Math.hypot(CARD_W, CARD_H * VIEW.squash) * s;
|
||||
if (!split) return card + 0.5 * (n - 1) * 28 * s;
|
||||
return card + 0.74 * CARD_W * s + 0.5 * (n - 1) * 28 * s;
|
||||
}
|
||||
|
||||
for (let seat = 0; seat < 7; seat++) {
|
||||
const L = seatLayout(seat);
|
||||
ok(`seat ${seat}: card spot on felt`, isOnFelt(L.card));
|
||||
ok(`seat ${seat}: bet spot on felt`, isOnFelt(L.bet));
|
||||
ok(`seat ${seat}: badge on felt`, isOnFelt(L.badge));
|
||||
ok(`seat ${seat}: split bets on felt`, isOnFelt(betPose(seat, 0)) && isOnFelt(betPose(seat, 1)));
|
||||
ok(`seat ${seat}: split badges on felt`, isOnFelt(badgePose(seat, 0)) && isOnFelt(badgePose(seat, 1)));
|
||||
ok(`seat ${seat}: insurance spot on felt`, isOnFelt(insurancePose(seat)));
|
||||
ok(`seat ${seat}: bet circle clear of the rail`, feltR(L.bet) + BET_SPOT_R < FELT_R);
|
||||
ok(`seat ${seat}: bet circle nearer the player than the cards`, L.bet.s > L.card.s);
|
||||
const p5 = cardPose(seat, 4, 5), p0 = cardPose(seat, 0, 5);
|
||||
ok(`seat ${seat}: a 5-card hand stays on the felt`, isOnFelt(p5) && isOnFelt(p0));
|
||||
for (let other = seat + 1; other < 7; other++) {
|
||||
const O = seatLayout(other);
|
||||
const d = dist(L.card, O.card);
|
||||
ok(`seats ${seat}/${other}: 3-card hands don't overlap`, d > handRadius(seat, 3) + handRadius(other, 3) - 50,
|
||||
`d=${d.toFixed(0)}`);
|
||||
ok(`seats ${seat}/${other}: bet circles apart`, dist(L.bet, O.bet) > 110, dist(L.bet, O.bet).toFixed(0));
|
||||
}
|
||||
}
|
||||
|
||||
section('Portraits');
|
||||
for (let seat = 0; seat < 7; seat++) {
|
||||
const pt = seatLayout(seat).portrait;
|
||||
ok(`seat ${seat}: portrait on screen`, pt.x - pt.r >= 0 && pt.x + pt.r <= 1920 && pt.y - pt.r >= 0 && pt.y + pt.r <= 1080);
|
||||
if (seat === 0) {
|
||||
ok('human portrait sits in the dock', pt.y - pt.r >= DOCK.y - 4);
|
||||
} else {
|
||||
ok(`seat ${seat}: portrait + labels clear of the dock`, pt.y + pt.r + 18 + 24 + 18 < DOCK.y);
|
||||
ok(`seat ${seat}: portrait off the felt`, !isOnFelt({ x: pt.x, y: pt.y }) && feltR(pt) > FELT_R);
|
||||
}
|
||||
for (let other = seat + 1; other < 7; other++) {
|
||||
const q = seatLayout(other).portrait;
|
||||
ok(`portraits ${seat}/${other} don't overlap`, dist(pt, q) > pt.r + q.r + 20);
|
||||
}
|
||||
}
|
||||
|
||||
// ── Dealer side ──────────────────────────────────────────────────────────────
|
||||
section('Dealer side');
|
||||
const dealer2 = dealerCardPose(0, 2);
|
||||
const dealerTop = dealer2.y - (CARD_H * dealer2.s * VIEW.squash) / 2;
|
||||
const dealerBottom = dealer2.y + (CARD_H * dealer2.s * VIEW.squash) / 2;
|
||||
ok('dealer cards clear the chip tray', dealerTop > project(0, TRAY.v1).y, `top=${dealerTop.toFixed(0)}`);
|
||||
ok('dealer cards clear the insurance line', dealerBottom < polar(INSURANCE_LINES.r0, 0).y,
|
||||
`bottom=${dealerBottom.toFixed(0)} line=${polar(INSURANCE_LINES.r0, 0).y.toFixed(0)}`);
|
||||
const d6 = dealerCardPose(5, 6);
|
||||
ok('6-card dealer hand stays clear of the shoe', d6.x + (CARD_W * d6.s) / 2 < project(SHOE.u, SHOE.v).x - 70 * d6.s);
|
||||
ok('6-card dealer hand stays clear of the discard', dealerCardPose(0, 6).x - (CARD_W * d6.s) / 2 > project(DISCARD.u, DISCARD.v).x + 60 * d6.s);
|
||||
ok('dealer row is on the felt', onFelt(0, DEALER_V));
|
||||
ok('shoe / discard / placard on the felt', onFelt(SHOE.u, SHOE.v) && onFelt(DISCARD.u, DISCARD.v) && onFelt(PLACARD.u, PLACARD.v));
|
||||
ok('placard clear of the tray', project(PLACARD.u, PLACARD.v).x + 52 * 0.72 < project(TRAY.u0, TRAY.v0).x);
|
||||
ok('placard clear of the discard holder', project(PLACARD.u, PLACARD.v).x - 52 * 0.72 > project(DISCARD.u, DISCARD.v).x + 54 * 0.72);
|
||||
const humanCardTop = seatLayout(0).card.y - (CARD_H * seatLayout(0).card.s * VIEW.squash) / 2;
|
||||
const lastText = FELT_TEXT.reduce((a, t) => (t.r > a.r ? t : a));
|
||||
ok('felt lettering clears the human\'s cards', polar(lastText.r, 0).y + lastText.size * 0.6 < humanCardTop,
|
||||
`text=${polar(lastText.r, 0).y.toFixed(0)} cards=${humanCardTop.toFixed(0)}`);
|
||||
for (const seat of [5, 6]) {
|
||||
const c = seatLayout(seat).card;
|
||||
ok(`seat ${seat} cards clear of the shoe/discard`, Math.abs(c.x - project(seat === 5 ? SHOE.u : DISCARD.u, SHOE.v).x) > 90);
|
||||
}
|
||||
|
||||
section('Dock');
|
||||
const railBottom = polar(RAIL_OUT, 0).y + RAIL_FACE_PX * polar(RAIL_OUT, 0).s;
|
||||
ok('rail front face ends above the dock', railBottom < DOCK.y, `rail=${railBottom.toFixed(0)}`);
|
||||
ok('dock reaches the bottom of the canvas', DOCK.y + DOCK.h === 1080);
|
||||
for (let seat = 0; seat < 7; seat++) {
|
||||
const b = betPose(seat);
|
||||
ok(`seat ${seat}: bet stack well above the dock`, b.y + 40 < DOCK.y);
|
||||
}
|
||||
|
||||
// ── Source lint (container hit-area gotcha) ──────────────────────────────────
|
||||
section('Source lint');
|
||||
const read = (rel) => readFileSync(new URL(rel, import.meta.url), 'utf8');
|
||||
for (const rel of ['../src/games/blackjack/BlackjackGame.js', '../src/ui/casino/CasinoDock.js', '../src/ui/casino/CasinoCards.js']) {
|
||||
const src = read(rel);
|
||||
ok(`${rel}: no hand-built Rectangle hit areas`, !/new Phaser\.Geom\.Rectangle\(/.test(src));
|
||||
ok(`${rel}: no setInteractive on containers`, !/add\.container\([^)]*\)[^;]*setInteractive/.test(src));
|
||||
}
|
||||
ok('dock chip buttons use a texture-space circle', /new Phaser\.Geom\.Circle\(64, 64, 62\)/.test(read('../src/ui/casino/CasinoDock.js')));
|
||||
ok('Blackjack uses the shared dock + card skin', /new CasinoDock\(/.test(read('../src/games/blackjack/BlackjackGame.js'))
|
||||
&& /new CardSkin\(/.test(read('../src/games/blackjack/BlackjackGame.js')));
|
||||
|
||||
console.log(`\n${pass} passed, ${fail} failed`);
|
||||
process.exit(fail ? 1 : 0);
|
||||
|
|
@ -481,6 +481,91 @@ console.log('\nDeck coverage');
|
|||
// 6 players + dealer × 7 = 49 cards ≤ 53
|
||||
ok('max 5 AI opponents: 6 players + dealer = 49 cards dealt ≤ 53', 6 * 7 + 7 <= 53);
|
||||
|
||||
// ── Table layout (PaiGowTable.js) ─────────────────────────────────────────────
|
||||
console.log('\nTable layout');
|
||||
{
|
||||
const T = await import('../src/games/paigow/PaiGowTable.js');
|
||||
const { seatLayout, fanPose, stackPose, boxBadge, boxCorner, screenOnFelt, dealerHighBox, dealerLowBox,
|
||||
dealerRowPose, SET_TRAY, TRAY_HIGH, TRAY_LOW, trayHighX, trayLowX, TRAY_SCALE, TRAY_CARD_Y,
|
||||
DOCK, VIEW, CARD_W, CARD_H, FAN_DX, diceStartIndex, rotateFrom, PLAY_ORDER, polar, FELT_TEXT,
|
||||
project, DICE_CUP, DICE_LAND, DECK } = T;
|
||||
const SEATS = [0, 1, 2, 3, 4];
|
||||
const dist = (a, b) => Math.hypot(a.x - b.x, a.y - b.y);
|
||||
// bounding circle of a box holding n cards
|
||||
const boxR = (box, n) => 0.5 * Math.hypot((CARD_W + (n - 1) * FAN_DX) * box.s, CARD_H * box.s * VIEW.squash);
|
||||
|
||||
for (const seat of SEATS) {
|
||||
const L = seatLayout(seat);
|
||||
ok(`seat ${seat}: HIGH / LOW / bet on the felt`, screenOnFelt(L.high) && screenOnFelt(L.low) && screenOnFelt(L.bet));
|
||||
ok(`seat ${seat}: all 5 HIGH fan cards on the felt`, [0, 4].every(i => screenOnFelt(fanPose(L.high, i, 5))));
|
||||
ok(`seat ${seat}: 7-card stack on the felt`, [0, 6].every(i => screenOnFelt(stackPose(L.high, i))));
|
||||
const gap = dist(L.high, L.low) - (CARD_H / 2) * L.high.s * VIEW.squash - (CARD_H / 2) * L.low.s * VIEW.squash;
|
||||
ok(`seat ${seat}: HIGH and LOW boxes don't overlap`, gap > 10, `gap ${gap.toFixed(0)}`);
|
||||
ok(`seat ${seat}: bet circle nearer the player than the HIGH box`, L.bet.s > L.high.s);
|
||||
ok(`seat ${seat}: badge + marker on screen`, boxBadge(L.high).y < DOCK.y && boxCorner(L.high, 5).x < 1920);
|
||||
for (const other of SEATS.filter(o => o > seat)) {
|
||||
const O = seatLayout(other);
|
||||
for (const [a, an] of [[L.high, 5], [L.low, 2]]) {
|
||||
for (const [b, bn] of [[O.high, 5], [O.low, 2]]) {
|
||||
ok(`seats ${seat}/${other}: boxes apart`, dist(a, b) > boxR(a, an) + boxR(b, bn) - 70,
|
||||
`d=${dist(a, b).toFixed(0)}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
const pt = L.portrait;
|
||||
if (seat > 0) {
|
||||
ok(`seat ${seat}: portrait + labels clear of the dock`, pt.y + pt.r + 60 < DOCK.y);
|
||||
ok(`seat ${seat}: portrait clear of the setting tray`,
|
||||
pt.x + pt.r < SET_TRAY.x0 || pt.x - pt.r > SET_TRAY.x1 || pt.y + pt.r < SET_TRAY.y0);
|
||||
}
|
||||
}
|
||||
const dh = dealerHighBox(), dl = dealerLowBox();
|
||||
ok('dealer HIGH and LOW boxes apart', dist(dh, dl) > boxR(dh, 5) + boxR(dl, 2) - 10);
|
||||
ok('dealer boxes on the felt', screenOnFelt(fanPose(dh, 0, 5)) && screenOnFelt(fanPose(dl, 1, 2)));
|
||||
ok('dealer 7-card row on the felt', screenOnFelt(dealerRowPose(0)) && screenOnFelt(dealerRowPose(6)));
|
||||
const dealerBottom = dh.y + (CARD_H / 2) * dh.s * VIEW.squash;
|
||||
const lowTop = (seat) => { const b = seatLayout(seat).low; return b.y - (CARD_H / 2) * b.s * VIEW.squash; };
|
||||
ok('felt lettering sits between the dealer and the seat-0 LOW box',
|
||||
FELT_TEXT.every(t => polar(t.r, 0).y - t.size * 0.5 > dealerBottom && polar(t.r, 0).y + t.size * 0.5 < lowTop(0)),
|
||||
`dealer ${dealerBottom.toFixed(0)} low ${lowTop(0).toFixed(0)}`);
|
||||
ok('dice cup / landing / deck on the felt', [DICE_CUP, DICE_LAND, DECK].every(p => screenOnFelt(project(p.u, p.v))));
|
||||
|
||||
// Setting tray
|
||||
for (let n = 5; n <= 7; n++) {
|
||||
const xs = Array.from({ length: n }, (_, i) => trayHighX(i, n));
|
||||
ok(`tray HIGH row of ${n} fits its zone`, xs[0] - (CARD_W * TRAY_SCALE) / 2 >= TRAY_HIGH.x0 - 2 && xs[n - 1] + (CARD_W * TRAY_SCALE) / 2 <= TRAY_HIGH.x1 + 2);
|
||||
}
|
||||
ok('tray LOW pair fits its zone', trayLowX(0) - (CARD_W * TRAY_SCALE) / 2 >= TRAY_LOW.x0 - 2 && trayLowX(1) + (CARD_W * TRAY_SCALE) / 2 <= TRAY_LOW.x1 + 2);
|
||||
ok('tray zones don\'t overlap', TRAY_HIGH.x1 < TRAY_LOW.x0);
|
||||
ok('tray cards fit vertically', TRAY_CARD_Y - (CARD_H * TRAY_SCALE) / 2 > SET_TRAY.y0 + 40 && TRAY_CARD_Y + (CARD_H * TRAY_SCALE) / 2 < SET_TRAY.y1 - 60);
|
||||
ok('tray clear of the human bet circle', seatLayout(0).bet.y + 50 < SET_TRAY.y0);
|
||||
|
||||
// Dice → first seat
|
||||
for (let n = 2; n <= 6; n++) {
|
||||
const hit = new Set();
|
||||
for (let total = 3; total <= 18; total++) {
|
||||
const idx = diceStartIndex(total, n);
|
||||
ok(`dice ${total} over ${n} positions in range`, idx >= 0 && idx < n);
|
||||
hit.add(idx);
|
||||
}
|
||||
ok(`every one of ${n} positions can receive the first hand`, hit.size === n);
|
||||
}
|
||||
ok('total 1 → the dealer (position 1)', diceStartIndex(1, 5) === 0 && diceStartIndex(6, 5) === 0);
|
||||
ok('rotateFrom keeps every position once', rotateFrom(['d', 5, 3, 1, 0], 2).join() === '3,1,0,d,5');
|
||||
ok('play order covers all six logic seats', [...PLAY_ORDER].sort().join() === '0,1,2,3,4,5');
|
||||
}
|
||||
|
||||
// ── Source lint ───────────────────────────────────────────────────────────────
|
||||
console.log('\nSource lint');
|
||||
{
|
||||
const { readFileSync } = await import('node:fs');
|
||||
const src = readFileSync(new URL('../src/games/paigow/PaiGowPokerGame.js', import.meta.url), 'utf8');
|
||||
ok('no hand-built Rectangle hit areas', !/new Phaser\.Geom\.Rectangle\(/.test(src));
|
||||
ok('tray cards set their size before setInteractive', /c\.setSize\(CARD_W, CARD_H\);\s*c\.setInteractive/.test(src));
|
||||
ok('out-of-chips Modal gets a string', !/new Modal\(this, \{/.test(src));
|
||||
ok('no references to undefined SFX.WIN / SFX.LOSE / SFX.SQUASH', !/SFX\.(WIN|LOSE|SQUASH)\b/.test(src));
|
||||
}
|
||||
|
||||
// ── Summary ────────────────────────────────────────────────────────────────────
|
||||
console.log(`\n ${pass} passed, ${fail} failed\n`);
|
||||
if (fail > 0) process.exit(1);
|
||||
|
|
|
|||
Loading…
Reference in New Issue