Reference · Rolls and exact odds
DieHandletype
What mountDie hands back.
Import it
import type { DieHandle } from "@johnmorrisdotca/korokoro";
Definition
type DieHandle = {
readonly element: HTMLElement;
readonly face: number;
readonly rolling: boolean;
roll(): void;
show(face: number): void;
setSides(sides: Sides, face?: number, faces?: CustomFace[]): void;
setOnePip(colour: "red" | "black"): void;
setLocale(locale: string): void;
setRollable(rollable: boolean): void;
destroy(): void;
};
Members
| Name | Type | Description |
|---|---|---|
element | HTMLElement | The die's own element, a button if it rolls. |
face | number | The face showing now (the one it will land on, while it tumbles). |
rolling | boolean | Whether it is tumbling. |
roll | (): void | Throw it, as a tap does. Does nothing on a die that does not roll, or while it is tumbling. |
show | (face: number): void | Show a face at once, with no tumble. Faces outside the die are ignored. |
setSides | (sides: Sides, face?: number, faces?: CustomFace[]): void | Change the kind of die, showing its first face (or |
setOnePip | (colour: "red" | "black"): void | Change the colour of a d6's one pip. |
setLocale | (locale: string): void | Change the language. |
setRollable | (rollable: boolean): void | Whether a tap rolls it, from now on. |
destroy | (): void | Take the die away, with every timer and listener. |
Examples
import type { DieHandle } from "@johnmorrisdotca/korokoro";
import { mountDie } from "@johnmorrisdotca/korokoro";
const value: DieHandle = mountDie(document.createElement("div"), { sides: 6, sound: false });
console.log(Object.keys(value));