Skip to content

Commit

Permalink
Update for 11.299
Browse files Browse the repository at this point in the history
  • Loading branch information
dev7355608 committed May 28, 2023
1 parent 2e0c087 commit fb3f676
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 64 deletions.
10 changes: 5 additions & 5 deletions module.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
"email": "dev7355608@gmail.com"
}
],
"version": "1.1.2",
"version": "1.1.3",
"compatibility": {
"minimum": "11.298",
"verified": "11.298"
"minimum": "11.299",
"verified": "11.299"
},
"scripts": [
"scripts/patches.js"
Expand Down Expand Up @@ -41,8 +41,8 @@
},
"url": "https://github.com/dev7355608/vision-5e",
"manifest": "https://github.com/dev7355608/vision-5e/releases/latest/download/module.json",
"download": "https://github.com/dev7355608/vision-5e/releases/download/v1.1.2/module.zip",
"changelog": "https://github.com/dev7355608/vision-5e/releases/tag/v1.1.2",
"download": "https://github.com/dev7355608/vision-5e/releases/download/v1.1.3/module.zip",
"changelog": "https://github.com/dev7355608/vision-5e/releases/tag/v1.1.3",
"bugs": "https://github.com/dev7355608/vision-5e/issues",
"readme": "https://raw.githubusercontent.com/dev7355608/vision-5e/main/README.md",
"license": "https://raw.githubusercontent.com/dev7355608/vision-5e/main/LICENSE"
Expand Down
103 changes: 44 additions & 59 deletions scripts/patches.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
VisionSource._initializeShaderKeys.push("deafened");

