From bf22d57fceae1ebe34c409058efbca4da7c97836 Mon Sep 17 00:00:00 2001 From: JimCanE <6275508-jimcane@users.noreply.gitlab.com> Date: Sat, 24 May 2025 08:49:07 +0200 Subject: [PATCH] feat(damageThresholds): move data to dataModel :facepalm: --- module/applications/sheets/pc.mjs | 21 --------------------- module/data/pc.mjs | 18 ++++++++++++++++++ templates/sheets/parts/health.hbs | 4 ++-- 3 files changed, 20 insertions(+), 23 deletions(-) diff --git a/module/applications/sheets/pc.mjs b/module/applications/sheets/pc.mjs index a49f097f..8112a697 100644 --- a/module/applications/sheets/pc.mjs +++ b/module/applications/sheets/pc.mjs @@ -5,22 +5,6 @@ import DhpLevelup from '../levelup.mjs'; import AncestrySelectionDialog from '../ancestrySelectionDialog.mjs'; import DaggerheartSheet from './daggerheart-sheet.mjs'; -function computeDamageThresholds(armor, currentLevel) { - if (!armor) { - return { - major: currentLevel, - severe: currentLevel * 2 - }; - } - const { - baseThresholds: { major = 0, severe = 0 } - } = armor.system; - return { - major: major + currentLevel, - severe: severe + currentLevel - }; -} - const { ActorSheetV2 } = foundry.applications.sheets; export default class PCSheet extends DaggerheartSheet(ActorSheetV2) { constructor(options = {}) { @@ -302,11 +286,6 @@ export default class PCSheet extends DaggerheartSheet(ActorSheetV2) { context.inventory = Array(1).fill(Array(5).fill([])); } - this.document.damageThresholds = computeDamageThresholds( - context.source.items.find(x => x.type === 'armor'), - context.source.system.levelData.currentLevel - ); - context.classFeatures = ( this.multiclassFeatureSetSelected ? this.document.system.multiclassFeatures diff --git a/module/data/pc.mjs b/module/data/pc.mjs index 6a9af44f..82d49235 100644 --- a/module/data/pc.mjs +++ b/module/data/pc.mjs @@ -380,11 +380,29 @@ export default class DhpPC extends foundry.abstract.TypeDataModel { this.evasion = this.class?.system?.evasion ?? 0; // this.armor.value = this.activeArmor?.baseScore ?? 0; + this.damageThresholds = this.computeDamageThresholds(); this.applyLevels(); this.applyEffects(); } + computeDamageThresholds() { + // TODO: missing weapon features and domain cards calculation + if (!this.armor) { + return { + major: this.levelData.currentLevel, + severe: this.levelData.currentLevel * 2 + }; + } + const { + baseThresholds: { major = 0, severe = 0 } + } = this.armor.system; + return { + major: major + this.levelData.currentLevel, + severe: severe + this.levelData.currentLevel + }; + } + applyLevels() { let healthBonus = 0, stressBonus = 0, diff --git a/templates/sheets/parts/health.hbs b/templates/sheets/parts/health.hbs index 374a9b2f..64dbc4c2 100644 --- a/templates/sheets/parts/health.hbs +++ b/templates/sheets/parts/health.hbs @@ -7,7 +7,7 @@