Add confirmation prompt when discarding mid-lay-down in Phase 10
- Prevents accidentally ending a turn and wiping staged mat cards by prompting before the discard takes effect. - New `confirmTurn` setting (default on) gates the prompt; toggleable in table settings alongside existing warn/hints options. - Confirmation modal shows current phase, per-group progress, and offers "Lay it down" / "Keep building" / "Discard & end turn" actions. - Settings modal height and row positions adjusted to fit the new option.
This commit is contained in:
parent
c193d0a4ca
commit
07c1d7ba04
|
|
@ -57,6 +57,7 @@ const D = {
|
|||
|
||||
const SETTINGS_KEY = 'phase10-settings';
|
||||
const DOUBLE_CLICK_MS = 320;
|
||||
const ROW_H = 30; // line height for stacked modal status rows
|
||||
const COLOR_ORDER = { red: 0, blue: 1, yellow: 2, green: 3 };
|
||||
const FONT_HAND = '"YummyCupcakes", "Comic Sans MS", cursive';
|
||||
|
||||
|
|
@ -71,7 +72,7 @@ const samePose = (a, b) => a && b && Math.abs(a.x - b.x) < 0.5 && Math.abs(a.y -
|
|||
&& Math.abs(a.rot - b.rot) < 0.001 && Math.abs(a.s - b.s) < 0.001 && Math.abs((a.q ?? SQ) - (b.q ?? SQ)) < 0.001;
|
||||
|
||||
function loadSettings() {
|
||||
const base = { pace: 'normal', hints: true, warn: true, sort: 'number' };
|
||||
const base = { pace: 'normal', hints: true, warn: true, confirmTurn: true, sort: 'number' };
|
||||
try {
|
||||
return { ...base, ...JSON.parse(localStorage.getItem(SETTINGS_KEY) || '{}') };
|
||||
} catch { return base; }
|
||||
|
|
@ -1431,6 +1432,12 @@ export default class Phase10Game extends Phaser.Scene {
|
|||
const idx = hand.findIndex(c => c.id === id);
|
||||
if (idx < 0) return;
|
||||
const card = hand[idx];
|
||||
// A discard ends the turn and wipes the mat, so never let it interrupt a
|
||||
// lay-down that's already under way without asking first.
|
||||
if (!confirmed && this.settings.confirmTurn && this.abandoningLaydown(id)) {
|
||||
this.confirmAbandonStage(card, () => this.discardCard(id, { confirmed: true }));
|
||||
return;
|
||||
}
|
||||
if (!confirmed && this.settings.warn) {
|
||||
const inPhase = !this.me().laidDown && this.advice?.laydown?.some(g => g.cards.some(c => c.id === id));
|
||||
if (card.value === 'wild' || inPhase) {
|
||||
|
|
@ -1863,6 +1870,71 @@ export default class Phase10Game extends Phaser.Scene {
|
|||
this.confirm(`Discard the ${cardName(card)}?`, why, 'Discard it', onYes, { no: 'Keep it' });
|
||||
}
|
||||
|
||||
// Is there staged work on the mat that a discard to `id` would throw away?
|
||||
// Dragging the *last* staged card onto the pile reads as un-staging it, so
|
||||
// that one stays quiet.
|
||||
abandoningLaydown(id) {
|
||||
if (this.me().laidDown || !this.stage) return false;
|
||||
const left = this.stagedIds();
|
||||
left.delete(id);
|
||||
return left.size > 0;
|
||||
}
|
||||
|
||||
// Show what's on the mat, with a one-tap way to finish the lay-down instead.
|
||||
confirmAbandonStage(card, onDiscard) {
|
||||
const me = this.me();
|
||||
const spec = getPhase(me.phase);
|
||||
const rows = spec.groups
|
||||
.map((sg, gi) => ({ n: this.stage[gi].length, st: groupStatus(sg.kind, sg.count, this.stageCards(gi)) }))
|
||||
.filter(r => r.n > 0);
|
||||
const ready = spec.groups.every((sg, gi) => groupStatus(sg.kind, sg.count, this.stageCards(gi)).ok);
|
||||
const staged = this.stagedIds().size;
|
||||
const fitsPhase = !ready && !!this.advice?.laydown?.some(g => g.cards.some(c => c.id === card.id));
|
||||
const why = card.value === 'wild'
|
||||
? 'A Wild builds any group — and costs 25 points if you end the game holding one.'
|
||||
: fitsPhase ? `The ${cardName(card)} is part of a Phase ${me.phase} you could still build.` : '';
|
||||
|
||||
const h = 470 + (rows.length - 1) * ROW_H + (why ? 30 : 0);
|
||||
this.openModal({ w: 700, h, onEscape: () => this.closeModal() });
|
||||
const top = CY - h / 2;
|
||||
let y = top + 54;
|
||||
this.modalText(CX, y, ready ? 'Throw away a finished phase?' : 'End your turn mid-lay-down?', {
|
||||
fontFamily: 'Righteous', fontSize: '34px', color: COLORS.textHex,
|
||||
});
|
||||
y += 46;
|
||||
this.modalText(CX, y, `Phase ${me.phase} — ${spec.short}`, {
|
||||
fontFamily: 'Righteous', fontSize: '21px', color: COLORS.goldHex,
|
||||
});
|
||||
y += 38;
|
||||
for (const r of rows) {
|
||||
this.modalText(CX, y, r.st.text, {
|
||||
fontFamily: '"Julius Sans One"', fontSize: '17px',
|
||||
color: r.st.ok ? '#7cf0a0' : r.st.valid ? COLORS.textHex : '#ff9a7a',
|
||||
});
|
||||
y += ROW_H;
|
||||
}
|
||||
this.modalText(CX, CY - 34, ready
|
||||
? `Discarding the ${cardName(card)} puts your lay-down back in your hand and passes play.`
|
||||
: `You've laid out ${staged} card${staged === 1 ? '' : 's'} of Phase ${me.phase}. Discarding the ${cardName(card)} ends your turn and returns them to your hand.`, {
|
||||
fontFamily: '"Julius Sans One"', fontSize: '17px', color: COLORS.mutedHex, align: 'center', wordWrap: { width: 600 },
|
||||
});
|
||||
if (why) this.modalText(CX, CY + 8, why, {
|
||||
fontFamily: '"Julius Sans One"', fontSize: '16px', color: '#f2d6a0', align: 'center', wordWrap: { width: 600 },
|
||||
});
|
||||
|
||||
const close = fn => () => { this.closeModal(); fn?.(); };
|
||||
if (ready) {
|
||||
this.modalButton(CX, CY + h / 2 - 152, 'Lay it down (↵)', close(() => this.layDown()), { width: 300 });
|
||||
this.modalButton(CX - 170, CY + h / 2 - 84, 'Keep building', close(), { width: 300, variant: 'ghost' });
|
||||
this.modalButton(CX + 170, CY + h / 2 - 84, 'Discard & end turn', close(onDiscard), { width: 300, variant: 'ghost' });
|
||||
} else {
|
||||
this.modalButton(CX, CY + h / 2 - 152, 'Keep building', close(), { width: 300 });
|
||||
this.modalButton(CX, CY + h / 2 - 84, 'Discard & end turn', close(onDiscard), { width: 300, variant: 'ghost' });
|
||||
}
|
||||
// Enter and Esc are the safe answers here — discarding has to be aimed at.
|
||||
this.modal.onEnter = () => this.closeModal();
|
||||
}
|
||||
|
||||
onLeave() {
|
||||
const inMatch = this.history.length > 0 || this.mode === 'human' || this.mode === 'ai';
|
||||
if (!inMatch || this.gs?.roundPhase === 'gameOver') { this.scene.start('GameMenu'); return; }
|
||||
|
|
@ -1900,8 +1972,9 @@ export default class Phase10Game extends Phaser.Scene {
|
|||
|
||||
openSettings(onDone = null) {
|
||||
const back = () => { this.closeModal(); onDone?.(); };
|
||||
this.openModal({ w: 760, h: 520, onEscape: back });
|
||||
const y0 = CY - 196;
|
||||
const w = 760, h = 580;
|
||||
this.openModal({ w, h, onEscape: back });
|
||||
const y0 = CY - h / 2 + 64;
|
||||
this.modalText(CX, y0, 'Table Settings', { fontFamily: 'Righteous', fontSize: '40px', color: COLORS.goldHex });
|
||||
const row = (y, label, options, current, apply) => {
|
||||
this.addToModal(this.add.text(CX - 330, y, label, {
|
||||
|
|
@ -1924,11 +1997,12 @@ export default class Phase10Game extends Phaser.Scene {
|
|||
row(y0 + 86, 'Opponent pace', [['relaxed', 'Relaxed'], ['normal', 'Normal'], ['fast', 'Fast']], this.settings.pace, (v) => { this.settings.pace = v; });
|
||||
row(y0 + 152, 'Card hints (★ keep · ▼ toss · + hit)', [[false, 'Off'], [true, 'On']], this.settings.hints, (v) => { this.settings.hints = v; this.layout(); });
|
||||
row(y0 + 218, 'Warn before tossing a Wild / phase card', [[false, 'Off'], [true, 'On']], this.settings.warn, (v) => { this.settings.warn = v; });
|
||||
row(y0 + 284, 'Hand order', [['manual', 'Manual'], ['number', '1·2·3'], ['color', 'Color'], ['phase', 'Phase']], this.settings.sort, (v) => {
|
||||
row(y0 + 284, 'Confirm ending a turn mid-lay-down', [[false, 'Off'], [true, 'On']], this.settings.confirmTurn, (v) => { this.settings.confirmTurn = v; });
|
||||
row(y0 + 350, 'Hand order', [['manual', 'Manual'], ['number', '1·2·3'], ['color', 'Color'], ['phase', 'Phase']], this.settings.sort, (v) => {
|
||||
this.settings.sort = v; this.sortHand(); this.layout(); this.refreshSortButtons();
|
||||
});
|
||||
this.modalText(CX, y0 + 340, 'Opponent hand speed also follows each opponent\'s skill.', { fontFamily: '"Julius Sans One"', fontSize: '13px', color: COLORS.mutedHex });
|
||||
this.modalButton(CX, y0 + 404, 'Done', back, { width: 220, height: 50, fontSize: 21 });
|
||||
this.modalText(CX, y0 + 406, 'Opponent hand speed also follows each opponent\'s skill.', { fontFamily: '"Julius Sans One"', fontSize: '13px', color: COLORS.mutedHex });
|
||||
this.modalButton(CX, y0 + 468, 'Done', back, { width: 220, height: 50, fontSize: 21 });
|
||||
}
|
||||
|
||||
openPhases() {
|
||||
|
|
|
|||
Loading…
Reference in New Issue