-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsensor-sight.js
More file actions
25 lines (22 loc) · 966 Bytes
/
Copy pathsensor-sight.js
File metadata and controls
25 lines (22 loc) · 966 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
'use strict';
import {libWrapper} from './module/shim.js';
Hooks.once('setup', () => {
libWrapper.register('sensor-sight', 'SightLayer.prototype.testVisibility', function (w, point, {tolerance=2, object=null}={}) {
// default logic
let r = w.apply(this, [point, {tolerance, object}]);
// is this within sensor range of any controlled token?
let s = canvas.tokens.controlled.reduce((a, t) => {
return a || inSensorRange(t, point);
}, false);
return r || s;
});
});
function inSensorRange(token, point) {
const sensors = token.actor.data.data.mech?.sensors
if (sensors === undefined) return false;
const range = Math.sqrt((token.x - point.x) * (token.x - point.x) + (token.y - point.y) * (token.y - point.y));
const scale = canvas.scene.data.gridType > 1 ? Math.sqrt(3) / 2 : 1;// Adjust the measurment on hexes
const grid = canvas.scene.data.grid;
return (sensors + .6) * grid * scale > range;
console.log(range);
}