2026-04-02 15:59:27 +08:00
|
|
|
import {Entity} from "@/utils/entity";
|
2026-04-01 13:36:16 +08:00
|
|
|
import {Region} from "./region";
|
2026-04-02 15:59:27 +08:00
|
|
|
import {RNG} from "@/utils/rng";
|
2026-04-01 13:36:16 +08:00
|
|
|
|
2026-04-02 13:52:15 +08:00
|
|
|
export type Part = {
|
|
|
|
|
id: string;
|
2026-04-02 13:58:52 +08:00
|
|
|
|
|
|
|
|
sides?: number;
|
|
|
|
|
side?: number;
|
|
|
|
|
|
2026-04-01 13:36:16 +08:00
|
|
|
alignments?: string[];
|
|
|
|
|
alignment?: string;
|
2026-04-02 13:52:15 +08:00
|
|
|
region: Entity<Region>;
|
2026-04-01 13:36:16 +08:00
|
|
|
position: number[];
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-02 13:52:15 +08:00
|
|
|
export function flip(part: Entity<Part>) {
|
|
|
|
|
part.produce(draft => {
|
2026-04-02 13:58:52 +08:00
|
|
|
if(!draft.sides)return;
|
|
|
|
|
draft.side = ((draft.side||0) + 1) % draft.sides;
|
2026-04-02 13:52:15 +08:00
|
|
|
});
|
2026-04-01 13:36:16 +08:00
|
|
|
}
|
|
|
|
|
|
2026-04-02 13:52:15 +08:00
|
|
|
export function flipTo(part: Entity<Part>, side: number) {
|
|
|
|
|
part.produce(draft => {
|
2026-04-02 13:58:52 +08:00
|
|
|
if(!draft.sides || side >= draft.sides)return;
|
2026-04-02 13:52:15 +08:00
|
|
|
draft.side = side;
|
|
|
|
|
});
|
2026-04-01 13:36:16 +08:00
|
|
|
}
|
|
|
|
|
|
2026-04-02 13:52:15 +08:00
|
|
|
export function roll(part: Entity<Part>, rng: RNG) {
|
|
|
|
|
part.produce(draft => {
|
2026-04-02 13:58:52 +08:00
|
|
|
if(!draft.sides)return;
|
2026-04-02 13:52:15 +08:00
|
|
|
draft.side = rng.nextInt(draft.sides);
|
|
|
|
|
});
|
2026-04-01 17:48:40 +08:00
|
|
|
}
|