Skip to content

Commit

Permalink
Add compatibility with Stealthy
Browse files Browse the repository at this point in the history
  • Loading branch information
dev7355608 committed Jun 11, 2023
1 parent cbb1b04 commit da3fdb3
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 3 deletions.
7 changes: 4 additions & 3 deletions module.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"email": "[email protected]"
}
],
"version": "1.1.4",
"version": "1.2.0",
"compatibility": {
"minimum": "11.299",
"verified": "11.301"
Expand All @@ -18,6 +18,7 @@
],
"esmodules": [
"scripts/automation.mjs",
"scripts/compatibility.mjs",
"scripts/config.mjs",
"scripts/hud.mjs"
],
Expand Down Expand Up @@ -45,8 +46,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.4/module.zip",
"changelog": "https://github.com/dev7355608/vision-5e/releases/tag/v1.1.4",
"download": "https://github.com/dev7355608/vision-5e/releases/download/v1.2.0/module.zip",
"changelog": "https://github.com/dev7355608/vision-5e/releases/tag/v1.2.0",
"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
64 changes: 64 additions & 0 deletions scripts/compatibility.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { DetectionModeDarkvision } from "./detection-modes/darkvision.mjs";

Hooks.once("init", () => {
if (!game.modules.get("stealthy")?.active) {
return;
}

Hooks.once("setup", () => {
stealthy.engine.basicVision = function (wrapped, visionSource, mode, config) {
return wrapped(visionSource, mode, config);
};

libWrapper.register(
"vision-5e",
"DetectionMode.prototype.testVisibility",
function (wrapped, testHidden, visionSource, mode, config = {}) {
if (testHidden[this.id] && stealthy.engine.isHidden(visionSource, config.object)) return false;
return wrapped(visionSource, mode, config);
},
libWrapper.MIXED,
{
bind: [Object.freeze({
blindsight: true,
devilsSight: true,
echolocation: true,
feelTremor: true,
ghostlyGaze: true,
hearing: true,
lightPerception: true,
seeAll: true
})],
perf_mode: libWrapper.PERF_FAST
}
);

const updateFriendlyUmbralSight = () => {
const friendlyUmbralSight = game.settings.get("stealthy", "friendlyUmbralSight");
const ignoreFriendlyUmbralSight = friendlyUmbralSight === "ignore"
|| friendlyUmbralSight === "inCombat" && !game.combat?.round;

if (DetectionModeDarkvision.friendlyUmbralSight === ignoreFriendlyUmbralSight) {
DetectionModeDarkvision.friendlyUmbralSight = !ignoreFriendlyUmbralSight;

if (canvas.ready) {
canvas.perception.refresh({ refreshVision: true });
}
}
};

updateFriendlyUmbralSight();

for (const hook of ["createSetting", "updateSetting", "deleteSetting"]) {
Hooks.on(hook, (setting) => {
if (setting.key === "stealthy.friendlyUmbralSight") {
updateFriendlyUmbralSight();
}
});
}

for (const hook of ["createCombat", "updateCombat", "deleteCombat"]) {
Hooks.on(hook, updateFriendlyUmbralSight);
}
});
});

0 comments on commit da3fdb3

Please sign in to comment.