Skip to content

Commit

Permalink
Update for 11.298
Browse files Browse the repository at this point in the history
  • Loading branch information
dev7355608 committed May 18, 2023
1 parent 9b78add commit 2e0c087
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 47 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.1",
"version": "1.1.2",
"compatibility": {
"minimum": "11.297",
"verified": "11.297"
"minimum": "11.298",
"verified": "11.298"
},
"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.1/module.zip",
"changelog": "https://github.com/dev7355608/vision-5e/releases/tag/v1.1.1",
"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",
"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
10 changes: 6 additions & 4 deletions scripts/automation.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,18 @@ const resetActiveTokens = (() => {
})();

Hooks.once("init", () => {
CONFIG.Actor.documentClass = class Actor5e extends CONFIG.Actor.documentClass {
#senses = {};
const SENSES = Symbol("senses");

CONFIG.Actor.documentClass = class Actor5e extends CONFIG.Actor.documentClass {
/** @override */
prepareData() {
super.prepareData();

const senses = this[SENSES] ??= {};

for (const [key, value] of Object.entries(this.system.attributes.senses)) {
if (this.#senses[key] !== value) {
this.#senses = { ...this.system.attributes.senses };
if (senses[key] !== value) {
this[SENSES] = { ...this.system.attributes.senses };
resetActiveTokens(this);

break;
Expand Down
12 changes: 2 additions & 10 deletions scripts/detection-modes/see-invisibility.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,7 @@ export class DetectionModeSeeInvisibility extends DetectionMode {
effects = document.effects;
document.effects = effects.filter(e => e !== icon);
} else {
effects = document.actor.appliedEffects.filter(e => e.statuses.has(statusId));

for (const effect of effects) {
effect.statuses.delete(statusId);
}
document.actor.statuses.delete(statusId);
}

return effects;
Expand All @@ -139,11 +135,7 @@ export class DetectionModeSeeInvisibility extends DetectionMode {
if (!document.actor) {
document.effects = effects;
} else {
const statusId = CONFIG.specialStatusEffects.INVISIBLE;

for (const effect of effects) {
effect.statuses.add(statusId);
}
document.actor.statuses.add(CONFIG.specialStatusEffects.INVISIBLE);
}
}
}
64 changes: 36 additions & 28 deletions scripts/patches.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ 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 @@ -92,6 +93,7 @@ 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 density = PIXI.Circle.approximateVertexDensity(radius);
Expand Down Expand Up @@ -222,12 +224,7 @@ class DetectionModeLightPerception extends DetectionMode {
_testPoint(visionSource, mode, target, test) {
if (!super._testPoint(visionSource, mode, target, test)) return false;
for (const lightSource of canvas.effects.lightSources) {
if (!lightSource.active) {
if (lightSource.hasActiveLayer) continue;
if (this.disabled) continue;
if (!canvas.darknessLevel.between(lightSource.data.darkness.min, lightSource.data.darkness.max)) continue;
if (lightSource instanceof GlobalLightSource && !canvas.effects.illumination.globalLight) continue;
}
if (lightSource.disabled) continue;
if (lightSource.shape.contains(test.point.x, test.point.y)) return true;
}
return false;
Expand All @@ -241,22 +238,29 @@ CONFIG.Canvas.detectionModes.lightPerception = new DetectionModeLightPerception(
});

CanvasVisibility.prototype.refreshVisibility = ((refreshVisibility) => {
const TRUE = new Boolean(true);
const FALSE = new Boolean(false);
return function () {
this.vision?.imprecise.clear();
this.vision?.sight.clear();

const visionSources = canvas.effects.visionSources;

for (const visionSource of visionSources) {
if (visionSource.data.radius === 0) {
visionSource.data.radius = Number.MIN_VALUE;
const blinded = visionSource.visionMode === CONFIG.Canvas.visionModes.blindness
|| visionSource.detectionMode.imprecise;

if (visionSource.data.blinded === !blinded) {
visionSource.data.blinded = blinded ? TRUE : FALSE;
}
}

refreshVisibility.call(this);

for (const visionSource of visionSources) {
if (visionSource.data.radius === Number.MIN_VALUE) {
visionSource.data.radius = 0;
if (visionSource.data.blinded === TRUE) {
visionSource.data.blinded = false;
} else if (visionSource.data.blinded === FALSE) {
visionSource.data.blinded = true;
}
}
};
Expand Down Expand Up @@ -378,7 +382,7 @@ CanvasVisibility.prototype.restrictVisibility = function () {
t.detectionFilter = undefined;
t.impreciseVisible = false;
t.visible = (!this.tokenVision && !t.document.hidden) || t.isVisible;
if (this.tokenVision && t.visible && canvas.effects.visionSources.has(t.sourceId) && t.vision.detectionMode.imprecise) {
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 });
Expand All @@ -400,8 +404,8 @@ CanvasVisibility.prototype.restrictVisibility = function () {
Hooks.on("drawCanvasVisibility", (layer) => {
const vision = layer.vision;

vision.imprecise = vision.addChild(new PIXI.LegacyGraphics());
vision.imprecise.blendMode = PIXI.BLEND_MODES.MAX_COLOR;
vision.sight = vision.addChild(new PIXI.LegacyGraphics());
vision.sight.blendMode = PIXI.BLEND_MODES.MAX_COLOR;

vision.mask = null;
vision.fov.mask = vision.los;
Expand All @@ -414,11 +418,7 @@ Hooks.on("drawCanvasVisibility", (layer) => {
const source = shape.config.source;

if (source instanceof VisionSource) {
if (source.detectionMode.imprecise || source.data.radius <= Number.MIN_VALUE) {
graphics = vision.imprecise;
} else {
graphics = vision.base;
}
graphics = vision.sight;
}
}

Expand Down Expand Up @@ -457,16 +457,24 @@ Hooks.on("drawCanvasVisibility", (layer) => {
configurable: true,
writable: true
});
});

FogManager.prototype.commit = ((commit) => {
return function () {
const vision = canvas.effects.visibility.vision;
vision.imprecise.visible = false;
commit.call(this);
vision.imprecise.visible = true;
}
})(FogManager.prototype.commit);
Object.defineProperty(vision.los.preview, "drawShape", {
value: function (shape) {
if (shape instanceof PointSourcePolygon) {
const source = shape.config.source;

if (source instanceof VisionSource) {
shape = source.light;
}
}

return Object.getPrototypeOf(this).drawShape.call(this, shape);
},
enumerable: false,
configurable: true,
writable: true
});
});

TokenDocument.prototype._prepareDetectionModes = function () {
if (!this.sight.enabled) return;
Expand Down

0 comments on commit 2e0c087

Please sign in to comment.