Update migration.js

Try to get items to work, just need to get the flag to work
This commit is contained in:
supervj 2021-03-04 22:07:44 -05:00
parent d48a25bf2f
commit b9cf140e33

View file

@ -136,7 +136,7 @@ export const migrateActorData = function(actor) {
const items = actor.items.map(i => { const items = actor.items.map(i => {
// Migrate the Owned Item // Migrate the Owned Item
let itemUpdate = migrateItemData(i); let itemUpdate = migrateItemData(i, actor);
// Prepared, Equipped, and Proficient for NPC actors // Prepared, Equipped, and Proficient for NPC actors
if ( actor.type === "npc" ) { if ( actor.type === "npc" ) {
@ -199,11 +199,11 @@ function cleanActorData(actorData) {
* Migrate a single Item entity to incorporate latest data model changes * Migrate a single Item entity to incorporate latest data model changes
* @param item * @param item
*/ */
export const migrateItemData = function(item) { export const migrateItemData = function(item, actor) {
const updateData = {}; const updateData = {};
_migrateItemClassPowerCasting(item, updateData); _migrateItemClassPowerCasting(item, updateData);
_migrateItemAttunement(item, updateData); _migrateItemAttunement(item, updateData);
_migrateItemPower(item, updateData); _migrateItemPower(item, actor, updateData);
return updateData; return updateData;
}; };
@ -461,7 +461,7 @@ function _migrateItemClassPowerCasting(item, updateData) {
/** /**
* @private * @private
*/ */
function _migrateItemPower(item, updateData) { async function _migrateItemPower(item, actor, updateData) {
if (item.type === "power"){ if (item.type === "power"){
// 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 = item?.flags?.core?.sourceId !== undefined; const hasSource = item?.flags?.core?.sourceId !== undefined;
@ -472,29 +472,19 @@ function _migrateItemPower(item, updateData) {
if ((hasDataVersion) && (item.flags.dataVersion === "1.2.4")) return updateData; if ((hasDataVersion) && (item.flags.dataVersion === "1.2.4")) return updateData;
// Check to see what the source of item is // Check to see what the source of item is
const sourceId = item.flags.core.sourceId; const sourceId = item.flags.core.sourceId;
const coreSource = sourceId.substr(0,sourceId.length-17); // Load item data for source power
const core_id = sourceId.substr(sourceId.length-16,16); const compPower = await fromUuid(sourceId);
let compendiumPowerType = "none" const powerData = compPower.data.data;
if (coreSource === "Compendium.sw5e.forcepowers"){ // Update all the item data
compendiumPowerType = "sw5e.forcepowers" updateData["data"] = powerData;
}else if (coreSource === "Compendium.sw5e.techpowers"){ // set flag to check to see if migration has been done so we don't do it again.
compendiumPowerType = "sw5e.techpowers"; const liveActor = game.actors.get(actor._id);
} const LiveItem = liveActor.items.find(actorItem => actorItem._id === item._id);
if (compendiumPowerType !== "none") { LiveItem.setFlag("sw5e", "dataVersion", "1.2.4");
game.packs.get(compendiumPowerType).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.
const liveItem = game.items.get(item._id);
liveItem.setFlag("sw5e", "dataVersion", "1.2.4");
})
}
} }
return updateData; return updateData;
} }
/* -------------------------------------------- */ /* -------------------------------------------- */