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.

Structure of the Container darkness (Graphics) fog (Container) explored (Sprite) update (Container) [mask=los] fov (Graphics) los (Graphics) sources (Container) [mask=los] dim (Graphics) bright (Graphics) dark (Graphics) black (Graphics) los (Graphics)

Constructor

new SightLayer()

Source:
See:

Extends

Members

_active :Boolean

Source:
Overrides:

Track whether the canvas layer is currently active for interaction

Type:
  • Boolean

_blurDistance :number|null

Source:

The blur distance for soft shadows

Type:
  • number | null

_channels :Object|null

Source:

The lighting channels which are an input to the ShadowMap

Type:
  • Object | null

_cull :Array.<number>

Source:

An Array which specifies the cull multiplier, minimum, and maximum distance to use This depends dynamically on the number of walls in the Scene

Type:

_fogResolution :number|null

Source:

The downscaling resolution used for the saved fog texture

Type:
  • number | null

alphas :Object|null

Source:

Configure the opacity levels used for each channel of the lighting map

Type:
  • Object | null

blurDistance

Source:

A getter to retrieve the current value of blur distance

blurDistance

Source:

A setter to apply a new blur distance value

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

sources :Object.<Map>

Source:

A mapping of the sources of lighting and vision which are active within the rendered Scene

Type:
  • Object.<Map>

tokenVision :boolean

Source:

Does the currently viewed Scene support Token field of vision?

Type:
  • boolean

Methods

(static) _castSightRays() → {Array}

Source:

A helper method responsible for casting rays at wall endpoints Rays are restricted by allowed angles and culling distance

Returns:

An array of Ray objects

Type
Array

(static) computeSight(origin, radius, minAngle, maxAngle, cullDistance, cullMult, density, walls) → {Object}

Source:

Evaluate the sight polygons for a given origin position and vision radius This method generates two polygons - one for line of sight, and another for field of vision 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 Description
origin Object

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

radius Number

A distance in canvas position units which reflects the visible range

minAngle Number

The minimum angle of restricted sight or light emission

maxAngle Number

The maximum angle of restricted sight or light emission

cullDistance Number

The minimum number of grid spaces after which to begin culling walls.

cullMult Number

The multiplier on the provided radius against which to cull wall endpoint checks. Default is 2

density Number

The density in degrees to which to guarantee that rays are broadcast. Default is 6

walls Array

A specific Array of Walls to test collision against

Returns:

An Array of Ray objects, and the two vision polygons

Type
Object

(async) _onResetFog(resetData) → {Promise}

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

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

Source:

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

Returns:
Type
Promise

initializeLights()

Source:

Initialize the sight layer for all AmbientLight based sources. This method calls the SightLayer#updateLight function for each Ambient Light object.

initializeTokens()

Source:

Initialize the sight layer for all Token based sources. This method calls the SightLayer#updateToken function for each Token object.

(async) loadFog() → {Promise}

Source:

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

Returns:
Type
Promise

(async) resetFog()

Source:

Reset the fog of war by clearing current exploration progress This approach currently takes the nuclear option of clearing any saved fog and redrawing the entire canvas It's not that inefficient, so it could be worth just keeping it this way for simplicity

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:

Update the display of the sight layer. Organize sources into rendering queues and draw lighting containers for each source

updateFog(x, y, radius, limit, force)

Source:

Update the fog layer when a player token reaches a board position which was not previously explored

Parameters:
Name Type Description
x Number

The origin x-coordinate from which to update fog exploration

y Number

The origin y-coordinate from which to update fog exploration

radius Number

The vision radius of the exploration from this point

limit Boolean

Was the position explored by a limited viewpoint?

force Boolean

Force the fog location to be updated even if it is not a larger radius

updateLight(light, defer, deleted, walls)

Source:

Update lighting data for a single light source, storing it as a source in the Sight Layer

Parameters:
Name Type Description
light AmbientLight

The light object being rendered

defer boolean

Defer rendering the update until later? Default is false

deleted boolean

An optional flag which denotes that the light object has been deleted

walls Array

Optionally pass an array of Walls which block vision for efficient computation

updateToken(token, defer, deleted, walls, updateFog)

Source:

Update lighting data for a single Token source, storing it as a source in the Sight Layer

Parameters:
Name Type Description
token Token

The Token object being rendered

defer boolean

Defer rendering the update until later? Default is false

deleted boolean

An optional flag which denotes that the Token object has been deleted

walls Array

Optionally pass an array of Walls which block vision for efficient computation

updateFog boolean

Update fog exploration progress for the current Token position?