Render the calendar, locations and people
Render the time of day, the location the player is at with its exits, and the people here in a UI of your own.
Render the world around the story: the time of day from the calendar, the location the player is at from places, and the people from the cast. Set up the runner first, as Start your own UI shows. In the React tabs, each plugin's UI comes from its /react subpath and goes in mountGame's plugins, as Show plugins in the React UI explains.
Render the clock
view.plugins.calendar holds the time as a CalendarView, with the day, the weekday, the period and the whole line in label, which is also in view.when. The React UI's CalendarClock, from calendarUi, renders in place of the React UI's own Clock, in the side column and in the top bar on a phone.
import type { RunnerSnapshot } from '@ifloom/engine'
// add, as in the vanilla template's src/main.ts.
import { add } from './runner.ts'
/** Where the game is in time, with the calendar's pieces on it for a stylesheet, and a nudge at curfew. */
export function drawCalendar(parent: HTMLElement, { view }: RunnerSnapshot): void {
const calendar = view.plugins.calendar
if (!calendar) return
const clock = add(parent, 'p', calendar.label, 'clock')
Object.assign(clock.dataset, { day: String(calendar.day), weekday: calendar.weekday, period: calendar.period })
// The last period of the day, with the curfew binding: time for bed.
if (calendar.curfew) add(parent, 'p', 'It’s late. Time for bed.', 'curfew')
}
Put the day, the weekday and the period on the clock's element as data attributes, so a stylesheet can colour the night. curfew is true in the last period of the day while the curfew binds, which is the moment to send the player to bed. CalendarClock sets data-day, data-weekday, data-period and data-curfew the same way, and useCalendar gives you the calendar's view in a React component of your own.
Render the location and its exits
view.plugins.places holds where the player is as a PlacesView, with the location, its exits and the things lying there. The React UI's LocationCard and Exits, from placesUi, go in the story before the room's actions.
import type { RunnerSnapshot } from '@ifloom/engine'
// add and drawChoices, as in the vanilla template's src/main.ts.
import { add, drawChoices } from './runner.ts'
/** Where you are: the place's name and picture, the ways out, and what lies here to pick up. */
export function drawPlace(parent: HTMLElement, { view }: RunnerSnapshot): void {
const places = view.plugins.places
if (!places?.location) return
const { location } = places
add(parent, 'h3', location.name)
if (location.image) Object.assign(add(parent, 'img'), { src: location.image, alt: '' })
// Each exit is a button like any other, greyed out with why it can't be taken.
if (places.exits.length) drawChoices(add(parent, 'nav', '', 'exits'), places.exits)
for (const thing of places.things) {
const row = add(parent, 'div', '', 'lying')
add(row, 'span', thing.count > 1 ? `${thing.name} ×${thing.count}` : thing.name)
drawChoices(row, [thing.pickUp])
}
}
Each exit and each thing's pickUp is a ready button, a RenderedChoice, so render it as any other button and send its command. An exit the player can't take has its reason in disabled, and an exit a lock hides isn't in the view at all. The location's name and words are also the room scene in view.scene, and its own actions are in view.actions, which Render the scene and its choices renders.
location is null while the player is nowhere, so render nothing then. A location with a picture has it in location.picture, which Render pictures and play sound renders, and the plugin leaves its hotspots out while a scene is open. usePlaces gives the view with go and pickUp to a React component of your own.
Render the people
view.plugins.cast holds the people as a CastView, with who is here in present and everyone in people, each a PersonView. The React UI's castUi puts PeopleHere after the room's actions, and a People section in the side column that opens Relationships in a dialog.
import type { RunnerSnapshot } from '@ifloom/engine'
// add and drawChoices, as in the vanilla template's src/main.ts.
import { add, drawChoices } from './runner.ts'
/** Who's here, each with their face and their Talk button, then everyone you've met. */
export function drawPeople(parent: HTMLElement, { view }: RunnerSnapshot): void {
const cast = view.plugins.cast
if (!cast) return
for (const person of cast.present) {
const card = add(parent, 'div', '', 'person')
card.dataset.person = person.ref
if (person.portrait) Object.assign(add(card, 'img'), { src: person.portrait, alt: '' })
add(card, 'strong', person.name)
if (person.description) add(card, 'span', person.description)
drawChoices(card, person.actions)
}
const met = cast.people.filter((person) => person.met)
if (!met.length) return
add(parent, 'h3', 'People you know')
const list = add(parent, 'ul')
for (const person of met) add(list, 'li', person.here ? `${person.fullName} (here)` : person.fullName)
}
Each person has a name, a portrait, a description and their buttons in actions, such as Talk. met says whether the player has met them, and here whether they're at the player's location. present is empty while a scene is open. A character is an entity of the cast's kind, so the stats the player can see on them, such as friendship, are on their entry in view.entities while the game lists the kind. usePeople gives the cast's view to a React component of your own.
For more on what these sections render, see:
Last updated on
Render saves, settings and the backlog
Render a save and load screen, a settings screen and the backlog with Undo in a UI of your own, in plain JS, React or Vue.
Render quests, achievements and statuses
Render a quest log, an achievements page and the statuses in play in a UI of your own, in plain JS, React or Vue.