Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/results/ResultGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ class ResultGroup {
/**
* Add a single result to the list.
*
* @param {ResultGroup|RollResults|number|string} value
* @param {ResultGroup|RollResults|Object|number|string} value
*
* @throws {TypeError} Value type is invalid
*/
Expand All @@ -258,6 +258,19 @@ class ResultGroup {
} else if ((typeof value === 'string') || isNumeric(value)) {
// string operator (e.g. '+', '/', etc.), or plain number
val = value;
} else if (typeof value === 'object') {
// plain object from importing, so do basic validation and instantiate the rich classes
if (value.type === 'result-group') {
val = new ResultGroup(value.results, value.modifiers, value.isRollGroup, value.useInTotal);
} else if (value.type === 'roll-results') {
if (value.rolls && Array.isArray(value.rolls)) {
val = new RollResults(value.rolls);
} else {
throw new TypeError('objects with type "roll-results" must have a rolls array');
}
} else {
throw new TypeError(`value.type must be 'result-group' or 'roll-results' but is '${value.type}'`);
}
} else {
throw new TypeError('value must be one of ResultGroup, RollResults, string, or number');
}
Expand Down
2 changes: 1 addition & 1 deletion tests/DiceRoll.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,7 @@ describe('DiceRoll', () => {
let diceRoll;

beforeEach(() => {
diceRoll = new DiceRoll('4d6/7+2d10dl1');
diceRoll = new DiceRoll('{4d6/7+2d10dl1}');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind reverting this, and creating a separate test for the roll group syntax?
Got to make sure that the other syntax still works, and that the group roll syntax works / throws the correct errors 😄

});

test('requires data', () => {
Expand Down