@planarally/dice
Version:
3D dice rolling functionality for babylon.js.
50 lines (49 loc) • 2.06 kB
TypeScript
import { type Part, type Status, type WithStatus } from "../../core/types";
export declare enum DxSegmentType {
Die = 0,
Literal = 1,
Operator = 2
}
declare const addOptions: readonly ["d4", "d6", "d8", "d10", "d12", "d20", "d100"];
declare const limitOperatorOptions: readonly ["keep", "drop", "min", "max"];
declare const rerollOperatorOptions: readonly ["inf", "once", "add", "explode"];
type operatorOptions = (typeof limitOperatorOptions)[number] | (typeof rerollOperatorOptions)[number];
declare const selectorOptions: readonly ["=", ">", "<", "highest", "lowest"];
declare const symbolOptions: readonly ["+", "-"];
export declare const DxConfig: {
addOptions: readonly ["d4", "d6", "d8", "d10", "d12", "d20", "d100"];
limitOperatorOptions: readonly ["keep", "drop", "min", "max"];
rerollOperatorOptions: readonly ["inf", "once", "add", "explode"];
selectorOptions: readonly ["=", ">", "<", "highest", "lowest"];
symbolOptions: readonly ["+", "-"];
};
export interface DieSegment extends Part {
type: DxSegmentType.Die;
die: (typeof addOptions)[number];
amount: number;
operator?: operatorOptions;
selector?: (typeof selectorOptions)[number];
selectorValue?: number;
}
export interface RollOptions {
d100Mode: 0 | 100;
}
type RolledDieOutput = number[];
export type ResolvedDieOutput = {
roll: number;
status?: "kept" | "dropped" | "overridden";
}[];
export interface OperatorSegment extends Part<(typeof symbolOptions)[number]> {
type: DxSegmentType.Operator;
}
interface LiteralSegment extends Part {
type: DxSegmentType.Literal;
value: number;
}
export type DxSegment = DieSegment | LiteralSegment | OperatorSegment;
export type WithDxStatus<D extends DxSegment, S extends Status> = S extends Status.PendingEvaluation ? D extends DieSegment ? WithStatus<D, S> & {
output: RolledDieOutput;
} : WithStatus<D, S> : S extends Status.Resolved ? D extends DieSegment ? WithStatus<D, S> & {
output: ResolvedDieOutput;
} : WithStatus<D, S> : WithStatus<D, S>;
export {};