SightLayer

SightLayer

The Sight Layer which implements dynamic vision, lighting, and fog of war

Constructor

new SightLayer()

Source:

Members

(static) DEFAULT_ALPHAS :Object

Source:

The default sight visibility layer alpha channels

Type:
  • Object

alphas :Object

Source:

Store the different opacity levels used for elements of the Sight Layer

Type:
  • Object

fog :PIXI.Container

Source:

The fog container which includes fog of war and exploration layers

Type:
  • PIXI.Container

fogData :Object

Source:

Fog of War data object

Type:
  • Object

fogExploration :Boolean

Source:

Track whether or not fog of war exploration is enabled for this Scene

Type:
  • Boolean

fogPositions :Object

Source:

Track the distinct grid positions which have had fog of war explored at a certain visible radius

Type:
  • Object

fov :Array

Source:

Track currently active field-of-view polygons

Type:

los :Object

Source:

Track currently active line-of-sight polygons

Type:
  • Object

map :PIXI.Container

Source:

The shadow map container which renders dark, dim, and bright light sources

Type:
  • PIXI.Container

queues :Object

Source:

Light source rendering queues divide the contents of the shadow-map into 4 lighting levels, each of which override the precedence of the previous level

  1. dim
  2. bright
  3. dark
  4. black
Type:
  • Object

shadowMapFilter :PIXI.filters.ColorMatrixFilter

Source:

A special ColorMatrixFilter which transforms greyscale to alpha

Type:
  • PIXI.filters.ColorMatrixFilter

tokens :Object

Source:

Classify arrays of tokens which either have vision or emit light

Type:
  • Object

tokenVision :Boolean

Source:

Track whether or not Token vision is enabled for this Scene

Type:
  • Boolean

Methods

_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

checkSight(origin, radius, minAngle, maxAngle, cullDistance, cullMultiplier, radialDensity, walls) → {Array}

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

[Optional] The minimum angle of restricted sight or light emission

maxAngle Number

[Optional] The maximum angle of restricted sight or light emission

cullDistance Number

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

cullMultiplier Number

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

radialDensity Number

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

walls Array

[Optional] A specific Array of Walls to test collision against

Returns:

An Array of Ray objects, and the two vision polygons

Type
Array

draw() → {SightLayer}

Source:

Draw Sight Layer canvas elements

Returns:
Type
SightLayer

(async) initialize()

Source:

Initialize starting sight for non-GM players

(async) initializeFog() → {Promise}

Source:

Initialize the fog container by resetting tracked fog positions and loading existing fog layer for the scene.

Returns:

A Promise which resolves once fog of war is fully loaded

Type
Promise

initializeSight(options)

Source:

Initialize sight and visibility

Parameters:
Name Type Description
options Object
Properties
Name Type Description
updateFog boolean

(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

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

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

updateLights()

Source:

Draw light containers for all ambient lights which do not change when a token is moved

First, iterate through each light and register light-level data. For each light source, store their light radii in a queue for rendering. Sort the queue in descending order of radius to ensure that we draw bright light after dim light, and negative light values last of all.

updateSight(options)

Source:

Draw the sight polygon for a specified token Support a number of options to configure how sight is updated

Parameters:
Name Type Description
options Object
Properties
Name Type Description
updateFog Boolean