frontispiece / apps / example / view / bootstrap.ts
bootstrap.ts
Raw
import htm from "htm"
import { h } from "preact"
import { Compiler } from "inkjs"
import { createInkHookState } from "@a-morphous/frontispiece-ink-hookstate"
import storyText from "../assets/sandbox.ink"
import { AddRandomLine, Clear, Log, Pause } from "../commands"

export const html = htm.bind(h)

const story = new Compiler(storyText).Compile()

const ink = createInkHookState(story)
export const InkHookStateController = ink.InkHookStateController
export const useInkHookState = ink.useInkHookState

InkHookStateController.registerCommand("pause", Pause)
InkHookStateController.registerCommand("log", Log)
InkHookStateController.registerCommand("clear", Clear)
InkHookStateController.registerCommand("addlines", AddRandomLine)

// listen to commands!
InkHookStateController._engine.events.on('madeChoice', (evt) => {
	console.log("we have made a choice!")
	console.log(evt.data.choice)
})