mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-07-22 02:19:54 +02:00
Corrected ChatDamageData and made damage.main nullable
This commit is contained in:
parent
578e6e6c76
commit
ce47c63ce6
4 changed files with 30 additions and 16 deletions
|
|
@ -188,19 +188,28 @@ export default class DHActorRoll extends foundry.abstract.TypeDataModel {
|
|||
}
|
||||
|
||||
static migrateData(source) {
|
||||
if (source.hasDamage && !source.damage.types) {
|
||||
source.damage = {
|
||||
types: Object.keys(source.damage).reduce((acc, key) => {
|
||||
const damageData = source.damage[key];
|
||||
const oldRoll = damageData.parts[0]?.roll;
|
||||
acc[key] = oldRoll ? {
|
||||
...oldRoll,
|
||||
options: {
|
||||
...oldRoll.options,
|
||||
damageTypes: damageData.parts[0].damageTypes ?? []
|
||||
}
|
||||
} : null;
|
||||
if (source.hasDamage && !source.damage.resources === undefined) {
|
||||
const getRoll = key => {
|
||||
const damageData = source.damage[key];
|
||||
const oldRoll = damageData.parts[0]?.roll;
|
||||
return oldRoll ? {
|
||||
...oldRoll,
|
||||
options: {
|
||||
...oldRoll.options,
|
||||
damageTypes: damageData.parts[0].damageTypes ?? []
|
||||
}
|
||||
} : null;
|
||||
};
|
||||
|
||||
source.damage = {
|
||||
main: source.damage.hitPoints ? getRoll('hitPoints') : null,
|
||||
resources: Object.keys(source.damage).reduce((acc, key) => {
|
||||
if (key === 'hitPoints') return acc;
|
||||
|
||||
const roll = getRoll(key);
|
||||
if (!roll) return acc;
|
||||
|
||||
acc[key] = roll;
|
||||
return acc;
|
||||
}, {})
|
||||
};
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ export class ChatDamageData extends foundry.abstract.DataModel {
|
|||
const fields = foundry.data.fields;
|
||||
|
||||
return {
|
||||
damage: new fields.JSONField({validate: ChatDamageData.#validateRoll}),
|
||||
main: new fields.JSONField({ nullable: true, validate: ChatDamageData.#validateRoll}),
|
||||
resources: new fields.TypedObjectField(new fields.JSONField({validate: ChatDamageData.#validateRoll}))
|
||||
};
|
||||
}
|
||||
|
|
@ -21,8 +21,10 @@ export class ChatDamageData extends foundry.abstract.DataModel {
|
|||
}
|
||||
|
||||
static #validateRoll(rollJSON) {
|
||||
const roll = JSON.parse(rollJSON);
|
||||
if (!roll.evaluated) throw new Error('Roll objects added to ChatMessage documents must be evaluated');
|
||||
if (rollJSON) {
|
||||
const roll = JSON.parse(rollJSON);
|
||||
if (!roll.evaluated) throw new Error('Roll objects added to ChatMessage documents must be evaluated');
|
||||
}
|
||||
}
|
||||
|
||||
_prepareRolls() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue