Constructor
new SightLayer()
- See:
Properties:
Name | Type | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
unexplored |
PIXI.Graphics | The unexplored background which spans the entire canvas |
|||||||||||||||
explored |
PIXI.Container | The exploration container which tracks exploration progress |
|||||||||||||||
revealed |
PIXI.Container | A container of regions which have previously been revealed |
|||||||||||||||
saved |
PIXI.Sprite | The saved fog exploration texture |
|||||||||||||||
pending |
PIXI.Container | Pending exploration which has not yet been committed to the texture |
|||||||||||||||
vision |
PIXI.Container | The container of current vision exploration Properties
|
Example
Hooks.on("sightRefresh", layer => {});
Extends
Members
(static) layerOptions
_active :boolean
- Overrides:
Track whether the canvas layer is currently active for interaction
Type:
- boolean
debounceSaveFog :function
A debounced function to save fog of war exploration once a stream of updates have stopped
Type:
- function
EXACT_VISION_THRESHOLD :number
Define the threshold value for the number of distinct Wall endpoints. Below this threshold, exact vision computation is used by casting a Ray at every endpoint. Above this threshold, approximate vision computation is used by culling to only nearby endpoints.
Type:
- number
exploration :FogExploration|null
The FogExploration document which applies to this canvas view
Type:
- FogExploration | null
FOG_COMMIT_THRESHOLD :number
Define the number of positions that are explored before a set of fog updates are pushed to the server.
Type:
- number
fogExploration :boolean
Does the currently viewed Scene support fog of war exploration?
Type:
- boolean
los :PIXI.Graphics
The canonical line-of-sight polygon which defines current Token visibility.
Type:
- PIXI.Graphics
losCache :CachedContainer
A cached container which creates a render texture used for the LOS mask.
Type:
MAXIMUM_FOW_TEXTURE_SIZE :number
The maximum allowable fog of war texture size.
Type:
- number
name :string
- Overrides:
The canonical name of the CanvasLayer
Type:
- string
options :CanvasLayerOptions
- Overrides:
Options for this layer instance.
Type:
sources :Collection.<string, PointSource>
A Collection of vision sources which are currently active within the rendered Scene.
Type:
- Collection.<string, PointSource>
tokenVision :boolean
Does the currently viewed Scene support Token field of vision?
Type:
- boolean
vision :PIXI.Container
The current vision container which provides line-of-sight for vision sources and field-of-view of light sources.
Type:
- PIXI.Container
Methods
(async) _handleResetFog() → {Promise}
If fog of war data is reset from the server, re-draw the canvas
Returns:
- Type
- Promise
activate() → {CanvasLayer}
- Overrides:
Activate the CanvasLayer, deactivating other layers and marking this layer's children as interactive.
Returns:
The layer instance, now activated
- Type
- CanvasLayer
commitFog()
Once a new Fog of War location is explored, composite the explored container with the current staging sprite Save that staging Sprite as the rendered fog exploration and swap it out for a fresh staging texture Do all this asynchronously, so it doesn't block token movement animation since this takes some extra time
deactivate() → {CanvasLayer}
- Overrides:
Deactivate the CanvasLayer, removing interactivity from its children.
Returns:
The layer instance, now inactive
- Type
- CanvasLayer
(async) draw() → {Promise.<CanvasLayer>}
- Overrides:
Draw the canvas layer, rendering its internal components and returning a Promise The Promise resolves to the drawn layer once its contents are successfully rendered.
Returns:
- Type
- Promise.<CanvasLayer>
getZIndex() → {number}
- Overrides:
Get the zIndex that should be used for ordering this layer vertically relative to others in the same Container.
Returns:
- Type
- number
(async) initializeFog() → {Promise.<void>}
Initialize fog of war - resetting it when switching scenes or re-drawing the canvas
Returns:
- Type
- Promise.<void>
initializeSources()
Initialize all Token vision sources which are present on this layer
(async) loadFog() → {Promise.<(PIXI.Texture|void)>}
Load existing fog of war data from local storage and populate the initial exploration sprite
Returns:
- Type
- Promise.<(PIXI.Texture|void)>
refresh(forceUpdateFogopt, skipUpdateFogopt)
Update the display of the sight layer. Organize sources into rendering queues and draw lighting containers for each source
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
forceUpdateFog |
boolean |
<optional> |
Always update the Fog exploration progress for this update |
skipUpdateFog |
boolean |
<optional> |
Never update the Fog exploration progress for this update |
(async) resetFog()
Dispatch a request to reset the fog of war exploration status for all users within this Scene. Once the server has deleted existing FogExploration documents, the _onResetFog handler will re-draw the canvas.
restrictVisibility()
Restrict the visibility of certain canvas assets (like Tokens or DoorControls) based on the visibility polygon These assets should only be displayed if they are visible given the current player's field of view
(async) saveFog()
Save Fog of War exploration data to a base64 string to the FogExploration document in the database. Assumes that the fog exploration has already been rendered as fog.rendered.texture.
(async) tearDown() → {Promise.<CanvasLayer>}
- Overrides:
Deconstruct data used in the current layer in preparation to re-draw the canvas
Returns:
- Type
- Promise.<CanvasLayer>
testVisibility(point, tolerance, objectopt) → {boolean}
Test whether a point on the Canvas is visible based on the current vision and LOS polygons
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
point |
Point | The point in space to test, an object with coordinates x and y. |
|
tolerance |
number | A numeric radial offset which allows for a non-exact match. For example, if tolerance is 2 then the test will pass if the point is within 2px of a vision polygon. |
|
object |
PIXI.DisplayObject |
<optional> |
An optional reference to the object whose visibility is being tested |
Returns:
Whether the point is currently visible.
- Type
- boolean
updateFog(source, force)
Update the fog layer when a player token reaches a board position which was not previously explored
Parameters:
Name | Type | Default | Description |
---|---|---|---|
source |
PointSource | The vision source for which the fog layer should update |
|
force |
boolean |
false
|
Force fog to be updated even if the location is already explored |
updateFogExplorationColors()
Update FoW unexplored and explored colors