Skip to content

Commit

Permalink
Fix imprecise-detected token's identity being revealed by the combat …
Browse files Browse the repository at this point in the history
…tracker
  • Loading branch information
dev7355608 committed Aug 31, 2024
1 parent 4da15e9 commit 1fd2deb
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 3 deletions.
6 changes: 3 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": "2.3.2",
"version": "2.3.3",
"compatibility": {
"minimum": "12",
"verified": "12"
Expand Down Expand Up @@ -60,8 +60,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/v2.3.2/module.zip",
"changelog": "https://github.com/dev7355608/vision-5e/releases/tag/v2.3.2",
"download": "https://github.com/dev7355608/vision-5e/releases/download/v2.3.3/module.zip",
"changelog": "https://github.com/dev7355608/vision-5e/releases/tag/v2.3.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
54 changes: 54 additions & 0 deletions scripts/combat-tracker.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { DETECTION_LEVELS } from "./const.mjs";

export default (CombatTracker) => class extends CombatTracker {

/** @override */
_onCombatantHoverIn(event) {
event.preventDefault();

if (!canvas.ready) {
return;
}

const li = event.currentTarget;
const combatant = this.viewed.combatants.get(li.dataset.combatantId);
const token = combatant.token?.object;

if (token?.detectionLevel === DETECTION_LEVELS.PRECISE) {
if (!token.controlled) {
token._onHoverIn(event, { hoverOutOthers: true });
}

this._highlighted = token;
}
}

/** @override */
hoverCombatant(combatant, hover) {
const token = combatant.token.object;

if (token.detectionLevel !== DETECTION_LEVELS.PRECISE) {
hover = false;
}

const trackers = [this.element[0]];

if (this._popout) {
trackers.push(this._popout.element[0]);
}

for (const tracker of trackers) {
const li = tracker.querySelector(`.combatant[data-combatant-id="${combatant.id}"]`);

if (!li) {
continue;
}

if (hover) {
li.classList.add("hover");
} else {
li.classList.remove("hover");
}
}
}
};
4 changes: 4 additions & 0 deletions scripts/main.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import TokenConfigMixin from "./token-config.mjs";
import TokenDocumentMixin from "./token-document.mjs";
import TokenHUDMixin from "./token-hud.mjs";
import VisionSourceMixin from "./vision-source.mjs";
import CombatTrackerMixin from "./combat-tracker.mjs";
import DetectionModeBlindsense from "./detection-modes/blindsense.mjs";
import DetectionModeBlindsight from "./detection-modes/blindsight.mjs";
import DetectionModeBloodSense from "./detection-modes/blood-sense.mjs";
Expand Down Expand Up @@ -39,6 +40,9 @@ Hooks.once("init", () => {
// Extend PointVisionSource
CONFIG.Canvas.visionSourceClass = VisionSourceMixin(CONFIG.Canvas.visionSourceClass);

// Extend CombatTracker
CONFIG.ui.combat = CombatTrackerMixin(CONFIG.ui.combat);

// Register the Inaudible status effect
CONFIG.statusEffects.push({
id: "inaudible",
Expand Down

0 comments on commit 1fd2deb

Please sign in to comment.