VisionSource.prototype._initialize = ((_initialize) => {
return function (data) {
_initialize.call(this, data);

data = this.data;

if (data.radius > 0) {
data.radius = Math.max(data.radius, data.externalRadius);
}

if (this.object instanceof Token) {
data.lightRadius ??= Math.clamped(this.object.lightPerceptionRange, 0, canvas.dimensions.maxR);
data.deafened ??= this.object.document.hasStatusEffect(CONFIG.specialStatusEffects.DEAF);
} else {
data.lightRadius ??= Infinity;
}
};
VisionSource.prototype._initialize = ((_initialize) => function (data) {
_initialize.call(this, data);

if (this.object instanceof Token) {
this.data.lightRadius = data.lightRadius ?? Math.clamped(this.object.lightPerceptionRange, 0, canvas.dimensions.maxR);
this.data.deafened = data.deafened ?? this.object.document.hasStatusEffect(CONFIG.specialStatusEffects.DEAF);
} else {
this.data.lightRadius = data.lightRadius ?? canvas.dimensions.maxR;
this.data.deafened = data.deafened ?? false;
}
})(VisionSource.prototype._initialize);

VisionSource.prototype._configure = function (changes) {
Expand All @@ -28,7 +21,7 @@ VisionSource.prototype._configure = function (changes) {
// Configure animation, if any
this.animation = {
animation: this.visionMode.animate,
seed: this.animation.seed ?? Math.floor(Math.random() * 100000)
seed: this.data.seed ?? this.animation.seed ?? Math.floor(Math.random() * 100000)
};

// Compute the light polygon
Expand Down Expand Up @@ -78,7 +71,6 @@ VisionSource.prototype._initializeVisionMode = function () {
Object.defineProperties(VisionSource.prototype, {
_createLightPolygon: {
value: function () {
if (this.data.disabled) return this.los;
const radius = this.data.lightRadius;
if (radius >= canvas.dimensions.maxR) return this.los;
const origin = { x: this.data.x, y: this.data.y };
Expand All @@ -93,9 +85,8 @@ Object.defineProperties(VisionSource.prototype, {
});

VisionSource.prototype._createRestrictedPolygon = function () {
if (this.data.disabled) return this.los;
const origin = { x: this.data.x, y: this.data.y };
const radius = this.data.radius > 0 ? this.data.radius : this.data.externalRadius;
const radius = this.data.radius || this.data.externalRadius;
const density = PIXI.Circle.approximateVertexDensity(radius);
if (!this.detectionMode.walls) {
const config = {
Expand All @@ -106,6 +97,7 @@ VisionSource.prototype._createRestrictedPolygon = function () {
useThreshold: false
};
if (!this.detectionMode.angle) config.angle = 360;
if (this.disabled) config.radius = 0;
return CONFIG.Canvas.polygonBackends[this.constructor.sourceType].create(origin, config);
}
if (!this.detectionMode.angle && this.data.angle !== 360) {
Expand All @@ -115,6 +107,7 @@ VisionSource.prototype._createRestrictedPolygon = function () {
density,
angle: 360
};
if (this.disabled) config.radius = 0;
return CONFIG.Canvas.polygonBackends[this.constructor.sourceType].create(origin, config);
}
const circle = new PIXI.Circle(origin.x, origin.y, radius);
Expand Down Expand Up @@ -295,7 +288,7 @@ CanvasVisibility.prototype.testVisibility = function (point, options = {}) {
}

// If no vision sources are present, the visibility is dependant of the type of user
if (!canvas.effects.visionSources.size) return game.user.isGM;
if (!canvas.effects.visionSources.some(s => s.active)) return game.user.isGM;

// Prepare an array of test points depending on the requested tolerance
const config = this._createTestConfig(point, options);
Expand Down Expand Up @@ -373,33 +366,12 @@ CanvasVisibility.prototype.testVisibility = function (point, options = {}) {
return false;
};

CanvasVisibility.prototype.restrictVisibility = function () {
// Activate or deactivate visual effects vision masking
canvas.effects.toggleMaskingFilters(this.visible);

// Tokens
for (let t of canvas.tokens.placeables) {
t.detectionFilter = undefined;
t.impreciseVisible = false;
t.visible = (!this.tokenVision && !t.document.hidden) || t.isVisible;
if (this.tokenVision && t.visible && canvas.effects.visionSources.get(t.sourceId)?.active && t.vision.detectionMode.imprecise) {
t.detectionFilter = DetectionModeLightPerception.getDetectionFilter();
}
if (canvas.tokens._highlight) t.renderFlags.set({ refreshState: true });
}

// Door Icons
for (let d of canvas.controls.doors.children) {
d.visible = !this.tokenVision || d.isVisible;
}

// Map Notes
for (let n of canvas.notes.placeables) {
n.visible = n.isVisible;
CanvasVisibility.prototype.restrictVisibility = ((restrictVisibility) => function () {
for (const token of canvas.tokens.placeables) {
token.impreciseVisible = false;
}
canvas.notes.hintMapNotes();
Hooks.callAll("sightRefresh", this);
};
return restrictVisibility.call(this);
})(CanvasVisibility.prototype.restrictVisibility);

Hooks.on("drawCanvasVisibility", (layer) => {
const vision = layer.vision;
Expand Down Expand Up @@ -491,6 +463,23 @@ TokenDocument.prototype._prepareDetectionModes = function () {
};

Object.defineProperties(Token.prototype, {
isVisible: {
get: ((isVisible) => function () {
this.detectionFilter = undefined;
this.impreciseVisible = false;
const visible = isVisible.call(this);
if (visible
&& canvas.effects.visibility.tokenVision
&& canvas.effects.visionSources.get(this.sourceId)?.active
&& this.vision.detectionMode.imprecise) {
this.detectionFilter = DetectionModeLightPerception.getDetectionFilter();
this.impreciseVisible = false;
}
return visible;
})(Object.getOwnPropertyDescriptor(Token.prototype, "isVisible").get),
configurable: true,
enumerable: false
},
lightPerceptionRange: {
get() {
return this.getLightRadius(this.document.detectionModes.find(m => m.id === DetectionMode.LIGHT_MODE_ID && m.enabled)?.range ?? 0);
Expand Down Expand Up @@ -574,17 +563,13 @@ Object.defineProperties(Token.prototype, {
}
});

Token.prototype._onApplyStatusEffect = ((_onApplyStatusEffect) => {
return function (statusId, active) {
_onApplyStatusEffect.call(this, statusId, active);

if (statusId === CONFIG.specialStatusEffects.DEAF) {
canvas.perception.update({ initializeVision: true });
} else if (statusId === CONFIG.specialStatusEffects.INAUDIBLE) {
canvas.perception.update({ refreshVision: true });
}
};
})(Token.prototype._onApplyStatusEffect);
Hooks.on("applyTokenStatusEffect", (token, statusId, active) => {
if (statusId === CONFIG.specialStatusEffects.DEAF) {
canvas.perception.update({ initializeVision: true });
} else if (statusId === CONFIG.specialStatusEffects.INAUDIBLE) {
canvas.perception.update({ refreshVision: true });
}
});

Hooks.on("refreshToken", (token) => {
const mesh = token._impreciseMesh;
Expand Down

0 comments on commit fb3f676

Please sign in to comment.