feat(damageThresholds): move data to dataModel 🤦

This commit is contained in:
JimCanE 2025-05-24 08:49:07 +02:00
parent 2313c4a18c
commit bf22d57fce
3 changed files with 20 additions and 23 deletions

View file

@ -5,22 +5,6 @@ import DhpLevelup from '../levelup.mjs';
import AncestrySelectionDialog from '../ancestrySelectionDialog.mjs'; import AncestrySelectionDialog from '../ancestrySelectionDialog.mjs';
import DaggerheartSheet from './daggerheart-sheet.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; const { ActorSheetV2 } = foundry.applications.sheets;
export default class PCSheet extends DaggerheartSheet(ActorSheetV2) { export default class PCSheet extends DaggerheartSheet(ActorSheetV2) {
constructor(options = {}) { constructor(options = {}) {
@ -302,11 +286,6 @@ export default class PCSheet extends DaggerheartSheet(ActorSheetV2) {
context.inventory = Array(1).fill(Array(5).fill([])); 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 = ( context.classFeatures = (
this.multiclassFeatureSetSelected this.multiclassFeatureSetSelected
? this.document.system.multiclassFeatures ? this.document.system.multiclassFeatures

View file

@ -380,11 +380,29 @@ export default class DhpPC extends foundry.abstract.TypeDataModel {
this.evasion = this.class?.system?.evasion ?? 0; this.evasion = this.class?.system?.evasion ?? 0;
// this.armor.value = this.activeArmor?.baseScore ?? 0; // this.armor.value = this.activeArmor?.baseScore ?? 0;
this.damageThresholds = this.computeDamageThresholds();
this.applyLevels(); this.applyLevels();
this.applyEffects(); 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() { applyLevels() {
let healthBonus = 0, let healthBonus = 0,
stressBonus = 0, stressBonus = 0,

View file

@ -7,7 +7,7 @@
</div> </div>
<div class="threshold-box"> <div class="threshold-box">
{{document.damageThresholds.major}} {{document.system.damageThresholds.major}}
</div> </div>
<div class="threshold-spacer"> <div class="threshold-spacer">
<i class="fa-solid fa-caret-left"></i> <i class="fa-solid fa-caret-left"></i>
@ -15,7 +15,7 @@
</div> </div>
<div class="threshold-box"> <div class="threshold-box">
{{document.damageThresholds.severe}} {{document.system.damageThresholds.severe}}
</div> </div>
<div class="threshold-spacer"> <div class="threshold-spacer">
<i class="fa-solid fa-caret-left"></i> <i class="fa-solid fa-caret-left"></i>