@oqf/runtime
v0.1.0
Published
Open Quest Format runtime: an engine agnostic quest state machine driven by events, for browsers and Node.
Maintainers
Readme
@oqf/runtime
The Open Quest Format runtime: an engine agnostic quest state machine driven by events. One
emit in, one on out. Runs in the browser and in Node, depends only on @oqf/core.
Usage
import { QuestRuntime } from '@oqf/runtime'
const runtime = new QuestRuntime({
documents: [document], // parsed with @oqf/core
resolveVar: (path) => world.read(path), // serves var.*
eventMap: { 'fish.caught': 'item.collected' }, // engine names to OQF names
})
const unsubscribe = runtime.on((event) => bus.emit(event.name, event.payload))
runtime.load(savegame.quests) // reconciles against the loaded quests
runtime.offer('harbormasters_ledger') // unseen to offered
runtime.accept('harbormasters_ledger') // offered to open, steps start
runtime.emit('item.collected', { item: 'fish.rare', amount: 5 })
runtime.emit({ name: 'guard.caught', payload: {} })
savegame.quests = runtime.save() // copies, safe to persist
unsubscribe()Notes
- Register handlers before the first
emit,offer,acceptorload. The constructor evaluates nothing, so no event is emitted before the game is listening. - A quest with an
unlockcondition is offered automatically when it becomes true. A quest without one waits foroffer. Games with no accept step callacceptimmediately. - A
customobjective never completes on its own. The engine reports it by emittingquest.<questId>.step.<stepId>.customwith{ done: true }. - World level state is not in the state documents. Flags the game set through
flag.setevents are replayed by the game, not restored byload. - When a
repeatquest reaches an outcome its document moves toruntime.historyand a fresh one takes its place.
