Skip to main content

Weather

Manage map weather from the server while keeping a client-side override for local effects.

Shared Types

Weather types are exported by @rpgjs/common:
Supported effects:
  • rain
  • snow
  • fog
  • cloud

Initial Map Weather

Set initial weather in @MapData() or in a map entry inside your server module:

Runtime API (Server)

RpgMap exposes:
  • map.getWeather(): WeatherState | null
  • map.setWeather(next: WeatherState | null, options?: { sync?: boolean })
  • map.patchWeather(patch: Partial<WeatherState>, options?: { sync?: boolean })
  • map.clearWeather(options?: { sync?: boolean })
Example:
When sync is not false, the weather is broadcast to players in the map.

Runtime API (Client)

RpgClientMap exposes:
  • map.weatherState (server-synchronized state)
  • map.localWeatherOverride (client-only override)
  • map.weather (computed: local override first, then server state)
  • map.getWeather()
  • map.setLocalWeather(next)
  • map.clearLocalWeather()
Example:

Rendering With CanvasEngine Preset

Use your map weather state to feed @canvasengine/presets:
You can derive those values from engine.sceneMap.weather() / engine.sceneMap.getWeather().