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

Presentation hints

The ui hints and inline pieces the React UI reads from content, such as transitions, reveals, dice and stat bars, and checkUiHints.

@ifloom/react, the optional React UI, reads these hints, so everything here is React only. To render a game in plain DOM, Vue or React by hand, see Start your own UI.

A ui hint is a ui field content writes on a scene, a choice, a block, a stat, a kind, an entity, a location or the game, which the engine carries to the view as written. Presentation hints explains the mechanism, and this page lists the hints the React UI reads. Add a transition or reveal lines uses them. In the showcase: examples/showcase/src/story/moving-day.ts.

KeyMeaning
transitionOn a scene, a location or the game, how the screen comes on and goes off. On a choice or an action, how the screen it leads to comes in.
transitionNamesOn the game, the transition names of the game's own.
revealOn a block, a wait before the block comes in.
diceOn a block, the roll rendered above it, which the block waits for.
timerOn a block, the running timer that counts down under it.
tiltOn a block, its picture set at a slight angle.
portraitsOn a scene or the game, false to leave out the picture beside each spoken line.
foldOn a section, the words the player opens and shuts its beats by.
displayOn a stat, a number, a bar or pips.
hueOn an entity or a kind, the colour of their spoken lines.
settingsOn the game, the ui settings the React UI applies itself.

Importing @ifloom/react anywhere in a game types these hints, so ui: { display: 'dial' } on a stat is a type error. A hint the React UI doesn't know still compiles, so another UI or a mod can add its own, and checkUiHints reports one the types let through. Prose holds inline pieces too, [[ui:name|words|arg]], which the React UI renders by name.

Scene renders the beats of a section with any hint, the React UI's or the game's own, as one group part. It copies each of the section's hints that's a string, a number or true/false onto the group as a data-* attribute, its camel-case name written in dashes, so ui: { card: 'result' } renders data-card="result". A hint on a single block makes no group, and a hint that's an object or a list isn't copied. Add panels, sections, components and hints declares and styles a hint of the game's own.

transition

transition sets how a screen comes on (in) and goes off (out), over ms milliseconds each. Its value is a Transition or a TransitionName, and a name on its own means the same both ways.

On a scene it is that scene's. On a location it is the room's while no scene is open. In the content's own ui it is the default for every screen that sets none, field by field, so a scene that sets only in takes out and ms from the game's. With no hint anywhere, a screen swaps at once with 'none', and ms is 300 when nothing sets it.

On a choice or an action, transition sets how the screen it leads to comes in, over whatever that screen says. A bare name there is only the in, and an out changes how the screen the choice leaves goes off. The runner records the choice that led to the screen in its snapshot's pressed, so a click, a number key, an inline action and a hotspot all count.

Scene plays a transition only when view.scene.key changes: a new scene, a minigame or another room. A choice that keeps the same scene open plays nothing. The scene before stays on the page, inert and hidden from screen readers, for its out, and the new one comes in by its in. useScene returns the same transition for a part of your own.

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

export const flat: Content = {
  ui: { transition: { in: 'fade', ms: 250 } },
  scenes: [
    {
      id: 'flat.window',
      title: 'By the window',
      ui: { transition: { in: 'fade', out: 'fade', ms: 600 } },
      body: [{ text: 'The high street is waking up.' }],
      choices: [{ id: 'unpack', label: 'Unpack', ui: { transition: { in: 'slide-up', ms: 400 } }, effects: [{ scene: null }] }],
    },
  ],
}

TransitionName

TransitionName is one of the built-in transitions in TRANSITIONS, or a name of the game's own from transitionNames. Its type is in TransitionName, and the list in TRANSITIONS.

KeyMeaning
fadeThe screen fades up from nothing, and fades away.
slide-upThe screen rises into place from a little below, and rises and fades.
slide-leftThe screen slides in from the right, and slides off to the left.
zoomThe screen grows slightly into place, and grows slightly and fades.
noneThe screen appears and goes at once.

