mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-07-21 18:09:54 +02:00
Fixed actorRoll migrateData
This commit is contained in:
parent
4bffc27403
commit
b7e92cfe0e
1 changed files with 18 additions and 14 deletions
|
|
@ -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;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue