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:
@canvasengine/presets) is supported:
effect can also be the id of a custom weather. The catalog
is exported by @rpgjs/common without importing the renderer, so an editor or a
server can list it:
Presets And Params
A weather state can name only apreset; effect is then the one of the preset.
params override the values of the preset. All params are forwarded to
CanvasEngine’s <Weather> as they are, so a parameter added by a newer
CanvasEngine works without a new RPGJS release (rayFan, rayLength, rayColor,
fogOpacity, colors, particleSize, haze, topDown, …).
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 | nullmap.setWeather(next: WeatherState | null, options?: { sync?: boolean })map.patchWeather(patch: Partial<WeatherState>, options?: { sync?: boolean })map.clearWeather(options?: { sync?: boolean })
patchWeather() merges params. A patch that names a new preset (or a new effect)
replaces the previous one, so the old effect never overrides the effect of the new preset.
When sync is not false, the weather is broadcast to players in the map.
A synchronized null is authoritative: clearWeather() removes an initial
weather effect declared in the map data in both standalone and MMORPG modes.
Runtime API (Client)
RpgClientMap exposes:
map.weatherState(server-synchronized state)map.localWeatherOverride(client-only override)map.weather(computed: local override first, then server state, then map-data fallback before the first synchronization)map.getWeather()map.setLocalWeather(next)map.clearLocalWeather()
Custom Weather
Register a weather component by id in a client module, likecomponentAnimations:
effect matches a registered id, the scene renders that component instead of
<Weather>, in the same layer (params.zIndex, 1000 by default). It receives
effect, params, transitionMs, durationMs, startedAt and seed as props.
Every client renders it, including players who join later. A registered id replaces
a built-in effect of the same name, so a game can restyle rain.
Rendering With CanvasEngine Preset
The scene already renders the weather state with CanvasEngine. To draw it yourself elsewhere, feed@canvasengine/presets with it:
engine.sceneMap.weather() / engine.sceneMap.getWeather().