Skip to the content

Karakuri documentation

Karakuri API: every export

Every export of every entry point, each with its own page. This page keeps the addresses the old one-page reference had.

@johnmorrisdotca/karakuri/physics

addBodyfunction

Adds a body to the world and gives it back.

addNodefunction

Adds a node and gives back its index.

addRopefunction

Lays a rope of pieces links from (ax, ay) to (bx, by): the first node is pinned and the last is the node end if one is given (its place is moved to the rope's end), and the nodes between are light.

Bodytype

A rigid body.

BodyTypetype

How a body moves: dynamic by forces and contacts, kinematic only as the game sets it (it pushes, and is not pushed), static not at all.

capsulesAlongfunction

A capsule chain for a drawn line: one capsule between each pair of neighbouring points.

CapsuleShapetype

A thick segment, from (ax, ay) to (bx, by) with a radius, placed in the body's own frame.

CircleShapetype

A disc, placed in the body's own frame (its origin is the body's centre of mass for a dynamic body).

clampfunction

value held between low and high.

closestOnSegmentfunction

The point on the segment a to b nearest to (px, py), and how far along the segment it is (0 to 1).

Contacttype

One contact between two shapes: the normal points from a towards b.

contactsBetweenfunction

The contacts between two bodies whose shapes are within margin of each other.

countOffunction

How many particles of a kind.

Disctype

The round bodies the particles must not enter (a character, a coin): centre and radius.

distancefunction

The distance between two points.

distanceSquaredfunction

The squared distance between two points, which needs no square root.

fillRectfunction

Fills the rectangle from (x, y) to (x + w, y + h) with particles of one kind on a grid a little looser than they settle.

Fluidtype

The liquid: its particles and how it behaves.

fluidNumbersfunction

Every number of the liquid's particles, for hashing it (kinds as 0, 1, 2).

gapfunction

The gap between two bodies: the smallest gap of any pair of their shapes (negative when they overlap).

hashNumbersfunction

A 32-bit FNV-1a hash of a list of numbers, taken over the bits of each as a 64-bit float.

isSettledfunction

Whether every dynamic body in the world is slower than speed (units a second) and is hardly turning.

lengthfunction

The length of (x, y).

linkCrossedfunction

The index of the first live link that the swipe from (x1, y1) to (x2, y2) crosses, or -1.

nearestTofunction

The nearest distance from a particle of a kind to a disc's surface (negative when it is inside), or Infinity when there is none.

nodeSpeedfunction

The speed of a node in units a second at a step of dt.

pointInPolygonfunction

Whether (px, py) is inside the polygon (an even-odd test over its vertices, in order).

refreshShapesfunction

Recomputes a body's shapes in world places from its position and angle.

Rigtype

A set of nodes and links, with the fixed shapes the round nodes rest on.

rigNumbersfunction

Every number of the rig's nodes, for hashing it.

Shapetype

A shape of a body.

STEPconstant

The length of the fixed step every game runs at, in seconds.

stepFluidfunction

Advances the liquid by one step of dt seconds.

stepRigfunction

Advances the rig by one step of dt seconds.

stepWorldfunction

Advances the world by one fixed step (STEP seconds) in substeps smaller ones.

unitfunction

The unit vector of (x, y), or (0, 0) for a zero vector.

Vectype

A point or a vector in the plane.

Worldtype

The world: its gravity (down is +y, in units a second squared), its bodies in the order they were added, and how hard it works.

worldNumbersfunction

Every number of a world's bodies' state, for hashing it: a determinism test compares these bit for bit.

WorldShapetype

A shape as the world sees it now: a circle as (ax, ay, r) with a = b, a capsule with its two ends.

@johnmorrisdotca/karakuri/levels

PIN_RESCUE_LEVELSconstant

The levels, each with more pins to choose between and more ways to lose.

PinRescueEntrytype

A level, the pins that win it in order (by index in pins), and pins that lose it in order.

RopeCutEntrytype

A level and the cuts that win it, in order: the step to cut at, which rope, which link of it.

SaveEntrytype

A level and the stroke that wins it (points, drawn in order) and a stroke that loses it.

STORIESconstant

The stories, one to a level.

StretchGrabberEntrytype

A level, the waypoints of one way to win it, and of one way to lose it.

TUBE_SORT_LEVELSconstant

The levels, each with more colours and more tubes than the one before.

@johnmorrisdotca/karakuri/play

createControllerfunction

Makes a controller for level level (from 1) of a game; a level out of range is held to the nearest.

defaultThemefunction

The theme without a page: the light one, for a drawing made where there is no style to read (a test, a server).

GameInfotype

What a game of the package is, for a chooser.

Infotype

What the player reads in the bar above the board.

KARAKURI_GAME_IDSconstant

The ids of the games, in the order the package lists them (kebab case, the same in every address and attribute).

KARAKURI_STYLEconstant

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_THEMESconstant

The look the games draw with, as custom properties, so a page can change any of them.

KarakuriMounttype

The native handle, including its controller and focused keyboard canvas.

mountKarakurifunction

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.

MountOptionstype

Initial native controller, level, layout, keyboard, clock and host callbacks.

Pointtype

A place in a game's own world, in its own units (not pixels).

readThemefunction

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.

Saytype

A line of words to be said in the player's language: a key of KARAKURI_STRINGS and the values for its {name}s.

Statustype

How a level stands: still being played, won, or lost.

Themetype

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.

@johnmorrisdotca/karakuri/element

defineBoardfunction

Defines the board or a subclass under a custom tag.

KarakuriBoardclass

A reflected puzzle-game element with a preserved native controller.

@johnmorrisdotca/karakuri/element/define

defineBoardfunction

Defines the board or a subclass under a custom tag.

KarakuriBoardclass

A reflected puzzle-game element with a preserved native controller.

@johnmorrisdotca/karakuri

GameInfotype

What a game of the package is, for a chooser.

Infotype

What the player reads in the bar above the board.

KARAKURI_STRINGSconstant

Native player, keyboard, game and story words in English and Japanese.

Pointtype

A place in a game's own world, in its own units (not pixels).

sayfunction

The words for key in lang, with each {name} filled from values; English when the language has none; the key itself when nobody has.

Saytype

A line of words to be said in the player's language: a key of KARAKURI_STRINGS and the values for its {name}s.

Statustype

How a level stands: still being played, won, or lost.

Themetype

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.

VERSIONconstant

The package's version, kept equal to package.json's by a test.

wordKeyfunction

The key a game's words are kept under: its id with underscores for hyphens (game_tube_sort, rules_tube_sort).