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

Add a content notice and pages of your own

Show a content notice the player confirms once before the title screen, and add pages of your own such as a list of endings.

Use this to show a content notice before the title screen, or to add a page of your own beside the title screen, such as a gallery or a list of endings found. Turn the title screen on first, as Add a title screen shows. Both pages read and write the player's profile, which outlives every save.

Show a notice before the title screen

In the React UI, give pages a gate. With a UI of your own, render the notice before the title screen, and remember in the profile's ui:gate that the player has read it:

// src/gate.ts
import type { Runner } from '@ifloom/engine'

/** The notice, unless the player confirmed it before on this device. `next` renders the title screen. */
export async function gate(root: HTMLElement, runner: Runner, next: () => void): Promise<void> {
  if (await runner.profile?.get('ui:gate')) return next()
  root.replaceChildren()
  root.appendChild(document.createElement('h1')).textContent = 'Before you start'
  root.appendChild(document.createElement('p')).textContent = 'This story mentions a house fire.'
  root.appendChild(document.createElement('p')).textContent = 'It happens off the page.'
  const confirm = root.appendChild(document.createElement('button'))
  confirm.textContent = 'Carry on'
  confirm.onclick = async () => {
    await runner.profile?.set('ui:gate', true)
    next()
  }
  Object.assign(root.appendChild(document.createElement('a')), { href: 'https://example.com/', textContent: '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

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:

// 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<void> {
  const finished = await runner.profile?.get<{ at: number }>('core:finished')
  root.replaceChildren()
  root.appendChild(document.createElement('h1')).textContent = 'Endings'
  root.appendChild(document.createElement('p')).textContent = finished ? 'You have reached an ending.' : 'No endings yet.'
  const button = root.appendChild(document.createElement('button'))
  button.textContent = 'Back'
  button.onclick = back
}

In the React UI, the component takes no props and fills the whole page. usePage moves between pages, and useProfile reads what outlives a save. Set showOnTitle: false to leave the page's button off the title screen, and open it yourself with usePage().go('endings'). A page with the id of one a plugin UI adds, such as achievements, replaces it.

Check it worked

Run npm run dev. The notice shows before the title screen. Press Carry on, reload the page, and it goes straight to the title screen. To see the notice again, clear the site's storage in the browser. The title screen has an Endings button, and its page says "No endings yet." until you finish the game.

For more, see:

Last updated on

On this page