Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Importing Group Rolls throws an error #289

Open
Ainias opened this issue Nov 22, 2023 · 1 comment
Open

[Bug]: Importing Group Rolls throws an error #289

Ainias opened this issue Nov 22, 2023 · 1 comment
Assignees
Labels

Comments

@Ainias
Copy link

Ainias commented Nov 22, 2023

Description

When importing an exported Roll with GroupRolls throws an error TypeError: value must be one of ResultGroup, RollResults, string, or number

Reproduceable with the following code:

DiceRoll.import(new DiceRoll("{1d20}").export());

Dice Roller version

5.4.1

Bundle type

ESM

Node version

v18.18.2

Browser name and version

Brave v1.60.114

@GreenImp
Copy link
Collaborator

GreenImp commented Nov 28, 2023

Thanks for raising, I'm able to replicate.

For reference, this is because, when exported, the results is an array of objects like:

{
  "averageTotal": 10.5,
  "maxTotal": 20,
  "minTotal": 1,
  "notation": "{1d20}",
  "output": "{1d20}: {[5]} = 5",
  "rolls": [
    {
      "calculationValue": 5,
      "isRollGroup": true,
      "modifierFlags": "",
      "modifiers": [],
      "results": [
        {
          "calculationValue": 5,
          "isRollGroup": false,
          "modifierFlags": "",
          "modifiers": [],
          "results": [
            {
              "rolls": [
                {
                  "calculationValue": 5,
                  "initialValue": 5,
                  "modifierFlags": "",
                  "modifiers": [],
                  "type": "result",
                  "useInTotal": true,
                  "value": 5
                }
              ],
              "type": "roll-results",
              "value": 5
            }
          ],
          "type": "result-group",
          "useInTotal": true,
          "value": 5
        }
      ],
      "type": "result-group",
      "useInTotal": true,
      "value": 5
    }
  ],
  "total": 5,
  "type": "dice-roll"
}

But by the time this is passed down to the ResultGroup.addResult() method, it expects the data to already be cast to a ResultGroup or RollResults object.

This will need to be changed to handle standard objects in this format as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants