From a32af32f3a23afd6b5c5183a94c1e8216872963c Mon Sep 17 00:00:00 2001 From: Dapoolp Date: Wed, 16 Jul 2025 03:20:45 +0200 Subject: [PATCH] 2 --- lang/en.json | 6 +++++- module/data/actor/character.mjs | 13 +++++++++++-- module/data/fields/actorField.mjs | 7 +++++-- module/dice/d20Roll.mjs | 4 ++-- module/documents/token.mjs | 22 ++++++++++++++++++++++ 5 files changed, 45 insertions(+), 7 deletions(-) diff --git a/lang/en.json b/lang/en.json index b9e0fefa..66918dad 100755 --- a/lang/en.json +++ b/lang/en.json @@ -406,7 +406,11 @@ "rerollDice": "Reroll Dice" } }, - + "CLASS": { + "Feature": { + "rallyDice": "Bardic Rally Dice" + } + }, "CONFIG": { "ActionType": { "passive": "Passive", diff --git a/module/data/actor/character.mjs b/module/data/actor/character.mjs index e25dba85..04d3f3da 100644 --- a/module/data/actor/character.mjs +++ b/module/data/actor/character.mjs @@ -102,7 +102,7 @@ export default class DhCharacter extends BaseDataActor { physical: bonusField('DAGGERHEART.GENERAL.Damage.physicalDamage'), magical: bonusField('DAGGERHEART.GENERAL.Damage.magicalDamage'), primaryWeapon: bonusField('DAGGERHEART.GENERAL.Damage.primaryWeapon'), - secondaryWeapon: bonusField('DAGGERHEART.GENERAL.Damage.primaryWeapon') + secondaryWeapon: bonusField('DAGGERHEART.GENERAL.Damage.secondaryWeapon') }), healing: bonusField('DAGGERHEART.GENERAL.Healing.healingAmount'), range: new fields.SchemaField({ @@ -121,7 +121,16 @@ export default class DhCharacter extends BaseDataActor { initial: 0, label: 'DAGGERHEART.GENERAL.Range.other' }) - }) + }), + rally: new fields.ArrayField( + new fields.NumberField({ + integer: true, + initial: 6 + }), + { + label: 'DAGGERHEART.CLASS.Feature.rallyDice' + } + ) }), companion: new ForeignDocumentUUIDField({ type: 'Actor', nullable: true, initial: null }), rules: new fields.SchemaField({ diff --git a/module/data/fields/actorField.mjs b/module/data/fields/actorField.mjs index fe00e251..047b6f4f 100644 --- a/module/data/fields/actorField.mjs +++ b/module/data/fields/actorField.mjs @@ -25,8 +25,11 @@ const stressDamageReductionRule = localizationPath => const bonusField = label => new fields.SchemaField({ - bonus: new fields.NumberField({ integer: true, initial: 0, label }), - dice: new fields.ArrayField(new fields.StringField()) + bonus: new fields.NumberField({ integer: true, initial: 0, label: `${game.i18n.localize(label)} Value` }), + dice: new fields.ArrayField( + new fields.StringField(), + { label: `${game.i18n.localize(label)} Dice` } + ) }); export { attributeField, resourceField, stressDamageReductionRule, bonusField }; diff --git a/module/dice/d20Roll.mjs b/module/dice/d20Roll.mjs index 004e4806..0c29fc42 100644 --- a/module/dice/d20Roll.mjs +++ b/module/dice/d20Roll.mjs @@ -130,9 +130,9 @@ export default class D20Roll extends DHRoll { value: this.options.roll.bonus }); - modifiers.push(...this.getBonus(`roll.${this.options.type}`, `${this.options.type.capitalize()} Bonus`)); + modifiers.push(...this.getBonus(`roll.${this.options.type}`, `${this.options.type?.capitalize()} Bonus`)); modifiers.push( - ...this.getBonus(`roll.${this.options.roll.type}`, `${this.options.roll.type.capitalize()} Bonus`) + ...this.getBonus(`roll.${this.options.roll.type}`, `${this.options.roll.type?.capitalize()} Bonus`) ); return modifiers; diff --git a/module/documents/token.mjs b/module/documents/token.mjs index 4592c843..3e7b49ea 100644 --- a/module/documents/token.mjs +++ b/module/documents/token.mjs @@ -32,4 +32,26 @@ export default class DHToken extends TokenDocument { return bars.concat(values); } + + static _getTrackedAttributesFromSchema(schema, _path=[]) { + const attributes = {bar: [], value: []}; + for ( const [name, field] of Object.entries(schema.fields) ) { + const p = _path.concat([name]); + if ( field instanceof foundry.data.fields.NumberField ) attributes.value.push(p); + if ( field instanceof foundry.data.fields.ArrayField ) attributes.value.push(p); + const isSchema = field instanceof foundry.data.fields.SchemaField; + const isModel = field instanceof foundry.data.fields.EmbeddedDataField; + if ( isSchema || isModel ) { + const schema = isModel ? field.model.schema : field; + const isBar = schema.has && schema.has("value") && schema.has("max"); + if ( isBar ) attributes.bar.push(p); + else { + const inner = this.getTrackedAttributes(schema, p); + attributes.bar.push(...inner.bar); + attributes.value.push(...inner.value); + } + } + } + return attributes; + } }