Fix dice and card depth ordering to use painter's algorithm

- Move per-game `setDepth` calls into a shared `applyDepth()` in Dice3D that derives depth from the die's projected ground position, so overlapping dice always render correctly regardless of creation order.
- Add left-to-right depth stacking for Pai Gow tray cards and bump drag depth so dragged cards sit above all siblings.
This commit is contained in:
Brian Fertig 2026-11-27 12:01:35 -07:00
parent 88b2ddfe16
commit 6da977b33b
No known key found for this signature in database
6 changed files with 23 additions and 8 deletions

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);

View File

@ -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);
}

View File

@ -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);

View File

@ -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;