@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.cjs
CHANGED
|
@@ -2681,22 +2681,42 @@ var RollBuilder = class _RollBuilder {
|
|
|
2681
2681
|
configGroups.set(key, { config, totalCount: config.count });
|
|
2682
2682
|
}
|
|
2683
2683
|
}
|
|
2684
|
-
const
|
|
2684
|
+
const rootConfig = this.getRootDieConfig();
|
|
2685
|
+
const groupedConfigs = Array.from(configGroups.values());
|
|
2686
|
+
let rootD20Group;
|
|
2687
|
+
if (rootConfig && rootConfig.sides === 20) {
|
|
2688
|
+
const rootIndex = groupedConfigs.findIndex(
|
|
2689
|
+
({ 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)
|
|
2690
|
+
);
|
|
2691
|
+
if (rootIndex !== -1) {
|
|
2692
|
+
rootD20Group = groupedConfigs.splice(rootIndex, 1)[0];
|
|
2693
|
+
}
|
|
2694
|
+
}
|
|
2695
|
+
const sortedDiceConfigs = groupedConfigs.map(({ config, totalCount }) => ({
|
|
2685
2696
|
...config,
|
|
2686
2697
|
count: totalCount
|
|
2687
2698
|
})).sort((a, b) => {
|
|
2699
|
+
const aHasPriority = a.reroll > 0 || a.minimum > 0;
|
|
2700
|
+
const bHasPriority = b.reroll > 0 || b.minimum > 0;
|
|
2701
|
+
if (aHasPriority !== bHasPriority) {
|
|
2702
|
+
return aHasPriority ? -1 : 1;
|
|
2703
|
+
}
|
|
2688
2704
|
if (b.sides !== a.sides) return b.sides - a.sides;
|
|
2689
2705
|
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);
|
|
2690
2706
|
return complexity(b) - complexity(a);
|
|
2691
2707
|
});
|
|
2708
|
+
const diceConfigs = rootD20Group ? [
|
|
2709
|
+
{ ...rootD20Group.config, count: rootD20Group.totalCount },
|
|
2710
|
+
...sortedDiceConfigs
|
|
2711
|
+
] : sortedDiceConfigs;
|
|
2692
2712
|
const totalModifier = this.subRollConfigs.reduce(
|
|
2693
2713
|
(sum, config) => sum + config.modifier,
|
|
2694
2714
|
0
|
|
2695
2715
|
);
|
|
2696
2716
|
if (diceConfigs.length === 0) return totalModifier.toString();
|
|
2697
|
-
const
|
|
2698
|
-
const newRootConfig =
|
|
2699
|
-
(c) => c.sides ===
|
|
2717
|
+
const rootDieConfig = this.getRootDieConfig();
|
|
2718
|
+
const newRootConfig = rootDieConfig ? diceConfigs.find(
|
|
2719
|
+
(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
|
|
2700
2720
|
) : void 0;
|
|
2701
2721
|
const diceExpressions = diceConfigs.map(
|
|
2702
2722
|
(config) => this.configToSingleExpressionWithoutModifier(
|