This repository has been archived by the owner on Oct 28, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
no-summon-vision.js
103 lines (92 loc) · 4.14 KB
/
no-summon-vision.js
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
Hooks.on("init", () => {
patch_SightLayer_updateToken();
});
function patch_SightLayer_updateToken() {
// This code copied from SightLayer#updateToken, foundry.js:32457, Foundry version 0.6.5
SightLayer.prototype.updateToken = function (
token,
{ defer = false, deleted = false, walls = null, forceUpdateFog = false } = {}
) {
let sourceId = `Token.${token.id}`;
this.sources.vision.delete(sourceId);
this.sources.lights.delete(sourceId);
if (deleted) return defer ? null : this.update();
if (token.data.hidden && !game.user.isGM) return;
// Vision is displayed if the token is controlled, or if it is observed by a player with no tokens controlled
let displayVision = token._controlled;
if (!displayVision && !game.user.isGM && /* CHANGED */ canvas.tokens.controlled.every((t) => !t.data.vision)) {
displayVision = token.actor && token.actor.hasPerm(game.user, "OBSERVER");
}
// Take no action for Tokens which are invisible or Tokens that have no sight or light
const globalLight = canvas.scene.data.globalLight;
let isVisionSource = this.tokenVision && token.hasSight && displayVision;
let isLightSource = token.emitsLight;
// If the Token is no longer a source, we don't need further work
if (!isVisionSource && !isLightSource) return;
// Prepare some common data
const center = token.getSightOrigin();
const maxR = globalLight ? Math.max(canvas.dimensions.width, canvas.dimensions.height) : null;
let [cullMult, cullMin, cullMax] = this._cull;
if (globalLight) cullMin = maxR;
// Prepare vision sources
if (isVisionSource) {
// Compute vision polygons
let dim = globalLight ? 0 : token.getLightRadius(token.data.dimSight);
const bright = globalLight ? maxR : token.getLightRadius(token.data.brightSight);
if (dim === 0 && bright === 0) dim = canvas.dimensions.size * 0.6;
const radius = Math.max(Math.abs(dim), Math.abs(bright));
const { los, fov } = this.constructor.computeSight(center, radius, {
angle: token.data.sightAngle,
cullMult: cullMult,
cullMin: cullMin,
cullMax: cullMax,
density: 6,
rotation: token.data.rotation,
walls: walls,
});
// Add a vision source
const source = new SightLayerSource({
x: center.x,
y: center.y,
los: los,
fov: fov,
dim: dim,
bright: bright,
});
this.sources.vision.set(sourceId, source);
// Update fog exploration for the token position
this.updateFog(center.x, center.y, Math.max(dim, bright), token.data.sightAngle !== 360, forceUpdateFog);
}
// Prepare light sources
if (isLightSource) {
// Compute light emission polygons
const dim = token.getLightRadius(token.data.dimLight);
const bright = token.getLightRadius(token.data.brightLight);
const radius = Math.max(Math.abs(dim), Math.abs(bright));
const { fov } = this.constructor.computeSight(center, radius, {
angle: token.data.lightAngle,
cullMult: cullMult,
cullMin: cullMin,
cullMax: cullMax,
density: 6,
rotation: token.data.rotation,
walls: walls,
});
// Add a light source
const source = new SightLayerSource({
x: center.x,
y: center.y,
los: null,
fov: fov,
dim: dim,
bright: bright,
color: token.data.lightColor,
alpha: token.data.lightAlpha,
});
this.sources.lights.set(sourceId, source);
}
// Maybe update
if (CONFIG.debug.sight) console.debug(`Updated SightLayer source for ${sourceId}`);
if (!defer) this.update();
};
}