Early development: IFLoom can change until 1.0. What's stable
IFLoom

@ifloom/engine

Every export of @ifloom/engine, the main entry for writing and running a game: its signature and its fields.

Generated from the source of @ifloom/engine and its TSDoc by npm run api-docs. Each export links to the page that explains it, where one does.

ActionCost

Type. Explained in Actions.

A cost a choice or an action declares in its cost, the stats it spends. The engine refuses it while the player has too little of one.

import type { ActionCost } from '@ifloom/engine'
type ActionCost = {
  stats?: Record<string, number>
  reasons?: Record<string, string>
}
FieldTypeOptionalDefaultDescription
statsRecord<string, number>yesThe stats the cost spends, by id, in the order the button lists them.
reasonsRecord<string, string>yesThe refusal lines by stat id, used in place of the stat's own line when the player has too little.

ActionDef

Type. Explained in Actions.

An action the game declares in actions, or one a plugin offers (a location's, an app's). It has the fields of a ButtonDef, the same as a choice.

Taking one with only a command sends that command. One with a cost, effects or once sends { type: 'action', id }, which runs its command, pays its cost and applies its effects. The id is the game's own, or '<plugin>/<id>' for a plugin's. An action with no label is never rendered as a button, so only a choice's command, another action or a hotspot runs it.

import type { ActionDef } from '@ifloom/engine'
type ActionDef = {
  id: string
  label?: string
  labels?: { when?: Condition; label: string }[]
  when?: Condition
  blocked?: Blocked[]
  cost?: ActionCost
  effects?: EffectRef[]
  command?: CommandRef
  once?: Once
  tags?: string[]
  irreversible?: string
  ui?: Ui<ChoiceUi>
}
FieldTypeOptionalDefaultDescription
idstringThe choice's or action's id, unique among its scene's choices or among the actions.
labelstringyesThe button's words, with tokens filled, such as 'Order a tea'. A choice with no label shows its id, and an action with none is never rendered as a button.
labels{ when?: Condition; label: string }[]yesThe button's words that depend on the state, such as "Not today" before you have bought it and "Right." after. The first entry whose when holds wins, and label is the fallback.
whenConditionyesThe condition under which the choice or action is offered and can be taken. Always, if left out.
blockedBlocked[]yesThe rules that refuse it for now. The first entry whose when holds greys the button out with its reason, or leaves it off with hide.
costActionCostyesThe stats it spends. The engine checks them before it runs, lists them on the button and pays them after its command.
effectsEffectRef[]yesThe effects it applies after its cost, in order. A plugin's or the game's effect in the short form does computed work.
commandCommandRefyesThe command the choice or action sends first, a plugin's in the short form or one of the engine's, but never choose. The button is refused with that command's reason while the command would be. An example is { 'devices/open': { id: 'messages' } }. The button's price includes what the command spends.
onceOnceyesThe limit of once a game ({ per: 'game' }) or once a turn ({ per: 'turn' }), counted in state.chosen. Once spent, a choice stays on screen and pays nothing more, and an action is refused, both with reason.
tagsstring[]yesThe tags a UI can style or filter it by. The engine gives them no meaning.
irreversiblestringyesThe warning that it can't be undone, which a UI shows on the button.
uiUi<ChoiceUi>yesThe ui hints carried to its button in the view. See ChoiceUi.

actionOf

Function. Explained in Actions.

Returns the action that { type: 'action', id } runs in this state. Returns undefined when there is none.

A plain id names one of the game's actions. An id of the form '<plugin>/<id>' names a plugin's action, from its action provider, else from the actions it offers now.

import { actionOf, type Game } from '@ifloom/engine'
function actionOf(state: GameState, game: Game, id: string): ActionDef | undefined

Uses: GameState, Game, ActionDef.

Amount

Type. Explained in Amounts.

A number content names that the engine works out when it reads it. Read one with amountOf.

An amount is a number, a stat of the player's by id, a stat with { stat, of? }, a kv key's number with { kv, of? } (a value that is not a number counts as 0), a value by name with { value, with? }, or a count of entities with { count, where? }, counted as the count condition counts. Amounts combine as a Formula does (sum, product, min, max, scale, clamp), with any amount as a part, and of names the owner as it does in conditions.

Effects take one in by and to, ranges in their bounds, stats in min and max, and rolls in plus and against. So { stat: 'coins', gte: { stat: 'rent' } } holds while the player has at least the rent.

import type { Amount } from '@ifloom/engine'
type Amount = number | StatKey | { stat: StatKey; of?: string } | { kv: string; of?: string } | ValueRef | { count: string | Select; where?: Condition } | { sum: Amount[] } | { product: Amount[] } | { min: Amount[] } | { max: Amount[] } | { scale: Amount; by: number } | { clamp: Amount; min?: number; max?: number }

Uses: StatKey, ValueRef, Select, Condition.

amountOf

Function. Explained in Amounts.

Returns an amount worked out in this state. An amount that doesn't read as a finite number gives 0, and so does an owner that isn't there.

