Initial
This commit is contained in:
53
resources/app/client/pixi/layers/grid/highlight.js
Normal file
53
resources/app/client/pixi/layers/grid/highlight.js
Normal file
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* A special Graphics class which handles Grid layer highlighting
|
||||
* @extends {PIXI.Graphics}
|
||||
*/
|
||||
class GridHighlight extends PIXI.Graphics {
|
||||
constructor(name, ...args) {
|
||||
super(...args);
|
||||
|
||||
/**
|
||||
* Track the Grid Highlight name
|
||||
* @type {string}
|
||||
*/
|
||||
this.name = name;
|
||||
|
||||
/**
|
||||
* Track distinct positions which have already been highlighted
|
||||
* @type {Set}
|
||||
*/
|
||||
this.positions = new Set();
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
|
||||
/**
|
||||
* Record a position that is highlighted and return whether or not it should be rendered
|
||||
* @param {number} x The x-coordinate to highlight
|
||||
* @param {number} y The y-coordinate to highlight
|
||||
* @return {boolean} Whether or not to draw the highlight for this location
|
||||
*/
|
||||
highlight(x, y) {
|
||||
let key = `${x},${y}`;
|
||||
if ( this.positions.has(key) ) return false;
|
||||
this.positions.add(key);
|
||||
return true;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
|
||||
/** @inheritdoc */
|
||||
clear() {
|
||||
this.positions = new Set();
|
||||
return super.clear();
|
||||
}
|
||||
|
||||
|
||||
/* -------------------------------------------- */
|
||||
|
||||
/** @inheritdoc */
|
||||
destroy(...args) {
|
||||
delete canvas.interface.grid.highlightLayers[this.name];
|
||||
return super.destroy(...args);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user