Skip to content

Commit

Permalink
Merge pull request #279 from Rayji96/animalken
Browse files Browse the repository at this point in the history
Add new migration script for the 'animal ken' skill to change the key…
  • Loading branch information
Veilza authored Mar 2, 2024
2 parents 30ae695 + 1f9fdb3 commit 4b3c5d8
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 13 deletions.
4 changes: 2 additions & 2 deletions module/actor/scripts/roll.js
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -121,4 +121,4 @@ export const _onConfirmRoll = async function (dataset, actor) {
selectors,
macro
})
}
}
4 changes: 2 additions & 2 deletions module/actor/wod-v5-sheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
10 changes: 4 additions & 6 deletions module/api/wod5e-api.js
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -81,15 +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
* @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.')
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)
Expand Down Expand Up @@ -196,7 +194,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 = {}
}) {
Expand Down
5 changes: 5 additions & 0 deletions module/scripts/migration.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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...')
Expand Down
56 changes: 56 additions & 0 deletions module/scripts/migration/migrate-animal-ken.js
Original file line number Diff line number Diff line change
@@ -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)
}
}
})
}
2 changes: 1 addition & 1 deletion module/scripts/migration/migrate-localization2.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions template.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
"name": "WOD5E.Skills.Athletics",
"bonuses": []
},
"animal ken": {
"animalken": {
"value": 0,
"name": "WOD5E.Skills.AnimalKen",
"bonuses": []
Expand Down Expand Up @@ -257,7 +257,7 @@
"name": "WOD5E.Skills.Athletics",
"visible": false
},
"animal ken": {
"animalken": {
"value": 0,
"name": "WOD5E.Skills.AnimalKen",
"visible": false
Expand Down

0 comments on commit 4b3c5d8

Please sign in to comment.