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:
@@ -22,6 +22,8 @@ export interface GameState {
|
||||
export interface Placement {
|
||||
/** Surface id (`type#id`). */
|
||||
surface: string;
|
||||
/** The path key this placement came from. */
|
||||
path: string;
|
||||
/** The matched route. */
|
||||
route: Route;
|
||||
/** The matched candidate, when the route has `:param`s. */
|
||||
@@ -97,6 +99,7 @@ export function computeSurfacePlacements(surface: Surface, paths: Record<string,
|
||||
for (const piece of parts) {
|
||||
placements.push({
|
||||
surface: surfaceId,
|
||||
path,
|
||||
route,
|
||||
candidate: match.candidate,
|
||||
piece,
|
||||
@@ -120,9 +123,9 @@ export function computeRenderState(pkg: Package, state: GameState): Placement[]
|
||||
return out;
|
||||
}
|
||||
|
||||
/** A stable key for a placement, unique across surfaces and pieces. */
|
||||
/** A stable key for a placement, unique across surfaces, paths, and pieces. */
|
||||
export function placementKey(p: Placement): string {
|
||||
return `${p.surface}:${p.piece}`;
|
||||
return `${p.surface}:${p.path}:${p.piece}`;
|
||||
}
|
||||
|
||||
/** The derived render state for a package, from the current game state. */
|
||||
|
||||
Reference in New Issue
Block a user