Skip to content

Commit

Permalink
Additional batch of migrations for legacy data.
Browse files Browse the repository at this point in the history
  • Loading branch information
Fyorl committed Jan 10, 2023
1 parent 32e6448 commit 2b0755b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
1 change: 1 addition & 0 deletions module/data/item/class.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export default class ClassData extends SystemDataModel.mixin(ItemDescriptionTemp
* @param {object} source The candidate source data from which the model will be constructed.
*/
static #migrateSpellcastingData(source) {
if ( source.spellcasting?.progression === "" ) source.spellcasting.progression = "none";
if ( typeof source.spellcasting !== "string" ) return;
source.spellcasting = {
progression: source.spellcasting,
Expand Down
1 change: 1 addition & 0 deletions module/data/item/feat.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,6 @@ export default class FeatData extends SystemDataModel.mixin(
const value = source.recharge.value;
if ( (value === 0) || (value === "") ) source.recharge.value = null;
else if ( (typeof value === "string") && Number.isNumeric(value) ) source.recharge.value = Number(value);
if ( source.recharge.charged === null ) source.recharge.charged = false;
}
}
1 change: 1 addition & 0 deletions module/data/item/templates/action.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export default class ActionTemplate extends foundry.abstract.DataModel {
*/
static #migrateSave(source) {
if ( source.save?.scaling === "" ) source.save.scaling = "spell";
if ( source.save?.ability === null ) source.save.ability = "";
if ( typeof source.save?.dc === "string" ) {
if ( source.save.dc === "" ) source.save.dc = null;
else if ( Number.isNumeric(source.save.dc) ) source.save.dc = Number(source.save.dc);
Expand Down
20 changes: 15 additions & 5 deletions module/data/item/templates/activated-effect.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,14 @@ export default class ActivatedEffectTemplate extends foundry.abstract.DataModel
* @param {object} source The candidate source data from which the model will be constructed.
*/
static #migrateRanges(source) {
if ( source.range?.long === "" ) source.range.long = null;
if ( source.range?.units === null ) source.range.units = "";
if ( typeof source.range?.value !== "string" ) return;
if ( source.range?.value === "" ) return source.range.value = null;
if ( !("range" in source) ) return;
if ( source.range.units === null ) source.range.units = "";
if ( typeof source.range.long === "string" ) {
if ( source.range.long === "" ) source.range.long = null;
else if ( Number.isNumeric(source.range.long) ) source.range.long = Number(source.range.long);
}
if ( typeof source.range.value !== "string" ) return;
if ( source.range.value === "" ) return source.range.value = null;
const [value, long] = source.range.value.split("/");
if ( Number.isNumeric(value) ) source.range.value = Number(value);
if ( Number.isNumeric(long) ) source.range.long = Number(long);
Expand All @@ -147,7 +151,13 @@ export default class ActivatedEffectTemplate extends foundry.abstract.DataModel
* @param {object} source The candidate source data from which the model will be constructed.
*/
static #migrateUses(source) {
if ( source.uses?.value === "" ) source.uses.value = null;
if ( !("uses" in source) ) return;
const value = source.uses.value;
if ( typeof value === "string" ) {
if ( value === "" ) source.uses.value = null;
else if ( Number.isNumeric(value) ) source.uses.value = Number(source.uses.value);
}
if ( source.uses.recovery === undefined ) source.uses.recovery = "";
}

/* -------------------------------------------- */
Expand Down

0 comments on commit 2b0755b

Please sign in to comment.