Transition

Transition is the object form of a transition hint. Every field is in Transition. in and out are the game's, else 'none', if left out, and ms is 300.

transitionNames

transitionNames on the game lists transition names of its own, which a stylesheet renders with CSS keyed on data-transition-in, data-transition-out and data-reveal. A name is lower-case letters, digits and -. Add a transition or reveal lines styles one.

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

export const town: Content = { ui: { transitionNames: ['curtain'] } }

reveal

reveal on a block makes it wait delay milliseconds after the reveal before it, or after the scene comes on, then come in with as. Its value is a Reveal. delay is 800 and as is 'fade' if left out.

The hint arrives on the first beat the block makes, and every beat from there waits, up to the next block with a reveal. Scene renders each revealed run in a reveal part with data-reveal and --ifloom-reveal-at, and holds the choices back until the last. Every word is in the page from the start, so a screen reader reads it. A click on the scene or any key shows the rest at once, and a player who asks for reduced motion sees it all at once.

Delays add up, so blocks with delays of 800 and 1500 come in at 800 and 2300. useScene returns the runs with these times, for a Scene of your own.

import type { Block } from '@ifloom/engine'

export const body: Block[] = [
  { prose: 'intro' },
  { prose: 'intro.tonight', ui: { reveal: { delay: 1200 } } },
  { prose: 'intro.cat', ui: { reveal: { delay: 1500, as: 'slide-up' } } },
]

Reveal

Reveal is the value of a reveal hint, its delay and its as. Every field is in Reveal.

dice

dice on a block is the key of a roll. When the last command rolled under that key, Scene renders the roll's DiceRoll above the block.

The dice tumble for a second and settle on the faces rolled, then the total and Passed or Failed come in. The block and everything after it wait in a reveal part, so the words don't give the result away, and the choices wait too. A roll made before the last command shows settled. A roll no block names, such as a trigger's, shows for a moment over the scene in a DiceOverlay. With motion off or reduced motion, the dice show settled at once, and a screen reader hears the result either way. Roll dice for a check builds a whole check.

import type { Block } from '@ifloom/engine'

export const body: Block[] = [
  { prose: 'place.park.stones' },
  { prose: 'park.skim.passed', when: { roll: 'skim', passed: true }, ui: { dice: 'skim' } },
  { prose: 'park.skim.failed', when: { roll: 'skim', passed: false }, ui: { dice: 'skim' } },
]

timer

timer on a block is the id of one of the game's timers. While that timer runs, Scene renders its Countdown under the block.

The countdown shows the timer's label, a bar that empties with each tick and the seconds left, and carries data-urgent with a quarter or less to go. With motion off or reduced motion it shows only the seconds. It goes when the timer runs out or stops. The hint only renders the timer, which runs out on time whether anything renders it or not, and Timers renders every running one elsewhere. Add a countdown builds a timed choice.

import type { Block } from '@ifloom/engine'

export const body: Block[] = [{ prose: 'flat.ring', ui: { timer: 'flat.ring' } }]

tilt

tilt on a block set to true sets the block's picture at a slight angle, like a photo dropped on a table. The engine's picture markup has no flag for it, since the angle is presentation.

import type { Block } from '@ifloom/engine'

export const body: Block[] = [{ prose: 'flat.photo', ui: { tilt: true } }]

portraits

portraits on a scene or the game set to false leaves out the picture beside each spoken line. A line shows its speaker's picture whenever the beat has one: the speaker entity's image, or the player's from content's player. A scene's hint wins over the game's.

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

export const look: Content = {
  player: { image: 'people/you.png' },
  // The letter scene is read alone, so its lines show no pictures.
  scenes: [{ id: 'letter', body: [{ text: 'Dear Sam,' }], choices: [], ui: { portraits: false } }],
}

fold

