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

Show a popup

Open a dialog from a word in the prose, either one that only shows words or one whose buttons change the game.

Use this to open a dialog from a word in the text. Choose one of two ways, by whether the dialog changes the game:

  • A popup that only shows something, such as the full text of a note, is a UI piece, [[ui:modal|words|key]]. Opening it isn't a command, so the save and the command log never see it.
  • A modal that changes the game, such as a lease to sign, is a panel opened by an inline action. Opening it is a command, its buttons send commands, and a replay opens it as play did.

Write a popup that only shows words

Write [[ui:modal|words|key|title]] where the link should go. The words show in the line, and the popup shows the prose key key. The title is optional, and without one the popup is titled with the words:

import { text, type Block, type Content } from '@ifloom/engine'

export const flatLine: Block = text(
  "Boxes, mostly. The window looks over the high street, and [[ui:modal|the radiator knocks|notice.welcome|Sam's note]] when it feels like it.",
)

export const notes: Content = {
  prose: { 'notice.welcome': 'Welcome to the building! Bins go out Thursday. The radiator knocks; ignore it. Sam, flat 2' },
}

The popup's line can have several paragraphs, bold, italics and tokens, and a translation or a mod rewrites it by its key. [[ui:image|words|path]] works the same way for a picture, which the words open large.

The React UI renders both with no code from you, as InlineModal and InlineImage.

Render the popup in a UI of your own

The view gives the line's beat a ui span, { type: 'ui', name: 'modal', text, args }, where args[0] is the prose key and args[1] the title. Read the line from the game's prose for the current state, and open a native <dialog> with showModal() when the words are pressed. The <dialog> closes on Escape, keeps focus inside while it's open, and returns focus to the link when it closes. Render the line's other spans as Render inline choices and tooltips does, and call this for a ui span named modal:

// src/popup.ts
import type { InlineSpan, Runner } from '@ifloom/engine'

export function drawPopup(runner: Runner, line: HTMLElement, span: Extract<InlineSpan, { type: 'ui' }>): void {
  const [key, title] = span.args
  const text = key ? runner.game.prose?.line(key, runner.state) : undefined
  // A key with no prose shows as its words, so the line still reads.
  if (text === undefined) return void line.append(span.text)
  const button = line.appendChild(document.createElement('button'))
  Object.assign(button, { type: 'button', className: 'popup-link', textContent: span.text })
  button.setAttribute('aria-haspopup', 'dialog')
  button.onclick = () => {
    const dialog = document.body.appendChild(document.createElement('dialog'))
    dialog.appendChild(document.createElement('h2')).textContent = title ?? span.text
    for (const paragraph of text.split('\n\n')) dialog.appendChild(document.createElement('p')).textContent = paragraph
    const close = dialog.appendChild(document.createElement('button'))
    Object.assign(close, { type: 'button', textContent: 'Close', onclick: () => dialog.close() })
    dialog.onclose = () => dialog.remove()
    dialog.showModal()
  }
}

Give the link a look of its own, so a player can tell it from an inline action, which does something:

.popup-link { padding: 0; border: 0; background: none; font: inherit; text-decoration: underline dashed; cursor: pointer; }
dialog::backdrop { background: rgb(0 0 0 / 0.5); }

Write a modal that changes the game

Open a panel with the panel effect, from an action the line links to. Give the panel's button an action with no label, which the panel sends and the room doesn't show:

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

export const lease: Content = {
  actions: [
    {
      id: 'sign-lease',
      cost: { stats: { coins: 50 }, reasons: { coins: "You can't cover the deposit yet." } },
      blocked: [{ when: { kv: 'signed' }, reason: 'You signed it already.' }],
      effects: [{ kv: 'signed', to: true }, { panel: null }],
    },
  ],
  prose: { 'lease.text': 'Twelve months, rent on the first. No pets. (Sam says nobody checks.)' },
}

// The flat's location gains the line and the action it links to.
export const leaseLine = text('The [[act:lease|lease]] is still on the table, unsigned.', { when: { not: { kv: 'signed' } } })
export const readLease = { id: 'lease', label: 'Read the lease', effects: [{ panel: 'lease', with: { title: 'The lease' } }] }

The panel stays open while the player reads. It closes when signing closes it with { panel: null }, when the player dismisses it with the closePanel command, or when the scene changes or the turn ends.

Render the panel by its name from view.panel. With the React UI, give mountGame a panels entry, { lease: LeasePanel }, and PanelHost renders it in a dialog titled with with.title. In a UI of your own, follow Render a panel, and send { type: 'action', id: 'sign-lease' } from its button.

Check it worked

Run npm run check, which reports an [[act:…]] that names no action. With the React UI, checkUiHints also reports a [[ui:modal|…]] whose key has no prose. Then press the words in the game. The popup opens over the story and closes on Escape. Signing the lease without 50 coins shows the cost's reason, and with them closes the panel and takes the line away.

Don't open a panel from a UI piece. A [[ui:…]] link isn't a choice or an action, so the checker, a replay and a UI without that piece don't know it does anything. An inline action does.

In the showcase, Small Town, the flat's "the radiator knocks" opens Sam's note, and at the café Ava's name opens her photo (examples/showcase/src/story/flat.ts and story/ava.ts). For more, see:

Last updated on

On this page