From ed54e2dbd8b54e2359ee8aab847981c9b7bfcf20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Fr=C3=B6lich?= Date: Tue, 9 Sep 2025 20:41:43 +0200 Subject: [PATCH 1/3] refactor(#266): move private sanity logic into prepareContext --- CHANGELOG.md | 6 ++++++ module/sheets/base-actor-sheet.js | 15 +++++++++++++++ templates/actor/partials/sanity-agent.html | 21 +++++---------------- 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7c7aec2..33ec08c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Release/Patch Notes +## Version 1.7.0 - ????-??-?? + +### **Tech Debt** + +- [#267](https://github.com/deltagreen-foundryvtt/delta-green-foundry-vtt-system/pull/267) - Moved private sanity logic out of templates. + ## Version 1.6.1 - 2025-09-09 > Thanks to the following new contributor: [Tobifroe](https://github.com/tobifroe). diff --git a/module/sheets/base-actor-sheet.js b/module/sheets/base-actor-sheet.js index 7b1227c..76bd6bc 100644 --- a/module/sheets/base-actor-sheet.js +++ b/module/sheets/base-actor-sheet.js @@ -94,6 +94,21 @@ export default class DGActorSheet extends DGSheetMixin(ActorSheetV2) { this._prepareSkillTooltips(); } + // Handle private sanity setting, override for GMs. + const keepSanityPrivate = game.settings.get( + "deltagreen", + "keepSanityPrivate", + ); + if (keepSanityPrivate && !game.user.isGM) { + context.maxSan = "???"; + context.currentSan = "???"; + context.keepSanityPrivate = true; + } else { + context.maxSan = this.actor.system.sanity.max; + context.currentSan = this.actor.system.sanity.value; + context.keepSanityPrivate = false; + } + // Set sanity block per actor type. context.sanityInputs = await foundry.applications.handlebars.renderTemplate( `${DGActorSheet.TEMPLATE_PATH}/partials/sanity-${this.actor.type}.html`, diff --git a/templates/actor/partials/sanity-agent.html b/templates/actor/partials/sanity-agent.html index 3a84228..cf37ebb 100644 --- a/templates/actor/partials/sanity-agent.html +++ b/templates/actor/partials/sanity-agent.html @@ -1,27 +1,16 @@ -{{#if (keepSanityPrivate)}} - -/ -
-
???
-
-{{else}} /
-
{{numberFormat actor.system.sanity.max decimals=0 sign=false}}
+
{{ maxSan }}
-{{/if}} From e377bda6444623fee0c857dcc8f2618ceec9e52e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Fr=C3=B6lich?= Date: Wed, 10 Sep 2025 09:31:50 +0200 Subject: [PATCH 2/3] chore: improve private sanity logic readability --- CHANGELOG.md | 6 -- module/sheets/base-actor-sheet.js | 144 ++++++++++++------------------ 2 files changed, 57 insertions(+), 93 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 33ec08c..7c7aec2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,11 +1,5 @@ # Release/Patch Notes -## Version 1.7.0 - ????-??-?? - -### **Tech Debt** - -- [#267](https://github.com/deltagreen-foundryvtt/delta-green-foundry-vtt-system/pull/267) - Moved private sanity logic out of templates. - ## Version 1.6.1 - 2025-09-09 > Thanks to the following new contributor: [Tobifroe](https://github.com/tobifroe). diff --git a/module/sheets/base-actor-sheet.js b/module/sheets/base-actor-sheet.js index 76bd6bc..9b4e0f8 100644 --- a/module/sheets/base-actor-sheet.js +++ b/module/sheets/base-actor-sheet.js @@ -99,15 +99,11 @@ export default class DGActorSheet extends DGSheetMixin(ActorSheetV2) { "deltagreen", "keepSanityPrivate", ); - if (keepSanityPrivate && !game.user.isGM) { - context.maxSan = "???"; - context.currentSan = "???"; - context.keepSanityPrivate = true; - } else { - context.maxSan = this.actor.system.sanity.max; - context.currentSan = this.actor.system.sanity.value; - context.keepSanityPrivate = false; - } + const hideSan = keepSanityPrivate && !game.user.isGM; + + context.maxSan = hideSan ? "???" : this.actor.system.sanity.max; + context.currentSan = hideSan ? "???" : this.actor.system.sanity.value; + context.keepSanityPrivate = keepSanityPrivate; // Set sanity block per actor type. context.sanityInputs = await foundry.applications.handlebars.renderTemplate( @@ -784,110 +780,94 @@ export default class DGActorSheet extends DGSheetMixin(ActorSheetV2) { const currentGroup = typedSkills[targetSkill].group; let htmlContent = `
`; - htmlContent += ` `; + htmlContent += ` `; htmlContent += ` `; htmlContent += `
`; htmlContent += `
`; - htmlContent += ` `; + htmlContent += ` `; htmlContent += ` `; htmlContent += `
`; @@ -925,40 +905,31 @@ export default class DGActorSheet extends DGSheetMixin(ActorSheetV2) { let htmlContent = ""; htmlContent += `
`; - htmlContent += ` `; + htmlContent += ` `; htmlContent += ` `; htmlContent += `
`; htmlContent += `
`; - htmlContent += ` `; + htmlContent += ` `; htmlContent += ` `; htmlContent += `
`; @@ -1096,9 +1067,8 @@ export default class DGActorSheet extends DGSheetMixin(ActorSheetV2) { ([key, skill]) => ({ value: key, group: optionGroups.typedSkills, - label: `${game.i18n.localize(`DG.TypeSkills.${skill.group}`)} (${ - skill.label - })`, + label: `${game.i18n.localize(`DG.TypeSkills.${skill.group}`)} (${skill.label + })`, targetNumber: skill.proficiency, }), ); From d4d615e98613559039268a0825f793336dbfbbbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Fr=C3=B6lich?= Date: Wed, 10 Sep 2025 09:34:08 +0200 Subject: [PATCH 3/3] fix: use builtin input disabled helper, lint --- module/sheets/base-actor-sheet.js | 130 ++++++++++++--------- templates/actor/partials/sanity-agent.html | 4 +- 2 files changed, 79 insertions(+), 55 deletions(-) diff --git a/module/sheets/base-actor-sheet.js b/module/sheets/base-actor-sheet.js index 9b4e0f8..c82f66b 100644 --- a/module/sheets/base-actor-sheet.js +++ b/module/sheets/base-actor-sheet.js @@ -780,94 +780,110 @@ export default class DGActorSheet extends DGSheetMixin(ActorSheetV2) { const currentGroup = typedSkills[targetSkill].group; let htmlContent = `
`; - htmlContent += ` `; + htmlContent += ` `; htmlContent += ` `; htmlContent += `
`; htmlContent += `
`; - htmlContent += ` `; + htmlContent += ` `; htmlContent += ` `; htmlContent += `
`; @@ -905,31 +921,40 @@ export default class DGActorSheet extends DGSheetMixin(ActorSheetV2) { let htmlContent = ""; htmlContent += `
`; - htmlContent += ` `; + htmlContent += ` `; htmlContent += ` `; htmlContent += `
`; htmlContent += `
`; - htmlContent += ` `; + htmlContent += ` `; htmlContent += ` `; htmlContent += `
`; @@ -1067,8 +1092,9 @@ export default class DGActorSheet extends DGSheetMixin(ActorSheetV2) { ([key, skill]) => ({ value: key, group: optionGroups.typedSkills, - label: `${game.i18n.localize(`DG.TypeSkills.${skill.group}`)} (${skill.label - })`, + label: `${game.i18n.localize(`DG.TypeSkills.${skill.group}`)} (${ + skill.label + })`, targetNumber: skill.proficiency, }), ); diff --git a/templates/actor/partials/sanity-agent.html b/templates/actor/partials/sanity-agent.html index cf37ebb..d3658d2 100644 --- a/templates/actor/partials/sanity-agent.html +++ b/templates/actor/partials/sanity-agent.html @@ -3,9 +3,7 @@ breaking-point-hit{{/if }}" type="text" name="system.sanity.value" - {{#if keepSanityPrivate }} - readonly - {{/if }} + {{disabled keepSanityPrivate}} value="{{ currentSan }}" data-dtype="Number" data-tooltip="{{localize 'DG.Tooltip.CurrentSanityPartOne' }}{{actor.system.sanity.currentBreakingPoint }}{{localize 'DG.Tooltip.CurrentSanityPartTwo' }}" />