@dicelette/core 1.28.2 → 1.28.3
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.d.mts +15 -2
- package/dist/index.d.ts +15 -2
- package/dist/index.js +21 -16
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +20 -16
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -212,10 +212,6 @@ import { evaluate as evaluate10 } from "mathjs";
|
|
|
212
212
|
import { DiceRoller as DiceRoller2, NumberGenerator as NumberGenerator7 } from "@dice-roller/rpg-dice-roller";
|
|
213
213
|
import { evaluate as evaluate8 } from "mathjs";
|
|
214
214
|
|
|
215
|
-
// src/dice/compare.ts
|
|
216
|
-
import { NumberGenerator as NumberGenerator4 } from "@dice-roller/rpg-dice-roller";
|
|
217
|
-
import { evaluate as evaluate2 } from "mathjs";
|
|
218
|
-
|
|
219
215
|
// src/utils.ts
|
|
220
216
|
import "uniformize";
|
|
221
217
|
import { NumberGenerator as NumberGenerator3 } from "@dice-roller/rpg-dice-roller";
|
|
@@ -434,6 +430,12 @@ function generateRandomStat(total = 100, max, min, engine = NumberGenerator2.eng
|
|
|
434
430
|
}
|
|
435
431
|
|
|
436
432
|
// src/utils.ts
|
|
433
|
+
function splitDiceComment(dice) {
|
|
434
|
+
const match = /\s+(#|\/{2}|\[|\/\*)(?<comment>.*)/i.exec(dice);
|
|
435
|
+
if (!match?.groups) return { dice: dice.trimEnd(), comment: void 0 };
|
|
436
|
+
const comment = match.groups.comment.trim() || void 0;
|
|
437
|
+
return { dice: dice.slice(0, match.index).trimEnd(), comment };
|
|
438
|
+
}
|
|
437
439
|
function escapeRegex(string) {
|
|
438
440
|
return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
439
441
|
}
|
|
@@ -470,6 +472,8 @@ function createCriticalCustom(dice, customCritical, template, engine = NumberGen
|
|
|
470
472
|
}
|
|
471
473
|
|
|
472
474
|
// src/dice/compare.ts
|
|
475
|
+
import { NumberGenerator as NumberGenerator4 } from "@dice-roller/rpg-dice-roller";
|
|
476
|
+
import { evaluate as evaluate2 } from "mathjs";
|
|
473
477
|
function isTrivialComparison(maxValue, minValue, compare) {
|
|
474
478
|
const canSucceed = canComparisonSucceed(maxValue, compare, minValue);
|
|
475
479
|
const canFail = canComparisonFail(maxValue, compare, minValue);
|
|
@@ -1060,7 +1064,7 @@ function setSortOrder(toRoll, sort) {
|
|
|
1060
1064
|
}
|
|
1061
1065
|
function prepareDice(diceInput) {
|
|
1062
1066
|
let dice = standardizeDice(replaceFormulaInDice(diceInput)).replace(/^\+/, "").replaceAll("=>", ">=").replaceAll("=<", "<=").trimStart();
|
|
1063
|
-
dice = dice.replaceAll(
|
|
1067
|
+
dice = dice.replaceAll(REMOVER_PATTERN.CRITICAL_BLOCK, "").trimEnd();
|
|
1064
1068
|
const explodingSuccess = normalizeExplodingSuccess(dice);
|
|
1065
1069
|
if (explodingSuccess) dice = explodingSuccess.dice;
|
|
1066
1070
|
let diceDisplay;
|
|
@@ -1112,9 +1116,8 @@ function handleBulkRolls(dice, isCurlyBulk, bulkContent, compare, explodingSucce
|
|
|
1112
1116
|
const bulkProcessContent = isCurlyBulk ? bulkContent : dice;
|
|
1113
1117
|
const diceArray = bulkProcessContent.split("#");
|
|
1114
1118
|
const numberOfDice = Number.parseInt(diceArray[0], 10);
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
const comments = commentsMatch ? commentsMatch[2] : void 0;
|
|
1119
|
+
const { dice: diceToRollBase, comment: comments } = splitDiceComment(diceArray[1]);
|
|
1120
|
+
let diceToRoll = diceToRollBase;
|
|
1118
1121
|
let curlyCompare;
|
|
1119
1122
|
if (isCurlyBulk) {
|
|
1120
1123
|
const curlyCompareRegex = diceToRoll.match(SIGN_REGEX_SPACE);
|
|
@@ -1299,7 +1302,7 @@ function handlePitySystem(dice, compare, diceRoll, roller, engine) {
|
|
|
1299
1302
|
}
|
|
1300
1303
|
|
|
1301
1304
|
// src/roll.ts
|
|
1302
|
-
function roll(dice, engine = NumberGenerator8.engines.nodeCrypto, pity, sort) {
|
|
1305
|
+
function roll(dice, engine = NumberGenerator8.engines.nodeCrypto, pity, sort, comment) {
|
|
1303
1306
|
if (sort === "none" /* None */) sort = void 0;
|
|
1304
1307
|
const prepared = prepareDice(dice);
|
|
1305
1308
|
if (!prepared.dice.includes("d")) return void 0;
|
|
@@ -1342,8 +1345,10 @@ function roll(dice, engine = NumberGenerator8.engines.nodeCrypto, pity, sort) {
|
|
|
1342
1345
|
}
|
|
1343
1346
|
const roller = new DiceRoller3();
|
|
1344
1347
|
NumberGenerator8.generator.engine = engine;
|
|
1345
|
-
|
|
1346
|
-
|
|
1348
|
+
const splitResult = splitDiceComment(processedDice);
|
|
1349
|
+
const diceBase = comment !== void 0 ? processedDice.trimEnd() : splitResult.dice;
|
|
1350
|
+
const resolvedComment = comment ?? splitResult.comment;
|
|
1351
|
+
const diceWithoutComment = setSortOrder(diceBase, sort);
|
|
1347
1352
|
let diceRoll;
|
|
1348
1353
|
try {
|
|
1349
1354
|
diceRoll = roller.roll(diceWithoutComment);
|
|
@@ -1359,8 +1364,6 @@ function roll(dice, engine = NumberGenerator8.engines.nodeCrypto, pity, sort) {
|
|
|
1359
1364
|
);
|
|
1360
1365
|
compare.trivial = trivial ? true : void 0;
|
|
1361
1366
|
}
|
|
1362
|
-
const commentMatch = processedDice.match(COMMENT_REGEX);
|
|
1363
|
-
const comment = commentMatch ? commentMatch[2] : void 0;
|
|
1364
1367
|
let rerollCount = 0;
|
|
1365
1368
|
let pityResult;
|
|
1366
1369
|
if (pity && compare) {
|
|
@@ -1377,7 +1380,7 @@ function roll(dice, engine = NumberGenerator8.engines.nodeCrypto, pity, sort) {
|
|
|
1377
1380
|
return {
|
|
1378
1381
|
...pityResult,
|
|
1379
1382
|
dice: prepared.isSimpleCurly ? finalDiceDisplay : processedDice,
|
|
1380
|
-
comment,
|
|
1383
|
+
comment: resolvedComment,
|
|
1381
1384
|
compare,
|
|
1382
1385
|
modifier: modificator,
|
|
1383
1386
|
pityLogs: rerollCount,
|
|
@@ -1399,7 +1402,7 @@ function roll(dice, engine = NumberGenerator8.engines.nodeCrypto, pity, sort) {
|
|
|
1399
1402
|
return {
|
|
1400
1403
|
dice: prepared.isSimpleCurly ? finalDiceDisplay : prepared.diceDisplay,
|
|
1401
1404
|
result: resultOutput,
|
|
1402
|
-
comment,
|
|
1405
|
+
comment: resolvedComment,
|
|
1403
1406
|
compare: compare ? compare : void 0,
|
|
1404
1407
|
modifier: modificator,
|
|
1405
1408
|
total: successes,
|
|
@@ -1410,7 +1413,7 @@ function roll(dice, engine = NumberGenerator8.engines.nodeCrypto, pity, sort) {
|
|
|
1410
1413
|
return {
|
|
1411
1414
|
dice: prepared.isSimpleCurly ? finalDiceDisplay : processedDice,
|
|
1412
1415
|
result: resultOutput,
|
|
1413
|
-
comment,
|
|
1416
|
+
comment: resolvedComment,
|
|
1414
1417
|
compare: compare ? compare : void 0,
|
|
1415
1418
|
modifier: modificator,
|
|
1416
1419
|
total: roller.total,
|
|
@@ -1626,6 +1629,7 @@ export {
|
|
|
1626
1629
|
replaceUnknown,
|
|
1627
1630
|
resolveFormulaHint,
|
|
1628
1631
|
roll,
|
|
1632
|
+
splitDiceComment,
|
|
1629
1633
|
standardizeDice,
|
|
1630
1634
|
templateSchema,
|
|
1631
1635
|
testDiceRegistered,
|