33 lines
727 B
TypeScript
33 lines
727 B
TypeScript
|
|
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>;
|
||
|
|
// current position in region
|
||
|
|
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);
|
||
|
|
}
|