Skip to content

Commit

Permalink
Use img not icon in V12 AEs
Browse files Browse the repository at this point in the history
  • Loading branch information
Eligarf committed Jul 9, 2024
1 parent f1312d6 commit c4a062e
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 15 deletions.
3 changes: 3 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# v4.5.2
* use 'img' instead of 'icon' for V12 active effects

# v4.5.1
* Update pt-BR.json (thanks Kharmans)
* Add ru.json to module.json
Expand Down
54 changes: 48 additions & 6 deletions scripts/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,40 @@ import { Stealthy } from "./stealthy.js";
import Doors from "./doors.js";
import { DetectionModesApplicationClass } from "./detectionModesMenu.js";

// return true if 'installed' (considered as a JRE version string) is
// greater than or equal to 'required' (again, a JRE version string).
function versionAtLeast(version, target) {

var a = version.split('.');
var b = target.split('.');

for (var i = 0; i < a.length; ++i) {
a[i] = Number(a[i]);
}
for (var i = 0; i < b.length; ++i) {
b[i] = Number(b[i]);
}
if (a.length == 2) {
a[2] = 0;
}

if (a[0] > b[0]) return true;
if (a[0] < b[0]) return false;

if (a[1] > b[1]) return true;
if (a[1] < b[1]) return false;

if (a[2] > b[2]) return true;
if (a[2] < b[2]) return false;

return true;
}

function migrate(moduleVersion, oldVersion) {
// ui.notifications.warn(`Updated Stealthy from ${oldVersion} to ${moduleVersion}`);
return moduleVersion;
}

export default class Engine {

constructor() {
Expand Down Expand Up @@ -93,6 +127,9 @@ export default class Engine {
}

getSettingsParameters(version) {
const module = game.modules.get(Stealthy.MODULE_ID);
const moduleVersion = module.version;

let sources = {
'none': "stealthy.source.min",
'ae': "stealthy.source.ae",
Expand Down Expand Up @@ -260,11 +297,12 @@ export default class Engine {
scope: 'world',
config: true,
type: String,
default: version,
default: '',
onChange: value => {
Stealthy.log(`Changing schema value to ${value}`);
const newValue = migrate(moduleVersion, value);
if (value != newValue) {
game.settings.set(MODULE_ID, 'schema', newValue);
game.settings.set(Stealthy.MODULE_ID, 'schema', newValue);
}
}
},
Expand Down Expand Up @@ -487,15 +525,17 @@ export default class Engine {
makeStealthEffectMaker(name) {
return (flag, source) => {
let effect = {
icon: game.settings.get(Stealthy.MODULE_ID, 'hiddenIcon'),
description: game.i18n.localize("stealthy.hidden.description"),
flags: {
stealthy: flag,
},
statuses: [name.toLowerCase()],
changes: [],
};
effect[(Math.floor(game.version) < 11) ? 'label' : 'name'] = name;
const beforeV11 = Math.floor(game.version) < 11;
effect[beforeV11 ? 'label' : 'name'] = name;
const beforeV12 = Math.floor(game.version) < 12;
effect[beforeV12 ? 'icon' : 'img'] = game.settings.get(Stealthy.MODULE_ID, 'hiddenIcon');

if (source === 'ae') {
if (typeof ATLUpdate !== 'undefined') {
Expand All @@ -513,14 +553,16 @@ export default class Engine {
makePerceptionEffectMaker(name) {
return (flag, source) => {
let effect = {
icon: game.settings.get(Stealthy.MODULE_ID, 'spotIcon'),
description: game.i18n.localize("stealthy.spot.description"),
flags: {
stealthy: flag,
},
statuses: ['spot'],
};
effect[(Math.floor(game.version) < 11) ? 'label' : 'name'] = name;
const beforeV11 = Math.floor(game.version) < 11;
effect[beforeV11 ? 'label' : 'name'] = name;
const beforeV12 = Math.floor(game.version) < 12;
effect[beforeV12 ? 'icon' : 'img'] = game.settings.get(Stealthy.MODULE_ID, 'spotIcon');

return effect;
};
Expand Down
11 changes: 3 additions & 8 deletions scripts/hooks.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import { Stealthy } from "./stealthy.js";

function migrate(moduleVersion, oldVersion) {

// ui.notifications.warn(`Updated Stealthy from ${oldVersion} to ${moduleVersion}`);
return moduleVersion;
}

Hooks.once('setup', () => {
const module = game.modules.get(Stealthy.MODULE_ID);
const moduleVersion = module.version;
Expand All @@ -15,8 +9,9 @@ Hooks.once('setup', () => {

const schemaVersion = game.settings.get(Stealthy.MODULE_ID, 'schema');
if (schemaVersion !== moduleVersion) {
Stealthy.log(`Found schema version ${schemaVersion}`);
Hooks.once('ready', () => {
game.settings.set(Stealthy.MODULE_ID, 'schema', migrate(moduleVersion, schemaVersion));
game.settings.set(Stealthy.MODULE_ID, 'schema', moduleVersion);
});
}

Expand Down Expand Up @@ -110,7 +105,7 @@ Hooks.on('getSceneControlButtons', (controls) => {
Hooks.on('renderSettingsConfig', (app, html, data) => {
const sections = [
{ label: "general", before: "friendlyStealth" },
{ label: "effects", before: "stealthToActor"},
{ label: "effects", before: "stealthToActor" },
{ label: "advanced", before: "hiddenLabel" },
{ label: "debug", before: "logLevel" },
];
Expand Down
1 change: 0 additions & 1 deletion scripts/systems/dnd5e.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,6 @@ class Engine5e extends Engine {
await actor.toggleStatusEffect('hiding', {active: true});
const beforeV11 = Math.floor(game.version) < 11;
let effect = actor.effects.find((e) => this.hiding === (beforeV11 ? e.label : e.name));
Stealthy.log('hiding', effect);
effect = foundry.utils.duplicate(effect);
effect.flags.stealthy = flag;
effect.disabled = false;
Expand Down

0 comments on commit c4a062e

Please sign in to comment.