mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-04-21 23:13:39 +02:00
Migrations are now not horrible =D
This commit is contained in:
parent
cd4a8069fc
commit
eefd35eb60
2 changed files with 9 additions and 57 deletions
|
|
@ -154,7 +154,7 @@ export default class DHArmor extends AttachableItem {
|
||||||
/** @inheritDoc */
|
/** @inheritDoc */
|
||||||
static migrateDocumentData(source) {
|
static migrateDocumentData(source) {
|
||||||
if (!source.system.armor) {
|
if (!source.system.armor) {
|
||||||
source.system.armor = { current: source.system.marks ?? 0, max: source.system.baseScore ?? 0 };
|
source.system.armor = { current: source.system.marks?.value ?? 0, max: source.system.baseScore ?? 0 };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -302,65 +302,17 @@ export async function runMigrations() {
|
||||||
|
|
||||||
/* Migrate existing effects modifying armor, creating new Armor Effects instead */
|
/* Migrate existing effects modifying armor, creating new Armor Effects instead */
|
||||||
const migrateEffects = async entity => {
|
const migrateEffects = async entity => {
|
||||||
const effectChangeData = [];
|
|
||||||
for (const effect of entity.effects) {
|
for (const effect of entity.effects) {
|
||||||
const oldArmorChanges = effect.system.changes.filter(x => x.key === 'system.armorScore');
|
if (effect.system.changes.every(x => x.key !== 'system.armorScore')) continue;
|
||||||
if (!oldArmorChanges.length) continue;
|
|
||||||
|
|
||||||
const changeData = {};
|
effect.update({
|
||||||
const newChanges = effect.system.changes.filter(x => x.key !== 'system.armorScore');
|
'system.changes': effect.system.changes.map(change => ({
|
||||||
if (newChanges.length) {
|
...change,
|
||||||
await effect.update({ 'system.changes': newChanges });
|
type: change.key === 'system.armorScore' ? 'armor' : change.type,
|
||||||
} else {
|
value: change.key === 'system.armorScore' ? { current: 0, max: change.value } : change.value
|
||||||
changeData.deleteId = effect.id;
|
}))
|
||||||
}
|
});
|
||||||
|
|
||||||
const oldEffectData = effect.toObject();
|
|
||||||
changeData.createData = {
|
|
||||||
...oldEffectData,
|
|
||||||
system: {
|
|
||||||
...oldEffectData.system,
|
|
||||||
changes: oldArmorChanges.map(change => ({
|
|
||||||
type: CONFIG.DH.GENERAL.activeEffectModes.armor.id,
|
|
||||||
phase: 'initial',
|
|
||||||
priority: 20,
|
|
||||||
value: {
|
|
||||||
current: 0,
|
|
||||||
max: change.value
|
|
||||||
}
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
};
|
|
||||||
effectChangeData.push(changeData);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const changeData of effectChangeData) {
|
|
||||||
const relatedActions = Array.from(entity.system.actions ?? []).filter(x =>
|
|
||||||
x.effects.some(effect => effect._id === changeData.deleteId)
|
|
||||||
);
|
|
||||||
const [newEffect] = await entity.createEmbeddedDocuments('ActiveEffect', [
|
|
||||||
{
|
|
||||||
...changeData.createData,
|
|
||||||
transfer: relatedActions.length ? false : true
|
|
||||||
}
|
|
||||||
]);
|
|
||||||
for (const action of relatedActions) {
|
|
||||||
await action.update({
|
|
||||||
effects: action.effects.map(effect => ({
|
|
||||||
...effect,
|
|
||||||
_id: effect._id === changeData.deleteId ? newEffect.id : effect._id
|
|
||||||
}))
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
await entity.deleteEmbeddedDocuments(
|
|
||||||
'ActiveEffect',
|
|
||||||
effectChangeData.reduce((acc, data) => {
|
|
||||||
if (data.deleteId) acc.push(data.deleteId);
|
|
||||||
return acc;
|
|
||||||
}, [])
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Migrate existing armors effects */
|
/* Migrate existing armors effects */
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue