Skip to content

Commit

Permalink
Merge pull request #2591 from Azmoria/Fix---allow-non-standard-dice-w…
Browse files Browse the repository at this point in the history
…ith-disabled-ddb-dice-again

Fix - allow non-standard dice with disabled ddb dice again
  • Loading branch information
Azmoria authored Oct 23, 2024
2 parents fab4817 + 2f38e50 commit e26d74e
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions DiceRoller.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/** DiceRoller.js - DDB dice rolling functions */

const allDiceRegex = /\d+d(?:100|20|12|10|8|6|4)(?:kh\d+|kl\d+|ro(<|<=|>|>=|=)\d+)*/g; // ([numbers]d[diceTypes]kh[numbers] or [numbers]d[diceTypes]kl[numbers]) or [numbers]d[diceTypes]
const rpgDiceRegex = /\d+d(?:\d+)(?:kh\d+|kl\d+|ro(<|<=|>|>=|=)\d+)*/g;
const validExpressionRegex = /^[dkhlro<=>\s\d+\-\(\)]*$/g; // any of these [d, kh, kl, spaces, numbers, +, -] // Should we support [*, /] ?
const validModifierSubstitutions = /(?<!\w)(str|dex|con|int|wis|cha|pb)(?!\w)/gi // case-insensitive shorthand for stat modifiers as long as there are no letters before or after the match. For example `int` and `STR` would match, but `mint` or `strong` would not match.
const diceRollCommandRegex = /^\/(r|roll|save|hit|dmg|skill|heal)\s/; // matches only the slash command. EG: `/r 1d20` would only match `/r`
Expand Down Expand Up @@ -147,6 +148,9 @@ class DiceRoll {

// find all dice expressions in the expression. converts "1d20+1d4" to ["1d20", "1d4"]
let separateDiceExpressions = parsedExpression.match(allDiceRegex)
if(window.EXPERIMENTAL_SETTINGS['rpgRoller'] == true){
separateDiceExpressions = parsedExpression.match(rpgDiceRegex);
}
if (!separateDiceExpressions) {
console.warn("Not parsing expression because there are no valid dice expressions within it", expression);
$('#chat-text:focus').addClass("chat-error-shake");
Expand Down

0 comments on commit e26d74e

Please sign in to comment.