Getting Started
Inspired by Twine SugarCube, Choicekit is a lightweight1, headless, framework-agnostic library for building interactive fiction.
Features
Section titled “Features”- Passages and navigation
- State with snapshot-based history
- Saving and loading with versioning, optional compression, and migrations
- Deterministic pseudorandom number generation (PRNG)
- Custom class serialization for richer game objects
- Headless by design (you bring the renderer and UI)
Installation
Section titled “Installation”Install from npm package choicekit.
npm install choicekitpnpm add choicekityarn add choicekitbun add choicekitSample usage
Section titled “Sample usage”Notes on the current API:
- Prefer
ChoicekitEngineBuilderfor ergonomic type-safe setup - Passage content lives on
passage.data
import { ChoicekitEngineBuilder } from "choicekit";
const engine = await new ChoicekitEngineBuilder() .withName("test-story") .withPassages( { name: "Start", data: "You wake up in a quiet room.", tags: ["intro"] }, { name: "Hallway", data: "A long corridor stretches ahead." }, ) .withVars({ playerName: "Dave", inventory: { gold: 123, gems: 12 } }) .build();
engine.setVars((state) => { state.playerName = "Sheep"; state.inventory.gems = 21;});
engine.navigateTo("Hallway");Footnotes
Section titled “Footnotes”-
Less than 8KB after minification and gzip compression ↩