From ba17e37423039127ecfbf3c9a7e18b4a9acc2341 Mon Sep 17 00:00:00 2001 From: Veilza Date: Sat, 2 Mar 2024 04:09:33 -0600 Subject: [PATCH 1/3] Add new migration script for the 'animal ken' skill to change the key to 'animalken' --- module/scripts/migration.js | 5 ++ .../scripts/migration/migrate-animal-ken.js | 56 +++++++++++++++++++ .../migration/migrate-localization2.js | 2 +- template.json | 4 +- 4 files changed, 64 insertions(+), 3 deletions(-) create mode 100644 module/scripts/migration/migrate-animal-ken.js diff --git a/module/scripts/migration.js b/module/scripts/migration.js index 7e006f58..946a0a1f 100644 --- a/module/scripts/migration.js +++ b/module/scripts/migration.js @@ -7,6 +7,7 @@ import { MigrateTrackers } from './migration/migrate-trackers.js' import { MigrateSpecialties } from './migration/migrate-specialties.js' import { MigrateLocalization2 } from './migration/migrate-localization2.js' import { MigrateItemImages } from './migration/migrate-item-images.js' +import { MigrateAnimalKen } from './migration/migrate-animal-ken.js' let worldVersion @@ -61,6 +62,10 @@ export const migrateWorld = async () => { const migrationIDs7 = await MigrateItemImages() updates.concat(migrationIDs7) + // Migrate the Animal Ken skill + const migrationIDs8 = await MigrateAnimalKen() + updates.concat(migrationIDs8) + // Only reload if there's 1 or more updates if (updates.length > 0) { ui.notifications.info('Upgrade complete! Foundry will now refresh in 10 seconds...') diff --git a/module/scripts/migration/migrate-animal-ken.js b/module/scripts/migration/migrate-animal-ken.js new file mode 100644 index 00000000..0d48c6cf --- /dev/null +++ b/module/scripts/migration/migrate-animal-ken.js @@ -0,0 +1,56 @@ +/* global ui, game */ + +export const MigrateAnimalKen = async function () { + return new Promise((resolve) => { + const actorsList = game.actors + const totalIterations = actorsList.size + const migrationIDs = [] + let counter = 0 + + // Fix the Animal Ken skill (v4.0.0) + for (const actor of actorsList) { + const actorData = actor.system + + // Handle SPC sheets first + if (actor.type === 'spc') { + // Check if the actor already has animalken (the fixed skill) + if (actorData.exceptionaldicepools['animal ken']) { + // Define the new actor skill we'll derive the data from + actorData.exceptionaldicepools.animalken = actorData.exceptionaldicepools['animal ken'] + // Delete the old skill + delete actorData.exceptionaldicepools['animal ken'] + + // Send a notification and push the actor ID to the migration IDs list + ui.notifications.info(`Fixing actor ${actor.name}: Migrating Animal Ken data.`) + migrationIDs.push(actor.uuid) + + // Update the actor's data with the new information + actor.update({ 'exceptionaldicepools': actorData.exceptionaldicepools}) + } + } else if (actor.type !== 'cell' && actor.type !== 'coterie') { // Ignore cell and coterie sheets + // Check if the actor already has animalken (the fixed skill) + if (actorData.skills['animal ken']) { + // Define the new actor skill we'll derive the data from + actorData.skills.animalken = actorData.skills['animal ken'] + // Delete the old skill + delete actorData.skills['animal ken'] + + // Send a notification and push the actor ID to the migration IDs list + ui.notifications.info(`Fixing actor ${actor.name}: Migrating Animal Ken data.`) + migrationIDs.push(actor.uuid) + + // Update the actor's data with the new information + actor.update({ 'skills': actorData.skills }) + } + } + + // Increase the counter and continue + counter++ + + // Only resolve when we're finished going through all the actors. + if (counter === totalIterations) { + resolve(migrationIDs) + } + } + }) +} diff --git a/module/scripts/migration/migrate-localization2.js b/module/scripts/migration/migrate-localization2.js index 55e55e56..324e851d 100644 --- a/module/scripts/migration/migrate-localization2.js +++ b/module/scripts/migration/migrate-localization2.js @@ -392,7 +392,7 @@ export const MigrateLocalization2 = async function () { for (const actor of actorsList) { const actorData = actor.system - // Check if there are any instances of VTM5E in the actor data + // Check if there are any instances of any of the localization comparisons in the actor data if (countInstances(actorData, LocalizationComparisons) > 0) { const newData = findAndReplace(actorData, LocalizationComparisons) diff --git a/template.json b/template.json index 6d1a235f..f1721666 100644 --- a/template.json +++ b/template.json @@ -88,7 +88,7 @@ "name": "WOD5E.Skills.Athletics", "bonuses": [] }, - "animal ken": { + "animalken": { "value": 0, "name": "WOD5E.Skills.AnimalKen", "bonuses": [] @@ -257,7 +257,7 @@ "name": "WOD5E.Skills.Athletics", "visible": false }, - "animal ken": { + "animalken": { "value": 0, "name": "WOD5E.Skills.AnimalKen", "visible": false From 4d01fd4c12d3302c1e66e06c311473e14ede546d Mon Sep 17 00:00:00 2001 From: Veilza Date: Sat, 2 Mar 2024 04:18:23 -0600 Subject: [PATCH 2/3] Linter fixes --- module/actor/scripts/roll.js | 4 ++-- module/actor/wod-v5-sheet.js | 4 ++-- module/api/wod5e-api.js | 9 ++++----- module/scripts/migration/migrate-animal-ken.js | 4 ++-- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/module/actor/scripts/roll.js b/module/actor/scripts/roll.js index 003ebcce..2159aaed 100644 --- a/module/actor/scripts/roll.js +++ b/module/actor/scripts/roll.js @@ -1,4 +1,4 @@ -/* global renderTemplate, Dialog, game, WOD5E */ +/* global WOD5E */ import { WOD5eDice } from '../../scripts/system-rolls.js' import { getActiveBonuses } from '../../scripts/rolls/situational-modifiers.js' @@ -121,4 +121,4 @@ export const _onConfirmRoll = async function (dataset, actor) { selectors, macro }) -} \ No newline at end of file +} diff --git a/module/actor/wod-v5-sheet.js b/module/actor/wod-v5-sheet.js index 13ef4337..2a6fde8d 100644 --- a/module/actor/wod-v5-sheet.js +++ b/module/actor/wod-v5-sheet.js @@ -166,10 +166,10 @@ export class WoDActor extends ActorSheet { // Collapsible items and other elements $('.collapsible').on('click', function () { $(this).toggleClass('active') - + const content = $(this).closest('.collapsible-container').find('.collapsible-content') - if (content.css('maxHeight') == '0px') { + if (content.css('maxHeight') === '0px') { content.css('maxHeight', content.prop('scrollHeight') + 'px') } else { content.css('maxHeight', '0px') diff --git a/module/api/wod5e-api.js b/module/api/wod5e-api.js index cb55a53e..ec162558 100644 --- a/module/api/wod5e-api.js +++ b/module/api/wod5e-api.js @@ -1,4 +1,4 @@ -/* global ChatMessage, game, ui */ +/* global renderTemplate, Dialog, ChatMessage, game, ui, WOD5E */ import { WOD5eDice } from '../scripts/system-rolls.js' import { _onConfirmRoll } from '../actor/scripts/roll.js' @@ -81,12 +81,11 @@ export class wod5eAPI { * * @param dataset A formatted dataset with various roll variables * @param actor (Optional, default to speaker actor) The actor that the roll is coming from - * @param data (Optional, default actor.system) Actor or item data to pass along with the roll + * */ static async RollFromDataset ({ dataset, - actor = game.actors.get(ChatMessage.getSpeaker().actor), - data = game.actors.get(ChatMessage.getSpeaker().actor)?.system || {} + actor = game.actors.get(ChatMessage.getSpeaker().actor) }) { // If there's no dataset, send an error and then stop the function if(!dataset) return console.error('No dataset defined.') @@ -196,7 +195,7 @@ export class wod5eAPI { } // Function to grab the values of any given paths and add them up as the total number of basic dice for the roll - static async getFlavorDescription({ + static async getFlavorDescription ({ valuePath = '', data = {} }) { diff --git a/module/scripts/migration/migrate-animal-ken.js b/module/scripts/migration/migrate-animal-ken.js index 0d48c6cf..afdcffc3 100644 --- a/module/scripts/migration/migrate-animal-ken.js +++ b/module/scripts/migration/migrate-animal-ken.js @@ -25,7 +25,7 @@ export const MigrateAnimalKen = async function () { migrationIDs.push(actor.uuid) // Update the actor's data with the new information - actor.update({ 'exceptionaldicepools': actorData.exceptionaldicepools}) + actor.update({ exceptionaldicepools: actorData.exceptionaldicepools }) } } else if (actor.type !== 'cell' && actor.type !== 'coterie') { // Ignore cell and coterie sheets // Check if the actor already has animalken (the fixed skill) @@ -40,7 +40,7 @@ export const MigrateAnimalKen = async function () { migrationIDs.push(actor.uuid) // Update the actor's data with the new information - actor.update({ 'skills': actorData.skills }) + actor.update({ skills: actorData.skills }) } } From 1f9fdb3f7ce0f7bbb50d7348196c8dd5264d7890 Mon Sep 17 00:00:00 2001 From: Veilza Date: Sat, 2 Mar 2024 04:26:57 -0600 Subject: [PATCH 3/3] Update wod5e-api.js --- module/api/wod5e-api.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/module/api/wod5e-api.js b/module/api/wod5e-api.js index ec162558..cac2af18 100644 --- a/module/api/wod5e-api.js +++ b/module/api/wod5e-api.js @@ -81,14 +81,13 @@ export class wod5eAPI { * * @param dataset A formatted dataset with various roll variables * @param actor (Optional, default to speaker actor) The actor that the roll is coming from - * */ static async RollFromDataset ({ dataset, actor = game.actors.get(ChatMessage.getSpeaker().actor) }) { // If there's no dataset, send an error and then stop the function - if(!dataset) return console.error('No dataset defined.') + if (!dataset) return console.error('No dataset defined.') // If selectDialog isn't set, just skip to the next dialog immediately if (!dataset.selectDialog) return _onConfirmRoll(dataset, actor)