{{ quest.hint }}
Done: {{ quests.done.map((quest) => quest.name).join(', ') }}
``` 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](https://ifloom.dev/docs/how-to/react/show-plugin-uis) places them in a layout of your own, and the [Render it yourself](https://ifloom.dev/docs/how-to/render/start) pages render every plugin's view. ## Add the plugins it works with [#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`](https://ifloom.dev/docs/reference/plugins#cooperates) table lists each partner and what happens without it. ## Check it worked [#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: ```text 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](https://ifloom.dev/docs/reference/plugins), with a page for each plugin's factory, content and calls. - [`Plugins`](https://ifloom.dev/docs/reference/react/kit#plugins), the component that places plugin UIs. - [How plugins work](https://ifloom.dev/docs/explanation/plugins). # Add a quest (https://ifloom.dev/docs/how-to/add-a-quest) Use this to give the player a goal in steps, such as settling into a new town. You need the [quests plugin](https://ifloom.dev/docs/reference/plugins/quests) (see [Add a plugin](https://ifloom.dev/docs/how-to/add-a-plugin)). A quest is a list of [stages](https://ifloom.dev/docs/reference/glossary#stage), each done the first time its condition holds, in order. Progress is never taken back. ## Declare the quest [#declare-the-quest] Add the quest to `data.quests.quests`, in the story file it belongs to. Each stage has a `hint`, which the player reads while it's the stage they're on, and a `done` condition. The showcase's first quest, cut down to two stages: ```ts import type { Content } from '@ifloom/engine' import { places } from '@ifloom/plugin-places' export const movingDay: Content = { data: { quests: { quests: [ { id: 'settle', name: 'Settle in', description: 'New town, new flat. Find your feet.', starts: { kv: 'phase', is: ['open'] }, stages: [ { id: 'out', hint: 'Step out onto the high street.', done: places.at('high-street') }, { id: 'ava', hint: 'Somebody runs the café. Say hello.', done: { seen: 'ava.hi' } }, ], }, ], }, }, } ``` Write each `done` for the moment something happens, such as arriving on the high street. A stage stays done when its condition stops holding, and a later stage counts only once the stages before it are done. The quest is done when its last stage is. ## Start it [#start-it] Give the quest a `starts` condition, and it starts the first time that holds after a command. `settle` starts when the intro sets the `phase` key to `open`. Leave `starts` out to start the quest from an effect instead, with `quests.start()`: ```ts import type { ActionDef } from '@ifloom/engine' import { quests } from '@ifloom/plugin-quests' export const collar: ActionDef = { id: 'collar', label: 'Turn up your collar', effects: [quests.start('scarf')] } ``` A quest can start another, as the showcase's `friend` quest does with `starts: quests.active('settle')`. Give a quest `secret: true` to leave it out of the count of quests still to find until it starts. ## Gate content on its progress [#gate-content-on-its-progress] Read a quest's progress with its conditions, anywhere a condition goes: ```ts import type { Choice } from '@ifloom/engine' import { quests } from '@ifloom/plugin-quests' export const river: Choice = { id: 'river', label: 'Walk to the river', when: quests.reached('friend', 'close'), effects: [{ scene: 'ava.river' }] } ``` - **`quests.active('settle')`** holds while the quest is started and not done. - **`quests.reached('friend', 'close')`** holds once that stage is done. - **`quests.done('settle')`** holds once the last stage is done. ## Show a badge for news [#show-a-badge-for-news] A quest has news when it starts, moves on a stage or is done. Print the number of quests with news the player hasn't looked at with `{{quests/updates}}`, such as in a button's label `To do ({{quests/updates}})`. When the player has looked, send `quests.seen()` to mark every quest's news seen, or `quests.seen('settle')` for one. The React UI's quest log shows the count as a badge, with a Mark all seen button that sends `quests.seen()`. ## Track one quest [#track-one-quest] Send `quests.track('scarf')` to track an active quest, which puts it first in the list. The quest log's Track button sends it. `quests.track()` with no quest stops tracking. Tracking a quest that isn't active is refused with `You are not doing that.` ## Check it worked [#check-it-worked] Run `npm run check`. It reports a quest with no stages, two stages with one id, and anything a `done` or `starts` names that the game doesn't have: ```text content · quests settle · stage out: unknown location "lido" ``` Then play in `npm run dev`. Once the quest starts, it shows in the quest log with its first hint, and the hint moves on as each stage is done. To render the log in a UI of your own, see [Render the quest log](https://ifloom.dev/docs/how-to/render/progress-plugins#render-the-quest-log). In the showcase, Small Town, `settle` is in [`examples/showcase/src/story/moving-day.ts`](https://github.com/IFLoom/ifloom/blob/main/examples/showcase/src/story/moving-day.ts) and `friend` in `src/story/ava.ts`. For more, see: - [Quests](https://ifloom.dev/docs/reference/plugins/quests), with [`QuestDef`](https://ifloom.dev/docs/reference/plugins/quests#questdef), [`QuestStage`](https://ifloom.dev/docs/reference/plugins/quests#queststage) and the [`quests/start`](https://ifloom.dev/docs/reference/plugins/quests#questsstart) effect. - [Build a friendship in stages](https://ifloom.dev/docs/how-to/build-friendships-in-stages), to pace a quest's stages over days. - [Stats, the kv store and storylines](https://ifloom.dev/docs/explanation/entities-and-traits#stats-the-kv-store-and-storylines). # Add a settings page (https://ifloom.dev/docs/how-to/add-a-settings-page) Use this to let the player change things such as hints or the text size. The engine has no settings of its own, so your content declares each one, and their [profile](https://ifloom.dev/docs/reference/profile) keeps the player's choices, so a new game starts with them. ## Declare the settings [#declare-the-settings] List them in your content's `settings`. A [setting](https://ifloom.dev/docs/reference/settings#settingdef) is a `toggle`, a `choice` or a `range`. This declares one of each sort the showcase uses: ```ts import type { Content } from '@ifloom/engine' export const settings: Content = { settings: [ { id: 'hints', label: 'Show hints', type: 'toggle', default: true }, { id: 'textSize', label: 'Text size', type: 'choice', affects: 'ui', options: [ { value: 'normal', label: 'Normal' }, { value: 'large', label: 'Large' }, ], default: 'normal', }, ], } ``` `hints` leaves out `affects`, so it's a play setting, part of the game state and the save. `textSize` has `affects: 'ui'`, so it never enters the game state. It's kept only in the profile, and only your UI reads it. ## Read a play setting in the story [#read-a-play-setting-in-the-story] Read a play setting with the [`{ setting }`](https://ifloom.dev/docs/reference/conditions#setting) condition, as you would a kv key. This high street shows a hint line only while hints are on: ```ts fragment body: [ { text: 'Bunting, a bus stop and the smell of the bakery.' }, { text: 'The café is open in the mornings.', when: { setting: 'hints' } }, ], ``` A change to a play setting goes through the game as a [`setting`](https://ifloom.dev/docs/reference/commands#setting) command, so it applies at once, is logged with the other commands and replays the same. A save keeps the settings it was made with, so loading an old save brings its values back. ## Show the settings page [#show-the-settings-page] In the React UI, turn on `pages`, and the title screen and the player's menu gain a Settings button once the game declares a setting. Its page renders a checkbox for a toggle, radio buttons for a choice and a slider for a range. With a UI of your own, render `view.settings` and send each change with `runner.setSetting`: ```ts tab="Plain JS" tab-group="framework" import type { RunnerSnapshot } from '@ifloom/engine' // runner and add, as in the vanilla template's src/main.ts. import { add, runner } from './runner.ts' /** A settings screen: every setting the game declares, with its value now. A change goes through runner.setSetting. */ export function drawSettings(parent: HTMLElement, { view, settings }: RunnerSnapshot): void { // settings has the values of both kinds: play settings from the state, ui settings from the profile. for (const setting of view.settings) { const label = add(parent, 'label', setting.label) const value = settings[setting.id] ?? setting.default if (setting.type === 'toggle') { const box = add(label, 'input') Object.assign(box, { type: 'checkbox', checked: value === true }) box.onchange = () => runner.setSetting(setting.id, box.checked) } else if (setting.type === 'choice') { const select = add(label, 'select') for (const option of setting.options ?? []) Object.assign(add(select, 'option', option.label), { value: option.value, selected: option.value === value }) select.onchange = () => runner.setSetting(setting.id, select.value) } else { const range = add(label, 'input') Object.assign(range, { type: 'range', min: String(setting.min ?? 0), max: String(setting.max ?? 100), step: String(setting.step ?? 1), value: String(value), }) range.onchange = () => runner.setSetting(setting.id, Number(range.value)) } } } ``` ```tsx tab="React" tab-group="framework" import { mountGame } from '@ifloom/react' import module from './game.ts' // `pages` opens on a title screen whose Settings page renders every setting the game declares, play and ui alike. mountGame(module.build(), { pages: true }) ``` ```vue tab="Vue" tab-group="framework" ``` Read each value from [`runner.snapshot().settings`](https://ifloom.dev/docs/reference/runner#settings), which holds both sorts, and fall back to the setting's `default`. [Render a settings screen](https://ifloom.dev/docs/how-to/render/saves-and-settings#render-a-settings-screen) says what each `SettingView` holds. ## Apply a ui setting where you render the story [#apply-a-ui-setting-where-you-render-the-story] Read the value where you render the story. The runner calls its listeners when the player changes it, so whatever renders on a change reads the new value. In the React UI, [`useSetting`](https://ifloom.dev/docs/reference/react/components#usesetting) reads it and renders the component again: ```ts fragment tab="Plain JS" tab-group="framework" // src/main.ts, in the vanilla template. In draw(): root.classList.toggle('large', runner.snapshot().settings.textSize === 'large') ``` ```tsx tab="React" tab-group="framework" import type { ReactNode } from 'react' import { useSetting } from '@ifloom/react' export function Story({ children }: { children: ReactNode }) { const size = useSetting('textSize') returnThis story mentions a house fire.
It happens off the page.
Not today ``` Confirming moves on to the title screen and is remembered on that device, so the notice doesn't show again. Declining follows the link. Every word on the notice is yours. In the React UI's `gate`, a blank line in `text` starts a new paragraph. Without an `href`, the decline button does nothing and the player stays on the notice. ## Add a page of your own [#add-a-page-of-your-own] In the React UI, give `pages.pages` a component for each page, by id, and the title screen gets a button for it. With a UI of your own, show the page from a button on your title screen. This endings page reads `core:finished`, which the runner writes to the profile the first time the game's `finished` condition holds: ```ts tab="Plain JS" tab-group="framework" // src/endings.ts import type { Runner } from '@ifloom/engine' /** The endings page. `back` renders the title screen again. */ export async function endings(root: HTMLElement, runner: Runner, back: () => void): Promise{finished ? 'You have reached an ending.' : 'No endings yet.'}
{{ finished ? 'You have reached an ending.' : 'No endings yet.' }}
{{ beat.text }}
``` [`browserRunner`](https://ifloom.dev/docs/reference/browser#browserrunner) starts a new game with undo, saves in `localStorage` and an autosave each turn. The imports keep their `.ts` extensions, as the templates' do. Drop them if your TypeScript settings don't allow it. [Start your own UI](https://ifloom.dev/docs/how-to/render/start) renders the rest of the game with your own code. ## Add the scripts [#add-the-scripts] Add the CLI's commands to `package.json`: ```json { "scripts": { "check": "ifloom check", "playtest": "ifloom playtest --turns 5 --out playtest/run.txt", "typecheck": "tsc --noEmit" } } ``` A project that builds with Vite can also use `ifloom dev` and `ifloom build`, with the [Vite preset](https://ifloom.dev/docs/reference/cli#the-vite-preset) in its `vite.config.ts`. A project that builds with something else keeps its own build. See [Build with Next.js](https://ifloom.dev/docs/how-to/build-with-next), [Build with webpack](https://ifloom.dev/docs/how-to/build-with-webpack) and [Build with esbuild](https://ifloom.dev/docs/how-to/build-with-esbuild). ## Check it worked [#check-it-worked] Run the checks from the project's folder: ```sh tab="npm" tab-group="package-manager" npm run check npm run typecheck ``` ```sh tab="pnpm" tab-group="package-manager" pnpm check pnpm typecheck ``` ```sh tab="yarn" tab-group="package-manager" yarn run check yarn run typecheck ``` ```sh tab="bun" tab-group="package-manager" bun run check bun run typecheck ``` `check` loads `src/game.ts` and prints `No problems.` when the game loads cleanly. Otherwise it lists each problem with the scene or key it's about. Then open the page: it shows "The door" and its words. For more, see: - [The CLI](https://ifloom.dev/docs/reference/cli), for the game module and every command. - [The runner](https://ifloom.dev/docs/reference/runner) and [the view](https://ifloom.dev/docs/reference/view), for what the page reads. - [How the pieces fit](https://ifloom.dev/docs/explanation/architecture), for the packages a game needs. # Arrange the layout (https://ifloom.dev/docs/how-to/arrange-the-layout) Use this to change how the page is laid out around the story. The layout is one file: in the React UI, `src/layout.tsx`, a component made of regions (`Game`, `Sidebar`, `Story`, `Overlay`) with the parts inside them, passed to `mountGame` as `layout`. The vanilla and vue templates have the same regions in `src/layout.ts` and `src/Layout.vue`. [`DefaultLayout`](https://ifloom.dev/docs/reference/react/components#defaultlayout) is the whole default layout. ## Fold a section [#fold-a-section] Wrap the parts in a [`Section`](https://ifloom.dev/docs/reference/react/components#section) with `collapsible`. The profile keeps the player's choice per `id`, so a folded section stays folded next time. With a UI of your own, use a `