Skip to content

Commit d7933fe

Browse files
committed
split results.dart into multiple files
1 parent 2f96d96 commit d7933fe

File tree

12 files changed

+737
-708
lines changed

12 files changed

+737
-708
lines changed

lib/dart_dice_parser.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,8 @@ library;
1515

1616
export 'src/dice_expression.dart';
1717
export 'src/dice_roller.dart';
18-
export 'src/results.dart';
18+
export 'src/enums.dart';
19+
export 'src/extensions.dart';
20+
export 'src/roll_result.dart';
21+
export 'src/roll_summary.dart';
22+
export 'src/rolled_die.dart';

lib/src/ast_core.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import 'dice_expression.dart';
22
import 'dice_roller.dart';
3-
import 'results.dart';
3+
import 'enums.dart';
4+
import 'roll_result.dart';
5+
import 'rolled_die.dart';
46
import 'utils.dart';
57

68
/// All our operations will inherit from this class.

lib/src/ast_dice.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import 'package:petitparser/parser.dart';
33

44
import 'ast_core.dart';
55
import 'dice_roller.dart';
6-
import 'results.dart';
6+
import 'enums.dart';
7+
import 'roll_result.dart';
78

89
/// roll fudge dice
910
class FudgeDice extends UnaryDice {

lib/src/ast_ops.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import 'package:collection/collection.dart';
22

33
import 'ast_core.dart';
4-
import 'results.dart';
4+
import 'enums.dart';
5+
import 'roll_result.dart';
6+
import 'rolled_die.dart';
57

68
/// default limit for rerolls/exploding/compounding to avoid getting stuck in loop
79
const defaultRerollLimit = 1000;

lib/src/dice_expression.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ import 'package:logging/logging.dart';
44
import 'package:petitparser/petitparser.dart';
55

66
import 'dice_roller.dart';
7+
import 'enums.dart';
78
import 'parser.dart';
8-
import 'results.dart';
9+
import 'roll_result.dart';
10+
import 'roll_summary.dart';
911
import 'stats.dart';
1012

1113
/// An abstract expression that can be evaluated.

lib/src/dice_roller.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ import 'dart:math';
22

33
import 'package:fast_immutable_collections/fast_immutable_collections.dart';
44

5-
import 'results.dart';
5+
import 'enums.dart';
6+
import 'roll_result.dart';
7+
import 'rolled_die.dart';
68
import 'utils.dart';
79

810
/// A dice roller for M dice of N sides (e.g. `2d6`).

lib/src/enums.dart

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/// types of die.
2+
enum DieType implements Comparable<DieType> {
3+
// normal polyhedral (1d6, 1d20, etc)
4+
polyhedral(),
5+
// fudge dice
6+
fudge(hasPotentialValues: true),
7+
// 1D66 (equivalent to `1d6*10 + 1d6`).
8+
d66(hasNSides: false),
9+
// 1d[1,3,5,7,9]
10+
special(hasPotentialValues: true),
11+
// single value (e.g. a sum or count of dice)
12+
singleVal(explodable: false, compoundable: false, hasPotentialValues: true);
13+
14+
const DieType({
15+
this.explodable = true,
16+
this.compoundable = true,
17+
this.hasPotentialValues = false,
18+
this.hasNSides = true,
19+
});
20+
21+
/// can the die be exploded?
22+
final bool explodable;
23+
24+
/// can the die be compounded?
25+
final bool compoundable;
26+
27+
/// whether the RolledDie must have non-empty potentialValues
28+
final bool hasPotentialValues;
29+
30+
/// whether the RolledDie must have non-zero nsides
31+
final bool hasNSides;
32+
33+
@override
34+
int compareTo(DieType dieType) => index.compareTo(dieType.index);
35+
}
36+
37+
enum OpType {
38+
value, // leaf nodes which are simple integer values
39+
add,
40+
subtract,
41+
multiply,
42+
count,
43+
drop,
44+
clamp,
45+
rollDice,
46+
rollFudge,
47+
rollPercent,
48+
rollD66,
49+
rollVals,
50+
reroll,
51+
compound,
52+
explode,
53+
}
54+
55+
enum CountType { count, success, failure, critSuccess, critFailure }

lib/src/extensions.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import 'package:fast_immutable_collections/fast_immutable_collections.dart';
2+
3+
import 'rolled_die.dart';
4+
5+
extension RolledDieIListExtensions on IList<RolledDie> {
6+
int get sum => map((d) => d.result).fold(0, (sum, i) => sum + i);
7+
8+
int get successCount => where((d) => d.success).length;
9+
10+
int get failureCount => where((d) => d.failure).length;
11+
12+
int get critSuccessCount => where((d) => d.critSuccess).length;
13+
14+
int get critFailureCount => where((d) => d.critFailure).length;
15+
}

0 commit comments

Comments
 (0)