diff --git a/src/games/backgammon/BackgammonTray.js b/src/games/backgammon/BackgammonTray.js index 95b3ed4..9e3ef7f 100644 --- a/src/games/backgammon/BackgammonTray.js +++ b/src/games/backgammon/BackgammonTray.js @@ -63,7 +63,6 @@ export class BoardDice { apply(i) { const p = this.poses[i]; const d = this.dice[i]; - d.setDepth(this.depth + p.v * 0.0002 + (p.h > 4 ? 0.3 : 0)); d.g.setAlpha(p.alpha); d.shadow.setAlpha(p.alpha); d.set(p.u, p.v, p.h, p.q); } diff --git a/src/games/monopoly/MonopolyTray.js b/src/games/monopoly/MonopolyTray.js index e342e85..e74a3aa 100644 --- a/src/games/monopoly/MonopolyTray.js +++ b/src/games/monopoly/MonopolyTray.js @@ -55,7 +55,6 @@ export class DiceTray { apply(i) { const p = this.poses[i], d = this.dice[i]; - d.setDepth(this.depth + p.v * 0.0002 + (p.h > 4 ? 0.3 : 0)); d.g.setAlpha(p.alpha); d.shadow.setAlpha(p.alpha); d.set(p.u, p.v, p.h, p.q); } diff --git a/src/games/paigow/PaiGowPokerGame.js b/src/games/paigow/PaiGowPokerGame.js index 89669ec..d7494f3 100644 --- a/src/games/paigow/PaiGowPokerGame.js +++ b/src/games/paigow/PaiGowPokerGame.js @@ -657,10 +657,9 @@ export default class PaiGowPokerGame extends Phaser.Scene { c.setSize(CARD_W, CARD_H); c.setInteractive({ useHandCursor: true, draggable: true }); c.on('pointerdown', () => { dragged = false; }); - c.on('dragstart', () => { dragged = true; c.setDepth(D.trayCards + 5); }); + c.on('dragstart', () => { dragged = true; c.setDepth(D.trayCards + 10); }); c.on('drag', (_p, x, y) => c.setPosition(x, y)); c.on('dragend', (pointer) => { - c.setDepth(D.trayCards); const inLow = pointer.x >= TRAY_LOW.x0 - 24 && pointer.x <= TRAY_LOW.x1 + 24; this.moveCard(i, inLow ? 'low' : 'high'); }); @@ -694,9 +693,17 @@ export default class PaiGowPokerGame extends Phaser.Scene { }; high.forEach((i, k) => place(i, trayHighX(k, high.length))); this.lowSel.forEach((i, k) => place(i, trayLowX(k))); + this.assignTrayDepths(); this.updateTrayUI(); } + // Left-to-right depth: every tray card sits above the card to its left. + assignTrayDepths() { + const high = this.trayOrder.filter(i => !this.lowSel.includes(i)); + high.forEach((i, k) => this.cards.get(`0:${i}`)?.setDepth(D.trayCards + k)); + this.lowSel.forEach((i, k) => this.cards.get(`0:${i}`)?.setDepth(D.trayCards + high.length + k)); + } + toggleCard(i) { if (!this.trayActive) return; const at = this.lowSel.indexOf(i); diff --git a/src/games/parchisi/ParchisiTray.js b/src/games/parchisi/ParchisiTray.js index bc6a123..713c3f6 100644 --- a/src/games/parchisi/ParchisiTray.js +++ b/src/games/parchisi/ParchisiTray.js @@ -46,7 +46,6 @@ export class DiceTray { apply(i) { const p = this.poses[i], d = this.dice[i]; - d.setDepth(this.depth + p.v * 0.0002 + (p.h > 4 ? 0.3 : 0)); d.g.setAlpha(p.alpha); d.shadow.setAlpha(p.alpha); d.set(p.u, p.v, p.h, p.q); } diff --git a/src/games/yatzi/YatziTray.js b/src/games/yatzi/YatziTray.js index 7a5debd..49a9b1c 100644 --- a/src/games/yatzi/YatziTray.js +++ b/src/games/yatzi/YatziTray.js @@ -57,7 +57,6 @@ export class YatziTray { apply(i) { const p = this.poses[i]; const d = this.dice[i]; - d.setDepth(this.depth + 3 + p.v * 0.0004 + (p.h > 4 ? 0.3 : 0)); d.g.setAlpha(p.alpha); d.shadow.setAlpha(p.alpha); d.set(p.u, p.v, p.h, p.q); diff --git a/src/ui/dice/Dice3D.js b/src/ui/dice/Dice3D.js index 0a0b672..85ba93a 100644 --- a/src/ui/dice/Dice3D.js +++ b/src/ui/dice/Dice3D.js @@ -265,15 +265,27 @@ export class Die3D { this.shadow = scene.add.graphics().setDepth(depth - 0.5); this.g = scene.add.graphics().setDepth(depth); this.state = { u: 0, v: 0, h: 0, q: [1, 0, 0, 0] }; + this.baseDepth = depth; this.scale = 1; this.glow = 0; this.visible = true; } setVisible(v) { this.visible = v; this.g.setVisible(v); this.shadow.setVisible(v); return this; } - setDepth(d) { this.g.setDepth(d); this.shadow.setDepth(d - 0.5); return this; } + setDepth(d) { this.baseDepth = d; this.applyDepth(); return this; } - set(u, v, h, q) { Object.assign(this.state, { u, v, h, q }); this.draw(); return this; } + // Painter's order: a die lower on screen (nearer the viewer) always draws + // over a die higher on screen, regardless of creation order. Depth is + // derived from the die's projected ground point, so overlapping dice are + // ordered correctly in every game that shares this class. + applyDepth() { + const p = this.opts.ground(this.state.u, this.state.v); + const d = this.baseDepth + p.y * 0.0005 + (this.state.h > 4 ? 0.3 : 0); + this.g.setDepth(d); + this.shadow.setDepth(d - 0.5); + } + + set(u, v, h, q) { Object.assign(this.state, { u, v, h, q }); this.applyDepth(); this.draw(); return this; } screenCenter() { const { u, v, h } = this.state;