roll-parser 3.3.0 → 3.3.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/CHANGELOG.md +12 -1
- package/README.md +6 -5
- package/dist/evaluator/evaluator.d.ts +15 -3
- package/dist/evaluator/evaluator.d.ts.map +1 -1
- package/dist/evaluator/evaluator.js +115 -91
- package/dist/evaluator/evaluator.js.map +1 -1
- package/dist/evaluator/modifiers/flags.d.ts +7 -1
- package/dist/evaluator/modifiers/flags.d.ts.map +1 -1
- package/dist/evaluator/modifiers/flags.js +9 -1
- package/dist/evaluator/modifiers/flags.js.map +1 -1
- package/dist/render.d.ts.map +1 -1
- package/dist/render.js +2 -1
- package/dist/render.js.map +1 -1
- package/dist/rng/seeded.d.ts.map +1 -1
- package/dist/rng/seeded.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +7 -8
- package/src/evaluator/evaluator.ts +155 -131
- package/src/evaluator/modifiers/flags.ts +18 -2
- package/src/render.ts +2 -1
- package/src/rng/seeded.ts +4 -0
- package/src/version.ts +1 -1
|
@@ -68,11 +68,27 @@ export function stripFlags(
|
|
|
68
68
|
return modifiers.filter((modifier) => !excluded.includes(modifier));
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
-
/**
|
|
71
|
+
/**
|
|
72
|
+
* Returns `modifiers` with `excluded` removed and `added` appended, in order.
|
|
73
|
+
*
|
|
74
|
+
* ! Always a fresh array. `mergeMetaRolls` clones a die as
|
|
75
|
+
* ! `{ ...die, modifiers: rewriteFlags(...) }`, so returning the input when it
|
|
76
|
+
* ! already matches would leave clone and original sharing mutated flags.
|
|
77
|
+
*/
|
|
72
78
|
export function rewriteFlags(
|
|
73
79
|
modifiers: readonly DieModifier[],
|
|
74
80
|
excluded: readonly DieModifier[],
|
|
75
81
|
...added: DieModifier[]
|
|
76
82
|
): DieModifier[] {
|
|
77
|
-
|
|
83
|
+
// One array, not `stripFlags`'s filter plus a spread — this runs per die.
|
|
84
|
+
const rewritten: DieModifier[] = [];
|
|
85
|
+
|
|
86
|
+
for (const modifier of modifiers) {
|
|
87
|
+
if (!excluded.includes(modifier)) rewritten.push(modifier);
|
|
88
|
+
}
|
|
89
|
+
for (const flag of added) {
|
|
90
|
+
rewritten.push(flag);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return rewritten;
|
|
78
94
|
}
|
package/src/render.ts
CHANGED
|
@@ -342,8 +342,9 @@ function renderGroup(
|
|
|
342
342
|
plain: boolean,
|
|
343
343
|
): string {
|
|
344
344
|
const { keptIndices } = part;
|
|
345
|
+
const kept = keptIndices == null ? null : new Set(keptIndices);
|
|
345
346
|
const subRolls = part.parts.map((sub, index) => {
|
|
346
|
-
if (
|
|
347
|
+
if (kept == null || kept.has(index)) {
|
|
347
348
|
return renderPart(sub, marks, plain);
|
|
348
349
|
}
|
|
349
350
|
const inner = renderPart(sub, marks, true);
|
package/src/rng/seeded.ts
CHANGED
|
@@ -246,6 +246,10 @@ export class SeededRNG implements RNG {
|
|
|
246
246
|
*/
|
|
247
247
|
private toSeedString(seed?: string | number): string {
|
|
248
248
|
// ! The library's one permitted `Math.random()` site — both draws stay here.
|
|
249
|
+
// ! Decimal double-to-string is a JIT fast path and other radixes are not, so
|
|
250
|
+
// ! every shorter encoding measured slower despite the shorter `hashSeed` loop.
|
|
251
|
+
// ! Only truncating each draw to a uint32 beats it, at 64 draw bits against the
|
|
252
|
+
// ! ~100 documented above. A faster auto-seed must skip the string, not shorten it.
|
|
249
253
|
if (seed == null) return `${Date.now()}-${Math.random()}-${Math.random()}`;
|
|
250
254
|
return String(seed);
|
|
251
255
|
}
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Generated by `bun run generate:version` from package.json — do not edit.
|
|
2
|
-
export const version = '3.3.
|
|
2
|
+
export const version = '3.3.1';
|