[v14] Add toggle for critical damage (#1762)

* Fix rolling critical damage after rerolling into a crit

* Add toggle for critical damage

---------

Co-authored-by: WBHarry <williambjrklund@gmail.com>
This commit is contained in:
Carlos Fernandez 2026-04-01 13:39:26 -04:00 committed by GitHub
parent e3b433cce9
commit 2b8e4cb2fa
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 51 additions and 2 deletions

View file

@ -22,6 +22,7 @@ export default class DamageDialog extends HandlebarsApplicationMixin(Application
},
actions: {
toggleSelectedEffect: this.toggleSelectedEffect,
toggleCritical: this.toggleCritical,
submitRoll: this.submitRoll
},
form: {
@ -53,6 +54,7 @@ export default class DamageDialog extends HandlebarsApplicationMixin(Application
context.hasHealing = this.config.hasHealing;
context.directDamage = this.config.directDamage;
context.selectedMessageMode = this.config.selectedMessageMode;
context.isCritical = this.config.isCritical;
context.rollModes = Object.entries(CONFIG.ChatMessage.modes).map(([action, { label, icon }]) => ({
action,
label,
@ -74,6 +76,11 @@ export default class DamageDialog extends HandlebarsApplicationMixin(Application
this.render();
}
static toggleCritical() {
this.config.isCritical = !this.config.isCritical;
this.render();
}
static toggleSelectedEffect(_event, button) {
this.selectedEffects[button.dataset.key].selected = !this.selectedEffects[button.dataset.key].selected;
this.render();

View file

@ -7,6 +7,10 @@ export default class DamageRoll extends DHRoll {
super(formula, data, options);
}
get isCritical() {
return !!this.options.isCritical;
}
static DefaultDialog = DamageDialog;
static async buildEvaluate(roll, config = {}, message = {}) {
@ -138,6 +142,7 @@ export default class DamageRoll extends DHRoll {
}
constructFormula(config) {
this.options.isCritical = config.isCritical;
for (const [index, part] of this.options.roll.entries()) {
part.roll = new Roll(Roll.replaceFormulaData(part.formula, config.data));
part.roll.terms = Roll.parse(part.roll.formula, config.data);