fix(tabletop): key placements by surface, path, and piece

A piece can appear on more than one path of the same surface (e.g. the
poker deck expands to every card while the flop also places the ace), so
the render key must include the path to stay unique.
This commit is contained in:
2026-08-09 22:46:06 +08:00
parent f494a6f9be
commit d9d38c2bee
4 changed files with 37 additions and 10 deletions
+28 -4
View File
@@ -97,6 +97,27 @@ describe('computeSurfacePlacements', () => {
const placements = computeSurfacePlacements(surface, { '/dock/0': ['harbor:boat#fleet'] });
expect(placements[0]!.candidate).toEqual({ seat: '0', x: 40, y: 5, rotation: 1 });
});
it('keeps the same piece on two paths as distinct placements', () => {
const surface = makeSurface({
layout: [
{ route: '/deck', x: 0, y: 0, rotation: 0 },
{ route: '/community/:slot', x: 0, y: 0, rotation: 0 },
],
});
// The deck expands to every card (including `as`); the flop also places `as`.
const placements = computeSurfacePlacements(surface, {
'/deck': ['poker:card#as', 'poker:card#kh'],
'/community/0': ['poker:card#as'],
});
expect(placements).toHaveLength(3);
const deck = placements.filter((p) => p.path === '/deck');
const flop = placements.filter((p) => p.path === '/community/0');
expect(deck).toHaveLength(2);
expect(flop).toHaveLength(1);
// The same piece on two paths yields distinct placement keys.
expect(placementKey(deck[0]!)).not.toBe(placementKey(flop[0]!));
});
});
describe('computeRenderState', () => {
@@ -116,11 +137,14 @@ describe('computeRenderState', () => {
});
describe('placementKey', () => {
it('is unique per surface and piece', () => {
const a = { surface: 'board#harbor', piece: 'harbor:card#a' } as never;
const b = { surface: 'board#harbor', piece: 'harbor:card#b' } as never;
const c = { surface: 'hud#hand', piece: 'harbor:card#a' } as never;
it('is unique per surface, path, and piece', () => {
const a = { surface: 'board#harbor', path: '/deck', piece: 'harbor:card#a' } as never;
const b = { surface: 'board#harbor', path: '/deck', piece: 'harbor:card#b' } as never;
const c = { surface: 'hud#hand', path: '/deck', piece: 'harbor:card#a' } as never;
// The same piece on two paths of the same surface is a distinct placement.
const d = { surface: 'board#harbor', path: '/community/0', piece: 'harbor:card#a' } as never;
expect(placementKey(a)).not.toBe(placementKey(b));
expect(placementKey(a)).not.toBe(placementKey(c));
expect(placementKey(a)).not.toBe(placementKey(d));
});
});