Skip to content

Commit

Permalink
V12 (#133)
Browse files Browse the repository at this point in the history
  • Loading branch information
Eligarf authored May 20, 2024
1 parent 9bb959f commit 6bccf16
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 95 deletions.
3 changes: 3 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# v4.0.7
* v12 compatability

# v4.0.6
* Handle tokens without skills (like vehicles)

Expand Down
4 changes: 2 additions & 2 deletions module.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
"flags": {}
}
],
"version": "4.0.2",
"version": "4.1",
"compatibility": {
"minimum": "10.291",
"verified": "11.315"
"verified": "12.323"
},
"relationships": {
"systems": [
Expand Down
50 changes: 31 additions & 19 deletions scripts/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ export default class Engine {


this.warnedMissingCE = false;

this.defaultDetectionModes = [
'basicSight',
'lightPerception',
'seeAll',
'seeInvisibility',
];

Hooks.once('setup', () => {
this.hiddenName = game.i18n.localize(game.settings.get(Stealthy.MODULE_ID, 'hiddenLabel'));
this.spotName = game.i18n.localize(game.settings.get(Stealthy.MODULE_ID, 'spotLabel'));
Expand All @@ -33,25 +41,29 @@ export default class Engine {
}

patchFoundry() {
// Generic Detection mode patching
const mode = 'detectionMode';
console.log(...Stealthy.colorizeOutput(`patching ${mode}`));
libWrapper.register(
Stealthy.MODULE_ID,
'DetectionMode.prototype._canDetect',
function (wrapped, visionSource, target) {
if (!(wrapped(visionSource, target))) return false;
const engine = stealthy.engine;
if (target instanceof DoorControl)
return engine.canSpotDoor(target, visionSource);
const tgtToken = target?.document;
if (tgtToken instanceof TokenDocument)
return engine.checkDispositionAndCanDetect(visionSource, tgtToken, mode);
return true;
},
libWrapper.MIXED,
{ perf_mode: libWrapper.PERF_FAST }
);
// Defaults are the allowed for the time being
const allowedModes = this.defaultDetectionModes;

const sightModes = allowedModes.filter((m) => m in CONFIG.Canvas.detectionModes);
for (const mode of sightModes) {
Stealthy.log(`patching ${mode}`);
libWrapper.register(
Stealthy.MODULE_ID,
`CONFIG.Canvas.detectionModes.${mode}._canDetect`,
function (wrapped, visionSource, target) {
if (!(wrapped(visionSource, target))) return false;
const engine = stealthy.engine;
if (target instanceof DoorControl)
return engine.canSpotDoor(target, visionSource);
const tgtToken = target?.document;
if (tgtToken instanceof TokenDocument)
return engine.checkDispositionAndCanDetect(visionSource, tgtToken, mode);
return true;
},
libWrapper.MIXED,
{ perf_mode: libWrapper.PERF_FAST }
);
}
}

// deprecated
Expand Down
4 changes: 3 additions & 1 deletion scripts/stealthy.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ export class Stealthy {
constructor(engine) {
this.engine = engine;
this.socket = null;
this.engine.patchFoundry();
Hooks.once('setup', () => {
this.engine.patchFoundry();
this.socket = socketlib.registerModule(Stealthy.MODULE_ID);
this.socket.register('TogglePerceptionBanking', this.togglePerceptionBanking);
this.socket.register('GetPerceptionBanking', this.getPerceptionBanking);
Expand All @@ -25,10 +25,12 @@ export class Stealthy {
}

async bankPerception(token, value) {
Stealthy.log(`stealthy.bankPerception`, { token, value });
await this.engine.bankPerception(token, value);
}

async bankStealth(token, value) {
Stealthy.log(`stealthy.bankStealth`, { token, value });
await this.engine.bankStealth(token, value);
}

Expand Down
51 changes: 10 additions & 41 deletions scripts/systems/dnd5e.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ class Engine5e extends Engine {
constructor() {
super();

if (game.modules.get("vision-5e")?.active) {
this.defaultDetectionModes.push(
'devilsSight',
'etherealSight',
'hearing',
'witchSight'
);
}

game.keybindings.register(Stealthy.MODULE_ID, "endTurn", {
name: game.i18n.localize("stealthy.dnd5e.endTurn.name"),
hint: game.i18n.localize("stealthy.dnd5e.endTurn.hint"),
Expand Down Expand Up @@ -90,46 +99,6 @@ class Engine5e extends Engine {
});
}

patchFoundry() {
super.patchFoundry();

// If vision-5e isn't active, just keep the default behavior
if (!game.modules.get("vision-5e")?.active) return;

// Pick the sight modes in vision-5e that we want Stealthy to affect
Hooks.once('setup', () => {
const sightModes = [
'basicSight',
'devilsSight',
'etherealSight',
'hearing',
'lightPerception',
'seeAll',
'seeInvisibility',
'witchSight',
];
for (const mode of sightModes) {
Stealthy.log(`patching ${mode}`);
libWrapper.register(
Stealthy.MODULE_ID,
`CONFIG.Canvas.detectionModes.${mode}._canDetect`,
function (wrapped, visionSource, target) {
if (!(wrapped(visionSource, target))) return false;
const engine = stealthy.engine;
if (target instanceof DoorControl)
return engine.canSpotDoor(target, visionSource);
const tgtToken = target?.document;
if (tgtToken instanceof TokenDocument)
return engine.checkDispositionAndCanDetect(visionSource, tgtToken, mode);
return true;
},
libWrapper.MIXED,
{ perf_mode: libWrapper.PERF_FAST }
);
}
});
}

static LIGHT_LABELS = ['dark', 'dim', 'bright', 'bright'];
static EXPOSURE = { dark: 0, dim: 1, bright: 2 };

Expand All @@ -150,7 +119,7 @@ class Engine5e extends Engine {
const perceptionPair = perceptionFlag?.perception;
const perceptionValue = (game.settings.get(Stealthy.MODULE_ID, 'perceptionDisadvantage'))
? this.adjustForLightingConditions({ perceptionPair, visionSource, source, tgtToken, detectionMode })
: this.adjustForDefaultConditions({ perceptionPair, visionSource, source, tgtToken, detectionMode })
: this.adjustForDefaultConditions({ perceptionPair, visionSource, source, tgtToken, detectionMode });

Stealthy.logIfDebug(`${detectionMode} vs '${tgtToken.name}': ${perceptionValue} vs ${stealthValue}`, { stealthFlag, perceptionFlag });
return perceptionValue > stealthValue;
Expand Down
32 changes: 0 additions & 32 deletions scripts/systems/pf1.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,38 +34,6 @@ export class EnginePF1 extends Engine {
});
}

patchFoundry() {
super.patchFoundry();

// Pick the sight modes in vision-5e that we want Stealthy to affect
// Hooks.once('setup', () => {
const sightModes = [
'basicSight',
'seeAll',
'seeInvisibility',
];
for (const mode of sightModes) {
console.log(`patching ${mode}`);
libWrapper.register(
Stealthy.MODULE_ID,
`CONFIG.Canvas.detectionModes.${mode}._canDetect`,
function (wrapped, visionSource, target) {
if (!(wrapped(visionSource, target))) return false;
const engine = stealthy.engine;
if (target instanceof DoorControl)
return engine.canSpotDoor(target, visionSource);
const tgtToken = target?.document;
if (tgtToken instanceof TokenDocument)
return engine.checkDispositionAndCanDetect(visionSource, tgtToken, mode);
return true;
},
libWrapper.MIXED,
{ perf_mode: libWrapper.PERF_FAST }
);
}
// });
}

async setValueInEffect(flag, skill, value, sourceEffect) {
const token = flag.token;
let effect = duplicate(sourceEffect);
Expand Down

0 comments on commit 6bccf16

Please sign in to comment.