@dicelette/core 1.24.2 → 1.25.1
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/index.js +51 -20
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +51 -20
- package/dist/index.mjs.map +1 -1
- package/package.json +59 -59
package/dist/index.js
CHANGED
|
@@ -154,11 +154,11 @@ var NoStatisticsError = class extends Error {
|
|
|
154
154
|
};
|
|
155
155
|
|
|
156
156
|
// src/interfaces/index.ts
|
|
157
|
-
var SortOrder = /* @__PURE__ */ ((
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
return
|
|
157
|
+
var SortOrder = /* @__PURE__ */ ((SortOrder3) => {
|
|
158
|
+
SortOrder3["Ascending"] = "sa";
|
|
159
|
+
SortOrder3["Descending"] = "sd";
|
|
160
|
+
SortOrder3["None"] = "none";
|
|
161
|
+
return SortOrder3;
|
|
162
162
|
})(SortOrder || {});
|
|
163
163
|
|
|
164
164
|
// src/interfaces/constant.ts
|
|
@@ -274,7 +274,9 @@ function generateStatsDice(originalDice, stats, dollarValue) {
|
|
|
274
274
|
while ((tokenMatch = tokenRegex.exec(outsideText)) !== null) {
|
|
275
275
|
result += outsideText.slice(lastIndex, tokenMatch.index);
|
|
276
276
|
const token = tokenMatch[0];
|
|
277
|
-
const
|
|
277
|
+
const tokenHasDollar = token.startsWith("$");
|
|
278
|
+
const tokenForCompare = tokenHasDollar ? token.slice(1) : token;
|
|
279
|
+
const tokenStd = tokenForCompare.standardize();
|
|
278
280
|
const diceMatch = /^(\d*)d(.+)$/i.exec(tokenStd);
|
|
279
281
|
if (diceMatch) {
|
|
280
282
|
const diceCount = diceMatch[1] || "";
|
|
@@ -320,7 +322,7 @@ function generateStatsDice(originalDice, stats, dollarValue) {
|
|
|
320
322
|
}
|
|
321
323
|
dice = result;
|
|
322
324
|
}
|
|
323
|
-
if (dollarValue) dice = dice.replaceAll(
|
|
325
|
+
if (dollarValue) dice = dice.replaceAll("$", dollarValue);
|
|
324
326
|
return replaceFormulaInDice(dice);
|
|
325
327
|
}
|
|
326
328
|
function replaceFormulaInDice(dice) {
|
|
@@ -506,8 +508,28 @@ var import_rpg_dice_roller4 = require("@dice-roller/rpg-dice-roller");
|
|
|
506
508
|
var import_mathjs3 = require("mathjs");
|
|
507
509
|
|
|
508
510
|
// src/dice/replace.ts
|
|
509
|
-
function replaceUnwantedText(dice) {
|
|
510
|
-
|
|
511
|
+
function replaceUnwantedText(dice, sortOrder) {
|
|
512
|
+
const d = dice.replaceAll(/[{}]/g, "").replaceAll(/s[ad]/gi, "");
|
|
513
|
+
if (sortOrder) return sortDice(d, sortOrder);
|
|
514
|
+
return d;
|
|
515
|
+
}
|
|
516
|
+
function sortDice(dice, sortOrder) {
|
|
517
|
+
if (sortOrder === "none" /* None */) return dice;
|
|
518
|
+
const dices = dice.split(/; ?/);
|
|
519
|
+
if (sortOrder === "sa" /* Ascending */) {
|
|
520
|
+
dices.sort((a, b) => {
|
|
521
|
+
const totalA = Number.parseInt(a.split("= ")[1], 10) || 0;
|
|
522
|
+
const totalB = Number.parseInt(b.split("= ")[1], 10) || 0;
|
|
523
|
+
return totalB - totalA;
|
|
524
|
+
});
|
|
525
|
+
} else if (sortOrder === "sd" /* Descending */) {
|
|
526
|
+
dices.sort((a, b) => {
|
|
527
|
+
const totalA = Number.parseInt(a.split("= ")[1], 10) || 0;
|
|
528
|
+
const totalB = Number.parseInt(b.split("= ")[1], 10) || 0;
|
|
529
|
+
return totalA - totalB;
|
|
530
|
+
});
|
|
531
|
+
}
|
|
532
|
+
return dices.join("; ");
|
|
511
533
|
}
|
|
512
534
|
function fixParenthesis(dice) {
|
|
513
535
|
const parenthesisRegex = /d\((\d+)\)/g;
|
|
@@ -773,6 +795,11 @@ function prepareDice(diceInput) {
|
|
|
773
795
|
isSimpleCurly
|
|
774
796
|
};
|
|
775
797
|
}
|
|
798
|
+
function getSortOrder(dice) {
|
|
799
|
+
if (dice.startsWith("sa") || dice.endsWith("sa")) return "sa" /* Ascending */;
|
|
800
|
+
if (dice.startsWith("sd") || dice.endsWith("sd")) return "sd" /* Descending */;
|
|
801
|
+
return void 0;
|
|
802
|
+
}
|
|
776
803
|
|
|
777
804
|
// src/dice/bulk.ts
|
|
778
805
|
function handleBulkRolls(dice, isCurlyBulk, bulkContent, compare, explodingSuccess, diceDisplay, engine, sort) {
|
|
@@ -797,6 +824,7 @@ function handleBulkRolls(dice, isCurlyBulk, bulkContent, compare, explodingSucce
|
|
|
797
824
|
}
|
|
798
825
|
}
|
|
799
826
|
}
|
|
827
|
+
sort = sort ?? getSortOrder(diceToRoll);
|
|
800
828
|
diceToRoll = setSortOrder(diceToRoll, sort);
|
|
801
829
|
const activeCompare = compare || curlyCompare || (explodingSuccess ? { sign: explodingSuccess.sign, value: explodingSuccess.value } : void 0);
|
|
802
830
|
if (activeCompare) {
|
|
@@ -810,7 +838,8 @@ function handleBulkRolls(dice, isCurlyBulk, bulkContent, compare, explodingSucce
|
|
|
810
838
|
isCurlyBulk,
|
|
811
839
|
curlyCompare,
|
|
812
840
|
compare,
|
|
813
|
-
engine
|
|
841
|
+
engine,
|
|
842
|
+
sort
|
|
814
843
|
);
|
|
815
844
|
}
|
|
816
845
|
const roller = new import_rpg_dice_roller6.DiceRoller();
|
|
@@ -826,14 +855,14 @@ function handleBulkRolls(dice, isCurlyBulk, bulkContent, compare, explodingSucce
|
|
|
826
855
|
const modificator = getModifier(dice);
|
|
827
856
|
return {
|
|
828
857
|
dice: finalDice,
|
|
829
|
-
result: replaceUnwantedText(roller.output),
|
|
858
|
+
result: replaceUnwantedText(roller.output, sort),
|
|
830
859
|
comment: comments,
|
|
831
860
|
compare: compare ? compare : void 0,
|
|
832
861
|
modifier: modificator,
|
|
833
862
|
total: roller.total
|
|
834
863
|
};
|
|
835
864
|
}
|
|
836
|
-
function handleBulkRollsWithComparison(numberOfDice, diceToRoll, comments, activeCompare, explodingSuccess, diceDisplay, isCurlyBulk, curlyCompare, compare, engine) {
|
|
865
|
+
function handleBulkRollsWithComparison(numberOfDice, diceToRoll, comments, activeCompare, explodingSuccess, diceDisplay, isCurlyBulk, curlyCompare, compare, engine, sort) {
|
|
837
866
|
const results = [];
|
|
838
867
|
let successCount = 0;
|
|
839
868
|
const roller = new import_rpg_dice_roller6.DiceRoller();
|
|
@@ -917,7 +946,7 @@ function handleBulkRollsWithComparison(numberOfDice, diceToRoll, comments, activ
|
|
|
917
946
|
}
|
|
918
947
|
if (compare && trivialComparisonDetected) compare.trivial = true;
|
|
919
948
|
const finalDice = isCurlyBulk ? `{${diceToRoll}${curlyCompare?.sign}${curlyCompare?.value}}` : diceToRoll;
|
|
920
|
-
const resultOutput = replaceUnwantedText(results.join("; "));
|
|
949
|
+
const resultOutput = replaceUnwantedText(results.join("; "), sort);
|
|
921
950
|
const finalTotal = explodingSuccess ? resultOutput.split(";").flatMap((segment) => extractValuesFromOutput(segment)).filter(
|
|
922
951
|
(val) => matchComparison(explodingSuccess.sign, val, explodingSuccess.value)
|
|
923
952
|
).length : successCount;
|
|
@@ -975,7 +1004,8 @@ function roll(dice, engine = import_rpg_dice_roller7.NumberGenerator.engines.nod
|
|
|
975
1004
|
pity,
|
|
976
1005
|
prepared.explodingSuccess,
|
|
977
1006
|
prepared.diceDisplay,
|
|
978
|
-
prepared.isSharedCurly
|
|
1007
|
+
prepared.isSharedCurly,
|
|
1008
|
+
sort
|
|
979
1009
|
);
|
|
980
1010
|
}
|
|
981
1011
|
let processedDice = fixParenthesis(prepared.dice);
|
|
@@ -1049,7 +1079,7 @@ function roll(dice, engine = import_rpg_dice_roller7.NumberGenerator.engines.nod
|
|
|
1049
1079
|
};
|
|
1050
1080
|
}
|
|
1051
1081
|
}
|
|
1052
|
-
let resultOutput = replaceUnwantedText(roller.output);
|
|
1082
|
+
let resultOutput = replaceUnwantedText(roller.output, sort);
|
|
1053
1083
|
if (prepared.explodingSuccess) {
|
|
1054
1084
|
const successes = countExplodingSuccesses(
|
|
1055
1085
|
diceRoll,
|
|
@@ -1082,7 +1112,7 @@ function roll(dice, engine = import_rpg_dice_roller7.NumberGenerator.engines.nod
|
|
|
1082
1112
|
trivial: compare?.trivial ? true : void 0
|
|
1083
1113
|
};
|
|
1084
1114
|
}
|
|
1085
|
-
function sharedRolls(dice, engine = import_rpg_dice_roller7.NumberGenerator.engines.nodeCrypto, pity, explodingSuccessMain, diceDisplay, isSharedCurly) {
|
|
1115
|
+
function sharedRolls(dice, engine = import_rpg_dice_roller7.NumberGenerator.engines.nodeCrypto, pity, explodingSuccessMain, diceDisplay, isSharedCurly, sort) {
|
|
1086
1116
|
if (!explodingSuccessMain)
|
|
1087
1117
|
explodingSuccessMain = normalizeExplodingSuccess(dice.split(";")[0] ?? dice);
|
|
1088
1118
|
if (explodingSuccessMain) {
|
|
@@ -1114,11 +1144,12 @@ function sharedRolls(dice, engine = import_rpg_dice_roller7.NumberGenerator.engi
|
|
|
1114
1144
|
} else {
|
|
1115
1145
|
diceMain = diceMainWithoutComments;
|
|
1116
1146
|
}
|
|
1147
|
+
const sortFromMain = getSortOrder(diceMain);
|
|
1117
1148
|
const rollBounds = getRollBounds(diceMain, engine);
|
|
1118
|
-
let diceResult = roll(diceMain, engine, pity);
|
|
1149
|
+
let diceResult = roll(diceMain, engine, pity, sort);
|
|
1119
1150
|
if (!diceResult || !diceResult.total) {
|
|
1120
1151
|
if (hidden) {
|
|
1121
|
-
diceResult = roll(fixParenthesis(split[0]), engine, pity);
|
|
1152
|
+
diceResult = roll(fixParenthesis(split[0]), engine, pity, sort);
|
|
1122
1153
|
hidden = false;
|
|
1123
1154
|
} else return void 0;
|
|
1124
1155
|
}
|
|
@@ -1137,7 +1168,7 @@ function sharedRolls(dice, engine = import_rpg_dice_roller7.NumberGenerator.engi
|
|
|
1137
1168
|
if (!total) {
|
|
1138
1169
|
return {
|
|
1139
1170
|
dice: displayDice,
|
|
1140
|
-
result: results.join(";"),
|
|
1171
|
+
result: replaceUnwantedText(results.join(";"), sortFromMain),
|
|
1141
1172
|
comment: mainComment,
|
|
1142
1173
|
compare: aggregatedCompare,
|
|
1143
1174
|
modifier: diceResult.modifier,
|
|
@@ -1219,7 +1250,7 @@ function sharedRolls(dice, engine = import_rpg_dice_roller7.NumberGenerator.engi
|
|
|
1219
1250
|
results.shift();
|
|
1220
1251
|
return {
|
|
1221
1252
|
dice: displayDice,
|
|
1222
|
-
result: results.join(";"),
|
|
1253
|
+
result: replaceUnwantedText(results.join(";"), sortFromMain),
|
|
1223
1254
|
comment: mainComment,
|
|
1224
1255
|
compare: hasTrivialComparison && aggregatedCompare ? { ...aggregatedCompare, trivial: true } : aggregatedCompare,
|
|
1225
1256
|
modifier: diceResult.modifier,
|