Giter VIP home page Giter VIP logo

rpg-dice-roller's Introduction

RPG Dice Roller

RPG Dice Roller

npm (scoped) Build Status Coverage Status npm type definitions License npm downloads

A JS based dice roller that can roll various types of dice and modifiers, along with mathematical equations.

Install

npm install @dice-roller/rpg-dice-roller

Documentation

Check out the documentation at https://dice-roller.github.io/documentation

Usage in the wild

Official

  • Vue components - For Tailwind, Bootstrap, basic HTML, and renderless
  • Vuepress plugin - Dice roller plugin used in this documentation
  • CLI - Command Line Interface for rolling dice

Contributing

We're always happy for community contributions. You can find our contributing guide in the docs: https://dice-roller.github.io/documentation/contributing

Licence

This dice roller has been released under the MIT licence, meaning you can do pretty much anything you like with it, so long as the original copyright remains in place.

You can use it in commercial products.

If the licence terminology in the licence.txt is confusing, check out this: https://www.tldrlegal.com/l/mit

rpg-dice-roller's People

Contributors

atorasuunva avatar dependabot[bot] avatar greenimp avatar jamesskemp avatar parnas avatar vincerv avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rpg-dice-roller's Issues

Add method for returning DiceRoller total

Currently, you can only get the total of an individual DiceRoll. If you want to get the total of all DiceRolls on a DiceRoller object, you have to manually loop through each roll and sum the totals.

I propose that there be a public method on the DiceRoller object which returns the sum totals for all of its rolls.

It probably makes sense to name the method the same as on the DiceRoll; getTotal().

Allow manual building of dice rolls

We could potentially open up the DiceRoll class to allow manual building of the object, by passing in the notation, and list of rolls.

The rolls passed in would need validating against the notation.

This would allow us to programatically populate dice rolls, which could be handy for saving and loading of rolls.

0s in 1s place are ignored

E.g. 3d6+10 results in [4,4,1]+1 = 10, or d20+40 results in [6]+4 = 10 while d20+42 results in[2]+42 = 44

Roll-20 like dice rolling

