@flare-engine/progression 0.4.6 → 0.4.7
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 +8 -18
- package/dist/index.d.mts.map +1 -1
- package/dist/index.d.ts +8 -18
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -10
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +5 -10
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
//#region src/collectible-registry.d.ts
|
|
2
1
|
/**
|
|
3
2
|
* Collectible-unlock registry: immutable unlock-set + partition + capstone.
|
|
4
3
|
*
|
|
@@ -52,9 +51,7 @@ interface CollectibleRegistry<K extends string> {
|
|
|
52
51
|
* unlock auto-fires on full completion regardless of whether the capstone id
|
|
53
52
|
* was directly unlocked via the `ids` set, which would be semantically ambiguous.
|
|
54
53
|
*/
|
|
55
|
-
declare function createCollectibleRegistry<K extends string>(ids: readonly K[], capstoneId?: K): CollectibleRegistry<K>;
|
|
56
|
-
//#endregion
|
|
57
|
-
//#region src/drop-roll.d.ts
|
|
54
|
+
export declare function createCollectibleRegistry<K extends string>(ids: readonly K[], capstoneId?: K): CollectibleRegistry<K>;
|
|
58
55
|
/**
|
|
59
56
|
* Pity-aware weighted drop roller.
|
|
60
57
|
*
|
|
@@ -103,14 +100,12 @@ interface DropTable<K extends string> {
|
|
|
103
100
|
* The `weightAt` accessor and scratch buffer are allocated once inside this
|
|
104
101
|
* factory (not per-roll).
|
|
105
102
|
*/
|
|
106
|
-
declare function createDropTable<K extends string>(entries: readonly DropEntry<K>[]): DropTable<K>;
|
|
103
|
+
export declare function createDropTable<K extends string>(entries: readonly DropEntry<K>[]): DropTable<K>;
|
|
107
104
|
/**
|
|
108
105
|
* Allocating convenience wrapper. Creates a fresh pity object and returns both.
|
|
109
106
|
* Use `table.rollInto` on the hot path; this is for tests and cold-path setup.
|
|
110
107
|
*/
|
|
111
|
-
declare function rollDrop<K extends string>(table: DropTable<K>, rollTable01: number, rollChance01: number, chancePerRoll: number, pity: DropPity<K>, thresholds: Partial<Record<K, number>>, isAllowed?: (item: K) => boolean): DropRollOut<K>;
|
|
112
|
-
//#endregion
|
|
113
|
-
//#region src/tier-resolve.d.ts
|
|
108
|
+
export declare function rollDrop<K extends string>(table: DropTable<K>, rollTable01: number, rollChance01: number, chancePerRoll: number, pity: DropPity<K>, thresholds: Partial<Record<K, number>>, isAllowed?: (item: K) => boolean): DropRollOut<K>;
|
|
114
109
|
/**
|
|
115
110
|
* Tier resolution: "highest threshold crossed by a running tally."
|
|
116
111
|
*
|
|
@@ -131,15 +126,13 @@ interface TierEntry<T> {
|
|
|
131
126
|
* one with the largest `at` that satisfies `tally >= at`.
|
|
132
127
|
* Ties (identical `at`) are broken by iteration order (last entry wins).
|
|
133
128
|
*/
|
|
134
|
-
declare function resolveTier<T>(entries: readonly TierEntry<T>[], tally: number): T | null;
|
|
129
|
+
export declare function resolveTier<T>(entries: readonly TierEntry<T>[], tally: number): T | null;
|
|
135
130
|
/**
|
|
136
131
|
* Returns the index (0-based) of the highest satisfied tier entry,
|
|
137
132
|
* or -1 when `tally` is below all thresholds.
|
|
138
133
|
* Same tie-breaking rules as `resolveTier`.
|
|
139
134
|
*/
|
|
140
|
-
declare function resolveTierIndex<T>(entries: readonly TierEntry<T>[], tally: number): number;
|
|
141
|
-
//#endregion
|
|
142
|
-
//#region src/unlock-dag.d.ts
|
|
135
|
+
export declare function resolveTierIndex<T>(entries: readonly TierEntry<T>[], tally: number): number;
|
|
143
136
|
/**
|
|
144
137
|
* Prerequisite DAG for unlock/progression graphs.
|
|
145
138
|
*
|
|
@@ -177,9 +170,7 @@ interface UnlockDag {
|
|
|
177
170
|
* Duplicate ids throw. Unknown `requires` ids are silently tolerated — a node
|
|
178
171
|
* whose prerequisite id doesn't exist in the graph is simply never satisfiable.
|
|
179
172
|
*/
|
|
180
|
-
declare function createUnlockDag(nodes: readonly DagNode[]): UnlockDag;
|
|
181
|
-
//#endregion
|
|
182
|
-
//#region src/upgrade-track.d.ts
|
|
173
|
+
export declare function createUnlockDag(nodes: readonly DagNode[]): UnlockDag;
|
|
183
174
|
/**
|
|
184
175
|
* Geometric upgrade track with an immutable buy operation.
|
|
185
176
|
* price(level) = round(base × growth^level) — the next-level cost from `level`.
|
|
@@ -225,7 +216,6 @@ interface UpgradeTrack {
|
|
|
225
216
|
* Returns an `UpgradeTrack` backed by `config`.
|
|
226
217
|
* The returned object is a plain object (no class) — safe to freeze or copy.
|
|
227
218
|
*/
|
|
228
|
-
declare function createUpgradeTrack(config: UpgradeTrackConfig): UpgradeTrack;
|
|
229
|
-
|
|
230
|
-
export { type CollectibleRegistry, type DagNode, type DropEntry, type DropPity, type DropRollOut, type DropTable, type TierEntry, type UnlockDag, type UpgradeBuyResult, type UpgradeTrack, type UpgradeTrackConfig, createCollectibleRegistry, createDropTable, createUnlockDag, createUpgradeTrack, resolveTier, resolveTierIndex, rollDrop };
|
|
219
|
+
export declare function createUpgradeTrack(config: UpgradeTrackConfig): UpgradeTrack;
|
|
220
|
+
export type { CollectibleRegistry, DagNode, DropEntry, DropPity, DropRollOut, DropTable, TierEntry, UnlockDag, UpgradeBuyResult, UpgradeTrack, UpgradeTrackConfig };
|
|
231
221
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/collectible-registry.ts","../src/drop-roll.ts","../src/tier-resolve.ts","../src/unlock-dag.ts","../src/upgrade-track.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/collectible-registry.ts","../src/drop-roll.ts","../src/tier-resolve.ts","../src/unlock-dag.ts","../src/upgrade-track.ts"],"mappings":";;;;;;UAOiB,oBAAoB;;WAE1B,KAAK,YAAY;;WAEjB,YAAY;;WAEZ,UA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wBAOI,mBAAmB,QAAQ,qBAAqB"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
//#region src/collectible-registry.d.ts
|
|
2
1
|
/**
|
|
3
2
|
* Collectible-unlock registry: immutable unlock-set + partition + capstone.
|
|
4
3
|
*
|
|
@@ -52,9 +51,7 @@ interface CollectibleRegistry<K extends string> {
|
|
|
52
51
|
* unlock auto-fires on full completion regardless of whether the capstone id
|
|
53
52
|
* was directly unlocked via the `ids` set, which would be semantically ambiguous.
|
|
54
53
|
*/
|
|
55
|
-
declare function createCollectibleRegistry<K extends string>(ids: readonly K[], capstoneId?: K): CollectibleRegistry<K>;
|
|
56
|
-
//#endregion
|
|
57
|
-
//#region src/drop-roll.d.ts
|
|
54
|
+
export declare function createCollectibleRegistry<K extends string>(ids: readonly K[], capstoneId?: K): CollectibleRegistry<K>;
|
|
58
55
|
/**
|
|
59
56
|
* Pity-aware weighted drop roller.
|
|
60
57
|
*
|
|
@@ -103,14 +100,12 @@ interface DropTable<K extends string> {
|
|
|
103
100
|
* The `weightAt` accessor and scratch buffer are allocated once inside this
|
|
104
101
|
* factory (not per-roll).
|
|
105
102
|
*/
|
|
106
|
-
declare function createDropTable<K extends string>(entries: readonly DropEntry<K>[]): DropTable<K>;
|
|
103
|
+
export declare function createDropTable<K extends string>(entries: readonly DropEntry<K>[]): DropTable<K>;
|
|
107
104
|
/**
|
|
108
105
|
* Allocating convenience wrapper. Creates a fresh pity object and returns both.
|
|
109
106
|
* Use `table.rollInto` on the hot path; this is for tests and cold-path setup.
|
|
110
107
|
*/
|
|
111
|
-
declare function rollDrop<K extends string>(table: DropTable<K>, rollTable01: number, rollChance01: number, chancePerRoll: number, pity: DropPity<K>, thresholds: Partial<Record<K, number>>, isAllowed?: (item: K) => boolean): DropRollOut<K>;
|
|
112
|
-
//#endregion
|
|
113
|
-
//#region src/tier-resolve.d.ts
|
|
108
|
+
export declare function rollDrop<K extends string>(table: DropTable<K>, rollTable01: number, rollChance01: number, chancePerRoll: number, pity: DropPity<K>, thresholds: Partial<Record<K, number>>, isAllowed?: (item: K) => boolean): DropRollOut<K>;
|
|
114
109
|
/**
|
|
115
110
|
* Tier resolution: "highest threshold crossed by a running tally."
|
|
116
111
|
*
|
|
@@ -131,15 +126,13 @@ interface TierEntry<T> {
|
|
|
131
126
|
* one with the largest `at` that satisfies `tally >= at`.
|
|
132
127
|
* Ties (identical `at`) are broken by iteration order (last entry wins).
|
|
133
128
|
*/
|
|
134
|
-
declare function resolveTier<T>(entries: readonly TierEntry<T>[], tally: number): T | null;
|
|
129
|
+
export declare function resolveTier<T>(entries: readonly TierEntry<T>[], tally: number): T | null;
|
|
135
130
|
/**
|
|
136
131
|
* Returns the index (0-based) of the highest satisfied tier entry,
|
|
137
132
|
* or -1 when `tally` is below all thresholds.
|
|
138
133
|
* Same tie-breaking rules as `resolveTier`.
|
|
139
134
|
*/
|
|
140
|
-
declare function resolveTierIndex<T>(entries: readonly TierEntry<T>[], tally: number): number;
|
|
141
|
-
//#endregion
|
|
142
|
-
//#region src/unlock-dag.d.ts
|
|
135
|
+
export declare function resolveTierIndex<T>(entries: readonly TierEntry<T>[], tally: number): number;
|
|
143
136
|
/**
|
|
144
137
|
* Prerequisite DAG for unlock/progression graphs.
|
|
145
138
|
*
|
|
@@ -177,9 +170,7 @@ interface UnlockDag {
|
|
|
177
170
|
* Duplicate ids throw. Unknown `requires` ids are silently tolerated — a node
|
|
178
171
|
* whose prerequisite id doesn't exist in the graph is simply never satisfiable.
|
|
179
172
|
*/
|
|
180
|
-
declare function createUnlockDag(nodes: readonly DagNode[]): UnlockDag;
|
|
181
|
-
//#endregion
|
|
182
|
-
//#region src/upgrade-track.d.ts
|
|
173
|
+
export declare function createUnlockDag(nodes: readonly DagNode[]): UnlockDag;
|
|
183
174
|
/**
|
|
184
175
|
* Geometric upgrade track with an immutable buy operation.
|
|
185
176
|
* price(level) = round(base × growth^level) — the next-level cost from `level`.
|
|
@@ -225,7 +216,6 @@ interface UpgradeTrack {
|
|
|
225
216
|
* Returns an `UpgradeTrack` backed by `config`.
|
|
226
217
|
* The returned object is a plain object (no class) — safe to freeze or copy.
|
|
227
218
|
*/
|
|
228
|
-
declare function createUpgradeTrack(config: UpgradeTrackConfig): UpgradeTrack;
|
|
229
|
-
|
|
230
|
-
export { type CollectibleRegistry, type DagNode, type DropEntry, type DropPity, type DropRollOut, type DropTable, type TierEntry, type UnlockDag, type UpgradeBuyResult, type UpgradeTrack, type UpgradeTrackConfig, createCollectibleRegistry, createDropTable, createUnlockDag, createUpgradeTrack, resolveTier, resolveTierIndex, rollDrop };
|
|
219
|
+
export declare function createUpgradeTrack(config: UpgradeTrackConfig): UpgradeTrack;
|
|
220
|
+
export type { CollectibleRegistry, DagNode, DropEntry, DropPity, DropRollOut, DropTable, TierEntry, UnlockDag, UpgradeBuyResult, UpgradeTrack, UpgradeTrackConfig };
|
|
231
221
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/collectible-registry.ts","../src/drop-roll.ts","../src/tier-resolve.ts","../src/unlock-dag.ts","../src/upgrade-track.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/collectible-registry.ts","../src/drop-roll.ts","../src/tier-resolve.ts","../src/unlock-dag.ts","../src/upgrade-track.ts"],"mappings":";;;;;;UAOiB,oBAAoB;;WAE1B,KAAK,YAAY;;WAEjB,YAAY;;WAEZ,UAAU,YAAY;;WAEtB;;;;;WAKA;;;;;;;EAOT,OAAO,IAAI,IAAI,oBAAoB;;;;;;EAMnC;IAAe,eAAe;IAAK,kBAAkB;;;;;EAIrD,iBAAiB;;;;;;;;;;;;;;wBAiEH,0BAA0B,kBACxC,cAAc,KACd,aAAa,IACZ,oBAAoB;;;;;;;;;;;UC5FN,UAAU;WAChB,MAAM;WACN;;;;;;KAOC,SAAS,oBAAoB,OAAO;UAE/B,YAAY;EAC3B,MAAM;EACN,MAAM,SAAS;;;;;;UAOA,UAAU;WAChB,kBAAkB,UAAU;;;;;;;;;;;;;EAarC,SACE,qBACA,sBACA,uBACA,MAAM,SAAS,IACf,YAAY,QAAQ,OAAO,aAC3B,YAAY,MAAM,eAClB,KAAK,YAAY;;;;;;;wBASL,gBAAgB,kBAAkB,kBAAkB,UAAU,OAAO,UAAU;;;;;wBAuE/E,SAAS,kBACvB,OAAO,UAAU,IACjB,qBACA,sBACA,uBACA,MAAM,SAAS,IACf,YAAY,QAAQ,OAAO,aAC3B,aAAa,MAAM,gBAClB,YAAY;;;;;;;UCvIE,UAAU;;WAEhB;;WAEA,MAAM;;;;;;;;;;wBAWD,YAAY,GAAG,kBAAkB,UAAU,MAAM,gBAAgB;;;;;;wBAiBjE,iBAAiB,GAAG,kBAAkB,UAAU,MAAM;;;;;;;UChCrD;;WAEN;;WAEA;;UAGM;WACN,OAAO,oBAAoB;;;;;;EAMpC,WAAW,SAAS,qBAAqB;;;;;;EAMzC,SAAS,SAAS;;;;;EAKlB,YAAY,SAAS;;;;;;;wBAQP,gBAAgB,gBAAgB,YAAY;;;;;;UClC3C;;WAEN;;WAEA;;WAEA;;UAGM;WACN;WACA;WACA;;UAGM;WACN,QAAQ;;;;;EAKjB,MAAM;;EAEN,OAAO,gBAAgB;;;;;EAKvB,IAAI,gBAAgB,uBAAuB;;;;;;;;EAQ3C,aAAa,kBACX,MAAM,OAAO,YACb,QAAQ,OAAO,YACf,WAAW,KAAK,eACf,OAAO;;;;;;wBAOI,mBAAmB,QAAQ,qBAAqB"}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
let _flare_engine_math = require("@flare-engine/math");
|
|
3
|
-
|
|
3
|
+
// src/collectible-registry.ts
|
|
4
4
|
function makeRegistry(all, capstoneId, unlocked) {
|
|
5
5
|
const isComplete = [...all].every((id) => unlocked.has(id));
|
|
6
6
|
const isCapstone = capstoneId !== null && unlocked.has(capstoneId);
|
|
@@ -59,8 +59,7 @@ function createCollectibleRegistry(ids, capstoneId) {
|
|
|
59
59
|
}
|
|
60
60
|
return makeRegistry(all, capstoneId ?? null, /* @__PURE__ */ new Set());
|
|
61
61
|
}
|
|
62
|
-
|
|
63
|
-
//#region src/drop-roll.ts
|
|
62
|
+
// src/drop-roll.ts
|
|
64
63
|
/**
|
|
65
64
|
* Pity-aware weighted drop roller.
|
|
66
65
|
*
|
|
@@ -125,8 +124,7 @@ function rollDrop(table, rollTable01, rollChance01, chancePerRoll, pity, thresho
|
|
|
125
124
|
table.rollInto(rollTable01, rollChance01, chancePerRoll, pity, thresholds, isAllowed ?? (() => true), out);
|
|
126
125
|
return out;
|
|
127
126
|
}
|
|
128
|
-
|
|
129
|
-
//#region src/tier-resolve.ts
|
|
127
|
+
// src/tier-resolve.ts
|
|
130
128
|
/**
|
|
131
129
|
* Returns the highest tier whose `at` threshold is met or exceeded by `tally`,
|
|
132
130
|
* or `null` when `tally` is below all thresholds.
|
|
@@ -161,8 +159,7 @@ function resolveTierIndex(entries, tally) {
|
|
|
161
159
|
}
|
|
162
160
|
return bestIdx;
|
|
163
161
|
}
|
|
164
|
-
|
|
165
|
-
//#region src/unlock-dag.ts
|
|
162
|
+
// src/unlock-dag.ts
|
|
166
163
|
/**
|
|
167
164
|
* Creates an `UnlockDag` from `nodes`.
|
|
168
165
|
* Duplicate ids throw. Unknown `requires` ids are silently tolerated — a node
|
|
@@ -197,8 +194,7 @@ function createUnlockDag(nodes) {
|
|
|
197
194
|
allUnlocked
|
|
198
195
|
};
|
|
199
196
|
}
|
|
200
|
-
|
|
201
|
-
//#region src/upgrade-track.ts
|
|
197
|
+
// src/upgrade-track.ts
|
|
202
198
|
/**
|
|
203
199
|
* Returns an `UpgradeTrack` backed by `config`.
|
|
204
200
|
* The returned object is a plain object (no class) — safe to freeze or copy.
|
|
@@ -240,7 +236,6 @@ function createUpgradeTrack(config) {
|
|
|
240
236
|
resolveStats
|
|
241
237
|
};
|
|
242
238
|
}
|
|
243
|
-
//#endregion
|
|
244
239
|
exports.createCollectibleRegistry = createCollectibleRegistry;
|
|
245
240
|
exports.createDropTable = createDropTable;
|
|
246
241
|
exports.createUnlockDag = createUnlockDag;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/collectible-registry.ts","../src/drop-roll.ts","../src/tier-resolve.ts","../src/unlock-dag.ts","../src/upgrade-track.ts"],"sourcesContent":["/**\n * Collectible-unlock registry: immutable unlock-set + partition + capstone.\n *\n * The registry is generic over a string id type.\n * All operations return new registry instances — no mutation.\n */\n\nexport interface CollectibleRegistry<K extends string> {\n /** The complete set of collectible ids (excluding the capstone). */\n readonly all: ReadonlySet<K>;\n /** The capstone id, or null when no capstone is defined. */\n readonly capstoneId: K | null;\n /** Currently unlocked ids (a subset of `all`, plus capstone when triggered). */\n readonly unlocked: ReadonlySet<K>;\n /** True when every collectible in `all` is unlocked. */\n readonly isComplete: boolean;\n /**\n * True when the capstone is in `unlocked`. Always false when `capstoneId`\n * is null.\n */\n readonly isCapstone: boolean;\n /**\n * Returns a new registry with `id` added to `unlocked`. Idempotent.\n * Automatically adds the capstone when `isComplete` transitions to true\n * and a capstone is defined.\n * Throws on unknown ids (not in `all` and not the capstoneId).\n */\n unlock(id: K): CollectibleRegistry<K>;\n /**\n * Partition the unlocked set into `{ have, missing }`.\n * `have` = ids in `all` that are in `unlocked` (capstone excluded).\n * `missing` = ids in `all` not yet unlocked.\n */\n partition(): { have: readonly K[]; missing: readonly K[] };\n /**\n * Returns all ids in `all` in insertion order.\n */\n list(): readonly K[];\n}\n\nfunction makeRegistry<K extends string>(\n all: ReadonlySet<K>,\n capstoneId: K | null,\n unlocked: ReadonlySet<K>,\n): CollectibleRegistry<K> {\n const isComplete = [...all].every((id) => unlocked.has(id));\n const isCapstone = capstoneId !== null && unlocked.has(capstoneId);\n\n function unlock(id: K): CollectibleRegistry<K> {\n if (!all.has(id) && id !== capstoneId) {\n throw new Error(`CollectibleRegistry: unknown id \"${String(id)}\"`);\n }\n if (unlocked.has(id)) return reg;\n const next = new Set<K>(unlocked);\n next.add(id);\n // Auto-unlock capstone on completion.\n if (capstoneId !== null && !next.has(capstoneId)) {\n const allComplete = [...all].every((k) => next.has(k));\n if (allComplete) next.add(capstoneId);\n }\n return makeRegistry(all, capstoneId, next);\n }\n\n function partition(): { have: readonly K[]; missing: readonly K[] } {\n const have: K[] = [];\n const missing: K[] = [];\n for (const id of all) {\n if (unlocked.has(id)) have.push(id);\n else missing.push(id);\n }\n return { have, missing };\n }\n\n function list(): readonly K[] {\n return [...all];\n }\n\n const reg: CollectibleRegistry<K> = {\n all,\n capstoneId,\n unlocked,\n isComplete,\n isCapstone,\n unlock,\n partition,\n list,\n };\n return reg;\n}\n\n/**\n * Creates a `CollectibleRegistry` from `ids` (the collectible set) and an\n * optional `capstoneId`.\n *\n * Duplicate ids in `ids` throw. `capstoneId` may equal one of the ids in `ids`\n * (it is tracked as a separate gate — the capstone fires only on full completion,\n * not by direct unlock through `ids` membership alone).\n *\n * The capstone MUST be distinct from all ids in `ids` — if not, the capstone\n * unlock auto-fires on full completion regardless of whether the capstone id\n * was directly unlocked via the `ids` set, which would be semantically ambiguous.\n */\nexport function createCollectibleRegistry<K extends string>(\n ids: readonly K[],\n capstoneId?: K,\n): CollectibleRegistry<K> {\n const all = new Set<K>();\n for (const id of ids) {\n if (all.has(id)) {\n throw new Error(`createCollectibleRegistry: duplicate id \"${String(id)}\"`);\n }\n all.add(id);\n }\n return makeRegistry<K>(all, capstoneId ?? null, new Set<K>());\n}\n","/**\n * Pity-aware weighted drop roller.\n *\n * `rollInto` is zero-alloc on the hot path: the `weightAt` accessor and the\n * `dryPrev` scratch buffer are allocated once inside the factory closure and\n * reused across calls. The `out` parameter receives the result in-place;\n * aliasing `out.pity` against the input `pity` is safe because the function\n * reads all input pity fields into `dryPrev` before writing any output pity\n * fields.\n */\n\nimport { weightedIndexBy } from '@flare-engine/math';\n\nexport interface DropEntry<K extends string> {\n readonly item: K;\n readonly weight: number;\n}\n\n/**\n * Per-item dry-roll counters feeding the pity guarantees.\n * Keys are the item ids whose pity is being tracked.\n */\nexport type DropPity<K extends string> = Record<K, number>;\n\nexport interface DropRollOut<K extends string> {\n item: K | 'none';\n pity: DropPity<K>;\n}\n\n/**\n * A `DropTable` is a factory that closes over a weight accessor to avoid\n * per-call allocations. Create once; reuse across frames.\n */\nexport interface DropTable<K extends string> {\n readonly entries: readonly DropEntry<K>[];\n /**\n * Zero-alloc weighted drop. Writes result into `out`.\n *\n * Algorithm:\n * 1. Check pity thresholds (first matching pity item fires unconditionally).\n * 2. If no pity fires and `rollChance01 >= chancePerRoll`, result = 'none'.\n * 3. Otherwise pick from the weighted table filtered by `isAllowed`.\n * An all-gated pool (every entry filtered out) fizzles to 'none'.\n *\n * `out.pity` counters reset for the dropped item, advance by 1 for all others.\n * Aliasing `out.pity` against the input `pity` is safe.\n */\n rollInto(\n rollTable01: number,\n rollChance01: number,\n chancePerRoll: number,\n pity: DropPity<K>,\n thresholds: Partial<Record<K, number>>,\n isAllowed: (item: K) => boolean,\n out: DropRollOut<K>,\n ): void;\n}\n\n/**\n * Creates a `DropTable` from `entries`.\n * The `weightAt` accessor and scratch buffer are allocated once inside this\n * factory (not per-roll).\n */\nexport function createDropTable<K extends string>(entries: readonly DropEntry<K>[]): DropTable<K> {\n // Closed-over filter state — set before each weightedIndexBy call.\n // `var` so the binding is function-scoped and hoisted; reassigned each call.\n var currentIsAllowed: (item: K) => boolean = () => true;\n\n const weightAt = (entry: DropEntry<K>): number =>\n currentIsAllowed(entry.item) ? entry.weight : 0;\n\n // Pre-allocated scratch buffer: stores dry counts read from `pity` before\n // any writes, enabling safe aliasing of out.pity === pity.\n const dryPrev = new Float32Array(entries.length);\n\n function rollInto(\n rollTable01: number,\n rollChance01: number,\n chancePerRoll: number,\n pity: DropPity<K>,\n thresholds: Partial<Record<K, number>>,\n isAllowed: (item: K) => boolean,\n out: DropRollOut<K>,\n ): void {\n let picked: K | 'none' = 'none';\n\n // Read all pity inputs into scratch before writing any output (aliasing guard).\n for (let i = 0; i < entries.length; i++) {\n dryPrev[i] = pity[(entries[i] as DropEntry<K>).item] ?? 0;\n }\n\n // Pity check — first item whose dry count + 1 meets or exceeds threshold.\n for (let i = 0; i < entries.length; i++) {\n const e = entries[i] as DropEntry<K>;\n const threshold = thresholds[e.item];\n if (threshold !== undefined && isAllowed(e.item) && (dryPrev[i] as number) + 1 >= threshold) {\n picked = e.item;\n break;\n }\n }\n\n // Chance gate + weighted pick.\n if (picked === 'none') {\n if (rollChance01 < chancePerRoll) {\n currentIsAllowed = isAllowed;\n // Compute allowed total to detect an all-gated pool (fizzles to 'none').\n let allowedTotal = 0;\n for (let i = 0; i < entries.length; i++) {\n allowedTotal += weightAt(entries[i] as DropEntry<K>);\n }\n if (allowedTotal > 0) {\n const idx = weightedIndexBy(entries, weightAt, rollTable01);\n const entry = entries[idx];\n if (entry !== undefined) picked = entry.item;\n }\n }\n }\n\n // Write output — pity counters.\n out.item = picked;\n for (let i = 0; i < entries.length; i++) {\n const e = entries[i] as DropEntry<K>;\n (out.pity as Record<string, number>)[e.item] =\n picked === e.item ? 0 : (dryPrev[i] as number) + 1;\n }\n }\n\n return { entries, rollInto };\n}\n\n/**\n * Allocating convenience wrapper. Creates a fresh pity object and returns both.\n * Use `table.rollInto` on the hot path; this is for tests and cold-path setup.\n */\nexport function rollDrop<K extends string>(\n table: DropTable<K>,\n rollTable01: number,\n rollChance01: number,\n chancePerRoll: number,\n pity: DropPity<K>,\n thresholds: Partial<Record<K, number>>,\n isAllowed?: (item: K) => boolean,\n): DropRollOut<K> {\n const out: DropRollOut<K> = { item: 'none', pity: { ...pity } };\n table.rollInto(\n rollTable01,\n rollChance01,\n chancePerRoll,\n pity,\n thresholds,\n isAllowed ?? (() => true),\n out,\n );\n return out;\n}\n","/**\n * Tier resolution: \"highest threshold crossed by a running tally.\"\n *\n * The tally tiers are caller-defined (generic `T`) so the same resolver\n * works for score brackets, XP thresholds, unlock gates, etc.\n */\n\nexport interface TierEntry<T> {\n /** Minimum tally value (inclusive) required to reach this tier. */\n readonly at: number;\n /** The tier value associated with this threshold. */\n readonly tier: T;\n}\n\n/**\n * Returns the highest tier whose `at` threshold is met or exceeded by `tally`,\n * or `null` when `tally` is below all thresholds.\n *\n * `entries` need not be sorted — the function scans all entries and returns the\n * one with the largest `at` that satisfies `tally >= at`.\n * Ties (identical `at`) are broken by iteration order (last entry wins).\n */\nexport function resolveTier<T>(entries: readonly TierEntry<T>[], tally: number): T | null {\n let best: T | null = null;\n let bestAt = Number.NEGATIVE_INFINITY;\n for (const e of entries) {\n if (tally >= e.at && e.at >= bestAt) {\n best = e.tier;\n bestAt = e.at;\n }\n }\n return best;\n}\n\n/**\n * Returns the index (0-based) of the highest satisfied tier entry,\n * or -1 when `tally` is below all thresholds.\n * Same tie-breaking rules as `resolveTier`.\n */\nexport function resolveTierIndex<T>(entries: readonly TierEntry<T>[], tally: number): number {\n let bestIdx = -1;\n let bestAt = Number.NEGATIVE_INFINITY;\n for (let i = 0; i < entries.length; i++) {\n const e = entries[i];\n if (e !== undefined && tally >= e.at && e.at >= bestAt) {\n bestIdx = i;\n bestAt = e.at;\n }\n }\n return bestIdx;\n}\n","/**\n * Prerequisite DAG for unlock/progression graphs.\n *\n * The graph is directed and acyclic by construction (caller contract — no runtime cycle\n * detection). Nodes are string ids; edges are \"requires\" lists.\n */\n\nexport interface DagNode {\n /** Unique string id for this node. */\n readonly id: string;\n /** Ids of nodes that must be in the cleared set before this node unlocks. */\n readonly requires: readonly string[];\n}\n\nexport interface UnlockDag {\n readonly nodes: ReadonlyMap<string, DagNode>;\n /**\n * Whether `id` is unlocked given the set of cleared (previously unlocked) ids.\n * A node with no requirements is always unlocked.\n * An unknown id returns false.\n */\n isUnlocked(cleared: ReadonlySet<string>, id: string): boolean;\n /**\n * The frontier: all nodes whose requirements are fully satisfied by `cleared`,\n * but which are NOT yet in `cleared`. Returned as a sorted array (stable\n * insertion order from `nodes`).\n */\n frontier(cleared: ReadonlySet<string>): readonly string[];\n /**\n * All nodes currently unlocked by `cleared` (including those already in\n * `cleared`). Returned as a sorted array (stable insertion order).\n */\n allUnlocked(cleared: ReadonlySet<string>): readonly string[];\n}\n\n/**\n * Creates an `UnlockDag` from `nodes`.\n * Duplicate ids throw. Unknown `requires` ids are silently tolerated — a node\n * whose prerequisite id doesn't exist in the graph is simply never satisfiable.\n */\nexport function createUnlockDag(nodes: readonly DagNode[]): UnlockDag {\n const map = new Map<string, DagNode>();\n for (const node of nodes) {\n if (map.has(node.id)) {\n throw new Error(`createUnlockDag: duplicate node id \"${node.id}\"`);\n }\n map.set(node.id, node);\n }\n\n function isUnlocked(cleared: ReadonlySet<string>, id: string): boolean {\n const node = map.get(id);\n if (!node) return false;\n for (const req of node.requires) {\n if (!cleared.has(req)) return false;\n }\n return true;\n }\n\n function frontier(cleared: ReadonlySet<string>): readonly string[] {\n const out: string[] = [];\n for (const [id] of map) {\n if (!cleared.has(id) && isUnlocked(cleared, id)) {\n out.push(id);\n }\n }\n return out;\n }\n\n function allUnlocked(cleared: ReadonlySet<string>): readonly string[] {\n const out: string[] = [];\n for (const [id] of map) {\n if (isUnlocked(cleared, id)) {\n out.push(id);\n }\n }\n return out;\n }\n\n return { nodes: map, isUnlocked, frontier, allUnlocked };\n}\n","/**\n * Geometric upgrade track with an immutable buy operation.\n * price(level) = round(base × growth^level) — the next-level cost from `level`.\n * Consolidates the common geometric-cost upgrade pattern.\n */\n\nexport interface UpgradeTrackConfig {\n /** Base price at level 0 → 1. */\n readonly base: number;\n /** Multiplicative growth factor per level. */\n readonly growth: number;\n /** Hard level cap (inclusive). */\n readonly cap: number;\n}\n\nexport interface UpgradeBuyResult {\n readonly ok: boolean;\n readonly wallet: number;\n readonly level: number;\n}\n\nexport interface UpgradeTrack {\n readonly config: UpgradeTrackConfig;\n /**\n * Cost to advance from `currentLevel` to `currentLevel + 1`.\n * Returns Infinity when at or above cap.\n */\n price(currentLevel: number): number;\n /** Whether `wallet` is sufficient and `currentLevel` is below cap. */\n canBuy(wallet: number, currentLevel: number): boolean;\n /**\n * Pure spend: deduct `price(currentLevel)` from `wallet` and return\n * the new state. Returns `{ ok: false, wallet, level }` when blocked.\n */\n buy(wallet: number, currentLevel: number): UpgradeBuyResult;\n /**\n * Fold all per-level stat deltas into a running accumulator.\n * `getLevel` is a caller-supplied reader so the resolver is unit-testable\n * without any save/store dep. `deltas` maps a stat key to the per-level delta;\n * `base` is the starting value for each key.\n * Returns a plain Record with the accumulated values.\n */\n resolveStats<K extends string>(\n base: Record<K, number>,\n deltas: Record<K, number>,\n getLevel: (key: K) => number,\n ): Record<K, number>;\n}\n\n/**\n * Returns an `UpgradeTrack` backed by `config`.\n * The returned object is a plain object (no class) — safe to freeze or copy.\n */\nexport function createUpgradeTrack(config: UpgradeTrackConfig): UpgradeTrack {\n function price(currentLevel: number): number {\n if (currentLevel >= config.cap) return Number.POSITIVE_INFINITY;\n return Math.round(config.base * config.growth ** currentLevel);\n }\n\n function canBuy(wallet: number, currentLevel: number): boolean {\n if (currentLevel >= config.cap) return false;\n return wallet >= price(currentLevel);\n }\n\n function buy(wallet: number, currentLevel: number): UpgradeBuyResult {\n if (!canBuy(wallet, currentLevel)) {\n return { ok: false, wallet, level: currentLevel };\n }\n return { ok: true, wallet: wallet - price(currentLevel), level: currentLevel + 1 };\n }\n\n function resolveStats<K extends string>(\n base: Record<K, number>,\n deltas: Record<K, number>,\n getLevel: (key: K) => number,\n ): Record<K, number> {\n const out = {} as Record<K, number>;\n for (const key of Object.keys(base) as K[]) {\n const level = Math.max(0, Math.floor(getLevel(key)));\n out[key] = (base[key] ?? 0) + (deltas[key] ?? 0) * level;\n }\n return out;\n }\n\n return { config, price, canBuy, buy, resolveStats };\n}\n"],"mappings":";;;AAwCA,S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AAC;EACvB,KAAK,MAAM,CAAC,OAAO,KACjB,IAAI,WAAW,SAAS,EAAE,GACxB,IAAI,KAAK,EAAE;EAGf,OAAO;CACT;CAEA,OAAO;EAAE,OAAO;EAAK;EAAY;EAAU;CAAY;AACzD;;;;;;;AC1BA,SAAgB,mBAAmB,QAA0C;CAC3E,SAAS,MAAM,cAA8B;EAC3C,IAAI,gBAAgB,OAAO,KAAK,OAAO,OAAO;EAC9C,OAAO,KAAK,MAAM,OAAO,OAAO,OAAO,UAAU,YAAY;CAC/D;CAEA,SAAS,OAAO,QAAgB,cAA+B;EAC7D,IAAI,gBAAgB,OAAO,KAAK,OAAO;EACvC,OAAO,UAAU,MAAM,YAAY;CACrC;CAEA,SAAS,IAAI,QAAgB,cAAwC;EACnE,IAAI,CAAC,OAAO,QAAQ,YAAY,GAC9B,OAAO;GAAE,IAAI;GAAO;GAAQ,OAAO;EAAa;EAElD,OAAO;GAAE,IAAI;GAAM,QAAQ,SAAS,MAAM,YAAY;GAAG,OAAO,eAAe;EAAE;CACnF;CAEA,SAAS,aACP,MACA,QACA,UACmB;EACnB,MAAM,MAAM,CAAC;EACb,KAAK,MAAM,OAAO,OAAO,KAAK,IAAI,GAAU;GAC1C,MAAM,QAAQ,KAAK,IAAI,GAAG,KAAK,MAAM,SAAS,GAAG,CAAC,CAAC;GACnD,IAAI,QAAQ,KAAK,QAAQ,MAAM,OAAO,QAAQ,KAAK;EACrD;EACA,OAAO;CACT;CAEA,OAAO;EAAE;EAAQ;EAAO;EAAQ;EAAK;CAAa;AACpD"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["weightedIndexBy"],"sources":["../src/collectible-registry.ts","../src/drop-roll.ts","../src/tier-resolve.ts","../src/unlock-dag.ts","../src/upgrade-track.ts"],"sourcesContent":["/**\n * Collectible-unlock registry: immutable unlock-set + partition + capstone.\n *\n * The registry is generic over a string id type.\n * All operations return new registry instances — no mutation.\n */\n\nexport interface CollectibleRegistry<K extends string> {\n /** The complete set of collectible ids (excluding the capstone). */\n readonly all: ReadonlySet<K>;\n /** The capstone id, or null when no capstone is defined. */\n readonly capstoneId: K | null;\n /** Currently unlocked ids (a subset of `all`, plus capstone when triggered). */\n readonly unlocked: ReadonlySet<K>;\n /** True when every collectible in `all` is unlocked. */\n readonly isComplete: boolean;\n /**\n * True when the capstone is in `unlocked`. Always false when `capstoneId`\n * is null.\n */\n readonly isCapstone: boolean;\n /**\n * Returns a new registry with `id` added to `unlocked`. Idempotent.\n * Automatically adds the capstone when `isComplete` transitions to true\n * and a capstone is defined.\n * Throws on unknown ids (not in `all` and not the capstoneId).\n */\n unlock(id: K): CollectibleRegistry<K>;\n /**\n * Partition the unlocked set into `{ have, missing }`.\n * `have` = ids in `all` that are in `unlocked` (capstone excluded).\n * `missing` = ids in `all` not yet unlocked.\n */\n partition(): { have: readonly K[]; missing: readonly K[] };\n /**\n * Returns all ids in `all` in insertion order.\n */\n list(): readonly K[];\n}\n\nfunction makeRegistry<K extends string>(\n all: ReadonlySet<K>,\n capstoneId: K | null,\n unlocked: ReadonlySet<K>,\n): CollectibleRegistry<K> {\n const isComplete = [...all].every((id) => unlocked.has(id));\n const isCapstone = capstoneId !== null && unlocked.has(capstoneId);\n\n function unlock(id: K): CollectibleRegistry<K> {\n if (!all.has(id) && id !== capstoneId) {\n throw new Error(`CollectibleRegistry: unknown id \"${String(id)}\"`);\n }\n if (unlocked.has(id)) return reg;\n const next = new Set<K>(unlocked);\n next.add(id);\n // Auto-unlock capstone on completion.\n if (capstoneId !== null && !next.has(capstoneId)) {\n const allComplete = [...all].every((k) => next.has(k));\n if (allComplete) next.add(capstoneId);\n }\n return makeRegistry(all, capstoneId, next);\n }\n\n function partition(): { have: readonly K[]; missing: readonly K[] } {\n const have: K[] = [];\n const missing: K[] = [];\n for (const id of all) {\n if (unlocked.has(id)) have.push(id);\n else missing.push(id);\n }\n return { have, missing };\n }\n\n function list(): readonly K[] {\n return [...all];\n }\n\n const reg: CollectibleRegistry<K> = {\n all,\n capstoneId,\n unlocked,\n isComplete,\n isCapstone,\n unlock,\n partition,\n list,\n };\n return reg;\n}\n\n/**\n * Creates a `CollectibleRegistry` from `ids` (the collectible set) and an\n * optional `capstoneId`.\n *\n * Duplicate ids in `ids` throw. `capstoneId` may equal one of the ids in `ids`\n * (it is tracked as a separate gate — the capstone fires only on full completion,\n * not by direct unlock through `ids` membership alone).\n *\n * The capstone MUST be distinct from all ids in `ids` — if not, the capstone\n * unlock auto-fires on full completion regardless of whether the capstone id\n * was directly unlocked via the `ids` set, which would be semantically ambiguous.\n */\nexport function createCollectibleRegistry<K extends string>(\n ids: readonly K[],\n capstoneId?: K,\n): CollectibleRegistry<K> {\n const all = new Set<K>();\n for (const id of ids) {\n if (all.has(id)) {\n throw new Error(`createCollectibleRegistry: duplicate id \"${String(id)}\"`);\n }\n all.add(id);\n }\n return makeRegistry<K>(all, capstoneId ?? null, new Set<K>());\n}\n","/**\n * Pity-aware weighted drop roller.\n *\n * `rollInto` is zero-alloc on the hot path: the `weightAt` accessor and the\n * `dryPrev` scratch buffer are allocated once inside the factory closure and\n * reused across calls. The `out` parameter receives the result in-place;\n * aliasing `out.pity` against the input `pity` is safe because the function\n * reads all input pity fields into `dryPrev` before writing any output pity\n * fields.\n */\n\nimport { weightedIndexBy } from '@flare-engine/math';\n\nexport interface DropEntry<K extends string> {\n readonly item: K;\n readonly weight: number;\n}\n\n/**\n * Per-item dry-roll counters feeding the pity guarantees.\n * Keys are the item ids whose pity is being tracked.\n */\nexport type DropPity<K extends string> = Record<K, number>;\n\nexport interface DropRollOut<K extends string> {\n item: K | 'none';\n pity: DropPity<K>;\n}\n\n/**\n * A `DropTable` is a factory that closes over a weight accessor to avoid\n * per-call allocations. Create once; reuse across frames.\n */\nexport interface DropTable<K extends string> {\n readonly entries: readonly DropEntry<K>[];\n /**\n * Zero-alloc weighted drop. Writes result into `out`.\n *\n * Algorithm:\n * 1. Check pity thresholds (first matching pity item fires unconditionally).\n * 2. If no pity fires and `rollChance01 >= chancePerRoll`, result = 'none'.\n * 3. Otherwise pick from the weighted table filtered by `isAllowed`.\n * An all-gated pool (every entry filtered out) fizzles to 'none'.\n *\n * `out.pity` counters reset for the dropped item, advance by 1 for all others.\n * Aliasing `out.pity` against the input `pity` is safe.\n */\n rollInto(\n rollTable01: number,\n rollChance01: number,\n chancePerRoll: number,\n pity: DropPity<K>,\n thresholds: Partial<Record<K, number>>,\n isAllowed: (item: K) => boolean,\n out: DropRollOut<K>,\n ): void;\n}\n\n/**\n * Creates a `DropTable` from `entries`.\n * The `weightAt` accessor and scratch buffer are allocated once inside this\n * factory (not per-roll).\n */\nexport function createDropTable<K extends string>(entries: readonly DropEntry<K>[]): DropTable<K> {\n // Closed-over filter state — set before each weightedIndexBy call.\n // `var` so the binding is function-scoped and hoisted; reassigned each call.\n var currentIsAllowed: (item: K) => boolean = () => true;\n\n const weightAt = (entry: DropEntry<K>): number =>\n currentIsAllowed(entry.item) ? entry.weight : 0;\n\n // Pre-allocated scratch buffer: stores dry counts read from `pity` before\n // any writes, enabling safe aliasing of out.pity === pity.\n const dryPrev = new Float32Array(entries.length);\n\n function rollInto(\n rollTable01: number,\n rollChance01: number,\n chancePerRoll: number,\n pity: DropPity<K>,\n thresholds: Partial<Record<K, number>>,\n isAllowed: (item: K) => boolean,\n out: DropRollOut<K>,\n ): void {\n let picked: K | 'none' = 'none';\n\n // Read all pity inputs into scratch before writing any output (aliasing guard).\n for (let i = 0; i < entries.length; i++) {\n dryPrev[i] = pity[(entries[i] as DropEntry<K>).item] ?? 0;\n }\n\n // Pity check — first item whose dry count + 1 meets or exceeds threshold.\n for (let i = 0; i < entries.length; i++) {\n const e = entries[i] as DropEntry<K>;\n const threshold = thresholds[e.item];\n if (threshold !== undefined && isAllowed(e.item) && (dryPrev[i] as number) + 1 >= threshold) {\n picked = e.item;\n break;\n }\n }\n\n // Chance gate + weighted pick.\n if (picked === 'none') {\n if (rollChance01 < chancePerRoll) {\n currentIsAllowed = isAllowed;\n // Compute allowed total to detect an all-gated pool (fizzles to 'none').\n let allowedTotal = 0;\n for (let i = 0; i < entries.length; i++) {\n allowedTotal += weightAt(entries[i] as DropEntry<K>);\n }\n if (allowedTotal > 0) {\n const idx = weightedIndexBy(entries, weightAt, rollTable01);\n const entry = entries[idx];\n if (entry !== undefined) picked = entry.item;\n }\n }\n }\n\n // Write output — pity counters.\n out.item = picked;\n for (let i = 0; i < entries.length; i++) {\n const e = entries[i] as DropEntry<K>;\n (out.pity as Record<string, number>)[e.item] =\n picked === e.item ? 0 : (dryPrev[i] as number) + 1;\n }\n }\n\n return { entries, rollInto };\n}\n\n/**\n * Allocating convenience wrapper. Creates a fresh pity object and returns both.\n * Use `table.rollInto` on the hot path; this is for tests and cold-path setup.\n */\nexport function rollDrop<K extends string>(\n table: DropTable<K>,\n rollTable01: number,\n rollChance01: number,\n chancePerRoll: number,\n pity: DropPity<K>,\n thresholds: Partial<Record<K, number>>,\n isAllowed?: (item: K) => boolean,\n): DropRollOut<K> {\n const out: DropRollOut<K> = { item: 'none', pity: { ...pity } };\n table.rollInto(\n rollTable01,\n rollChance01,\n chancePerRoll,\n pity,\n thresholds,\n isAllowed ?? (() => true),\n out,\n );\n return out;\n}\n","/**\n * Tier resolution: \"highest threshold crossed by a running tally.\"\n *\n * The tally tiers are caller-defined (generic `T`) so the same resolver\n * works for score brackets, XP thresholds, unlock gates, etc.\n */\n\nexport interface TierEntry<T> {\n /** Minimum tally value (inclusive) required to reach this tier. */\n readonly at: number;\n /** The tier value associated with this threshold. */\n readonly tier: T;\n}\n\n/**\n * Returns the highest tier whose `at` threshold is met or exceeded by `tally`,\n * or `null` when `tally` is below all thresholds.\n *\n * `entries` need not be sorted — the function scans all entries and returns the\n * one with the largest `at` that satisfies `tally >= at`.\n * Ties (identical `at`) are broken by iteration order (last entry wins).\n */\nexport function resolveTier<T>(entries: readonly TierEntry<T>[], tally: number): T | null {\n let best: T | null = null;\n let bestAt = Number.NEGATIVE_INFINITY;\n for (const e of entries) {\n if (tally >= e.at && e.at >= bestAt) {\n best = e.tier;\n bestAt = e.at;\n }\n }\n return best;\n}\n\n/**\n * Returns the index (0-based) of the highest satisfied tier entry,\n * or -1 when `tally` is below all thresholds.\n * Same tie-breaking rules as `resolveTier`.\n */\nexport function resolveTierIndex<T>(entries: readonly TierEntry<T>[], tally: number): number {\n let bestIdx = -1;\n let bestAt = Number.NEGATIVE_INFINITY;\n for (let i = 0; i < entries.length; i++) {\n const e = entries[i];\n if (e !== undefined && tally >= e.at && e.at >= bestAt) {\n bestIdx = i;\n bestAt = e.at;\n }\n }\n return bestIdx;\n}\n","/**\n * Prerequisite DAG for unlock/progression graphs.\n *\n * The graph is directed and acyclic by construction (caller contract — no runtime cycle\n * detection). Nodes are string ids; edges are \"requires\" lists.\n */\n\nexport interface DagNode {\n /** Unique string id for this node. */\n readonly id: string;\n /** Ids of nodes that must be in the cleared set before this node unlocks. */\n readonly requires: readonly string[];\n}\n\nexport interface UnlockDag {\n readonly nodes: ReadonlyMap<string, DagNode>;\n /**\n * Whether `id` is unlocked given the set of cleared (previously unlocked) ids.\n * A node with no requirements is always unlocked.\n * An unknown id returns false.\n */\n isUnlocked(cleared: ReadonlySet<string>, id: string): boolean;\n /**\n * The frontier: all nodes whose requirements are fully satisfied by `cleared`,\n * but which are NOT yet in `cleared`. Returned as a sorted array (stable\n * insertion order from `nodes`).\n */\n frontier(cleared: ReadonlySet<string>): readonly string[];\n /**\n * All nodes currently unlocked by `cleared` (including those already in\n * `cleared`). Returned as a sorted array (stable insertion order).\n */\n allUnlocked(cleared: ReadonlySet<string>): readonly string[];\n}\n\n/**\n * Creates an `UnlockDag` from `nodes`.\n * Duplicate ids throw. Unknown `requires` ids are silently tolerated — a node\n * whose prerequisite id doesn't exist in the graph is simply never satisfiable.\n */\nexport function createUnlockDag(nodes: readonly DagNode[]): UnlockDag {\n const map = new Map<string, DagNode>();\n for (const node of nodes) {\n if (map.has(node.id)) {\n throw new Error(`createUnlockDag: duplicate node id \"${node.id}\"`);\n }\n map.set(node.id, node);\n }\n\n function isUnlocked(cleared: ReadonlySet<string>, id: string): boolean {\n const node = map.get(id);\n if (!node) return false;\n for (const req of node.requires) {\n if (!cleared.has(req)) return false;\n }\n return true;\n }\n\n function frontier(cleared: ReadonlySet<string>): readonly string[] {\n const out: string[] = [];\n for (const [id] of map) {\n if (!cleared.has(id) && isUnlocked(cleared, id)) {\n out.push(id);\n }\n }\n return out;\n }\n\n function allUnlocked(cleared: ReadonlySet<string>): readonly string[] {\n const out: string[] = [];\n for (const [id] of map) {\n if (isUnlocked(cleared, id)) {\n out.push(id);\n }\n }\n return out;\n }\n\n return { nodes: map, isUnlocked, frontier, allUnlocked };\n}\n","/**\n * Geometric upgrade track with an immutable buy operation.\n * price(level) = round(base × growth^level) — the next-level cost from `level`.\n * Consolidates the common geometric-cost upgrade pattern.\n */\n\nexport interface UpgradeTrackConfig {\n /** Base price at level 0 → 1. */\n readonly base: number;\n /** Multiplicative growth factor per level. */\n readonly growth: number;\n /** Hard level cap (inclusive). */\n readonly cap: number;\n}\n\nexport interface UpgradeBuyResult {\n readonly ok: boolean;\n readonly wallet: number;\n readonly level: number;\n}\n\nexport interface UpgradeTrack {\n readonly config: UpgradeTrackConfig;\n /**\n * Cost to advance from `currentLevel` to `currentLevel + 1`.\n * Returns Infinity when at or above cap.\n */\n price(currentLevel: number): number;\n /** Whether `wallet` is sufficient and `currentLevel` is below cap. */\n canBuy(wallet: number, currentLevel: number): boolean;\n /**\n * Pure spend: deduct `price(currentLevel)` from `wallet` and return\n * the new state. Returns `{ ok: false, wallet, level }` when blocked.\n */\n buy(wallet: number, currentLevel: number): UpgradeBuyResult;\n /**\n * Fold all per-level stat deltas into a running accumulator.\n * `getLevel` is a caller-supplied reader so the resolver is unit-testable\n * without any save/store dep. `deltas` maps a stat key to the per-level delta;\n * `base` is the starting value for each key.\n * Returns a plain Record with the accumulated values.\n */\n resolveStats<K extends string>(\n base: Record<K, number>,\n deltas: Record<K, number>,\n getLevel: (key: K) => number,\n ): Record<K, number>;\n}\n\n/**\n * Returns an `UpgradeTrack` backed by `config`.\n * The returned object is a plain object (no class) — safe to freeze or copy.\n */\nexport function createUpgradeTrack(config: UpgradeTrackConfig): UpgradeTrack {\n function price(currentLevel: number): number {\n if (currentLevel >= config.cap) return Number.POSITIVE_INFINITY;\n return Math.round(config.base * config.growth ** currentLevel);\n }\n\n function canBuy(wallet: number, currentLevel: number): boolean {\n if (currentLevel >= config.cap) return false;\n return wallet >= price(currentLevel);\n }\n\n function buy(wallet: number, currentLevel: number): UpgradeBuyResult {\n if (!canBuy(wallet, currentLevel)) {\n return { ok: false, wallet, level: currentLevel };\n }\n return { ok: true, wallet: wallet - price(currentLevel), level: currentLevel + 1 };\n }\n\n function resolveStats<K extends string>(\n base: Record<K, number>,\n deltas: Record<K, number>,\n getLevel: (key: K) => number,\n ): Record<K, number> {\n const out = {} as Record<K, number>;\n for (const key of Object.keys(base) as K[]) {\n const level = Math.max(0, Math.floor(getLevel(key)));\n out[key] = (base[key] ?? 0) + (deltas[key] ?? 0) * level;\n }\n return out;\n }\n\n return { config, price, canBuy, buy, resolveStats };\n}\n"],"mappings":";;;AAwCA,SAAS,aACP,KACA,YACA,UACwB;CACxB,MAAM,aAAa,CAAC,GAAG,GAAG,CAAC,CAAC,OAAO,OAAO,SAAS,IAAI,EAAE,CAAC;CAC1D,MAAM,aAAa,eAAe,QAAQ,SAAS,IAAI,UAAU;CAEjE,SAAS,OAAO,IAA+B;EAC7C,IAAI,CAAC,IAAI,IAAI,EAAE,KAAK,OAAO,YACzB,MAAM,IAAI,MAAM,oCAAoC,OAAO,EAAE,EAAE,EAAE;EAEnE,IAAI,SAAS,IAAI,EAAE,GAAG,OAAO;EAC7B,MAAM,OAAO,IAAI,IAAO,QAAQ;EAChC,KAAK,IAAI,EAAE;EAEX,IAAI,eAAe,QAAQ,CAAC,KAAK,IAAI,UAAU,GACzB;OAAA,CAAC,GAAG,GAAG,CAAC,CAAC,OAAO,MAAM,KAAK,IA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AAQ,YAAY,GAC9B,OAAO;GAAE,IAAI;GAAO;GAAQ,OAAO;EAAa;EAElD,OAAO;GAAE,IAAI;GAAM,QAAQ,SAAS,MAAM,YAAY;GAAG,OAAO,eAAe;EAAE;CACnF;CAEA,SAAS,aACP,MACA,QACA,UACmB;EACnB,MAAM,MAAM,CAAC;EACb,KAAK,MAAM,OAAO,OAAO,KAAK,IAAI,GAAU;GAC1C,MAAM,QAAQ,KAAK,IAAI,GAAG,KAAK,MAAM,SAAS,GAAG,CAAC,CAAC;GACnD,IAAI,QAAQ,KAAK,QAAQ,MAAM,OAAO,QAAQ,KAAK;EACrD;EACA,OAAO;CACT;CAEA,OAAO;EAAE;EAAQ;EAAO;EAAQ;EAAK;CAAa;AACpD"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { weightedIndexBy } from "@flare-engine/math";
|
|
2
|
-
|
|
2
|
+
// src/collectible-registry.ts
|
|
3
3
|
function makeRegistry(all, capstoneId, unlocked) {
|
|
4
4
|
const isComplete = [...all].every((id) => unlocked.has(id));
|
|
5
5
|
const isCapstone = capstoneId !== null && unlocked.has(capstoneId);
|
|
@@ -58,8 +58,7 @@ function createCollectibleRegistry(ids, capstoneId) {
|
|
|
58
58
|
}
|
|
59
59
|
return makeRegistry(all, capstoneId ?? null, /* @__PURE__ */ new Set());
|
|
60
60
|
}
|
|
61
|
-
|
|
62
|
-
//#region src/drop-roll.ts
|
|
61
|
+
// src/drop-roll.ts
|
|
63
62
|
/**
|
|
64
63
|
* Pity-aware weighted drop roller.
|
|
65
64
|
*
|
|
@@ -124,8 +123,7 @@ function rollDrop(table, rollTable01, rollChance01, chancePerRoll, pity, thresho
|
|
|
124
123
|
table.rollInto(rollTable01, rollChance01, chancePerRoll, pity, thresholds, isAllowed ?? (() => true), out);
|
|
125
124
|
return out;
|
|
126
125
|
}
|
|
127
|
-
|
|
128
|
-
//#region src/tier-resolve.ts
|
|
126
|
+
// src/tier-resolve.ts
|
|
129
127
|
/**
|
|
130
128
|
* Returns the highest tier whose `at` threshold is met or exceeded by `tally`,
|
|
131
129
|
* or `null` when `tally` is below all thresholds.
|
|
@@ -160,8 +158,7 @@ function resolveTierIndex(entries, tally) {
|
|
|
160
158
|
}
|
|
161
159
|
return bestIdx;
|
|
162
160
|
}
|
|
163
|
-
|
|
164
|
-
//#region src/unlock-dag.ts
|
|
161
|
+
// src/unlock-dag.ts
|
|
165
162
|
/**
|
|
166
163
|
* Creates an `UnlockDag` from `nodes`.
|
|
167
164
|
* Duplicate ids throw. Unknown `requires` ids are silently tolerated — a node
|
|
@@ -196,8 +193,7 @@ function createUnlockDag(nodes) {
|
|
|
196
193
|
allUnlocked
|
|
197
194
|
};
|
|
198
195
|
}
|
|
199
|
-
|
|
200
|
-
//#region src/upgrade-track.ts
|
|
196
|
+
// src/upgrade-track.ts
|
|
201
197
|
/**
|
|
202
198
|
* Returns an `UpgradeTrack` backed by `config`.
|
|
203
199
|
* The returned object is a plain object (no class) — safe to freeze or copy.
|
|
@@ -239,7 +235,6 @@ function createUpgradeTrack(config) {
|
|
|
239
235
|
resolveStats
|
|
240
236
|
};
|
|
241
237
|
}
|
|
242
|
-
//#endregion
|
|
243
238
|
export { createCollectibleRegistry, createDropTable, createUnlockDag, createUpgradeTrack, resolveTier, resolveTierIndex, rollDrop };
|
|
244
239
|
|
|
245
240
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/collectible-registry.ts","../src/drop-roll.ts","../src/tier-resolve.ts","../src/unlock-dag.ts","../src/upgrade-track.ts"],"sourcesContent":["/**\n * Collectible-unlock registry: immutable unlock-set + partition + capstone.\n *\n * The registry is generic over a string id type.\n * All operations return new registry instances — no mutation.\n */\n\nexport interface CollectibleRegistry<K extends string> {\n /** The complete set of collectible ids (excluding the capstone). */\n readonly all: ReadonlySet<K>;\n /** The capstone id, or null when no capstone is defined. */\n readonly capstoneId: K | null;\n /** Currently unlocked ids (a subset of `all`, plus capstone when triggered). */\n readonly unlocked: ReadonlySet<K>;\n /** True when every collectible in `all` is unlocked. */\n readonly isComplete: boolean;\n /**\n * True when the capstone is in `unlocked`. Always false when `capstoneId`\n * is null.\n */\n readonly isCapstone: boolean;\n /**\n * Returns a new registry with `id` added to `unlocked`. Idempotent.\n * Automatically adds the capstone when `isComplete` transitions to true\n * and a capstone is defined.\n * Throws on unknown ids (not in `all` and not the capstoneId).\n */\n unlock(id: K): CollectibleRegistry<K>;\n /**\n * Partition the unlocked set into `{ have, missing }`.\n * `have` = ids in `all` that are in `unlocked` (capstone excluded).\n * `missing` = ids in `all` not yet unlocked.\n */\n partition(): { have: readonly K[]; missing: readonly K[] };\n /**\n * Returns all ids in `all` in insertion order.\n */\n list(): readonly K[];\n}\n\nfunction makeRegistry<K extends string>(\n all: ReadonlySet<K>,\n capstoneId: K | null,\n unlocked: ReadonlySet<K>,\n): CollectibleRegistry<K> {\n const isComplete = [...all].every((id) => unlocked.has(id));\n const isCapstone = capstoneId !== null && unlocked.has(capstoneId);\n\n function unlock(id: K): CollectibleRegistry<K> {\n if (!all.has(id) && id !== capstoneId) {\n throw new Error(`CollectibleRegistry: unknown id \"${String(id)}\"`);\n }\n if (unlocked.has(id)) return reg;\n const next = new Set<K>(unlocked);\n next.add(id);\n // Auto-unlock capstone on completion.\n if (capstoneId !== null && !next.has(capstoneId)) {\n const allComplete = [...all].every((k) => next.has(k));\n if (allComplete) next.add(capstoneId);\n }\n return makeRegistry(all, capstoneId, next);\n }\n\n function partition(): { have: readonly K[]; missing: readonly K[] } {\n const have: K[] = [];\n const missing: K[] = [];\n for (const id of all) {\n if (unlocked.has(id)) have.push(id);\n else missing.push(id);\n }\n return { have, missing };\n }\n\n function list(): readonly K[] {\n return [...all];\n }\n\n const reg: CollectibleRegistry<K> = {\n all,\n capstoneId,\n unlocked,\n isComplete,\n isCapstone,\n unlock,\n partition,\n list,\n };\n return reg;\n}\n\n/**\n * Creates a `CollectibleRegistry` from `ids` (the collectible set) and an\n * optional `capstoneId`.\n *\n * Duplicate ids in `ids` throw. `capstoneId` may equal one of the ids in `ids`\n * (it is tracked as a separate gate — the capstone fires only on full completion,\n * not by direct unlock through `ids` membership alone).\n *\n * The capstone MUST be distinct from all ids in `ids` — if not, the capstone\n * unlock auto-fires on full completion regardless of whether the capstone id\n * was directly unlocked via the `ids` set, which would be semantically ambiguous.\n */\nexport function createCollectibleRegistry<K extends string>(\n ids: readonly K[],\n capstoneId?: K,\n): CollectibleRegistry<K> {\n const all = new Set<K>();\n for (const id of ids) {\n if (all.has(id)) {\n throw new Error(`createCollectibleRegistry: duplicate id \"${String(id)}\"`);\n }\n all.add(id);\n }\n return makeRegistry<K>(all, capstoneId ?? null, new Set<K>());\n}\n","/**\n * Pity-aware weighted drop roller.\n *\n * `rollInto` is zero-alloc on the hot path: the `weightAt` accessor and the\n * `dryPrev` scratch buffer are allocated once inside the factory closure and\n * reused across calls. The `out` parameter receives the result in-place;\n * aliasing `out.pity` against the input `pity` is safe because the function\n * reads all input pity fields into `dryPrev` before writing any output pity\n * fields.\n */\n\nimport { weightedIndexBy } from '@flare-engine/math';\n\nexport interface DropEntry<K extends string> {\n readonly item: K;\n readonly weight: number;\n}\n\n/**\n * Per-item dry-roll counters feeding the pity guarantees.\n * Keys are the item ids whose pity is being tracked.\n */\nexport type DropPity<K extends string> = Record<K, number>;\n\nexport interface DropRollOut<K extends string> {\n item: K | 'none';\n pity: DropPity<K>;\n}\n\n/**\n * A `DropTable` is a factory that closes over a weight accessor to avoid\n * per-call allocations. Create once; reuse across frames.\n */\nexport interface DropTable<K extends string> {\n readonly entries: readonly DropEntry<K>[];\n /**\n * Zero-alloc weighted drop. Writes result into `out`.\n *\n * Algorithm:\n * 1. Check pity thresholds (first matching pity item fires unconditionally).\n * 2. If no pity fires and `rollChance01 >= chancePerRoll`, result = 'none'.\n * 3. Otherwise pick from the weighted table filtered by `isAllowed`.\n * An all-gated pool (every entry filtered out) fizzles to 'none'.\n *\n * `out.pity` counters reset for the dropped item, advance by 1 for all others.\n * Aliasing `out.pity` against the input `pity` is safe.\n */\n rollInto(\n rollTable01: number,\n rollChance01: number,\n chancePerRoll: number,\n pity: DropPity<K>,\n thresholds: Partial<Record<K, number>>,\n isAllowed: (item: K) => boolean,\n out: DropRollOut<K>,\n ): void;\n}\n\n/**\n * Creates a `DropTable` from `entries`.\n * The `weightAt` accessor and scratch buffer are allocated once inside this\n * factory (not per-roll).\n */\nexport function createDropTable<K extends string>(entries: readonly DropEntry<K>[]): DropTable<K> {\n // Closed-over filter state — set before each weightedIndexBy call.\n // `var` so the binding is function-scoped and hoisted; reassigned each call.\n var currentIsAllowed: (item: K) => boolean = () => true;\n\n const weightAt = (entry: DropEntry<K>): number =>\n currentIsAllowed(entry.item) ? entry.weight : 0;\n\n // Pre-allocated scratch buffer: stores dry counts read from `pity` before\n // any writes, enabling safe aliasing of out.pity === pity.\n const dryPrev = new Float32Array(entries.length);\n\n function rollInto(\n rollTable01: number,\n rollChance01: number,\n chancePerRoll: number,\n pity: DropPity<K>,\n thresholds: Partial<Record<K, number>>,\n isAllowed: (item: K) => boolean,\n out: DropRollOut<K>,\n ): void {\n let picked: K | 'none' = 'none';\n\n // Read all pity inputs into scratch before writing any output (aliasing guard).\n for (let i = 0; i < entries.length; i++) {\n dryPrev[i] = pity[(entries[i] as DropEntry<K>).item] ?? 0;\n }\n\n // Pity check — first item whose dry count + 1 meets or exceeds threshold.\n for (let i = 0; i < entries.length; i++) {\n const e = entries[i] as DropEntry<K>;\n const threshold = thresholds[e.item];\n if (threshold !== undefined && isAllowed(e.item) && (dryPrev[i] as number) + 1 >= threshold) {\n picked = e.item;\n break;\n }\n }\n\n // Chance gate + weighted pick.\n if (picked === 'none') {\n if (rollChance01 < chancePerRoll) {\n currentIsAllowed = isAllowed;\n // Compute allowed total to detect an all-gated pool (fizzles to 'none').\n let allowedTotal = 0;\n for (let i = 0; i < entries.length; i++) {\n allowedTotal += weightAt(entries[i] as DropEntry<K>);\n }\n if (allowedTotal > 0) {\n const idx = weightedIndexBy(entries, weightAt, rollTable01);\n const entry = entries[idx];\n if (entry !== undefined) picked = entry.item;\n }\n }\n }\n\n // Write output — pity counters.\n out.item = picked;\n for (let i = 0; i < entries.length; i++) {\n const e = entries[i] as DropEntry<K>;\n (out.pity as Record<string, number>)[e.item] =\n picked === e.item ? 0 : (dryPrev[i] as number) + 1;\n }\n }\n\n return { entries, rollInto };\n}\n\n/**\n * Allocating convenience wrapper. Creates a fresh pity object and returns both.\n * Use `table.rollInto` on the hot path; this is for tests and cold-path setup.\n */\nexport function rollDrop<K extends string>(\n table: DropTable<K>,\n rollTable01: number,\n rollChance01: number,\n chancePerRoll: number,\n pity: DropPity<K>,\n thresholds: Partial<Record<K, number>>,\n isAllowed?: (item: K) => boolean,\n): DropRollOut<K> {\n const out: DropRollOut<K> = { item: 'none', pity: { ...pity } };\n table.rollInto(\n rollTable01,\n rollChance01,\n chancePerRoll,\n pity,\n thresholds,\n isAllowed ?? (() => true),\n out,\n );\n return out;\n}\n","/**\n * Tier resolution: \"highest threshold crossed by a running tally.\"\n *\n * The tally tiers are caller-defined (generic `T`) so the same resolver\n * works for score brackets, XP thresholds, unlock gates, etc.\n */\n\nexport interface TierEntry<T> {\n /** Minimum tally value (inclusive) required to reach this tier. */\n readonly at: number;\n /** The tier value associated with this threshold. */\n readonly tier: T;\n}\n\n/**\n * Returns the highest tier whose `at` threshold is met or exceeded by `tally`,\n * or `null` when `tally` is below all thresholds.\n *\n * `entries` need not be sorted — the function scans all entries and returns the\n * one with the largest `at` that satisfies `tally >= at`.\n * Ties (identical `at`) are broken by iteration order (last entry wins).\n */\nexport function resolveTier<T>(entries: readonly TierEntry<T>[], tally: number): T | null {\n let best: T | null = null;\n let bestAt = Number.NEGATIVE_INFINITY;\n for (const e of entries) {\n if (tally >= e.at && e.at >= bestAt) {\n best = e.tier;\n bestAt = e.at;\n }\n }\n return best;\n}\n\n/**\n * Returns the index (0-based) of the highest satisfied tier entry,\n * or -1 when `tally` is below all thresholds.\n * Same tie-breaking rules as `resolveTier`.\n */\nexport function resolveTierIndex<T>(entries: readonly TierEntry<T>[], tally: number): number {\n let bestIdx = -1;\n let bestAt = Number.NEGATIVE_INFINITY;\n for (let i = 0; i < entries.length; i++) {\n const e = entries[i];\n if (e !== undefined && tally >= e.at && e.at >= bestAt) {\n bestIdx = i;\n bestAt = e.at;\n }\n }\n return bestIdx;\n}\n","/**\n * Prerequisite DAG for unlock/progression graphs.\n *\n * The graph is directed and acyclic by construction (caller contract — no runtime cycle\n * detection). Nodes are string ids; edges are \"requires\" lists.\n */\n\nexport interface DagNode {\n /** Unique string id for this node. */\n readonly id: string;\n /** Ids of nodes that must be in the cleared set before this node unlocks. */\n readonly requires: readonly string[];\n}\n\nexport interface UnlockDag {\n readonly nodes: ReadonlyMap<string, DagNode>;\n /**\n * Whether `id` is unlocked given the set of cleared (previously unlocked) ids.\n * A node with no requirements is always unlocked.\n * An unknown id returns false.\n */\n isUnlocked(cleared: ReadonlySet<string>, id: string): boolean;\n /**\n * The frontier: all nodes whose requirements are fully satisfied by `cleared`,\n * but which are NOT yet in `cleared`. Returned as a sorted array (stable\n * insertion order from `nodes`).\n */\n frontier(cleared: ReadonlySet<string>): readonly string[];\n /**\n * All nodes currently unlocked by `cleared` (including those already in\n * `cleared`). Returned as a sorted array (stable insertion order).\n */\n allUnlocked(cleared: ReadonlySet<string>): readonly string[];\n}\n\n/**\n * Creates an `UnlockDag` from `nodes`.\n * Duplicate ids throw. Unknown `requires` ids are silently tolerated — a node\n * whose prerequisite id doesn't exist in the graph is simply never satisfiable.\n */\nexport function createUnlockDag(nodes: readonly DagNode[]): UnlockDag {\n const map = new Map<string, DagNode>();\n for (const node of nodes) {\n if (map.has(node.id)) {\n throw new Error(`createUnlockDag: duplicate node id \"${node.id}\"`);\n }\n map.set(node.id, node);\n }\n\n function isUnlocked(cleared: ReadonlySet<string>, id: string): boolean {\n const node = map.get(id);\n if (!node) return false;\n for (const req of node.requires) {\n if (!cleared.has(req)) return false;\n }\n return true;\n }\n\n function frontier(cleared: ReadonlySet<string>): readonly string[] {\n const out: string[] = [];\n for (const [id] of map) {\n if (!cleared.has(id) && isUnlocked(cleared, id)) {\n out.push(id);\n }\n }\n return out;\n }\n\n function allUnlocked(cleared: ReadonlySet<string>): readonly string[] {\n const out: string[] = [];\n for (const [id] of map) {\n if (isUnlocked(cleared, id)) {\n out.push(id);\n }\n }\n return out;\n }\n\n return { nodes: map, isUnlocked, frontier, allUnlocked };\n}\n","/**\n * Geometric upgrade track with an immutable buy operation.\n * price(level) = round(base × growth^level) — the next-level cost from `level`.\n * Consolidates the common geometric-cost upgrade pattern.\n */\n\nexport interface UpgradeTrackConfig {\n /** Base price at level 0 → 1. */\n readonly base: number;\n /** Multiplicative growth factor per level. */\n readonly growth: number;\n /** Hard level cap (inclusive). */\n readonly cap: number;\n}\n\nexport interface UpgradeBuyResult {\n readonly ok: boolean;\n readonly wallet: number;\n readonly level: number;\n}\n\nexport interface UpgradeTrack {\n readonly config: UpgradeTrackConfig;\n /**\n * Cost to advance from `currentLevel` to `currentLevel + 1`.\n * Returns Infinity when at or above cap.\n */\n price(currentLevel: number): number;\n /** Whether `wallet` is sufficient and `currentLevel` is below cap. */\n canBuy(wallet: number, currentLevel: number): boolean;\n /**\n * Pure spend: deduct `price(currentLevel)` from `wallet` and return\n * the new state. Returns `{ ok: false, wallet, level }` when blocked.\n */\n buy(wallet: number, currentLevel: number): UpgradeBuyResult;\n /**\n * Fold all per-level stat deltas into a running accumulator.\n * `getLevel` is a caller-supplied reader so the resolver is unit-testable\n * without any save/store dep. `deltas` maps a stat key to the per-level delta;\n * `base` is the starting value for each key.\n * Returns a plain Record with the accumulated values.\n */\n resolveStats<K extends string>(\n base: Record<K, number>,\n deltas: Record<K, number>,\n getLevel: (key: K) => number,\n ): Record<K, number>;\n}\n\n/**\n * Returns an `UpgradeTrack` backed by `config`.\n * The returned object is a plain object (no class) — safe to freeze or copy.\n */\nexport function createUpgradeTrack(config: UpgradeTrackConfig): UpgradeTrack {\n function price(currentLevel: number): number {\n if (currentLevel >= config.cap) return Number.POSITIVE_INFINITY;\n return Math.round(config.base * config.growth ** currentLevel);\n }\n\n function canBuy(wallet: number, currentLevel: number): boolean {\n if (currentLevel >= config.cap) return false;\n return wallet >= price(currentLevel);\n }\n\n function buy(wallet: number, currentLevel: number): UpgradeBuyResult {\n if (!canBuy(wallet, currentLevel)) {\n return { ok: false, wallet, level: currentLevel };\n }\n return { ok: true, wallet: wallet - price(currentLevel), level: currentLevel + 1 };\n }\n\n function resolveStats<K extends string>(\n base: Record<K, number>,\n deltas: Record<K, number>,\n getLevel: (key: K) => number,\n ): Record<K, number> {\n const out = {} as Record<K, number>;\n for (const key of Object.keys(base) as K[]) {\n const level = Math.max(0, Math.floor(getLevel(key)));\n out[key] = (base[key] ?? 0) + (deltas[key] ?? 0) * level;\n }\n return out;\n }\n\n return { config, price, canBuy, buy, resolveStats };\n}\n"],"mappings":";;AAwCA,SAAS,aACP,KACA,YACA,UACwB;CACxB,MAAM,aAAa,CAAC,GAAG,GAAG,CAAC,CAAC,OAAO,OAAO,SAAS,IAAI,EAAE,CAAC;CAC1D,MAAM,aAAa,eAAe,QAAQ,SAAS,IAAI,UAAU;CAEjE,SAAS,OAAO,IAA+B;EAC7C,IAAI,CAAC,IAAI,IAAI,EAAE,KAAK,OAAO,YACzB,MAAM,IAAI,MAAM,oCAAoC,OAAO,EAAE,EAAE,EAAE;EAEnE,IAAI,SAAS,IAAI,EAAE,GAAG,OAAO;EAC7B,MAAM,OAAO,IAAI,IAAO,QAAQ;EAChC,KAAK,IAAI,EAAE;EAEX,IAAI,eAAe,QAAQ,CAAC,KAAK,IAAI,UAAU;OACzB,CAAC,GAAG,GAAG,CAAC,CAAC,OAAO,MAAM,KAAK,IAAI,CAAC,CACtC,GAAG,KAAK,IAAI,UAAU;EAAA;EAEtC,OAAO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AAI;GAAM,QAAQ,SAAS,MAAM,YAAY;GAAG,OAAO,eAAe;EAAE;CACnF;CAEA,SAAS,aACP,MACA,QACA,UACmB;EACnB,MAAM,MAAM,CAAC;EACb,KAAK,MAAM,OAAO,OAAO,KAAK,IAAI,GAAU;GAC1C,MAAM,QAAQ,KAAK,IAAI,GAAG,KAAK,MAAM,SAAS,GAAG,CAAC,CAAC;GACnD,IAAI,QAAQ,KAAK,QAAQ,MAAM,OAAO,QAAQ,KAAK;EACrD;EACA,OAAO;CACT;CAEA,OAAO;EAAE;EAAQ;EAAO;EAAQ;EAAK;CAAa;AACpD"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/collectible-registry.ts","../src/drop-roll.ts","../src/tier-resolve.ts","../src/unlock-dag.ts","../src/upgrade-track.ts"],"sourcesContent":["/**\n * Collectible-unlock registry: immutable unlock-set + partition + capstone.\n *\n * The registry is generic over a string id type.\n * All operations return new registry instances — no mutation.\n */\n\nexport interface CollectibleRegistry<K extends string> {\n /** The complete set of collectible ids (excluding the capstone). */\n readonly all: ReadonlySet<K>;\n /** The capstone id, or null when no capstone is defined. */\n readonly capstoneId: K | null;\n /** Currently unlocked ids (a subset of `all`, plus capstone when triggered). */\n readonly unlocked: ReadonlySet<K>;\n /** True when every collectible in `all` is unlocked. */\n readonly isComplete: boolean;\n /**\n * True when the capstone is in `unlocked`. Always false when `capstoneId`\n * is null.\n */\n readonly isCapstone: boolean;\n /**\n * Returns a new registry with `id` added to `unlocked`. Idempotent.\n * Automatically adds the capstone when `isComplete` transitions to true\n * and a capstone is defined.\n * Throws on unknown ids (not in `all` and not the capstoneId).\n */\n unlock(id: K): CollectibleRegistry<K>;\n /**\n * Partition the unlocked set into `{ have, missing }`.\n * `have` = ids in `all` that are in `unlocked` (capstone excluded).\n * `missing` = ids in `all` not yet unlocked.\n */\n partition(): { have: readonly K[]; missing: readonly K[] };\n /**\n * Returns all ids in `all` in insertion order.\n */\n list(): readonly K[];\n}\n\nfunction makeRegistry<K extends string>(\n all: ReadonlySet<K>,\n capstoneId: K | null,\n unlocked: ReadonlySet<K>,\n): CollectibleRegistry<K> {\n const isComplete = [...all].every((id) => unlocked.has(id));\n const isCapstone = capstoneId !== null && unlocked.has(capstoneId);\n\n function unlock(id: K): CollectibleRegistry<K> {\n if (!all.has(id) && id !== capstoneId) {\n throw new Error(`CollectibleRegistry: unknown id \"${String(id)}\"`);\n }\n if (unlocked.has(id)) return reg;\n const next = new Set<K>(unlocked);\n next.add(id);\n // Auto-unlock capstone on completion.\n if (capstoneId !== null && !next.has(capstoneId)) {\n const allComplete = [...all].every((k) => next.has(k));\n if (allComplete) next.add(capstoneId);\n }\n return makeRegistry(all, capstoneId, next);\n }\n\n function partition(): { have: readonly K[]; missing: readonly K[] } {\n const have: K[] = [];\n const missing: K[] = [];\n for (const id of all) {\n if (unlocked.has(id)) have.push(id);\n else missing.push(id);\n }\n return { have, missing };\n }\n\n function list(): readonly K[] {\n return [...all];\n }\n\n const reg: CollectibleRegistry<K> = {\n all,\n capstoneId,\n unlocked,\n isComplete,\n isCapstone,\n unlock,\n partition,\n list,\n };\n return reg;\n}\n\n/**\n * Creates a `CollectibleRegistry` from `ids` (the collectible set) and an\n * optional `capstoneId`.\n *\n * Duplicate ids in `ids` throw. `capstoneId` may equal one of the ids in `ids`\n * (it is tracked as a separate gate — the capstone fires only on full completion,\n * not by direct unlock through `ids` membership alone).\n *\n * The capstone MUST be distinct from all ids in `ids` — if not, the capstone\n * unlock auto-fires on full completion regardless of whether the capstone id\n * was directly unlocked via the `ids` set, which would be semantically ambiguous.\n */\nexport function createCollectibleRegistry<K extends string>(\n ids: readonly K[],\n capstoneId?: K,\n): CollectibleRegistry<K> {\n const all = new Set<K>();\n for (const id of ids) {\n if (all.has(id)) {\n throw new Error(`createCollectibleRegistry: duplicate id \"${String(id)}\"`);\n }\n all.add(id);\n }\n return makeRegistry<K>(all, capstoneId ?? null, new Set<K>());\n}\n","/**\n * Pity-aware weighted drop roller.\n *\n * `rollInto` is zero-alloc on the hot path: the `weightAt` accessor and the\n * `dryPrev` scratch buffer are allocated once inside the factory closure and\n * reused across calls. The `out` parameter receives the result in-place;\n * aliasing `out.pity` against the input `pity` is safe because the function\n * reads all input pity fields into `dryPrev` before writing any output pity\n * fields.\n */\n\nimport { weightedIndexBy } from '@flare-engine/math';\n\nexport interface DropEntry<K extends string> {\n readonly item: K;\n readonly weight: number;\n}\n\n/**\n * Per-item dry-roll counters feeding the pity guarantees.\n * Keys are the item ids whose pity is being tracked.\n */\nexport type DropPity<K extends string> = Record<K, number>;\n\nexport interface DropRollOut<K extends string> {\n item: K | 'none';\n pity: DropPity<K>;\n}\n\n/**\n * A `DropTable` is a factory that closes over a weight accessor to avoid\n * per-call allocations. Create once; reuse across frames.\n */\nexport interface DropTable<K extends string> {\n readonly entries: readonly DropEntry<K>[];\n /**\n * Zero-alloc weighted drop. Writes result into `out`.\n *\n * Algorithm:\n * 1. Check pity thresholds (first matching pity item fires unconditionally).\n * 2. If no pity fires and `rollChance01 >= chancePerRoll`, result = 'none'.\n * 3. Otherwise pick from the weighted table filtered by `isAllowed`.\n * An all-gated pool (every entry filtered out) fizzles to 'none'.\n *\n * `out.pity` counters reset for the dropped item, advance by 1 for all others.\n * Aliasing `out.pity` against the input `pity` is safe.\n */\n rollInto(\n rollTable01: number,\n rollChance01: number,\n chancePerRoll: number,\n pity: DropPity<K>,\n thresholds: Partial<Record<K, number>>,\n isAllowed: (item: K) => boolean,\n out: DropRollOut<K>,\n ): void;\n}\n\n/**\n * Creates a `DropTable` from `entries`.\n * The `weightAt` accessor and scratch buffer are allocated once inside this\n * factory (not per-roll).\n */\nexport function createDropTable<K extends string>(entries: readonly DropEntry<K>[]): DropTable<K> {\n // Closed-over filter state — set before each weightedIndexBy call.\n // `var` so the binding is function-scoped and hoisted; reassigned each call.\n var currentIsAllowed: (item: K) => boolean = () => true;\n\n const weightAt = (entry: DropEntry<K>): number =>\n currentIsAllowed(entry.item) ? entry.weight : 0;\n\n // Pre-allocated scratch buffer: stores dry counts read from `pity` before\n // any writes, enabling safe aliasing of out.pity === pity.\n const dryPrev = new Float32Array(entries.length);\n\n function rollInto(\n rollTable01: number,\n rollChance01: number,\n chancePerRoll: number,\n pity: DropPity<K>,\n thresholds: Partial<Record<K, number>>,\n isAllowed: (item: K) => boolean,\n out: DropRollOut<K>,\n ): void {\n let picked: K | 'none' = 'none';\n\n // Read all pity inputs into scratch before writing any output (aliasing guard).\n for (let i = 0; i < entries.length; i++) {\n dryPrev[i] = pity[(entries[i] as DropEntry<K>).item] ?? 0;\n }\n\n // Pity check — first item whose dry count + 1 meets or exceeds threshold.\n for (let i = 0; i < entries.length; i++) {\n const e = entries[i] as DropEntry<K>;\n const threshold = thresholds[e.item];\n if (threshold !== undefined && isAllowed(e.item) && (dryPrev[i] as number) + 1 >= threshold) {\n picked = e.item;\n break;\n }\n }\n\n // Chance gate + weighted pick.\n if (picked === 'none') {\n if (rollChance01 < chancePerRoll) {\n currentIsAllowed = isAllowed;\n // Compute allowed total to detect an all-gated pool (fizzles to 'none').\n let allowedTotal = 0;\n for (let i = 0; i < entries.length; i++) {\n allowedTotal += weightAt(entries[i] as DropEntry<K>);\n }\n if (allowedTotal > 0) {\n const idx = weightedIndexBy(entries, weightAt, rollTable01);\n const entry = entries[idx];\n if (entry !== undefined) picked = entry.item;\n }\n }\n }\n\n // Write output — pity counters.\n out.item = picked;\n for (let i = 0; i < entries.length; i++) {\n const e = entries[i] as DropEntry<K>;\n (out.pity as Record<string, number>)[e.item] =\n picked === e.item ? 0 : (dryPrev[i] as number) + 1;\n }\n }\n\n return { entries, rollInto };\n}\n\n/**\n * Allocating convenience wrapper. Creates a fresh pity object and returns both.\n * Use `table.rollInto` on the hot path; this is for tests and cold-path setup.\n */\nexport function rollDrop<K extends string>(\n table: DropTable<K>,\n rollTable01: number,\n rollChance01: number,\n chancePerRoll: number,\n pity: DropPity<K>,\n thresholds: Partial<Record<K, number>>,\n isAllowed?: (item: K) => boolean,\n): DropRollOut<K> {\n const out: DropRollOut<K> = { item: 'none', pity: { ...pity } };\n table.rollInto(\n rollTable01,\n rollChance01,\n chancePerRoll,\n pity,\n thresholds,\n isAllowed ?? (() => true),\n out,\n );\n return out;\n}\n","/**\n * Tier resolution: \"highest threshold crossed by a running tally.\"\n *\n * The tally tiers are caller-defined (generic `T`) so the same resolver\n * works for score brackets, XP thresholds, unlock gates, etc.\n */\n\nexport interface TierEntry<T> {\n /** Minimum tally value (inclusive) required to reach this tier. */\n readonly at: number;\n /** The tier value associated with this threshold. */\n readonly tier: T;\n}\n\n/**\n * Returns the highest tier whose `at` threshold is met or exceeded by `tally`,\n * or `null` when `tally` is below all thresholds.\n *\n * `entries` need not be sorted — the function scans all entries and returns the\n * one with the largest `at` that satisfies `tally >= at`.\n * Ties (identical `at`) are broken by iteration order (last entry wins).\n */\nexport function resolveTier<T>(entries: readonly TierEntry<T>[], tally: number): T | null {\n let best: T | null = null;\n let bestAt = Number.NEGATIVE_INFINITY;\n for (const e of entries) {\n if (tally >= e.at && e.at >= bestAt) {\n best = e.tier;\n bestAt = e.at;\n }\n }\n return best;\n}\n\n/**\n * Returns the index (0-based) of the highest satisfied tier entry,\n * or -1 when `tally` is below all thresholds.\n * Same tie-breaking rules as `resolveTier`.\n */\nexport function resolveTierIndex<T>(entries: readonly TierEntry<T>[], tally: number): number {\n let bestIdx = -1;\n let bestAt = Number.NEGATIVE_INFINITY;\n for (let i = 0; i < entries.length; i++) {\n const e = entries[i];\n if (e !== undefined && tally >= e.at && e.at >= bestAt) {\n bestIdx = i;\n bestAt = e.at;\n }\n }\n return bestIdx;\n}\n","/**\n * Prerequisite DAG for unlock/progression graphs.\n *\n * The graph is directed and acyclic by construction (caller contract — no runtime cycle\n * detection). Nodes are string ids; edges are \"requires\" lists.\n */\n\nexport interface DagNode {\n /** Unique string id for this node. */\n readonly id: string;\n /** Ids of nodes that must be in the cleared set before this node unlocks. */\n readonly requires: readonly string[];\n}\n\nexport interface UnlockDag {\n readonly nodes: ReadonlyMap<string, DagNode>;\n /**\n * Whether `id` is unlocked given the set of cleared (previously unlocked) ids.\n * A node with no requirements is always unlocked.\n * An unknown id returns false.\n */\n isUnlocked(cleared: ReadonlySet<string>, id: string): boolean;\n /**\n * The frontier: all nodes whose requirements are fully satisfied by `cleared`,\n * but which are NOT yet in `cleared`. Returned as a sorted array (stable\n * insertion order from `nodes`).\n */\n frontier(cleared: ReadonlySet<string>): readonly string[];\n /**\n * All nodes currently unlocked by `cleared` (including those already in\n * `cleared`). Returned as a sorted array (stable insertion order).\n */\n allUnlocked(cleared: ReadonlySet<string>): readonly string[];\n}\n\n/**\n * Creates an `UnlockDag` from `nodes`.\n * Duplicate ids throw. Unknown `requires` ids are silently tolerated — a node\n * whose prerequisite id doesn't exist in the graph is simply never satisfiable.\n */\nexport function createUnlockDag(nodes: readonly DagNode[]): UnlockDag {\n const map = new Map<string, DagNode>();\n for (const node of nodes) {\n if (map.has(node.id)) {\n throw new Error(`createUnlockDag: duplicate node id \"${node.id}\"`);\n }\n map.set(node.id, node);\n }\n\n function isUnlocked(cleared: ReadonlySet<string>, id: string): boolean {\n const node = map.get(id);\n if (!node) return false;\n for (const req of node.requires) {\n if (!cleared.has(req)) return false;\n }\n return true;\n }\n\n function frontier(cleared: ReadonlySet<string>): readonly string[] {\n const out: string[] = [];\n for (const [id] of map) {\n if (!cleared.has(id) && isUnlocked(cleared, id)) {\n out.push(id);\n }\n }\n return out;\n }\n\n function allUnlocked(cleared: ReadonlySet<string>): readonly string[] {\n const out: string[] = [];\n for (const [id] of map) {\n if (isUnlocked(cleared, id)) {\n out.push(id);\n }\n }\n return out;\n }\n\n return { nodes: map, isUnlocked, frontier, allUnlocked };\n}\n","/**\n * Geometric upgrade track with an immutable buy operation.\n * price(level) = round(base × growth^level) — the next-level cost from `level`.\n * Consolidates the common geometric-cost upgrade pattern.\n */\n\nexport interface UpgradeTrackConfig {\n /** Base price at level 0 → 1. */\n readonly base: number;\n /** Multiplicative growth factor per level. */\n readonly growth: number;\n /** Hard level cap (inclusive). */\n readonly cap: number;\n}\n\nexport interface UpgradeBuyResult {\n readonly ok: boolean;\n readonly wallet: number;\n readonly level: number;\n}\n\nexport interface UpgradeTrack {\n readonly config: UpgradeTrackConfig;\n /**\n * Cost to advance from `currentLevel` to `currentLevel + 1`.\n * Returns Infinity when at or above cap.\n */\n price(currentLevel: number): number;\n /** Whether `wallet` is sufficient and `currentLevel` is below cap. */\n canBuy(wallet: number, currentLevel: number): boolean;\n /**\n * Pure spend: deduct `price(currentLevel)` from `wallet` and return\n * the new state. Returns `{ ok: false, wallet, level }` when blocked.\n */\n buy(wallet: number, currentLevel: number): UpgradeBuyResult;\n /**\n * Fold all per-level stat deltas into a running accumulator.\n * `getLevel` is a caller-supplied reader so the resolver is unit-testable\n * without any save/store dep. `deltas` maps a stat key to the per-level delta;\n * `base` is the starting value for each key.\n * Returns a plain Record with the accumulated values.\n */\n resolveStats<K extends string>(\n base: Record<K, number>,\n deltas: Record<K, number>,\n getLevel: (key: K) => number,\n ): Record<K, number>;\n}\n\n/**\n * Returns an `UpgradeTrack` backed by `config`.\n * The returned object is a plain object (no class) — safe to freeze or copy.\n */\nexport function createUpgradeTrack(config: UpgradeTrackConfig): UpgradeTrack {\n function price(currentLevel: number): number {\n if (currentLevel >= config.cap) return Number.POSITIVE_INFINITY;\n return Math.round(config.base * config.growth ** currentLevel);\n }\n\n function canBuy(wallet: number, currentLevel: number): boolean {\n if (currentLevel >= config.cap) return false;\n return wallet >= price(currentLevel);\n }\n\n function buy(wallet: number, currentLevel: number): UpgradeBuyResult {\n if (!canBuy(wallet, currentLevel)) {\n return { ok: false, wallet, level: currentLevel };\n }\n return { ok: true, wallet: wallet - price(currentLevel), level: currentLevel + 1 };\n }\n\n function resolveStats<K extends string>(\n base: Record<K, number>,\n deltas: Record<K, number>,\n getLevel: (key: K) => number,\n ): Record<K, number> {\n const out = {} as Record<K, number>;\n for (const key of Object.keys(base) as K[]) {\n const level = Math.max(0, Math.floor(getLevel(key)));\n out[key] = (base[key] ?? 0) + (deltas[key] ?? 0) * level;\n }\n return out;\n }\n\n return { config, price, canBuy, buy, resolveStats };\n}\n"],"mappings":";;AAwCA,SAAS,aACP,KACA,YACA,UACwB;CACxB,MAAM,aAAa,CAAC,GAAG,GAAG,CAAC,CAAC,OAAO,OAAO,SAAS,IAAI,EAAE,CAAC;CAC1D,MAAM,aAAa,eAAe,QAAQ,SAAS,IAAI,UAAU;CAEjE,SAAS,OAAO,IAA+B;EAC7C,IAAI,CAAC,IAAI,IAAI,EAAE,KAAK,OAAO,YACzB,MAAM,IAAI,MAAM,oCAAoC,OAAO,EAAE,EAAE,EAAE;EAEnE,IAAI,SAAS,IAAI,EAAE,GAAG,OAAO;EAC7B,MAAM,OAAO,IAAI,IAAO,QAAQ;EAChC,KAAK,IAAI,EAAE;EAEX,IAAI,eAAe,QAAQ,CAAC,KAAK,IAAI,UAAU,GACzB;OAAA,CAAC,GAAG,GAAG,CAAC,CAAC,OAAO,MAAM,KAAK,IAAI,CAAC,CACtC,GAAG,KAAK,IAAI,UAAU;EAAA;EAEtC,OAAO,aAAa,KAAK,YAAY,IAAI;CAC3C;CAEA,SAAS,YAA2D;EAClE,MAAM,OAAY,CAAC;EACnB,MAAM,UAAe,CAAC;EACtB,KAAK,MAAM,MAAM,KACf,IAAI,SAAS,IAAI,EAAE,GAAG,KAAK,KAAK,EAAE;OAC7B,QAAQ,KAAK,EAAE;EAEtB,OAAO;GAAE;GAAM;EAAQ;CACzB;CAEA,SAAS,OAAqB;EAC5B,OAAO,CAAC,GAAG,GAAG;CAChB;CAEA,MAAM,MAA8B;EAClC;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF;CACA,OAAO;AACT;;;;;;;;;;;;;AAcA,SAAgB,0BACd,KACA,YACwB;CACxB,MAAM,sBAAM,IAAI,IAAO;CACvB,KAAK,MAAM,MAAM,KAAK;EACpB,IAAI,IAAI,IAAI,EAAE,GACZ,MAAM,IAAI,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": "Meta-progression primitives: upgrade tracks, drop-roll with pity, unlock DAG, tier resolution, collectible registry",
|
|
5
5
|
"keywords": ["flare-engine", "progression", "upgrade", "drop", "unlock", "tier"],
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -45,6 +45,6 @@
|
|
|
45
45
|
},
|
|
46
46
|
"sideEffects": false,
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@flare-engine/math": "^0.4.
|
|
48
|
+
"@flare-engine/math": "^0.4.7"
|
|
49
49
|
}
|
|
50
50
|
}
|