rollWithStatistics method
Compute and return a RollStatistics with all information from a roll, including the result from each individual dice roll within.
See RollStatistics and RollResult for more info.
Implementation
RollStatistics rollWithStatistics(String roll) {
final sanitizedRoll = _sanitizeStringNotation(roll);
final Iterable<Match> matches = _singleDiceRegExp.allMatches(sanitizedRoll);
var newRoll = sanitizedRoll;
final results = <RollResult>[];
for (var i = matches.length - 1; i >= 0; i--) {
final result = _rollSingleDie(matches.elementAt(i));
results.add(result);
newRoll = newRoll.replaceRange(
matches.elementAt(i).start,
matches.elementAt(i).end,
result.finalResult.toString(),
);
}
final exactResult = _parser
.parse(newRoll)
// ignore: avoid_as
.evaluate(EvaluationType.REAL, _context) as double;
return RollStatistics(
rollNotation: sanitizedRoll,
results: results,
finalResult: exactResult.round(),
);
}