diff --git a/module/systemRegistration/migration-handlers/2_6_0.mjs b/module/systemRegistration/migration-handlers/2_6_0.mjs new file mode 100644 index 00000000..1efd5600 --- /dev/null +++ b/module/systemRegistration/migration-handlers/2_6_0.mjs @@ -0,0 +1,20 @@ +import { MigrationHandlerBase } from './base.mjs'; + +export class Migration_2_6_0 extends MigrationHandlerBase { + version = '2.6.0'; + + /** @inheritdoc */ + async updateActorSource(actor) { + if (actor.type === 'party') { + return { + _id: actor._id, + system: { + tagTeam: { + initiator: null, + members: _replace({}) + } + } + }; + } + } +} \ No newline at end of file diff --git a/module/systemRegistration/migration-handlers/base.mjs b/module/systemRegistration/migration-handlers/base.mjs index 7426570d..29c181ce 100644 --- a/module/systemRegistration/migration-handlers/base.mjs +++ b/module/systemRegistration/migration-handlers/base.mjs @@ -1,8 +1,9 @@ /** * @import DHItem from "../../documents/item.mjs"; +* @import DhActor from "../../documents/actor.mjs"; */ - /** + * The base class of an async migration. * These are generally run between versions for things that require compendiums or must be done in post. * The migrate() functions calls the various updateXSource() functions. @@ -22,6 +23,16 @@ export class MigrationHandlerBase { return null; } + /** + * Update a world actor + * @param {DhActor} actor + * @returns {Promise} + * @protected + */ + async updateActorSource(actor) { + return null; + } + async migrate() { // todo: handle more than just migrating effects. Right now this can only migrate effects // NOTE: the preload is hardcoded, we should not hardcode it @@ -60,10 +71,39 @@ export class MigrationHandlerBase { } }; - for (const actor of game.actors) { + const updateActor = async actor => { + const actorUpdate = await this.updateActorSource(actor); + if (actorUpdate) { + batch.push({ + action: 'update', + documentName: 'Actor', + updates: [actorUpdate] + }); + } + + const aeUpdates = []; for (const item of actor.items) { await updateItem(item); } + + for (const effect of actor.effects) { + const changes = await this.updateActiveEffectSource(effect.toObject(), { parent: actor }); + if (changes) aeUpdates.push(changes); + } + if (aeUpdates.length) { + batch.push({ + action: 'update', + documentName: 'ActiveEffect', + updates: aeUpdates, + parent: actor + }); + } + } + + + for (const actor of game.actors) { + await updateActor(actor); + progress.advance(); } for (const item of game.items) { diff --git a/module/systemRegistration/migrations.mjs b/module/systemRegistration/migrations.mjs index fef97b8f..af11cd2c 100644 --- a/module/systemRegistration/migrations.mjs +++ b/module/systemRegistration/migrations.mjs @@ -1,5 +1,6 @@ import { defaultRestOptions } from '../config/generalConfig.mjs'; import { Migration_2_5_2 } from './migration-handlers/2_5_2.mjs'; +import { Migration_2_6_0 } from './migration-handlers/2_6_0.mjs'; export async function runMigrations() { let lastMigrationVersion = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.LastMigrationVersion); @@ -329,7 +330,8 @@ export async function runMigrations() { /* -------------------------------------------- */ const migrations = [ - new Migration_2_5_2() + new Migration_2_5_2(), + new Migration_2_6_0() ].filter(m => m.version && foundry.utils.isNewerVersion(m.version, lastMigrationVersion)); for (const handler of migrations) {