Skip to content

Commit

Permalink
fix: prevent undesired bypass of damage dialog (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
akrigline authored Jan 23, 2022
1 parent 38a5a79 commit 4defb20
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions scripts/patches/item-damage-patch.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,15 @@ export function patchItemRollDamage() {
config = {}
};

let { formulaGroup = 0, event = {}, critical = event[advModifier], options = {} } = config;
let {
formulaGroup = 0,
event = {},
critical = event[advModifier],
fastForward = rollDialogBehaviorSetting === "skip"
? !event[showDamageDialogModifier] && !event[advModifier]
: event[showDamageDialogModifier] || event[advModifier],
options = {}
} = config;

// Set up initial inner roll parameters
const actionTypeDamageType = this.data.data.actionType === "heal"
Expand All @@ -29,19 +37,21 @@ export function patchItemRollDamage() {
let rollMode = options.rollMode ?? game.settings.get("core", "rollMode");
let bonus = null;

const shouldShowDialog = !critical && (rollDialogBehaviorSetting === "skip"
? event[showDamageDialogModifier]
: !event[showDamageDialogModifier]);
// Show a custom dialog that applies to all damage parts
if (shouldShowDialog) {
if (!fastForward) {
const dialogOptions = mergeObject(
options.dialogOptions || {},
{
top: event?.clientY ? event.clientY - 80 : null,
left: event?.clientX ? window.innerWidth - 710 : null,
}
);
const dialogData = await _damageDialog({ title, rollMode, dialogOptions });
const dialogData = await _damageDialog({
title,
rollMode,
defaultButton: critical ? 'critical' : 'normal',
dialogOptions
});

if (!dialogData) return null;

Expand Down Expand Up @@ -95,7 +105,7 @@ export function patchItemRollDamage() {
* @returns {Promise<{ critical: Boolean, bonus: Number, rollMode: String }>}
* @private
*/
async function _damageDialog({ title, rollMode, dialogOptions } = {}) {
async function _damageDialog({ title, rollMode, defaultButton, dialogOptions } = {}) {
const template = "systems/dnd5e/templates/chat/roll-dialog.html";
const dialogData = {
formula: "",
Expand All @@ -120,7 +130,7 @@ async function _damageDialog({ title, rollMode, dialogOptions } = {}) {
callback: html => resolve({ critical: false, ..._parseDamageDialog(html[0].querySelector("form")) })
},
},
default: "normal",
default: defaultButton ?? 'normal',
close: () => resolve(null)
}, dialogOptions).render(true);
});
Expand Down

0 comments on commit 4defb20

Please sign in to comment.