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

The game

The loaded Game every engine function takes, with its fields, the room shown while no scene is open, and sceneOf.

A Game is one loaded game: its scenes, stats, entities and the rest of its content, merged with the base that holds its id and code. loadGame makes it, and every engine function takes it as an argument, so nothing is registered globally. Content, packs and the base explains where each part comes from.

In the showcase: examples/showcase/src/game.ts.

import { sceneOf, type Game } from '@ifloom/engine'

Game

A loaded game, the base's fields and the merged content's. Every field is in Game.

The base gives id, title, version, plugins, receivers and rules. The content and packs give the rest, so a mod can reach it, and loadGame sets prose, traits, data and packs as it merges. Content lists how each content key merges. These fields need more than their API description:

FieldMeaning
idThe game's id, which saves are kept under. A save from another game's id is refused, so the id never changes once players have saves.
versionThe game's own version, a whole number from 1, which saves record. Declaring it, even as 1, stops the engine filling new stats, settings and entities into old saves itself. See migrations.
pluginsThe plugins the game is built with. Their hooks run in this order.
receiversThe order the receive effect asks the plugins that keep things, by id. The order of plugins if left out. See Receivers.
introSceneThe scene open on the first frame, counted as seen once at turn 0. A game without one opens on its room with nothing seen.
actionsThe actions the room offers. One with a label is a button after every plugin's buttons, and one without is done only by { type: 'action', id }.
traitsEvery declared entity's traits, worked out from the content's traits table, the entities and their kinds.
packsThe ids of the packs the game was loaded with, in order. A save records them, and names a missing one in missingPacks.

A new game starts at turn 0 with introScene open and the content's kv in the kv store. Each plugin's state starts at its own start, so the places plugin's start puts the player at a location. startingState builds it.

While no scene is open, the screen shows the room. The room is the scene of the first provider that answers, the game's own rules.scene first, which with the places plugin is the location the player is at. With no provider, it's a scene titled with game.title and no body. Under it come the plugins' buttons and then the game's actions, unless a lock that denies '*' is on. The engine adds no button of its own.

The core keeps no locations and no characters. The places plugin adds locations and the cast adds characters, each an entity in the content's entities. A linear story without them gives an introScene and leaves the screen to whichever scene is open.

The showcase's base holds what the game is and its code. Its first scene, starting kv and buttons are content:

import { loadGame, type Content } from '@ifloom/engine'
import { calendar } from '@ifloom/plugin-calendar'
import { places } from '@ifloom/plugin-places'
import { cast } from '@ifloom/plugin-cast'
import { rules } from './rules.ts'

const movingDay: Content = {
  introScene: 'intro',
  kv: { phase: 'arrival' },
  actions: [{ id: 'wait', label: 'Wait a while', effects: [calendar.pass(1)] }],
}

export const { game, problems } = loadGame([movingDay], {
  id: 'small-town',
  title: 'Small Town',
  plugins: [calendar(), places({ start: 'flat' }), cast()],
  rules,
})

Organise your game's files shows how a game splits its content across files.

saveable

The content's reasons to refuse saving, as Blocked entries. Saving is refused while an entry's when holds, and the first entry that holds gives the reason. A game without saveable always allows saving.

Each content file's entries come after the ones before, and a pack's come after the content's. A pack entry with the id of an earlier entry replaces it.

import type { Content } from '@ifloom/engine'

export const flat: Content = {
  // No saving on moving day until the boxes are unpacked.
  saveable: [{ when: { kv: 'phase', is: 'arrival' }, reason: 'Unpack first.' }],
}

The runner's save fails with the reason, and the runner skips an autosave that falls due. Loading is never refused. view.saving gives { allowed, reason, visible }, so a UI greys out its Save button with the reason, or hides it while an entry with hide holds. The content checker checks each when as it checks any condition.

Functions

sceneOf

Returns the scene with this id as the content declares it, or undefined when there is none. Its signature is in sceneOf.

import { sceneOf } from '@ifloom/engine'

sceneOf(game, 'ava.hi')?.title // 'Ava'

Every lookup follows one naming rule. One definition by id is xOf(game, id), as in sceneOf, statOf and actionOf. A list is xsOf(game), as in the quests plugin's questsOf. What an entity is in play takes the state too, xOf(state, game, ref), as in the cast's personOf. Every function that reads the game in play takes the state first and the game second.

A scene as the player sees it in a state is in the view, so a tool that previews a scene opens it in a state and reads view(state, game).scene. entityOf looks up an entity.

Caveats

  • game.scenes holds each scene as the content declares it. The engine works out what a scene shows each time it renders it.
  • Plugins go on the base and only there. Content and packs can carry a plugin's data, but can't add a plugin.
  • checkGame checks that every id the game names resolves. loadGame runs it, and a test that runs it fails on a broken id at commit time.

Last updated on

On this page