@yipe/dice 0.2.6 → 0.2.8
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 +23 -20
- package/dist/builder/index.cjs.map +1 -1
- package/dist/builder/index.js +23 -20
- package/dist/builder/index.js.map +1 -1
- package/package.json +1 -1
package/dist/builder/index.cjs
CHANGED
|
@@ -2429,6 +2429,12 @@ var defaultConfig = {
|
|
|
2429
2429
|
keep: void 0,
|
|
2430
2430
|
rollType: "flat"
|
|
2431
2431
|
};
|
|
2432
|
+
var rollConfigsEqual = (a, b) => {
|
|
2433
|
+
return a.count === b.count && a.sides === b.sides && a.modifier === b.modifier && a.reroll === b.reroll && a.explode === b.explode && a.minimum === b.minimum && a.bestOf === b.bestOf && a.keep === b.keep && a.rollType === b.rollType;
|
|
2434
|
+
};
|
|
2435
|
+
var configComplexityScore = (config) => {
|
|
2436
|
+
return (config.reroll > 0 ? 1 : 0) + (config.explode > 0 ? 1 : 0) + (config.minimum > 0 ? 1 : 0) + (config.bestOf > 0 ? 1 : 0) + (config.keep !== void 0 ? 1 : 0) + (config.rollType !== "flat" ? 1 : 0);
|
|
2437
|
+
};
|
|
2432
2438
|
var RollBuilder = class _RollBuilder {
|
|
2433
2439
|
constructor(countOrConfigs = 1) {
|
|
2434
2440
|
__publicField(this, "subRollConfigs");
|
|
@@ -2698,12 +2704,9 @@ var RollBuilder = class _RollBuilder {
|
|
|
2698
2704
|
})).sort((a, b) => {
|
|
2699
2705
|
const aHasPriority = a.reroll > 0 || a.minimum > 0;
|
|
2700
2706
|
const bHasPriority = b.reroll > 0 || b.minimum > 0;
|
|
2701
|
-
if (aHasPriority !== bHasPriority)
|
|
2702
|
-
return aHasPriority ? -1 : 1;
|
|
2703
|
-
}
|
|
2707
|
+
if (aHasPriority !== bHasPriority) return aHasPriority ? -1 : 1;
|
|
2704
2708
|
if (b.sides !== a.sides) return b.sides - a.sides;
|
|
2705
|
-
|
|
2706
|
-
return complexity(b) - complexity(a);
|
|
2709
|
+
return configComplexityScore(b) - configComplexityScore(a);
|
|
2707
2710
|
});
|
|
2708
2711
|
const diceConfigs = rootD20Group ? [
|
|
2709
2712
|
{ ...rootD20Group.config, count: rootD20Group.totalCount },
|
|
@@ -2715,9 +2718,7 @@ var RollBuilder = class _RollBuilder {
|
|
|
2715
2718
|
);
|
|
2716
2719
|
if (diceConfigs.length === 0) return totalModifier.toString();
|
|
2717
2720
|
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
|
|
2720
|
-
) : void 0;
|
|
2721
|
+
const newRootConfig = rootDieConfig ? diceConfigs.find((c) => rollConfigsEqual(c, rootDieConfig)) : void 0;
|
|
2721
2722
|
const diceExpressions = diceConfigs.map(
|
|
2722
2723
|
(config) => this.configToSingleExpressionWithoutModifier(
|
|
2723
2724
|
config,
|
|
@@ -2763,7 +2764,11 @@ var RollBuilder = class _RollBuilder {
|
|
|
2763
2764
|
}
|
|
2764
2765
|
}
|
|
2765
2766
|
if (config.minimum > 0) {
|
|
2766
|
-
|
|
2767
|
+
if (config.reroll > 0 && !config.explode) {
|
|
2768
|
+
baseDie = `${config.minimum}>(${baseDie})`;
|
|
2769
|
+
} else {
|
|
2770
|
+
baseDie = `${config.minimum}>${baseDie}`;
|
|
2771
|
+
}
|
|
2767
2772
|
if (config.reroll > 0 && config.explode > 0) {
|
|
2768
2773
|
for (let i = 1; i <= config.reroll; i++) {
|
|
2769
2774
|
baseDie += ` reroll ${i}`;
|
|
@@ -2788,11 +2793,10 @@ var RollBuilder = class _RollBuilder {
|
|
|
2788
2793
|
const baseDieExpression = this.configToSingleExpressionWithoutModifier(
|
|
2789
2794
|
{
|
|
2790
2795
|
...config,
|
|
2791
|
-
count:
|
|
2796
|
+
count: config.count,
|
|
2792
2797
|
modifier: 0,
|
|
2793
2798
|
rollType: "flat",
|
|
2794
|
-
keep: void 0
|
|
2795
|
-
bestOf: 0
|
|
2799
|
+
keep: void 0
|
|
2796
2800
|
},
|
|
2797
2801
|
false
|
|
2798
2802
|
);
|
|
@@ -2801,21 +2805,20 @@ var RollBuilder = class _RollBuilder {
|
|
|
2801
2805
|
const isComplex = baseDie.length > `d${config.sides}`.length;
|
|
2802
2806
|
const isHalflingShorthand = baseDie === "hd20";
|
|
2803
2807
|
const isD20Shorthand = baseDie === "d20" && isRootDie;
|
|
2804
|
-
const hasMinimum =
|
|
2805
|
-
const hasReroll =
|
|
2808
|
+
const hasMinimum = config.minimum > 0;
|
|
2809
|
+
const hasReroll = config.reroll > 0;
|
|
2806
2810
|
const effectiveCount = config.isSubtraction ? Math.abs(config.count) : config.count < 0 ? 1 : Math.abs(config.count);
|
|
2807
2811
|
if (effectiveCount > 1) {
|
|
2808
|
-
const shouldAddParentheses = isComplex
|
|
2809
|
-
!hasMinimum && !hasReroll || // Simple complex case
|
|
2810
|
-
hasReroll && !hasMinimum);
|
|
2812
|
+
const shouldAddParentheses = isComplex;
|
|
2811
2813
|
mainExpression = shouldAddParentheses ? `${effectiveCount}(${baseDie})` : `${effectiveCount}${baseDie}`;
|
|
2812
2814
|
} else if (effectiveCount === 1) {
|
|
2815
|
+
const needsParens = hasReroll && hasMinimum;
|
|
2813
2816
|
if (config.isSubtraction) {
|
|
2814
|
-
mainExpression = `1${baseDie}`;
|
|
2817
|
+
mainExpression = needsParens ? `1(${baseDie})` : `1${baseDie}`;
|
|
2815
2818
|
} else if (isComplex || isHalflingShorthand || isD20Shorthand || config.count < 0) {
|
|
2816
|
-
mainExpression = baseDie;
|
|
2819
|
+
mainExpression = needsParens ? `1(${baseDie})` : baseDie;
|
|
2817
2820
|
} else {
|
|
2818
|
-
mainExpression = `1${baseDie}`;
|
|
2821
|
+
mainExpression = needsParens ? `1(${baseDie})` : `1${baseDie}`;
|
|
2819
2822
|
}
|
|
2820
2823
|
} else {
|
|
2821
2824
|
mainExpression = baseDie;
|