Skip to content

Commit

Permalink
localized tooltip and added schema version
Browse files Browse the repository at this point in the history
  • Loading branch information
Eligarf committed Apr 26, 2024
1 parent 3875af4 commit 9031090
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 5 deletions.
4 changes: 4 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# v1.2.2
* Localize the tooltips
* Added a schema setting to help with any future data migrations

# v1.2.1
* Added tooltip for cover adjustments

Expand Down
8 changes: 6 additions & 2 deletions languages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"undetected": "Undetected",
"unnoticed": "Unnoticed"
},
"negativeDelta": "",
"positiveDelta": "",
"standardCover": "Standard Cover",
"greaterCover": "Greater Cover",
"logLevel": {
"name": "Logging Level",
"none": "No logging",
Expand All @@ -24,6 +24,10 @@
"computeCover": {
"name": "Compute Cover at Combat Start",
"hint": "Use 'PF2e Perception' to automatically compute cover between tokens using stealth for initiative and non-allied Tokens. It is only used for this check, and will not utilize greater cover"
},
"schema": {
"name": "Schema Version",
"hint": "Set this to a previous version to force a data migration from the specified version to the current version"
}
}
}
41 changes: 38 additions & 3 deletions scripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ Hooks.once('init', () => {
const cover = (computeCover)
? perceptionApi.token.getCover(stealther.token._object, other.token._object)
: perceptionData?.[other.token.id]?.cover;

switch (cover) {
case 'standard':
coverBonus = 2;
Expand All @@ -137,8 +137,15 @@ Hooks.once('init', () => {
}
if (coverBonus) {
const oldDelta = stealther.initiative - target.dc;
target.oldDelta = (oldDelta < 0) ? `${oldDelta}` : `+${oldDelta}`
target.tooltip = (coverBonus == 2) ? 'Standard Cover: +2' : (coverBonus == 4) ? 'Greater Cover: +4' : `Cover: +${coverBonus}`;
target.oldDelta = (oldDelta < 0) ? `${oldDelta}` : `+${oldDelta}`;
switch (coverBonus) {
case 2:
target.tooltip = `${game.i18n.localize(`${MODULE_ID}.standardCover`)}: +2`;
break;
case 4:
target.tooltip = `${game.i18n.localize(`${MODULE_ID}.greaterCover`)}: +4`;
break;
}
}

// Handle failing to win at stealth
Expand Down Expand Up @@ -223,6 +230,12 @@ Hooks.once('init', () => {
});
});

function migrate(moduleVersion, oldVersion) {

ui.notifications.warn(`Updated PF2e Avoid Notice data from ${oldVersion} to ${moduleVersion}`);
return moduleVersion;
}

Hooks.once('setup', () => {
const module = game.modules.get(MODULE_ID);
const moduleVersion = module.version;
Expand Down Expand Up @@ -256,6 +269,28 @@ Hooks.once('setup', () => {
default: false,
});

game.settings.register(MODULE_ID, 'schema', {
name: game.i18n.localize(`${MODULE_ID}.schema.name`),
hint: game.i18n.localize(`${MODULE_ID}.schema.hint`),
scope: 'world',
config: true,
type: String,
default: `${moduleVersion}`,
onChange: value => {
const newValue = migrate(moduleVersion, value);
if (value != newValue) {
game.settings.set(MODULE_ID, 'schema', newValue);
}
}
});
const schemaVersion = game.settings.get(MODULE_ID, 'schema');
if (schemaVersion !== moduleVersion) {
Hooks.once('ready', () => {
game.settings.set(MODULE_ID, 'schema', migrate(moduleVersion, schemaVersion));
});
}


game.settings.register(MODULE_ID, 'logLevel', {
name: game.i18n.localize(`${MODULE_ID}.logLevel.name`),
scope: 'client',
Expand Down

0 comments on commit 9031090

Please sign in to comment.