An amount is a number, a stat (the player's by id, or { stat, of }), a kv key's number ({ kv, of }), a value by name ({ value, with }), a count of entities ({ count }) or a formula of these.

import { amountOf, type Game } from '@ifloom/engine'
function amountOf(state: GameState, game: Game, amount: Amount): number

Uses: GameState, Game, Amount.

Applied

Type. Explained in Commands.

The answer apply gives for a command, a Result with the state on both sides. When ok is false, the command was refused, state is unchanged and reason says why.

newGame is true when the command was a newGame and state is the new game's first state.

import type { Applied } from '@ifloom/engine'
type Applied = { ok: true; state: GameState; reason?: never; newGame?: true } | { ok: false; state: GameState; reason: string }

Uses: GameState.

apply

Function. Explained in Commands.

Runs a command and returns the next state. A refused command returns the state unchanged, with the reason.

A null state, or a start command, returns the game's starting state.

import { apply, type Game } from '@ifloom/engine'
function apply(state: GameState | null, game: Game, ref: CommandRef): Applied

Uses: GameState, Game, CommandRef, Applied.

applyEffects

Function. Explained in Effects.

Returns the state after a list of effects, the engine's and plugins' short calls alike ({ 'quests/start': { quest: 'bread' } }). A call to an effect no plugin declares is skipped.

A plugin's context.apply runs effects the same way.

import { applyEffects, type Game } from '@ifloom/engine'
function applyEffects(state: GameState, game: Game, effects: readonly EffectRef[]): GameState

Uses: GameState, Game, EffectRef.

artSrc

Function. Explained in Prose and markup.

Returns a picture's or video's path in the game's art/ folder, relative to the page. A URL (https:, data:, //host/…) is returned unchanged.

'photo/ava.svg' and 'art/photo/ava.svg' both give 'art/photo/ava.svg'. A name with no extension gets .jpg, or .mp4 when type is 'video'.

import { artSrc } from '@ifloom/engine'
function artSrc(path: string, type?: 'image' | 'video'): string

AudioChannelView

Type. Explained in Audio.

An audio channel as the audio player needs it, in view.audio.channels.

import type { AudioChannelView } from '@ifloom/engine'
type AudioChannelView = {
  mode: 'background' | 'cue'
  track: string | null
  src: string | null
  loop: boolean
  volume: number
  volumeSetting: string | null
  crossfade: number
  duck: { under: string[]; to: number } | null
  playlist?: { tracks: string[]; srcs: string[]; volumes: number[]; order: 'inOrder' | 'loop' | 'shuffle' }
}
FieldTypeOptionalDefaultDescription
mode'background' | 'cue'The channel's mode. background plays a track or playlist until it changes, and cue plays one-shot sounds, listed in cues.
trackstring | nullThe id of the track or playlist playing. Null for silence, and always null on a cue channel.
srcstring | nullThe file to play, through audioSrc, a playlist's first. Null for silence.
loopbooleanThe channel's loop mark, true when the track repeats. A playlist repeats as a whole unless its order is 'inOrder'.
volumenumberThe track's own volume, from 0 to 1, or a playlist's first track's. The player multiplies it by the volume setting's value.
volumeSettingstring | nullThe id of the ui setting that sets the channel's volume. Null when there's none.
crossfadenumberThe milliseconds to fade between tracks. 0 on a cue channel.
duck{ under: string[]; to: number } | nullThe channel's ducking, quietening it to to (0 to 1) while any channel in under plays. Null when it doesn't duck.
playlist{ tracks: string[]; srcs: string[]; volumes: number[]; order: 'inOrder' | 'loop' | '…yesThe playlist's tracks, files, volumes and order, already shuffled when it shuffles. Left out for a single track.

AudioCue

Type. Explained in Audio.

A one-shot sound that is due, in view.audio.cues. The audio player plays each key once.

import type { AudioCue } from '@ifloom/engine'
type AudioCue = {
  key: string
  channel: string
  track: string
  src: string
  volume: number
}
FieldTypeOptionalDefaultDescription
keystringThe cue's key, the same for the same sound in the same visit across view calls and reloads.
channelstringThe cue channel the sound plays on, sfx or voice unless the game declares others.
trackstringThe track's id in audio.tracks.
srcstringThe file to play, through audioSrc.
volumenumberThe track's own volume, from 0 to 1. The player multiplies it by the channel's volume setting.

audioSrc

Function. Explained in Audio.

Returns a sound file's path relative to the page, under audio/. A bare name gets .ogg.

Like artSrc, the path is relative and never starts with /.

import { audioSrc } from '@ifloom/engine'
function audioSrc(path: string): string

AudioState

Type. Explained in Audio.

The audio a save keeps, in state.audio. The engine reads the tracks and channels from content.

import type { AudioState } from '@ifloom/engine'
type AudioState = {
  channels: Record<string, string | null>
  cues: { seq: number; track: string }[]
  seq: number
  shown: number
  started: Record<string, { track: string; turn: number }>
}
FieldTypeOptionalDefaultDescription
channelsRecord<string, string | null>The tracks audio effects have put on background channels, by channel. Null is silence, and a channel missing here is left to the scene, the plugins and the defaults.
cues{ seq: number; track: string }[]The last 20 sound effects, oldest first, each with its number in the running count.
seqnumberThe number of sound effects there have been.
shownnumberThe number of times a scene has been entered, all scenes together. Each visit's sounds get keys of their own from it.
startedRecord<string, { track: string; turn: number }>The track each background channel is playing and the turn it started, for a shuffled playlist's draw.

AudioView

Type. Explained in Audio.

The audio as the audio player needs it, in view.audio. It's empty when the game has no audio.

import type { AudioView } from '@ifloom/engine'
type AudioView = {
  channels: Record<string, AudioChannelView>
  cues: AudioCue[]
  muteSetting: string | null
  soundSetting: string | null
}
FieldTypeOptionalDefaultDescription
channelsRecord<string, AudioChannelView>Every channel with its track resolved, from the open scene, then an effect, then a plugin, then the game's default.
cuesAudioCue[]The sounds that are due, from sound effects and the open scene's sound and voice beats, in order.
muteSettingstring | nullThe id of the ui setting that mutes everything while it's on. Null when there's none.
soundSettingstring | nullThe id of the ui setting that mutes everything while it's off. Null when there's none.

AutosaveOptions

Type. Explained in The runner.

Settings for autosave, when the runner saves on its own. Autosave is off unless createRunner is given these.

import type { AutosaveOptions } from '@ifloom/engine'
type AutosaveOptions = {
  slot?: string
  every: 'command' | 'scene' | 'turn'
}
FieldTypeOptionalDefaultDescription
slotstringyesThe slot autosave writes to. 'auto' if left out.
every'command' | 'scene' | 'turn'The moment autosave writes, after every command or only when the scene or the turn changes. It skips a save while the game's saveable refuses saving.

BacklogEntry

Type. Explained in The runner.

One scene of the backlog, as the player saw it. The backlog keeps scenes only, never the room or a minigame.

import type { BacklogEntry } from '@ifloom/engine'
type BacklogEntry = {
  turn: number
  when: string | null
  sceneId: string
  title: string
  beats: SceneBeat[]
  chose?: string
}
FieldTypeOptionalDefaultDescription
turnnumberThe turn the scene was shown in.
whenstring | nullThe time in the game when the scene was shown, from view.when, or null when no plugin gives one.
sceneIdstringThe scene's id.
titlestringThe scene's title as it was shown.
beatsSceneBeat[]The scene's beats as the player read them.
chosestringyesThe label of the choice the player made in the scene, once they made one. A choice at a decision of a flow shows in beats instead.

BacklogOptions

Type. Explained in The runner.

Settings for the backlog, the list of scenes the player has seen with the choice made in each. The backlog is off unless createRunner is given these or true.

import type { BacklogOptions } from '@ifloom/engine'
type BacklogOptions = {
  limit?: number
}
FieldTypeOptionalDefaultDescription
limitnumberyesThe number of entries the backlog keeps, dropping the oldest. 200 if left out.

BeatSize

Type. Explained in Prose and markup.

The width of an image or video beat, inline in the column with the words or wide across it.

import type { BeatSize } from '@ifloom/engine'
type BeatSize = 'inline' | 'wide'

Block

Type. Explained in Scenes.

One entry of a scene's body, told apart by its key, such as { text }, { say } or { decide }. A block with a when is left out while it fails.

The body is composed from blocks rather than read whole from one prose key. So a conditional line is one more block, and each block's words mean one thing.

import type { Block } from '@ifloom/engine'
type Block = ({ text: string; id?: string; when?: Condition } | { prose: string; when?: Condition } | { variants: string; when?: Condition; gate?: Record<string, Condition>; image?: Record<string, string> } | { media: SceneMedia; when?: Condition } | { say: string; speaker: string; voice?: string; id?: string; when?: Condition } | { blocks: Block[]; when?: Condition } | { cases: Block[]; when?: Condition } | { decide: string; choices: FlowChoice[]; when?: Condition } | { point: string; when?: undefined } | { minigame: string; when?: Condition } | { panel: string; with?: PluginArgs; when?: Condition }) & { ui?: Ui<BlockUi> }

Uses: Condition, SceneMedia, FlowChoice, PluginArgs, Ui, BlockUi.

Blocked

Type. Explained in Actions.

A rule that refuses a choice, an action, a location or an app while its when holds. The first entry of a blocked list whose when holds gives the reason the button shows.

import type { Blocked } from '@ifloom/engine'
type Blocked = {
  when: Condition
  reason: Reason
  hide?: boolean
}
FieldTypeOptionalDefaultDescription
whenConditionThe rule's condition, which refuses the choice or action while it holds.
reasonReasonThe rule's reason, which the player reads on the greyed-out button and as the refusal.
hidebooleanyesThe rule's hide mark. When true, the button is left off the screen while when holds, rather than greyed out.

BlockExtras

Type. Explained in Flowing scenes.

The fields any block can have beside its own, a condition and ui hints.

import type { BlockExtras } from '@ifloom/engine'
type BlockExtras = {
  when?: Condition
  ui?: Ui<BlockUi>
}
FieldTypeOptionalDefaultDescription
whenConditionyesThe block's condition, which leaves it out while it fails.
uiUi<BlockUi>yesThe block's ui hints. See BlockUi.

BlockUi

Type. Explained in Presentation hints.

The ui hints a block of a scene's body takes in its ui, carried on the first beat the block makes. The engine declares none, and a UI package augments this interface with its own.

import type { BlockUi } from '@ifloom/engine'
type BlockUi = {

  // …
}

Plugins add fields of their own to it, which their pages list.

BrokenSave

Type. Explained in Saves.

A save in a slot that can't be read, as list() gives it. The listing keeps it so the player can delete it.

import type { BrokenSave } from '@ifloom/engine'
type BrokenSave = {
  slot: string
  broken: string
}
FieldTypeOptionalDefaultDescription
slotstringThe broken save's slot.
brokenstringThe reason the save can't be read, in the words read would give.

buildEffects

Function. Explained in Calls by name.

Returns the effects ready for the reducer, without the calls no plugin or game has. The content checker (checkGame) reports each call it leaves out.

Every other effect stays as written. A call runs in its turn, on the state the effects before it left.

import { buildEffects, type Game } from '@ifloom/engine'
function buildEffects(game: Game, refs: readonly EffectRef[]): Effect[]

Uses: Game, EffectRef, Effect.

ButtonDef

Type. Explained in Actions.

The fields a scene's choice (Choice) and an action (ActionDef) share, read the same way for both. Taking one runs its command, then pays its cost, then applies its effects.

import type { ButtonDef } from '@ifloom/engine'
type ButtonDef = {
  id: string
  label?: string
  labels?: { when?: Condition; label: string }[]
  when?: Condition
  blocked?: Blocked[]
  cost?: ActionCost
  effects?: EffectRef[]
  command?: CommandRef
  once?: Once
  tags?: string[]
  irreversible?: string
  ui?: Ui<ChoiceUi>
}
FieldTypeOptionalDefaultDescription
idstringThe choice's or action's id, unique among its scene's choices or among the actions.
labelstringyesThe button's words, with tokens filled, such as 'Order a tea'. A choice with no label shows its id, and an action with none is never rendered as a button.
labels{ when?: Condition; label: string }[]yesThe button's words that depend on the state, such as "Not today" before you have bought it and "Right." after. The first entry whose when holds wins, and label is the fallback.
whenConditionyesThe condition under which the choice or action is offered and can be taken. Always, if left out.
blockedBlocked[]yesThe rules that refuse it for now. The first entry whose when holds greys the button out with its reason, or leaves it off with hide.
costActionCostyesThe stats it spends. The engine checks them before it runs, lists them on the button and pays them after its command.
effectsEffectRef[]yesThe effects it applies after its cost, in order. A plugin's or the game's effect in the short form does computed work.
commandCommandRefyesThe command the choice or action sends first, a plugin's in the short form or one of the engine's, but never choose. The button is refused with that command's reason while the command would be. An example is { 'devices/open': { id: 'messages' } }. The button's price includes what the command spends.
onceOnceyesThe limit of once a game ({ per: 'game' }) or once a turn ({ per: 'turn' }), counted in state.chosen. Once spent, a choice stays on screen and pays nothing more, and an action is refused, both with reason.
tagsstring[]yesThe tags a UI can style or filter it by. The engine gives them no meaning.
irreversiblestringyesThe warning that it can't be undone, which a UI shows on the button.
uiUi<ChoiceUi>yesThe ui hints carried to its button in the view. See ChoiceUi.

callOf

Function. Explained in Calls by name.

Returns the name and arguments of a call in the short form, or undefined for the engine's own conditions and effects. A plugin's guard or price uses it to read effects.

{ 'calendar/pass': { by: 2 } } gives { name: 'calendar/pass', with: { by: 2 } }.

import { callOf } from '@ifloom/engine'
function callOf(entry: object): { name: string; with: Record<string, unknown> } | undefined

CarryOver

Type. Explained in Game state.

The stats and kv keys a New Game+ carries over from the game before, declared in carryOver. A plugin carries its own state with its carry.

import type { CarryOver } from '@ifloom/engine'
type CarryOver = {
  stats?: string[]
  kv?: string[]
}
FieldTypeOptionalDefaultDescription
statsstring[]yesThe player's stats to carry, by id.
kvstring[]yesThe player's kv keys to carry, by key.

cases

Function. Explained in Flowing scenes.

Returns a { cases } block that shows only the first of blocks whose own when holds, or that has none. Leave the last without a when as the fallback.

A when in extras leaves the whole block out while it fails.

cases([
  text(`Rain streaks the window.`, { when: { kv: 'rain' } }),
  text(`Ava's umbrella is by the door.`, { when: { kv: 'cloudy' } }),
  text(`The street is dry.`),
])
import { cases } from '@ifloom/engine'
function cases(blocks: Block[], extras?: BlockExtras): Block

Uses: Block, BlockExtras.

chance

Function. Explained in Randomness.

Returns true numerator times in outOf, drawn from parts.

import { chance } from '@ifloom/engine'
function chance(numerator: number, outOf: number, ...parts: (string | number)[]): boolean

Change

Type. Explained in Changes.

A stat the last command moved, with its old and new values and the change in the stat's own format. state.changes keeps these.

import type { Change } from '@ifloom/engine'
type Change = {
  stat: string
  of?: EntityRef
  from: number
  to: number
  by: number
  label: string
  text: string
}
FieldTypeOptionalDefaultDescription
statstringThe stat's id.
ofEntityRefyesThe entity the stat is kept on. Left out for the player's stat.
fromnumberThe stat's value before the command.
tonumberThe stat's value after the command.
bynumberThe amount the stat moved, to - from, above 0 when it went up.
labelstringThe stat's label.
textstringThe change in the stat's format, signed, such as '+30 coins' or '-£5'.

ChangesDef

Type. Explained in Changes.

The stats the game declares in changes for view.changes to track, by id. An entity stat's id covers that stat on every entity.

import type { ChangesDef } from '@ifloom/engine'
type ChangesDef = {
  stats: string[]
}
FieldTypeOptionalDefaultDescription
statsstring[]The ids of the stats to track.

ChangeView

Type. Explained in Changes.

A stat change as the player sees it, in view.changes. It adds the words that say what moved to a Change.

import type { ChangeView } from '@ifloom/engine'
type ChangeView = {
  stat: string
  of?: EntityRef
  from: number
  to: number
  by: number
  label: string
  text: string
  name?: string
}
FieldTypeOptionalDefaultDescription
statstringThe stat's id.
ofEntityRefyesThe entity the stat is kept on. Left out for the player's stat.
fromnumberThe stat's value before the command.
tonumberThe stat's value after the command.
bynumberThe amount the stat moved, to - from, above 0 when it went up.
labelstringThe stat's label.
textstringThe change in the stat's format, signed, such as '+30 coins' or '-£5'.
namestringyesThe words to show after text, so the change says what moved. Left out when the stat's format already says it (+30 coins). It's the entity's name for an entity's stat (+4 Ava), else the stat's label when text has no words in it (+1 Charm, +20% Mood).

ChannelDef

Type. Explained in Audio.

An audio channel the game declares in audio.channels, merged over the default channels. It sets whether its sounds replace each other or overlap, and how they fade.

import type { ChannelDef } from '@ifloom/engine'
type ChannelDef = {
  mode: 'background' | 'cue'
  crossfade?: number
  volume?: string
  duck?: { under: string[]; to: number }
}
FieldTypeOptionalDefaultDescription
mode'background' | 'cue'The channel's mode. A background channel plays one thing until it changes, and a cue channel plays each sound once, overlapping.
crossfadenumberyesThe milliseconds a background channel takes to fade from one track to the next. 1000 for music, 600 for ambience and 1000 for others.
volumestringyesThe id of the ui setting, a range, that sets the channel's volume.
duck{ under: string[]; to: number }yesThe channel's ducking, quietening it to to (0 to 1) while any channel in under plays. No ducking if left out.

Checked

Type. Explained in Checking content.

The report checkGame returns, with the content's problems, warnings and files.

import type { Checked } from '@ifloom/engine'
type Checked = {
  problems: Problem[]
  warnings: Problem[]
  files: FileRef[]
}
FieldTypeOptionalDefaultDescription
problemsProblem[]The content's faults, such as a broken reference, a key declared twice, or a call with the wrong arguments. Any problem fails ifloom check.
warningsProblem[]The faults that may show in play but aren't problems, such as a token that may be unset with no fallback. A warning fails no check.
filesFileRef[]The files the content names (pictures, videos, sounds) and where, for a build to check they exist.

checkGame

Function. Explained in Checking content.

Returns the Checked report of a game's content, its problems, warnings and the files it names. It runs on any Game, hand-built or loaded.

Give probes to also render every scene against each state, so the report includes a scene that throws for one through the game's own conditions or values. A hand-built game's problems name the pack game.

import { checkGame, type Game } from '@ifloom/engine'
function checkGame(game: Game, options?: { probes?: readonly Probe[] }): Checked

Uses: Game, Probe, Checked.

Choice

Type. Explained in Scenes.

A choice a scene declares in its choices or a decision, with the fields of a ButtonDef. The player sends it as { type: 'choose', id }, and state.chosen counts it as <scene>#<id>.

A spent once choice stays on screen with its once.reason and pays nothing more.

import type { Choice } from '@ifloom/engine'
type Choice = {
  id: string
  label?: string
  labels?: { when?: Condition; label: string }[]
  when?: Condition
  blocked?: Blocked[]
  cost?: ActionCost
  effects?: EffectRef[]
  command?: CommandRef
  once?: Once
  tags?: string[]
  irreversible?: string
  ui?: Ui<ChoiceUi>
}
FieldTypeOptionalDefaultDescription
idstringThe choice's or action's id, unique among its scene's choices or among the actions.
labelstringyesThe button's words, with tokens filled, such as 'Order a tea'. A choice with no label shows its id, and an action with none is never rendered as a button.
labels{ when?: Condition; label: string }[]yesThe button's words that depend on the state, such as "Not today" before you have bought it and "Right." after. The first entry whose when holds wins, and label is the fallback.
whenConditionyesThe condition under which the choice or action is offered and can be taken. Always, if left out.
blockedBlocked[]yesThe rules that refuse it for now. The first entry whose when holds greys the button out with its reason, or leaves it off with hide.
costActionCostyesThe stats it spends. The engine checks them before it runs, lists them on the button and pays them after its command.
effectsEffectRef[]yesThe effects it applies after its cost, in order. A plugin's or the game's effect in the short form does computed work.
commandCommandRefyesThe command the choice or action sends first, a plugin's in the short form or one of the engine's, but never choose. The button is refused with that command's reason while the command would be. An example is { 'devices/open': { id: 'messages' } }. The button's price includes what the command spends.
onceOnceyesThe limit of once a game ({ per: 'game' }) or once a turn ({ per: 'turn' }), counted in state.chosen. Once spent, a choice stays on screen and pays nothing more, and an action is refused, both with reason. The choice's limit of once a game or once a turn. See Once.
tagsstring[]yesThe tags a UI can style or filter it by. The engine gives them no meaning.
irreversiblestringyesThe warning that it can't be undone, which a UI shows on the button.
uiUi<ChoiceUi>yesThe ui hints carried to its button in the view. See ChoiceUi.

choice

Function. Explained in Flowing scenes.

Returns a choice for a decision or a scene's ending choices, with label as its words. Its id is unique within the scene.

Every other field of a Choice goes in fields, such as effects, cost, blocked, once or command, and then, the blocks the flow shows once the player chooses it.

import { choice } from '@ifloom/engine'
function choice(id: string, label: string, fields?: Omit<FlowChoice, 'id' | 'label'>): FlowChoice

Uses: FlowChoice.

ChoiceUi

Type. Explained in Presentation hints.

The ui hints a choice or an action takes in its ui. The engine declares none, and a UI package augments this interface with its own.

import type { ChoiceUi } from '@ifloom/engine'
type ChoiceUi = {

  // …
}

Plugins add fields of their own to it, which their pages list.

clampStat

Function. Explained in Stats.

Returns value held to the stat's declared range. The range is 0 to 100 unless the stat declares one.

import { clampStat, type Game } from '@ifloom/engine'
function clampStat(state: GameState, game: Game, id: string, value: number): number

Uses: GameState, Game.

Command

Type. Explained in Commands.

A request to change the game, told apart by its type, such as { type: 'choose', id }. The reducer applies it or refuses it.

import type { Command } from '@ifloom/engine'
type Command =
  | { type: 'setting'; id: string; to: KvValue; }
  | { type: 'scene'; id: string; }
  | { type: 'action'; id: string; }
  | { type: 'input'; id: string; to?: KvValue; }
  | { type: 'minigame'; input: string; }
  | { type: 'start'; seed?: number; kv?: Record<string, KvValue>; }
  | { type: 'newGame'; }
  | { type: 'custom'; name: string; with?: Record<string, unknown>; }
  | { type: 'dismiss'; id?: string; }
  | { type: 'choose'; id: string; }
  | { type: 'leave'; }
  | { type: 'tick'; ms: number; }
  | { type: 'closePanel'; }

Uses: KvValue.

CommandCall

Type. Explained in Declaring a plugin's calls.

A plugin's or the game's command in the short form, type-checked against CommandRegistry.

import type { CommandCall } from '@ifloom/engine'
type CommandCall = CallIn<CommandRegistry>

Uses: CallIn, CommandRegistry.

CommandLog

Type. Explained in The runner.

A record of play, the state it started from and every command since. The engine is deterministic, so replay gives the same state from it every time.

A log makes a bug report a developer can step through, or plays two versions of a game the same way to compare them.

import type { CommandLog } from '@ifloom/engine'
type CommandLog = {
  game: string
  start: GameState
  commands: Command[]
  schema?: number
  plugins?: Record<string, number>
}
FieldTypeOptionalDefaultDescription
gamestringThe id of the game the log was played in, so it isn't played against another game.
startGameStateThe state the log's first command was applied to.
commandsCommand[]The log's commands, oldest first, refused ones included.
schemanumberyesThe engine's SCHEMA the log's commands were written in. A log without one is read as the oldest schema.
pluginsRecord<string, number>yesThe commandVersion of each plugin the log's commands were written in, by plugin id.

commandOf

Function. Explained in Calls by name.

Returns the command the engine runs for ref. A short-form call becomes { type: 'custom', name, with }.

import { commandOf } from '@ifloom/engine'
function commandOf(ref: CommandRef): Command

Uses: CommandRef, Command.

CommandRef

Type. Explained in Calls by name.

A command in content, a plain command or a plugin's in the short form ({ 'places/go': { id: 'cafe' } }), checked against CommandRegistry.

import type { CommandRef } from '@ifloom/engine'
type CommandRef = Command | CommandCall

Uses: Command, CommandCall.

CommandRegistry

Type. Explained in Declaring a plugin's calls.

The registry of commands plugins and the game add, by full name, with each one's arguments. It works as ConditionRegistry does.

import type { CommandRegistry } from '@ifloom/engine'
type CommandRegistry = {

  // …
}

Plugins add fields of their own to it, which their pages list.

Condition

Type. Explained in Conditions.

A test of the state that holds or doesn't, written as plain data on a block, a choice or a variants member. Each kind is told apart by its one key, such as { stat: 'coins', gte: 3 }.

A plugin's condition, or the game's own from its rules, is a PluginCall in the short form ({ 'quests/done': { quest: 'bakery' } }), checked against ConditionRegistry when its name is declared there. Being data, a condition stays serialisable and the content checker can check it.

import type { Condition } from '@ifloom/engine'
type Condition =
  | { kv: string; is?: KvValue | readonly KvValue[]; of?: string; } & Range
  | { all: Condition[]; }
  | { any: Condition[]; }
  | { not: Condition; }
  | { count: string | Select; where?: Condition; } & Range
  | { entity: string; }
  | { owned: string; of?: string; via?: string; } & Range
  | { turn: Range; }
  | { value: string; with?: PluginArgs; is?: KvValue | readonly KvValue[]; } & Range
  | { storyline: string; open?: boolean; }
  | { setting: string; is?: KvValue; } & Range
  | { stat: string; of?: string; } & Range
  | { level: string; of?: string; } & Range
  | { chose: string; } & Range
  | { seen: string; } & Range
  | { since: string; last?: boolean; } & Range
  | { scene: string[]; }
  | { timer: string; } & Range
  | { roll: string; passed?: boolean; critical?: boolean | 'max' | 'min'; }
  | ConditionCall

Uses: KvValue, Range, Select, PluginArgs, ConditionCall.

ConditionCall

Type. Explained in Declaring a plugin's calls.

A plugin's or the game's condition in the short form, type-checked against ConditionRegistry.

import type { ConditionCall } from '@ifloom/engine'
type ConditionCall = CallIn<ConditionRegistry>

Uses: CallIn, ConditionRegistry.

ConditionRegistry

Type. Explained in Declaring a plugin's calls.

The registry of conditions plugins and the game add, by full name, with each one's arguments, or true for none. A plugin augments it, and a call to a declared name is type-checked against it.

declare module '@ifloom/engine' {
  interface ConditionRegistry {
    'quests/done': { quest: string }
    'calendar/weekend': true
  }
}
import type { ConditionRegistry } from '@ifloom/engine'
type ConditionRegistry = {

  // …
}

Plugins add fields of their own to it, which their pages list.

Content

Type. Explained in Content and packs.

One file of the game's own content, such as story/cafe.ts. Each scene, stat or prose key may be declared only once across the game's content.

Content has no id or schema, since it is compiled with the engine it runs on.

type Content = {
  name?: string
  strings?: Record<string, string>
  prose?: Record<string, string>
  words?: Record<string, string>
  variants?: Record<string, VariantMember[]>
  data?: Record<string, Record<string, readonly PluginEntry[]>>
  kinds?: KindDef[]
  entities?: EntityDef[]
  traits?: TraitTable
  player?: PlayerDef | undefined
  kv?: Record<string, KvValue>
  resets?: Record<string, KvValue>
  storylines?: StorylineDef[]
  actions?: ActionDef[]
  triggers?: TriggerDef[]
  inputs?: InputDef[]
  settings?: SettingDef[]
  stats?: StatDef[]
  introScene?: string
  scenes?: DataScene[]
  minigames?: MinigameDef[]
  timers?: TimerDef[]
  audio?: Partial<GameAudio>
  media?: GameMedia
  ui?: Ui<GameUi>
  saveable?: Blocked[]
  locks?: Lock[]
  phrases?: Phrases
  changes?: ChangesDef
  carryOver?: CarryOver
  finished?: Condition
  credits?: CreditGroup[]
}
FieldTypeOptionalDefaultDescription
namestringyesThe content's name in problems, such as story.cafe. content if left out.
stringsRecord<string, string>yesThe lines that replace the engine's and plugins' strings, by key.
proseRecord<string, string>yesThe prose keys' lines, by key.
wordsRecord<string, string>yesThe words table, other words for the fields a player reads, by key. A translation is one pack with this table and its own prose. Each key names one field, as translatableFields lists them (action.wait.label, entity.character:ava.name, scene.cafe.counter.text.intro). loadGame lays it over the merged content, a later pack's over an earlier one's, and reports a key that names no field.
variantsRecord<string, VariantMember[]>yesThe variants lists' members by list name, in order. Content and packs append to a list. A member is a prose key, or { prose: key, weight } to be drawn more or less often than the rest.
dataRecord<string, Record<string, readonly PluginEntry[]>>yesThe plugins' content, by plugin id and then list, such as { quests: { quests: [...] } }. A pack's entry replaces the one with the same id, as its scenes do.
kindsKindDef[]yesThe pack's kinds. A later pack's kind replaces an earlier one with the same id.
entitiesEntityDef[]yesThe pack's entities at the start. A later pack's entity replaces an earlier one with the same kind and id.
traitsTraitTableyesThe pack's traits, by trait id and then entity, over what each entity declares itself, such as { 'laundry/washable': { 'clothing:scarf': { temp: 30 } } }. A later pack's row replaces an earlier one's.
playerPlayerDef | undefinedyesThe pack's player. It replaces the content's player whole.
kvRecord<string, KvValue>yesThe pack's starting kv store, by key. A later pack's value replaces an earlier one's.
resetsRecord<string, KvValue>yesThe pack's keys reset each turn, by key. A later pack's value replaces an earlier one's.
storylinesStorylineDef[]yesThe pack's storylines, merged by id over the content's.
actionsActionDef[]yesThe pack's actions, by id. A later pack's action replaces an earlier one with the same id.
triggersTriggerDef[]yesThe pack's triggers, merged by id over the content's.
inputsInputDef[]yesThe pack's inputs, merged by id over the content's.
settingsSettingDef[]yesThe pack's settings. A later pack's setting replaces an earlier one with the same id.
statsStatDef[]yesThe pack's stats. A later pack's stat replaces an earlier one with the same id.
introScenestringyesThe scene open on the first frame. A later pack's replaces an earlier one's.
scenesDataScene[]yesThe pack's scenes. A later pack's scene replaces an earlier one with the same id.
minigamesMinigameDef[]yesThe pack's minigames. A later pack's minigame replaces an earlier one with the same id.
timersTimerDef[]yesThe pack's timers. A later pack's timer replaces an earlier one with the same id.
audioPartial<GameAudio>yesThe pack's tracks, channels and defaults, over the content's. A later pack's track or channel replaces an earlier one with the same id, and its mute, sound and default entries win too.
mediaGameMediayesThe pack's pools of pictures and videos. A later pack's pool replaces an earlier one with the same id, files and all.
uiUi<GameUi>yesThe pack's ui hints for the whole game, merged hint by hint. A later pack's hint replaces an earlier one's, and the rest stay.
saveableBlocked[]yesThe pack's reasons to refuse saving, added after the content's. An entry with the id of an earlier one replaces it.
locksLock[]yesThe pack's locks, added after the content's. A lock with the id of an earlier one replaces it.
phrasesPhrasesyesThe pack's phrases, words that change with the state, printed in a line as {{name}}. Each is a plain string or a list of { when?, text } rows tried in order, and an object is a group. A later pack's phrase replaces an earlier one with the same full name, and a pack can add phrases to a group.
changesChangesDefyesThe pack's tracked stats, by id, such as { stats: ['coins', 'trust'] }. The engine adds every file's and pack's lists together.
carryOverCarryOveryesThe pack's rules for a New Game+. They replace the content's carryOver whole.
finishedConditionyesThe pack's condition for the game being finished. It replaces the content's, and the runner records the first time it holds in the profile's core:finished.
creditsCreditGroup[]yesThe pack's credits, in groups. A group whose id is already declared gets these credits after its own. Its title or description replaces the earlier one, and a new id adds a group after the others.

CreatedEntity

Type. Explained in Effects.

The fields a create effect gives a new entity in its with. The engine reads each one left out from the entity it's made like, else from its kind.

import type { CreatedEntity } from '@ifloom/engine'
type CreatedEntity = {
  id?: string
  name?: string
  description?: string
  image?: string
  tags?: string[]
  traits?: Record<string, unknown>
  stats?: Record<string, number>
  kv?: Record<string, KvValue>
}
FieldTypeOptionalDefaultDescription
idstringyesThe entity's id within its kind. The next free number (#1, #2) if left out.
namestringyesThe entity's name. The like entity's if left out.
descriptionstringyesThe entity's description, with tokens filled when it's read. The like entity's if left out.
imagestringyesThe entity's picture, through artSrc. The like entity's if left out.
tagsstring[]yesThe entity's own tags, after its kind's and its like entity's.
traitsRecord<string, unknown>yesThe entity's trait data, by trait id, over its like entity's or its kind's.
statsRecord<string, number>yesThe entity's starting stats, over its like entity's.
kvRecord<string, KvValue>yesThe entity's starting kv keys, over its like entity's.

CreateFields

Type. Explained in Effects.

The fields a create effect takes besides its kind.

import type { CreateFields } from '@ifloom/engine'
type CreateFields = {
  like?: string
  with?: CreatedEntity
  effects?: EffectRef[]
}
FieldTypeOptionalDefaultDescription
likestringyesThe entity of the same kind the new one reads what it isn't given from.
withCreatedEntityyesThe new entity's fields, its id, name, description, picture, tags, traits, stats and kv.
effectsEffectRef[]yesEffects that run once the entity is made, with '$' as it, such as [{ receive: '$' }] to hand it over.

createRunner

Function. Explained in The runner.

Returns a Runner that plays a game from a start state. Undo, the backlog, saving, autosave and the profile are off unless RunnerOptions turns them on.

The runner wraps apply with undo and redo, a backlog, a command log, saving, loading and autosave, and tells listeners when the state changes.

import { createRunner, type Game } from '@ifloom/engine'
function createRunner(game: Game, start: GameState, options?: RunnerOptions): Runner

Uses: Game, GameState, RunnerOptions, Runner.

Credit

Type. Explained in Credits.

One credit in a group, such as a person, a studio or a source the game thanks. Only name is needed.

import type { Credit } from '@ifloom/engine'
type Credit = {
  name: string
  role?: string
  description?: string
  href?: string
  licence?: string
  art?: string
}
FieldTypeOptionalDefaultDescription
namestringThe person, studio or source credited, as the credits page shows it. It's a name, so a translation leaves it alone.
rolestringyesThe credit's role, the part they played or gave, such as 'Writer', 'Cover photograph' or 'Gold patron'.
descriptionstringyesA line more about the credit, such as 'The harbour at dawn, via Unsplash'.
hrefstringyesA link to them or to the source, http:, https: or mailto:.
licencestringyesThe licence the work is used under, such as 'CC BY 4.0'.
artstringyesThe path of a picture beside the credit, such as a portrait or the credited image itself.

CreditGroup

Type. Explained in Credits.

A group of credits the game declares in credits, such as the team or the patrons, shown under its title in order.

import type { CreditGroup } from '@ifloom/engine'
type CreditGroup = {
  id: string
  title: string
  description?: string
  credits: Credit[]
}
FieldTypeOptionalDefaultDescription
idstringThe group's id. Content and packs that name the same id add to one group.
titlestringThe group's heading, such as 'Patrons'.
descriptionstringyesA line under the heading, such as 'With thanks to everyone on Patreon'.
creditsCredit[]The group's credits, in order.

creditsOf

Function. Explained in Credits.

Returns the game's credit groups that have at least one credit, in order, as a credits page shows them. Empty when the game credits no one.

import { creditsOf, type Game } from '@ifloom/engine'
function creditsOf(game: Pick<Game, 'credits'>): readonly CreditGroup[]

Uses: Game, CreditGroup.

CustomContext

Type. Explained in Calls by name.

The context every plugin or game function gets beside the state, with the game, queries, values and seeded draws. PluginContext extends it.

import type { CustomContext, Game } from '@ifloom/engine'
type CustomContext = {
  game: Game
  query: Query
  value: (name: string, args?: PluginArgs) => string | number | undefined
  roll: (max: number, name: string) => number
}
FieldTypeOptionalDefaultDescription
gameGameThe context's loaded game.
queryQueryThe context's query function, which asks a plugin or the game by full name (query('loyalty/stampsLeft')).
value(name: string, args?: PluginArgs) => string | number | undefinedThe context's value function, which returns a value by full name, a plugin's (messages/unread) or the game's, asked with args. It returns undefined when no plugin or game has that value.
roll(max: number, name: string) => numberThe context's roll function, which returns a whole number from 0 to max - 1, drawn from the save's seed, the turn and name. The same save and turn always draw the same number.

DataScene

Type. Explained in Scenes.

A scene the game declares in scenes, with its body and its choices. Its id is unique across the game.

import type { DataScene } from '@ifloom/engine'
type DataScene = {
  drawnFrom?: string[]
  weight?: number
  when?: Condition
  minigame?: string
  id: string
  title?: string
  speaker?: string
  tags?: string[]
  panel?: ScenePanel
  audio?: Record<string, string | null>
  picture?: PictureDef
  ui?: Ui<SceneUi>
  body: Block[]
  choices: Choice[]
}
FieldTypeOptionalDefaultDescription
drawnFromstring[]yesThe sets the scene can be drawn from, by name, such as ['cafe']. A { scene: { from: 'cafe' } } effect draws one of the scenes that name 'cafe' here. It's separate from tags, which only style the scene.
weightnumberyesThe scene's weight in a draw, against the other scenes it could be drawn with. 1 if left out, and it needs drawnFrom.
whenConditionyesThe storylet's condition. The scene can be drawn only while it holds, but a scene command or effect that names the scene opens it regardless.
minigamestringyesThe id of the minigame that starts when the scene is entered. The scene shows again once it ends.
idstringThe scene's id, unique across the game, such as 'cafe.counter'.
titlestringyesThe scene's title, in view.scene.title. The room's title, else the game's, if left out.
speakerstringyesThe scene's speaker, by entity id or reference ('ava', 'character:ava'), in view.scene.speaker and view.scene.image.
tagsstring[]yesThe tags a UI can style the scene by, such as ['letter'] or ['flashback']. The engine gives them no meaning.
panelScenePanelyesThe panel held open for as long as the scene is, such as { panel: 'counter', with: { vendor: 'cafe' } }. It is view.panel, as one the panel effect opens is, with the scene's id in scene. See ScenePanel.
audioRecord<string, string | null>yesThe tracks that play on background channels while the scene is open, by channel, such as { ambience: 'rain' }. Null silences one.
picturePictureDefyesThe scene's layered picture with hotspots, in view.scene.picture. See PictureDef.
uiUi<SceneUi>yesThe scene's ui hints, carried to view.scene.ui. See SceneUi.
bodyBlock[]The scene's body, its blocks from top to bottom. See Block.
choicesChoice[]The scene's ending choices, offered under the body once the flow ends. A flowing scene's other choices are in its decisions.

decide

Function. Explained in Flowing scenes.

Returns a decision, where the flow waits until the player chooses one of choices. Its id is unique within the scene.

The chosen choice's then comes next, then the blocks after the decision.

import { decide } from '@ifloom/engine'
function decide(id: string, choices: FlowChoice[], extras?: BlockExtras): Block

Uses: FlowChoice, BlockExtras, Block.

declaredTrait

Function. Explained in Entities.

Returns the data of one trait on one entity from content alone, typed by TraitRegistry, or undefined when it lacks the trait. Use it for a check, or anywhere with no state.

A row in a content traits table wins, then the entity's own traits, each laid over its kind's default. An entity made in play gets its kind's default here, and traitOf adds the data it was made with. It doesn't ask whether the entity is still in the game.

import { declaredTrait } from '@ifloom/engine'
function declaredTrait<K extends string>(game: TraitSource, ref: string, id: K): TraitData<K> | undefined

Uses: TraitSource, TraitData.

declaredWithTrait

Function. Explained in Entities.

Returns every declared entity that has a trait, as references in content order. It reads content alone, as declaredTrait does.

import { declaredWithTrait } from '@ifloom/engine'
function declaredWithTrait(game: TraitSource, id: string): EntityRef[]

Uses: TraitSource, EntityRef.

describeProblem

Function. Explained in Checking content.

Returns a Problem as one line, pack · where · what.

import { describeProblem } from '@ifloom/engine'
function describeProblem(problem: Problem): string

Uses: Problem.

Dice

Type. Explained in Dice rolls.

Dice a roll effect throws, in notation ('2d6+1', '1d20', 'd100') or as a count of dice and their sides. A count of 1 if left out.

import type { Dice } from '@ifloom/engine'
type Dice = string | { count?: number; sides: number }

dismiss

Function. Explained in Commands.

Returns the state with the notice id marked seen, or every notice when id is left out.

import { dismiss } from '@ifloom/engine'
function dismiss(state: GameState, id?: string): GameState

Uses: GameState.

draw

Function. Explained in Randomness.

Returns a whole number from 0 up to but not including max, drawn from parts. Returns 0 when max is 0 or less.

import { draw } from '@ifloom/engine'
function draw(max: number, ...parts: (string | number)[]): number

drawOne

Function. Explained in Randomness.

Returns one entry of items, drawn from parts. Every entry is equally likely.

import { drawOne } from '@ifloom/engine'
function drawOne<T>(items: readonly T[], ...parts: (string | number)[]): T

Effect

Type. Explained in Effects.

A change to the state, told apart by its one key as a condition is ({ stat: 'coins', by: -2 }, { scene: null }). It runs in its turn, on the state the effects before it left.

A plugin's effect, or the game's own, is a PluginCall in the short form, such as { 'quests/start': { quest: 'bakery' } } or { 'game/payRent': {} }.

import type { Effect } from '@ifloom/engine'
type Effect =
  | { kv: string; to: KvValue; of?: string; }
  | { kv: string; by: Amount; of?: string; }
  | { kv: string; random: [Amount, Amount]; of?: string; }
  | { audio: string; to?: string | null; }
  | { turn: true | { by: number; }; }
  | { stat: string; by: Amount; of?: string; }
  | { stat: string; to: Amount; of?: string; }
  | { scene: string | { from: string; otherwise?: string; } | null; }
  | { timer: string; to?: number | null; }
  | { timer: string; by: number; }
  | { roll: string; dice: Dice; plus?: Amount; against?: Amount; }
  | { you: string | null; }
  | { minigame: string; }
  | { sound: string; }
  | { remove: string; }
  | { create: string; } & CreateFields
  | { each: string | Select; where?: Condition; effects: Effect[]; }
  | { receive: string; by?: Amount; to?: string; via?: string; }
  | { release: string; by?: Amount; from?: string; via?: string; }
  | { closeStoryline: string; turns: number; }
  | { notify: string; text?: string; image?: string; tag?: string; id?: string; }
  | { point: string; }
  | { panel: string | null; with?: PluginArgs; }
  | EffectCall

Uses: KvValue, Amount, Dice, CreateFields, Select, Condition, PluginArgs, EffectCall.

EffectCall

Type. Explained in Declaring a plugin's calls.

A plugin's or the game's effect in the short form, type-checked against EffectRegistry.

import type { EffectCall } from '@ifloom/engine'
type EffectCall = CallIn<EffectRegistry>

Uses: CallIn, EffectRegistry.

EffectRef

Type. Explained in Calls by name.

An effect in content, one of the engine's or a plugin's or the game's in the short form. It is the same type as Effect.

import type { EffectRef } from '@ifloom/engine'
type EffectRef = Effect

Uses: Effect.

EffectRegistry

Type. Explained in Declaring a plugin's calls.

The registry of effects plugins and the game add, by full name, with each one's arguments. It works as ConditionRegistry does.

import type { EffectRegistry } from '@ifloom/engine'
type EffectRegistry = {

  // …
}

Plugins add fields of their own to it, which their pages list.

effectsOf

Function. Explained in Actions.

Returns the effects a command would apply, worked out before it runs. Plugins' guards and prices, and locks on an effect, read them.

An action gives its cost as stat effects, then its effects. A choice gives its effects, and a plugin command gives its effectsOf. Any other command gives none.

import { effectsOf, type Game } from '@ifloom/engine'
function effectsOf(state: GameState, game: Game, command: CommandRef): Effect[]

Uses: GameState, Game, CommandRef, Effect.

entitiesOf

Function. Explained in Entities.

Returns every entity of a kind in the game, as references. Declared ones come first in content order, then those made in play in the order they were made.

import { entitiesOf, type Game } from '@ifloom/engine'
function entitiesOf(state: GameState, game: Game, kind: string): EntityRef[]

Uses: GameState, Game, EntityRef.

EntitiesView

Type. Explained in The view.

A listed kind as the player sees it, in view.entities, with its listed entities.

import type { EntitiesView } from '@ifloom/engine'
type EntitiesView = {
  id: string
  label: string
  plural: string
  unique: boolean
  entries: EntityView[]
}
FieldTypeOptionalDefaultDescription
idstringThe kind's id, such as 'character'.
labelstringThe kind's label for one entity, such as 'Character'.
pluralstringThe kind's label for several, for a heading, such as 'Characters'. Its label when the kind gives none.
uniquebooleanThe kind's unique mark, true when each entity is one particular thing that can hold others.
entriesEntityView[]The kind's listed, visible entities, declared ones first, then those created in play.

EntityDef

Type. Explained in Entities.

An entity the game declares in entities, there from the start of the game. Its id is unique within its kind.

import type { EntityDef } from '@ifloom/engine'
type EntityDef = {
  id: string
  of: string
  name: string
  description?: string
  image?: string
  tags?: string[]
  visible?: Condition
  stats?: Record<string, number>
  kv?: Record<string, KvValue>
  traits?: { [K in keyof TraitRegistry]?: Partial<TraitRegistry[K]> } & Record<string, unknown>
  ui?: Ui<EntityUi>
}
FieldTypeOptionalDefaultDescription
idstringThe entity's id, unique within its kind.
ofstringThe id of the entity's kind.
namestringThe entity's name, as the player reads it, such as "Ana". The engine fills its tokens when it reads it.
descriptionstringyesThe entity's description, a line or two the player reads, with its tokens filled as the name's are.
imagestringyesThe entity's picture, a path in the game's art/ folder or a URL, read through artSrc.
tagsstring[]yesThe entity's tags, after its kind's, which a UI or a plugin can sort or filter it by.
visibleConditionyesThe entity's visibility condition, asked with '$' as it, which narrows its kind's listed. Always visible if left out.
statsRecord<string, number>yesThe entity's starting stats, where they differ from each stat's start.
kvRecord<string, KvValue>yesThe entity's starting kv keys.
traits{ [K in keyof TraitRegistry]?: Partial<TraitRegistry[K]> } & Record<string, unknown>yesThe entity's traits, by trait id, such as { 'laundry/washable': { temp: 30 } }. They go over its kind's and under a content traits row for the entity, and an object merges with its kind's field by field.
uiUi<EntityUi>yesThe entity's ui hints, laid over its kind's field by field and carried to the view. See EntityUi.

entityDescription

Function. Explained in Entities.

Returns an entity's description with its tokens filled, or undefined when it has none.

import { entityDescription, type Game } from '@ifloom/engine'
function entityDescription(state: GameState, game: Game, ref: string): string | undefined

Uses: GameState, Game.

entityImage

Function. Explained in Entities.

Returns an entity's picture before artSrc, the one it was made with, else its definition's, else its like's.

import { entityImage, type Game } from '@ifloom/engine'
function entityImage(state: GameState, game: Game, ref: string): string | undefined

Uses: GameState, Game.

entityKv

Function. Explained in Entities.

Returns an entity's kv store, the keys of its like and then its definition's, with the keys play set laid over them.

import { entityKv, type Game } from '@ifloom/engine'
function entityKv(state: GameState, game: Game, ref: string): Record<string, KvValue>

Uses: GameState, Game, KvValue.

entityName

Function. Explained in Entities.

Returns an entity's name with its tokens filled, the name it was created with or else its definition's. Returns the entity's id when it has neither.

import { entityName, type Game } from '@ifloom/engine'
function entityName(state: GameState, game: Game, ref: string): string

Uses: GameState, Game.

entityOf

Function. Explained in Entities.

Returns the save's record of an entity, or {} for a declared one play hasn't changed. Returns undefined when the entity isn't in the game.

import { entityOf, type Game } from '@ifloom/engine'
function entityOf(state: GameState, game: Game, ref: string): EntityState | undefined

Uses: GameState, Game, EntityState.

EntityRef

Type. Explained in Common types.

A reference to an entity, its kind and its id joined by :, such as 'staff:ana'. A bare id or a typo with no : fails to compile where a reference is wanted.

Inside an each or a count's where, content writes '$' for the entity being looked at, in fields typed as plain strings.

import type { EntityRef } from '@ifloom/engine'
type EntityRef = `${string}:${string}`

EntityState

Type. Explained in Entities.

The state a save keeps for one entity, only the fields play changed. A declared entity has no record until play changes it, and reads every other field from content.

import type { EntityState } from '@ifloom/engine'
type EntityState = {
  name?: string
  description?: string
  image?: string
  like?: EntityRef
  tags?: string[]
  traitData?: Record<string, unknown>
  stats?: Stats
  kv?: Record<string, KvValue>
  traits?: Record<string, unknown>
}
FieldTypeOptionalDefaultDescription
namestringyesThe name the entity was made with in play. The engine reads a declared entity's name from content.
descriptionstringyesThe description the entity was made with in play.
imagestringyesThe picture the entity was made with in play.
likeEntityRefyesThe entity the entity was made like. The fields it doesn't have itself (name, description, picture, tags, stats, kv and traits), the engine reads from that one.
tagsstring[]yesThe tags the entity was made with, after its kind's and its like's.
traitDataRecord<string, unknown>yesThe trait data the entity was made with, by trait id, over its like's or its kind's. Its traits' state is in traits.
statsStatsyesThe entity's stats changed in play, by id. The engine reads the others from its definition, then from the stat's start.
kvRecord<string, KvValue>yesThe entity's kv keys set in play. The engine reads the others from its definition.
traitsRecord<string, unknown>yesThe state of the entity's traits that keep one, by trait id, once play changed it. See traitState.

entityTags

Function. Explained in Entities.

Returns an entity's tags, its kind's, then its like's, then its own, each once.

import { entityTags, type Game } from '@ifloom/engine'
function entityTags(state: GameState, game: Game, ref: string): string[]

Uses: GameState, Game.

EntityUi

Type. Explained in Presentation hints.

The ui hints a kind takes for each of its entities, and an entity takes over its kind's. The engine declares none, and a UI package augments this interface with its own.

import type { EntityUi } from '@ifloom/engine'
type EntityUi = {

  // …
}

Plugins add fields of their own to it, which their pages list.

EntityView

Type. Explained in The view.

An entity as the player sees it, in an EntitiesView's entries.

import type { EntityView } from '@ifloom/engine'
type EntityView = {
  id: string
  ref: string
  name: string
  description: string | null
  image: string | null
  tags: string[]
  flags: Record<string, boolean>
  stats: StatView[]
  kv: Record<string, KvValue>
  ui?: Ui<EntityUi>
}
FieldTypeOptionalDefaultDescription
idstringThe entity's id within its kind.
refstringThe entity's reference, such as 'staff:ana'.
namestringThe entity's name, with its prose tokens filled in.
descriptionstring | nullThe entity's description, with its tokens filled in. Null if it has none.
imagestring | nullThe entity's picture, as a path through artSrc. Null if it has none.
tagsstring[]The entity's tags, its kind's first and then its own.
flagsRecord<string, boolean>The answer to each of the kind's flags for this entity, by name. Empty when the kind declares none.
statsStatView[]The kind's listed stats the player can see on this entity, in the order the game declares them.
kvRecord<string, KvValue>The entity's kv store as it reads now, its declared keys with play's changes over them.
uiUi<EntityUi>yesThe entity's ui hints (a EntityUi), its own over its kind's, kept as written. Left out if it has none.

explain

Function. Explained in Conditions.

Returns the Explanation of a condition against a state, part by part. An undefined condition always holds.

import { explain, type Game } from '@ifloom/engine'
function explain(state: GameState, game: Game, condition: Condition | undefined): Explanation

Uses: GameState, Game, Condition, Explanation.

explainText

Function. Explained in Conditions.

Returns an Explanation as indented lines with ✓ or ✗ on each, for a log or a debug panel.

import { explainText } from '@ifloom/engine'
function explainText(explanation: Explanation, depth?: number): string

Uses: Explanation.

Explanation

Type. Explained in Conditions.

A condition's tree with each part marked as holding or not, returned by explain. Each leaf says what it read and what it wanted.

It answers the question authors ask most, why a choice is refused or missing.

import type { Explanation } from '@ifloom/engine'
type Explanation = {
  holds: boolean
  why: string
  parts?: Explanation[]
}
FieldTypeOptionalDefaultDescription
holdsbooleanTrue when this part of the condition holds.
whystringThe part's one line, saying what it checked and what it found.
partsExplanation[]yesThe parts of an all, any or not, each explained.

FileRef

Type. Explained in Checking content.

A file the game names, with the place that names it. Its path is the one the page asks for, after artSrc or audioSrc.

import type { FileRef } from '@ifloom/engine'
type FileRef = {
  path: string
  type: 'picture' | 'video' | 'audio'
  where: string
}
FieldTypeOptionalDefaultDescription
pathstringThe file's path, as the page asks for it.
type'picture' | 'video' | 'audio'The file's type.
wherestringThe place the content names the file, written as a Problem's where is.

FillPart

Type. Explained in Saves.

A part of the state MigrationTools.fill can fill, named by the feature that fills it.

The parts are the player's stats (start values), kv keys (the content's starting kv and per-turn resets) and play settings (defaults).

import type { FillPart } from '@ifloom/engine'
type FillPart =
  | 'kv'
  | 'settings'
  | 'stats'

fillTokens

Function. Explained in Prose and markup.

Returns text with its {{…}} tokens filled for this state. An unset bare name prints nothing, and any other token that names nothing stays as written, so the missing name shows on screen.

The tokens are these:

  • {{name}} reads one of the game's phrases (content's phrases, with . between groups: {{outfit.verdict}}), then a value in rules.values, then a kv key such as {{playerName}}.
  • {{plugin/name}} reads a plugin's value, with any arguments after the name ({{messages/unread channel=texts}}).
  • {{kv:key of=storyline:baker}} reads a key in another kv store.
  • {{v:game/name}} and {{v:plugin/name}} are the older way to write a value, and still work.

