Skip to the content

Korokoroコロコロ

Roll mixed dice or type notation, compare exact probabilities, keep a history and replay seeded rolls.

Korokoro describes something small rolling in Japanese. About the name

Contents

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

NameTypeDescription
elementHTMLElement

The die's own element, a button if it rolls.

facenumber

The face showing now (the one it will land on, while it tumbles).

rollingboolean

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 face).

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));

View sourceEdit on GitHubMade from the source of @johnmorrisdotca/korokoro 1.16.0.