Closed coreyabrown closed 3 years ago
Makes sense. I hate the way I did these Regexes. Ugh... these things were refactored so many times, this one probably fell through the cracks.
Anyway, just built a new computer, and my IDE isn't set up yet. It'll take me a couple days, but should be a very easy fix.
Cool! I tried to fix it myself, but my computer is so crappy, I couldn't even install npm!!
I jinxed myself by calling this an easy fix.
Got it mostly working, but I'm currently stuck on PF2E's rule that you should always round down on fractions. The current way the math works is that all dice are rolled, and then the math is done. This will lead to very odd results for complex math.
I'll think on this some more. Worst case, I can always release with multiplication support as that's safe from this issue.
That's true. Division would cause problems, but multiplication and parentheses should always result in whole numbers based on the possible inputs.
Also, re-reading my proposed fix, it looks like the escape characters weren't saved in my copy paste! You'd likely add the following to the regex:
|\*|(|)
You probably already knew that, just figured I would clarify!
I think I have a solution, but it'll require some refactoring. On the plus side, I'll be able to remove an entire dependency while also heavily increasing the amount of stuff the roller can do.
Consider changing the propertiesRegex to the line below to allow for multiplication and division when adding properties as well as parentheses. This would allow automatic rolling for critical hits i.e. criticalbowdamage:=2*({1d6}+{1d6})+{1d10}
In the example below, I added "|*|\/|(|)" to the existing regex to allow the other characters that math.js should be able to handle.
propertiesRegex = /(?!)?(?\w+):((?\d+)(\/|\)(?\d+)|(?(=?(\w|[|]|{|}|+|-|*|\/|(|))+)))/g;