A token can end in | and the words shown while it is unset, as in {{flatmateName|Your flatmate}}. A token is unset when its kv key is missing or not text or a number, no row of its phrase holds, no one has its value, or its value is ''. The fallback is shown as written, with no tokens filled. The engine never reads a token's printed words for tokens again, but it fills a phrase's own words when it prints the phrase.

import { fillTokens, type Game } from '@ifloom/engine'
function fillTokens(state: GameState, game: Game, text: string): string

Uses: GameState, Game.

FlowChoice

Type. Explained in Flowing scenes.

A choice at a decision, a Choice with the blocks the flow shows once the player chooses it.

import type { FlowChoice } from '@ifloom/engine'
type FlowChoice = {
  id: string
  label?: string
  labels?: { when?: Condition; label: string }[]
  when?: Condition
  blocked?: Blocked[]
  cost?: ActionCost
  effects?: EffectRef[]
  command?: CommandRef
  once?: Once
  tags?: string[]
  irreversible?: string
  ui?: Ui<ChoiceUi>
  then?: Block[]
}
FieldTypeOptionalDefaultDescription
idstringThe choice's or action's id, unique among its scene's choices or among the actions.
labelstringyesThe button's words, with tokens filled, such as 'Order a tea'. A choice with no label shows its id, and an action with none is never rendered as a button.
labels{ when?: Condition; label: string }[]yesThe button's words that depend on the state, such as "Not today" before you have bought it and "Right." after. The first entry whose when holds wins, and label is the fallback.
whenConditionyesThe condition under which the choice or action is offered and can be taken. Always, if left out.
blockedBlocked[]yesThe rules that refuse it for now. The first entry whose when holds greys the button out with its reason, or leaves it off with hide.
costActionCostyesThe stats it spends. The engine checks them before it runs, lists them on the button and pays them after its command.
effectsEffectRef[]yesThe effects it applies after its cost, in order. A plugin's or the game's effect in the short form does computed work.
commandCommandRefyesThe command the choice or action sends first, a plugin's in the short form or one of the engine's, but never choose. The button is refused with that command's reason while the command would be. An example is { 'devices/open': { id: 'messages' } }. The button's price includes what the command spends.
onceOnceyesThe limit of once a game ({ per: 'game' }) or once a turn ({ per: 'turn' }), counted in state.chosen. Once spent, a choice stays on screen and pays nothing more, and an action is refused, both with reason. The choice's limit of once a game or once a turn. See Once.
tagsstring[]yesThe tags a UI can style or filter it by. The engine gives them no meaning.
irreversiblestringyesThe warning that it can't be undone, which a UI shows on the button.
uiUi<ChoiceUi>yesThe ui hints carried to its button in the view. See ChoiceUi.
thenBlock[]yesThe blocks shown once the choice is chosen. The flow then carries on after the decision, or from its { point } effect's point.

FlowState

Type. Explained in Flowing scenes.

The visit a save keeps for the open scene, with its path so far and the wait the flow stands at. The engine reads the scene's body from content.

import type { FlowState } from '@ifloom/engine'
type FlowState = {
  scene: string
  path: FlowStep[]
  waiting: { minigame: string } | { panel: string } | null
}
FieldTypeOptionalDefaultDescription
scenestringThe id of the scene the visit is of.
pathFlowStep[]The visit's steps in order, the choices made, the points jumped to and the minigames and panels done with. The view replays them to render the visit.
waiting{ minigame: string } | { panel: string } | nullThe minigame being played or the panel open where the flow stands, until it's done. Null while the flow waits on neither.

FlowStep

Type. Explained in Flowing scenes.

A step of a visit's path in state.flow, kept in the order the steps came.

{ chose } is a choice at a decision or among the ending choices, { point } a jump a choice made, and { minigame } or { panel } a wait done with.

import type { FlowStep } from '@ifloom/engine'
type FlowStep = { chose: string } | { point: string } | { minigame: string } | { panel: string }

fold

Function. Explained in Flowing scenes.

Returns a fold, a section the player can open and shut under label, such as a letter to read. A UI without the fold hint shows the blocks open.

A fold is presentation only, a section with the React UI's fold hint, and keeps no state.

import { fold } from '@ifloom/engine'
function fold(label: string, blocks: Block[], extras?: BlockExtras): Block

Uses: Block, BlockExtras.

Formula

Type. Explained in Stats.

A formula a derived stat declares in its derive, to work the stat out from other stats. A number is itself, and a string is another stat's value.

For a stat with of, a string names the same entity's stat.

The other forms combine formulas:

  • { sum: [...] }, { product: [...] }, { min: [...] } and { max: [...] } combine a list.
  • { scale: f, by: n } is f times n.
  • { clamp: f, min?, max? } holds f between the two.
import type { Formula } from '@ifloom/engine'
type Formula = number | string | { sum: Formula[] } | { product: Formula[] } | { min: Formula[] } | { max: Formula[] } | { scale: Formula; by: number } | { clamp: Formula; min?: number; max?: number }

Game

Type. Explained in The game.

A loaded game, the core's fields and each feature's. loadGame makes it from the base, the content and the packs.

type Game = {
  id: string
  title: string
  version?: number
  packs?: string[]
  prose?: ProseStore
  rules?: GameRules
  strings?: Record<string, string>
  plugins?: readonly Plugin<any>[]
  receivers?: readonly string[]
  data?: Record<string, Record<string, readonly PluginEntry[]>>
  kinds?: KindDef[]
  entities?: EntityDef[]
  traits?: TraitTable
  player?: PlayerDef | undefined
  kv?: Record<string, KvValue>
  resets?: Record<string, KvValue>
  storylines?: StorylineDef[]
  actions?: ActionDef[]
  triggers?: TriggerDef[]
  inputs?: InputDef[]
  settings?: SettingDef[]
  stats?: StatDef[]
  introScene?: string
  scenes: DataScene[]
  minigames?: MinigameDef[]
  timers?: TimerDef[]
  audio?: GameAudio
  media?: GameMedia
  ui?: Ui<GameUi>
  saveable?: Blocked[]
  locks?: Lock[]
  phrases?: Record<string, PhraseRow[] | PhraseWithArgs>
  changes?: ChangesDef
  carryOver?: CarryOver
  finished?: Condition
  credits?: CreditGroup[]
}
FieldTypeOptionalDefaultDescription
idstringThe game's id. Saves and packs record it, so a save from another game is refused.
titlestringThe game's title, which a title page shows.
versionnumberyesThe game's own version, a whole number from 1. Saves record it, and rules.migrations carry an older save forward. 1 if left out. Declaring it also stops the engine filling new stats, settings and entities into old saves by itself, so your migration steps fill them with tools.fill().
packsstring[]yesThe ids of the packs the game was loaded with, in order. Saves record them, and the game's own content has no id.
proseProseStoreyesThe game's prose keys and variants lists, with their weights. loadGame makes it from the content's prose.
rulesGameRulesyesThe game's own code, its hooks, providers and the calls content makes as game/<name>. See GameRules.
stringsRecord<string, string>yesThe game's lines in place of the engine's and plugins' strings, by key, such as { finishFirst: 'Not yet.', 'quests/notDoing': 'Not on your list.' }. Packs can add theirs, and a later pack's line wins.
pluginsreadonly Plugin<any>[]yesThe plugins the game is built with, in the order their hooks run.
receiversreadonly string[]yesThe order the receive effect asks the plugins that keep things, by plugin id. The order of plugins if left out. ['wardrobe', 'inventory'] sends clothes to the wardrobe and the rest to the inventory.
dataRecord<string, Record<string, readonly PluginEntry[]>>yesThe plugins' content, by plugin id and then list, such as data.quests.quests. loadGame merges packs' entries by id, as it does scenes.
kindsKindDef[]yesThe game's kinds, the sorts of entity it keeps, each with its own stats.
entitiesEntityDef[]yesThe game's entities at the start. Play can create more.
traitsTraitTableyesThe game's traits, by trait id and then entity. In content given to loadGame they're rows over what entities declare. On the game loadGame returns, they're every entity's traits, worked out. Read them with declaredTrait.
playerPlayerDef | undefinedyesThe game's player, such as their picture beside their own spoken lines.
kvRecord<string, KvValue>yesThe kv store a new game starts with, such as the stretch it opens in, { phase: 'arrival' }.
resetsRecord<string, KvValue>yesThe keys the engine puts back at the start of each turn, with the value each goes back to. Use them to count something once a turn.
storylinesStorylineDef[]yesThe game's storylines, threads of story each with its own kv store, which a closeStoryline effect rests for some turns. None if left out.
actionsActionDef[]yesThe game's actions, by id. None if left out. An action with a label is a button in the room while no scene is open, and one with no label is done only by { type: 'action', id }.
triggersTriggerDef[]yesThe game's triggers, effects that run by themselves the first time a condition holds. They fire in this order.
inputsInputDef[]yesThe game's inputs, the fields the player fills in, each writing a kv key.
settingsSettingDef[]yesThe game's settings, which the player changes from a settings page. None if left out.
statsStatDef[]yesThe game's stats. The engine has none of its own.
introScenestringyesThe scene open on the first frame. The game opens on the room if left out.
scenesDataScene[]The game's scenes, as data.
minigamesMinigameDef[]yesThe game's minigames. None if left out.
timersTimerDef[]yesThe game's timers. None if left out.
audioGameAudioyesThe game's tracks and channels. No audio if left out.
mediaGameMediayesThe game's pools of pictures and videos. None if left out.
uiUi<GameUi>yesThe game's ui hints, such as how every screen comes in. The engine carries them to the view as written and gives them no meaning.
saveableBlocked[]yesThe game's reasons to refuse saving, as blocked entries refused while their when holds. The first entry that holds gives the reason, and saving is always allowed if left out.
locksLock[]yesThe game's locks, checked in order. The first one that stops a command gives the reason.
phrasesRecord<string, PhraseRow[] | PhraseWithArgs>yesThe game's phrases, by full dotted name (outfit.verdict), each as its rows or its rows with the arguments it takes. None if left out.
changesChangesDefyesThe stats the engine tracks changes of, from the content and every pack together. Nothing is tracked if left out.
carryOverCarryOveryesThe game's rules for a New Game+, the parts of the last game a new one keeps. startingState's carry applies them.
finishedConditionyesThe game's condition for being finished. The runner records the first time it holds in the profile's core:finished, so a title page can offer New Game+.
creditsCreditGroup[]yesThe game's credits, in groups, in the order they were first declared. None if left out.

GameAudio

Type. Explained in Audio.

The audio the game declares in audio, its tracks, the channels they play on and the settings that set their volume.

import type { GameAudio } from '@ifloom/engine'
type GameAudio = {
  tracks: Record<string, TrackDef | PlaylistDef>
  channels?: Record<string, ChannelDef>
  mute?: string
  sound?: string
  default?: Record<string, string>
}
FieldTypeOptionalDefaultDescription
tracksRecord<string, TrackDef | PlaylistDef>The game's tracks and playlists, by id, each a file with its volume or a list of tracks to play in turn.
channelsRecord<string, ChannelDef>yesThe game's channels, merged over the defaults, music and ambience (background) and sfx and voice (cue).
mutestringyesThe id of the ui setting, a toggle, that mutes everything while it's on, such as a "Mute" box.
soundstringyesThe id of the ui setting, a toggle, that plays sound only while it's on, such as a "Sound" box. It's the reverse of mute.
defaultRecord<string, string>yesThe track each background channel plays when nothing else sets one, by channel.

GameBase

Type. Explained in Content and packs.

The base loadGame takes beside the content, the game's id, title, version, plugins and rules. Anything a mod could change goes in the content or a pack instead.

import type { GameBase } from '@ifloom/engine'
type GameBase = {
  id: string
  title: string
  version?: number
  plugins?: readonly Plugin<any>[]
  receivers?: readonly string[]
  rules?: GameRules
}
FieldTypeOptionalDefaultDescription
idstringThe game's id. Saves and packs record it, so a save from another game is refused.
titlestringThe game's title, which a title page shows.
versionnumberyesThe game's own version, a whole number from 1. Saves record it, and rules.migrations carry an older save forward. 1 if left out. Declaring it also stops the engine filling new stats, settings and entities into old saves by itself, so your migration steps fill them with tools.fill().
pluginsreadonly Plugin<any>[]yesThe plugins the game is built with, in the order their hooks run.
receiversreadonly string[]yesThe order the receive effect asks the plugins that keep things, by plugin id. The order of plugins if left out. ['wardrobe', 'inventory'] sends clothes to the wardrobe and the rest to the inventory.
rulesGameRulesyesThe game's own code, its hooks, providers and the calls content makes as game/<name>. See GameRules.

GameMedia

Type. Explained in Media.

The media the game declares in media, pools of pictures and videos by id.

import type { GameMedia } from '@ifloom/engine'
type GameMedia = {
  pools?: Record<string, PoolFile[]>
}
FieldTypeOptionalDefaultDescription
poolsRecord<string, PoolFile[]>yesThe game's pools, named lists of files content draws from, as in [[img:@door|night]] or { pool: 'door', tags: ['night'] }.

GameRules

Type. Explained in Rules and hooks.

The game's own code, a plain object with the members a plugin has. Content calls its members with game as the plugin id, such as the condition { 'game/tired': true }.

The engine runs it as the plugin game, before every other plugin, with the same context (PluginContext, and TurnContext for the turn hooks). Its slice, get and set read and write the game's own state when it has a start. Every member is optional and means what a plugin's does (see Plugin), except migrations, which carry the whole save from one version of the game to the next.

A plugin's id, versions, content, strings and data are the game's own content, so GameRules leaves them out. Locks and per-turn resets are content too, in locks and resets. Its calls, declared with defineCalls('game', …) and passed through defineRules, type its members' arguments and let the content checker check every game/ call against them.