RPG dice rolling function covering more features

  • addition, subtraction, multiplication, division
  • modulo, exponentiation
    Note: with modulus and exponentiation, at present, you need to surround the roll with parenthesis. ie. (1d6)%2, (1d6)^0.5 (See #90)
  • floor, round, ceil, abs (See #64)
    • Abilities are expanded (meaning the definition of the ability is placed in the formula anywhere that ability appears).
      Macros are expanded, including nested macros up to 99 levels deep.
      Variables are substituted
      Roll queries are executed (the player making the roll is asked to provide a value for each query, and that value is substituted in where the roll query appears in the formula)
      All previous steps are repeated until there are no longer any unresolved abilities, macros, variables, or queries. This allows for nesting (e.g. putting an attribute in a macro).
      Inline rolls are executed, starting with the most deeply nested inline roll working upward. The overall result of the inline roll is substituted in place where it appeared in the formula.
      The remaining roll is executed: first, dice are rolled for any dice (e.g. "2d6" is rolled; including any special dice such as dropped or exploding), then the result of that roll is substituted into the formula. Next, floor() and ceil() functions are executed. Finally, the entire remaining formula is evaluated, including observing proper math order of operations (parentheses first, then multiplication/division, then addition/subtraction).

  • All Types Of Dice
    • Basic Roll of NdX
    • Fate/Fudge Roll NdF
    • Computed Dice Roll (N+Y)dX or Nd(X+Y)
  • All Roll Modifiers
    • Target Number / Successes (B,F) - CP
    • Failures (B,F) - fCP
    • Exploding Dice (B,F) !CP
    • Compounding Dice (B,F) !!CP
    • Penetrating Dice (B,F) !pCP
    • [ ] Dice Matching m and mt
    • Keep / Drop Dice (B,F) khN or klN or dhN dlN (See #65)
    • Rerolling Dice (B,F) rCP (See #89)
    • Sorting Dice (B,F) sa or sd
    • Order of Operations for Modifiers
      • Exploding, Compounding, Penetrating, Rerolls
        These are applied while the dice are still rolling. imagine that you roll some exploding 6d6 on your table and the instant one of them settles as a 6 another die is rolled
        Keep, Drop, Success, Failure, Sorting
        These are applied after all of the dice have "settled" and all of the result values are known.

  • Grouped Rolls (See #88)
  • Grouped Roll Modifiers (See #88)
    • Keep / Drop khN or klN or dhN or dlN
    • Target Number / Successes (B,F) CP
    • Failures (B,F) fCP

Code: https://app.roll20.net/assets/dengine.js?v=123
Mirror: https://ghostbin.com/paste/2n67m
Reference: https://wiki.roll20.net/Dice_Reference

Allow parenthesis around equations

Currently parenthesis in equations are ignored, and can cause additions to be missed.

To enable greater control over how notation equations are calculated (Order of equations) parenthesis should be handled.

Also, currently additions are collected in such a way that they must directly precede the dice.
This will work (Although parenthesis will be ignored):

1d6+(2d8*2): [3]+[7,2]*2 = 21

But this will ignore the *2:

(1d6+2d8)*2: [3]+[7,2] = 12 // should equal 24

It should also allow nested parenthesis:

((1d6+2d8)*2)+(2d10-L)

This will probably mean reworking the entire parsing function, to loop individually through each block of parenthesis recursively, before then running equations on the block totals.

Compounding dice with L/H uses total of all rolls

When using compounding dice in conjuction with the H/L modifiers it calculates the values incorrectly.
Instead of using the Highest or Lowest roll, it sums all the rolls, and uses that, meaning that the compounded value returned is always 0 for -H/L and doubled for +H/L.

This works correctly:

2d6!!: [4, 14!!] = 18

These are incorrect:

2d6!!-L: [4, 14!!]-L = 0
2d6!!-H: [4, 14!!]-H = 0
2d6!!+L: [4, 14!!]+L = 36
2d6!!+H: [4, 14!!]+H = 36

It should be:

2d6!!-L: [4, 14!!]-L = 14
2d6!!-H: [4, 14!!]-H = 4
2d6!!+L: [4, 14!!]+L = 22
2d6!!+H: [4, 14!!]+H = 28

Instead of summing only rolls which compounded, it sums them all, so [4, 14!!] becomes [18!!]. So getting the max/min roll will always return 18 as it's now the only roll.

The roll array itself may look something like this:

[4, 6, 6, 2]

Where the last three are the compounded second roll.

Instead of summing the entire roll array, we only want to sum compounded rolls.

Target Numbers on roll groups

Describe the bug
There is a difference in the POV of the meaning of this simple formula 2d6>4
the >4 part mean threshold so every value above 4 will be counted as a success...
but I see many dice rollers (and roll20 which is the most complete reference IMHO) that this means target number which will evaluate the roll and then see if that value is bigger than 4.

To Reproduce
Steps to reproduce the behavior:

  1. Go to http://rpg.greenimp.co.uk/dice-roller/
  2. Imput 2d6>4 on the format box
  3. Check the result
  4. You can also try Imput (2d6)>4 on the format box

Observed behavior
1 success for any dice that is above 4

Expected behavior
1 success if all the formula totals more than 4

Exploding dice

Exploding dice roll an additional die if the maximum, on that die, is rolled. If that die is also the maximum it is rolled again, and so forth, until a roll is made that isn't the maximum.

ie. Rolling a 6, on a d6, a 10 on a d10.

By default, exploding dice count as separate dice rolls, rather than being silently added to the total. So the roll output could look something like:

2d6!: [4, 6!, 6!, 2] = 20

Where the second roll exploded, so we rolled again, which also exploded. The fourth role, however, did not, so we stop rolling.

I guess this means that we could use it with things like the L and H modifiers as well:

2d6!-L: [4, 6!, 6!, 2] = 18

Where we subtract the lowest of all rolls (including exploded ones).

Provide existing helper methods as public

There are various private helper methods being used throughout, which could benefit from being made public.

A few examples are:

  • equateNumbers
  • compareNumbers

They could be made available on the DiceRoller object, perhaps under a utils object: DiceRoller.utils.equateNumbers()

These could then also be tested in the unit tests (See #13), and also used during testing (Once their tests have passed).

Keeping/Dropping `n` dice

Look into the option of allowing the keeping/dropping of a specified number of dice that are either highest or lowest.

Maybe something like: 5d6DL2
Would mean "Roll 5d6 and drop the lowest 2 rolls"

We currently have H|L notation, to calculate based on the highest/lowest roll: 5d6-L
Would mean "Roll 5d6 and subtract (drop) the lowest result.

Repeat die throw patterns

Under the multiplication section of the Wikipedia dice notation, it says:

Multiplication can also mean repeating throws of similar setup (usually represented byย xย rather than multiplication symbol):

  • 3 x (2d6+4)ย means "roll two 6-sided dice adding four to result, repeat the roll 3 times adding the results together."

So this would do the same roll (2d6) and addition (+ 4) three times, summing the result:

(2d6+4)+(2d6+4)+(2d6+4)

This differs from this notation, using the multiplication symbol:

3 * (2d6+4)

Which would only do the roll (2d6) and addition (+4) once, and multiply the result by 3.

It would be good to be able to handle this, and also with the ability for the repeat number to be on the other side: (2d6+4) x 3 (See #1)

Bear in mind that this is an actual 'x' letter, not a multiplication symbol.

Compound exploding dice

Sometimes we want to compound exploding dice, rather than having them show as separate dice.
For example, the following:

2d6!: [4, 6!, 6!, 2] = 20

Would be compounded to:

2d6!: [4, 14!] = 20

Where the re-rolled dice are added to the original exploded roll.

Taking cue from Roll20's dice roller, the syntax should probably be double exclamation marks: !!. ie.

2d6!!: [4, 14!!] = 20

This is blocked by #4

Incorrect notation for compounding penetrating dice

When compounding and penetrating dice, the notation is not always correct. See the below examples:

2d2!!p: [1,2,1!!p] = 4;
2d2!!p: [3!!p,] = 4;
2d2!!p: [1,] = 2;
2d2!!p: [1,] = 2;
2d2!!p: [1,] = 2;
2d2!!p: [3!!p,] = 4

When rolling multiple dice, if the second (Maybe last if more than 2) roll doesn't penetrate, it seems to output nothing for the second role.
When rolling multiple dice, if the second penetrates multiple times, it doesn't compound the second with its other rolls.

Dice Re-rolls

Not the same as compounding or penetrating dice, this would re-roll dice if they meet the compare point, but the original value would be ignored.

Drop Bower support

Bower has long been deprecated in favour of other things. With this in mind, we should drop support for Bower, which basically means removing the bower.json file from the root directory.

To ensure removal causes the least amount of problems for those still using Bower to install rpg-dice-roller, we should release this change as a major version (v2.0.0).

More info on how to drop Bower support: https://bower.io/blog/2017/how-to-drop-bower-support/

Allow whitespace in notation

Notations don't currently allow for whitespace.

This is currently valid:

3d6-L+2

But this is currently not:

3d6 - L + 2

We should just ignore/strip out all whitespace from a notation.

Question: Dice Pools and counting hits

What would be the roll notation for 13 10-sided dice, count hits where the number on the dice is 5 or higher?
e.g. [10,5,5,4,3,1,8,8,10,4,2,10,1] = 7 hits

What would it be where 10s count as double? In the previous example, it would instead be 10 hits.

Allow rolling multiple notations at once

The DiceRoller.roll() method only allows you to pass a single notation at a time, meaning that to roll multiple notations at once you have to call it multiple times, like this:

const diceRoller = new DiceRoller();

const rolls = [];
rolls.push(diceRoller.roll('1d6'));
rolls.push(diceRoller.roll('5d10-H'));
rolls.push(diceRoller.roll('8d6'));

We should allow rolling of multiple notations in one go, like this:

const diceRoller = new DiceRoller();

const rolls = diceRoller.rollMany([
  '1d6',
  '5d10-H',
  '8d6',
]);

The method response would be to return an array of the DiceRolls - probably just a list of responses from DiceRoller.roll(), as I'm sure we can hook into that method.

See if we can remove Chrome requirement for CI

We were using the chrome engine for CI, to run Jasmine using Grunt. We're no longer using Grunt, and are just running Jasmine directly. I don't think this needs the Chrome engine anymore, as I think it uses Node's.

This should be tested and, if not required, removed from the Travis build as it slows CI down.

Cannot import an exported DiceRoller object

The DiceRoller export only exports the contents of the log property, so contains a list of logs, but the DiceRoller import expects an object with a log property.

Currently, we get something like this:

[{"notation":"2d2!p","rolls":[[1,1]]},{"notation":"2d2!p","rolls":[[2,0,2,1,1,0]]},{"notation":"2d2!p","rolls":[[2,1,0,1]]}]

Whereas the import is expecting this:

{
  log: [{"notation":"2d2!p","rolls":[[1,1]]},{"notation":"2d2!p","rolls":[[2,0,2,1,1,0]]},{"notation":"2d2!p","rolls":[[2,1,0,1]]}]
}

Either the import needs to be changed to accept an array of rolls, without a log property, or the export needs to include the log property.. or both.

Make `toString` methods openly public

The DiceRoller and DiceRoll objects both have a toString method, for outputting the notation as a string, when used in JS string contexts.

The functionality in these methods should be moved to their own functions, on their respective objects, which are publicly available (I know the toString method is public, but it's not obvious).
The toString method can then call these functions.

The functions will both be named getNotation.

Allow operations either side of the die

According to the multiplier notation information, mathematical operators can be either side of the die:
1d6*4 and 4*1d6 are both valid.

With multiplication it doesn't really make a difference, but with subtraction and division it could produce completely different results.
For example, 1d6-2 is completely different to 2-1d6

Currently, the regular expression only matches operations after the die. We should also handle those before the die.

Integrate automatic unit test

To ensure code consistency and that changes will not break the build, we should integrate continuous integration testing.

This will most likely be done with Travis and will require nodeJS.

Also to look in to automatically pushing up successful builds to the demo site: http://rpg.greenimp.co.uk/dice-roller/

Split classes etc. into separate files

To make it easier to maintain, the DiceRoller and DiceRoll classes should be split into their own files.
It would probably also be best to split the utility methods into their own (And maybe even the notation parsing), rather than as a property on the DiceRoller objects.

Strange behaviour with additions over 100

While testing the library out I ran into strange behaviour. When adding a number to a roll that is larger than 100 and is subject to certain conditions, a part of the number is ignored.

e.g. 1d1+102 will output [1]+10 = 11 instead of [1]+102 = 103

On the other hand 1d1+110 does output [1]+110 = 111

It seems like in numbers with more than 2 digits, every digit after the first 0 is ignored.

While this is likely not a big deal for most RPG situations, it is incorrect behavior nonetheless.

Node Js flatMap is not defined

Hello !
I ran into an issue with the latest version (3.1.0) in nodeJs
When calling :

const { DiceRoller } = require('rpg-dice-roller');
const diceRoller = new DiceRoller();
let roll = diceRoller.roll('1d100');

i got this error :

ReferenceError: flatMap is not defined
 at rollGroups (C:\git\project\node_modules\rpg-dice-roller\lib\umd\bundle.js:66659:15)

When i look a the function rollGroups i see :

return group.flatMap(function (elm) {...}

It seems a working flatmap function has been created in this script but outside the scope of rollGroups and this semantics is not supported by NodeJs...
It should must be something like this :
return flatMap(group,function(elem{...}))

Thanks in advance!

Penetrating Dice

Some exploding dice system use a penetrating rule. This works in exactly the same way as the normal exploding dice rules (See #4), except that the following dice rolled have 1 subtracted from their roll.

So, if I rolled 1d6 (penetrating), and got a 6, I would roll another d6, subtracting 1 from the result. If that d6 rolled a 6 (before the -1) it would penetrate, and so on.

This forum post on Roll20 explains it fairly succinctly: https://app.roll20.net/forum/post/2692/penetrating-dice-rolls-not-being-handled-properly

I'd suggest either of the following notations:

5d6!p  // this is what roll20 uses, so familiar to their users
5d6p   // excluding the `!` as it is almost functionality of it's own

It should also handle the Compare Points, as noted in #5 and possibly compounding, as mentioned in #6, although the syntax may have to change slightly.

Group Rolls

We should allow rolls to be grouped, so that we can carry out actions on a group at a time rather than individual rolls.

This was discussed briefly in #86
It would allow us to do things like {2d6}>4 to only return a success if the total rolled is greater than 4, rather than this, 2d6>4 which will check each roll.

Or, a better example, with multiple rolls is something like this: {4d6+2d8, 3d20+3, 5d10+1}>40

Without modifiers

If a roll group has no modifiers, then the total value of the group will be the totals of each sub-roll added together.

{4d6, 2d10, d4}: {[2, 6, 4, 2], [7, 4], [1]} = 26
  • Add sub-roll values together

Modifiers

With modifier's the total will still generally be the sum of the sub-rolls, but they will be altered by the modifiers first.

Applicable modifiers (Other's won't work with roll groups):

  • Keep
    Keep the best or last sub-roll result values.

    • For a single sub-roll, it will keep the specified number of dice out of all the rolls:
      // roll 4d10 and 5d6, out of those 9 dice, only keep the highest two. Then total the values
      {4d10*5d6}k2: {[8, 1d, 4d, 1d]*[1d, 5, 1d, 5d, 3d]} = 40
      
    • For multiple sub-rolls, it will keep the specified number of sub-rolls based on their total value:
      // roll the sub-rolls, total their values, and only keep the highest two
      {4d10, 5d6, 2d10}k2: {[8, 1, 4, 1], [1, 5, 1, 5, 3], [6, 3]d} = 29
      
  • Drop

    • Single sub-roll
    • Multiple sub-rolls

    Same as Keep, but for dropping.

    // roll the sub-rolls, total them, and drop the lowest
    {4d6+2d8, 3d20+3, 5d10+1}d1: {([3, 5, 3, 2]+[7, 4])d, [2, 14, 7]+3, [5, 7, 3, 9, 8]+1]} = 58
    

    Unsure on how to display modifiers for sub-rolls, but perhaps parenthesis like above could work.

  • Target success / failure

    • Single sub-roll
    • Multiple sub-rolls

    I need to look into how this should work. The functionality on Roll20 seems a bit strange, so not sure we should mimic this exactly. See details below.

  • Sorting

    • For a single sub-roll, it will sort each dice roll as though they all have the sorting modifier applied.
    • For multiple sub-rolls, it will also sort the sub-rolls themselves by result value

Target success / failure

Looking at how Roll20 handle it seems a bit illogical:

Single sub-rolls:

{3d20+5}>21 - Roll 3 d20's, for each roll add 5 and then count a success for each result of 21 or more.

So something like:

{3d20+5}>21: {[20+5, 7+5, 19+5]} = 2 successes

group-roll-target-success-single

Whereas I would logically expect it to roll 3 d20s and add 5 to the total, count a success if the total is greater than 21:

{3d20+5}>21: {[20, 7, 19]+5} = 1 success
Multiple sub-rolls

This works as expected:

{4d6+2d8, 3d20+3, 5d10+1}>40 - Roll each of the three sub-roll expression and total them up. Count one success for each sub-roll total of 40 or more.

It seems to handle the 3d20+3 correctly by rolling 3 d20s and adding 3 to the total, as can be seen here:

If it added 3 to each roll, this would pass:
group-roll-target-success-multiple

But this is the only roll that passes, because it's the only way to reach a value of 7 if it add 3 to the total:
group-roll-target-success-multiple-success

So there is an inconsistency with how mathematical equations are handled for sub-rolls, depending on whether there is one sub-roll, or multiple, which seems wrong and confusing to me.

'fudge' dice

It would be good to be able to handle 'fudge' dice. These are quite simple in that they are 6 sided dice with a plus (+), minus (-), or blank on each face.

As the wiki on Dice notation explains:

The default is one third of each [symbol], usually represented by a six-sided die with two of each, known as dF.2 or just dF. Four of these (4dF) are rolled to determine results from -4 to +4, which is equivalent to 4d3-8. Variants include dF.1, which is a six-sided die with four blanks, one plus and one minus.

So, just to clarify, dF.2 is the same as dF.

A single fudge dice (dF) is equal to 1d3-2.

For a dF.1, on 1d6 a roll of 1 = -1, 6 = +1, others = 0

Storytelling System type dice

This is a feature that will allow players of the Storytelling system to get clear results with one dice roll.

roll a dice pool target number 8+ and explode 9+ and if so how

In the Roll20 standard I would type /roll 6d10>=8!>=9 but that does not seem to work or /roll 6d10>7!>8

Exploding dice Compare Point

By default, exploding dice will explode when rolled to the highest number on the dice. However, some systems allow for the "Compare Point" to be changed.

A usage case is that I may want to explode a d6 only if I roll a 5, or if I roll anything greater than a 4.

For example, 3d6!5 would explode only if a 5 is rolled. 3d6!>4 would explode on any dice greater than 4.

Other options:

3d6!<4   // explode on any dice less than 3
3d6!>=4  // explode on any dice greater than or equal to 4
3d6!<=4  // explode on any dice less than or equal to 4

This is blocked by #4

Build documentation

The readme is very long, and is difficult to find what you want. The demo page is outdated.

We need to build a proper documentation site that can be split into multiple pages, with example code and better readability.

This documentation should have interactive rollers, and can replace the demo files in the repo.

Any help/advice on good systems for writing documentation would be appreciated.

  • Documentation
    • Choose framework to use
    • Build component to enable dice rolling inside the documentation
    • Write documentation (TBC)
  • Delete /demo/ files from repository
  • Add link to documentation to readme

Separate `DiceRoll` function for returning and calculating totals

The only way to calculate the DieRoll total is currently to use the diceRoll.total getter property.

This can be confusing if we want to calculate the total, but not set it to a variable, and JSHint doesn't like it:

diceRoller.total;

Throws:

Expected and assignment or function call and instead saw an expression.

For this reason, and the fact that it would be best to split functionality and value returning, we should create a separate (private) method for calculating the total.

Probably called calculateTotal

Exploded die with compare point or penetration has incorrect notation

If an exploding die has a compare point, and the dies didn't roll the maximum amount, the notation doesn't add the expected "!" mark.

ie.

1d6!>2: [5,3,6!,1] = 6

Should be:

1d6!>2: [5!,3!,6!,1] = 6

This also happens with penetrating dice:

ie.

1d6!p: [6!,5,3] = 14

Should be:

1d6!p: [6!,5!,3] = 14

Another case is where it doesn't explode, but the notation flags it as so. This happens when the compare point is lower than the max possible on the dice, and the max is rolled.

ie.

1d2!<2: [2!] = 2

Should be:

1d2!<2: [2] = 2

Unit test throws the following:

Expected "1d2!<2: [2!] = 2" to match parsed notation "1d2!<2: [2] = 2"

This is also apparent on compounding dice.

Tests for Utility functions

We've not currently got any tests for the utility functions in DiceRoller.utils.

Automated Jasmine tests should be added.

Success / Failure dice rolls (Pool dice)

Allow for dice pool style success / failure roll counts, where you can specify a compare point and any dice matching it are classed as successes, others are failures. When calculating the total, instead of summing the numbers, we count the number of successful rolls, and visually show that it's success being displayed and not a total.

For example:

13d10>=5: [10,5,5,4,3,1,8,8,10,4,2,10,1] = 7 successes // success is greater than or equal to 5
4d6>=4: [3,4,6,2] = 2 successes // success is greater than or equal to 4
4d6<3: [3,4,6,2] = 2 successes // success is less than 2
4d6=6: [3,4,6,2] = 1 successes // success is equal to 6

Information:

Allow decimal points in arithmetic numbers

Currently only whole numbers can be used in notation. Any decimal points are ignored.

Passing the notation of 1d6+2.5 would give an output like:

1d6+2.5: [1]+2 = 3

Where the .5 gets stripped out.

I think decimals should only be allowed for numbers as part of an equation, and not as any part of the dice. It wouldn't make sense to roll 2.5d3.4

Ambiguity of `notation` and `getNotation`

DiceRoll objects have two very similarly named properties/methods:

  • A notation property, which contains the notations used when the object was created; 2d6
  • A getNotation() method which returns the whole parsed notation and rolls; 2d6: [3, 6] = 9

They do two very different things, but the naming makes it seem as though they should probably be the same. It is very ambiguous.

As the term notation refers to the string representation of the dice to be rolled (ie. 2d6), I suggest the the getNotation() method be renamed to something more appropriate.

This will also affect the DiceRoller.getNotation() method, as it functions similarly to the DiceRoll.getNotation() method.

Return parsed notation as typed object

The parsed notation is currently returned as a generic object, in the following format:

{
          operator:   +|-|/|*, // dice operator for concatenating with previous rolls
          qty:        {Number}  // number of times to roll the die
          sides:      {Number|String},  // how many sides the die has
          fudge:      {Object|null},                                            // if fudge die this is set to the fudge notation match
          explode:    {boolean},                                             // flag - whether to explode the dice rolls or not
          penetrate:  {boolean},                // flag - whether to penetrate the dice rolls or not
          compound:   {boolean},                // flag - whether to compound exploding dice or not
          additions:  {Array}                                                       // list of any additions (ie. +2, -L)
        }

It might be good to return a strict type object/class instance, to help ensure property sanity.

TypeScript definitions file

Is your feature request related to a problem? Please describe.
No. This is an enhancement request.

Describe the solution you'd like
I recently discovered this library and would love to use it in a project that uses TypeScript. To best enable this it would be great if typings were available.

Describe alternatives you've considered
I plan on working on a TypeScript definition file for my own use, but if there's interest, think it would benefit this project if it were included.

Additional context
My plan is to create the initial TypeScript definitions via dts-gen (already done) and then update them based upon this project's actual documentation. I would then be testing it in my own project.

I understand that TypeScript definitions may not appeal to you, depending upon your own usage and target audience, and since it does require updating if the library changes, so not a big deal if you're not interested. Just want to gauge if there's interest as that will determine how much effort I put into this.

Thanks for the great library!

Including dice-roller.js causes app to load forever

I'm having two issues with rpg-dice-roller.

First, npmjs.org does not have the current release (1.5.0); it only has up to 1.3.0.

Also, including dice-roller.js causes my entire app to load forever (even if I'm not calling it dice-roller.js). The app just sits in a loading state forever. When I remove the include for dice-roller.js, the app loads fine. I've verified that this issue exists in 1.3.0 and 1.5.0. I've not tried other versions.

I don't think it's my code because merely doing this:
require('./dice-roller.js')
causes my app to sit in a loading state forever.

There are no errors being thrown. I only see these warnings, but they appear to be irrelevant:

webpackHotDevClient.js:138 ./src/dice-roller.js
Line 11: 'use strict' is unnecessary inside of modules strict
Line 24: 'use strict' is unnecessary inside of modules strict
Line 275: Expected a default case default-case
Line 719: Missing radix parameter radix

I'm running NodeJS 8.11.2.

Thanks!

Use modulus and exponentiation without parenthesis

Describe the bug
Currently, to use modulus or exponentiation in notation, you must surround the dice roll in parenthesis, otherwise the modulus and exponentiation gets ignored.

To Reproduce
Roll a notation like: 1d6^0.5, or 1d6%2

Expected behavior

  • For 1d6^0.5 the output should be something like: 1d6^0.5: [6]^0.5 = 2.45
  • For 1d6%2 the output should be something like: 1d6%2: [2]%2 = 0

Actual behaviour

  • For 1d6^0.5 the output is: 1d6^0.5: [6] = 6
  • For 1d6%2 the output should be something like: 1d6%2: [2] = 2

Workaround
If I put parenthesis around the dice roll it works:

  • (1d6)^0.5: ([6])^0.5 = 2.45
  • (1d6)%2: ([2])%2 = 0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.