RpgMap
Reference for theRpgMap class.
Members
- addInDatabase
- applySyncToClient
- broadcast
- clear
- clearWeather
- createDynamicEvent
- createDynamicWorldMaps
- createShape
- damageFormulas
- database
- dataIsReady$
- deleteWorldMaps
- events
- getEvent
- getEventBy
- getEvents
- getEventsBy
- getPlayer
- getPlayers
- getShape
- getShapes
- getWeather
- getWorldMaps
- globalConfig
- guiExit
- guiInteraction
- hooks
- interceptorPacket
- maps
- off
- on
- onAction
- onInput
- onJoin
- onLeave
- patchWeather
- players
- playSound
- processInput
- removeEvent
- removeInDatabase
- removeShape
- setAutoTick
- setSync
- setWeather
- shakeMap
- showAnimation
- showComponentAnimation
- sounds
- stopSound
- updateMap
- updateWorld
- updateWorldMaps
addInDatabase
Add data to the map’s database This method delegates to BaseRoom’s implementation to avoid code duplication.- Source:
packages/server/src/rooms/map.ts - Kind:
method - Defined in:
RpgMap
Signature
Parameters
id:stringdata:anyoptions?:{ force?: boolean }
Returns
true if data was added, false if ignored (ID already exists)Examples
applySyncToClient
Apply sync to the client This method applies sync to the client by calling the$applySync() method.
- Source:
packages/server/src/rooms/map.ts - Kind:
method - Defined in:
RpgMap
Signature
Examples
broadcast
Broadcast a custom websocket event to all clients connected to this map. This is a convenience wrapper around$broadcast({ type, value }).
On the client side, receive the event by injecting WebSocketToken
and subscribing with socket.on(type, cb).
- Source:
packages/server/src/rooms/map.ts - Kind:
method - Defined in:
RpgMap
Signature
Parameters
type:stringvalue?:any
Examples
clear
Clear all server resources and reset state This method should be called to clean up all server-side resources when shutting down or resetting the map. It stops the input processing loop and ensures that all subscriptions are properly cleaned up.Design
This method is used primarily in testing environments to ensure clean state between tests. It stops the tick subscription to prevent memory leaks.- Source:
packages/server/src/rooms/map.ts - Kind:
method - Defined in:
RpgMap
Signature
Examples
clearWeather
Clear weather for this map.- Source:
packages/server/src/rooms/map.ts - Kind:
method - Defined in:
RpgMap
Signature
Parameters
options?:WeatherSetOptions
createDynamicEvent
Creates a dynamic event on the map This method handles both class-based events and object-based events with hooks. For class-based events, it creates a new instance of the class. For object-based events, it creates a dynamic class that extends RpgEvent and implements the hook methods from the object.- Source:
packages/server/src/rooms/map.ts - Kind:
method - Defined in:
RpgMap
Signature
Parameters
eventObj:EventPosOptionoptions?:CreateDynamicEventOptions
Examples
createDynamicWorldMaps
Create a world manager dynamically Creates a new WorldMapsManager instance and configures it with the provided map configurations. This is used when loading world data from Tiled or other map editors.- Source:
packages/server/src/rooms/map.ts - Kind:
method - Defined in:
RpgMap
Signature
Parameters
world:{ id?: string; maps: WorldMapConfig[] }
Returns
The newly created WorldMapsManager instanceExamples
createShape
Create a shape dynamically on the map This method creates a static hitbox on the map that can be used for collision detection, area triggers, or visual boundaries. The shape is backed by the physics engine’s static entity system for accurate collision detection.Architecture
Creates a static entity (hitbox) in the physics engine at the specified position and size. The shape is stored internally and can be retrieved by name. When players or events collide with this hitbox, theonInShape and onOutShape hooks are automatically
triggered on both the player and the event.
- Source:
packages/server/src/rooms/map.ts - Kind:
method - Defined in:
RpgMap
Signature
Parameters
obj:{ x: number; y: number; width: number; height: number; name?: string; z?: number; color?: string; collision?: boolean; properties?: Record<string, any>; }
Returns
The created RpgShape instanceExamples
damageFormulas
Damage formulas configuration for the map Contains formulas for calculating damage from skills, physical attacks, critical hits, and element coefficients. Default formulas are merged with custom formulas when the map is loaded.- Source:
packages/server/src/rooms/map.ts - Kind:
property - Defined in:
RpgMap
Signature
database
Signal containing the map’s database of items, classes, and other game data This database can be dynamically populated usingaddInDatabase() and
removeInDatabase() methods. It’s used to store game entities like items,
classes, skills, etc. that are specific to this map.
- Source:
packages/server/src/rooms/map.ts - Kind:
property - Defined in:
RpgMap
Signature
Examples
dataIsReady$
BehaviorSubject that completes when the map data is ready This subject is used to signal when the map has finished loading all its data. Players wait for this to complete before the map is fully initialized.- Source:
packages/server/src/rooms/map.ts - Kind:
property - Defined in:
RpgMap
Signature
Examples
deleteWorldMaps
Delete a world manager by id Removes the world maps manager from this map instance. Currently, only one world manager is supported, so this clears the single manager.- Source:
packages/server/src/rooms/map.ts - Kind:
method - Defined in:
RpgMap
Signature
Parameters
id:string
Returns
true if the manager was deleted, false if it didn’t existExamples
events
Synchronized signal containing all events (NPCs, objects) on the map This signal is automatically synchronized with clients using- Source:
packages/server/src/rooms/map.ts - Kind:
property - Defined in:
RpgMap
Signature
Examples
getEvent
Get an event by its ID Returns the event with the specified ID, or undefined if not found. The return type can be narrowed using TypeScript generics.- Source:
packages/server/src/rooms/map.ts - Kind:
method - Defined in:
RpgMap
Signature
Parameters
eventId:string
Returns
The event instance, or undefined if not foundExamples
getEventBy
Get the first event that matches a condition Searches through all events on the map and returns the first one that matches the provided callback function.- Source:
packages/server/src/rooms/map.ts - Kind:
method - Defined in:
RpgMap
Signature
Parameters
cb:(event: RpgEvent) => boolean
Returns
The first matching event, or undefined if none foundExamples
getEvents
Get all events on the map Returns an array of all events (NPCs, objects, etc.) that are currently on this map.- Source:
packages/server/src/rooms/map.ts - Kind:
method - Defined in:
RpgMap
Signature
Returns
Array of all RpgEvent instances on the mapExamples
getEventsBy
Get all events that match a condition Searches through all events on the map and returns all events that match the provided callback function.- Source:
packages/server/src/rooms/map.ts - Kind:
method - Defined in:
RpgMap
Signature
Parameters
cb:(event: RpgEvent) => boolean
Returns
Array of all matching eventsExamples
getPlayer
Get a player by their ID Returns the player with the specified ID, or undefined if not found.- Source:
packages/server/src/rooms/map.ts - Kind:
method - Defined in:
RpgMap
Signature
Parameters
playerId:string
Returns
The player instance, or undefined if not foundExamples
getPlayers
Get all players currently on the map Returns an array of all players that are currently connected to this map.- Source:
packages/server/src/rooms/map.ts - Kind:
method - Defined in:
RpgMap
Signature
Returns
Array of all RpgPlayer instances on the mapExamples
getShape
Get a shape by its name Returns a shape with the specified name, or undefined if no shape with that name exists on the map.- Source:
packages/server/src/rooms/map.ts - Kind:
method - Defined in:
RpgMap
Signature
Parameters
name:string
Returns
The RpgShape instance, or undefined if not foundExamples
getShapes
Get all shapes on the map Returns an array of all shapes that have been created on this map, regardless of whether they are static shapes or player-attached shapes.- Source:
packages/server/src/rooms/map.ts - Kind:
method - Defined in:
RpgMap
Signature
Returns
Array of RpgShape instancesExamples
getWeather
Get the current map weather state.- Source:
packages/server/src/rooms/map.ts - Kind:
method - Defined in:
RpgMap
Signature
getWorldMaps
Get a world manager by id Returns the world maps manager for the given world ID. Currently, only one world manager is supported per map instance.- Source:
packages/server/src/rooms/map.ts - Kind:
method - Defined in:
RpgMap
Signature
Parameters
id:string
Returns
The WorldMapsManager instance, or null if not initializedExamples
globalConfig
Global configuration object for the map This object contains configuration settings that apply to the entire map. It’s populated from the map data whenupdateMap() is called.
- Source:
packages/server/src/rooms/map.ts - Kind:
property - Defined in:
RpgMap
Signature
guiExit
Handle GUI exit from a player This method is called when a player closes or exits a GUI. It removes the GUI from the player’s active GUIs.- Source:
packages/server/src/rooms/map.ts - Kind:
method - Defined in:
RpgMap
Signature
Parameters
player:RpgPlayer{ guiId, data }
Examples
guiInteraction
Handle GUI interaction from a player This method is called when a player interacts with a GUI element. It synchronizes the player’s changes to ensure the client state is up to date.- Source:
packages/server/src/rooms/map.ts - Kind:
method - Defined in:
RpgMap
Signature
Parameters
player:RpgPlayervalue:{ guiId: string, name: string, data: any }
Examples
hooks
Get the hooks system for this map Returns the dependency-injected Hooks instance that allows you to trigger and listen to various game events.- Source:
packages/server/src/rooms/map.ts - Kind:
getter - Defined in:
RpgMap
Signature
Returns
The Hooks instance for this mapExamples
interceptorPacket
Intercepts and modifies packets before they are sent to clients This method is automatically called by- Source:
packages/server/src/rooms/map.ts - Kind:
method - Defined in:
RpgMap
Signature
Parameters
player:RpgPlayerpacket:anyconn:MockConnection
Returns
Modified packet with timestamp and ack info, or null if player is invalidExamples
maps
Array of map configurations - can contain MapOptions objects or instances of map classes This array stores the configuration for this map and any related maps. It’s populated when the map is loaded viaupdateMap().
- Source:
packages/server/src/rooms/map.ts - Kind:
property - Defined in:
RpgMap
Signature
off
Remove all listeners for a custom client event on this map.- Source:
packages/server/src/rooms/map.ts - Kind:
method - Defined in:
RpgMap
Signature
Parameters
type:string
on
Listen to custom websocket events sent by clients on this map. The callback receives the player who sent the event and the payload. This is useful for map-wide custom interactions that are not covered by built-in actions such as movement, GUI events, or the action button.- Source:
packages/server/src/rooms/map.ts - Kind:
method - Defined in:
RpgMap
Signature
Parameters
type:stringcb:(player: RpgPlayer, data: any) => void | Promise<void>
Examples
onAction
Handle action input from a player This method is called when a player performs an action (like pressing a button). It checks for collisions with events and triggers the appropriate hooks.Architecture
- Gets all entities colliding with the player
- Triggers
onActionhook on colliding events - Triggers
onInputhook on the player
- Source:
packages/server/src/rooms/map.ts - Kind:
method - Defined in:
RpgMap
Signature
Parameters
player:RpgPlayeraction:any
Examples
onInput
Handle movement input from a player This method is called when a player sends movement input from the client. It queues the input for processing by the game loop. Inputs are processed with frame numbers to ensure proper ordering and client-side prediction.Architecture
-
Inputs are queued in
player.pendingInputs - Duplicate frames are skipped to prevent processing the same input twice
- Inputs are processed asynchronously by the game loop
-
Source:
packages/server/src/rooms/map.ts -
Kind:
method -
Defined in:
RpgMap
Signature
Parameters
player:RpgPlayerinput:any
Examples
onJoin
Called when a player joins the map This method is automatically called by- Source:
packages/server/src/rooms/map.ts - Kind:
method - Defined in:
RpgMap
Signature
Parameters
player:RpgPlayerconn:MockConnection
Examples
onLeave
Called when a player leaves the map This method is automatically called by- Source:
packages/server/src/rooms/map.ts - Kind:
method - Defined in:
RpgMap
Signature
Parameters
player:RpgPlayerconn:MockConnection
Examples
patchWeather
Patch the current weather state. Nestedparams values are merged.
- Source:
packages/server/src/rooms/map.ts - Kind:
method - Defined in:
RpgMap
Signature
Parameters
patch:Partial<WeatherState>options?:WeatherSetOptions
players
Synchronized signal containing all players currently on the map This signal is automatically synchronized with clients using- Source:
packages/server/src/rooms/map.ts - Kind:
property - Defined in:
RpgMap
Signature
Examples
playSound
Play a sound for all players on the map This method plays a sound for all players currently on the map by iterating over each player and callingplayer.playSound(). The sound must be defined
on the client side (in the client module configuration).
This is ideal for environmental sounds, battle music, or map-wide events that
all players should hear simultaneously.
Design
Iterates over all players on the map and callsplayer.playSound() for each one.
This avoids code duplication and reuses the existing player sound logic.
For player-specific sounds, use player.playSound() directly.
- Source:
packages/server/src/rooms/map.ts - Kind:
method - Defined in:
RpgMap
Signature
Parameters
soundId:stringoptions?:{ volume?: number; loop?: boolean }
Examples
processInput
Process pending inputs for a player with anti-cheat validation This method processes pending inputs for a player while performing anti-cheat validation to prevent time manipulation and frame skipping. It validates the time deltas between inputs and ensures they are within acceptable ranges. To preserve movement itinerary under network bursts, the number of inputs processed per call is capped.Architecture
Important: This method only updates entity velocities - it does NOT step the physics engine. Physics simulation is handled centrally by the game loop (tick$ -> runFixedTicks). This ensures:
- Consistent physics timing (60fps fixed timestep)
- No double-stepping when multiple inputs are processed
- Deterministic physics regardless of input frequency
-
Source:
packages/server/src/rooms/map.ts -
Kind:
method -
Defined in:
RpgMap
Signature
Parameters
playerId:stringcontrols?:Controls
Returns
Promise containing the player and processed input stringsExamples
removeEvent
Remove an event from the map Removes the event with the specified ID from the map. The event will be removed from the synchronized events signal, causing it to disappear on all clients.- Source:
packages/server/src/rooms/map.ts - Kind:
method - Defined in:
RpgMap
Signature
Parameters
eventId:string
Examples
removeInDatabase
Remove data from the map’s database This method delegates to BaseRoom’s implementation to avoid code duplication.- Source:
packages/server/src/rooms/map.ts - Kind:
method - Defined in:
RpgMap
Signature
Parameters
id:string
Returns
true if data was removed, false if ID didn’t existExamples
removeShape
Delete a shape from the map Removes a shape by its name and cleans up the associated static hitbox entity. If the shape doesn’t exist, the method does nothing.- Source:
packages/server/src/rooms/map.ts - Kind:
method - Defined in:
RpgMap
Signature
Parameters
name:string
Returns
voidExamples
setAutoTick
Enable or disable automatic tick processing When disabled, the input processing loop will not run automatically. This is useful for unit tests where you want manual control over when inputs are processed.- Source:
packages/server/src/rooms/map.ts - Kind:
method - Defined in:
RpgMap
Signature
Parameters
enabled:boolean
Examples
setSync
Configure runtime synchronized properties on the map This method allows you to dynamically add synchronized properties to the map that will be automatically synced with clients. The schema follows the same structure as module properties with$initial, $syncWithClient, and $permanent options.
Architecture
- Reads a schema object shaped like module props
- Creates typed sync signals with
-
Source:
packages/server/src/rooms/map.ts -
Kind:
method -
Defined in:
RpgMap
Signature
Parameters
schema:Record<string, any>
Examples
setWeather
Set the full weather state for this map. Whensync is true (default), all connected clients receive the new weather.
- Source:
packages/server/src/rooms/map.ts - Kind:
method - Defined in:
RpgMap
Signature
Parameters
next:WeatherState | nulloptions?:WeatherSetOptions
shakeMap
Shake the map for all players This method triggers a shake animation on the map for all players currently on the map. The shake effect creates a visual feedback that can be used for earthquakes, explosions, impacts, or any dramatic event that should affect the entire map visually.Architecture
Broadcasts a shake event to all clients connected to the map. Each client receives the shake configuration and triggers the shake animation on the map container using Canvas Engine’s shake directive.- Source:
packages/server/src/rooms/map.ts - Kind:
method - Defined in:
RpgMap
Signature
Parameters
options?:{ intensity?: number; duration?: number; frequency?: number; direction?: 'x' | 'y' | 'both'; }
Examples
showAnimation
Display a spritesheet animation at a specific position on the map This method displays a temporary visual animation using a spritesheet at any location on the map. It’s a convenience method that internally uses showComponentAnimation with the built-in ‘animation’ component. This is useful for spell effects, environmental animations, or any visual feedback that uses predefined spritesheets.- Source:
packages/server/src/rooms/map.ts - Kind:
method - Defined in:
RpgMap
Signature
Parameters
position:{ x: number, y: number }graphic:stringanimationName?:string
Examples
showComponentAnimation
Display a component animation at a specific position on the map This method broadcasts a component animation to all clients connected to the map, allowing temporary visual effects to be displayed at any location on the map. Component animations are custom Canvas Engine components that can display complex effects with custom logic and parameters.- Source:
packages/server/src/rooms/map.ts - Kind:
method - Defined in:
RpgMap
Signature
Parameters
id:stringposition:{ x: number, y: number }params:any
Examples
sounds
Array of sound IDs to play when players join the map These sounds are automatically played for each player when they join the map. Sounds must be defined on the client side.- Source:
packages/server/src/rooms/map.ts - Kind:
property - Defined in:
RpgMap
Signature
Examples
stopSound
Stop a sound for all players on the map This method stops a sound that was previously started withmap.playSound()
for all players on the map by iterating over each player and calling player.stopSound().
- Source:
packages/server/src/rooms/map.ts - Kind:
method - Defined in:
RpgMap
Signature
Parameters
soundId:string
Examples
updateMap
Update the map configuration and data This endpoint receives map data from the client and initializes the map. It loads the map configuration, damage formulas, events, and physics.Architecture
- Validates the request body using MapUpdateSchema
- Updates map data, global config, and damage formulas
- Merges events and sounds from map configuration
- Triggers hooks for map loading
- Loads physics engine
- Creates all events on the map
- Completes the dataIsReady$ subject
- Source:
packages/server/src/rooms/map.ts - Kind:
method - Defined in:
RpgMap
Signature
Parameters
request:Request
Returns
Promise that resolves when the map is fully loadedExamples
updateWorld
Update (or create) a world configuration and propagate to all maps in that world This endpoint receives world map configuration data (typically from Tiled world import) and creates or updates the world manager. The world ID is extracted from the URL path.Architecture
- Extracts world ID from URL path parameter
- Normalizes input to array of WorldMapConfig
- Ensures all required map properties are present (width, height, tile sizes)
- Creates or updates the world manager
-
{ id: string, maps: WorldMapConfig[] } -
WorldMapConfig[] -
Source:
packages/server/src/rooms/map.ts -
Kind:
method -
Defined in:
RpgMap
Signature
Parameters
request:Request
Returns
Promise resolving to{ ok: true } when complete
Examples
updateWorldMaps
Update world maps by id. Auto-create when missing. Updates the world maps configuration. If the world manager doesn’t exist, it is automatically created. This is useful for dynamically loading world data or updating map positions.- Source:
packages/server/src/rooms/map.ts - Kind:
method - Defined in:
RpgMap
Signature
Parameters
id:stringmaps:WorldMapConfig[]