SightLayer

SightLayer

The Sight Layer which implements dynamic vision, lighting, and fog of war This layer uses an event-driven workflow to perform the minimal required calculation in response to changes.

Constructor

new SightLayer()

Source:
See:
Example

The sightRefresh hook

Hooks.on("sightRefresh", layer => {});

Extends

Members

(static) EXACT_VISION_THRESHOLD :number

Source:

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

(static) FOG_COMMIT_THRESHOLD :number

Source:

Define the number of positions that are explored before a set of fog updates are pushed to the server.

Type:
  • number

_active :boolean

Source:
Overrides:

Track whether the canvas layer is currently active for interaction

Type:
  • boolean

_blurDistance :number

Source:

The blur distance for soft shadows

Type:
  • number

_fogResolution :number

Source:

The downscaling resolution used for the saved fog texture

Type:
  • number

_visionPool :Array.<PIXI.Container>

Source:

A pool of fog of war exploration containers that can be recycled

Type:

debounceSaveFog :function

Source:

A debounced function to save fog of war exploration once a stream of updates have stopped

Type:
  • function

fogData :Object

Source:

Fog of War data object

Type:
  • Object

fogExploration :boolean

Source:

Does the currently viewed Scene support fog of war exploration?

Type:
  • boolean

los :PIXI.Graphics

Source:

The canonical line-of-sight polygon which defines current Token visibility.

Type:
  • PIXI.Graphics

name

Source:
Overrides:

The canonical name of the CanvasLayer

sources :Collection.<string, PointSource>

Source:

A Collection of vision sources which are currently active within the rendered Scene.

Type:

tokenVision :boolean

Source:

Does the currently viewed Scene support Token field of vision?

Type:
  • boolean

Methods

(static) _castRays(x, y, distance, density, endpoints, limitAngle, aMin, aMax) → {Array.<Ray>}

Source:

A helper method responsible for casting rays at wall endpoints. Rays are restricted by limiting angles.

Parameters:
Name Type Description
x number

The origin x-coordinate

y number

The origin y-coordinate

distance number

The ray distance

density number

The desired radial density

endpoints Array.<PointArray>

An array of endpoints to target

limitAngle boolean

Whether the rays should be cast subject to a limited angle of emission

aMin number

The minimum bounding angle

aMax number

The maximum bounding angle

Returns:

An array of Ray objects

Type
Array.<Ray>

(static) _visualizeSight(bounds, endpoints, rays, los, fov)

Source:

Visualize the sight layer to understand algorithm performance.

Parameters:
Name Type Description
bounds Rectangle

The initial rectangular bounds of the vision check

endpoints Array.<PointArray>

The wall endpoints being tested

rays Array.<Ray>

The array of cast vision Rays

los PIXI.Polygon

The resulting line-of-sight polygon

fov PIXI.Polygon

The resulting field-of-vision polygon

(static) computeSight(origin, radius, angleopt, densityopt, endpointsopt, unrestrictedopt) → {Object}

Source:

Compute line-of-sight and field-of-vision polygons for a given origin position and visibility radius. The line-of-sight polygon defines the unrestricted area of visibility for the source. The field-of-vision polygon defines the restricted area of visibility for the source.

Parameters:
Name Type Attributes Description
origin Point

An point with coordinates x and y representing the origin of the test

radius number

A distance in canvas pixels which reflects the visible range

angle number <optional>

An optional limited angle of emission with which to restrict polygons

density number <optional>

The desired radial density of emission for rays, in degrees

endpoints Array.<Point> <optional>

An array of explicit endpoints against which to compute sight

unrestricted boolean <optional>

Compute sight that is unrestricted by walls

Returns:

The computed rays and polygons

Type
Object

(async) _onResetFog(resetData) → {Promise.<Canvas>}

Source:

If fog of war data is reset from the server, re-draw the canvas

Parameters:
Name Type Description
resetData Object

Fog reset data sent by the server

Returns:
Type
Promise.<Canvas>

activate()

Source:
Overrides:

Activate the CanvasLayer, deactivating other layers and marking this layer's children as interactive

deactivate()

Source:
Overrides:

Deactivate the CanvasLayer, removing interactivity from its children

(async) draw() → {Promise.<CanvasLayer>}

Source:
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>

(async) initialize()

Source:

Initialize the Sight Layer. Initialization has the following hierarchical workflow:

Initialize Layer (reset entire layer) InitializeLights (used to reset all lights) UpdateLight (update a single light) InitializeTokens (reset all tokens) UpdateToken (update a single token) Initialize Fog (reset FOW state)

(async) initializeFog() → {Promise.<void>}

Source:

Initialize fog of war - resetting it when switching scenes or re-drawing the canvas

Returns:
Type
Promise.<void>

initializeTokens()

Source:
Deprecated:
  • since 0.7.3
See:
  • Canvas#initializeSources

(async) loadFog() → {Promise.<PIXI.Texture>}

Source:

Load existing fog of war data from local storage and populate the initial exploration sprite

Returns:
Type
Promise.<PIXI.Texture>

refresh(forceUpdateFogopt, noUpdateFogopt)

Source:

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

noUpdateFog boolean <optional>

Never update the Fog exploration progress for this update

(async) resetFog()

Source:

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()

Source:

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) tearDown()

Source:
Overrides:

Deconstruct data used in the current layer in preparation to re-draw the canvas

testVisibility(point, tolerance) → {boolean}

Source:

Test whether a point on the Canvas is visible based on the current vision and LOS polygons

Parameters:
Name Type Description
point Object | PIXI.Point

The point in space to test. This can be an Object with x and y coordinates or a Point object.

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.

Returns:

Whether the point is currently visible.

Type
boolean

update()

Source:
Deprecated:
  • since 0.7.3
See:

updateFog(source, force)

Source:

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

updateLight()

Source:
Deprecated:
  • since 0.7.3
See:

updateToken()

Source:
Deprecated:
  • since 0.7.3
See: