mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-07-22 10:29:54 +02:00
Start on migration handlers
This commit is contained in:
parent
d860040824
commit
babd18c9a4
2 changed files with 42 additions and 28 deletions
35
module/systemRegistration/migration-handlers/2_5_2.mjs
Normal file
35
module/systemRegistration/migration-handlers/2_5_2.mjs
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
export class Migration_2_5_2 {
|
||||
version = '2.5.2';
|
||||
|
||||
async updateEffect(effectSource, item) {
|
||||
let shouldUpdate = false;
|
||||
const newChanges = [];
|
||||
const srdItem = item?._stats.compendiumSource ?
|
||||
await foundry.utils.fromUuid(item?._stats.compendiumSource) :
|
||||
null;
|
||||
for (let i = 0; i < effectSource.system.changes.length; i++) {
|
||||
const change = effectSource.system.changes[i];
|
||||
const srdEffect = srdItem?.effects.find(x => x.name === effectSource.name);
|
||||
if (change.type === 'custom') {
|
||||
const srdChange = srdEffect ? srdEffect.system.changes[i] : null;
|
||||
if (
|
||||
change.key === srdChange.key &&
|
||||
change.value === srdChange.value &&
|
||||
change.type !== srdChange.type
|
||||
) {
|
||||
shouldUpdate = true;
|
||||
newChanges.push(srdChange);
|
||||
}
|
||||
} else {
|
||||
newChanges.push(change);
|
||||
}
|
||||
}
|
||||
|
||||
if (shouldUpdate) {
|
||||
return {
|
||||
_id: effectSource._id,
|
||||
system: { changes: newChanges }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
import { defaultRestOptions } from '../config/generalConfig.mjs';
|
||||
import { Migration_2_5_2 } from './migration-handlers/2_5_2.mjs';
|
||||
|
||||
export async function runMigrations() {
|
||||
let lastMigrationVersion = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.LastMigrationVersion);
|
||||
|
|
@ -328,41 +329,19 @@ export async function runMigrations() {
|
|||
progress.advance();
|
||||
}
|
||||
|
||||
// todo: introduce a runner class that can handle passing on to the different update functions
|
||||
const handler = new Migration_2_5_2();
|
||||
|
||||
const batch = [];
|
||||
for (const actor of game.actors) {
|
||||
for (const item of actor.items) {
|
||||
for (const effect of item.effects) {
|
||||
let shouldUpdate = false;
|
||||
const newChanges = [];
|
||||
const srdItem = item._stats.compendiumSource ?
|
||||
await foundry.utils.fromUuid(item._stats.compendiumSource) :
|
||||
null;
|
||||
for (let i = 0; i < effect.system.changes.length; i++) {
|
||||
const change = effect.system.changes[i];
|
||||
const srdEffect = srdItem?.effects.find(x => x.name === effect.name);
|
||||
if (change.type === 'custom') {
|
||||
const srdChange = srdEffect ? srdEffect.system.changes[i] : null;
|
||||
if (
|
||||
change.key === srdChange.key &&
|
||||
change.value === srdChange.value &&
|
||||
change.type !== srdChange.type
|
||||
) {
|
||||
shouldUpdate = true;
|
||||
newChanges.push(srdChange);
|
||||
}
|
||||
} else {
|
||||
newChanges.push(change);
|
||||
}
|
||||
}
|
||||
|
||||
if (shouldUpdate) {
|
||||
const changes = handler.updateEffect(effect.toObject(), effect.parent);
|
||||
if (changes) {
|
||||
batch.push({
|
||||
action: 'update',
|
||||
documentName: 'ActiveEffect',
|
||||
updates: [{
|
||||
_id: effect.id,
|
||||
system: { changes: newChanges }
|
||||
}],
|
||||
updates: [changes],
|
||||
parent: item
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue