Skip to main content

Time Manager

Use withTimeManager() to add synchronized game time without adding methods to RpgMap. The server owns the canonical time. The client receives a map snapshot and infers the displayed time locally from elapsedMinutes, scale, paused, and serverTimestamp.

Register the Module

You can use the same module object on both sides:
For a client-only declaration, this also works:

Server API

Use TimeManager from server hooks, events, or services:
Read the derived state:

Client API

Use ClientTimeManager for display logic:
The client does not write time. It projects the current display value from the last synchronized map snapshot.

Snapshot

The synchronized map field is internal and namespaced:
Game code should use TimeManager and ClientTimeManager instead of reading __rpgjsTime directly.

Lighting

When lighting.enabled is true, the server can apply map lighting from time phases:
If lighting is omitted or disabled, the time manager does not modify map lighting.

Weather Ambiences

When weather.enabled is true, the server can roll weather ambiences per map. Each ambience has a weight and a game-time duration. When the duration expires, the server rolls the next ambience and applies it with the existing map weather API.
maps[mapId] overrides the default weather table for that map. A weather: null ambience clears the map weather. If weather is omitted, disabled, or no table exists for a map, the time manager does not modify that map’s weather. Weather remains server-owned. Clients receive the regular weatherState map update and should read engine.sceneMap.weather() or engine.sceneMap.getWeather() for rendering.

Environment Hooks

Use hooks on withTimeManager() when the environment should drive gameplay rules from the plugin itself:
onBeforeWeatherChange() can return false to cancel the roll, or another { key, ambience } candidate to replace it. Initial map registration is silent: hooks run only after an actual time, lighting, or weather transition. Transition payloads include the current map so plugin hooks can update synchronized map state or trigger map-local systems. Events can react locally by declaring matching methods:
Global event hooks work too:
This keeps the environment logic centralized in the time plugin while still letting map events behave like Stardew Valley objects: crops grow on day changes, lamps react to lighting phases, and NPCs or interactables react to weather changes.