Reference
Controllers and canvas player
import { … } from "@johnmorrisdotca/karakuri/play";
40.0 kB minified and gzipped, with everything it imports (measured with esbuild)
Exports
| Name | Kind | What it is |
|---|---|---|
Controller | type | One level of one game, played. |
createController | function | Makes a controller for level level (from 1) of a game; a level out of range is held to the nearest. |
defaultTheme | function | The theme without a page: the light one, for a drawing made where there is no style to read (a test, a server). |
GameInfo | type | What a game of the package is, for a chooser. |
Info | type | What the player reads in the bar above the board. |
KARAKURI_GAME_IDS | constant | The ids of the games, in the order the package lists them (kebab case, the same in every address and attribute). |
KARAKURI_GAMES | constant | THE GAMES of the package, by id. |
KARAKURI_STYLE | constant | THE STYLE the player wears: the colours as custom properties on .karakuri (light, and dark when the page asks for it by prefers-color-scheme or by data-theme="dark" on the root), the layout of the bar, the play area and the buttons, and the one rule that matters for games played with fingers: nothing on the board can be selected, dragged or double-tapped, and the play area stops the page scrolling under a finger only for the games that read a finger's whole path. |
KARAKURI_THEMES | constant | The look the games draw with, as custom properties, so a page can change any of them. |
KarakuriGame | type | The id of a game of the package. |
KarakuriMount | type | The native handle, including its controller and focused keyboard canvas. |
mountKarakuri | function | Plays one game of the package in host: a canvas that scales to the box it is given, the pointer (finger or mouse) wired to the game, a fixed-step loop that runs only while something moves, and (with ui: "full") the bar, the buttons and the card that says how a level ended. |
MountOptions | type | Initial native controller, level, layout, keyboard, clock and host callbacks. |
Point | type | A place in a game's own world, in its own units (not pixels). |
readTheme | function | Reads the theme a game draws with from an element's computed style: each colour is --kk-<name>, with the light or the dark default beneath. |
Say | type | A line of words to be said in the player's language: a key of KARAKURI_STRINGS and the values for its {name}s. |
Status | type | How a level stands: still being played, won, or lost. |
StatusEvent | type | What a status callback is given. |
Theme | type | The colours and sizes a game draws with, read from the page's custom properties (--kk-*) so that it follows light, dark and the family's cloths. |