From 3c59fa59d74ccaf17b8c0bfc721efe16399e6c93 Mon Sep 17 00:00:00 2001
From: Azmoria <65363489+Azmoria@users.noreply.github.com>
Date: Mon, 28 Oct 2024 02:26:57 -0400
Subject: [PATCH] QoL - add damage type option to /dmg rolls after `:`eg.
`/dmg 8d6 fireball:fire`; Wrap gamelog roll type below action name so it's
never cut off
---
CharactersPage.js | 7 +++++--
ChatObserver.js | 26 +++++++-------------------
DiceRoller.js | 19 ++++++++++++++-----
MessageBroker.js | 2 +-
abovevtt.css | 24 ++++++++++++++++++++++--
5 files changed, 49 insertions(+), 29 deletions(-)
diff --git a/CharactersPage.js b/CharactersPage.js
index 2f57f2f7b..e5312d346 100644
--- a/CharactersPage.js
+++ b/CharactersPage.js
@@ -444,6 +444,7 @@ function getRollData(rollButton){
let expression = '';
let rollType = 'custom';
let rollTitle = 'AboveVTT';
+ let damageType = undefined;
if($(rollButton).find('.ddbc-damage__value').length>0){
expression = $(rollButton).find('.ddbc-damage__value').text().replace(/\s/g, '');
}
@@ -462,7 +463,9 @@ function getRollData(rollButton){
rollType = $(rollButton).attr('data-rolltype');;
}
if($(rollButton).hasClass('avtt-roll-formula-button')){
- expression = DiceRoll.fromSlashCommand($(rollButton).attr('data-slash-command')).expression;
+ let slashCommand = DiceRoll.fromSlashCommand($(rollButton).attr('data-slash-command'))
+ expression = slashCommand.expression;
+ damageType = slashCommand.damageType;
let title = $(rollButton).attr('title').split(':');
if(title != undefined && title[0] != undefined){
rollTitle = title[0];
@@ -520,7 +523,7 @@ function getRollData(rollButton){
const modifier = (roll.rolls.length > 1 && expression.match(/[+-]\d*$/g, '')) ? `${roll.rolls[roll.rolls.length-2]}${roll.rolls[roll.rolls.length-1]}` : '';
const followingText = $(rollButton)[0].nextSibling?.textContent?.trim()?.split(' ')[0]
- const damageType = followingText && window.ddbConfigJson.damageTypes.some(d => d.name.toLowerCase() == followingText.toLowerCase()) ? followingText : undefined
+ damageType = followingText && window.ddbConfigJson.damageTypes.some(d => d.name.toLowerCase() == followingText.toLowerCase()) ? followingText : damageType;
return {
diff --git a/ChatObserver.js b/ChatObserver.js
index 89bd936c6..82a079bae 100644
--- a/ChatObserver.js
+++ b/ChatObserver.js
@@ -61,27 +61,15 @@ class ChatObserver {
#parseSlashCommand(text) {
let diceRoll = DiceRoll.fromSlashCommand(text);
- if(window.AboveDice){
+
+ let didSend = window.diceRoller.roll(diceRoll); // TODO: update this with more details?
+ if (didSend === false) {
+ // it was too complex so try to send it through rpgDiceRoller
let expression = text.replace(diceRollCommandRegex, "").match(allowedExpressionCharactersRegex)?.[0];
- let roll = new rpgDiceRoller.DiceRoll(expression);
- let msgdata = {
- player: window.PLAYER_NAME,
- img: window.PLAYER_IMG,
- text: `
${roll.total}${roll.output}
`,
- whisper: (gamelog_send_to_text() != "Everyone") ? window.PLAYER_NAME : ``,
- language: $('#chat-language').val()
- };
- window.MB.inject_chat(msgdata);
- }
- else{
- let didSend = window.diceRoller.roll(diceRoll); // TODO: update this with more details?
- if (didSend === false) {
- // it was too complex so try to send it through rpgDiceRoller
- let expression = text.replace(diceRollCommandRegex, "").match(allowedExpressionCharactersRegex)?.[0];
- didSend = send_rpg_dice_to_ddb(expression, window.pc.name, window.pc.image, rollType, undefined, action);
- }
- return didSend;
+ didSend = send_rpg_dice_to_ddb(expression, window.pc.name, window.pc.image, rollType, undefined, action);
}
+ return didSend;
+
}
diff --git a/DiceRoller.js b/DiceRoller.js
index a4cd5e031..264e688e0 100644
--- a/DiceRoller.js
+++ b/DiceRoller.js
@@ -125,7 +125,7 @@ class DiceRoll {
* @param entityId {string|undefined} the id of the entity associated with this roll. If {entityType} is "character" this should be the id for that character. If {entityType} is "monster" this should be the id for that monster. If {entityType} is "user" this should be the id for that user.
* @param sendToOverride {string|undefined} if undefined, the roll will go to whatever the gamelog is set to.
*/
- constructor(expression, action = undefined, rollType = undefined, name = undefined, avatarUrl = undefined, entityType = undefined, entityId = undefined, sendToOverride = undefined) {
+ constructor(expression, action = undefined, rollType = undefined, name = undefined, avatarUrl = undefined, entityType = undefined, entityId = undefined, sendToOverride = undefined, damageType = undefined) {
let parsedExpression = expression.replaceAll(/\s+/g, "").replaceAll(/^(d\d+)|([+-])(d\d+)/g, '$21$1$3');; // remove all spaces and 1's to d6 -> 1d6, d8 -> 1d8 etc.
@@ -173,6 +173,7 @@ class DiceRoll {
this.action = action;
this.rollType = rollType;
this.sendToOverride = sendToOverride;
+ this.damageType = damageType;
if (name) this.name = name;
if (avatarUrl) this.avatarUrl = avatarUrl;
if (entityType) this.entityType = entityType;
@@ -225,12 +226,14 @@ class DiceRoll {
let action = modifiedSlashCommand.replace(diceRollCommandRegex, "").replace(allowedExpressionCharactersRegex, "");
console.debug("DiceRoll.fromSlashCommand text: ", slashCommandText, ", slashCommand:", slashCommand, ", expression: ", expression, ", action: ", action);
let rollType = undefined;
+ let damageType = undefined;
if (slashCommand.startsWith("/r")) {
// /r and /roll allow users to set both the action and the rollType by separating them with `:` so try to parse that out
[action, rollType] = action.split(":") || [undefined, undefined];
} else if (slashCommand.startsWith("/hit")) {
rollType = "to hit";
} else if (slashCommand.startsWith("/dmg")) {
+ [action, damageType] = action.split(":") || [action, undefined];
rollType = "damage";
} else if (slashCommand.startsWith("/skill")) {
rollType = "check";
@@ -239,7 +242,7 @@ class DiceRoll {
} else if (slashCommand.startsWith("/heal")) {
rollType = "heal";
}
- return new DiceRoll(expression, action, rollType, name, avatarUrl, entityType, entityId, sendToOverride);
+ return new DiceRoll(expression, action, rollType, name, avatarUrl, entityType, entityId, sendToOverride, damageType);
}
}
@@ -378,15 +381,18 @@ class DiceRoller {
if(damageType == undefined && this.#pendingDamageType != undefined){
damageType = this.#pendingDamageType;
}
+ else if(damageType == undefined && diceRoll.damageType != undefined){
+ damageType = diceRoll.damageType;
+ }
msgdata = {
player: diceRoll.name ? diceRoll.name : window.PLAYER_NAME,
img: diceRoll.avatarUrl ? diceRoll.avatarUrl : window.PLAYER_IMG,
text: `