Add a plugin
Install a first-party plugin, list it in the game's plugins in the right order, write its content and show it in the React UI.
Use this to add any first-party plugin, such as the calendar, places or quests, to a game you already have. The steps are the same for all seventeen; First-party plugins lists them, and How plugins work explains what one adds.
Install the package
Install the plugin's package beside the engine. Every plugin is @ifloom/plugin-<id>:
npm install @ifloom/plugin-questsThe package has @ifloom/engine as a peer dependency, so it uses the game's copy. Its React UI is in the same package, so there's nothing more to install for it.
List it in the game's plugins
Call the plugin's factory in the plugins of the base you pass to loadGame, in src/game.ts:
import { loadGame, type Content } from '@ifloom/engine'
import { defineGame } from '@ifloom/cli/game'
import { calendar } from '@ifloom/plugin-calendar'
import { places } from '@ifloom/plugin-places'
import { quests } from '@ifloom/plugin-quests'
declare const town: Content
export default defineGame({
build: () => loadGame([town], { id: 'small-town', title: 'Small Town', plugins: [calendar(), places({ start: 'flat' }), quests()] }),
})Order the list with these rules:
- List the calendar first. Plugins'
onTurnhooks run in list order, and the calendar's moves the clock on. Plugins after it see the new day, and plugins before it see the old one. - List places after the calendar. Plugins' labels join in list order, so the header reads
Day 1 · Monday morning · High Street. - Put the rest in any order. The cast asks places where the player is by name, so its place in the list changes nothing.
A game chooses its plugins when it's built. A mod can bring content for a plugin the game has, but it can't add a plugin.
Write its content
Content calls a plugin's conditions, effects and commands by their full name, <id>/<name>, with the arguments as an object. The plugin's helpers write them for you, and they are properties of its factory:
import { calendar } from '@ifloom/plugin-calendar'
import { places } from '@ifloom/plugin-places'
const bed = { id: 'bed', label: 'Go to bed', when: places.at('flat'), command: calendar.sleep() }A plugin's lists go under data.<id> in your content, such as data.quests.quests. A plugin whose content is entities has definers instead, such as places.location({ … }) and cast.person({ … }), written in entities. Each plugin's reference page lists its content under ## Content.
Show it on screen
With the React UI, import the plugin's UI from its /react subpath and list it in mountGame's plugins. With a UI of your own, render the plugin's view from view.plugins.<id>. The quest log, in each framework:
import type { RunnerSnapshot } from '@ifloom/engine'
// add and drawChoices, as in the vanilla template's src/main.ts.
import { add, drawChoices } from './runner.ts'
/** The quest log: the active quests, the tracked one first, each with its hint and how far along it is, then the finished ones. */
export function drawQuests(parent: HTMLElement, { view }: RunnerSnapshot): void {
const quests = view.plugins.quests
if (!quests) return
for (const quest of quests.active) {
const entry = add(parent, 'section', '', 'quest')
if (quest.updated) entry.dataset.updated = ''
add(entry, 'h3', `${quest.name} (${quest.stage} of ${quest.stages})`)
add(entry, 'p', quest.hint)
// Track it, so it comes first; the same button says Untrack once it's tracked.
if (quest.track) drawChoices(entry, [quest.track])
}
if (quests.done.length) add(parent, 'p', `Done: ${quests.done.map((quest) => quest.name).join(', ')}`, 'done')
// Mark all seen, while there is news: it clears the "updated" marks.
if (quests.seen) drawChoices(parent, [quests.seen])
}
The React UI's default layout puts each plugin's parts where its UI says, in the order of the list. Show plugins in the React UI places them in a layout of your own, and the Render it yourself pages render every plugin's view.
Add the plugins it works with
No first-party plugin needs another. Some do more when the game has a partner, such as the shop's opening hours with the calendar, or the cast's people in the room with places. The cooperates table lists each partner and what happens without it.
Check it worked
Run npm run check. It prints No problems. when the game has every plugin its content calls. A call to a plugin the game lacks shows up as a problem:
story.ava · scene ava.park · no plugin condition named "quests/done"; the game has no plugin "quests"Add the missing factory to plugins, or remove the call.
For more, see:
- First-party plugins, with a page for each plugin's factory, content and calls.
Plugins, the component that places plugin UIs.- How plugins work.
Last updated on