forked from GitHub-Mirrors/foundry-sw5e
Code Cleanup and fix multiple migrations
see above
This commit is contained in:
parent
893c7b9d5e
commit
a99faad77c
3 changed files with 29 additions and 88 deletions
|
@ -268,10 +268,9 @@ function _updateNPCData(actor) {
|
||||||
// check for flag.core, if not there is no compendium monster so exit
|
// check for flag.core, if not there is no compendium monster so exit
|
||||||
const hasSource = actor?.flags?.core?.sourceId !== undefined;
|
const hasSource = actor?.flags?.core?.sourceId !== undefined;
|
||||||
if (!hasSource) return actor;
|
if (!hasSource) return actor;
|
||||||
// shortcut out if dataVersion flag is set to 1.2.4
|
// shortcut out if dataVersion flag is set to 1.2.4 or higher
|
||||||
const hasDataVersion = actor?.flags?.sw5e?.dataVersion !== undefined;
|
const hasDataVersion = actor?.flags?.sw5e?.dataVersion !== undefined;
|
||||||
// TODO update check to do version checking
|
if (hasDataVersion && (actor.flags.sw5e.dataVersion === "1.2.4" || isNewerVersion("1.2.4", actor.flags.sw5e.dataVersion))) return actor;
|
||||||
if ((hasDataVersion) && (actor.flags.sw5e.dataVersion === "1.2.4")) return actor;
|
|
||||||
// Check to see what the source of NPC is
|
// Check to see what the source of NPC is
|
||||||
const sourceId = actor.flags.core.sourceId;
|
const sourceId = actor.flags.core.sourceId;
|
||||||
const coreSource = sourceId.substr(0,sourceId.length-17);
|
const coreSource = sourceId.substr(0,sourceId.length-17);
|
||||||
|
@ -303,12 +302,12 @@ function _updateNPCData(actor) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// get actor to create new powers
|
||||||
const liveActor = game.actors.get(actor._id);
|
const liveActor = game.actors.get(actor._id);
|
||||||
|
// create the powers on the actor
|
||||||
liveActor.createEmbeddedEntity("OwnedItem", newPowers);
|
liveActor.createEmbeddedEntity("OwnedItem", newPowers);
|
||||||
|
|
||||||
// set flag to check to see if migration has been done so we don't do it again.
|
// set flag to check to see if migration has been done so we don't do it again.
|
||||||
// actor.flags.sw5e.dataVersion === "1.2.4";
|
|
||||||
liveActor.setFlag("sw5e", "dataVersion", "1.2.4");
|
liveActor.setFlag("sw5e", "dataVersion", "1.2.4");
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -483,97 +482,38 @@ function _migrateItemClassPowerCasting(item, updateData) {
|
||||||
async function _migrateItemPower(item, actor, updateData) {
|
async function _migrateItemPower(item, actor, updateData) {
|
||||||
// if item is not a power shortcut out
|
// if item is not a power shortcut out
|
||||||
if (item.type !== "power") return updateData;
|
if (item.type !== "power") return updateData;
|
||||||
|
|
||||||
// check for flag.core, if not there is no compendium power so exit
|
// check for flag.core, if not there is no compendium power so exit
|
||||||
const hasSource = item?.flags?.core?.sourceId !== undefined;
|
const hasSource = item?.flags?.core?.sourceId !== undefined;
|
||||||
if (!hasSource) return updateData;
|
if (!hasSource) return updateData;
|
||||||
// shortcut out if dataVersion flag is set to 1.2.4
|
|
||||||
|
// shortcut out if dataVersion flag is set to 1.2.4 or higher
|
||||||
const hasDataVersion = item?.flags?.sw5e?.dataVersion !== undefined;
|
const hasDataVersion = item?.flags?.sw5e?.dataVersion !== undefined;
|
||||||
// TODO update check to do version checking
|
if (hasDataVersion && (item.flags.sw5e.dataVersion === "1.2.4" || isNewerVersion("1.2.4", item.flags.sw5e.dataVersion))) return updateData;
|
||||||
if ((hasDataVersion) && (item.flags.sw5e.dataVersion === "1.2.4")) return updateData;
|
|
||||||
// Check to see what the source of Power is
|
// Check to see what the source of Power is
|
||||||
const sourceId = item.flags.core.sourceId;
|
const sourceId = item.flags.core.sourceId;
|
||||||
const coreSource = sourceId.substr(0, sourceId.length - 17);
|
const coreSource = sourceId.substr(0, sourceId.length - 17);
|
||||||
const core_id = sourceId.substr(sourceId.length - 16, 16);
|
const core_id = sourceId.substr(sourceId.length - 16, 16);
|
||||||
if (coreSource === "Compendium.sw5e.techpowers") {
|
|
||||||
game.packs
|
//if power type is not force or tech exit out
|
||||||
.get("sw5e.techpowers")
|
let powerType = "none";
|
||||||
.getEntity(core_id)
|
if (coreSource === "Compendium.sw5e.forcepowers") powerType = "sw5e.forcepowers";
|
||||||
.then((corePower) => {
|
if (coreSource === "Compendium.sw5e.techpowers") powerType = "sw5e.techpowers";
|
||||||
const coreData = corePower.data.data;
|
if (powerType === "none") return updateData;
|
||||||
// copy Core Power Data over original Power
|
|
||||||
updateData["data"] = coreData;
|
|
||||||
updateData["flags"] = {"sw5e": {"dataVersion": "1.2.4"}};
|
|
||||||
|
|
||||||
// set flag to check to see if migration has been done so we don't do it again.
|
|
||||||
// item.flags.sw5e.dataVersion === "1.2.4";
|
|
||||||
|
|
||||||
return updateData;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (coreSource === "Compendium.sw5e.forcepowers") {
|
|
||||||
const compendium = game.packs.get("sw5e.forcepowers");
|
|
||||||
|
|
||||||
const corePower = await compendium.getEntity(core_id)
|
|
||||||
const coreData = corePower.data.data;
|
|
||||||
|
|
||||||
|
game.packs.get(powerType).getEntity(core_id).then(corePower => {
|
||||||
|
const corePowerData = corePower.data.data;
|
||||||
// copy Core Power Data over original Power
|
// copy Core Power Data over original Power
|
||||||
updateData["data"] = coreData;
|
updateData["data"] = corePowerData;
|
||||||
updateData["flags"] = {"sw5e": {"dataVersion": "1.2.4"}};
|
updateData["flags"] = {"sw5e": {"dataVersion": "1.2.4"}};
|
||||||
|
|
||||||
// set flag to check to see if migration has been done so we don't do it again.
|
|
||||||
// item.setFlag("sw5e", "dataVersion", "1.2.4");
|
|
||||||
|
|
||||||
return updateData;
|
return updateData;
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
|
|
||||||
/**
|
|
||||||
* @private
|
|
||||||
|
|
||||||
function _migrateItemPower(item, actor, updateData) {
|
|
||||||
if (item.type === "power"){
|
|
||||||
// check for flag.core, if not there is no compendium monster so exit
|
|
||||||
const hasSource = item?.flags?.core?.sourceId !== undefined;
|
|
||||||
if (!hasSource) return updateData;
|
|
||||||
// shortcut out if dataVersion flag is set to 1.2.4
|
|
||||||
const hasDataVersion = item?.flags?.sw5e?.dataVersion !== undefined;
|
|
||||||
// TODO update check to do version checking
|
|
||||||
if ((hasDataVersion) && (item.flags.sw5e.dataVersion === "1.2.4")) return updateData;
|
|
||||||
// Check to see what the source of item is
|
|
||||||
const sourceId = item.flags.core.sourceId;
|
|
||||||
const coreSource = sourceId.substr(0,sourceId.length-17);
|
|
||||||
const core_id = sourceId.substr(sourceId.length-16,16);
|
|
||||||
if (coreSource === "Compendium.sw5e.forcepowers") {
|
|
||||||
game.packs.get("sw5e.forcepowers").getEntity(core_id).then(compPower => {
|
|
||||||
const powerData = compPower.data.data;
|
|
||||||
// Update all the item data
|
|
||||||
updateData["data"] = powerData;
|
|
||||||
|
|
||||||
// set flag to check to see if migration has been done so we don't do it again.
|
|
||||||
item.flags.sw5e.dataVersion === "1.2.4";
|
|
||||||
});
|
|
||||||
|
|
||||||
}else if (coreSource === "Compendium.sw5e.techpowers"){
|
|
||||||
game.packs.get("sw5e.techpowers").getEntity(core_id).then(compPower => {
|
|
||||||
const powerData = compPower.data.data;
|
|
||||||
// Update all the item data
|
|
||||||
updateData["data"] = powerData;
|
|
||||||
|
|
||||||
// set flag to check to see if migration has been done so we don't do it again.
|
|
||||||
item.flags.sw5e.dataVersion === "1.2.4";
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return updateData;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
/* -------------------------------------------- */
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete the old data.attuned boolean
|
* Delete the old data.attuned boolean
|
||||||
* @private
|
* @private
|
||||||
|
@ -585,7 +525,6 @@ function _migrateItemAttunement(item, updateData) {
|
||||||
return updateData;
|
return updateData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
16
sw5e.js
16
sw5e.js
|
@ -196,16 +196,18 @@ Hooks.once("ready", function() {
|
||||||
// Determine whether a system migration is required and feasible
|
// Determine whether a system migration is required and feasible
|
||||||
if ( !game.user.isGM ) return;
|
if ( !game.user.isGM ) return;
|
||||||
const currentVersion = game.settings.get("sw5e", "systemMigrationVersion");
|
const currentVersion = game.settings.get("sw5e", "systemMigrationVersion");
|
||||||
const NEEDS_MIGRATION_VERSION = "R1-A1";
|
const NEEDS_MIGRATION_VERSION = "1.2.4.R1-A4";
|
||||||
|
// Check for R1 SW5E versions
|
||||||
|
const SW5E_NEEDS_MIGRATION_VERSION = "R1-A5";
|
||||||
const COMPATIBLE_MIGRATION_VERSION = 0.80;
|
const COMPATIBLE_MIGRATION_VERSION = 0.80;
|
||||||
const needsMigration = currentVersion && isNewerVersion(NEEDS_MIGRATION_VERSION, currentVersion);
|
const needsMigration = currentVersion && (isNewerVersion(SW5E_NEEDS_MIGRATION_VERSION, currentVersion) || isNewerVersion(NEEDS_MIGRATION_VERSION, currentVersion));
|
||||||
//if ( !needsMigration ) return;
|
if ( !needsMigration ) return;
|
||||||
|
|
||||||
// Perform the migration
|
// Perform the migration
|
||||||
//if ( currentVersion && isNewerVersion(COMPATIBLE_MIGRATION_VERSION, currentVersion) ) {
|
if ( currentVersion && isNewerVersion(COMPATIBLE_MIGRATION_VERSION, currentVersion) ) {
|
||||||
// const warning = `Your SW5e system data is from too old a Foundry version and cannot be reliably migrated to the latest version. The process will be attempted, but errors may occur.`;
|
const warning = `Your SW5e system data is from too old a Foundry version and cannot be reliably migrated to the latest version. The process will be attempted, but errors may occur.`;
|
||||||
// ui.notifications.error(warning, {permanent: true});
|
ui.notifications.error(warning, {permanent: true});
|
||||||
//}
|
}
|
||||||
migrations.migrateWorld();
|
migrations.migrateWorld();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
"name": "sw5e",
|
"name": "sw5e",
|
||||||
"title": "SW 5th Edition",
|
"title": "SW 5th Edition",
|
||||||
"description": "A comprehensive game system for running games of SW 5th Edition in the Foundry VTT environment.",
|
"description": "A comprehensive game system for running games of SW 5th Edition in the Foundry VTT environment.",
|
||||||
"version": "R1-A4",
|
"version": "1.2.4.R1-A5",
|
||||||
"author": "Dev Team",
|
"author": "Dev Team",
|
||||||
"scripts": [],
|
"scripts": [],
|
||||||
"esmodules": ["sw5e.js"],
|
"esmodules": ["sw5e.js"],
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue