3d-dice / dice-box

3D Game Dice for any JavaScript App
https://fantasticdice.games/
MIT License
137 stars 30 forks source link

1.0.7 has a bug with the Dice Roller #69

Closed clevett closed 1 year ago

clevett commented 1 year ago

When trying to use Parser Interface + Dice Roller to do advanced parsing there is an error thrown when using.

const finalResults = DRP.parseFinalResults(results);

The function below works fine in Dicebox 1.0.5 but breaks in 1.0.7

This is the function that I have in a React hook

  if (dicebox) {
    // This method is triggered whenever dice are finished rolling
    dicebox.onRollComplete = (results: unknown) => {
      // handle any rerolls
      const rerolls = DRP.handleRerolls(results);
      if (rerolls.length) {
        rerolls.forEach((roll: { groupId: unknown }) =>
          dicebox.add(roll, roll.groupId)
        );
        return rerolls;
      }
      // if no rerolls needed then parse the final results
      const finalResults = DRP.parseFinalResults(results);
      setResult(finalResults);
    };

Screenshot 2023-02-06 at 16 01 49

frankieali commented 1 year ago

So, my best guess on this one is that this is related to the flexible-dice-names work I did. In this case, I removed the hardcoded dice id's that followed the pattern of 'd' + int. This was done to allow for dice to be identified by their unique ids defined in the theme. Specifically, this was implemented for fate dice and rolls of 3df. To that end, the advancedRoller had some updates to accommodate this new output from dice-box. Take a look at this commit on dice-ui. The note in the code states // convert string names back to intigers needed by DRP (yup, I spelled integers wrong).

Long story short, I think you need to update dice-ui as well.

frankieali commented 1 year ago

On sec ... perhaps I need to update the dice-ui npm package. It seems I committed the changes but did not publish an update.

frankieali commented 1 year ago

Updated Dice UI to version 0.4.3. This should work with dice-box 1.0.8.

clevett commented 1 year ago

I'm not using Dice UI at all since I am writing my own UI for this.

"dependencies": { "@3d-dice/dice-box": "1.0.8", "@3d-dice/dice-parser-interface": "0.2.0" }

which also installed the require dependency "@3d-dice/dice-roller-parser": "^0.2.6"

frankieali commented 1 year ago

Ok, fair enough. The problem is still the same though. Dice-box is outputting the final result with result.sides as a string now. This needs to be converted back into an int before it gets to dice-roller-parser. This type check probably needs to be done in dice-parser-interface instead of dice-ui. I'll make an update.

frankieali commented 1 year ago

Ok, I pushed an update to @3d-dice/dice-parser-interface and bumped the version to 0.2.1. Give it a try.

clevett commented 1 year ago

Thanks so much Frank! I'll try add the update today.