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

RollerOptionstype

Everything a tray can be told when it is mounted. All of it is optional.

Import it

import type { RollerOptions } from "@johnmorrisdotca/korokoro";

Definition

type RollerOptions = {
    locale?: string;
    strings?: Partial<RollerStrings>;
    storage?: StorageLike | null;
    storageKey?: string;
    spec?: Partial<RollSpec>;
    query?: string;
    shareBase?: string;
    cloth?: Cloth;
    onePip?: "red" | "black";
    theme?: Record<`--kk-${string}`, string>;
    wide?: boolean;
    onRoll?: (roll: Roll) => void;
    animationMs?: number;
    sound?: boolean;
    playSound?: PlaySound;
    hold?: boolean;
    placeholder?: boolean;
    keyboard?: boolean;
    diceWar?: boolean;
    languageChooser?: boolean;
    size?: RollerSize;
};

Members

NameTypeDescription
locale (optional)string | undefined

For numbers and times, and for which built-in words to use: "ja…" is Japanese, anything else English.

strings (optional)Partial<RollerStrings> | undefined

Words to use instead of the built-in ones.

storage (optional)StorageLike | null | undefined

Where the history is kept. Defaults to localStorage; pass null to keep nothing.

storageKey (optional)string | undefined

The key the history is kept under. Defaults to "korokoro.history".

spec (optional)Partial<RollSpec> | undefined

The dice showing when the tray opens.

query (optional)string | undefined

A query string that may hold a shared roll or a seed. Defaults to the page's own.

shareBase (optional)string | undefined

The address a shared link points at. Defaults to the page's own, without its query.

cloth (optional)"green" | "blue" | "red" | "black" | "wood" | undefined

The cloth the felt is laid in: "green" (unless said), "blue", "red", "black" or "wood", the family's five. theme is laid over it.

onePip (optional)"red" | "black" | undefined

The colour of a d6's one pip, on the felt and in the history: "red" (unless said) or "black", the colour of the other pips.

theme (optional)Record<`--kk-${string}`, string> | undefined

CSS variables for the tray, such as { "--kk-felt": "#234" }: set on the tray itself, so they win over its defaults in both themes.

wide (optional)boolean | undefined

Tray and panels side by side on a wide screen.

onRoll (optional)((roll: Roll) => void) | undefined

Called once each roll has landed.

animationMs (optional)number | undefined

Length of the tumble, in milliseconds, from the throw to the last die landing. Reduced motion always skips it.

sound (optional)boolean | undefined

Whether the tray has a sound at all. Left out or true, it has a mute button, and starts with the sound on unless the device asks for reduced motion or somebody muted it here before. False, it is silent and has no button.

playSound (optional)PlaySound | undefined

A sound of your own for each throw, in place of the recorded dice. It is called only while the tray is not muted.

hold (optional)boolean | undefined

Whether a die on the felt can be tapped to hold it while the rest are rolled again. Left out or true, plain dice can be held once they have been rolled. False, a tap anywhere on the felt rolls, a die included.

placeholder (optional)boolean | undefined

Whether the dice the tray opens with are only a suggestion. Left out or true, they are: the first die button tapped replaces them with one of that die, so one tap gives a d20, and every tap after that adds. False, the opening dice are the user's own roll and the first tap adds to them. A roll that arrives by a shared link is always the user's.

keyboard (optional)boolean | undefined

Whether Space rolls from anywhere on the page. Left out or true, it does, unless something that takes typing has the focus. False, the page keeps its Space (to scroll, say) and the tray rolls from the keyboard only when the focus is inside it: for a tray that is one thing among many on a page.

diceWar (optional)boolean | undefined

Whether Dice War is among the games: a table of the person at the tray and computers, played with the tray's own dice (diceWar.ts has the rules). Off unless asked for, so a tray that does not want a game in it is as it was.

languageChooser (optional)boolean | undefined

Whether the tray offers its own small choice of language, English or 日本語, remembered on the device. Off unless asked for, so the tray stays as plain as it was.

size (optional)RollerSize | undefined

How much of the tray is drawn, for a tray put into a small space on somebody's page. "small" is the felt and the result and nothing else: the dice are the ones it was given. "medium" adds the choice of dice and the bonus. "large", and left out, is everything: the history, the stats and the odds too.

Examples

import type { RollerOptions } from "@johnmorrisdotca/korokoro";
const value: RollerOptions = { spec: { count: 2, sides: 6 }, storage: null, sound: false };
console.log(value.spec?.count);
2

What it prints (run when this page was built)

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