import type { GameRules, Game } from '@ifloom/engine'
type GameRules<S = any> = {
  conditions?: Record<string, (state: GameState, args: PluginArgs, context: PluginContext<S>) => boolean>
  effects?: Record<string, (state: GameState, args: PluginArgs, context: PluginContext<S>) => GameState>
  view?: ((state: GameState, context: PluginContext<S>) => unknown)
  references?: PluginReferences
  commands?: Record<string, PluginCommand<S, PluginArgs>>
  traits?: readonly TraitDef<any, any>[]
  actions?: ((state: GameState, context: PluginContext<S>) => readonly ButtonDef[] | undefined)
  audio?: ((state: GameState, context: PluginContext<S>) => Record<string, string | null> | undefined)
  scene?: ((state: GameState, context: PluginContext<S>) => RoomScene | undefined)
  action?: ((state: GameState, id: string, context: PluginContext<S>) => ButtonDef | undefined)
  label?: ((state: GameState, context: PluginContext<S>) => string | undefined)
  start?: ((game: Game) => S)
  values?: Record<string, (state: GameState, args: PluginArgs, context: PluginContext<S>) => string | number>
  calls?: AnyCalls
  macros?: Record<string, Macro<S, PluginArgs>>
  queries?: Record<string, (state: GameState, args: PluginArgs, context: PluginContext<S>) => unknown>
  statModifiers?: ((state: GameState, context: PluginContext<S>) => readonly StatModifier[] | undefined)
  onTurn?: ((state: GameState, context: TurnContext<S>) => GameState)
  onTurnDone?: ((state: GameState, context: TurnContext<S>) => GameState)
  onStat?: ((before: GameState, after: GameState, stat: string, by: number, context: PluginContext<S>) => GameState)
  onCommand?: ((before: GameState, after: GameState, context: PluginContext<S>) => GameState)
  guard?: ((state: GameState, asked: Asked, context: PluginContext<S>) => Refusal | undefined)
  price?: ((state: GameState, effects: readonly Effect[], context: PluginContext<S>) => string[] | undefined)
  saveName?: ((state: GameState, context: PluginContext<S>) => string | undefined)
  profile?: ((state: GameState, previous: GameState, stored: unknown, context: PluginContext<S>) => unknown)
  check?: (game: Game, tools: CheckTools) => PluginProblem[]
  migrations?: Record<number, (state: GameState, tools: MigrationTools) => GameState>
}
FieldTypeOptionalDefaultDescription
conditionsRecord<string, (state: GameState, args: PluginArgs, context: PluginContext<S>) => boolean>yesThe plugin's conditions content can test, by name without the prefix.
effectsRecord<string, (state: GameState, args: PluginArgs, context: PluginContext<S>) =>…yesThe plugin's effects content can apply, by name without the prefix. Each takes the state the effects before it left and returns the next one, so two in one list compose. Prices and guards can't see what an effect does until it runs. An effect that only stands for other effects belongs in macros instead.
view((state: GameState, context: PluginContext<S>) => unknown)yesReturns the plugin's view, which a UI reads at view.plugins[id]. Declare its type V in ViewRegistry under the plugin's id, and every view types view.plugins[id] as V.
referencesPluginReferencesyesThe references the plugin's calls and content make, which the content checker resolves as it resolves the engine's own. See PluginReferences.
commandsRecord<string, PluginCommand<S, PluginArgs>>yesThe plugin's commands a choice or action can send, by name without the prefix.
traitsreadonly TraitDef<any, any>[]yesThe traits the plugin gives meaning to, each id the plugin's id, / and a name. A trait is data only, and the plugin's code decides what it does. Content writes them on a kind, an entity or content's traits table, and the plugin reads them with traitOf or declaredTrait.
actions((state: GameState, context: PluginContext<S>) => readonly ButtonDef[] | undefined)yesReturns the actions offered while no scene is open, such as a location's things to do. The view lists them before the game's own actions, rendered the same way.
audio((state: GameState, context: PluginContext<S>) => Record<string, string | null> |…yesReturns the tracks the plugin plays on background channels, by channel, such as a location's ambience. Null silences a channel, and the first plugin that names a channel wins it. A plugin's track is below an open scene's and an audio effect's, and above the game's default. A channel left out is the next plugin's, then the default's.
scene((state: GameState, context: PluginContext<S>) => RoomScene | undefined)yesReturns the RoomScene the screen shows while no scene is open, such as a location's description or a dashboard's heading. The first plugin that answers fills it. With none, the room shows the game's title and its actions.
action((state: GameState, id: string, context: PluginContext<S>) => ButtonDef | undefined)yesReturns one of the plugin's actions that isn't among its actions now, by id without the prefix, such as an app's. Undefined when there is none. { type: 'action', id: '<plugin>/<id>' } runs it, as for an action with a cost or effects. Without this provider, the engine looks the id up among the plugin's actions.
label((state: GameState, context: PluginContext<S>) => string | undefined)yesReturns a few words on the time or place in the game for a header or a save, such as "Day 3 · Wednesday morning".
start((game: Game) => S)yesReturns the plugin's state in a new game. A plugin with no state leaves it out.
valuesRecord<string, (state: GameState, args: PluginArgs, context: PluginContext<S>) => string…yesThe plugin's values, words and numbers content reads by name with arguments, as a condition is asked. Prose prints one as {{id/name channel=texts}}, and an Amount reads one as { value: 'id/name', with }.
callsAnyCallsyesThe declaration of the plugin's conditions, effects and commands, each with the arguments it takes, from defineCalls. Every declared call needs an implementation, and every implementation a declaration. The implementations get their arguments read by it. The content checker reports a call that leaves an argument out, gets one wrong or names something the game lacks, and a translation reaches the words in a call's arguments.
macrosRecord<string, Macro<S, PluginArgs>>yesThe plugin's macros, effects that stand for other effects, by name without the prefix. A name is an effect's or a macro's, never both. Content calls one as any effect. It returns the effects it stands for, worked out from the state, so a button's price and the guards see what it would do. See Macro.
queriesRecord<string, (state: GameState, args: PluginArgs, context: PluginContext<S>) => unknown>yesThe plugin's queries, answers other plugins ask for by name without importing it, such as context.query('calendar/whenNext', { when }). A query answers what a condition's yes or no can't, such as a location, a time or a list.
statModifiers((state: GameState, context: PluginContext<S>) => readonly StatModifier[] | undefined)yesReturns the changes to what the player's stats read now, worked out from the plugin's state, such as a timed boost. It must not read stats itself, or it reads itself. Nothing is written into the state. Every reading of the stat (conditions, derived stats, costs, the view) sees the changed value, and stat effects still write the kept value underneath.
onTurn((state: GameState, context: TurnContext<S>) => GameState)yesThe hook run at the end of a turn, once the counter has moved on and resets are back. It returns the next state, and the hooks run in order, the game's first. context.before is the state as the turn ended, and a turn effect applied through context.apply does nothing.
onTurnDone((state: GameState, context: TurnContext<S>) => GameState)yesThe hook run once every onTurn has run, so it sees their changes, such as the calendar's new day. It returns the next state and runs in the same order and context as onTurn.
onStat((before: GameState, after: GameState, stat: string, by: number, context: PluginContext<…yesThe hook run when a stat effect changes one of the player's stats. before is the state before it, after the state with it, and by how far it moved. Return before to undo the change, after to keep it, or after with more changes. The hooks run in order, the game's first, each seeing what the one before returned.
onCommand((before: GameState, after: GameState, context: PluginContext<S>) => GameState)yesThe hook run after every command that took, with the state before and the state after. It returns the next state, and its context is the state after.
guard((state: GameState, asked: Asked, context: PluginContext<S>) => Refusal | undefined)yesReturns a Refusal for a command, given the effects it would apply, or undefined to let it through. The engine asks it after the locks, of every command but the ones that ignore locks.
price((state: GameState, effects: readonly Effect[], context: PluginContext<S>) => string[] |…yesReturns the plugin's words for what a button costs that the engine can't say, such as ['until evening']. The engine asks it with the effects the button would apply.
saveName((state: GameState, context: PluginContext<S>) => string | undefined)yesReturns the name a save is listed under, such as the name the player typed. It is kept as SaveMeta.playerName and shown for @you's lines. The first that answers names it, the game's first. With none, saves have no player name.
profile((state: GameState, previous: GameState, stored: unknown, context: PluginContext<S>) =>…yesReturns the value the plugin keeps in the player's profile, which outlives saves and new games, such as earned achievements. Return undefined to leave the stored value. The runner asks it after every command that took, with the state after, the state before and the value the plugin's profile namespace (its id) holds now. Only a runner with a profile asks, and apply never does.
check(game: Game, tools: CheckTools) => PluginProblem[]yesReturns the problems the plugin's own rules find that a reference can't express, such as two entries with one id or an exit to nowhere. The content checker runs it after the references. tools words problems with anything else the plugin names as the checker does.
migrationsRecord<number, (state: GameState, tools: MigrationTools) => GameState>yesThe game's save migrations, keyed by the game version each upgrades from, so step 1 takes a version-1 save to version 2. A version with no step is carried forward unchanged. They run on the whole state when an older save loads, after the engine's and plugins' own migrations.

GameState

Type. Explained in Game state.

The state a save keeps, the core's fields and each feature's. The engine reads definitions from content, so the save holds only what play changed.

Each field declares its new-game value and load default once, in FIELDS or in its feature's state.

import type { GameState, Notice } from '@ifloom/engine'
type GameState = {
  version: typeof SAVE_VERSION
  seed: number
  plugins: Record<string, PluginSlice>
  gameVersion?: number
  entities: Record<string, Record<string, EntityState>>
  created: Record<string, number>
  removed: string[]
  you: EntityRef | null
  turn: number
  kv: Record<string, KvValue>
  storylines: Record<string, StorylineState>
  notices: Notice[]
  fired: Record<string, number>
  settings: Record<string, KvValue>
  stats: Stats
  sceneId: string | null
  seen: Record<string, Times>
  chosen: Record<string, Times>
  minigame: MinigameState | null
  flow: FlowState | null
  timers: Record<string, RunningTimer>
  audio: AudioState
  media: MediaState
  panel: OpenPanel | null
  rolls: RollsState
  changes: Change[]
}
FieldTypeOptionalDefaultDescription
versiontypeof SAVE_VERSIONThe save format's version, SAVE_VERSION. loadState carries an older save forward.
seednumberThe save's random seed, fixed when the game starts. Every seeded draw (variants, pools, rolls, storylets) mixes it in, so two games draw differently.
pluginsRecord<string, PluginSlice>The plugins' own state, by plugin id.
gameVersionnumberyesThe game's own version (game.version) the save was made with. It is set only when the game declares a version, and a save without it counts as version 1.
entitiesRecord<string, Record<string, EntityState>>The changes play has made to the game's entities, by kind and id, such as entities.staff.ana. A declared entity has no record until something changes it. An entity created in play has a record from the start.
createdRecord<string, number>The number of entities of each kind created in play, for the next one's id.
removedstring[]The references of declared entities removed in play. A create with the same id brings one back.
youEntityRef | nullThe protagonist the player is playing, which 'you' names. Null while the player plays themselves.
turnnumberThe number of turns that have passed, the engine's one clock. It starts at 0. The game decides how long a turn is (a day, an hour, a week or a chapter). The engine dates seen, fired and notices in turns.
kvRecord<string, KvValue>The player's kv store, keys with a true/false, number or text value.
storylinesRecord<string, StorylineState>The storylines a save keeps, by id, each with its kv store and the turn it stays closed until.
noticesNotice[]The notices the game has raised, oldest first. The state keeps the last 50.
firedRecord<string, number>The turn each trigger last fired on, by trigger id.
settingsRecord<string, KvValue>The value of each play setting the game declares, by id.
statsStatsThe player's stats, by id. An entity's stats are kept on the entity.
sceneIdstring | nullThe id of the open scene. Null while no scene is open and the room shows.
seenRecord<string, Times>The scenes the player has entered, by id, with a count and the first and last turn of each. Content can gate a chain of scenes on it without a kv key per link. Entering the scene that's already open, such as a hub rendered again after a choice, doesn't count.
chosenRecord<string, Times>The choices the player has chosen, by scene#choice, with a count and the first and last turn of each. Content can gate on an earlier decision with it, and a choice's once reads it.
minigameMinigameState | nullThe minigame being played, or null.
flowFlowState | nullThe open scene's visit, each choice, jump and wait passed in order, and the wait the flow stands at. It starts again each time a scene is entered. Null while no scene is open, and for a visit with nothing to keep yet.
timersRecord<string, RunningTimer>The running timers, by id, in the order they started.
audioAudioStateThe audio a save keeps, the tracks effects put on channels, the last sounds and the count of scenes entered.
mediaMediaStateThe file each pool request was given, so a revisit and a reload show the same one.
panelOpenPanel | nullThe panel the panel effect opened over the story, or null.
rollsRollsStateThe rolls this save has made.
changesChange[]The stats the last command moved, in the order the game declares them, the player's first. A tick that moved nothing keeps the list from before it.

GameUi

Type. Explained in Presentation hints.

The ui hints the whole game takes in its ui. The engine declares none, and a UI package augments this interface with its own.

import type { GameUi } from '@ifloom/engine'
type GameUi = {

  // …
}

Plugins add fields of their own to it, which their pages list.

hash

Function. Explained in Randomness.

Returns a 32-bit unsigned hash of text. Texts that differ in one character give unrelated numbers.

import { hash } from '@ifloom/engine'
function hash(text: string): number

HelperRegistry

Type. Explained in The runner.

The registry of helper reports, by helper id, that a helper augments to type its own. It is empty until a helper augments it, as startUnlocks from @ifloom/plugin-unlocks does for unlocks.

A helper types its report here as a plugin types its view in ViewRegistry.

import type { HelperRegistry } from '@ifloom/engine'
type HelperRegistry = {

  // …
}

Plugins add fields of their own to it, which their pages list.

HelpersIn

Type. Explained in The runner.

The helpers' reports, by helper id. Each report a helper declares in HelperRegistry is typed, and the rest are unknown.

import type { HelpersIn } from '@ifloom/engine'
type HelpersIn = {
  [key: string]: unknown
  // …
}

Plugins add fields of their own to it, which their pages list.

HistoryOptions

Type. Explained in The runner.

Settings for undo and redo. Undo is off unless createRunner is given these or true, and never steps back past a barrier these set.

import type { HistoryOptions } from '@ifloom/engine'
type HistoryOptions = {
  depth?: number
  stopAtIrreversible?: boolean
  stopAtNewTurn?: boolean
  stopWhen?: Condition
}
FieldTypeOptionalDefaultDescription
depthnumberyesThe number of steps back undo reaches. 50 if left out.
stopAtIrreversiblebooleanyesThe setting that stops undo at a choice marked irreversible. On unless set to false.
stopAtNewTurnbooleanyesThe setting that stops undo at the start of a new turn. Off if left out.
stopWhenConditionyesA condition that stops undo at any state where it holds, tested after each command.

holds

Function. Explained in Conditions.

Returns true when condition holds in this state. An undefined condition always holds.

The engine finds a condition's kind by its one key. A condition with no known key, or with two, never holds, and the content checker reports it. A range bound that is an Amount is worked out first, so the kind reads a number.

import { holds, type Game } from '@ifloom/engine'
function holds(state: GameState, game: Game, condition: Condition | undefined): boolean

Uses: GameState, Game, Condition.

HotspotDef

Type. Explained in Media.

A hotspot on a picture, a clickable area the UI renders as a button. It either sends command or chooses the open scene's choice choice.

import type { HotspotDef } from '@ifloom/engine'
type HotspotDef = {
  id: string
  rect: [ number, number, number, number ]
  label: string
  command?: CommandRef
  choice?: string
  when?: Condition
  layer?: string
}
FieldTypeOptionalDefaultDescription
idstringThe hotspot's id.
rect[ number, number, number, number ]The hotspot's area, in percent of the picture, as [x, y, width, height] from the top left.
labelstringThe hotspot's label, which a screen reader reads and the tooltip shows.
commandCommandRefyesThe command the hotspot sends, written as an action's command.
choicestringyesThe id of the open scene's choice the hotspot chooses.
whenConditionyesThe hotspot's condition. The hotspot shows only while it holds.
layerstringyesThe id of the layer the hotspot goes with. The hotspot shows only while that layer does.

HotspotView

Type. Explained in Media.

A hotspot as the player sees it, in a PictureView's hotspots. The UI renders it as a button over the picture.

import type { HotspotView } from '@ifloom/engine'
type HotspotView = {
  id: string
  rect: [ number, number, number, number ]
  label: string
  command: Command
  disabled?: string
  warning?: string
  layer?: string
}
FieldTypeOptionalDefaultDescription
idstringThe hotspot's id.
rect[ number, number, number, number ]The hotspot's area, in percent of the picture, as [x, y, width, height] from the top left.
labelstringThe hotspot's label.
commandCommandThe command pressing the hotspot sends, its own command or the command that chooses its choice.
disabledstringyesThe reason the hotspot can't be pressed now, as on a button's disabled. Left out when it can.
warningstringyesThe warning a plugin gives against pressing the hotspot, as on a button's warning.
layerstringyesThe id of the layer the hotspot goes with. Left out for a hotspot on the whole picture.

image

Function. Explained in Flowing scenes.

Returns a { media } block, a picture or a video at this place in the flow, such as image('cafe/cup', { alt: 'A cup of tea' }).

import { image } from '@ifloom/engine'
function image(src: string, media?: Omit<SceneMedia, 'src'> & BlockExtras): Block

Uses: SceneMedia, BlockExtras, Block.

inlineChoices

Function. Explained in The view.

Returns the choices and actions that a scene's or a room's beats hold inline, in the order they come.

import { inlineChoices } from '@ifloom/engine'
function inlineChoices(beats: readonly SceneBeat[]): RenderedChoice[]

Uses: SceneBeat, RenderedChoice.

inlineMarkup

Function. Explained in Prose and markup.

Returns a line of prose cut at its inline markup ([[act:…]], [[tip:…]], [[ui:…]], **bold**, *italic*). Returns null when it has none.

Broken markup stays in the words as written, so it shows on screen, and the content checker reports it. Broken markup is markup with no id or key, a tooltip or UI piece with no words, a UI piece whose name isn't an id or that has an empty argument, or stars that don't close. A \* is a star shown unchanged, and bold and italics inside or around inline markup are not read.

import { inlineMarkup } from '@ifloom/engine'
function inlineMarkup(text: string): InlinePart[] | null

Uses: InlinePart.

InlinePart

Type. Explained in Prose and markup.

One piece of a line of prose as inlineMarkup reads it, told apart by its type. Each marked piece keeps its source in markup.

import type { InlinePart } from '@ifloom/engine'
type InlinePart = { type: 'text'; text: string } | { type: 'act'; id: string; text?: string; markup: string } | { type: 'tip'; key: string; text: string; markup: string } | { type: 'ui'; name: string; text: string; args: string[]; markup: string } | { type: 'bold'; text: string; markup: string } | { type: 'italic'; text: string; markup: string }

InlineSpan

Type. Explained in Prose and markup.

One piece of a paragraph that holds inline markup, in a beat's spans, in order. Each piece is told apart by its type.

import type { InlineSpan } from '@ifloom/engine'
type InlineSpan = { type: 'text'; text: string } | { type: 'action'; text: string; choice: RenderedChoice } | { type: 'tip'; text: string; tip: string } | { type: 'bold'; text: string } | { type: 'italic'; text: string } | { type: 'ui'; name: string; text: string; args: string[] }

Uses: RenderedChoice.

InlineUi

Type. Explained in Presentation hints.

The UI pieces a UI renders inside a line of prose from [[ui:name|words|arg|…]], by name. Each name maps to the arguments it takes after the words, as a tuple of text.

The engine declares none, and a UI package augments this interface with its own:

declare module '@ifloom/engine' {
  interface InlineUi { modal: [key: string, title?: string] }
}

The engine never reads it. The view's { type: 'ui' } span has name: string and args: string[], so a name no UI declared still comes through, and this interface only types a UI's components.

import type { InlineUi } from '@ifloom/engine'
type InlineUi = {

  // …
}

Plugins add fields of their own to it, which their pages list.

InlineUiArgs

Type. Explained in Presentation hints.

The arguments of the UI piece named N, as a UI package declared them in InlineUi. Any text when no package declared N.

import type { InlineUiArgs } from '@ifloom/engine'
type InlineUiArgs<N extends string> = N extends keyof InlineUi ? InlineUi[N] : readonly string[]

Uses: InlineUi.

InputDef

Type. Explained in Inputs.

An input the game declares in inputs, a field the player fills in, such as a pet's name. The input command writes its value to a kv key and refuses one the declaration doesn't allow.

import type { InputDef } from '@ifloom/engine'
type InputDef = {
  id: string
  label: string
  type: 'text' | 'number' | 'choice'
  key?: string
  when?: Condition
  maxLength?: number
  min?: number
  max?: number
  options?: { value: KvValue; label: string }[]
}
FieldTypeOptionalDefaultDescription
idstringThe input's id, which the input command names.
labelstringThe input's label, the name of the field the player fills in.
type'text' | 'number' | 'choice'The input's type, text (typed words), number or choice (one of options).
keystringyesThe kv key the input writes. The input's id if left out.
whenConditionyesThe input's condition. The input is on offer only while it holds.
maxLengthnumberyesThe most characters a text input takes, after trimming. 40 if left out.
minnumberyesThe lowest number a number input takes, included. No bound if left out.
maxnumberyesThe highest number a number input takes, included. No bound if left out.
options{ value: KvValue; label: string }[]yesThe values a choice input offers, each with the label the player reads.

InputView

Type. Explained in The view.

An input as the player sees it, in view.inputs. Only inputs whose when holds are listed.

import type { InputView } from '@ifloom/engine'
type InputView = {
  id: string
  label: string
  type: InputDef['type']
  maxLength: number | null
  min: number | null
  max: number | null
  options: { value: KvValue; label: string }[]
  value: KvValue | null
}
FieldTypeOptionalDefaultDescription
idstringThe input's id, which the input command names.
labelstringThe input's label, the name of the field.
typeInputDef['type']The input's type, text, number or choice.
maxLengthnumber | nullThe most characters a text input takes, after trimming, 40 unless the input sets it. Null for a number or a choice.
minnumber | nullThe lowest number the input takes. Null with no bound, and for text or a choice.
maxnumber | nullThe highest number the input takes. Null with no bound, and for text or a choice.
options{ value: KvValue; label: string }[]The values a choice input offers, each with its label. Empty for text or a number.
valueKvValue | nullThe value the input's kv key holds now. Null when it's unset.

inRange

Function. Explained in Conditions.

Returns true when value is in the range, with each bound worked out in this state first. A range with no bounds holds above 0.

So { gte: { stat: 'rent' } } compares the value with the rent.

import { inRange, type Game } from '@ifloom/engine'
function inRange(state: GameState, game: Game, value: number, range: Range): boolean

Uses: GameState, Game, Range.

InstalledMod

Type. Explained in Mods.

A mod the player has added, as the mod store keeps it.

import type { InstalledMod } from '@ifloom/engine'
type InstalledMod = {
  id: string
  name: string
  version?: string
  description?: string
  enabled: boolean
  pack: Pack
}
FieldTypeOptionalDefaultDescription
idstringThe mod's id.
namestringThe mod's name, for a mods page.
versionstringyesThe mod's own version, as its author writes it.
descriptionstringyesThe mod's description, a line for a mods page.
enabledbooleanTrue when the mod is on. A mod that is off stays installed and is left out of the game.
packPackThe pack the mod adds, as the file wrote it, with its id set to mod:<id>. loadGame upgrades it.

isUnique

Function. Explained in Entities.

Returns true when the entity's kind is unique, so each entity is one particular someone or something.

import { isUnique, type Game } from '@ifloom/engine'
function isUnique(game: Pick<Game, 'kinds' | 'plugins'>, ref: string): boolean

Uses: Game.

jump

Function. Explained in Flowing scenes.

Returns the jump effect { point: id }, which carries the flow on from a point instead of after the choice's decision, once its then is done. A flow loops only this way, through a choice.

It goes in a choice's effects, never its then: it's the same object as point(id), so in a then it's a point.

import { jump } from '@ifloom/engine'
function jump(id: string): { point: string }

KindDef

Type. Explained in Entities.

A kind of entity the game declares in kinds, such as the staff of a café or the dishes on its menu. Each entity of the kind has its own stats and kv keys.

So a stat declared with of: 'staff' belongs to each member of staff, not to the player.

import type { KindDef } from '@ifloom/engine'
type KindDef = {
  id: string
  label: string
  plural?: string
  unique?: boolean
  listed?: boolean | Condition
  tags?: string[]
  flags?: Record<string, Condition>
  traits?: { [K in keyof TraitRegistry]?: Partial<TraitRegistry[K]> } & Record<string, unknown>
  ui?: Ui<EntityUi>
}
FieldTypeOptionalDefaultDescription
idstringThe kind's id, the part before the : in each of its entity references.
labelstringThe kind's label for one entity, as the player reads it, such as "Member of staff".
pluralstringyesThe kind's label for more than one, such as "Staff". The label if left out.
uniquebooleanyesThe kind's unique mark. True when each entity is one particular thing that can hold others, such as a person, and false when its things stack, such as dishes.
listedboolean | ConditionyesThe kind's listing rule for the view, true, false or a condition asked of each entity with '$' as it. A game's kinds are listed if left out, and a plugin's are not.
tagsstring[]yesThe tags every entity of the kind has, before its own tags.
flagsRecord<string, Condition>yesThe kind's flags, named conditions asked of each listed entity with '$' as it, such as { met: { 'cast/met': { character: '$' } } }. The view answers them in each entity's flags.
traits{ [K in keyof TraitRegistry]?: Partial<TraitRegistry[K]> } & Record<string, unknown>yesThe default traits of every entity of the kind, by trait id. An entity's own object for a trait is laid over this one field by field, and any other value replaces it whole.
uiUi<EntityUi>yesThe ui hints of every entity of the kind, under each entity's own. See EntityUi.

KvValue

Type. Explained in Common types.

A value in the kv store, which is true or false, a number or text.

import type { KvValue } from '@ifloom/engine'
type KvValue = boolean | number | string

lackingLine

Function. Explained in Stats.

Returns the refusal for a cost the player can't cover, from the stat's lacking, else the notEnough string with the stat's label in lower case.

import { lackingLine, type Game } from '@ifloom/engine'
function lackingLine(game: Game, id: string, amount: number): string

Uses: Game.

Loaded

Type. Explained in Content and packs.

The result of loadGame, the merged game with its prose, its variants and the problems found.

import type { Loaded, Game } from '@ifloom/engine'
type Loaded = {
  game: Game
  prose: Record<string, string>
  variants: Record<string, string[]>
  problems: Problem[]
}
FieldTypeOptionalDefaultDescription
gameGameThe loaded game, ready to run.
proseRecord<string, string>The game's prose keys' lines, merged from the content and the packs.
variantsRecord<string, string[]>The game's variants lists by name, each with its members' prose keys.
problemsProblem[]The problems with the content and the packs, each naming the one it came from. Empty when there are none.

LoadedSave

Type. Explained in Saves.

A save read back, with its state carried forward to this game through loadState.

import type { LoadedSave } from '@ifloom/engine'
type LoadedSave = {
  meta: SaveMeta
  state: GameState
  missingPacks: string[]
  missingPlugins: string[]
}
FieldTypeOptionalDefaultDescription
metaSaveMetaThe save's SaveMeta.
stateGameStateThe save's state, carried forward to this game's version through loadState.
missingPacksstring[]The ids of the mods the save was made with that the game wasn't loaded with, such as a mod since turned off.
missingPluginsstring[]The ids of the plugins the save was made with that this game does not have. The save keeps their state, unused.

loadGame

Function. Explained in Content and packs.

Returns the game merged from the base, the content and then the packs in order, with every problem found. Each problem names the content or pack that brought it.

The content checker (checkGame) checks the merged game. loadGame adds where each problem came from, and the problems with the content and packs themselves, such as a key declared twice or a key they can't hold. So a mod author reads "mod:spicier · scene allie.talk · choice kiss · unknown scene 'allie.snog'", not a stack trace.

import { loadGame } from '@ifloom/engine'
function loadGame(content: readonly Content[], base: GameBase, options?: LoadOptions): Loaded

Uses: Content, GameBase, LoadOptions, Loaded.

LoadOptions

Type. Explained in Content and packs.

Settings for loadGame. A game loaded without them has no packs.

import type { LoadOptions } from '@ifloom/engine'
type LoadOptions = {
  packs?: readonly Pack[]
}
FieldTypeOptionalDefaultDescription
packsreadonly Pack[]yesThe packs to load over the content, in order, each over the ones before, such as mods and unlocked content.

loadState

Function. Explained in Saves.

Returns a state from a save, a command log or a test made ready to play in this game. Returns a failed Result with a reason the player can read when it can't be.

It runs the engine's own steps and each field's load default, then the plugins' migrations, then the game's migrations, and last fills in the values the game declares and the save lacks.

import { loadState, type Game } from '@ifloom/engine'
function loadState(raw: unknown, game: Game): Result<GameState>

Uses: Game, Result, GameState.

MediaState

Type. Explained in Media.

The media a save keeps, in state.media. The engine reads the pools from content.

import type { MediaState } from '@ifloom/engine'
type MediaState = {
  picks: Record<string, string>
}
FieldTypeOptionalDefaultDescription
picksRecord<string, string>The file each pool request was given, by the key pickKey returns.

mediaType

Function. Explained in Prose and markup.

Returns 'video' for a file with a video extension (.mp4, .webm), else 'image'.

import { mediaType } from '@ifloom/engine'
function mediaType(src: string): 'image' | 'video'

memoryDriver

Function. Explained in Saves.

Returns a SaveDriver that keeps saves in memory, gone when the page is. Use it for tests and previews.

import { memoryDriver } from '@ifloom/engine'
function memoryDriver(): SaveDriver

Uses: SaveDriver.

MigrationTools

Type. Explained in Saves.

The tools a step of rules.migrations or a plugin's migrations gets beside the state.

import type { MigrationTools, Game } from '@ifloom/engine'
type MigrationTools = {
  game: Game
  fill: (parts?: FillPart[]) => GameState
}
FieldTypeOptionalDefaultDescription
gameGameThe game the save is loading into, for a step that reads its content, such as the entity an old id now names.
fill(parts?: FillPart[]) => GameStateReturns the state the step was given, with the values the game declares and the save lacks filled in. It fills the parts asked for, or every part if left out. A migration fills nothing unless its step calls this. See FillPart.

minigame

Function. Explained in Commands.

Returns a { minigame } block, a minigame played at this place in the flow. The flow waits until it ends, then carries on.

import { minigame } from '@ifloom/engine'
function minigame(id: string, extras?: BlockExtras): Block

Uses: BlockExtras, Block.

MinigameDef

Type. Explained in Minigames.

A minigame the game declares in minigames, a small state machine played with named inputs and timed by ticks. Every key it uses must be in its kv.

import type { MinigameDef } from '@ifloom/engine'
type MinigameDef = {
  id: string
  title?: string
  start: string
  kv?: Record<string, number>
  keys?: Record<string, string[]>
  states: Record<string, MinigameStateDef>
}
FieldTypeOptionalDefaultDescription
idstringThe minigame's id, which the minigame effect and a scene's minigame name.
titlestringyesThe minigame's title.
startstringThe id of the state the minigame starts in.
kvRecord<string, number>yesThe minigame's kv store, with each key's starting number, such as { score: 0 }. Content reads and writes the keys with of: 'minigame'.
keysRecord<string, string[]>yesThe keys a UI maps to each input, by input name, such as { up: ['ArrowUp', 'w'] }. Key names are those KeyboardEvent.key gives, and a UI picks its own if left out.
statesRecord<string, MinigameStateDef>The minigame's states, by name.

MinigameInput

Type. Explained in Minigames.

An input of the running minigame as the player sees it, in view.minigame.inputs. It has what a RenderedChoice needs, so a UI renders it as any button.

import type { MinigameInput } from '@ifloom/engine'
type MinigameInput = {
  id: string
  label: string
  command: { type: 'minigame'; input: string }
}
FieldTypeOptionalDefaultDescription
idstringThe input's name, as the minigame's on names it, such as 'up'.
labelstringThe input's label, from its on entry, else the minigame.<input> string (Up, Space), else its name with a capital.
command{ type: 'minigame'; input: string }The command pressing the input sends.

MinigameSceneFields

Type. Explained in Minigames.

The scene field that starts a minigame.

import type { MinigameSceneFields } from '@ifloom/engine'
type MinigameSceneFields = {
  minigame?: string
}
FieldTypeOptionalDefaultDescription
minigamestringyesThe id of the minigame that starts when the scene is entered. The scene shows again once it ends.

MinigameState

Type. Explained in Minigames.

The running minigame a save keeps, in state.minigame. The engine reads its states from content.

import type { MinigameState } from '@ifloom/engine'
type MinigameState = {
  id: string
  state: string
  elapsed: number
  kv: Record<string, number>
  steps: number
}
FieldTypeOptionalDefaultDescription
idstringThe minigame's id.
statestringThe name of the state the minigame is in.
elapsednumberThe milliseconds of ticks since the minigame entered that state.
kvRecord<string, number>The minigame's kv store, as play has left it.
stepsnumberThe number of transitions the minigame has taken, part of its random draws' seed.

MinigameStateDef

Type. Explained in Minigames.

A state of a minigame, in its states. It can wait (after), listen to inputs (on), move on by itself (always) or end the minigame (final).

import type { MinigameStateDef } from '@ifloom/engine'
type MinigameStateDef = {
  label?: string
  after?: { ms: number } & MinigameTransition
  on?: ({ input: string; when?: Condition; label?: string } & MinigameTransition)[]
  always?: ({ when?: Condition } & MinigameTransition)[]
  final?: { effects?: EffectRef[]; copy?: Record<string, string> }
}
FieldTypeOptionalDefaultDescription
labelstringyesThe words the player reads while the minigame is in this state, with tokens filled.
after{ ms: number } & MinigameTransitionyesThe state's timer. Once ms milliseconds of ticks have passed in the state, the engine takes the transition, and one that stays put starts the timer again. The tick that runs down the game's named timers runs it down too, in the order they run out.
on({ input: string; when?: Condition; label?: string } & MinigameTransition)[]yesThe state's inputs. For each input, the first entry whose when holds is taken, and an input with no such entry isn't live. label is the input's words for its button in this state, with tokens filled, such as a quiz's answer. The first live entry with one gives it. Without one the button reads the minigame.<input> string, else the input's name.
always({ when?: Condition } & MinigameTransition)[]yesThe state's automatic transitions, the first whose when holds taken on entering the state. Use them for a state that only decides where to go next, such as a win.
final{ effects?: EffectRef[]; copy?: Record<string, string> }yesThe state's ending. Entering the state ends the minigame. copy writes keys of the minigame's kv store to the player's ({ score: 'arrows.best' }). Then the minigame closes and effects run.

MinigameTarget

Type. Explained in Minigames.

A state a transition can go to at random, as its id or as its id with a weight. The weight is 1 if left out.

import type { MinigameTarget } from '@ifloom/engine'
type MinigameTarget = string | { state: string; weight?: number }

MinigameTransition

Type. Explained in Minigames.

A minigame transition, the state it goes to and the effects it runs on the way. With no go or to it stays in its state.

import type { MinigameTransition } from '@ifloom/engine'
type MinigameTransition = {
  go?: string
  to?: MinigameTarget[]
  effects?: EffectRef[]
}
FieldTypeOptionalDefaultDescription
gostringyesThe id of the state the transition goes to.
toMinigameTarget[]yesThe states the transition draws one from at random, by weight, when there's no go. The draw is seeded by the save.
effectsEffectRef[]yesThe effects the transition runs before it moves. Any effect works, such as a kv effect with of: 'minigame' or a turn.

MinigameView

Type. Explained in Minigames.

The running minigame as the player sees it, in view.minigame.

import type { MinigameView } from '@ifloom/engine'
type MinigameView = {
  id: string
  title: string | null
  state: string
  label: string | null
  timeLeft: number | null
  timeTotal: number | null
  inputs: MinigameInput[]
  kv: Record<string, number>
  keys: Record<string, string[]>
}
FieldTypeOptionalDefaultDescription
idstringThe minigame's id.
titlestring | nullThe minigame's title, or null.
statestringThe name of the state the minigame is in.
labelstring | nullThe state's label, with tokens filled, or null. view.scene.body has it rendered.
timeLeftnumber | nullThe milliseconds left on the state's timer. Null when the state has no timer.
timeTotalnumber | nullThe whole length of the state's timer in milliseconds. Null when the state has no timer.
inputsMinigameInput[]The inputs that are live now, in the order the state lists them.
kvRecord<string, number>The minigame's kv store now.
keysRecord<string, string[]>The keys the game maps to each input, by input name. Empty when it maps none.

ModFile

Type. Explained in Mods.

A mod as a JSON file, with the game it is for and the pack it adds. A mod is data only, so no code runs that the game didn't ship.

import type { ModFile } from '@ifloom/engine'
type ModFile = {
  ifloomMod: 1
  id: string
  name: string
  version?: string
  game: string
  description?: string
  pack: Pack
}
FieldTypeOptionalDefaultDescription
ifloomMod1The file's format, 1.
idstringThe mod's id. Its pack is loaded as mod:<id>.
namestringThe mod's name, for a mods page.
versionstringyesThe mod's own version, as its author writes it, such as '1.2'.
gamestringThe id of the game the mod was made for.
descriptionstringyesThe mod's description, a line for a mods page.
packPackThe Pack the mod adds, laid over the game's content.

Mods

Type. Explained in Mods.

One game's mod store, returned by mods. No call rejects, and a driver's failure answers with a reason and the driver's error as its cause.

import type { Mods } from '@ifloom/engine'
type Mods = {
  list: () => Promise<Result<InstalledMod[]>>
  add: (text: string) => Promise<Result<InstalledMod>>
  remove: (id: string) => Promise<Result<void>>
  setEnabled: (id: string, enabled: boolean) => Promise<Result<void>>
  packs: () => Promise<Result<Pack[]>>
}
FieldTypeOptionalDefaultDescription
list() => Promise<Result<InstalledMod[]>>Returns the installed mods, on or off, in name order. A mod stored unreadably is left out.
add(text: string) => Promise<Result<InstalledMod>>Adds a mod from a file's text, turned on, replacing one with the same id. It returns the mod, or the reason it can't be added.
remove(id: string) => Promise<Result<void>>Removes a mod, and does nothing if it isn't installed.
setEnabled(id: string, enabled: boolean) => Promise<Result<void>>Turns a mod on or off, and does nothing if it isn't installed.
packs() => Promise<Result<Pack[]>>Returns the packs of the mods that are on, in name order, to pass to loadGame as packs.

mods

Function. Explained in Mods.

Returns the Mods store of a game, kept by a driver. In a browser, an IndexedDB driver keeps mods across reloads with no server.

import { mods } from '@ifloom/engine'
function mods(gameId: string, driver: SaveDriver): Mods

Uses: SaveDriver, Mods.

need

Function. Explained in Actions.

Returns a blocked entry written the other way round, refused with reason unless when holds. For example need('Not on an empty stomach.', { stat: 'energy', gte: 2 }).

import { need } from '@ifloom/engine'
function need(reason: Reason, when: Condition): Blocked

Uses: Reason, Condition, Blocked.

Notice

Type. Explained in Notices.

A message the game gives the player outside a scene, such as a quest moving on or the rent falling due. The notify effect raises one, and the dismiss command marks it seen.

A UI shows a notice as a badge or a toast.

import type { Notice } from '@ifloom/engine'
type Notice = {
  id: string
  title: string
  text?: string
  image?: string
  tag?: string
  turn: number
  seen: boolean
}
FieldTypeOptionalDefaultDescription
idstringThe notice's id. A notice raised with the id of an earlier one replaces it.
titlestringThe notice's short line, kept as written. The view fills its tokens.
textstringyesThe notice's longer words, kept as written. The view fills their tokens.
imagestringyesThe notice's picture, as a path in the game's art/ folder ('notes/bins.jpg') or a URL.
tagstringyesThe notice's subject, for grouping badges, such as 'messages' or 'quests'.
turnnumberThe turn the notice was raised on.
seenbooleanThe notice's seen mark, true once the player has dismissed it.

NoticesView

Type. Explained in The view.

The notices as the player sees them, in view.notices. Only notices the player hasn't dismissed are listed.

import type { NoticesView } from '@ifloom/engine'
type NoticesView = {
  unseen: NoticeView[]
  byTag: Record<string, number>
}
FieldTypeOptionalDefaultDescription
unseenNoticeView[]The notices the player hasn't dismissed, newest first.
byTagRecord<string, number>The number of unseen notices for each tag, for badges. Untagged notices count under ''.

NoticeView

Type. Explained in The view.

A notice as the player sees it, in view.notices.unseen.

import type { NoticeView } from '@ifloom/engine'
type NoticeView = {
  id: string
  title: string
  text: string
  image: string | null
  tag: string | null
  turn: number
}
FieldTypeOptionalDefaultDescription
idstringThe notice's id, which the dismiss command takes.
titlestringThe notice's short line, with its tokens filled in.
textstringThe notice's longer words, with their tokens filled in. Empty if it has none.
imagestring | nullThe notice's picture, as a path through artSrc. Null if it has none.
tagstring | nullThe notice's subject, for grouping badges, such as 'messages'. Null if it has none.
turnnumberThe turn the notice was raised on.

notify

Function. Explained in Effects.

Returns the state with a notice raised. A notice with the id of an earlier one replaces it, unseen, as the newest.

import { notify, type Notice } from '@ifloom/engine'
function notify(state: GameState, notice: Omit<Notice, 'id' | 'turn' | 'seen'> & { id?: string }): GameState

Uses: GameState, Notice.

Once

Type. Explained in Actions.

A limit of once a game or once a turn on a choice, an action or a plugin's entry, such as a cheat. The engine counts a choice's or an action's uses in state.chosen.

import type { Once } from '@ifloom/engine'
type Once = {
  per: 'game' | 'turn'
  reason?: Reason
}
FieldTypeOptionalDefaultDescription
per'game' | 'turn'The limit's span, 'game' for once in the whole game or 'turn' for once a turn.
reasonReasonyesThe reason the player reads once the limit is spent. For a choice or an action, the engine's done string ("Already done.") if left out.

OpenPanel

Type. Explained in Panels.

The open panel, a named piece of UI over the story, with the arguments it was opened with. state.panel and view.panel hold it.

import type { OpenPanel } from '@ifloom/engine'
type OpenPanel = {
  panel: string
  with: PluginArgs
  scene?: string
}
FieldTypeOptionalDefaultDescription
panelstringThe panel's name, which the UI renders it by, such as 'shop', 'jobs' or one of the game's own.
withPluginArgsThe panel's arguments, such as { vendor: 'cafe' }. Empty if the effect gave none.
scenestringyesThe scene that holds the panel open, for a scene's own panel, which stays open as long as the scene does. It's left out for a panel the panel effect opened. closePanel doesn't close a panel a scene holds open.

ownedCount

Function. Explained in Entities.

Returns how many of a thing of has, added up across the receivers, or in the one via names.

import { ownedCount, type Game } from '@ifloom/engine'
function ownedCount(state: GameState, game: Game, ref: EntityRef, of?: string, via?: string): number

Uses: GameState, Game, EntityRef.

Pack

Type. Explained in Content and packs.

Content from outside the game's code, such as a mod, unlocked supporter content or a JSON export. It goes over the game's content and the packs before it, replacing what they declare by id.

type Pack = {
  id: string
  schema: number
  plugins?: Record<string, number>
  strings?: Record<string, string>
  prose?: Record<string, string>
  words?: Record<string, string>
  variants?: Record<string, VariantMember[]>
  data?: Record<string, Record<string, readonly PluginEntry[]>>
  kinds?: KindDef[]
  entities?: EntityDef[]
  traits?: TraitTable
  player?: PlayerDef | undefined
  kv?: Record<string, KvValue>
  resets?: Record<string, KvValue>
  storylines?: StorylineDef[]
  actions?: ActionDef[]
  triggers?: TriggerDef[]
  inputs?: InputDef[]
  settings?: SettingDef[]
  stats?: StatDef[]
  scenes?: DataScene[]
  patches?: Patch[]
  introScene?: string
  minigames?: MinigameDef[]
  timers?: TimerDef[]
  audio?: Partial<GameAudio>
  media?: GameMedia
  ui?: Ui<GameUi>
  saveable?: Blocked[]
  locks?: Lock[]
  phrases?: Phrases
  changes?: ChangesDef
  finished?: Condition
  carryOver?: CarryOver
  credits?: CreditGroup[]
}
FieldTypeOptionalDefaultDescription
idstringThe pack's id, which saves record. A mod's is mod:<id>.
schemanumberThe schema the pack was written against. loadGame upgrades an older one and refuses a newer one.
pluginsRecord<string, number>yesThe version of each plugin's content the pack was written for, by plugin id ({ shop: 13 }), numbered as Plugin.contentVersion is. That plugin's own steps upgrade an older one as it loads. A plugin left out is read as written for the pack's schema, or for the plugin's own version if that is lower.
stringsRecord<string, string>yesThe lines that replace the engine's and plugins' strings, by key.
proseRecord<string, string>yesThe prose keys' lines, by key.
wordsRecord<string, string>yesThe words table, other words for the fields a player reads, by key. A translation is one pack with this table and its own prose. Each key names one field, as translatableFields lists them (action.wait.label, entity.character:ava.name, scene.cafe.counter.text.intro). loadGame lays it over the merged content, a later pack's over an earlier one's, and reports a key that names no field.
variantsRecord<string, VariantMember[]>yesThe variants lists' members by list name, in order. Content and packs append to a list. A member is a prose key, or { prose: key, weight } to be drawn more or less often than the rest.
dataRecord<string, Record<string, readonly PluginEntry[]>>yesThe plugins' content, by plugin id and then list, such as { quests: { quests: [...] } }. A pack's entry replaces the one with the same id, as its scenes do.
kindsKindDef[]yesThe pack's kinds. A later pack's kind replaces an earlier one with the same id.
entitiesEntityDef[]yesThe pack's entities at the start. A later pack's entity replaces an earlier one with the same kind and id.
traitsTraitTableyesThe pack's traits, by trait id and then entity, over what each entity declares itself, such as { 'laundry/washable': { 'clothing:scarf': { temp: 30 } } }. A later pack's row replaces an earlier one's.
playerPlayerDef | undefinedyesThe pack's player. It replaces the content's player whole.
kvRecord<string, KvValue>yesThe pack's starting kv store, by key. A later pack's value replaces an earlier one's.
resetsRecord<string, KvValue>yesThe pack's keys reset each turn, by key. A later pack's value replaces an earlier one's.
storylinesStorylineDef[]yesThe pack's storylines, merged by id over the content's.
actionsActionDef[]yesThe pack's actions, by id. A later pack's action replaces an earlier one with the same id.
triggersTriggerDef[]yesThe pack's triggers, merged by id over the content's.
inputsInputDef[]yesThe pack's inputs, merged by id over the content's.
settingsSettingDef[]yesThe pack's settings. A later pack's setting replaces an earlier one with the same id.
statsStatDef[]yesThe pack's stats. A later pack's stat replaces an earlier one with the same id.
scenesDataScene[]yesThe pack's scenes. A later pack's scene replaces an earlier one with the same id.
patchesPatch[]yesThe pack's patches to the choices of scenes declared before it.
introScenestringyesThe scene open on the first frame. A later pack's replaces an earlier one's.
minigamesMinigameDef[]yesThe pack's minigames. A later pack's minigame replaces an earlier one with the same id.
timersTimerDef[]yesThe pack's timers. A later pack's timer replaces an earlier one with the same id.
audioPartial<GameAudio>yesThe pack's tracks, channels and defaults, over the content's. A later pack's track or channel replaces an earlier one with the same id, and its mute, sound and default entries win too.
mediaGameMediayesThe pack's pools of pictures and videos. A later pack's pool replaces an earlier one with the same id, files and all.
uiUi<GameUi>yesThe pack's ui hints for the whole game, merged hint by hint. A later pack's hint replaces an earlier one's, and the rest stay.
saveableBlocked[]yesThe pack's reasons to refuse saving, added after the content's. An entry with the id of an earlier one replaces it.
locksLock[]yesThe pack's locks, added after the content's. A lock with the id of an earlier one replaces it.
phrasesPhrasesyesThe pack's phrases, words that change with the state, printed in a line as {{name}}. Each is a plain string or a list of { when?, text } rows tried in order, and an object is a group. A later pack's phrase replaces an earlier one with the same full name, and a pack can add phrases to a group.
changesChangesDefyesThe pack's tracked stats, by id, such as { stats: ['coins', 'trust'] }. The engine adds every file's and pack's lists together.
finishedConditionyesThe pack's condition for the game being finished. It replaces the content's, and the runner records the first time it holds in the profile's core:finished.
carryOverCarryOveryesThe pack's rules for a New Game+. They replace the content's carryOver whole.
creditsCreditGroup[]yesThe pack's credits, in groups. A group whose id is already declared gets these credits after its own. Its title or description replaces the earlier one, and a new id adds a group after the others.

panel

Function. Explained in Effects.

Returns a { panel } block, a panel opened at this place in the flow with args as its with. The flow waits until the player closes it.

import { panel } from '@ifloom/engine'
function panel(name: string, args?: PluginArgs, extras?: BlockExtras): Block

Uses: PluginArgs, BlockExtras, Block.

parseRef

Function. Explained in Entities.

Returns an entity reference such as 'staff:ana' split into its kind and id, or undefined when the string isn't one.

import { parseRef } from '@ifloom/engine'
function parseRef(ref: string): { kind: string; id: string } | undefined

Patch

Type. Explained in Content and packs.

A patch a pack declares in patches, a change to one choice of a scene an earlier pack or the content declared. It adds, drops or replaces the choice.

addChoice puts the choice before the choice before names, or last when before is left out or not found. dropChoice names the choice to drop, and replaceChoice takes the place of the choice with its id.

import type { Patch } from '@ifloom/engine'
type Patch = { scene: string; addChoice: DataScene['choices'][number]; before?: string } | { scene: string; dropChoice: string } | { scene: string; replaceChoice: DataScene['choices'][number] }

Uses: DataScene.

Phrase

Type. Explained in Phrases.

A phrase the game declares in phrases, words for the middle of a sentence that change with the state. It's a list of rows tried in order, a plain string, or rows with their arguments.

import type { Phrase } from '@ifloom/engine'
type Phrase = string | PhraseRow[] | PhraseWithArgs

Uses: PhraseRow, PhraseWithArgs.

PhraseRow

Type. Explained in Phrases.

A row of a phrase, its words shown while when holds. A row with no when always holds, and the view fills the tokens in its words.

import type { PhraseRow } from '@ifloom/engine'
type PhraseRow = {
  when?: Condition
  text: string
}
FieldTypeOptionalDefaultDescription
whenConditionyesThe row's condition. The row's words show while it holds, and always when it's left out.
textstringThe row's words, with tokens the view fills.

Phrases

Type. Explained in Phrases.

The phrases the game declares in phrases, by name. Each entry is a phrase or a group of more phrases, nested as deep as you like.

{ outfit: { verdict: [...] }, weather: 'grey' } declares outfit.verdict and weather.

import type { Phrases } from '@ifloom/engine'
type Phrases = {
  [key: string]: Phrase | Phrases
}

PhraseWithArgs

Type. Explained in Phrases.

A phrase that takes arguments, with their names in args and its rows. A token passes each argument as name=value.

In a row's when, a string that is exactly $<arg> becomes the value the token passed, as an entity reference when it names one. In a row's text, $<arg> becomes that entity's name, or the value as passed.

import type { PhraseWithArgs } from '@ifloom/engine'
type PhraseWithArgs = {
  args: string[]
  rows: PhraseRow[]
}
FieldTypeOptionalDefaultDescription
argsstring[]The names of the arguments the phrase takes.
rowsPhraseRow[]The phrase's rows, tried in order.

PictureDef

Type. Explained in Media.

A picture a scene or a location declares in its picture, layers with hotspots on them.

import type { PictureDef } from '@ifloom/engine'
type PictureDef = {
  layers: PictureLayer[]
  hotspots?: HotspotDef[]
  aspect?: string
}
FieldTypeOptionalDefaultDescription
layersPictureLayer[]The picture's layers, bottom first.
hotspotsHotspotDef[]yesThe picture's hotspots, each a button the UI renders over the picture.
aspectstringyesThe picture's width over height, in CSS form, such as '16/9'. The UI's own if left out.

PictureLayer

Type. Explained in Media.

A layer of a picture, a file or a pool's pick, shown while when holds. Give src or pool, not both.

import type { PictureLayer } from '@ifloom/engine'
type PictureLayer = {
  id?: string
  src?: string
  pool?: string
  tags?: string[]
  when?: Condition
  video?: boolean
  controls?: boolean
  once?: boolean
  sound?: boolean
  poster?: string
}
FieldTypeOptionalDefaultDescription
idstringyesThe layer's id, which a hotspot's layer names.
srcstringyesThe layer's file, in the game's art/ folder or a URL.
poolstringyesThe pool in media.pools the layer's file is drawn from. The save keeps the pick.
tagsstring[]yesThe tags the pool's pick should have, most important first.
whenConditionyesThe layer's condition. The layer shows only while it holds.
videobooleanyesThe layer's video mark, true to show it as a video. A .mp4 or .webm file is a video anyway.
controlsbooleanyesThe controls flag, which shows the player's controls, so the video waits to be started instead of playing by itself.
oncebooleanyesThe once flag, which plays the video once instead of looping.
soundbooleanyesThe sound flag, which plays the video with sound instead of muted.
posterstringyesThe still shown before the video plays, as a path like any picture's.

PictureLayerView

Type. Explained in Media.

A picture layer as the player sees it, in a PictureView's layers.

import type { PictureLayerView } from '@ifloom/engine'
type PictureLayerView = {
  id: string | null
  src: string
  video?: VideoView
}
FieldTypeOptionalDefaultDescription
idstring | nullThe layer's id, or null.
srcstringThe layer's file, through artSrc, with a pool's pick resolved.
videoVideoViewyesThe layer's playback settings when it's a video. Left out for a still picture.

PictureView

Type. Explained in Media.

A picture as the player sees it, in view.scene.picture or a location's picture. It lists the layers shown now, bottom first, and the hotspots on them.

import type { PictureView } from '@ifloom/engine'
type PictureView = {
  aspect: string | null
  layers: PictureLayerView[]
  hotspots: HotspotView[]
}
FieldTypeOptionalDefaultDescription
aspectstring | nullThe picture's width over height, such as '16/9'. Null when the picture doesn't set it.
layersPictureLayerView[]The layers whose when holds, bottom first.
hotspotsHotspotView[]The hotspots whose when holds and whose layer shows.

Played

Type. Explained in Entities.

The one the player is playing, a protagonist or 'player'.

import type { Played } from '@ifloom/engine'
type Played = EntityRef | typeof PLAYER

Uses: EntityRef.

PLAYER

Const. Explained in Entities.

The id of the player themselves, whoever they are playing.

import { PLAYER } from '@ifloom/engine'
const PLAYER: 'player'

PlaylistDef

Type. Explained in Audio.

A playlist the game declares in audio.tracks, background tracks played one after another. Its order is 'loop' if left out.

import type { PlaylistDef } from '@ifloom/engine'
type PlaylistDef = {
  playlist: (string | { track: string; weight?: number })[]
  order?: 'inOrder' | 'loop' | 'shuffle'
}
FieldTypeOptionalDefaultDescription
playlist(string | { track: string; weight?: number })[]The playlist's track ids, each on a background channel. In a shuffled playlist a track can carry a weight, { track: 'rain', weight: 3 }, which makes it likely to come earlier. A plain id has weight 1.
order'inOrder' | 'loop' | 'shuffle'yesThe playlist's order. 'inOrder' plays the list once, 'loop' plays it over and over, and 'shuffle' plays it over and over in an order drawn from the save's seed. 'loop' if left out. With weights, the shuffle draws the first track by weight, then the next from those left, and so on, so a heavier track tends to play sooner.

PluginCall

Type. Explained in Calls by name.

A plugin's or the game's condition, effect or command in the short form, with its full name as the only key. The value is its arguments as an object, or true for none.

{ 'quests/done': { quest: 'bakery' } } and { 'calendar/weekend': true } are calls. Any other value, such as a list, a string or a number, is a problem the content checker reports, and the engine asks the call with no arguments.

import type { PluginCall } from '@ifloom/engine'
type PluginCall = {
  [key: `${string}/${string}`]: true | PluginArgs
}

pluginQuery

Function. Explained in Queries and partners.

Returns a plugin's query by full name, ready to ask, or undefined when the game doesn't have it.

As with context.query, a name declared in QueryRegistry takes its arguments and answers its type. Any other name takes any arguments, with the answer's type given.

import { pluginQuery, type Game } from '@ifloom/engine'
function pluginQuery<K extends keyof QueryRegistry>(game: Game | undefined, name: K): ((state: GameState, ...args: QueryArgs<K>) => QueryAnswer<K>) | undefined
function pluginQuery<T = unknown>(game: Game | undefined, name: string): ((state: GameState, args?: PluginArgs) => T) | undefined

Uses: QueryRegistry, Game, GameState, QueryArgs, QueryAnswer, PluginArgs.

point

Function. Explained in Effects.

Returns a point, a place in the flow a choice's jump(id) goes to, anywhere in a scene's body, a section or a choice's then.

import { point } from '@ifloom/engine'
function point(id: string): Block

Uses: Block.

PoolFile

Type. Explained in Media.

A file in a pool in media.pools, with its path, its tags and its weight against the other files that fit. The weight is 1 if left out.

import type { PoolFile } from '@ifloom/engine'
type PoolFile = {
  src: string
  tags?: string[]
  weight?: number
}
FieldTypeOptionalDefaultDescription
srcstringThe file's path, in the game's art/ folder or a URL.
tagsstring[]yesThe file's tags, which a request's tags match.
weightnumberyesThe file's weight in a draw, against the other files that fit. 1 if left out.

Price

Type. Explained in The view.

The cost of a choice or action, shown on its button before the player presses it. It lists costs only, since a payout printed on a choice tells the player which one is right.

import type { Price } from '@ifloom/engine'
type Price = {
  stats?: { id: string; amount: number; text: string }[]
  notes?: string[]
  text: string
}
FieldTypeOptionalDefaultDescription
stats{ id: string; amount: number; text: string }[]yesThe stats the price spends, in the order the button lists them, each with its amount and its words in text.
notesstring[]yesThe plugins' words for what else it costs, such as "until evening".
textstringThe whole price as one line for the player, such as 2 coins · until evening. It joins each stat's text, then the notes, with the priceSeparator string.

Probe

Type. Explained in Checking content.

A state the content checker renders every scene against, named for the problems it finds. Make one with probe, by playing.

import type { Probe } from '@ifloom/engine'
type Probe = {
  name: string
  state: GameState
}
FieldTypeOptionalDefaultDescription
namestringThe probe's name, which the problems it finds carry, such as 'evening, after the café'.
stateGameStateThe state to render every scene against.

Problem

Type. Explained in Checking content.

A fault the content checker finds in a game's content, with the pack it came from and the place in it.

import type { Problem } from '@ifloom/engine'
type Problem = {
  pack: string
  where: string
  what: string
}
FieldTypeOptionalDefaultDescription
packstringThe name or id of the content or pack the problem came from. It is game for a hand-built game.
wherestringThe place in the content the problem is, such as scene cafe.counter or finished.
whatstringThe fault, such as unknown storyline "tides".

Profile

Type. Explained in The profile.

The player's record that outlives a save, such as settings, whether they have finished the game, and plugins' records like achievements. It is one JSON object of namespaces, kept at <game id>.profile in a save driver.

The engine uses two namespaces, core:settings (each setting's stored value, by id) and core:finished ({ at }, when the game was first finished). A UI uses ui: names, such as the React UI's gate, ui:gate. A plugin uses its own bare id, which can't hold a :, so the prefixes are reserved.

import type { Profile } from '@ifloom/engine'
type Profile = {
  get: <T = unknown>(namespace: string) => Promise<T | undefined>
  set: (namespace: string, value: unknown) => Promise<void>
  update: <T = unknown>(namespace: string, change: (current: T | undefined) => T | undefined) => Promise<T | undefined>
  subscribe: (listener: (namespace: string, value: unknown) => void) => () => void
}
FieldTypeOptionalDefaultDescription
get<T = unknown>(namespace: string) => Promise<T | undefined>Returns the value a namespace holds, or undefined if it holds none.
set(namespace: string, value: unknown) => Promise<void>Stores a value in a namespace. Undefined clears it.
update<T = unknown>(namespace: string, change: (current: T | undefined) => T | undefined) =>…Changes a namespace from the value it holds now, with no other write in between, and returns the value it holds afterwards. Return undefined, or the same value, from change to leave it.
subscribe(listener: (namespace: string, value: unknown) => void) => () => voidCalls a listener with the namespace and new value of every write, and returns a function that stops it.

profile

Function. Explained in The profile.

Returns the Profile of a game, kept by a driver. Reads and writes run one at a time, in order.

It reads only the game's id, so a profile can be opened before the game is built, as in profile({ id: 'small-town' }, driver).

import { profile, type Game } from '@ifloom/engine'
function profile(game: Pick<Game, 'id'>, driver: SaveDriver): Profile

Uses: Game, SaveDriver, Profile.

proseBeats

Function. Explained in Prose and markup.

Returns the prose key's line rendered as beats, the way a scene's body is rendered. Returns null when the game has no line by that key.

The engine fills its tokens for this save, cuts it into paragraphs and spoken lines, names each speaker from their entity and puts its inline markup (bold, italics, UI pieces) in spans. A UI calls it to show a line away from the scene, such as in a dialog an inline piece opens.

import { proseBeats, type Game } from '@ifloom/engine'
function proseBeats(state: GameState, game: Game, key: string): SceneBeat[] | null

Uses: GameState, Game, SceneBeat.

ProseStore

Type. Explained in Prose and markup.

The store of prose keys and variants lists that scenes read. loadGame makes it from the content's prose.

import type { ProseStore } from '@ifloom/engine'
type ProseStore = {
  line: (key: string, state?: GameState) => string | undefined
  variants: (name: string) => string[]
  weight?: (name: string, key: string) => number
  keys?: () => string[]
}
FieldTypeOptionalDefaultDescription
line(key: string, state?: GameState) => string | undefinedThe store's function that returns a prose key's line, with its tokens filled for state.
variants(name: string) => string[]The store's function that returns a variants list's members by its name, in declaration order.
weight(name: string, key: string) => numberyesThe store's function that returns a member's weight in a variants list. Every member weighs 1 if left out.
keys() => string[]yesThe store's function that lists every prose key, so the content checker can read all the prose's markup. The checker reads only the keys content names if left out.

protagonist

Function. Explained in Entities.

Returns whom 'you' stands for now, the protagonist the you effect chose or else 'player'.

import { protagonist } from '@ifloom/engine'
function protagonist(state: GameState): Played

Uses: GameState, Played.

Query

Type. Explained in Queries and partners.

A function that asks a plugin or the game a query by full name. It returns undefined when the game has no such query.

A name declared in QueryRegistry takes its declared arguments and returns its declared answer. Any other name takes any arguments, and you give the answer's type, as in query<number>('loyalty/stampsLeft').

import type { Query } from '@ifloom/engine'
type Query = { <K extends keyof QueryRegistry>(name: K, ...args: QueryArgs<K>): QueryAnswer<K> | undefined; <T = unknown>(name: string, args?: PluginArgs): T | undefined }

Uses: QueryRegistry, QueryArgs, QueryAnswer, PluginArgs.

QueryRegistry

Type. Explained in Declaring a plugin's calls.

The registry of queries plugins and the game answer, by full name, each typed as a function from its arguments to its answer ('loyalty/stampsLeft': () => number). context.query and pluginQuery read it.

A plugin declares its own queries here. Code that doesn't import the answering plugin gives the answer's type, query<number>('loyalty/stampsLeft').

import type { QueryRegistry } from '@ifloom/engine'
type QueryRegistry = {

  // …
}

Plugins add fields of their own to it, which their pages list.

Range

Type. Explained in Common types.

The bounds a condition compares a number with, so { gte: 3 } holds for 3 or more. Each bound is an Amount, such as { gte: { stat: 'rent' } }.

import type { Range } from '@ifloom/engine'
type Range = {
  gte?: Amount
  gt?: Amount
  lte?: Amount
  lt?: Amount
}
FieldTypeOptionalDefaultDescription
gteAmountyesThe range's lower bound, which the number must reach or pass.
gtAmountyesThe range's lower bound, which the number must pass.
lteAmountyesThe range's upper bound, which the number must not pass.
ltAmountyesThe range's upper bound, which the number must stay below.

RawPack

Type. Explained in Plugin migrations.

A pack as it arrived, in the shape of the schema it records, which may be older than SCHEMA.

import type { RawPack } from '@ifloom/engine'
type RawPack = {
  schema: number
}

It also takes any other key: [key: string]: unknown.

FieldTypeOptionalDefaultDescription
schemanumberThe content schema the pack was written for.

Reason

Type. Explained in Actions.

The words a player reads when something is refused, written in place ('Closed.') or as a strings key ({ string: 'shop/closed' }). Read one with reasonOf.

A key lets a game reword a reason once for every place that uses it.

import type { Reason } from '@ifloom/engine'
type Reason = string | { string: string }

reasonOf

Function. Explained in Strings.

Returns a refusal's words for a Reason. A string is returned as written, and { string: 'shop/closed' } is read with stringOf.

import { reasonOf, type Game } from '@ifloom/engine'
function reasonOf(game: Game | undefined, reason: string | { string: string }): string

Uses: Game.

receiversOf

Function.

Returns the game's plugins that keep things, in the order receive asks them.

function receiversOf(game: Game | undefined): readonly Receiving[]

Uses: Game.

receiveThing

Function. Explained in Entities.

Returns the state with count of a thing given to to, by the first receiver that claims it.

The one via names takes it whether it claims it or not. The state comes back unchanged when none takes it.

import { receiveThing, type Game } from '@ifloom/engine'
function receiveThing(state: GameState, game: Game, ref: EntityRef, count: number, to?: string, via?: string): GameState

Uses: GameState, Game, EntityRef.

releaseThing

Function. Explained in Entities.

Returns the state with up to count of a thing taken from from, asking each receiver in order until it's done.

import { releaseThing, type Game } from '@ifloom/engine'
function releaseThing(state: GameState, game: Game, ref: EntityRef, count: number, from?: string, via?: string): GameState

Uses: GameState, Game, EntityRef.

RenderedChoice

Type. Explained in The view.

A choice or action ready to render as a button, in view.scene.choices, view.actions or a plugin's view. A UI sends its command when the player presses it.

import type { RenderedChoice } from '@ifloom/engine'
type RenderedChoice = {
  id: string
  label: string
  price?: Price
  disabled?: string
  tags?: string[]
  irreversible?: string
  ui?: Ui<ChoiceUi>
  warning?: string
  command: Command
}
FieldTypeOptionalDefaultDescription
idstringThe choice's or action's id.
labelstringThe button's label, with tokens filled.
pricePriceyesThe button's price for this state, with its words in text. Left out when it's free.
disabledstringyesThe reason the player can't press the button now, in the player's words. Left out when they can.
tagsstring[]yesThe choice's or action's tags, for a UI to style or filter it by.
irreversiblestringyesThe warning that the choice or action can't be undone, for a UI to show on its button.
uiUi<ChoiceUi>yesThe choice's or action's ui hints, unchanged from content. Left out with none, and typed by ChoiceUi.
warningstringyesThe reason a plugin's guard gives for refusing the button softly, such as running past dawn. The player can press it, but the reducer refuses it, so a UI shows the warning instead.
commandCommandThe command a UI sends when the player presses the button, as runner.apply(choice.command).

replay

Function. Explained in The runner.

Returns the state a CommandLog ends in, played back against a game. A log that can't be read, such as one from a newer engine, gives the reason.

The log's start comes in through loadState. The engine's command steps and each plugin's commandMigrations carry its commands forward from the versions the log records, so a log from an older engine, plugin or game still plays. A command that is refused is skipped, as it was when it was played.

import { replay, type Game } from '@ifloom/engine'
function replay(game: Game, log: CommandLog): Result<GameState>

Uses: Game, CommandLog, Result, GameState.

resolveYou

Function. Explained in Entities.

Returns whom an id stands for now, so 'you' becomes the protagonist or the player. Any other id is returned unchanged.

import { resolveYou } from '@ifloom/engine'
function resolveYou(state: GameState, who: string): string

Uses: GameState.

Result

Type. Explained in Common types.

The answer of a call that can fail in a way its caller should expect, such as a save that won't read. A function that returns a Result never throws for those failures.

ok tells success from failure. On success value holds the answer. On failure reason says why, in words a player can read, and cause holds the error behind it when one was thrown (a save driver's, say), for a log.

import type { Result } from '@ifloom/engine'
type Result<T> = { ok: true; value: T; reason?: never; cause?: never } | { ok: false; reason: string; cause?: unknown; value?: never }

Roll

Type. Explained in Dice rolls.

A roll the roll effect made, with the face each die showed, the total and the outcome against a target. view.rolls lists the last command's.

import type { Roll } from '@ifloom/engine'
type Roll = {
  key: string
  dice: string
  faces: number[]
  plus: number
  total: number
  against?: number
  passed?: boolean
  critical?: 'max' | 'min'
}
FieldTypeOptionalDefaultDescription
keystringThe kv key the roll stored its total under.
dicestringThe dice thrown, in notation without the added number, such as '2d6'.
facesnumber[]The face each die showed, in order.
plusnumberThe number added to the faces, the notation's own +1 and the effect's plus together. 0 when nothing was added.
totalnumberThe roll's total, the faces added up plus plus.
againstnumberyesThe target the total had to reach. Left out when the effect gave none.
passedbooleanyesThe roll's outcome, true when the total reached against. Left out when there's no target.
critical'max' | 'min'yesThe roll's critical mark, 'max' when every die showed its highest face and 'min' when every die showed 1.

RollsState

Type. Explained in Dice rolls.

The rolls a save keeps, with the count of rolls made, the last command's rolls and the latest roll under each key.

import type { RollsState } from '@ifloom/engine'
type RollsState = {
  made: number
  last: Roll[]
  latest: Record<string, Roll>
}
FieldTypeOptionalDefaultDescription
madenumberThe number of rolls this save has made. It's part of each new roll's seed.
lastRoll[]The rolls the last command made, in order.
latestRecord<string, Roll>The latest roll under each key, which the roll condition reads.

Runner

Type. Explained in The runner.

The object a UI drives a game through, returned by createRunner or by browserRunner from @ifloom/browser. A call that can fail in a way a UI should expect answers with a Result and never throws.

A refused command, an empty slot and a setting with no profile to keep it are such failures.

import type { Runner, Game } from '@ifloom/engine'
type Runner = {
  readonly game: Game
  readonly state: GameState
  view: () => View
  apply: (ref: CommandRef) => Result<GameState>
  undo: () => boolean
  redo: () => boolean
  log: () => CommandLog
  played: () => number
  readonly saves: Saves | undefined
  readonly offers: { undo: boolean; backlog: boolean }
  save: (slot: string, name?: string | undefined) => Promise<Result<SaveMeta>>
  restore: (loaded: LoadedSave) => void
  load: (slot: string) => Promise<Result<LoadedSave>>
  settled: () => Promise<void>
  readonly profile: Profile | undefined
  setSetting: (id: string, to: KvValue) => Result<KvValue>
  newGame: (start?: StartOptions | undefined) => Promise<GameState>
  snapshot: () => RunnerSnapshot
  subscribe: (listener: (snapshot: RunnerSnapshot) => void) => () => void
  setHelper: <K extends string>(id: K, value: (K extends 'unlocks' ? HelperRegistry[K] : unknown) | undefined) => void
}
FieldTypeOptionalDefaultDescription
gameGameThe game this runner plays.
stateGameStateThe state in play.
view() => ViewReturns the view of the state in play. It returns the same object for the same state, so a UI, the audio player and the backlog can all read it. Each plugin's view reads that plugin's profile namespace. When a namespace changes, the runner builds that plugin's view again into a new view object and tells listeners, though the state is the same.
apply(ref: CommandRef) => Result<GameState>Runs a command and returns the next state. A refused command leaves the state as it was and returns the reason. The runner logs a tick like any command, but undo steps over it, it adds nothing to the backlog, and it autosaves only when it changes the scene or the turn. A newGame, sent on its own or by a choice, starts a new game as newGame() does, with the profile's play settings as last read.
undo() => booleanSteps back one command. Returns false when there is nothing to undo.
redo() => booleanSteps forward one command after an undo. Returns false when there is nothing to redo.
log() => CommandLogReturns the CommandLog of this game, its start state and every command since, for replay.
played() => numberReturns the time played, in milliseconds. It counts on from the time a loaded save recorded.
savesSaves | undefinedThe save store this runner writes to, for a menu that reads, exports or imports saves. It is undefined without saves. Its writes and removals show in the snapshot's saves. Like the store, it never rejects. When the driver fails, each call answers why and tells onSaveError.
offers{ undo: boolean; backlog: boolean }The features a menu should offer, undo true when history is on and backlog true when the backlog is on.
save(slot: string, name?: string | undefined) => Promise<Result<SaveMeta>>Saves the state in play to a slot and returns the save's SaveMeta. It fails with the reason when there are no saves, the game's saveable refuses saving now, or the driver fails. view().saving says beforehand whether a save would be refused.
restore(loaded: LoadedSave) => voidPuts a save in play that did not come from a slot, such as one the player imported from a file (saves.importText). It starts a fresh history, backlog and log, as load does.
load(slot: string) => Promise<Result<LoadedSave>>Loads a slot into play and returns the save. The runner starts a fresh history, backlog and log from it, and the time played it recorded. It fails with the reason when there are no saves, the slot is empty, this game can't read the save, or the driver fails. A driver's failure is told to onSaveError too.
settled() => Promise<void>Returns a promise that settles once every autosave and profile write so far is written. It also waits for the first listing of the saves and the first read of the profile.
profileProfile | undefinedThe profile this runner writes settings and finished to, which a UI can use for namespaces of its own. It is undefined without profile. It never rejects. A read the driver fails answers undefined, and a write it fails is dropped, each told to onSaveError.
setSetting(id: string, to: KvValue) => Result<KvValue>Changes a setting of either kind and returns the value set. A value its declaration refuses, or a ui setting without a profile, fails with the reason. The runner sends a play setting as the setting command, so it changes the game in play, and the profile keeps it for the next new game. It writes a ui setting to the profile only. Listeners are told either way.
newGame(start?: StartOptions | undefined) => Promise<GameState>Starts a new game in place and returns its first state. The history, backlog, log and time played start fresh. Play settings not given are the player's, from the profile, or from the game in play without one. The seed is random unless given. For New Game+, pass carry: runner.state.
snapshot() => RunnerSnapshotReturns the RunnerSnapshot, one value with all a UI renders. The same object comes back until any part of it changes.
subscribe(listener: (snapshot: RunnerSnapshot) => void) => () => voidCalls a listener with each new snapshot and returns a function that stops it. A new snapshot comes with a change of state, of a setting, of the profile a view reads, of the saves, or of a helper's report.
setHelper<K extends string>(id: K, value: (K extends 'unlocks' ? HelperRegistry[K] : unknown) |…Sets a helper's report under its id in the snapshot's helpers, and tells listeners when it changes. Undefined removes the report. startUnlocks reports this way whether it is checking a code.

RunnerOptions

Type. Explained in The runner.

Settings for createRunner. Undo, the backlog, saving, autosave and the profile are each off when left out.

import type { RunnerOptions } from '@ifloom/engine'
type RunnerOptions = {
  saves?: Saves
  history?: HistoryOptions | boolean
  backlog?: BacklogOptions | boolean
  autosave?: AutosaveOptions
  now?: () => number
  onSaveError?: (error: unknown) => void
  profile?: Profile
}
FieldTypeOptionalDefaultDescription
savesSavesyesThe save store that save, load and autosave write to. Without it, save and load refuse and autosave does nothing.
historyHistoryOptions | booleanyesThe undo and redo settings, true for 50 steps back or a HistoryOptions. Undo is off if left out.
backlogBacklogOptions | booleanyesThe backlog settings, true for 200 entries or a BacklogOptions. The backlog is off if left out.
autosaveAutosaveOptionsyesThe autosave policy, which writes a slot of its own ('auto') as the game goes on. It needs saves, and autosave is off if left out.
now() => numberyesThe clock that times play, in milliseconds. Date.now if left out, and tests pass their own.
onSaveError(error: unknown) => voidyesThe function the runner tells each error a save driver or the profile throws. Without it, the runner drops the error. It hears about an autosave, save, load, any call through runner.saves or runner.profile, the first listing of the saves and a profile write. The writes queued after a failed one still run.
profileProfileyesThe profile that keeps what outlives a save, such as settings, finished and plugins' namespaces. Without one, the runner writes nothing there and refuses to change a ui setting.

RunnerSnapshot

Type. Explained in The runner.

One value with all a UI renders from the runner, including the view, the settings, the backlog and the saves. It's a new object whenever a part changes, and the same object until then.

runner.snapshot() returns it, and runner.subscribe passes each new one to its listeners. A UI that keeps it whole (Vue's shallowRef, React's useSyncExternalStore, a Svelte store) renders again exactly when something changed.

import type { RunnerSnapshot } from '@ifloom/engine'
type RunnerSnapshot = {
  readonly state: GameState
  readonly view: View
  readonly settings: Readonly<Record<string, KvValue>>
  readonly backlog: readonly BacklogEntry[]
  readonly canUndo: boolean
  readonly canRedo: boolean
  readonly saves: readonly SaveListing[]
  readonly helpers: HelpersIn
  readonly pressed: RenderedChoice | null
  readonly fresh: boolean
}
FieldTypeOptionalDefaultDescription
stateGameStateThe state in play, the same as runner.state.
viewViewThe view of the state in play, the same as runner.view().
settingsReadonly<Record<string, KvValue>>The value of each setting the game declares, by setting id. A stored value that no longer fits its setting reads as the default. A play setting's value comes from the game in play. A ui setting's value comes from the profile, or is its default without a profile or until the profile has been read (settled).
backlogreadonly BacklogEntry[]The backlog's entries, oldest first. It is empty unless the backlog is on.
canUndobooleanTrue when undo has a step to go back to.
canRedobooleanTrue when redo has a step to go forward to.
savesreadonly SaveListing[]The saves in the runner's saves, newest first, then any that can't be read. It is empty without saves. The runner lists them once when it starts (settled waits for it). It keeps the list up to date as it saves and as runner.saves writes and removes.
helpersHelpersInThe reports of the helpers started beside the runner, by helper id, such as unlocks. A helper sets its report with setHelper.
pressedRenderedChoice | nullThe choice or action that led to the screen on show, as it was offered. A UI reads its ui hints to play the transition it asks for. The runner sets it when a command it runs changes the screen (view.scene.key), from the choices, inline actions and actions of the view the command was sent from, and keeps it while the screen stays. It is null after a tick, a command no choice or action offered, an undo, a redo, a load or a new game.
freshbooleanTrue when the state on show came from a command the runner just ran, and false after an undo, a redo, a load or a new game. A UI animates what the player just did, such as the dice of view.rolls, only while it's true.

RunningTimer

Type. Explained in Timers.

A running timer a save keeps, with the milliseconds left and its whole length. The engine reads its effects from content when it runs out.

import type { RunningTimer } from '@ifloom/engine'
type RunningTimer = {
  left: number
  total: number
}
FieldTypeOptionalDefaultDescription
leftnumberThe milliseconds the timer has left. At 0 it runs out on the next tick.
totalnumberThe timer's whole length in milliseconds, the length it started with, raised when time added goes past it.

SAVE_VERSION

Const. Explained in Saves.

The save format's version. Only a change to the shape of a field saves already have bumps it, with a step in STEPS that reshapes older saves.

An added field doesn't bump it. The field declares a load default in FIELDS or in its feature's state, and an older save gets that default when it loads.

import { SAVE_VERSION } from '@ifloom/engine'
const SAVE_VERSION: 1

SaveDriver

Type. Explained in Saves.

A store of text by key that the save store and the profile write to. Every driver is asynchronous, even over synchronous storage, so a game can swap one for another.

The save store talks to a driver and nothing else, so a game chooses where its saves are kept. @ifloom/browser has drivers for localStorage and IndexedDB, memoryDriver keeps them in memory, and a game can write its own, such as a desktop wrapper's file system or a sync service.

import type { SaveDriver } from '@ifloom/engine'
type SaveDriver = {
  name: string
  get: (key: string) => Promise<string | null>
  set: (key: string, value: string) => Promise<void>
  remove: (key: string) => Promise<void>
  keys: (prefix: string) => Promise<string[]>
}
FieldTypeOptionalDefaultDescription
namestringThe driver's name, such as "localStorage" or "indexedDB", for diagnostics and the debug panel.
get(key: string) => Promise<string | null>Returns the text stored under a key, or null if there's none.
set(key: string, value: string) => Promise<void>Stores text under a key, replacing what was there.
remove(key: string) => Promise<void>Deletes a key, and does nothing if it isn't there.
keys(prefix: string) => Promise<string[]>Returns every key that starts with a prefix.

SaveExtra

Type. Explained in Saves.

Settings for Saves.write besides the state.

import type { SaveExtra } from '@ifloom/engine'
type SaveExtra = {
  name?: string
  played?: number
  savedAt?: number
}
FieldTypeOptionalDefaultDescription
namestringyesThe player's name for the save. The plugins' when words, else the turn, if left out.
playednumberyesThe time played, in milliseconds. 0 if left out.
savedAtnumberyesThe time the save was written, in epoch milliseconds. Now if left out.

SaveFile

Type. Explained in Saves.

A save as a driver stores it, the state with its SaveMeta. ifloom is this envelope's format, 1, apart from the state's own version (SAVE_VERSION), which loadState carries forward.

import type { SaveFile } from '@ifloom/engine'
type SaveFile = {
  ifloom: 1
  meta: SaveMeta
  state: GameState
}
FieldTypeOptionalDefaultDescription
ifloom1The envelope's format, 1.
metaSaveMetaThe save's SaveMeta.
stateGameStateThe saved state, in the shape of the version that wrote it.

SaveListing

Type. Explained in Saves.

One entry of a game's saves from list(), a SaveMeta or a BrokenSave. Tell them apart with 'broken' in entry.

import type { SaveListing } from '@ifloom/engine'
type SaveListing = SaveMeta | BrokenSave

Uses: SaveMeta, BrokenSave.

SaveMeta

Type. Explained in Saves.

The facts a save records about itself, for a load page. list() and write return it.

import type { SaveMeta } from '@ifloom/engine'
type SaveMeta = {
  game: string
  slot: string
  name: string
  savedAt: number
  played: number
  turn: number
  when: string | null
  playerName: string | null
  packs: string[]
  plugins: Record<string, number>
  gameVersion: number
}
FieldTypeOptionalDefaultDescription
gamestringThe id of the game the save belongs to. Reading or importing another game's save is refused.
slotstringThe save's slot, such as '1', 'auto' or a name of the game's own.
namestringThe save's name, the player's, else the plugins' when words, else the turn.
savedAtnumberThe time the save was written, in epoch milliseconds.
playednumberThe time played when the save was written, in milliseconds, as the runner counted it.
turnnumberThe number of turns that had passed when the save was written.
whenstring | nullThe time and place in the game in the plugins' words, such as "Day 3 · Wednesday morning · The café", or null when no plugin gives one.
playerNamestring | nullThe player's name for the save's game, such as the name the player typed, or null. It comes from the first saveName that answers, the game's rules.saveName first, then each plugin's.
packsstring[]The ids of the packs the game was loaded with. A mod among them that is missing on load is reported in missingPacks.
pluginsRecord<string, number>The version of each plugin the game was built with, by plugin id.
gameVersionnumberThe game's own version (game.version) the save was made with. 1 for a game that declares none.

Saves

Type. Explained in Saves.

One game's save store, returned by saves. No call rejects, and a driver's failure answers with a reason a player can read and the driver's error as its cause.

import type { Saves } from '@ifloom/engine'
type Saves = {
  readonly driver: SaveDriver
  write: (slot: string, state: GameState, extra?: SaveExtra | undefined) => Promise<Result<SaveMeta>>
  read: (slot: string) => Promise<Result<LoadedSave | null>>
  list: () => Promise<Result<SaveListing[]>>
  remove: (slot: string) => Promise<Result<void>>
  exportSlot: (slot: string) => Promise<Result<string | null>>
  importText: (text: string) => Result<LoadedSave>
}
FieldTypeOptionalDefaultDescription
driverSaveDriverThe driver that keeps the saves.
write(slot: string, state: GameState, extra?: SaveExtra | undefined) => Promise<Result<…Writes a state to a slot and returns the save's SaveMeta. It fails with the notSaved string if the driver fails.
read(slot: string) => Promise<Result<LoadedSave | null>>Returns the save in a slot, carried forward and checked against this game, or null when the slot is empty. A failure gives the reason the save can't be read, or the notLoaded string if the driver fails.
list() => Promise<Result<SaveListing[]>>Returns the game's saves, newest first, then any that can't be read as BrokenSaves, by slot. It fails with the notListed string if the driver fails. Tell the two apart with 'broken' in entry. A broken save can still be removed.
remove(slot: string) => Promise<Result<void>>Deletes the save in a slot, and does nothing if the slot is empty. It fails with the notRemoved string if the driver fails.
exportSlot(slot: string) => Promise<Result<string | null>>Returns a slot's save as text a player can keep as a file, or null if the slot is empty. It fails with the notExported string if the driver fails.
importText(text: string) => Result<LoadedSave>Returns the save in text from a file the player chose, checked against this game. A text that isn't this game's save fails with the reason.

saves

Function. Explained in Saves.

Returns the Saves store of a game, kept by a driver. The game chooses its slots' names, such as 'auto', 'quick' or '1'.

Each key starts with the game's id, because every game opened from disk shares one storage origin in Chromium, and itch.io serves many games from shared domains. The format's version is inside the save (loadState), never in the key, so a new version never orphans an old save.

import { saves, type Game } from '@ifloom/engine'
function saves(game: Game, driver: SaveDriver): Saves

Uses: Game, SaveDriver, Saves.

SavingView

Type. Explained in The view.

The player's leave to save as the player sees it, in view.saving. A UI greys out or hides its Save button from it.

import type { SavingView } from '@ifloom/engine'
type SavingView = {
  allowed: boolean
  reason: string | null
  visible: boolean
}
FieldTypeOptionalDefaultDescription
allowedbooleanThe leave to save, false while one of the game's saveable entries holds.
reasonstring | nullThe reason of the first saveable entry that holds. Null when saving is allowed.
visiblebooleanThe Save button's visibility, false while the entry that holds has hide. A UI then leaves Save off the screen rather than greying it out.

say

Function. Explained in Flowing scenes.

Returns a { say } block, a spoken line under the id of who says it. Its beat is a say beat with that speaker and their name.

who names the speaker as @id: "…" does in prose, an entity by reference or bare id ('ava' is character:ava), 'you' for whoever the player is playing, or 'player'.

import { say } from '@ifloom/engine'
function say(who: string, words: string, extras?: BlockExtras & { id?: string; voice?: string }): Block

Uses: BlockExtras, Block.

SceneBeat

Type. Explained in Prose and markup.

One piece of a rendered body, in view.scene.beats, told apart by its type. Any beat can carry ui, the ui hints of the block it starts.

import type { SceneBeat } from '@ifloom/engine'
type SceneBeat = ({ type: 'text'; text: string; spans?: InlineSpan[] } | { type: 'say'; who: 'character' | 'player'; speaker?: EntityRef; name?: string; image?: string; text: string; voice?: string; spans?: InlineSpan[] } | { type: 'image'; src: string; alt?: string; size: BeatSize } | { type: 'video'; src: string; poster?: string; alt?: string; size: BeatSize; autoplay: boolean; loop: boolean; muted: boolean; controls: boolean } | { type: 'sound'; track: string } | { type: 'chose'; label: string }) & { ui?: Ui<BlockUi>; section?: Ui<BlockUi> }

Uses: InlineSpan, EntityRef, BeatSize, Ui, BlockUi.

SceneMedia

Type. Explained in Scenes.

A picture or a video in a scene's body, written as a { media } block. Give a file as src, or have a pool draw one with pool and tags.

import type { SceneMedia } from '@ifloom/engine'
type SceneMedia = {
  src?: string
  pool?: string
  tags?: string[]
  alt?: string
  size?: 'inline' | 'wide'
  at?: 'lead' | 'end'
  video?: boolean
  controls?: boolean
  once?: boolean
  sound?: boolean
  poster?: string
}
FieldTypeOptionalDefaultDescription
srcstringyesThe media's file, a path in the game's art/ folder or a URL.
poolstringyesThe pool in game.media.pools that draws the file.
tagsstring[]yesThe tags the pool's pick should have, most important first. See poolCandidates.
altstringyesThe media's alternative text, for a screen reader.
size'inline' | 'wide'yesThe media's size, 'inline' or 'wide'. 'inline' if left out.
at'lead' | 'end'yesThe media's position. lead opens the scene, as an establishing picture does, and end follows the body. A block with none sits where it is in the body, in order with the prose.
videobooleanyesThe video mark, which renders the file as a video. A .mp4 or .webm file is a video without it.
controlsbooleanyesThe controls flag, which shows the player's controls, so the video waits to be started instead of playing by itself.
oncebooleanyesThe once flag, which plays the video once instead of looping.
soundbooleanyesThe sound flag, which plays the video with sound instead of muted.
posterstringyesThe still shown before the video plays, as a path like any picture's.

sceneOf

Function. Explained in The game.

Returns the scene with this id from the game's content, or undefined when there is none.

import { sceneOf, type Game } from '@ifloom/engine'
function sceneOf(game: Game, id: string): DataScene | undefined

Uses: Game, DataScene.

ScenePanel

Type. Explained in Panels.

A panel a scene declares in its panel, held open for as long as the scene is open. with is empty if left out.

import type { ScenePanel } from '@ifloom/engine'
type ScenePanel = {
  panel: string
  with?: PluginArgs
}
FieldTypeOptionalDefaultDescription
panelstringThe panel's name, which the UI renders it by.
withPluginArgsyesThe panel's arguments, such as { vendor: 'cafe' }. Empty if left out.

SceneUi

Type. Explained in Presentation hints.

The ui hints a scene or a room scene takes in its ui, for the UI that renders it. The engine declares none, and a UI package augments this interface with its own.

import type { SceneUi } from '@ifloom/engine'
type SceneUi = {

  // …
}

Plugins add fields of their own to it, which their pages list.

SCHEMA

Const. Explained in Content and packs.

The content schema this engine reads. PACK_STEPS upgrade a pack of an older schema, and a newer one is refused.

import { SCHEMA } from '@ifloom/engine'
const SCHEMA: 1

Screen

Type. Explained in The view.

One state rendered once by screen, with what each choice would apply, the pool picks and the audio tracks.

import type { Screen } from '@ifloom/engine'
type Screen = {
  scene: ScreenScene
  choices: ScreenChoice[]
  actions: ScreenChoice[]
  picture: PictureView | null
  plugins: Record<string, unknown>
  picks: Record<string, string>
  audio: AudioView & { tracks: Record<string, string | null> }
}
FieldTypeOptionalDefaultDescription
sceneScreenSceneThe open scene as rendered, or the room when none is open. While a minigame is played, the minigame's key, title and words replace theirs, without their ui. view.minigame holds the running minigame's state.
choicesScreenChoice[]The open scene's visible choices, each with its effects, availability and price. It is empty for the room and while a minigame is played.
actionsScreenChoice[]The room's actions while no scene is open and no lock stops everything. The actions providers' come first (the game's rules', then each plugin's), then the game's own actions.
picturePictureView | nullThe open scene's layered picture and its hotspots, or null.
pluginsRecord<string, unknown>The plugins' views, by plugin id.
picksRecord<string, string>The pool picks this screen made that the save doesn't hold yet, by pick key. The reducer records them.
audioAudioView & { tracks: Record<string, string | null> }The audio that should be playing, as in view.audio, with tracks added. tracks gives the track each background channel resolved to (null for silence), and the reducer records them as started.

screen

Function. Explained in The view.

Returns the Screen for a state, the open scene or the room rendered once. Use it when you need what view leaves out, such as each choice's effects.

The screen holds the choices, actions, picture, plugins' views, pool picks and audio of that one render.

Every choice's availability and effects come from that one render of the scene. view formats a screen for a UI.

import { screen, type Game } from '@ifloom/engine'
function screen(state: GameState, game: Game, options?: ViewOptions): Screen

Uses: GameState, Game, ViewOptions, Screen.

ScreenChoice

Type. Explained in The view.

A choice or action on a Screen, with the effects pressing its button would apply. The view leaves the effects out.

import type { ScreenChoice } from '@ifloom/engine'
type ScreenChoice = {
  id: string
  label: string
  price?: Price
  disabled?: string
  tags?: string[]
  irreversible?: string
  ui?: Ui<ChoiceUi>
  warning?: string
  command: Command
  effects: Effect[]
}
FieldTypeOptionalDefaultDescription
idstringThe choice's or action's id.
labelstringThe button's label, with tokens filled.
pricePriceyesThe button's price for this state, with its words in text. Left out when it's free.
disabledstringyesThe reason the player can't press the button now, in the player's words. Left out when they can.
tagsstring[]yesThe choice's or action's tags, for a UI to style or filter it by.
irreversiblestringyesThe warning that the choice or action can't be undone, for a UI to show on its button.
uiUi<ChoiceUi>yesThe choice's or action's ui hints, unchanged from content. Left out with none, and typed by ChoiceUi.
warningstringyesThe reason a plugin's guard gives for refusing the button softly, such as running past dawn. The player can press it, but the reducer refuses it, so a UI shows the warning instead.
commandCommandThe command a UI sends when the player presses the button, as runner.apply(choice.command).
effectsEffect[]The effects pressing the button would apply, such as a choice's effects or an action's cost and effects.

ScreenScene

Type. Explained in The view.

The scene on a Screen, or the room when none is open, without its choices and picture.

import type { ScreenScene } from '@ifloom/engine'
type ScreenScene = {
  id: string | null
  key: string
  title: string
  body: string
  beats: SceneBeat[]
  fresh: number
  tags: string[]
  speaker: SpeakerView | null
  image: string | null
  ui?: Ui<SceneUi>
}
FieldTypeOptionalDefaultDescription
idstring | nullThe open scene's id, or null for the room.
keystringThe screen's key, which changes when the screen does and only then. It is scene:<id> while a scene is open, minigame:<id> while a minigame is played, room:<id> for a plugin's room scene and room without one.
titlestringThe screen's title, the scene's or the room's.
bodystringThe body as markup text. A UI renders beats, which are this text parsed.
beatsSceneBeat[]The body parsed into beats, such as paragraphs, speech, pictures and past choices, ready to render.
freshnumberThe index of the first beat the flow's last step added, from its chose beat on, so a UI can animate only those. It's 0 for the room and before the visit's first step.
tagsstring[]The scene's tags, for a UI to style it by.
speakerSpeakerView | nullThe scene's speaker, read from their entity. Null without one, or when it names no entity.
imagestring | nullThe speaker's picture to show with the scene, or null without one.
uiUi<SceneUi>yesThe scene's ui hints, or the room scene's when no scene is open, unchanged from content. Left out with none, and typed by SceneUi.

Select

Type. Explained in Entities.

A selection of entities that a count or an each reads. Every entity in the game when it sets nothing.

It narrows to those of a kind, those with a tag or a trait, and those where holds for, with '$' as each one. Things someone has are where: { owned: '$' }.

import type { Select } from '@ifloom/engine'
type Select = {
  of?: string
  tag?: string
  trait?: string
  where?: Condition
}
FieldTypeOptionalDefaultDescription
ofstringyesThe kind the entities are of.
tagstringyesThe tag the entities have, their kind's or their own.
traitstringyesThe id of a trait the entities carry.
whereConditionyesThe condition each entity must meet, with '$' as that entity.

SettingDef

Type. Explained in Settings.

A setting the game declares in settings, which the player changes on a settings page. A play setting is saved with the state, and a ui setting is kept only in the profile.

Its type sets the rest of its fields. A toggle has a true/false default. A choice has options, each a value with its label, and one value as its default. A range has min, max, an optional step and a number as its default.

import type { SettingDef } from '@ifloom/engine'
type SettingDef = { id: string; label: string; affects?: 'play' | 'ui' } & ({ type: 'toggle'; default: boolean } | { type: 'choice'; options: { value: string; label: string }[]; default: string } | { type: 'range'; min: number; max: number; step?: number; default: number })

SettingView

Type. Explained in The view.

A setting as the player sees it on a settings page, in view.settings.

import type { SettingView } from '@ifloom/engine'
type SettingView = {
  id: string
  label: string
  type: 'toggle' | 'choice' | 'range'
  affects: 'play' | 'ui'
  options?: { value: string; label: string }[]
  min?: number
  max?: number
  step?: number
  default: KvValue
  value: KvValue | null
}
FieldTypeOptionalDefaultDescription
idstringThe setting's id.
labelstringThe setting's label.
type'toggle' | 'choice' | 'range'The setting's type, a toggle (on or off), a choice among options, or a range from min to max.
affects'play' | 'ui'The setting's reach. The save keeps a play setting, which changes the game, and the profile keeps a ui setting, which changes only how the game is shown.
options{ value: string; label: string }[]yesThe options of a choice setting, each a value with its label.
minnumberyesThe lowest value of a range setting.
maxnumberyesThe highest value of a range setting.
stepnumberyesThe step of a range setting. Left out when the setting gives none, which means 1.
defaultKvValueThe setting's default, its value until the player changes it.
valueKvValue | nullThe value of a play setting in this game. Null for a ui setting, which the UI reads from the profile.

Someone

Type. Explained in Entities.

Someone, 'player', a unique entity ('character:ava') or 'you'. 'you' is whoever the player is playing now, the player unless a you effect switched to a protagonist. It's who a receive gives a thing to.

import type { Someone } from '@ifloom/engine'
type Someone = EntityRef | typeof PLAYER | typeof YOU

Uses: EntityRef.

SpeakerView

Type. Explained in The view.

A speaker or sender as the player sees them, in view.scene.speaker and in plugins' views.

import type { SpeakerView } from '@ifloom/engine'
type SpeakerView = {
  id: string
  ref: EntityRef
  name: string
  image: string | null
  ui?: Ui<EntityUi>
}
FieldTypeOptionalDefaultDescription
idstringThe speaker's id in the content, a bare id ('ava') or a reference ('character:ava').
refEntityRefThe speaker's entity.
namestringThe speaker's name, read from their entity with its tokens filled.
imagestring | nullThe speaker's picture, from their entity through artSrc, or null when the entity has none.
uiUi<EntityUi>yesThe speaker's entity's ui hints (see EntityUi). Left out when the entity has none.

startingState

Function. Explained in Commands.

Returns the state of a new game, with every field at its start value. With carry, the New Game+'s carried values go over it.

Features then work out the fields that read the whole state, such as the audio the opening screen starts playing.

import { startingState, type Game } from '@ifloom/engine'
function startingState(game: Game, options?: StartOptions): GameState

Uses: Game, StartOptions, GameState.

StartOptions

Type. Explained in Commands.

Settings for startingState. A new game left without them gets a seed hashed from the game's id.

import type { StartOptions } from '@ifloom/engine'
type StartOptions = {
  seed?: number
  kv?: Record<string, KvValue>
  settings?: Record<string, unknown>
  carry?: GameState
}
FieldTypeOptionalDefaultDescription
seednumberyesThe new game's random seed. Hashed from the game's id if left out, so tests draw the same.
kvRecord<string, KvValue>yesThe kv keys written before the first scene, such as a name from a title page or a difficulty.
settingsRecord<string, unknown>yesThe player's stored values for the game's play settings, such as the profile's core:settings, which browserRunner passes. A missing or invalid value starts at its default, and an undeclared id is ignored.
carryGameStateyesThe state a finished game ended on, for a New Game+. The engine copies the stats, kv keys and things the game's carryOver lists from it.

StatDef

Type. Explained in Stats.

A stat the game declares in stats, a number it keeps for the player or for each entity of a kind. The engine has no stats of its own.

Charisma, money, energy and a reputation are stats.

import type { StatDef } from '@ifloom/engine'
type StatDef = {
  id: string
  of?: string
  label: string
  start?: number
  min?: Amount
  max?: Amount
  visible?: Condition
  listed?: boolean
  spendable?: boolean
  lacking?: StatWords
  format?: StatWords
  derive?: Formula
  levels?: StatLevels
  round?: StatRound
  ui?: Ui<StatUi>
}
FieldTypeOptionalDefaultDescription
idstringThe stat's id.
ofstringyesThe kind of entity the stat is kept on, such as 'staff' for every member of staff. The player's stat if left out.
labelstringThe stat's label, such as "Charisma" or "Money".
startnumberyesThe stat's value in a new game. 0 if left out.
minAmountyesThe stat's lowest value. 0 if left out, and an Amount, so a floor can move with the game ({ stat: 'debtLimit' }).
maxAmountyesThe stat's highest value. 100 if left out, and an Amount, so a ceiling can move with the game. It can read another stat ({ stat: 'fitness' }) or a value by name ({ value: 'game/energyMax' }, with with for its arguments). A ceiling that reads the stat itself reads 100.
visibleConditionyesThe stat's condition. The player can see the stat only while it holds, and always if left out.
listedbooleanyesThe stat's listed mark, false to leave it out of view.stats for a game that shows it its own way, as a gauge or a purse. True if left out.
spendablebooleanyesThe stat's spendable mark, true for a stat spent on things, such as money, energy or time. A choice's or action's price is made of spendable stats.
lackingStatWordsyesThe refusal when a cost needs more than the player has, with {n} for the amount. Without it the engine says "Not enough" and the label. It's one line ('Not enough on you.', 'Need {n} energy.') or one for 1 and one for any other amount, as format takes.
formatStatWordsyesThe stat's value written for the player, with {n} for the number, such as '£{n}' or '{n} energy'. The bare number if left out. For words that change with the number, give one for 1 and one for any other, { one: '{n} coin', other: '{n} coins' }.
deriveFormulayesThe formula the stat is worked out from instead of being kept, such as { sum: ['strength', 'agility'] }. A derived stat is read like any stat and never written, and the loader reports a stat effect on one.
levelsStatLevelsyesThe levels the stat passes as it grows. None if left out.
roundStatRoundyesThe stat's rounding when it's read, 'floor', 'round' or 'ceil' to a whole number, or 'none'. 'none' if left out. It applies last, after derive and any plugin's modifiers, and the value is then held to the range. The kept value underneath is never rounded.
uiUi<StatUi>yesThe stat's ui hints, carried to its view as written.

StatKey

Type. Explained in Common types.

A stat's id. The game declares each stat with a StatDef.

import type { StatKey } from '@ifloom/engine'
type StatKey = string

statLevel

Function. Explained in Stats.

Returns the level a stat with levels has reached, with the value the next level starts at and the progress towards it. Returns undefined for a stat with no levels.

next is null at the top level. progress runs from 0 at this level's start to 1 at the next one's, and is 1 at the top.

import { statLevel, type Game } from '@ifloom/engine'
function statLevel(state: GameState, game: Game, id: string, of?: string): { level: number; next: number | null; progress: number } | undefined

Uses: GameState, Game.

StatLevels

Type. Explained in Stats.

The levels a stat declares in its levels, thresholds it passes as it grows. It can raise a notice when the player's stat passes one.

import type { StatLevels } from '@ifloom/engine'
type StatLevels = {
  at: number[]
  names?: string[]
  notice?: string
  hidden?: boolean
}
FieldTypeOptionalDefaultDescription
atnumber[]The value each level starts at, lowest first. A value below the first is level 0.
namesstring[]yesThe levels' names, one for each level from level 0 (below the first threshold) up, so one more than at, such as ['Couch potato', 'Jogger', 'Runner'] for at: [10, 25]. The view gives the stat's level its name.
noticestringyesThe notice raised, tagged level, when a command takes the player's stat up a level, such as '{label} is now level {level}.'. The engine fills {label}, {level} and {name}, the level's name, and raises no notice if left out. The view fills its tokens as it does any notice's.
hiddenbooleanyesThe levels' hidden mark, true to keep them from the player. The view then gives the stat no level, and { level } conditions still read them. Use it for a hidden rating, such as how much a character trusts you.

statOf

Function. Explained in Stats.

Returns the stat the game declares with this id. Undefined when there's none.

import { statOf, type Game } from '@ifloom/engine'
function statOf(game: Game, id: string): StatDef | undefined

Uses: Game, StatDef.

StatRound

Type. Explained in Stats.

The rounding a stat declares in its round, applied when the stat is read.

import type { StatRound } from '@ifloom/engine'
type StatRound = 'none' | 'floor' | 'round' | 'ceil'

Stats

Type. Explained in Entities, things and traits.

The current values of the stats the save keeps, by stat id.

import type { Stats } from '@ifloom/engine'
type Stats = {
  [key: string]: number
}

StatUi

Type. Explained in Presentation hints.

The ui hints a stat takes in its ui. The engine declares none, and a UI package augments this interface with its own.

import type { StatUi } from '@ifloom/engine'
type StatUi = {

  // …
}

Plugins add fields of their own to it, which their pages list.

statValue

Function. Explained in Stats.

Returns a stat's value, the player's or, with of, an entity's ('staff:ana'). An entity that isn't there reads 0.

A derived stat is worked out from its formula and held to its range. A kept stat the save doesn't have yet reads as its start.

import { statValue, type Game } from '@ifloom/engine'
function statValue(state: GameState, game: Game, id: string, of?: string): number

Uses: GameState, Game.

StatView

Type. Explained in The view.

A stat as the player sees it, in view.stats and view.statsById, with its value, its range, the value written out and its hints.

import type { StatView } from '@ifloom/engine'
type StatView = {
  key: StatKey
  label: string
  value: number
  min: number
  max: number
  text: string
  level?: { level: number; name: string | null; next: number | null; progress: number }
  ui?: Ui<StatUi>
}
FieldTypeOptionalDefaultDescription
keyStatKeyThe stat's id.
labelstringThe stat's label.
valuenumberThe stat's value as play reads it, kept or derived, with the plugins' modifiers, rounded and held to its range.
minnumberThe stat's lowest value now.
maxnumberThe stat's highest value now.
textstringThe stat's value written with its format, such as '12 coins' or '80%'. The bare number with no format.
level{ level: number; name: string | null; next: number | null; progress: number }yesThe stat's place in its levels, with its level and that level's name, null without levels.names. It also has the value the next level starts at (null at the top) and the progress towards it, from 0 to 1. It's left out for a stat with no levels or hidden ones.
uiUi<StatUi>yesThe stat's ui hints, kept as written. Left out if it has none.

StatWords

Type. Explained in Stats.

A stat's words for a number, with {n} for it. It's one line for every number, or one for exactly 1 and other for the rest.

import type { StatWords } from '@ifloom/engine'
type StatWords = string | { one: string; other: string }

StoryletFields

Type. Explained in Storylets.

The fields that make a scene a storylet, a scene the { scene: { from } } effect draws at random from a named set. They name the sets, the scene's weight and when it can be drawn.

import type { StoryletFields } from '@ifloom/engine'
type StoryletFields = {
  drawnFrom?: string[]
  weight?: number
  when?: Condition
}
FieldTypeOptionalDefaultDescription
drawnFromstring[]yesThe sets the scene can be drawn from, by name, such as ['cafe']. A { scene: { from: 'cafe' } } effect draws one of the scenes that name 'cafe' here. It's separate from tags, which only style the scene.
weightnumberyesThe scene's weight in a draw, against the other scenes it could be drawn with. 1 if left out, and it needs drawnFrom.
whenConditionyesThe storylet's condition. The scene can be drawn only while it holds, but a scene command or effect that names the scene opens it regardless.

StorylineDef

Type. Explained in Storylines.

A storyline the game declares in storylines, a thread of the story with its own kv keys. A storyline can close until a later turn.

import type { StorylineDef } from '@ifloom/engine'
type StorylineDef = {
  id: string
  name: string
}
FieldTypeOptionalDefaultDescription
idstringThe storyline's id, read as storyline:<id> in a kv effect's of.
namestringThe storyline's name, as the player reads it.

storylineOpen

Function. Explained in Storylines.

Returns true when the storyline is open. A storyline closed until a turn opens again once that turn comes.

import { storylineOpen } from '@ifloom/engine'
function storylineOpen(state: GameState, id: string): boolean

Uses: GameState.

StorylineState

Type. Explained in Storylines.

The state a save keeps for one storyline. The engine reads its definition from content.

import type { StorylineState } from '@ifloom/engine'
type StorylineState = {
  closedUntil: number | null
  kv: Record<string, KvValue>
}
FieldTypeOptionalDefaultDescription
closedUntilnumber | nullThe storyline's turn to open again, or null while it is open.
kvRecord<string, KvValue>The storyline's own kv keys, read and written with of: 'storyline:<id>'.

StringKey

Type. Explained in Strings.

A key of the engine's own lines in STRINGS.

import type { StringKey } from '@ifloom/engine'
type StringKey = keyof typeof STRINGS

stringOf

Function. Explained in Strings.

Returns the line for a key with each {name} token filled from vars. Returns the key itself when no table has it, so a missing line shows.

The engine looks in the game's strings, then the plugin's defaults for a <plugin>/<name> key, then its own. A token with no value in vars stays as written.

import { stringOf, type Game } from '@ifloom/engine'
function stringOf(game: Game | undefined, key: StringKey | (string & {}), vars?: Record<string, string | number>): string

Uses: Game, StringKey.

STRINGS

Const. Explained in Strings.

The engine's own lines for the player, in English, by key. A game replaces any of them in its content's or a pack's strings, so a translation can ship as a mod.

The engine fills each {name} token from the values it has when it shows the line. Plugins declare their own defaults under their id (quests/notDoing), and a game replaces those the same way.

import { STRINGS } from '@ifloom/engine'
const STRINGS: {
  finishFirst: 'Finish this first.'
  notSupported: 'This game does not do that.'
  noSuchAction: 'There is no such thing to do.'
  notEnough: 'Not enough {stat}.'
  noSuchScene: 'There is no such scene.'
  nothingToChoose: 'There is nothing to choose.'
  notOnOffer: 'That is not on offer.'
  noSuchThing: 'There is no such thing.'
  badArgument: 'That can’t be done: "{arg}" must be {kind}.'
  noSuchInput: 'There is no such thing to fill in.'
  notNow: 'Not now.'
  enterSomething: 'Enter something first.'
  enterNumber: 'Enter a number.'
  tooLong: 'Keep it to {n} characters.'
  between: 'Between {min} and {max}.'
  atLeast: 'At least {min}.'
  atMost: 'At most {max}.'
  notAnOption: 'That is not one of the options.'
  noMinigame: 'Nothing is being played.'
  noPanel: 'Nothing is open.'
  notLive: 'That does nothing now.'
  noTimer: 'Nothing is counting down.'
  tickLength: 'A tick is a number of milliseconds above 0.'
  noSuchSetting: 'There is no such setting.'
  notAGameSetting: 'That setting does not change the game.'
  noProfile: 'This game keeps no settings between plays.'
  onOrOff: 'Choose on or off.'
  inSteps: 'In steps of {step}.'
  lookAround: 'Look around'
  priceSeparator: ' · '
  'minigame.up': 'Up'
  'minigame.down': 'Down'
  'minigame.left': 'Left'
  'minigame.right': 'Right'
  'minigame.space': 'Space'
  you: 'You'
  momentPassed: 'The moment has passed.'
  done: 'Already done.'
  notASave: 'That is not a save file.'
  otherGame: 'That save belongs to another game ({game}).'
  saveTooOld: 'That save is from a version this game cannot read.'
  pluginNewer: 'That save was made with a newer version of {plugin}.'
  gameNewer: 'That save was made with a newer version of this game.'
  pluginUnreadable: 'That save\'s {plugin} is from a version this game cannot read.'
  noSaves: 'This game keeps no saves.'
  emptySlot: 'Nothing is saved there.'
  notSaved: 'The game could not be saved.'
  notLoaded: 'The game could not be loaded.'
  notListed: 'The saves could not be read.'
  notRemoved: 'The save could not be deleted.'
  notExported: 'The save could not be exported.'
  turnLabel: 'Turn {turn}'
}
FieldTypeOptionalDefaultDescription
finishFirst'Finish this first.'The refusal of a command that can't run while a scene or minigame is open.
notSupported'This game does not do that.'The refusal of a command no feature, plugin or rule of the game handles.
noSuchAction'There is no such thing to do.'The refusal of an action or a game command the game doesn't declare.
notEnough'Not enough {stat}.'The refusal of a choice or action the player can't pay for, with {stat} the stat's label.
noSuchScene'There is no such scene.'The refusal of entering a scene the game doesn't declare.
nothingToChoose'There is nothing to choose.'The refusal of a choice while no scene is open.
notOnOffer'That is not on offer.'The refusal of a choice or action that isn't offered now.
noSuchThing'There is no such thing.'The refusal of a command that names an entity the game doesn't have.
badArgument'That can’t be done: "{arg}" must be {kind}.'The refusal of a plugin command whose argument {arg} isn't a {kind}.
noSuchInput'There is no such thing to fill in.'The refusal of the input command for an input the game doesn't declare.
notNow'Not now.'The refusal of the input command while the input's when doesn't hold.
enterSomething'Enter something first.'The refusal of an empty value for a text input.
enterNumber'Enter a number.'The refusal of a value that isn't a number for a number input or a number setting.
tooLong'Keep it to {n} characters.'The refusal of a text value longer than {n} characters.
between'Between {min} and {max}.'The refusal of a number outside an input's or a range setting's {min} and {max}.
atLeast'At least {min}.'The refusal of a number below the input's {min}.
atMost'At most {max}.'The refusal of a number above the input's {max}.
notAnOption'That is not one of the options.'The refusal of a value that isn't one of an input's or a setting's options.
noMinigame'Nothing is being played.'The refusal of a minigame command while no minigame runs.
noPanel'Nothing is open.'The refusal of closePanel while no panel is open.
notLive'That does nothing now.'The refusal of a minigame input that does nothing in the minigame's current state.
noTimer'Nothing is counting down.'The refusal of the tick command while no timer or minigame clock runs.
tickLength'A tick is a number of milliseconds above 0.'The refusal of a tick whose ms isn't a number above 0.
noSuchSetting'There is no such setting.'The refusal of a setting the game doesn't declare.
notAGameSetting'That setting does not change the game.'The refusal of a ui setting sent as a command, since only a play setting changes the state.
noProfile'This game keeps no settings between plays.'The refusal of a setting change when the runner keeps no profile.
onOrOff'Choose on or off.'The refusal of a value other than true or false for a toggle setting.
inSteps'In steps of {step}.'The refusal of a range setting's value that isn't a whole number of {step}s.
lookAround'Look around'The label of the button that leaves a scene the game no longer declares.
priceSeparator' · 'The separator between the parts of a price on a button, such as 2 coins · until evening.
minigame.up'Up'The label of a minigame input's button, keyed minigame.<input>. An input with no line shows its own name with a capital. A game labels its own inputs the same way, as in 'minigame.jump': 'Jump'.
minigame.down'Down'The label of the minigame input down.
minigame.left'Left'The label of the minigame input left.
minigame.right'Right'The label of the minigame input right.
minigame.space'Space'The label of the minigame input space.
you'You'The name the player's spoken lines (@you: "Hi.") show when no saveName gives one. A game in another language sets its own.
momentPassed'The moment has passed.'The text shown for an open scene the game no longer declares, such as after a mod is removed.
done'Already done.'The reason on a choice or action with once, after the player has taken it that game or turn.
notASave'That is not a save file.'The refusal of an imported file or a state that isn't a save.
otherGame'That save belongs to another game ({game}).'The refusal of a save made by another game, with {game} that game's id.
saveTooOld'That save is from a version this game cannot read.'The refusal of a save from an engine version too old for the engine's steps to carry forward.
pluginNewer'That save was made with a newer version of {plugin}.'The refusal of a save made with a newer version of the plugin {plugin}.
gameNewer'That save was made with a newer version of this game.'The refusal of a save made with a newer version of the game.
pluginUnreadable'That save\'s {plugin} is from a version this game cannot read.'The refusal of a save whose state for the plugin {plugin} its migrations can't carry forward.
noSaves'This game keeps no saves.'The refusal of a save or load when the runner keeps no saves.
emptySlot'Nothing is saved there.'The refusal of loading a slot that holds no save.
notSaved'The game could not be saved.'The reason a save failed to write.
notLoaded'The game could not be loaded.'The reason a save failed to read.
notListed'The saves could not be read.'The reason the saves failed to list.
notRemoved'The save could not be deleted.'The reason a save failed to delete.
notExported'The save could not be exported.'The reason a save failed to export.
turnLabel'Turn {turn}'The save's name when no plugin's saveName gives one.

Strings

Type. Explained in Strings.

A table of lines a game, pack or plugin gives by key. A key is an engine key or a plugin's <id>/<name>.

import type { Strings } from '@ifloom/engine'
type Strings = {
  you?: string
  done?: string
  finishFirst?: string
  notSupported?: string
  noSuchAction?: string
  notEnough?: string
  noSuchScene?: string
  nothingToChoose?: string
  notOnOffer?: string
  noSuchThing?: string
  badArgument?: string
  noSuchInput?: string
  notNow?: string
  enterSomething?: string
  enterNumber?: string
  tooLong?: string
  between?: string
  atLeast?: string
  atMost?: string
  notAnOption?: string
  noMinigame?: string
  noPanel?: string
  notLive?: string
  noTimer?: string
  tickLength?: string
  noSuchSetting?: string
  notAGameSetting?: string
  noProfile?: string
  onOrOff?: string
  inSteps?: string
  lookAround?: string
  priceSeparator?: string
  'minigame.up'?: string
  'minigame.down'?: string
  'minigame.left'?: string
  'minigame.right'?: string
  'minigame.space'?: string
  momentPassed?: string
  notASave?: string
  otherGame?: string
  saveTooOld?: string
  pluginNewer?: string
  gameNewer?: string
  pluginUnreadable?: string
  noSaves?: string
  emptySlot?: string
  notSaved?: string
  notLoaded?: string
  notListed?: string
  notRemoved?: string
  notExported?: string
  turnLabel?: string
  // …
}

It also takes any other key: [key: string]: string.

Its fields are the keys of Partial<Record<StringKey, string>> & Record<string, string>, so they grow when a game or a plugin adds to those.

text

Function. Explained in Flowing scenes.

Returns a { text } block of words in place, one paragraph or several. A blank line between lines starts a new paragraph.

It strips the indentation every line shares and the blank lines at either end, so the words can sit indented in your code. The words are read as prose is, so @ava: "…" is a spoken line, [[img:…]] a picture and {{key}} a token. An id keys the block in a translation's words table as scene.<scene>.text.<id>, and a hash of its words keys it without one.

import { text } from '@ifloom/engine'
function text(words: string, extras?: BlockExtras & { id?: string }): Block

Uses: BlockExtras, Block.

TextLine

Type. Explained in Presentation hints.

A line of words a player reads, a prose line or words in place. A UI checks the [[ui:…]] pieces in it.

import type { TextLine } from '@ifloom/engine'
type TextLine = {
  where: string
  text: string
}
FieldTypeOptionalDefaultDescription
wherestringThe place the line is, written as a Problem's where is.
textstringThe line's words, markup and all.

TimerDef

Type. Explained in Timers.

A timer the game declares in timers, a named countdown in real time. The timer effect starts it, and its effects run when it runs out.

import type { TimerDef } from '@ifloom/engine'
type TimerDef = {
  id: string
  label?: string
  ms: number
  effects?: EffectRef[]
}
FieldTypeOptionalDefaultDescription
idstringThe timer's id, which the timer effect and condition name.
labelstringyesThe timer's label, such as 'The phone'. None if left out.
msnumberThe timer's length when started, in milliseconds.
effectsEffectRef[]yesThe timer's effects, which run when it runs out. Stopping it with to: null runs none of them.

TimerView

Type. Explained in Timers.

A running timer as the player sees it, in view.timers. The view never lists its effects.

import type { TimerView } from '@ifloom/engine'
type TimerView = {
  id: string
  label: string | null
  left: number
  total: number
}
FieldTypeOptionalDefaultDescription
idstringThe timer's id.
labelstring | nullThe timer's label, or null.
leftnumberThe milliseconds the timer has left.
totalnumberThe timer's whole length in milliseconds, for a bar. left / total is the share left.

Times

Type. Explained in Game state.

A count of times something happened, with the turns of the first and the last. GameState.seen keeps one per scene and GameState.chosen one per choice.

import type { Times } from '@ifloom/engine'
type Times = {
  n: number
  first: number
  last: number
}
FieldTypeOptionalDefaultDescription
nnumberThe number of times it happened.
firstnumberThe turn it first happened on.
lastnumberThe turn it last happened on.

TrackDef

Type. Explained in Audio.

A track the game declares in audio.tracks, a sound file it ships. It plays on the 'sfx' channel unless channel says otherwise.

import type { TrackDef } from '@ifloom/engine'
type TrackDef = {
  src: string
  channel?: string
  loop?: boolean
  volume?: number
}
FieldTypeOptionalDefaultDescription
srcstringThe track's file, under the game's audio/ folder, such as 'audio/cafe.ogg'. audioSrc turns it into a path.
channelstringyesThe channel the track plays on. 'sfx' if left out. A sound effect and [[sound:id]] play it there, and a background channel takes only a track whose channel is a background one.
loopbooleanyesThe track's loop mark, true to repeat it while it's on a background channel. True if left out.
volumenumberyesThe track's own volume, from 0 to 1. 1 if left out.

TraitData

Type. Explained in Entities.

The data trait K takes, as TraitRegistry declares it, or unknown for an undeclared id.

import type { TraitData } from '@ifloom/engine'
type TraitData<K extends string> = K extends keyof TraitRegistry ? TraitRegistry[K] : unknown

Uses: TraitRegistry.

traitOf

Function. Explained in Entities.

Returns the data of one trait on one entity in play, typed by TraitRegistry, or undefined when it lacks the trait.

A declared entity reads as declaredTrait does. An entity made in play reads the trait data it was made with, laid over its like's, or else over its kind's default.

import { traitOf, type Game } from '@ifloom/engine'
function traitOf<K extends string>(state: GameState, game: Game, ref: string, id: K): TraitData<K> | undefined

Uses: GameState, Game, TraitData.

TraitRegistry

Type. Explained in Entities.

The registry of the traits plugins declare, by trait id, with the data each takes. A plugin augments it to type declaredTrait and the traits field of entities, kinds and traits tables.

declare module '@ifloom/engine' {
  interface TraitRegistry {
    'laundry/washable': { temp: number; gentle?: boolean }
  }
}
import type { TraitRegistry } from '@ifloom/engine'
type TraitRegistry = {

  // …
}

Plugins add fields of their own to it, which their pages list.

TraitSource

Type. Explained in Entities.

The parts of a game its traits are worked out from, its kinds, its entities and its traits table.

import type { TraitSource } from '@ifloom/engine'
type TraitSource = {
  kinds?: KindDef[]
  entities?: EntityDef[]
  traits?: TraitTable
}
FieldTypeOptionalDefaultDescription
kindsKindDef[]yesThe game's kinds, the sorts of entity it keeps, each with its own stats.
entitiesEntityDef[]yesThe game's entities at the start. Play can create more.
traitsTraitTableyesThe game's traits, by trait id and then entity. In content given to loadGame they're rows over what entities declare. On the game loadGame returns, they're every entity's traits, worked out. Read them with declaredTrait.

TraitTable

Type. Explained in Entities.

A table of trait data by trait id and then entity, such as { 'laundry/washable': { 'clothing:scarf': { temp: 30 } } }.

In content, its rows give entities a trait over the entity's own. On a loaded game, it holds every entity's traits, worked out.

import type { TraitTable } from '@ifloom/engine'
type TraitTable = {
  [key: string]: Record<`${string}:${string}`, unknown>
  // …
}

Plugins add fields of their own to it, which their pages list.

translatableFields

Function. Explained in The words table.

Returns every field of the game's content a player reads and a translation can reword, each once, by its words-table key. Load the game without its translation packs to list the words to translate.

A { text } block with no id is keyed by a hash of its words, so its key changes when its words do.

const table = Object.fromEntries(translatableFields(game).map((field) => [field.key, field.text]))
import { translatableFields, type Game } from '@ifloom/engine'
function translatableFields(game: Game): WordField[]

Uses: Game, WordField.

TriggerDef

Type. Explained in Triggers.

A trigger the game declares in triggers, effects that run by themselves. They run the first time when holds after a command.

Use one for a text that arrives the turn after a meeting, a notice when a debt comes due, or a scene that interrupts.

import type { TriggerDef } from '@ifloom/engine'
type TriggerDef = {
  id: string
  when: Condition
  effects: EffectRef[]
  once?: { per: 'game' | 'turn' }
}
FieldTypeOptionalDefaultDescription
idstringThe trigger's id, which state.fired records.
whenConditionThe trigger's condition. The trigger fires the first time it holds after a command.
effectsEffectRef[]The trigger's effects, which run when it fires.
once{ per: 'game' | 'turn' }yesThe trigger's limit, once in the whole game ({ per: 'game' }) or at most once a turn ({ per: 'turn' }). { per: 'game' } if left out.

Ui

Type. Explained in Presentation hints.

A ui field of ui hints, typed by the hints a UI package declared for that target. It also takes undeclared hints, which the engine carries all the same.

import type { Ui } from '@ifloom/engine'
type Ui<T> = {
  [key: string]: unknown
}

UiField

Type. Explained in Presentation hints.

A ui field in a game's content, with the thing it's written on and the place it is.

import type { UiField } from '@ifloom/engine'
type UiField = {
  on: UiTarget
  id?: string
  where: string
  ui: unknown
}
FieldTypeOptionalDefaultDescription
onUiTargetThe sort of thing the field is written on, such as a scene, a choice or a stat.
idstringyesThe id of the thing the field is written on, where it has one.
wherestringThe place the field is, written as a Problem's where is.
uiunknownThe field's hints, unchanged from content.

UiInContent

Type. Explained in Presentation hints.

The ui fields and lines of words uiInContent finds, in the order the content checker walks them.

import type { UiInContent } from '@ifloom/engine'
type UiInContent = {
  fields: UiField[]
  lines: TextLine[]
}
FieldTypeOptionalDefaultDescription
fieldsUiField[]The ui fields in the content.
linesTextLine[]The lines of words that could hold a UI piece.

uiInContent

Function. Explained in Presentation hints.

Returns the UiInContent of a game, every ui field and every line that could hold a UI piece. A UI package's checker reads it to check its own hints.

The content checker's own walk finds them, in scenes, the blocks and decisions of their flows, choices, actions, stats, kinds, entities, the game's own and plugins' content, such as a location's room and body.

import { uiInContent, type Game } from '@ifloom/engine'
function uiInContent(game: Game): UiInContent

Uses: Game, UiInContent.

UiTarget

Type. Explained in Presentation hints.

The target a ui field is written on, which a UI package's checker reads.

It's a scene or room scene (scene), a choice or action (choice), a block or section (block), a stat, a kind or entity (entity), or the game.

import type { UiTarget } from '@ifloom/engine'
type UiTarget = 'scene' | 'choice' | 'block' | 'stat' | 'entity' | 'game'

upgradePack

Function. Explained in Content and packs.

Returns the pack upgraded to SCHEMA and to each plugin's content version. Returns a failed Result when the pack was written for a newer engine or plugin, or for a schema older than any step.

Pass the game's plugins (game.plugins, or the base's), so each one's content is carried forward too. The engine's step from each schema runs after every plugin step keyed by that schema or below. Each plugin's later steps run after.

A pack that records no version for a plugin is read as written for the plugin's current version. The result records every plugin's version in plugins, and a pack with nothing to upgrade comes back unchanged. loadGame passes context (see PackContext).

import { upgradePack } from '@ifloom/engine'
function upgradePack(pack: { schema: number; plugins?: Record<string, number> }, plugins: readonly Plugin[], context?: PackContext): Result<Pack>

Uses: Plugin, PackContext, Result, Pack.

ValueRef

Type. Explained in Calls by name.

A reference to a value by full name, with the arguments it is asked with. It sets a stat's ceiling, an app's badge or an achievement's progress, as in { value: 'messages/unread', with: { channel: 'texts' } }.

import type { ValueRef } from '@ifloom/engine'
type ValueRef = {
  value: string
  with?: PluginArgs
}
FieldTypeOptionalDefaultDescription
valuestringThe value's full name, a plugin's (messages/unread) or the game's (game/…).
withPluginArgsyesThe arguments the value is asked with. None if left out.

VariantMember

Type. Explained in Prose and markup.

A member of a variants list, a prose key or a prose key with a weight. A plain key has weight 1, so { prose: 'cafe.order/late', weight: 3 } is drawn three times as often.

import type { VariantMember } from '@ifloom/engine'
type VariantMember = string | { prose: string; weight?: number }

VideoFlags

Type. Explained in Media.

The flags a video's markup or { media } block can set, each changing one default.

import type { VideoFlags } from '@ifloom/engine'
type VideoFlags = {
  controls?: boolean
  once?: boolean
  sound?: boolean
  poster?: string
}
FieldTypeOptionalDefaultDescription
controlsbooleanyesThe controls flag, which shows the player's controls, so the video waits to be started instead of playing by itself.
oncebooleanyesThe once flag, which plays the video once instead of looping.
soundbooleanyesThe sound flag, which plays the video with sound instead of muted.
posterstringyesThe still shown before the video plays, as a path like any picture's.

VideoView

Type. Explained in Media.

A video's playback settings as the player sees them, worked out from its VideoFlags.

import type { VideoView } from '@ifloom/engine'
type VideoView = {
  autoplay: boolean
  loop: boolean
  muted: boolean
  controls: boolean
  poster?: string
}
FieldTypeOptionalDefaultDescription
autoplaybooleanThe video's autoplay mark, which starts it as soon as it is shown. True unless it shows controls.
loopbooleanThe video's loop mark, which plays it again when it ends. True unless its flags ask to play once.
mutedbooleanThe video's muted mark. True unless its flags ask for sound.
controlsbooleanThe video's controls mark, which shows the player's play, pause and volume controls.
posterstringyesThe still shown before the video plays, through artSrc.

View

Type. Explained in The view.

One state as a UI renders it, returned by view. It holds the core's fields and each feature's.

import type { View } from '@ifloom/engine'
type View = {
  title: string
  when: string | null
  scene: { id: string | null; key: string; title: string; body: string; beats: SceneBeat[]; fresh: number; tags: string[]; speaker: SpeakerView | null; image: string | null; picture: PictureView | null; choices: RenderedChoice[]; ui?: Ui<SceneUi> }
  actions: RenderedChoice[]
  plugins: ViewsIn
  entities: EntitiesView[]
  turn: number
  notices: NoticesView
  inputs: InputView[]
  settings: SettingView[]
  stats: StatView[]
  statsById: Record<string, StatView>
  minigame: MinigameView | null
  timers: TimerView[]
  audio: AudioView
  panel: OpenPanel | null
  saving: SavingView
  rolls: Roll[]
  changes: ChangeView[]
}
FieldTypeOptionalDefaultDescription
titlestringThe game's title.
whenstring | nullThe time in the game in the plugins' words, such as "Day 3 · Wednesday morning", or null when no plugin gives one.
scene{ id: string | null; key: string; title: string; body: string; beats: SceneBeat[]; fresh:…The open scene as the player sees it, or the room when none is open, or the minigame while one is played.
actionsRenderedChoice[]The actions on offer besides the scene's choices, ready to render. The actions providers' come first, such as wait, sleep and travel, then the game's own actions.
pluginsViewsInThe plugins' views, by plugin id. Each plugin that declares its view in ViewRegistry has it typed.
entitiesEntitiesView[]Each listed kind with its listed, visible entities, in the order the kinds are declared. A kind whose listed is false is left out, and a listed kind with no entities shows empty.
turnnumberThe number of turns that have passed, 0 on the first.
noticesNoticesViewThe notices the player hasn't dismissed, with a count for each tag.
inputsInputView[]The inputs on offer now, in the order the game declares them, each with its value.
settingsSettingView[]Every setting the game declares, in order, for a settings page.
statsStatView[]The player's listed stats the player can see now, in the order the game declares them.
statsByIdRecord<string, StatView>Every one of the player's stats, by id, listed and visible or not.
minigameMinigameView | nullThe minigame being played, or null.
timersTimerView[]The running timers, in the order they started.
audioAudioViewThe audio each channel should play and the sounds that are due. Empty when the game has no audio.
panelOpenPanel | nullThe panel open over the story. It's the one the panel effect opened, else the open scene's own, else null.
savingSavingViewThe player's leave to save now, with the reason when it's refused.
rollsRoll[]The rolls the last command made, in order. Empty when it made none.
changesChangeView[]The stats the last command moved that the player can see, the player's first, each with the words that say what moved.

view

Function. Explained in The view.

Returns the View of a state, the value a UI renders. Without options.profile, no plugin's view reads the profile.

The scene, its choices, the room's actions, the plugins' views and the audio come from screen, which renders the open scene once, and the rest comes from the state. view only formats, so each choice's effects and the pool picks stay on the screen.

import { view, type Game } from '@ifloom/engine'
function view(state: GameState, game: Game, options?: ViewOptions): View

Uses: GameState, Game, ViewOptions, View.

ViewOptions

Type. Explained in The view.

Settings for screen and view besides the state. Without profile, no plugin's view reads the profile.

import type { ViewOptions } from '@ifloom/engine'
type ViewOptions = {
  profile?: Readonly<Record<string, unknown>>
}
FieldTypeOptionalDefaultDescription
profileReadonly<Record<string, unknown>>yesThe player's profile, by namespace. Each plugin's view reads its own namespace as context.profile, and the runner passes this.

ViewRegistry

Type. Explained in Declaring a plugin's calls.

The registry of each plugin's view by plugin id (shop: ShopView), which types view.plugins. The game's own rules.view is under game.

import type { ViewRegistry } from '@ifloom/engine'
type ViewRegistry = {

  // …
}

Plugins add fields of their own to it, which their pages list.

ViewsIn

Type. Explained in A plugin's view, scene and actions.

The plugins' views by plugin id, in view.plugins. Each plugin that declares its view in ViewRegistry is typed.

import type { ViewsIn } from '@ifloom/engine'
type ViewsIn = {
  [key: string]: unknown
  // …
}

Plugins add fields of their own to it, which their pages list.

weighted

Function. Explained in Randomness.

Returns one entry of items, drawn from parts by each entry's weight. Returns undefined when no entry can be drawn.

An entry of weight 3 comes up three times as often as one of weight 1. A weight left out counts as 1. An entry whose weight is 0 or less, or not a number, is never drawn.

import { weighted } from '@ifloom/engine'
function weighted<T>(items: readonly T[], weightOf: (item: T) => number | undefined, ...parts: (string | number)[]): T | undefined

when

Function. Explained in Flowing scenes.

Returns a section of blocks shown only while condition holds. A section can hold any block a body can.

import { when } from '@ifloom/engine'
function when(condition: Condition, blocks: Block[], extras?: Omit<BlockExtras, 'when'>): Block

Uses: Condition, Block, BlockExtras.

whyNot

Function. Explained in Actions.

Returns the reason the player can't send this command now, or undefined when they can.

The reducer refuses a command with this reason, and the view greys out its button with the same words. So a button and the rule behind it can't disagree, and every refusal is a sentence the player can read.

The engine checks in the order the player would notice: the core's refusals such as a lock first, then the plugins' guards, then the command's own needs.

import { whyNot, type Game } from '@ifloom/engine'
function whyNot(state: GameState, game: Game, command: CommandRef): string | undefined

Uses: GameState, Game, CommandRef.

withTrait

Function. Explained in Entities.

Returns every entity in the game that has a trait, as references. Declared ones not removed come first in content order, then those made in play with their kind's, their like's or their own trait.

import { withTrait, type Game } from '@ifloom/engine'
function withTrait(state: GameState, game: Game, id: string): EntityRef[]

Uses: GameState, Game, EntityRef.

WordField

Type. Explained in The words table.

A field of the game's content a player reads and a translation can reword, as translatableFields lists it.

import type { WordField } from '@ifloom/engine'
type WordField = {
  key: string
  text: string
  where: string
}
FieldTypeOptionalDefaultDescription
keystringThe field's key in a pack's words table, such as action.wait.label.
textstringThe field's words from content, tokens and markup included.
wherestringThe field's place as a problem names it, such as scene cafe.counter or quests coffee.

WordPart

Type. Explained in The words table.

One field's part in a WordShape, telling how the walk reads that field.

import type { WordPart } from '@ifloom/engine'
type WordPart = true | 'blocks' | 'effects' | 'button' | WordShape | readonly [ WordPart ]

Uses: WordShape.

WordShape

Type. Explained in The words table.

A map of the fields of an entry that hold words a translation can replace. A plugin's defineData declares one for each data list, and a trait's words declares one for its data.

Each field of the shape is one of these:

  • true: a field of words, or a record of them (a stat's { one, other });
  • 'blocks': a list of blocks, as a scene's body;
  • 'effects': a list of effects, for the words of the notices they raise;
  • 'button': a button, as an action is: its label, labels, blocked reasons, once reason, irreversible warning and effects;
  • a shape, for an object's own fields;
  • a shape in a list, [shape], for a list of entries;
  • { '*': shape }, for a record of entries, each named by its key.
import type { WordShape } from '@ifloom/engine'
type WordShape = {
  [key: string]: WordPart
}

writeEntity

Function. Explained in Entities.

Returns the state with one entity's record replaced. A record for an entity not yet there is added after the rest of its kind.

import { writeEntity } from '@ifloom/engine'
function writeEntity(state: GameState, ref: string, next: EntityState): GameState

Uses: GameState, EntityState.

YOU

Const. Explained in Entities.

The id of whoever the player is playing now, the protagonist the you effect last chose or else the player.

import { YOU } from '@ifloom/engine'
const YOU: 'you'

Last updated on

On this page

ActionCostActionDefactionOfAmountamountOfAppliedapplyapplyEffectsartSrcAudioChannelViewAudioCueaudioSrcAudioStateAudioViewAutosaveOptionsBacklogEntryBacklogOptionsBeatSizeBlockBlockedBlockExtrasBlockUiBrokenSavebuildEffectsButtonDefcallOfCarryOvercaseschanceChangeChangesDefChangeViewChannelDefCheckedcheckGameChoicechoiceChoiceUiclampStatCommandCommandCallCommandLogcommandOfCommandRefCommandRegistryConditionConditionCallConditionRegistryContentCreatedEntityCreateFieldscreateRunnerCreditCreditGroupcreditsOfCustomContextDataScenedecidedeclaredTraitdeclaredWithTraitdescribeProblemDicedismissdrawdrawOneEffectEffectCallEffectRefEffectRegistryeffectsOfentitiesOfEntitiesViewEntityDefentityDescriptionentityImageentityKventityNameentityOfEntityRefEntityStateentityTagsEntityUiEntityViewexplainexplainTextExplanationFileRefFillPartfillTokensFlowChoiceFlowStateFlowStepfoldFormulaGameGameAudioGameBaseGameMediaGameRulesGameStateGameUihashHelperRegistryHelpersInHistoryOptionsholdsHotspotDefHotspotViewimageinlineChoicesinlineMarkupInlinePartInlineSpanInlineUiInlineUiArgsInputDefInputViewinRangeInstalledModisUniquejumpKindDefKvValuelackingLineLoadedLoadedSaveloadGameLoadOptionsloadStateMediaStatemediaTypememoryDriverMigrationToolsminigameMinigameDefMinigameInputMinigameSceneFieldsMinigameStateMinigameStateDefMinigameTargetMinigameTransitionMinigameViewModFileModsmodsneedNoticeNoticesViewNoticeViewnotifyOnceOpenPanelownedCountPackpanelparseRefPatchPhrasePhraseRowPhrasesPhraseWithArgsPictureDefPictureLayerPictureLayerViewPictureViewPlayedPLAYERPlaylistDefPluginCallpluginQuerypointPoolFilePriceProbeProblemProfileprofileproseBeatsProseStoreprotagonistQueryQueryRegistryRangeRawPackReasonreasonOfreceiversOfreceiveThingreleaseThingRenderedChoicereplayresolveYouResultRollRollsStateRunnerRunnerOptionsRunnerSnapshotRunningTimerSAVE_VERSIONSaveDriverSaveExtraSaveFileSaveListingSaveMetaSavessavesSavingViewsaySceneBeatSceneMediasceneOfScenePanelSceneUiSCHEMAScreenscreenScreenChoiceScreenSceneSelectSettingDefSettingViewSomeoneSpeakerViewstartingStateStartOptionsStatDefStatKeystatLevelStatLevelsstatOfStatRoundStatsStatUistatValueStatViewStatWordsStoryletFieldsStorylineDefstorylineOpenStorylineStateStringKeystringOfSTRINGSStringstextTextLineTimerDefTimerViewTimesTrackDefTraitDatatraitOfTraitRegistryTraitSourceTraitTabletranslatableFieldsTriggerDefUiUiFieldUiInContentuiInContentUiTargetupgradePackValueRefVariantMemberVideoFlagsVideoViewViewviewViewOptionsViewRegistryViewsInweightedwhenwhyNotwithTraitWordFieldWordPartWordShapewriteEntityYOU