Skip to main content

Calendar module

@rpgjs/calendar is an optional RPGJS v5 module. It keeps the calendar of the world (the date of today and the events on it) and shows it in a window. It has no clock: your game moves the date, for example when the player sleeps. A synchronized time system can drive it later without changing the API below. The server owns the data. The client only displays what the server sends, and asks it for another month.

Register it

The calendar

Events

  • title and description are shown as they are, or translated when they start with rpg..
  • icon is an image URL or a path (/icons/market.png), or a short glyph (⚑). An event takes the icon and the color of its category when it has none.
  • A multi-day event is listed on each of its days.
  • An invalid event throws a readable error when it is added.
Add and remove events at runtime with calendar.addEvent() and calendar.removeEvent(id).

Sources

A source provides events for a range of dates. Use it for what the game already knows: quests, birthdays of NPCs, the weather of the day.
  • world sources (the default) are shown to everybody. player sources are only asked when a player opens the calendar, so one player’s events never reach another.
  • list() is called once each time the calendar is opened or another month is asked. It gets a range of about a year (the month and the events to come), so a source that reads a database should filter by range.
  • A source that throws, or returns an invalid event, is logged and skipped: the calendar still opens.

Move today and react

Hooks only see the events of the world. A hook that throws is logged and the others still run.

Open the window

The player moves between months with the arrows, selects a day with the pointer or the movement keys (left and right move by a day, up and down by a week), and closes the window with the close button or escape. The list on the right shows the events from the selected day on. Add import "@rpgjs/ui-css/index.css" to get the styles. The catalogue of the GUI has the calendar in Compositions / Calendar. Replace the window with provideCalendar({ component }); it receives the CalendarView as data.

Texts

Translate with rpg.calendar.* keys (English and French are included): title, subtitle, events, weekday.mon…, season.spring…, month.1… A month is named by its rpg.calendar.month.N key when you give one. Otherwise it shows its season, with its place when a season has several months (Spring 2).