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

Arrange the layout

Arrange the page around the story, with sections that fold or open in a dialog and a side column that becomes a drawer on a phone.

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 is the whole default layout.

Fold a section

Wrap the parts in a 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 <details>, which folds with no code:

// src/main.ts, with section() from the vanilla template's src/layout.ts
import { layout, section } from './layout.ts'

function draw(view: View): void {
  const { sidebar } = layout(root)
  const stats = add(section(sidebar, 'stats', 'Stats'), 'dl', '', 'stats')
  for (const stat of view.stats) {
    add(stats, 'dt', stat.label)
    add(stats, 'dd', stat.text)
  }
  // …the story, as before
}

A Section hides itself when nothing in it renders anything, so a Quests section in a game without the quests plugin takes no space. The cards inside have titles of their own, so pass them title={false}.

Open a section in a dialog

Give the Section dialog instead of collapsible for something the player looks at now and then, such as the quest log or the people they've met. It becomes a button that opens its children in a dialog, and badge puts a count on the button:

// A button that opens a <dialog> with the quests' names.

const quests = view.plugins.quests
if (quests) {
  const dialog = add(sidebar, 'dialog')
  for (const quest of quests.active) add(dialog, 'p', quest.name)
  add(dialog, 'button', 'Close').onclick = () => dialog.close()
  add(sidebar, 'button', quests.updates ? `Quests (${quests.updates})` : 'Quests').onclick = () => dialog.showModal()
}

A dialog opened from the side column stays open while the player acts inside it.

Show a part only at some locations

Give a Section a when, any condition content could write, such as a wardrobe shown only at home. When does the same for anything else, and useHolds answers in a hook. They read the state and change nothing, so saves and replays aren't affected. With a UI of your own, ask the engine's holds as you render:

import { holds } from '@ifloom/engine'
import { places } from '@ifloom/plugin-places'

// In draw(), after the stats:
if (holds(runner.state, runner.game, places.at('flat'))) {
  const worn = section(sidebar, 'wardrobe', 'Wearing')
  // …what the player has on, from view.plugins.wardrobe
}

To decide in plain code instead, read a plugin's view. This lists the exits only outdoors, from the places plugin's view, read in React with usePlaces:

const places = view.plugins.places
if (places?.location?.tags.includes('outdoors')) {
  const list = add(story, 'ul')
  for (const exit of places.exits) add(add(list, 'li'), 'button', exit.label).onclick = () => runner.apply(exit.command)
}

Open a panel from the story

For something that shouldn't be on screen until the story asks, such as the wardrobe when the player opens the wardrobe door, put the panel effect on an action:

import { places } from '@ifloom/plugin-places'

const flat = places.location({
  id: 'flat', name: 'Your flat', description: 'Home', exits: ['high-street'],
  body: [{ prose: 'place.flat' }],
  actions: [{ id: 'wardrobe', label: 'Open the wardrobe', effects: [{ panel: 'wardrobe' }] }],
})

The React UI's PanelHost renders the built-in panels by name, so keep one in your layout. Open a shop, a job board or another panel shows the effect in every kind of content, and Render a panel renders view.panel in a UI of your own.

Place the story's text

The React UI keeps the scene's title, its words, the choices, the inputs, the exits and the people here to a reading column --width-prose wide, centred in the story. Pictures, a location's layered picture and panels still use the whole width. To keep the column to the start of the story instead, give Story align="start". The vanilla and vue templates keep their text to the start already, and a few lines in src/styles.css centre it:

/* src/styles.css: the story's text in a column in the middle, as the React UI renders it */
.story > h2,
.prose,
.inputs,
.choices {
  width: 100%;
  max-width: 70ch;
  margin-inline: auto;
}

In the React UI you can also leave the layout alone and set the --margin-prose token, the column's margin-inline, in a preset or your stylesheet. auto centres the column and 0 auto keeps it to the start. An align on Story wins over the token:

:root {
  --margin-prose: 0 auto;
}

Style the side column on a phone

The React UI's Sidebar becomes a drawer below 48rem, Tailwind's md, with no work from you. A slim top bar holds the title, the clock and a menu button, and the button slides the side column in over the story. Focus stays in it, Escape closes it, and it closes once the player chooses something. Style it with its parts:

[data-part="top-bar"] { background: var(--card); }
[data-part="drawer"] { width: 20rem; }
[data-part="drawer-button"] { border-radius: 999px; }

The vanilla and vue templates stack the side column above the story on a phone, with a media query in src/styles.css. A section that folds keeps that short.

Check it worked

Play in npm run dev. Fold the Stats section and reload: it stays folded. Go home to the flat, and the Wearing section shows. Narrow the window below 48rem, and the side column moves into the drawer behind the menu button.

For more, see:

Last updated on

On this page