fold on a section, { blocks }, is the words the player opens its beats by. The engine's fold builder writes it.

The engine carries a section's hints on every beat it makes, as the beat's section. Scene renders those beats in a <details> with the words as its summary, shut at first, inside the section's group part. A fold is presentation only and keeps no state.

import { fold, text } from '@ifloom/engine'

export const postcard = fold('Read the postcard', [text('Wish you were here. The sea is cold and the chips are good. J.')])

display

display on a stat sets how the StatList and the cast UI's Relationships render it. Its value is a StatDisplay.

'number', the default, is the value as the game formats it. 'bar' adds a bar under it from its min to its max. 'pips' adds a row of pips, one per point, and a range over 20 renders as a bar and checkUiHints reports it. StatGauge renders the bar and the pips.

import type { StatDef } from '@ifloom/engine'

export const stats: StatDef[] = [
  { id: 'energy', label: 'Energy', start: 80, max: 100, ui: { display: 'bar' } },
  { id: 'charm', label: 'Charm', start: 1, max: 20, ui: { display: 'pips' } },
]

StatDisplay

StatDisplay is the value of a stat's display hint, 'number', 'bar' or 'pips'. Its type is in StatDisplay.

hue

hue on an entity, or on a kind for all its entities, is a colour as a hue from 0 to 360. While a scene's speaker has one, Scene colours their spoken lines with it, lighter in dark mode.

Scene also sets data-speaker-hue and --ifloom-speaker-hue on the scene, for a stylesheet's own rules.

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

export const ava = cast.person({ id: 'ava', name: 'Ava', ui: { hue: 20 }, home: 'park', talk: 'ava.hi' })

settings

