Added a Setting that controls if scroll texts should be shown on resource change (#578)

This commit is contained in:
WBHarry 2025-08-05 04:14:23 +02:00 committed by GitHub
parent 089657a896
commit 04fbf9db4f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 95 additions and 1 deletions

View file

@ -1,4 +1,5 @@
import DHBaseActorSettings from '../../applications/sheets/api/actor-setting.mjs';
import { createScrollText, getScrollTextData } from '../../helpers/utils.mjs';
const resistanceField = (resistanceLabel, immunityLabel, reductionLabel) =>
new foundry.data.fields.SchemaField({
@ -88,4 +89,28 @@ export default class BaseDataActor extends foundry.abstract.TypeDataModel {
const data = { ...this };
return data;
}
async _preUpdate(changes, options, userId) {
const allowed = await super._preUpdate(changes, options, userId);
if (allowed === false) return;
const autoSettings = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Automation);
if (changes.system?.resources && autoSettings.resourceScrollTexts) {
const textData = Object.keys(changes.system.resources).reduce((acc, key) => {
const resource = changes.system.resources[key];
if (resource.value !== undefined && resource.value !== this.resources[key].value) {
acc.push(getScrollTextData(this.resources, resource, key));
}
return acc;
}, []);
options.scrollingTextData = textData;
}
}
_onUpdate(changes, options, userId) {
super._onUpdate(changes, options, userId);
createScrollText(this.parent, options.scrollingTextData);
}
}

View file

@ -8,7 +8,7 @@
* @property {boolean} isInventoryItem- Indicates whether items of this type is a Inventory Item
*/
import { addLinkedItemsDiff, updateLinkedItemApps } from '../../helpers/utils.mjs';
import { addLinkedItemsDiff, createScrollText, getScrollTextData, updateLinkedItemApps } from '../../helpers/utils.mjs';
import { ActionsField } from '../fields/actionField.mjs';
import FormulaField from '../fields/formulaField.mjs';
@ -184,11 +184,20 @@ export default class BaseDataItem extends foundry.abstract.TypeDataModel {
if (allowed === false) return false;
addLinkedItemsDiff(changed.system?.features, this.features, options);
const autoSettings = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Automation);
const armorChanged =
changed.system?.marks?.value !== undefined && changed.system.marks.value !== this.marks.value;
if (armorChanged && autoSettings.resourceScrollTexts && this.parent.parent?.type === 'character') {
const armorData = getScrollTextData(this.parent.parent.system.resources, changed.system.marks, 'armor');
options.scrollingTextData = [armorData];
}
}
_onUpdate(changed, options, userId) {
super._onUpdate(changed, options, userId);
updateLinkedItemApps(options, this.parent.sheet);
createScrollText(this.parent?.parent, options.scrollingTextData);
}
}

View file

@ -40,6 +40,11 @@ export default class DhAutomation extends foundry.abstract.DataModel {
choices: CONFIG.DH.GENERAL.ruleChoice,
initial: CONFIG.DH.GENERAL.ruleChoice.onWithToggle.id,
label: 'DAGGERHEART.SETTINGS.Automation.FIELDS.damageReductionRulesDefault.label'
}),
resourceScrollTexts: new fields.BooleanField({
required: true,
initial: true,
label: 'DAGGERHEART.SETTINGS.Automation.FIELDS.resourceScrollTexts.label'
})
};
}