Fixed actorRoll migrateData

This commit is contained in:
WBHarry 2026-07-18 12:37:51 +02:00
parent 4bffc27403
commit b7e92cfe0e

View file

@ -188,31 +188,35 @@ export default class DHActorRoll extends foundry.abstract.TypeDataModel {
} }
static migrateData(source) { static migrateData(source) {
if (source.hasDamage && !source.damage.resources === undefined) { const { main, resources, ...flatDamageKeys } = source.damage;
if (!main && !resources) {
source.damage.main = null;
source.damage.resources = {};
const getRoll = key => { const getRoll = key => {
const damageData = source.damage[key]; const damageData = source.damage[key];
const oldRoll = damageData.parts[0]?.roll; const oldRoll = damageData.parts[0]?.roll;
return oldRoll ? { return oldRoll ? JSON.stringify({
...oldRoll, ...oldRoll,
options: { options: {
...oldRoll.options, ...oldRoll.options,
damageTypes: damageData.parts[0].damageTypes ?? [] damageTypes: damageData.parts[0].damageTypes ?? []
} }
} : null; }) : null;
}; };
source.damage = { for (const key of Object.keys(flatDamageKeys)) {
main: source.damage.hitPoints ? getRoll('hitPoints') : null, if (key === 'hitPoints' && source.hasDamage && !source.hasHealing) {
resources: Object.keys(source.damage).reduce((acc, key) => { source.damage.main = getRoll('hitPoints');
if (key === 'hitPoints') return acc; }
else {
source.damage.resources[key] = getRoll(key);
}
}
}
const roll = getRoll(key); for (const key of Object.keys(flatDamageKeys)) {
if (!roll) return acc; delete source.damage[key];
acc[key] = roll;
return acc;
}, {})
};
} }
return source; return source;