tom-wolfe / dice-typescript Goto Github PK
View Code? Open in Web Editor NEWA TypeScript library for parsing dice rolling expressions, most commonly used in tabletop RPGs.
License: MIT License
A TypeScript library for parsing dice rolling expressions, most commonly used in tabletop RPGs.
License: MIT License
Can you please publish the latest version (1.6.0) to NPM?
Hi,
Would it be possible, for performance reasons, to set up a customised & disableable limit for the number of faces / dice?
Thanks you for your work,
Add ellipsis syntax in groups for repetition, for example:
{2d20kl,...5}>=14
The above will repeat 2d20kl 5 times within the group, and mark each one a success if it is greater than or equal to 14.
Add support in the parser and interpreter, and write tests, for compare points to denote successes and failures. For example 5d20>13 denotes a success for all rolls over 13.
Happens for some cases such as:
6d10>=7\s
- This somehow produces a sa
thing for the dice roll. 6d10>=7 \s [2,3,8,9,10,10]>=7sa๐ฒ 4(2) = 42
When I try and use this in my typescript project, tsc complains about the *.d.ts files missing.
Visual Studio Code error below:
attributes.ts(2,23): error TS7016: Could not find a declaration file for module 'dice-typescript'. '/Users/williamlightning/Documents/Projects/working/node_modules/dice-typescript/dist/index.js' implicitly has an 'any' type.
Try `npm install @types/dice-typescript` if it exists or add a new declaration (.d.ts) file containing `declare module 'dice-typescript';`
The terminal process terminated with exit code: 2
In the section describing implementation of custom functions, a type ErrorMessage[]
is referenced. Should be InterpreterError[]
.
I forked this repo to try to add the amount of results kept or dropped in the renderedExpression. If I roll this 5d6d2
, I would like to see the renderedExpression [5, 4, 1, 2, 2]dl2
(currently it only shows [5, 4, 1, 2, 2]dl
, withou the amount dropped).
I tried two approaches to this:
amount
to the Keep/Drop Expression. This was done in the parseKeep/parseDrop
method. Then the generators must read this new attribute and show the amount.generateKeep
and generateDrop
methods to read the Keep/Drop childs and figure out the amount kept/dropped.Wich one of this approaches should I follow? I'm not sure wich one is the best. There is any other way? I can make a pull request after adding this feature.
As far as I can tell, 'keep' expressions (k[hl]?\d+
) are being ignored because the lexer does not have the token for it defined. When debugging, parseKeep
is skipped. (Apparently it should just be an TokenType
is missing a Keep
entry.Identifier
, but still, the keep functionality does not appear to be accessible).
The change in #22 added a check to explode/reroll condition to verify if the condition included all dice results (if that was allowed if would make explodes/rerolls forever). Roll20 don't do that, it simply allows 1000 rerolls and then stops (accepting the last roll, whatever it is). Try using this dice roll in Roll20: /roll 1d2r<3
(wait a few seconds to get a result).
Explode/reroll logic is done with while
:
https://github.com/trwolfe13/dice-typescript/blob/dce5f9b6126ede665883f587704423bb78d03660/src/interpreter/dice-interpreter.class.ts#L223
https://github.com/trwolfe13/dice-typescript/blob/dce5f9b6126ede665883f587704423bb78d03660/src/interpreter/dice-interpreter.class.ts#L341)
This would still cause infinite loops if adding more complex explode/reroll conditions (eg: d2r=1r=2
or d8r=4r<4r>4
)
How about setting a hard limit to rerolls (like Roll20 does)?
Currently the lexer, parser and interpreter only support inline integers. For example, the following is invalid:
3d6 * 1.5
While certainly not a common usage, it is a mathematically valid expression. Add support for parsing real numbers in the lexer, parser and interpreter, and write the appropriate unit tests for them.
The Getting Started section states:
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.
However, I don't see a deployment section in the main README or associated documentation. Is that section somewhere I'm not seeing, or still in progress?
Thanks!
Currently dice modifiers such as exploding dice, re-rolling dice, etc. are not supported.
Support for these should be implemented in the parser and interpreter, and have appropriate tests written.
Showing the total works great, it'd be nice to also be able to show the individual results, or a populated expression: 4d10dl2 + 5
would give you [1*,7,4*,5] + 5
.
Maybe a renderedExpression property on Result
?
I tried looking at this, but typescript/javascript are not my forte, and I got lost in the AST/Expressions.
Really cool project, even cooler when I saw the 5th ed e-tools you've put together!
For example, trying to roll the expression something
will crash.
Looking at the stack trace, I think it is crashing when trying to interpret something
as a function name. which I haven't defined. Notably, an error message is added to the error message array, but that doesn't seem to matter since we immediately try to find and call a function with that name.
Personally, I would expect the roll
method to return a result with most of the values undefined
or null
or something similar, but allowing me to access the error messages. Alternatively, if you do want to just throw an error, it would be nice if the error message described the problem with the expression (e.g., No function called "something" defined in dice interpreter
).
Currently it is possible to achieve a decimal dice roll. Take the following example:
(5 / 2)d20
Exactly how this is handled is not defined. It should explicitly round the 5 / 2 to the nearest integer.
Make sure this is the case, write unit tests for it and update the documentation.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.