Components
Every component and hook @ifloom/react exports, from GameShell to the pages around the game, with what each renders.
These are the components and hooks of @ifloom/react, the optional React UI, so everything here is React only. To render a game in plain DOM, Vue or React by hand, see Start your own UI. Choosing a UI says when to use which.
Every game component reads the view through useGame, so it renders only inside a GameProvider, and GameShell is one. A game replaces any of them by name in components, and each entry names the data-parts it renders, which React UI parts lists. Each plugin's own React UI, such as the shop's counter, is under ## React UI on that plugin's page. The shadcn/ui primitives are on the kit's page and need no provider. In the showcase: examples/showcase/src/layout.tsx.
Every component that takes className merges it over its own classes with cn, so a later Tailwind class wins: <Scene className="gap-8" />.
The game
GameShell
GameShell renders the whole UI: a GameProvider with the game's sound, its text size and, with pages on, the pages, around its layout. Its props are in GameShellProps, and The React UI describes them.
mountGame renders a GameShell too. With no layout, it renders the DefaultLayout. It passes components, classes, unstyled and the other UiOptions to its provider.
import { GameShell } from '@ifloom/react'
import { Layout } from './layout.tsx'
import { panels } from './panels.tsx'
export const App = () => <GameShell runner={runner} panels={panels} layout={Layout} pages />Set up the React UI mounts it in a new game.
Layouts
A layout is a component that renders the page from the regions and parts below. Rearrange or replace the React UI's parts writes one, and Arrange the layout makes the common changes.
DefaultLayout
DefaultLayout is the React UI's own layout, which a GameShell with no layout renders and the react and next templates copy into src/layout.tsx. Its signature is in DefaultLayout. It renders these regions:
- A
Sidebarwith theTitle, theClock, theGameMenu, and a foldingstatssection with theStatList. The plugin UIs' parts for thestatsandsidebarspots follow, such as the inventory plugin's card. The engine keeps no inventory, so the React UI has none of its own. - A
Storywith theSceneand theInputFields, then the plugin UIs'roomparts, theRoomActions, and the plugin UIs'storyparts. - A
PanelHost, and anOverlaywith theNotices.
Each <Plugins at="…" /> renders the parts the game's plugin UIs bring for that spot, in the order of its plugins list. A part with nothing to show renders nothing, and a section with nothing in it hides, so the layout suits any game.
Game
Game renders the page, a layout's root inside the game's provider. Its props are in GameProps.
With a Sidebar anywhere inside it, the page is a grid that carries data-has-sidebar: the side column is --width-sidebar wide and the story fills the rest. Without one, the page is a single centred column up to --width-reading wide. With pages on, it renders on the game page only.
Parts: page (with data-has-sidebar).
Sidebar
Sidebar renders the side column, an <aside> carrying data-sidebar, with its children in order. Its props are in SidebarProps.
Below Tailwind's md breakpoint (48rem), the column becomes a drawer. A slim top-bar holds the game's title, the Clock and a drawer-button labelled ui.openSidebar, which opens the column as a dialog from the left. Escape closes the drawer, and so does the state moving on, unless a dialog the drawer opened is still on top. Where matchMedia is missing, as on the server, it stays a column.
Parts: sidebar, top-bar, top-bar-title, drawer-button, drawer and drawer-overlay.
Story
Story renders the main column, a <main> with its children in order. Its props are in StoryProps.
The scene's words, choices and inputs, and the room's buttons, form a reading column --width-prose wide. Pictures, panels and minigames use the whole width. align places the reading column, 'center' or 'start', as data-align on the <main>. Left out, the --margin-prose token decides, and it centres the column unless a preset changes it.
<Story align="start">
<Scene />
</Story>Parts: story.
Overlay
Overlay renders a box that floats at the bottom right of the window, across its width on a phone and --width-notice wide from md. Its props are in Overlay. At the end of the page it sits after the content, so nothing is left under it, and it hides while it's empty. The default layout puts the Notices in it.
Parts: overlay.
Section
Section renders a titled part of a layout, which hides itself when its children render nothing. Its props are in SectionProps.
collapsibleputs a button on its title that folds it. The profile'sui:sectionskeeps each player's choice byid, andopen(defaulttrue) sets how it starts before the player chooses. Without a profile, the choice lasts until the page closes.dialogmakes the title, withbadgeafter it, a button that opens the children in aPartDialog.whenis a condition, and the section shows only while it holds, asWhendoes.
import { Section } from '@ifloom/react'
import { WardrobeCard } from '@ifloom/plugin-wardrobe/react'
import { places } from '@ifloom/plugin-places'
<Section id="wardrobe" title="Wearing" collapsible when={places.at('flat')}>
<WardrobeCard title={false} />
</Section>A card inside a section has a title of its own, so pass title={false} to the inventory plugin's InventoryCard, WardrobeCard and the rest, or the heading shows twice.
Parts: section (with data-section, data-open when it folds and data-dialog when it opens a dialog), section-title, section-toggle, section-body and section-badge.
When
When renders its children while condition holds, and nothing otherwise. Its props are in When. Any condition works, a plugin's included, and it's checked each time the view changes. It only reads, so it changes nothing in a save or a replay.
useHolds
useHolds returns whether a condition holds on the state on show, using the engine's holds. Its signature is in useHolds.
No condition always holds. When and Section's when use it. It's for placing parts of a layout when the view has no field for the case, such as a sidebar section shown once the player has been somewhere. What the story shows belongs in content, where the content checker reads it.
import { useHolds } from '@ifloom/react'
function RainBanner() {
return useHolds({ kv: 'raining' }) ? <p>It's raining.</p> : null
}WithPages
WithPages renders its children, or with pages on, the pages around them, showing the children on the game page only. Its props are in WithPages. GameShell has one, so you need it only under a GameProvider of your own.
GameProvider
GameProvider connects every component under it to a runner. Its props are in GameProviderProps.
It subscribes to the runner and reads runner.view() again only when the state changes, or when the part of the profile the plugins' views show changes. plugins are the plugin UIs to render. panels, inline and sections are the game's own, over what the plugin UIs bring under the same names. mods turns on the mod manager. The UiOptions go to a UiProvider inside it, and with keys on it listens for the keyboard shortcuts.
On its own it plays no sound, sizes no text and renders no pages. GameShell adds those around any layout, so you need the provider alone only for a root of your own, as Rearrange or replace the React UI's parts writes.
Define plugins, panels, inline, sections, mods, components and classes once, outside your component. A new object on each render, such as panels={{ StallPanel }}, renders every component under the provider again.
useGame
useGame returns the runner, its snapshot, the View on show and send. The fields are in GameContextValue.
Every component under the provider renders again when the runner hands a new snapshot: after a command, a setting, a save or a helper's report. send runs a command through runner.apply and returns its Result, so a component can show a refusal. It takes a plain command or a plugin's CommandRef, such as send(shop.buy('counter', 'item:sandwich')). plugins lists the plugin UIs whose plugin the game has, in their order. It throws outside a GameProvider.
import { useState } from 'react'
import { places } from '@ifloom/plugin-places'
import { useGame } from '@ifloom/react'
import { Button } from '@ifloom/react/kit'
function GoHome() {
const { send } = useGame()
const [said, setSaid] = useState<string>()
return (
<>
<Button onClick={() => setSaid(send(places.go('flat')).reason)}>Go home</Button>
{said ? <p className="text-sm text-muted-foreground">{said}</p> : null}
</>
)
}The runner covers what the view doesn't, such as runner.undo(), runner.save(...) and runner.snapshot().backlog.
ModsOption
ModsOption is the game's mods for the mod manager, passed as mods on GameShell or GameProvider. Every field is in ModsOption.
| Field | Meaning |
|---|---|
store | The Mods store the game loaded its mods from at start-up. |
problems | The content checker's problems, written by describeProblem. The manager shows each one that starts mod:<id> under that mod. |
onChange | The function that builds the game again with the mods as they now are, such as () => location.reload(). Without it, the manager never offers to restart. |
PanelComponent
PanelComponent is the type of a game's own panel: a scene's panel, an app's panel section, or a panel content opens. Its type is in PanelComponent. Its data is the panel's with. Add panels, sections, components and hints writes one.
InlineComponents
InlineComponents is a game's own components for UI pieces in its prose, by name, for the provider's inline. Its type is in InlineComponents.
One piece's component is an InlineComponent, and its props are InlineProps: the piece's name, its words as text, and its args, typed by what InlineUi declares for that name. Type a component as InlineComponent<'stamp'> to have its args typed. The hints page lists the built-in pieces.
PluginSectionComponent
PluginSectionComponent is the type of a component that renders a plugin's view inside a device's app. Its type is in PluginSectionComponent. data is that plugin's slice of view.plugins, and with is the section's with. A plugin UI registers its own in its sections, as the messages and feed UIs do.
Customising
These options make the UI a game's own, below the theme's tokens. Theme the React UI and Rearrange or replace the React UI's parts use them step by step.
UiOptions
UiOptions is the settings mountGame, GameShell and GameProvider take for the UI's look and behaviour. Every field is in UiOptions.
It is two halves, for a wrapper that passes on only one. StyleOptions holds components, classes and unstyled. BehaviourOptions holds viewer, keys and motion.
| Field | Meaning |
|---|---|
unstyled | Drops every built-in class and keeps the elements, their data-parts and their behaviour. false if left out. |
viewer | Turns on the MediaViewer. true if left out. With false, clicking a picture in the story does nothing. |
motion | Turns on scene transitions, reveals and tumbling dice. true if left out. With false, or a player whose system asks for reduced motion, everything shows at once. |
KeyOptions
KeyOptions is the keyboard shortcuts' settings, passed as keys. Every field is in KeyOptions. keys: true turns on the built-in keys, and an object adds your own:
- 1 to 9 press the choices on screen in order: the open scene's choices, or the
RoomActionswhile no scene is open. A greyed-out choice keeps its number, and its key does nothing. Inline actions have no number. - Escape opens the
GameMenu's buttons in a dialog, when the menu is on screen. mapsends a command for each key it lists, by itsKeyboardEvent.keyname. These come first, so mapping'1'or'Escape'replaces it.
import { mountGame } from '@ifloom/react'
import module from './game.ts'
mountGame(module.build(), {
keys: { map: { w: { type: 'action', id: 'wait' } } },
})The keys never fire while the player types in a field, holds Ctrl, Alt, Meta or Shift, or has a dialog open. A number key presses the ChoiceButton rendered with that number, so it works in any layout that renders choices with it. A running minigame's keys come first, whether keys is on or not. Define keys once outside your component, since a new map on each render registers the listener again.
Components
Components is a game's own components in place of built-in ones, by name. Its type is in Components.
Each replacement renders everywhere the UI renders that component, with the same props plus Default, the built-in one. These are the names:
- Layout:
Game,Sidebar,Story,Overlay,Section,When,Title,Clock,StatList,RoomActions,EntityTableandIcon. - Scene:
Scene,Beat,SceneHeader,BeatGroup,Fold,InlineAction,Tip,ChoiceList,ChoiceButton,PriceTag,InputFields,InputField,Picture,Video,LayeredPicture,HotspotandMediaViewer. - Around the story:
Notices,Notice,NoticeStrip,MinigameCard,DiceRoll,DiceOverlay,Countdown,Timers,Changes,ChangeItemandPanelHost. - Menu and pages:
GameMenu,SavesMenu,Backlog,ModManager,TitlePage,SettingsPage,LoadPage,CreditsPageandGatePage.
The built-in UI pieces are replaced in inline instead. A plugin UI adds its own names, such as ShopCounter, once you import its /react. Inside a replacement, render the built-in one through Default: importing it by name gives your replacement again.
import type { Components } from '@ifloom/react'
const components: Components = {
Clock: ({ Default }) => (
<div className="flex items-center gap-1 text-sm">
<span aria-hidden>◷</span>
<Default />
</div>
),
}Rearrange or replace the React UI's parts replaces one.
OverridableComponents and PartNames
OverridableComponents is the interface of every name components takes, and PartNames is the interface of the parts plugin UIs add to PartKey. Their types are in OverridableComponents and PartNames. A plugin's /react augments both, so components, classes, overridable and usePart take its names typed. Write a plugin's React UI augments them.
Override
Override is the type of one replacement in Components: a component that takes the built-in one's props and Default. Its type is in Override.
Classes
Classes is Tailwind classes for parts, by data-part name. Its type is in Classes. A string is merged with the built-in classes as cn merges them, so yours win where they clash. A function gets the built-in classes and returns the ones to use, so () => 'font-serif' replaces them.
import type { Classes } from '@ifloom/react'
const classes: Classes = {
choice: 'rounded-none',
'scene-title': (defaults) => `${defaults} uppercase tracking-widest`,
}PartKey
PartKey is a data-part name, one the React UI renders or one a plugin UI adds through PartNames. Its type is in PartKey. Together they're every key Classes takes, and React UI parts says what each one is.
UiProvider
UiProvider gives the components under it a game's components, classes and unstyled. Its props are in UiProvider. GameProvider has one inside it, so you need your own only to change one corner of the page. A nested provider merges its components and classes over the outer one's, and unstyled stays on once either turns it on.
import { UiProvider } from '@ifloom/react'
import { QuestLog } from '@ifloom/plugin-quests/react'
<UiProvider classes={{ quest: 'border-dashed' }}>
<QuestLog title="To do" />
</UiProvider>usePart
usePart returns the attributes for one part, its data-part and its classes, to spread onto an element. Its signature is in usePart.
It works the classes out from defaults (the built-in ones), the game's classes for the name and unstyled, then adds extra, a className your caller passed. A replacement or a component of your own that uses it takes part in a game's classes and stylesheet.
import { usePart, useGame } from '@ifloom/react'
function Purse() {
const { view } = useGame()
const attrs = usePart('stat-value', 'font-medium tabular-nums')
return <p {...attrs}>{view.statsById.coins.text}</p>
}overridable
overridable returns a component that a game can replace by name in components, from @ifloom/react/kit. Its signature is in overridable. Every built-in component is made with it, and the name has to be a key of OverridableComponents. Add panels, sections, components and hints makes one.
Icon
Icon renders one of the UI's icons by its IconName, from @ifloom/react/kit. Its props are in Icon.
With a label, a screen reader reads it; without one, it's hidden from them. The built-in icons are Lucide's, and replacing Icon in components changes the set everywhere. The names say where each goes: close on dialogs and notices, back in an open app, warning on a choice or hotspot, voice on a line's replay button, zoom for enlarging a picture, menu on the phone's drawer button, and chevron on a section's title.
The scene
Scene
Scene renders the open scene, or the room while no scene is open. Its props are in Scene.
The room is a plugin's room scene, such as the places plugin's, or else the game's title and an empty body. From top to bottom, Scene renders these parts:
- The heading, a
SceneHeader. - The scene's
LayeredPicturewhenview.scene.picturehas layers, or else itsimage, centred and at mostmax-h-80tall. - Each
Beatof the body, a section with ui hints in aBeatGroup, and a block with arevealhint in arevealpart that waits for it. - The inputs on offer while the scene is open, as
InputFields in aninputspart. - The panel the scene holds, when a component of that name exists, else its choices as a
ChoiceList. With reveals to come, these wait in arevealpart withdata-reveal-choices.
While a minigame runs, Scene renders that instead: the panel named by the minigame's id, or else a MinigameCard. It runs the minigame's clock either way. The <article> carries data-scene with the scene's id, or room, and data-minigame while one runs.
The article sits in a scene-transition part and renders afresh whenever view.scene.key changes, playing the content's transition hints. A block with a dice hint gets a DiceRoll above it, and rolls no block names show in a DiceOverlay. While the scene's speaker has a hue hint, the article carries data-speaker-hue and --ifloom-speaker-hue. useScene works all the timing out, and Add a transition or reveal lines and Roll dice for a check use it.
A click on the scene, or any key, shows every reveal at once and does nothing else, so a number key can't press a choice that isn't shown yet. With motion off, everything shows at once. A scene that names a panel with no component shows its choices instead, with no warning.
Parts: scene-transition, scene (with data-scene), scene-header, scene-portrait, scene-title, scene-image, beats, reveal, group, fold, fold-summary, fold-beats and inputs.
Render the scene renders the same view in any framework.
useScene
useScene returns everything Scene works out before it renders: the transition, the beats in the runs they're revealed in, the rolls and the wait. The fields are in SceneTiming.
A scene of your own on it keeps the React UI's motion. The wait lasts as long as the last run, plus the transition in and the reveal's fade, then stops by itself. Coming back to a screen, or new rolls on the same one, start it again.
| Field | Meaning |
|---|---|
transition | The screen's ScreenTransition: its key (view.scene.key, to key the element by), and how it comes in and goes out, in ms. The choice that led here, the snapshot's pressed, decides how it comes in. |
groups | The beats in runs, each a RevealGroup of RevealBeats. The first run shows with the screen, and each later one has a RevealPoint saying when it comes. |
pending | Whether runs are still to come. The choices can't be pressed until then. |
skip | The function that shows everything at once. Scene calls it on a click or the first key. |
rolls | The SceneRolls: every roll in view.rolls, the fresh ones that tumble, and at, which counts each new set. A load, an undo or a redo brings no fresh rolls. |
unnamed | The fresh rolls no beat on screen names, which Scene shows in a DiceOverlay. |
import { Beat, ChoiceList, useScene } from '@ifloom/react'
function PlainScene() {
const { view, transition, groups, pending, skip } = useScene()
return (
<article key={transition.key} data-transition-in={transition.in} onClick={pending ? skip : undefined}>
<h2>{view.scene.title}</h2>
{groups.map((group, n) => (
<div key={n} data-reveal={group.reveal?.as} style={{ animationDelay: `${group.reveal?.at ?? 0}ms` }}>
{group.beats.map(({ beat, index }) => (
<Beat key={index} beat={beat} />
))}
</div>
))}
{pending ? null : <ChoiceList choices={view.scene.choices} />}
</article>
)
}SceneHeader
SceneHeader renders the scene's heading: the speaker's portrait, when the scene has a speaker with a picture, and its title. Its props are in SceneHeader. A replacement still comes in with the scene.
import type { Components } from '@ifloom/react'
const components: Components = {
SceneHeader: ({ scene }) => <h2 className="chapter">{scene.title}</h2>,
}Parts: scene-header, scene-portrait and scene-title.
BeatGroup
BeatGroup renders a section of the body that has ui hints, its beats in one group part. Its props are in BeatGroup. Each hint that is a string, a number or a boolean becomes a data-* attribute in dashes, so { card: 'result' } is data-card="result" and plain CSS can style the section as one box. A replacement keeps its reveals, since Scene works the runs out around it. Add panels, sections, components and hints styles a hint of a game's own.
Parts: group.
Fold
Fold renders a section with a fold hint, what fold() writes, as a <details> the player opens and shuts. Its props are in Fold. It sits inside the section's BeatGroup, under label, the hint's words, and starts shut.
Parts: fold, fold-summary and fold-beats.
useMotion
useMotion returns whether to play transitions and reveals: the motion option, unless the player's system asks for reduced motion. Its signature is in useMotion. useReducedMotion returns only the system's setting, and follows it when the player changes it. A replacement that animates anything asks one of them.
import { useGame, useMotion } from '@ifloom/react'
function SceneTitle() {
const { view } = useGame()
const motion = useMotion()
return <h2 data-transition-in={motion ? 'fade' : undefined}>{view.scene.title}</h2>
}Beat
Beat renders one beat of a body by its type. Its props are in Beat.
| Kind | Meaning |
|---|---|
text | A paragraph. Its spans render in the line, an inline action as an InlineAction and a tooltip as a Tip. Bold and italics are the parts bold and italic. |
say | A paragraph in --speech under the speaker's name, the speaker-name part. The player's own line is in --player-speech and indented. A line with a voice ends with a replay button while the audio player runs. A line whose beat has an image sits in a line part with the speaker's picture beside it, the line-portrait part, unless the portraits hint is false. A replacement reads the picture from the beat's image. |
image | A Picture, full width or at most max-w-sm for size: 'inline', tilted a little by the tilt hint. |
video | A Video, sized as a picture is. |
sound | Nothing, because the audio player plays it. |
chose | A choice made earlier in a flowing scene: its label, small and in italics, after a ›. |
import { Beat } from '@ifloom/react'
<Beat beat={{ type: 'say', who: 'character', speaker: 'character:ava', name: 'Ava', text: '“Morning. What can I get you?”' }} />While the viewer is on, a picture or a clip sits inside a viewer-open button that opens the MediaViewer, labelled ui.zoom and the beat's alt text. A clip with controls has its own full-screen button instead. The Backlog, MessagesSection and FeedSection render their beats with Beat, so a replacement changes them all.
Parts: beat (with data-beat, and data-who on a spoken line), speaker-name, voice-replay, viewer-open, bold and italic.
InlineAction
InlineAction renders an inline action in the prose, from an action span, as a button inside the line that sends choice.command. Its props are in InlineAction.
A price follows the words in a PriceTag. A greyed-out one isn't disabled: it has aria-disabled and data-disabled, so Tab reaches it and pressing it shows the reason. The reason, a warning or an irreversible note is in a tip-content bubble, opened on hover, focus or a tap, and is the button's description. Inline actions have no number key.
Parts: inline-action (with data-choice, and data-disabled, data-warning and data-irreversible when they apply) and tip-content.
Tip
Tip renders a tooltip in the prose, from a tip span: its words as a button underlined with dots, and the note in a tip-content bubble with role="tooltip". Its props are in Tip.
The bubble opens on hover, focus or a tap and closes on Escape, a tap elsewhere or the pointer leaving. The button's aria-describedby points at the note. The bubble sits in the page's body, so a scrolling panel can't clip it, and stays inside the window.
Parts: tip and tip-content.
InlineTrigger
InlineTrigger renders the words of an inline piece as a button in the line that opens something over the page. Its props are in InlineTrigger. It has the part inline-ui, data-ui set to name, aria-haspopup="dialog" and aria-expanded from open, and focus returns to it when open goes back to false. The built-in modal and image use it.
InlineModal
InlineModal renders the built-in modal piece, [[ui:modal|words|key|title]], as an InlineTrigger that opens a PartDialog with the prose line key. Its props are in InlineModal. The engine's proseBeats gives the line for this save, rendered in an inline-modal part, under title or else the words. A key with no prose shows the words alone. Show a popup uses it.
InlineImage
InlineImage renders the built-in image piece, [[ui:image|words|path|alt]], as an InlineTrigger that opens the picture in the MediaViewer. Its props are in InlineImage. The path resolves as [[img:…]] does, and alt falls back to the words. It opens even with viewer: false, because the words are the only way to see it.
InlineMail
InlineMail renders the built-in mail piece, [[ui:mail|body|From: Ava|Subject: Hello]], as a letter on a card, the part inline-mail. Its props are in InlineMail. Each argument is a mail-header line, and the words are the mail-body, with their line breaks kept.
InlineProp
InlineProp renders the built-in prop piece, [[ui:prop|words|face]], as a note in the story's world in a dashed box, the part inline-prop. Its props are in InlineProp. data-face carries the face (sticky, clip or diary) for a stylesheet to dress.
InlineMono
InlineMono renders the built-in mono piece, [[ui:mono|words]], in a monospace face, the part inline-mono, for a sign or a screen. Its props are in InlineMono.
Picture
Picture renders an <img> that renders nothing, and takes no space, when its file is missing or src is empty. Its props are an <img>'s, in Picture.
It loads lazily unless you pass loading="eager", and still calls your onError. It remembers which src failed, so a new src on the same element gets its own chance. Its src goes through assetUrl. While the game's pictures setting is off (the settings hint's images), it renders nothing, except inside a KeepPicturesOn. Every picture the UI's components render is a Picture.
import { Picture } from '@ifloom/react'
<Picture src={person.portrait} alt={person.name} className="size-8 rounded-full object-cover" />It carries the data-part the component rendering it gives, such as scene-portrait.
usePicturesShown
usePicturesShown returns whether pictures render where it's called: false only while the setting named in the settings hint's images is off. Its signature is in usePicturesShown. It's true outside a game and inside a KeepPicturesOn. Picture and Video ask it.
import { usePicturesShown } from '@ifloom/react'
function Postcard({ src }: { src: string }) {
return usePicturesShown() ? <img src={src} alt="" /> : <p>(A postcard of the pier.)</p>
}KeepPicturesOn
KeepPicturesOn renders the pictures inside it whatever the pictures setting says. Its props are in KeepPicturesOn. LayeredPicture wraps itself in one, because its hotspots are part of play.
Video
Video renders a video clip as a <video playsinline>, with alt as its aria-label. Its props are in VideoProps. The flags are a video beat's or a VideoView's, so either spreads in.
import { Video } from '@ifloom/react'
<Video src="art/cafe/steam.mp4" poster="art/cafe/steam.jpg" autoplay loop muted controls={false} />It loads nothing until it scrolls into view, then plays if autoplay is set and pauses when it scrolls out. Where IntersectionObserver is missing, it plays straight away. A clip with muted: false follows the audio settings: muted by the mute or sound setting, at the volume of the game's video channel, else its sfx channel. Browsers refuse to start a clip with sound by itself, so give one controls. Its src and poster go through assetUrl, and it renders nothing while pictures are off.
Parts: video.
LayeredPicture
LayeredPicture renders a layered picture with hotspots, from a PictureView. Its props are in LayeredPicture. Scene renders view.scene.picture with it, and LocationCard a location's picture.
import { LayeredPicture, useGame } from '@ifloom/react'
function Room() {
const { view } = useGame()
return view.scene.picture ? <LayeredPicture picture={view.scene.picture} className="max-w-2xl" /> : null
}The box takes the picture's aspect, or the first layer's own shape once it loads, and 16/9 until then. The layers stack bottom first, each filling the box with object-fit: cover, a Picture or a Video with data-layer. A layer above the first needs transparent areas for the ones below to show. The Hotspots go on top. Add pictures and backgrounds builds one.
Parts: picture and picture-layer.
Hotspot
Hotspot renders one hotspot of a LayeredPicture as a <button> placed by its rect, in percent, that sends its command. Its props are in Hotspot; the hotspot is a HotspotView.
Its label is its aria-label and tooltip. It's invisible until the player points at it or tabs to it. A disabled one is dimmed, has aria-disabled and stays in the tab order, with its reason in title and read out. A warning shows the warning Icon in its corner.
Parts: hotspot (with data-hotspot) and hotspot-warning.
MediaViewer
MediaViewer renders a picture or a clip from the story large over the page, in a Dialog. Its props are in MediaViewerProps, and what it shows is a ViewerMedia, an image or video beat.
Beat opens it when the player clicks a picture or a clip in a scene, the backlog, a message or a post. A layered picture's layers don't open it. Escape, a click outside and the close button (ui.closeViewer) close it. viewer: false in UiOptions turns it off for the whole game.
Parts: viewer, viewer-close and dialog-overlay.
assetUrl
assetUrl returns where a picture is: its data: URL in a build made with ifloom build --inline-assets, and the path unchanged anywhere else. Its signature is in assetUrl. It ignores a leading ./.
Picture, Video and DeviceScreen call it. A component of your own that renders a picture from a path must call it too, or use a Picture, because a one-file build has no art/ folder.
import { assetUrl } from '@ifloom/react'
function Postcard({ src }: { src: string }) {
return <div className="h-40 bg-cover" style={{ backgroundImage: `url(${assetUrl(src)})` }} />
}ChoiceButton
ChoiceButton renders a RenderedChoice as a full-width button that sends its command. Its props are in ChoiceButton. It renders a scene's choices, the room's actions and a character's buttons.
The button shows its label, a warning icon when the choice has a warning, its price as a PriceTag, and its irreversible line in --destructive. A greyed-out choice is disabled and shows its reason. One with a warning that isn't greyed out shows the warning's words, so the player reads them first. With keys on, its number shows first in a <kbd>. A choice's tags aren't rendered.
Parts: choice (with data-choice, and data-choice-key when keys are on), choice-key, choice-label, choice-price, choice-warning, choice-irreversible and choice-reason.
ChoiceList
ChoiceList renders a column of ChoiceButtons, and nothing for an empty list. Its props are in ChoiceList. part names it 'choices' (the default) or 'actions', as RoomActions passes.
import { ChoiceList, useGame } from '@ifloom/react'
function RoomButtons() {
const { view } = useGame()
return <ChoiceList choices={view.actions} />
}Parts: choices, or actions.
PriceTag
PriceTag renders a Price's text in --price, and nothing for a price with no text. Its props are in PriceTag. The text is each stat's cost, then the plugins' notes, joined by the engine's priceSeparator string.
Parts: choice-price.
Stats, things and time
Title
Title renders the game's title, view.title, as a heading. Its props are in Title.
Parts: title.
RoomActions
RoomActions renders the buttons offered while no scene is open, view.actions, as a ChoiceList: the room's, the game's and the plugins' actions. Its props are in RoomActions. The default layout puts it at the bottom of the story.
Parts: actions.
Clock
Clock renders view.when, the time in the plugins' words, such as Day 3 · Wednesday afternoon. Its props are in Clock. It renders nothing when no plugin says the time. The calendar's UI renders its CalendarClock in its place.
Parts: clock.
useClock
useClock returns the time from the running game as { when }, view.when or null when no plugin says. The fields are in ClockState. The calendar's useCalendar gives the day and the period apart.
import { useClock } from '@ifloom/react'
function TopLine() {
const { when } = useClock()
return when ? <p className="text-xs uppercase">{when}</p> : null
}StatList
StatList renders the stats the view lists, each label beside its formatted value, such as 12 coins. Its props are in StatList. A stat the game doesn't list isn't in the view, and with no stats it renders nothing.
A stat with levels shows its level in its label, the level's name from levels.names or else ui.statLevel, and a progressbar towards the next one (ui.statProgress). A stat whose display hint is 'bar' gets a bar from its min to its max, and one with 'pips' gets a pip per point, in rows of ten at most. A range over 20 renders as a bar. Both are a meter for screen readers.
stats: [
{ id: 'energy', label: 'Energy', start: 80, max: 100, ui: { display: 'bar' } },
{ id: 'hearts', label: 'Hearts', start: 3, max: 5, ui: { display: 'pips' } },
]Build a HUD writes a bar of your own.
Parts: stats, stat (with data-stat), stat-label, stat-value, stat-level, stat-progress, stat-bar, stat-pips (with --pips-per-row) and stat-pip (with data-filled).
EntityTable
EntityTable renders a table for each kind in view.entities, headed with its plural. Its props are in EntityTable.
Each row is one entity: its picture, name and description, then its stats. The columns are every stat any row shows, and a row without one has a blank cell. kinds limits it to those kinds. It renders nothing when none has entities. The default layout leaves it out, and the café's layout puts it in the story.
import { EntityTable } from '@ifloom/react'
<EntityTable kinds={['dish']} className="border-t pt-4" />Parts: entities (with data-kind), entity-heading, entity-table, entity-columns, entity-column, entity-row (with data-entity), entity-name, entity-image, entity-desc and entity-value.
Inputs
InputField
InputField renders one of the game's inputs, an InputView, under its label. Its props are in InputField.
A text or number input is a box and an Enter button (ui.enter) that sends input, honouring maxLength, min and max. A choice input is a button per option, with the chosen one filled in. A refused value shows its reason under the field until one is accepted. The box follows the input's value when an undo or a load changes it. An empty number box sends no value, so the engine refuses it with enterSomething.
Parts: input (with data-input), input-label, input-field, input-options, input-submit, input-error and button.
InputFields
InputFields renders an InputField for each input in view.inputs while no scene is open. Its props are in InputFields. While a scene is open it renders nothing, because Scene renders them between its words and its choices. A lock that denies '*' denies input too, so a scene that asks for a value while the game is locked lists input in the lock's except. Ask for a name adds one.
Parts: inputs.
What changed
Changes
Changes renders the stats the last command moved, view.changes, as ChangeItem pills such as +30 coins. Its props are in Changes.
It lists only the stats named in content's changes.stats, and renders nothing when the last command moved none. A tick that moved nothing keeps the list. The default layout leaves it out, so a layout places it, here after the scene:
import { Changes, Scene } from '@ifloom/react'
// What the last command moved, as pills under the scene: `+30 coins`, `-5%`, `+2 Ava`.
// Each pill is a `change` part with data-stat, data-of and data-dir="up" or "down" for your CSS.
export function StoryWithChanges() {
return (
<>
<Scene />
<Changes />
</>
)
}
Parts: changes, labelled ui.changes.
ChangeItem
ChangeItem renders one ChangeView as a pill: its signed text, then its name when the view gives one. Its props are in ChangeItem. So +30 coins stands alone, while +20% reads +20% Energy. Its title says the stat's label, from what to what.
Parts: change (with data-stat, data-of for an entity's stat, and data-dir set to up or down), change-text and change-label.
The player's menu
GameMenu
GameMenu renders a row of buttons for what the runner offers, and nothing when there are none. Its props are in GameMenu. It shows these buttons:
- Saves (
ui.saves) when the runner hassaves. - Backlog (
ui.backlog) whenrunner.offers.backlogis on. - Mods (
ui.mods) when the provider hasmods. - A button for each plugin UI's
settingswhilepagesis off. - Undo and Redo when
runner.offers.undois on, greyed out with nothing to undo or redo. - Settings (
ui.settings) and Title screen (ui.titlePage) withpageson.
Settings and Title screen switch to those pages. Saves, Backlog and Mods each open a dialog with a SavesMenu, a Backlog or a ModManager, and loading a save closes it. With keys on, Escape opens the same buttons in a dialog headed ui.menu. The options of createRunner decide which buttons the player sees.
Parts: menu (with data-menu), menu-button, dialog, dialog-overlay, dialog-title and dialog-close.
SavesMenu
SavesMenu renders the save and load screen over the runner's saves, and nothing when it has none. Its props are in SavesMenu.
Save in a new slot (ui.saveNew) writes the next numbered slot, and Import a save file (ui.importSave) plays on from a .json file. Each slot, newest first, has Load, Save, Export and Delete, and export downloads <game>-<slot>.json. A save that can't be read is listed last with its reason and a Delete button. Saving over a slot gives it the default name, meta.when or Turn N.
While the game's saveable refuses, the Save buttons are greyed out with the reason from view.saving, and the menu carries data-saving="blocked". A save made with mods or plugins this game lacks still loads, with a line naming them. onLoaded runs after a load or an import.
Parts: saves (with data-saves), saves-actions, save-slot (with data-save-slot), save-name, save-details, saves-message, saves-blocked, saves-empty, file-button and button.
useSaves
useSaves returns the save slots from the running game and the functions SavesMenu uses on them, for a save screen of your own. The fields are in SavesState.
available is false when the runner has no saves, and then nothing does anything. Each function resolves to whether it worked, and message says why the last one failed. While saving.allowed is false, save and overwrite are refused with the reason. broken lists the saves that can't be read, which only remove takes.
import { useSaves } from '@ifloom/react'
function QuickSave() {
const saves = useSaves()
if (!saves.available || !saves.saving.visible) return null
return (
<button disabled={!saves.saving.allowed} title={saves.saving.reason ?? undefined} onClick={() => void saves.save('Before the park')}>
Quick save
</button>
)
}Render a save and load screen renders one in any framework.
Backlog
Backlog renders the runner's backlog, oldest first, in a ScrollArea. Its props are in Backlog. Each entry shows its title and its beats as Beats, then You chose: … (ui.chose) when the player made a choice there. It shows ui.backlogEmpty while empty, which it always is unless the runner was made with backlog.
Parts: backlog, backlog-entry (with data-backlog), backlog-title, backlog-choice and backlog-empty.
useBacklog
useBacklog returns the backlog's entries, oldest first, from the runner's snapshot. Its signature is in useBacklog. It's empty unless the runner was made with backlog.
import { useBacklog } from '@ifloom/react'
function LastChoice() {
const last = useBacklog().findLast((entry) => entry.chose)
return last ? <p className="text-sm">Last time: {last.chose}</p> : null
}ModManager
ModManager renders the mods screen over the provider's ModsOption, and nothing without one. Its props are in ModManager.
Add a mod file (ui.addMod) reads a .json file through the store's add, and shows the store's reason when it can't. Each mod, in name order, shows its name, version and description, an On/Off button with aria-pressed, a Delete button, and its problems. After a change, Restart with these mods (ui.applyMods) calls onChange. GameMenu and the SettingsPage open it.
A change takes effect only after the restart, since the running game was built with the mods as they were. The problems shown are the ones from start-up, so a new mod shows none until then. Let players add mods sets it up.
Parts: mods (with data-mods), mod (with data-mod), mod-name, mod-version, mod-state, mod-text, mod-problem, mods-message, mods-empty, mods-restart, mods-changed, file-button and button.
useMods
useMods returns the mods from the provider's mods and the functions ModManager uses on them. The fields are in ModsState. available is false without mods, changed says whether a restart would differ, and message says why the last change failed.
Pages
With pages on, the game opens on its splash cards and then a title screen, and the shell with the story is the game page. The other pages are splash, gate, title, load, settings and credits, any a plugin UI adds, such as achievements, and any in PagesOptions.pages. Add a title screen and Add pages around the game set them up.
PagesOptions
PagesOptions is the settings pages takes on mountGame and GameShell, and pages: true is {}. Every field is in PagesOptions.
| Field | Meaning |
|---|---|
gate | The GateOptions of a notice shown before the title screen, rendered by GatePage. |
splash | The SplashOptions of the cards shown as the game opens, rendered by SplashPage. Left out, the game shows the poweredByIFLoom card alone, and false shows none. |
pages | The game's own pages by id, each a PageDef. Each gets a title-screen button labelled label unless showOnTitle is false, and its component renders as the whole page. One with a plugin UI's page id replaces it. |
import { mountGame, usePage } from '@ifloom/react'
import module from './game.ts'
function Postcards() {
const { back } = usePage()
return (
<section>
<h1>Postcards from the seaside</h1>
<button onClick={back}>Back</button>
</section>
)
}
mountGame(module.build(), {
pages: {
subtitle: 'A new flat, a new town',
pages: { postcards: { label: 'Postcards', component: Postcards } },
},
})usePage
usePage returns the Page on show and the functions that move between pages. The fields are in PageState.
go(page) shows a page: splash, title, game and gate start afresh, and any other goes on top. endSplash() ends the splash cards and shows the gate or the title screen. back() returns to the page under this one, or the title screen. enabled is false without pages, and then page is always 'game'. go('game') only switches page, so start a game with runner.newGame or a load first.
TitlePage
TitlePage renders the game's title, the subtitle and art, and a column of buttons each carrying data-title-button. Its props are in TitlePage. It shows these buttons:
- Continue (
ui.continue) loads the newest save, when there is one. - New game (
ui.newGame) callsrunner.newGame(). - New Game+ (
ui.newGamePlus) when the game declarescarryOverand the profile'score:finishedis set. - Load (
ui.load) when the runner hassaves. - Settings (
ui.settings) when the game has a setting, a plugin UI's settings or mods. - A button for each added page whose
showOnTitleisn'tfalse. - Credits (
ui.credits) when the game'screditsname someone.
The first button is the main one. Parts: title-page (with data-page="title"), title-art, title-name, title-subtitle, title-buttons and title-button.
SettingsPage
SettingsPage renders view.settings: a checkbox for a toggle, radio buttons for a choice, and a slider for a range. Its props are in SettingsPage.
Each change goes through runner.setSetting, which writes a ui setting to the profile and sends a play setting as a setting command. A refused change shows its reason. The plugin UIs' settings follow the list, then, with mods, a Mods section with the ModManager. It says ui.noSettings when there's nothing to show. Add a settings page declares the settings.
Parts: settings-page, page-heading, settings, setting (with data-setting and data-affects), setting-label, setting-control, setting-value, settings-empty, settings-message, settings-mods, mods-title, mods-hint and page-back.
LoadPage
LoadPage renders every save, newest first, with a Load button each, a Delete button for one that can't be read, and an import button. Its props are in LoadPage. Loading goes to the game. Unlike SavesMenu, it can't save, since there may be no game in play.
Parts: load-page, page-heading, saves, save-slot, save-name, save-details, saves-message, saves-empty, file-button, button and page-back.
CreditsPage
CreditsPage renders the game's credits from creditsOf, with a Back button. Its props are in CreditsPage. Each group has its title and description, and each credit shows its picture, its name, its role, then its description and licence. A credit with an href shows its name as a link, which opens in a new tab.
Parts: credits-page, page-heading, credits, credit-group (with data-credit-group), credit-group-title, credit-group-description, credit-list, credit, credit-art, credit-name, credit-link, credit-role, credit-meta and page-back.
GatePage
GatePage renders the notice from PagesOptions.gate that the player confirms before the title screen, such as a content note. Its props are in GatePage. Every word on it is the game's, and the text splits into paragraphs on blank lines.
import { mountGame } from '@ifloom/react'
import module from './game.ts'
mountGame(module.build(), {
pages: {
gate: {
title: 'Before you start',
text: 'This story mentions a house fire.\n\nIt happens off the page.',
confirm: 'Carry on',
decline: { label: 'Not today', href: 'https://example.com/' },
},
},
})Confirming stores { confirmedAt } in the profile's ui:gate and goes to the title screen, so the gate shows once per device. Declining follows href, or does nothing without one. Without a profile the gate shows every time, and mountGame always has one.
Parts: gate-page, gate-title, gate-text, gate-buttons, gate-confirm and gate-decline.
SplashPage
SplashPage renders the cards from PagesOptions.splash one after another as the game opens, before the gate and the title screen. Its props are in SplashPage. Each card is a SplashCard that shows its art, title and text, or its own component. Add splash cards sets them up.
| Field | Meaning |
|---|---|
ms | How long the card holds between coming in and going out, 2000 milliseconds if left out. |
transition | A TransitionName, or { in, out, ms }, the same as a scene's. A fade of 600 milliseconds each way if left out. |
skippable | On SplashOptions, false to make the player watch every card. Otherwise a click, Enter or Space skips one card, and Escape or the Skip button (ui.skipSplash) skips them all. |
The cards play on every launch. With reduced motion, from the player's system or the motion option, each card holds for its ms with no transitions. After the last card, SplashPage calls usePage().endSplash(), which shows the gate or the title screen.
import { mountGame, poweredByIFLoom } from '@ifloom/react'
import module from './game.ts'
mountGame(module.build(), {
pages: {
splash: {
cards: [
{ id: 'studio', art: 'art/studio-logo.png', title: 'Harbour Games', ms: 1500 },
poweredByIFLoom(),
{ id: 'logo', art: 'art/logo.png', transition: { in: 'zoom', out: 'fade', ms: 800 } },
],
},
},
})Parts: splash-page (with data-page="splash"), splash-card (with data-splash-card and the card's id), splash-art, splash-title, splash-text, splash-link and splash-skip.
poweredByIFLoom
poweredByIFLoom returns the "Powered by IFLoom" card. Its signature is in poweredByIFLoom. The IFLoom mark pops in with a glow and a shine, then ui.poweredBy, the IFLoom name and a Visit ifloom.dev link (ui.visitIfloom) rise in turn. The link opens the site in a new tab without skipping the card. It carries UTM parameters so the site can count visits from splash cards: utm_source=ifloom-game, utm_medium=splash, utm_campaign=powered-by-ifloom, and the game's id as utm_content. Nothing about the player is sent. The card holds for 3000 milliseconds, and with reduced motion it shows everything at once. A game with no splash option shows this card alone. A game that lists its own cards puts it among them where it should show, or leaves it out. Its argument changes the card's ms or transition, such as poweredByIFLoom({ ms: 1000 }).
useSetting
useSetting returns a setting's value from the running game, as the snapshot's settings holds it. Its signature is in useSetting. A ui setting's value comes from the profile and re-renders when it changes. A stored value that no longer suits the setting gives its default, and a setting the game doesn't declare gives undefined.
import { useSetting } from '@ifloom/react'
function Story({ children }: { children: React.ReactNode }) {
const size = useSetting('textSize')
return <div className={size === 'large' ? 'text-lg' : undefined}>{children}</div>
}TextSize
TextSize copies the setting named in the settings hint's textSize to data-text-size on <html>, and renders nothing. Its signature is in TextSize. GameShell has one, so you need it only under a GameProvider of your own.
useProfile
useProfile returns what the profile holds in a namespace, kept current as it's written. Its signature is in useProfile. It's undefined before the first read and without a profile. The title screen reads useProfile('core:finished') to offer New Game+.
const settings = useProfile<Record<string, unknown>>('core:settings')Around the story
Notices
Notices renders the first limit (3 if left out) of the view's unseen notices, each a Notice, in a list with role="status". Its props are in Notices. Under 48rem it shows the newest only, with a notices-more button (ui.noticesMore) for the rest. The default layout puts it in the Overlay.
import { Notices } from '@ifloom/react'
<Notices limit={1} className="fixed top-4 left-1/2 w-96 -translate-x-1/2" />Parts: notices and notices-more.
Notice
Notice renders one notice: its picture, title and text, and a close button (ui.dismiss) that sends dismiss. Its props are in Notice. Show a notice sends one.
import type { Components } from '@ifloom/react'
const components: Components = {
Notice: ({ notice, Default }) => (notice.image ? <Default notice={notice} /> : <p className="text-sm italic">{notice.title}</p>),
}Parts: notice (with data-notice), notice-image, notice-title, notice-text and notice-dismiss.
NoticeStrip
NoticeStrip renders a row of counts for what's waiting, each a button that opens where it is, in a <nav> labelled ui.unread. Its props are in NoticeStrip.
Notices (ui.notices) counts the unseen notices and opens them in a dialog with Mark all seen (ui.allSeen). The plugin UIs' strip parts follow, such as the devices plugin's DeviceStrip. It hides while nothing in it renders. The default layout leaves it out.
<Story>
<NoticeStrip />
<Scene />
</Story>Parts: notice-strip, notice-strip-item (with data-strip, notices or the device and app ids) and badge.
Dice, timers and minigames
DiceRoll
DiceRoll renders one Roll from view.rolls: the dice, a face for each die, what was added, and once they settle, the total and with a target, its outcome. Its props are in DiceRollProps.
With animate (the default), the faces tumble for a second before they settle; the roll was made already. With motion off, it shows settled. A status region reads the result once the dice settle, worded by ui.diceRolled. Scene renders one above a block with a dice hint. Roll dice for a check shows one.
import { DiceRoll, useGame } from '@ifloom/react'
function LastRolls() {
const { view } = useGame()
return view.rolls.map((roll, at) => <DiceRoll key={at} roll={roll} animate={false} />)
}Parts: dice (with data-roll, data-state, data-passed and data-critical), dice-label, dice-faces, dice-face (with data-rolling, data-high and data-low), dice-plus, dice-total, dice-outcome and dice-critical.
DiceOverlay
DiceOverlay renders rolls the story doesn't name for a moment near the top of the window, a DiceRoll each. Its props are in DiceOverlay. It goes about two and a half seconds after the dice settle, or on its close button (ui.diceDismiss). Scene renders one for the fresh rolls no block's dice hint names, and a replacement of () => null shows none.
Parts: dice-overlay and dice-dismiss.
Countdown
Countdown renders one running timer by id: its label, a bar that empties, and the seconds left (ui.timerLeft). Its props are in CountdownProps.
The bar is a progressbar from 0 to the timer's total, labelled with its label. With a quarter or less left, the parts carry data-urgent. With motion off, only the seconds show. It renders nothing while the timer isn't running. A block with a timer hint gets one under it, and a replacement changes that one too. Add a countdown starts a timer.
import { Countdown, Game, Scene, Sidebar, Story } from '@ifloom/react'
export function Layout() {
return (
<Game>
<Sidebar>
<Countdown timer="flat.ring" label={false} />
</Sidebar>
<Story>
<Scene />
</Story>
</Game>
)
}Parts: timer (with data-timer and data-urgent), timer-label, timer-bar and timer-left.
Timers
Timers renders a Countdown for every running timer, in the order they started, in a timers part. Its props are in Timers. The default layout leaves it out. GameProvider runs the clock that ticks the timers, so a timer runs out on time whether or not anything renders it.
useTimer and useTimers
useTimers returns view.timers, and useTimer one TimerView from it by id, or null while that timer isn't running. Their signatures are in useTimer and useTimers.
import { useTimer } from '@ifloom/react'
function RingingPhone() {
const ringing = useTimer('flat.ring')
if (!ringing) return null
return <span className="phone" style={{ opacity: 0.4 + (0.6 * ringing.left) / ringing.total }}>☎</span>
}MinigameCard
MinigameCard renders the running minigame, view.minigame: its title, the state's label in a live region, a bar for the state's timer, and a button per live input. Its props are in MinigameCard.
Each button sends { type: 'minigame', input }. The card maps the keyboard to the inputs: the keys the minigame lists, else the arrows, the space bar or an input's own letter. These keys work whether keys is on or not, and a held key doesn't repeat. A component in panels under the minigame's id replaces it for that minigame only. Build a minigame writes one.
Parts: minigame (with data-minigame and data-state), minigame-title, minigame-state, minigame-timer, minigame-inputs and minigame-input (with data-input).
useMinigame
useMinigame returns the running minigame, or null, and send, which presses one of its inputs and returns the runner's result. The fields are in MinigameControls. With keys: true, it maps the keyboard as MinigameCard does.
Calling it runs the game's clock, one per runner, which sends a tick about every 100 ms with the real time since the last. The clock pauses while the page is hidden, so a minigame waits for a player who looked away. Scene calls it while a minigame runs, so a root that leaves out Scene calls it itself.
import { useMinigame } from '@ifloom/react'
function ArrowPad() {
const { minigame, send } = useMinigame({ keys: true })
if (!minigame) return null
return (
<div className="grid grid-cols-3 gap-2">
{minigame.inputs.map((input) => (
<button key={input.id} onClick={() => send(input.id)}>{input.label}</button>
))}
</div>
)
}Panels
A panel is a named piece of UI that content opens over the story. The React UI renders its own, and each plugin UI the game lists brings its own, such as shopUi's shop. Open a panel opens one.
PanelHost
PanelHost renders the open panel, view.panel, in a PartDialog, and closing the dialog sends closePanel. Its signature is in PanelHost.
It renders the game's own panels component of that name, else a listed plugin UI's, else a built-in one, with the panel's with as data. A scene's own panel renders in the scene instead. The dialog's title is with.title, else the plugin UI's title, else the panel's name. A name nothing renders shows nothing, though the panel stays open in the state.
import { mountGame } from '@ifloom/react'
import module from './game.ts'
function Noticeboard({ data }: { data: unknown }) {
return <p>Lost: one grey cat, answers to Biscuit.</p>
}
mountGame(module.build(), { panels: { noticeboard: Noticeboard } })Parts: dialog, dialog-overlay, dialog-title and dialog-close, with the panel in a div carrying data-panel.
Built-in panels
The built-in panels are the ones PanelHost renders by name for what the engine keeps. A plugin UI's or the game's panel of the same name replaces one.
| Name | Meaning |
|---|---|
stats | The StatList. |
The first-party plugins' panels are on their pages: inventory, shop, jobs, wardrobe, quests, people, achievements and statuses.
PartDialog
PartDialog renders a Dialog with the UI's dialog parts, as the menu, PanelHost and the plugin UIs do, from @ifloom/react/kit. Its props are in PartDialog. It's open while open is true, titled title, and calls onClose when the player closes it.
import { useState } from 'react'
import { Button, PartDialog } from '@ifloom/react/kit'
function Map() {
const [open, setOpen] = useState(false)
return (
<>
<Button variant="outline" onClick={() => setOpen(true)}>Town map</Button>
<PartDialog open={open} onClose={() => setOpen(false)} title="Small Town">
<img src="art/map.png" alt="" />
</PartDialog>
</>
)
}Parts: dialog, dialog-overlay, dialog-title and dialog-close.
Sound
useAudio
useAudio plays the game's sound with the audio player while the component is mounted, and returns the player, or null until it starts. Its signature is in useAudio.
Inside a GameProvider it uses that runner, and outside one it takes runner. The other options go to startAudio. GameShell and mountGame start a player themselves, so you need it only under a GameProvider of your own, and one beside theirs takes over from it. Add music and sound starts one.
import { GameProvider, useAudio } from '@ifloom/react'
import { MyPage } from './my-page.tsx'
function Sound() {
useAudio({ log: console.debug })
return null
}
export const App = () => (
<GameProvider runner={runner}>
<Sound />
<MyPage />
</GameProvider>
)Words
UiStringKey, Words and Say
UiStringKey is a key of the UI's own English words, without the ui. prefix, and The React UI lists them. Their types are in UiStringKey, Words and Say. A Words is a table of words by key, such as a plugin UI's SHOP_WORDS. A Say is the function that words a key with its {name} values filled in.
useWords
useWords returns the game's word for a key from the running game: game.strings['ui.' + key], or the English. Its signature is in useWords. It fills each {name} from vars, and says a key nothing has as written. Given a plugin UI's table, it says that table's keys too, typed. A plugin's own UI gets its words from usePlugin instead.
import { useWords } from '@ifloom/react'
import { QUESTS_WORDS } from '@ifloom/plugin-quests/react'
function JournalHeading() {
const words = useWords(QUESTS_WORDS)
return <h3>{words('quests')}</h3>
}Last updated on