@yipe/dice 0.2.4 → 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/builder/index.js
CHANGED
|
@@ -2679,22 +2679,42 @@ var RollBuilder = class _RollBuilder {
|
|
|
2679
2679
|
configGroups.set(key, { config, totalCount: config.count });
|
|
2680
2680
|
}
|
|
2681
2681
|
}
|
|
2682
|
-
const
|
|
2682
|
+
const rootConfig = this.getRootDieConfig();
|
|
2683
|
+
const groupedConfigs = Array.from(configGroups.values());
|
|
2684
|
+
let rootD20Group;
|
|
2685
|
+
if (rootConfig && rootConfig.sides === 20) {
|
|
2686
|
+
const rootIndex = groupedConfigs.findIndex(
|
|
2687
|
+
({ config }) => config.sides === rootConfig.sides && config.rollType === rootConfig.rollType && config.reroll === rootConfig.reroll && config.explode === rootConfig.explode && config.minimum === rootConfig.minimum && config.bestOf === rootConfig.bestOf && JSON.stringify(config.keep) === JSON.stringify(rootConfig.keep)
|
|
2688
|
+
);
|
|
2689
|
+
if (rootIndex !== -1) {
|
|
2690
|
+
rootD20Group = groupedConfigs.splice(rootIndex, 1)[0];
|
|
2691
|
+
}
|
|
2692
|
+
}
|
|
2693
|
+
const sortedDiceConfigs = groupedConfigs.map(({ config, totalCount }) => ({
|
|
2683
2694
|
...config,
|
|
2684
2695
|
count: totalCount
|
|
2685
2696
|
})).sort((a, b) => {
|
|
2697
|
+
const aHasPriority = a.reroll > 0 || a.minimum > 0;
|
|
2698
|
+
const bHasPriority = b.reroll > 0 || b.minimum > 0;
|
|
2699
|
+
if (aHasPriority !== bHasPriority) {
|
|
2700
|
+
return aHasPriority ? -1 : 1;
|
|
2701
|
+
}
|
|
2686
2702
|
if (b.sides !== a.sides) return b.sides - a.sides;
|
|
2687
2703
|
const complexity = (c) => (c.reroll > 0 ? 1 : 0) + (c.minimum > 0 ? 1 : 0) + (c.explode > 0 ? 1 : 0) + (c.bestOf > 0 ? 1 : 0) + (c.keep ? 1 : 0);
|
|
2688
2704
|
return complexity(b) - complexity(a);
|
|
2689
2705
|
});
|
|
2706
|
+
const diceConfigs = rootD20Group ? [
|
|
2707
|
+
{ ...rootD20Group.config, count: rootD20Group.totalCount },
|
|
2708
|
+
...sortedDiceConfigs
|
|
2709
|
+
] : sortedDiceConfigs;
|
|
2690
2710
|
const totalModifier = this.subRollConfigs.reduce(
|
|
2691
2711
|
(sum, config) => sum + config.modifier,
|
|
2692
2712
|
0
|
|
2693
2713
|
);
|
|
2694
2714
|
if (diceConfigs.length === 0) return totalModifier.toString();
|
|
2695
|
-
const
|
|
2696
|
-
const newRootConfig =
|
|
2697
|
-
(c) => c.sides ===
|
|
2715
|
+
const rootDieConfig = this.getRootDieConfig();
|
|
2716
|
+
const newRootConfig = rootDieConfig ? diceConfigs.find(
|
|
2717
|
+
(c) => c.sides === rootDieConfig.sides && c.rollType === rootDieConfig.rollType && c.reroll === rootDieConfig.reroll && c.explode === rootDieConfig.explode && c.minimum === rootDieConfig.minimum && c.bestOf === rootDieConfig.bestOf && c.keep === rootDieConfig.keep
|
|
2698
2718
|
) : void 0;
|
|
2699
2719
|
const diceExpressions = diceConfigs.map(
|
|
2700
2720
|
(config) => this.configToSingleExpressionWithoutModifier(
|