Skip to content

Commit

Permalink
Uses proper wait for dice so nice wait
Browse files Browse the repository at this point in the history
  • Loading branch information
ChasarooniZ committed Oct 28, 2024
1 parent 6ce67bc commit 8f2e602
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 25 deletions.
20 changes: 2 additions & 18 deletions scripts/helpers/misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,8 @@ export function doSomethingOnDamageApply() {
);
}

export function handleDiceSoNice(func, params, msg = null) {
if (
game.modules.get("dice-so-nice")?.active &&
!game.settings.get("dice-so-nice", "immediatelyDisplayChatMessages") &&
msg?.rolls?.find((roll) => roll.dice.length > 0)
) {
const hookId = Hooks.on("diceSoNiceRollComplete", (id) => {
if (id === msg.id || msg === null) {
func(...params);
disableHook();
}
});
function disableHook() {
Hooks.off("diceSoNiceRollComplete", hookId);
}
} else {
func(...params);
}
export async function handleDiceSoNice(msg = null) {
return game.dice3d.waitFor3DAnimationByMessageID(message?.id);
}

export function localize(str) {
Expand Down
27 changes: 20 additions & 7 deletions scripts/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,15 @@ Hooks.on("ready", () => {
//Attack Roll Stuff
if (dat.isAttackRoll) {
// Rotate on Attack Roll
if (isRotateOnAttack()) handleDiceSoNice(rotateOnAttack, [msg], msg);
if (isShakeOnAttack(msg.token.actor))
handleDiceSoNice(shakeOnAttack, [msg.token, msg.flags.pf2e.context.outcome], msg);
if (isRotateOnAttack()) {
await handleDiceSoNice(msg);
rotateOnAttack(msg);
}

if (isShakeOnAttack(msg.token.actor)) {
await handleDiceSoNice(msg);
shakeOnAttack(msg.token, msg.flags.pf2e.context.outcome);
}
}

//On Damage Application
Expand Down Expand Up @@ -220,9 +226,15 @@ function checkRollNumbers(dat, msg) {
roll: msg.rolls[0]?.total ?? "",
type: msg.flags.pf2e.context.type,
};
if (doChecks) handleDiceSoNice(generateRollScroll, [roll_deets], msg);
if (doCrits && roll_deets.outcome === "criticalSuccess")
handleDiceSoNice(createCritAnimation, [roll_deets], msg);
if (doChecks) {
await handleDiceSoNice(msg);
generateRollScroll(roll_deets);
}
if (doCrits && roll_deets.outcome === "criticalSuccess") {
await handleDiceSoNice(msg);
createCritAnimation(roll_deets);
}

}
}

Expand All @@ -238,7 +250,8 @@ function damageRollNumbers(dat, msg) {
},
"Damage: "
);
handleDiceSoNice(generateDamageScroll, [dmg_list, targets, msg], msg);
await handleDiceSoNice(msg);
generateDamageScroll(dmg_list, targets, msg);
}
}

Expand Down

0 comments on commit 8f2e602

Please sign in to comment.