boardgame-core/src/core/part.ts

34 lines
775 B
TypeScript
Raw Normal View History

2026-04-01 13:36:16 +08:00
import {Entity, EntityAccessor} from "../utils/entity";
import {Region} from "./region";
import {RNG} from "../utils/rng";
export type Part = Entity & {
// cards have 2 sides, dices have multiple, tokens have 1
sides: number;
// mostly rotations, if relevant
alignments?: string[];
// current side
side: number;
// current alignment
alignment?: string;
// current region
region: EntityAccessor<Region>;
2026-04-01 17:48:40 +08:00
// current position in region, expect to be the same length as region's axes
2026-04-01 13:36:16 +08:00
position: number[];
}
export function flip(part: Part) {
part.side = (part.side + 1) % part.sides;
}
export function flipTo(part: Part, side: number) {
part.side = side;
}
export function roll(part: Part, rng: RNG) {
part.side = rng.nextInt(part.sides);
2026-04-01 17:48:40 +08:00
}