Skip to content

Commit

Permalink
Bump migration version. Fix some issues with non-DataModel migrations.
Browse files Browse the repository at this point in the history
  • Loading branch information
Fyorl committed Jan 10, 2023
1 parent 2b0755b commit 4af6f42
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
11 changes: 11 additions & 0 deletions module/data/item/templates/equippable-item.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export default class EquippableItemTemplate extends foundry.abstract.DataModel {
/** @inheritdoc */
static migrateData(source) {
EquippableItemTemplate.#migrateAttunement(source);
EquippableItemTemplate.#migrateEquipped(source);
}

/* -------------------------------------------- */
Expand All @@ -33,4 +34,14 @@ export default class EquippableItemTemplate extends foundry.abstract.DataModel {
if ( (source.attuned === undefined) || (source.attunement !== undefined) ) return;
source.attunement = source.attuned ? CONFIG.DND5E.attunementTypes.ATTUNED : CONFIG.DND5E.attunementTypes.NONE;
}

/* -------------------------------------------- */

/**
* Migrate the equipped field.
* @param {object} source The candidate source data from which the model will be constructed.
*/
static #migrateEquipped(source) {
if ( source.equipped === null ) source.equipped = false;
}
}
4 changes: 2 additions & 2 deletions module/migration.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ export const migrateMacroData = function(macro, migrationData) {
*/
export const migrateSceneData = function(scene, migrationData) {
const tokens = scene.tokens.map(token => {
const t = token.toObject();
const t = token instanceof foundry.abstract.DataModel ? token.toObject() : token;
const update = {};
_migrateTokenImage(t, update);
if ( Object.keys(update).length ) foundry.utils.mergeObject(t, update);
Expand Down Expand Up @@ -487,7 +487,7 @@ function _migrateDocumentIcon(document, updateData, {iconMap, field="img"}={}) {
*/
function _migrateEffectArmorClass(effect, updateData) {
let containsUpdates = false;
const changes = effect.changes.map(c => {
const changes = (effect.changes || []).map(c => {
if ( c.key !== "system.attributes.ac.base" ) return c;
c.key = "system.attributes.ac.armor";
containsUpdates = true;
Expand Down
2 changes: 1 addition & 1 deletion system.json
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
"gridUnits": "ft",
"primaryTokenAttribute": "attributes.hp",
"flags": {
"needsMigrationVersion": "2.0.2",
"needsMigrationVersion": "2.1.0",
"compatibleMigrationVersion": "0.8"
}
}

0 comments on commit 4af6f42

Please sign in to comment.