Skip to content

Commit

Permalink
Disambiguate version naming in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Eligarf committed Jun 29, 2024
1 parent 4444153 commit 392b5c4
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 33 deletions.
4 changes: 4 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# v4.3.2
* Fix module.json warning
* Disambiguate version naming in tests

# v4.3.1
* Fix Roll.evaluate warning in V12
* Update pt-BR.json (thanks Kharmans)
Expand Down
3 changes: 0 additions & 3 deletions module.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,6 @@
"flags": {}
}
],
"templates": [
"templates/detectionModes.hbs"
],
"socket": true,
"url": "https://github.com/Eligarf/stealthy",
"manifest": "replaced",
Expand Down
8 changes: 4 additions & 4 deletions scripts/doors.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ export default class Doors {
Stealthy.MODULE_ID,
"WallConfig.prototype._updateObject",
async function (wrapped, event, formData) {
const v10 = Math.floor(game.version) < 11;
const beforeV11 = Math.floor(game.version) < 11;
let result = await wrapped(event, formData);
Stealthy.log('WallConfig.prototype._updateObject', { me: this, event, formData, result });
if (v10) {
if (beforeV11) {
if (result) result = Doors.UpdateHiddenDoor(this, formData);
} else {
result = Doors.UpdateHiddenDoor(this, formData);
Expand Down Expand Up @@ -49,8 +49,8 @@ export default class Doors {
static RenderHiddenDoor(wallConfig, html, css) {
Stealthy.log('RenderHiddenDoor', { wallConfig, html, css });
if (css.document.door == 1) {
const v10 = Math.floor(game.version) < 11;
if (v10) {
const beforeV11 = Math.floor(game.version) < 11;
if (beforeV11) {
const hiddenDoorBlock = `
<fieldset>
<legend><i class="fa-solid fa-piggy-bank"></i> Stealthy</legend>
Expand Down
24 changes: 12 additions & 12 deletions scripts/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,13 +238,13 @@ export default class Engine {
}

findHiddenEffect(actor) {
const v10 = Math.floor(game.version) < 11;
return actor?.effects.find((e) => !e.disabled && this.hiddenName === (v10 ? e.label : e.name));
const beforeV11 = Math.floor(game.version) < 11;
return actor?.effects.find((e) => !e.disabled && this.hiddenName === (beforeV11 ? e.label : e.name));
}

findSpotEffect(actor) {
const v10 = Math.floor(game.version) < 11;
return actor?.effects.find((e) => !e.disabled && this.spotName === (v10 ? e.label : e.name));
const beforeV11 = Math.floor(game.version) < 11;
return actor?.effects.find((e) => !e.disabled && this.spotName === (beforeV11 ? e.label : e.name));
}

makeHiddenEffectMaker(name) {
Expand Down Expand Up @@ -290,15 +290,15 @@ export default class Engine {
}

async updateOrCreateEffect({ name, actor, flag, source, makeEffect }) {
const v10 = Math.floor(game.version) < 11;
let effect = actor.effects.find((e) => name === (v10 ? e.label : e.name));
const beforeV11 = Math.floor(game.version) < 11;
let effect = actor.effects.find((e) => name === (beforeV11 ? e.label : e.name));

if (!effect) {
// See if we can source from outside
if (source === 'ce') {
if (game.dfreds?.effectInterface?.findEffectByName(name)) {
await game.dfreds.effectInterface.addEffect({ effectName: name, uuid: actor.uuid });
effect = actor.effects.find((e) => name === (v10 ? e.label : e.name));
effect = actor.effects.find((e) => name === (beforeV11 ? e.label : e.name));
}
if (!effect && !this.warnedMissingCE) {
this.warnedMissingCE = true;
Expand All @@ -311,7 +311,7 @@ export default class Engine {
else if (source === 'clt') {
if (game.clt?.getCondition(name)) {
await game.clt.applyCondition(name, actor);
effect = actor.effects.find(e => name === (v10 ? e.label : e.name));
effect = actor.effects.find(e => name === (beforeV11 ? e.label : e.name));
}
if (!effect && !this.warnedMissingCLT) {
this.warnedMissingCLT = true;
Expand Down Expand Up @@ -406,10 +406,10 @@ export default class Engine {

// Hidden doors can only be spotted if they are in range
const maxRange = stealthyFlags?.maxRange ?? Infinity;
const v12 = Math.floor(game.version) >= 12;
const distance = (v12)
? canvas.grid.measurePath([visionSource.object.center, doorControl.center]).distance
: canvas.grid.measureDistance(visionSource.object.center, doorControl.center);
const beforeV12 = Math.floor(game.version) < 12;
const distance = (beforeV12)
? canvas.grid.measureDistance(visionSource.object.center, doorControl.center)
: canvas.grid.measurePath([visionSource.object.center, doorControl.center]).distance;

if (distance > maxRange) return false;

Expand Down
12 changes: 6 additions & 6 deletions scripts/stealthy.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ export class Stealthy {
this.socket.register('GetPerceptionBanking', this.getPerceptionBanking);
this.socket.register('RefreshPerception', this.refreshPerception);
});
const v11 = Math.floor(game.version) < 12;
if (v11) {
const beforeV12 = Math.floor(game.version) < 12;
if (beforeV12) {
this.refreshOptions = {
refreshLighting: true,
refreshVision: true,
refreshSounds: true
refreshSounds: true,
};
} else {
this.refreshOptions = {
refreshLighting: true,
refreshVision: true,
refreshSounds: true,
refreshOcclusion: true
refreshOcclusion: true,
};
}
}
Expand Down Expand Up @@ -55,12 +55,12 @@ export class Stealthy {
if (toggled || !game.user.isGM)
return;

const v10 = Math.floor(game.version) < 11;
const beforeV11 = Math.floor(game.version) < 11;
const name = game.i18n.localize('stealthy.spot.name');
let updates = [];
for (let token of canvas.tokens.placeables) {
const actor = token.actor;
const spot = actor.effects.find((e) => name === (v10 ? e.label : e.name));
const spot = actor.effects.find((e) => name === (beforeV11 ? e.label : e.name));
if (spot) {
actor.deleteEmbeddedDocuments('ActiveEffect', [spot.id]);
}
Expand Down
16 changes: 8 additions & 8 deletions scripts/systems/pf1.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,13 @@ export class EnginePF1 extends Engine {
}

findHiddenEffect(actor) {
const v10 = Math.floor(game.version) < 11;
return actor?.items.find((i) => i.system.active && (v10 ? i.label : i.name) === 'Hidden');
const beforeV11 = Math.floor(game.version) < 11;
return actor?.items.find((i) => i.system.active && (beforeV11 ? i.label : i.name) === 'Hidden');
}

findSpotEffect(actor) {
const v10 = Math.floor(game.version) < 11;
return actor?.items.find((i) => i.system.active && (v10 ? i.label : i.name) === 'Spot');
const beforeV11 = Math.floor(game.version) < 11;
return actor?.items.find((i) => i.system.active && (beforeV11 ? i.label : i.name) === 'Spot');
}

makeHiddenEffectMaker(name) {
Expand All @@ -123,8 +123,8 @@ export class EnginePF1 extends Engine {

async updateOrCreateHiddenEffect(actor, flag) {
let hidden = this.findHiddenEffect(actor);
const v10 = Math.floor(game.version) < 11;
hidden ??= actor?.items.find((i) => (v10 ? i.label : i.name) === 'Hidden');
const beforeV11 = Math.floor(game.version) < 11;
hidden ??= actor?.items.find((i) => (beforeV11 ? i.label : i.name) === 'Hidden');
if (!hidden) {
const effect = {
"name": "Hidden",
Expand Down Expand Up @@ -154,8 +154,8 @@ export class EnginePF1 extends Engine {
let spot = this.findSpotEffect(actor);

// PF1 buffs can be disabled, if so, look for one already on the actor
const v10 = Math.floor(game.version) < 11;
spot ??= actor?.items.find((i) => (v10 ? i.label : i.name) === 'Spot');
const beforeV11 = Math.floor(game.version) < 11;
spot ??= actor?.items.find((i) => (beforeV11 ? i.label : i.name) === 'Spot');
if (!spot) {
const effect = {
"name": "Spot",
Expand Down

0 comments on commit 392b5c4

Please sign in to comment.