grid

Helper functions related to grid-centric canvas operations

Details

Methods


<static> highlightRing( config [, options ] ) → {Array.<{x: Number, y: Number, ring: Number}>}

Description

For gridded scenes, will highlight a corresponding number of concentric rings spreading outward from the provided starting point (which is given a negative ring index).

By default, the number of rings to highlight is zero and the layer is cleared before drawing, which results in erasing any highlighted rings on the canvas.

Parameters
Name Type Attributes Description
config object
Name Type Attributes Default Description
x Number
y Number
rings Number | Array.<Number> <optional>
0

Number of concentric rings to highlight. If an array is provided, it is treated as a "schedule" where each entry represents value number of size-width rings.

name String <optional>
'warpgate-ring'

Highlight layer name to be used for drawing/clearing

options object <optional>
Name Type Attributes Default Description
size Number <optional>
1

Width of each ring, in grid spaces

colors Color | Array.<Color> | ColorFn <optional>
game.user.color

Colors for each ring 'band' (based on size option). If a Color is passed, all highlights will use that color. If an Array<Color> is passed each size-width ring will be colored according to the provided list, which is iterated circularly (i.e. repeats if short). If a ColorFn is passed, it will be used to generate the color on a per-square/hex basis (see ColorFn for more details). Any falsey value provided (either in list or as ColorFn return) will not highlight the given location (e.g. "transparent highlight").

clear boolean <optional>
true

Clear any current highlights on named layer before drawing more.

lifetime Number <optional>
0

Time (in milliseconds) before the highlighted ring is automatically cleared. A negative value or zero indicates "indefinitely". Ignored if config.rings is less than 1.

Returns

Highlighted grid locations (in pixels) and their corresponding ring index

Examples
const name = 'rangefinder';
			const size = 2;
			const rings = 5;
			const colors = ['red', '#00FF00', 0x0000FF, false];
			
			// Draw a simple ring on the default layer
			warpgate.grid.highlightRing({x: token.x, y:token.y, rings:1});
			
			// Draw a larger temporary ring on the rangerfinder layer
			const highlights = warpgate.grid.highlightRing(
			    {x: token.x, y:token.y, rings, name}, 
			    {size, colors, clear: true, lifetime:2000});
			    
			ui.notifications.info(`Highlighted ${highlights.length} grid positions.`);