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

@ifloom/plugin-calendar

Every export of @ifloom/plugin-calendar and its /react subpath: its signature and its fields.

Generated from the source of @ifloom/plugin-calendar and @ifloom/plugin-calendar/react and its TSDoc by npm run api-docs. Each export links to the page that explains it, where one does.

@ifloom/plugin-calendar

calendar

Function. Explained in Calendar.

Returns the calendar plugin, for the game's plugins. List it before other plugins, so their hooks see the new day when a turn ends.

Its helpers write its calls, such as calendar.sleep() and calendar.day({ gte: 3 }).

import { calendar } from '@ifloom/plugin-calendar'
function calendar(options?: CalendarOptions): DefinedPlugin<CalendarState, CalendarView>

Uses: CalendarOptions, DefinedPlugin, CalendarState, CalendarView.

HelperSignatureDescription
calendar.sleep(): CommandRefReturns the calendar/sleep command, which passes time to the waking period of the next day.
calendar.pass(n?: number): EffectRefReturns the calendar/pass effect, which moves the clock on n periods (1 if left out).
calendar.period(...ids: string[]): ConditionReturns the calendar/period condition, which holds in any of the periods named.
calendar.weekday(...days: number[]): ConditionReturns the calendar/weekday condition, which holds on any of the days of the week named, counting from 0.
calendar.weekend(): ConditionReturns the calendar/weekend condition, which holds on a day in CalendarOptions.weekend.
calendar.day(range: Range): ConditionReturns the calendar/day condition, which holds while the day, counting from 0, is in the range.

CalendarOptions

Type. Explained in Calendar.

Settings for calendar(). Every field is optional and has the default its comment gives.

import type { CalendarOptions } from '@ifloom/plugin-calendar'
type CalendarOptions = {
  periods?: (string | PeriodDef)[]
  week?: number
  weekend?: number[]
  turn?: 'period' | 'day' | 'week' | false
  start?: { day?: number; period?: string }
  sleep?: { from?: string[]; wake?: string } | false
  curfew?: Condition | false
}
FieldTypeOptionalDefaultDescription
periods(string | PeriodDef)[]yesThe periods of a day, in order. Morning, afternoon, evening, night and late if left out.
weeknumberyesThe number of days in a week. 7 if left out.
weekendnumber[]yesThe days of the week that are the weekend, counting from 0. The last two days of the week if left out.
turn'period' | 'day' | 'week' | falseyesThe length of a turn, one 'period', one 'day' or one 'week'. 'day' if left out. Passing time ends a turn at each boundary it crosses, and a turn ended any other way moves the clock to the start of the next. With false, the clock and the turn run independently.
start{ day?: number; period?: string }yesThe day and period a new game starts at. Day 0 and the first period if left out.
sleep{ from?: string[]; wake?: string } | falseyesThe settings of the calendar/sleep command. false leaves the command out. from lists the periods the player can sleep from, the last three if left out. wake is the period the player wakes in the next day, the first if left out.
curfewCondition | falseyesThe curfew's condition. While it holds, the calendar warns against passing time over the end of the day, and the engine refuses that command so the player goes to bed instead. The curfew always binds if left out, and never with false.

CalendarState

Type. Explained in Calendar.

The clock a save keeps for the calendar. The plugin reads the periods and the week from its options, so the save keeps only the day and period.

import type { CalendarState } from '@ifloom/plugin-calendar'
type CalendarState = {
  day: number
  period: string
}
FieldTypeOptionalDefaultDescription
daynumberThe day, counting from 0.
periodstringThe id of the period the clock is in.

CalendarView

Type. Explained in Calendar.

The calendar as the player sees it, in view.plugins.calendar. Its label is the line a UI's clock shows.

import type { CalendarView } from '@ifloom/plugin-calendar'
type CalendarView = {
  day: number
  weekday: string
  weekdayIndex: number
  period: string
  periodLabel: string
  label: string
  curfew: boolean
}
FieldTypeOptionalDefaultDescription
daynumberThe day, counting from 1 as the player does.
weekdaystringThe weekday's name, such as 'Wednesday'. In a week of other than 7 days, it reads "Day 3 of the week".
weekdayIndexnumberThe weekday's position in the week, counting from 0.
periodstringThe period's id, such as 'morning'.
periodLabelstringThe period's name as the player reads it, such as 'Morning'.
labelstringThe calendar's whole line, such as "Day 3 · Wednesday morning", from the calendar/label string.
curfewbooleanTrue in the day's last period, with no scene open, while the curfew binds. A UI can offer bed then.

PeriodDef

Type. Explained in Calendar.

A period of the day, one entry of CalendarOptions.periods. A bare string in periods is a period with only an id.

import type { PeriodDef } from '@ifloom/plugin-calendar'
type PeriodDef = {
  id: string
  label?: string
}
FieldTypeOptionalDefaultDescription
idstringThe period's id, such as 'morning'.
labelstringyesThe period's name as the player reads it. The id if left out.

@ifloom/plugin-calendar/react

CalendarClock

Const. Explained in Calendar.

Renders the game's time, such as "Day 3 · Wednesday morning", from view.when. A preset styles its clock part.

It carries data-day, data-weekday and data-period attributes, and data-curfew while the curfew binds. calendarUi renders it in place of the core Clock.

import { CalendarClock } from '@ifloom/plugin-calendar/react'
const CalendarClock: ComponentType<{ className?: string; }>

calendarUi

Const. Explained in Calendar.

The calendar plugin's React UI, for plugins on mountGame or GameProvider. It replaces the core Clock with CalendarClock, in the sidebar and in the top bar on a phone.

import { calendarUi } from '@ifloom/plugin-calendar/react'
const calendarUi: PluginUi

Uses: PluginUi.

useCalendar

Function. Explained in Calendar.

Returns the calendar plugin's view from the running game, or null in a game without the plugin. It re-renders when the view changes.

The view has the day, the weekday, the period and the curfew. CalendarClock renders from it.

import { useCalendar } from '@ifloom/plugin-calendar/react'
function useCalendar(): CalendarView | null

Uses: CalendarView.

Last updated on

On this page