daggerheart/module/systemRegistration/migration-handlers/base.mjs
WBHarry effab8db0c
Some checks are pending
Project CI / build (24.x) (push) Waiting to run
[Rework] ChatMessage Damage (#2079)
* Initial rework

* Removed unneeded method

* Removed outcommented code

* Added migration

* Fixed DamageActions

* Semi-corrected reroll of one of multiple results on a die

* Code improvement

* Added aseDie.rerollResult method to specifically reroll a specific result die in a grouping

* TagTeamDialog somewhat working

* Added migration for TagTeamData

* Fix for mean tagTeamDialog.finish

* .

* Improved migration

* Internalised ChatDamageData.prepareRolls to its own constructor

* Moved DamageTypes to roll.options

* TagTeamDialog fixes to accomodate new flat damage.types structure

* Changed so all default rolls become BaseRolls to access convenience functions and getters

* .

* Fixed so that party.tagTeam now uses a declared damageRollData(ChatDamageData) field. rollData.options.damage is retired.

* Critical damage fixes

* Corrected TagTeamDialog rerender logic when selecting a roll

* Fixed so that DamageTypes are retained and joined together throughout TagTeamDialog

* Removed some remaining types.<>.roll references

* [Rework] Damage and Damage Resource split (#2094)

* Changed the label of ActionSheet damage.resources to Mark Resources

* Fix assigning includeBase

* Localize add resource

* Maybe simplify API

* Fix onRollSimple

* Handle erroring action update differently

---------

Co-authored-by: Carlos Fernandez <cfern1990@gmail.com>
2026-07-19 03:02:57 +02:00

117 lines
No EOL
3.6 KiB
JavaScript

/**
* @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.
* Generally a subclass will override the version and the updateXSource() functions.
*/
export class MigrationHandlerBase {
version = null;
/**
* Gets change data for an active effect's source, or null if no changes
* @param {object} effectSource
* @param {DHItem} item
* @returns {Promise<object>}
* @protected
*/
async updateActiveEffectSource(effectSource, item) {
return null;
}
/**
* Update a world actor
* @param {DhActor} actor
* @returns {Promise<object>}
* @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
const numActors = game.actors.size;
const numItems = game.items.size;
const finalUpdateProgress = 5;
const DhProgress = game.system.api.applications.ui.DhProgress;
const preRunProgress = game.packs.size;
const progress = DhProgress.createMigrationProgress(
preRunProgress + numActors + numItems + finalUpdateProgress
);
// Preload. Avoid hardcoding in the future
for (const pack of game.packs) {
await pack.getDocuments();
progress.advance();
}
const batch = [];
const updateItem = async item => {
const itemUpdates = [];
for (const effect of item.effects) {
const changes = await this.updateActiveEffectSource(effect.toObject(), item);
if (changes) itemUpdates.push(changes);
}
if (itemUpdates.length) {
batch.push({
action: 'update',
documentName: 'ActiveEffect',
updates: itemUpdates,
parent: item
});
}
};
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) {
await updateItem(item);
progress.advance();
}
await foundry.documents.modifyBatch(batch);
progress.advance({ by: finalUpdateProgress });
}
}