settings on the game names the ui settings the React UI applies itself, by each setting's id. The settings page renders them as it renders any other.

  • textSize names a ui choice setting. TextSize, which GameShell renders, copies its value to data-text-size on <html>. The styles size the page from its root for small (87.5%), normal (the browser's own), large (118.75%) and larger (137.5%), and the UI is sized in rem, so everything scales.
  • images names a ui toggle setting. While it's off, Picture and Video render nothing. A LayeredPicture stays, since its hotspots are part of play.

A sound switch is the engine's, since the audio player reads it too, and the game names it in audio.sound or audio.mute.

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

export const settings: Content = {
  settings: [
    { id: 'textSize', label: 'Text size', type: 'choice', affects: 'ui', options: [{ value: 'normal', label: 'Normal' }, { value: 'large', label: 'Large' }], default: 'normal' },
    { id: 'pictures', label: 'Show pictures', type: 'toggle', affects: 'ui', default: true },
  ],
  ui: { settings: { textSize: 'textSize', images: 'pictures' } },
}

TEXT_SIZES

TEXT_SIZES is the textSize options the styles size, in order: small, normal, large and larger. Its value is in TEXT_SIZES. An option of another name needs CSS of the game's own, such as :root[data-text-size="huge"] { font-size: 150%; }.

import { TEXT_SIZES } from '@ifloom/react'
import type { SettingDef } from '@ifloom/engine'

export const textSize: SettingDef = {
  id: 'textSize',
  label: 'Text size',
  type: 'choice',
  affects: 'ui',
  default: 'normal',
  options: TEXT_SIZES.map((size) => ({ value: size, label: size })),
}

InlineUi

An inline piece is a UI piece in prose, [[ui:name|words|arg|…]], which the React UI renders with the component of that name. The React UI declares five names in the engine's InlineUi:

KeyMeaning
modal[[ui:modal|words|key|title]] renders the words as a link that opens a dialog with the prose line key, titled title or the words. InlineModal renders it.
image[[ui:image|words|path|alt]] renders the words as a link that opens the picture at path in the viewer. InlineImage renders it.
mail[[ui:mail|body|From: Ava|Subject: Hello]] renders a letter as a card, the header lines as written and then the body. InlineMail renders it.
prop[[ui:prop|words|sticky]] renders a note in a dashed box by its face, sticky, clip or diary. InlineProp renders it.
mono[[ui:mono|words]] renders the words in a monospace face, for a sign or a screen. InlineMono renders it.

mail, prop and mono open nothing, and a mail or prop written as a paragraph of its own renders as one. The modal and the image render as buttons in the line, with the part inline-ui and data-ui set to the name. Escape, the close button or a click outside closes what they opened, and focus goes back to the words.

A modal shows words and can't change the game. A dialog with buttons that change the game is a panel opened from an inline action, and Show a popup writes both. A game adds pieces of its own, or replaces a built-in one, with inline. A name that neither inline nor the built-ins have shows its words as plain text.

export const prose = {
  'place.flat': "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.",
  'notice.welcome': 'Welcome to the building! Bins go out Thursday. Sam, flat 2',
}

Functions

checkUiHints

checkUiHints returns the problems with a game's hints and inline pieces for the React UI, as where: what lines, or an empty list. Its signature is in checkUiHints.

The engine's content checker only makes sure a hint is data, so checkUiHints catches these:

  • a hint the React UI doesn't read, such as ui.transiton, or one written where it isn't read, such as a reveal on a scene
  • a transition name neither built in nor in transitionNames, or a negative ms
  • a reveal delay that isn't whole milliseconds
  • a display other than 'number', 'bar' and 'pips', or pips on a range over 20
  • a hue outside 0 to 360
  • a block's dice that isn't a roll's key, or a block's timer that isn't one of the game's timers
  • a settings key other than textSize and images, a textSize that isn't a ui choice setting with options the styles size, or an images that isn't a ui toggle
  • an inline piece whose name is neither built in, nor a plugin UI's, nor in inline, a modal with no prose key or a missing one, an image with no path, and either with more than two arguments

It walks the content with the engine's uiInContent, as the content checker does, so it reads every ui field, every prose line and every block of words written in place, a plugin's content included. A problem in a block names its scene, as scene park block: ui.dice ….

import { describe, expect, it } from 'vitest'
import { checkUiHints } from '@ifloom/react'
import module from '../src/game.ts'

const { game } = module.build()

describe('the content', () => {
  it('has hints the React UI can render', () => {
    expect(checkUiHints(game)).toEqual([])
  })
})

CheckUiOptions

CheckUiOptions is the settings for checkUiHints, naming the hints and pieces that aren't built in. Every field is in CheckUiOptions.

FieldMeaning
pluginsThe plugin UIs the game gives mountGame, whose hints and inline pieces count as known.
inlineThe game's own inline pieces, the object it gives mountGame.
allowHint and piece names not to report, such as the game's own hints or another UI's.
import { checkUiHints } from '@ifloom/react'
import { shopUi } from '@ifloom/plugin-shop/react'
import { expect } from 'vitest'

expect(checkUiHints(game, { plugins: [shopUi], allow: ['card'] })).toEqual([])

UiHint

UiHint is a hint's declaration: its name under ui, the places content writes it in on, and a check that returns the problems with a value. Every field is in UiHint.

The React UI declares each hint on this page once as a UiHint, and checkUiHints is built from those declarations, so a hint is known only where its on names. Each inline piece is declared the same way, with its name, its component and its check. A plugin UI declares the hints its components read in its PluginUi's hints. Each problem a check returns follows the place, such as ui.timer "kettle" is not a timer the game has.

HintCheckContext

HintCheckContext is what a hint's check is told: the game, what the hint is on, that thing's id and the game's transition names. Every field is in HintCheckContext.

Caveats

  • The picture an image piece opens is text to the engine, so ifloom build doesn't check the file exists as it does for [[img:…]].
  • Nothing about an inline piece goes in a save or the log, and anything a piece sends with useGame().send is a command like any other, so a piece that changes the game is better written as an inline action.

Last updated on

On this page