Made baseEffect.stacking nullable instead of having an enabled property

This commit is contained in:
WBHarry 2026-03-25 13:40:40 +01:00
parent 0fbe027d7d
commit 5ff1d0c71f
14 changed files with 70 additions and 43 deletions

View file

@ -151,6 +151,10 @@ export default class DhActiveEffectConfig extends foundry.applications.sheets.Ac
});
});
htmlElement
.querySelector('.stacking-change-checkbox')
?.addEventListener('change', this.stackingChangeToggle.bind(this));
htmlElement
.querySelector('.armor-change-checkbox')
?.addEventListener('change', this.armorChangeToggle.bind(this));
@ -209,6 +213,16 @@ export default class DhActiveEffectConfig extends foundry.applications.sheets.Ac
return partContext;
}
stackingChangeToggle(event) {
const stackingFields = this.document.system.schema.fields.stacking.fields;
const systemData = {
stacking: event.target.checked
? { value: stackingFields.value.initial, max: stackingFields.max.initial }
: null
};
return this.submit({ updateData: { system: systemData } });
}
armorChangeToggle(event) {
if (event.target.checked) {
this.addArmorChange();

View file

@ -89,12 +89,12 @@ export default class DhEffectsDisplay extends HandlebarsApplicationMixin(Applica
const element = event.target.closest('.effect-container');
const effects = DhEffectsDisplay.getTokenEffects();
const effect = effects.find(x => x.id === element.dataset.effectId);
if (!effect || (delta >= 0 && !effect.system.stacking?.enabled)) {
if (!effect || (delta >= 0 && !effect.system.stacking)) {
return;
}
const maxValue = effect.system.stacking.max ?? Infinity;
const newValue = Math.clamp((effect.system.stacking.value ?? 1) + delta, 0, maxValue);
const maxValue = effect.system.stacking?.max ?? Infinity;
const newValue = Math.clamp((effect.system.stacking?.value ?? 1) + delta, 0, maxValue);
if (newValue > 0) {
await effect.update({ 'system.stacking.value': newValue });
} else {

View file

@ -52,7 +52,7 @@ export default class DhTokenPlaceable extends foundry.canvas.placeables.Token {
const icon = new PIXI.Sprite(tex);
icon.tint = tint ?? 0xffffff;
if (effect?.system?.stacking?.enabled && effect.system.stacking.value > 1) {
if (effect.system.stacking?.value > 1) {
const stackOverlay = new PIXI.Text(effect.system.stacking.value, {
fill: '#f3c267',
stroke: '#000000',

View file

@ -81,17 +81,19 @@ export default class BaseEffect extends foundry.data.ActiveEffectTypeDataModel {
label: 'DAGGERHEART.GENERAL.range'
})
}),
stacking: new fields.SchemaField({
enabled: new fields.BooleanField({ initial: false, label: 'DAGGERHEART.GENERAL.enabled' }),
value: new fields.NumberField({
initial: 1,
min: 1,
integer: true,
nullable: false,
label: 'DAGGERHEART.GENERAL.value'
}),
max: new fields.NumberField({ integer: true, label: 'DAGGERHEART.GENERAL.max' })
})
stacking: new fields.SchemaField(
{
value: new fields.NumberField({
initial: 1,
min: 1,
integer: true,
nullable: false,
label: 'DAGGERHEART.GENERAL.value'
}),
max: new fields.NumberField({ integer: true, label: 'DAGGERHEART.GENERAL.max' })
},
{ nullable: true, initial: null }
)
};
}

View file

@ -109,15 +109,13 @@ export default class DhActiveEffect extends foundry.documents.ActiveEffect {
}
const existingEffect = this.actor.effects.find(x => x.origin === data.origin);
const stacks = data.system?.stacking?.enabled;
const stacks = Boolean(data.system?.stacking);
if (existingEffect && !stacks) return false;
if (existingEffect && stacks) {
const incrementedValue = existingEffect.system.stacking.value + 1;
await existingEffect.update({
'system.stacking.value': existingEffect.system.stacking.max
? Math.min(incrementedValue, existingEffect.system.stacking.max)
: incrementedValue
'system.stacking.value': Math.min(incrementedValue, existingEffect.system.stacking.max ?? Infinity)
});
return false;
}
@ -198,17 +196,13 @@ export default class DhActiveEffect extends foundry.documents.ActiveEffect {
} catch (_) {}
}
const evalValue = this.effectSafeEval(this.effectRollParse(key, parseModel, effect.parent, effect));
const stackingParsedValue = effect.system.stacking
? Roll.replaceFormulaData(key, { stacks: effect.system.stacking.value })
: key;
const evalValue = itemAbleRollParse(stackingParsedValue, parseModel, effect.parent);
return evalValue ?? key;
}
static effectRollParse(value, actor, item, effect) {
const stackingParsedValue = effect.system.stacking?.enabled
? Roll.replaceFormulaData(value, { stacks: effect.system.stacking.value })
: value;
return itemAbleRollParse(stackingParsedValue, actor, item);
}
/**
* Altered Foundry safeEval to allow non-numeric return
* @param {string} expression