@flare-engine/progression 0.2.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Grzegorz Otto
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,66 @@
1
+ # @flare-engine/progression
2
+
3
+ Meta-progression primitives: geometric upgrade tracks, pity-aware weighted drop rolling, unlock DAG, tier resolution, and collectible-unlock registry. Pure, zero-alloc on hot paths. Depends on `@flare-engine/math`.
4
+
5
+ ## Install
6
+
7
+ ```sh
8
+ bun add @flare-engine/progression
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```ts
14
+ import {
15
+ createUpgradeTrack,
16
+ createDropTable,
17
+ rollDrop,
18
+ createUnlockDag,
19
+ resolveTier,
20
+ createCollectibleRegistry,
21
+ } from '@flare-engine/progression';
22
+
23
+ // Upgrade track — geometric price curve
24
+ const track = createUpgradeTrack({ base: 500, growth: 1.5, cap: 10 });
25
+ const price = track.price(3); // 500 * 1.5^3
26
+ const wallet = 1000;
27
+ const result = track.buy(wallet, 3); // { ok, wallet, level }
28
+
29
+ // Drop roll with pity — create once, reuse across frames (zero-alloc rollInto)
30
+ const entries = [
31
+ { item: 'rare' as const, weight: 8 },
32
+ { item: 'common' as const, weight: 60 },
33
+ ];
34
+ const table = createDropTable(entries);
35
+ const pity = { rare: 0, common: 0 };
36
+ const thresholds = { rare: 25 };
37
+ const isAllowed = (_item: 'rare' | 'common') => true;
38
+
39
+ // Hot path — zero-alloc in-place roll
40
+ const out = { item: 'none' as 'rare' | 'common' | 'none', pity: { ...pity } };
41
+ table.rollInto(0.0, 0.0, 0.12, pity, thresholds, isAllowed, out);
42
+
43
+ // Cold path / test helper — allocating wrapper
44
+ const result2 = rollDrop(table, 0.0, 0.0, 0.12, pity, thresholds);
45
+
46
+ // Unlock DAG
47
+ const dag = createUnlockDag([
48
+ { id: 'b', requires: ['a'] },
49
+ { id: 'a', requires: [] },
50
+ ]);
51
+ const frontier = dag.frontier(new Set(['a']));
52
+
53
+ // Tier resolve
54
+ const tier = resolveTier([{ at: 1, tier: 'bronze' }, { at: 10, tier: 'silver' }], 5);
55
+
56
+ // Collectible registry
57
+ const reg = createCollectibleRegistry(['item-1', 'item-2', 'item-3'], 'set-complete');
58
+ const reg2 = reg.unlock('item-1').unlock('item-2').unlock('item-3');
59
+ reg2.isCapstone; // true
60
+ ```
61
+
62
+ See [API spec](../../docs/design/api-specs.md#flare-engineprogression).
63
+
64
+ ## License
65
+
66
+ MIT
@@ -0,0 +1,225 @@
1
+ /**
2
+ * Geometric upgrade track with an immutable buy operation.
3
+ * price(level) = round(base × growth^level) — the next-level cost from `level`.
4
+ * Consolidates the common geometric-cost upgrade pattern.
5
+ */
6
+ interface UpgradeTrackConfig {
7
+ /** Base price at level 0 → 1. */
8
+ readonly base: number;
9
+ /** Multiplicative growth factor per level. */
10
+ readonly growth: number;
11
+ /** Hard level cap (inclusive). */
12
+ readonly cap: number;
13
+ }
14
+ interface UpgradeBuyResult {
15
+ readonly ok: boolean;
16
+ readonly wallet: number;
17
+ readonly level: number;
18
+ }
19
+ interface UpgradeTrack {
20
+ readonly config: UpgradeTrackConfig;
21
+ /**
22
+ * Cost to advance from `currentLevel` to `currentLevel + 1`.
23
+ * Returns Infinity when at or above cap.
24
+ */
25
+ price(currentLevel: number): number;
26
+ /** Whether `wallet` is sufficient and `currentLevel` is below cap. */
27
+ canBuy(wallet: number, currentLevel: number): boolean;
28
+ /**
29
+ * Pure spend: deduct `price(currentLevel)` from `wallet` and return
30
+ * the new state. Returns `{ ok: false, wallet, level }` when blocked.
31
+ */
32
+ buy(wallet: number, currentLevel: number): UpgradeBuyResult;
33
+ /**
34
+ * Fold all per-level stat deltas into a running accumulator.
35
+ * `getLevel` is a caller-supplied reader so the resolver is unit-testable
36
+ * without any save/store dep. `deltas` maps a stat key to the per-level delta;
37
+ * `base` is the starting value for each key.
38
+ * Returns a plain Record with the accumulated values.
39
+ */
40
+ resolveStats<K extends string>(base: Record<K, number>, deltas: Record<K, number>, getLevel: (key: K) => number): Record<K, number>;
41
+ }
42
+ /**
43
+ * Returns an `UpgradeTrack` backed by `config`.
44
+ * The returned object is a plain object (no class) — safe to freeze or copy.
45
+ */
46
+ declare function createUpgradeTrack(config: UpgradeTrackConfig): UpgradeTrack;
47
+
48
+ /**
49
+ * Pity-aware weighted drop roller.
50
+ *
51
+ * `rollInto` is zero-alloc on the hot path: the `weightAt` accessor and the
52
+ * `dryPrev` scratch buffer are allocated once inside the factory closure and
53
+ * reused across calls. The `out` parameter receives the result in-place;
54
+ * aliasing `out.pity` against the input `pity` is safe because the function
55
+ * reads all input pity fields into `dryPrev` before writing any output pity
56
+ * fields.
57
+ */
58
+ interface DropEntry<K extends string> {
59
+ readonly item: K;
60
+ readonly weight: number;
61
+ }
62
+ /**
63
+ * Per-item dry-roll counters feeding the pity guarantees.
64
+ * Keys are the item ids whose pity is being tracked.
65
+ */
66
+ type DropPity<K extends string> = Record<K, number>;
67
+ interface DropRollOut<K extends string> {
68
+ item: K | 'none';
69
+ pity: DropPity<K>;
70
+ }
71
+ /**
72
+ * A `DropTable` is a factory that closes over a weight accessor to avoid
73
+ * per-call allocations. Create once; reuse across frames.
74
+ */
75
+ interface DropTable<K extends string> {
76
+ readonly entries: readonly DropEntry<K>[];
77
+ /**
78
+ * Zero-alloc weighted drop. Writes result into `out`.
79
+ *
80
+ * Algorithm:
81
+ * 1. Check pity thresholds (first matching pity item fires unconditionally).
82
+ * 2. If no pity fires and `rollChance01 >= chancePerRoll`, result = 'none'.
83
+ * 3. Otherwise pick from the weighted table filtered by `isAllowed`.
84
+ * An all-gated pool (every entry filtered out) fizzles to 'none'.
85
+ *
86
+ * `out.pity` counters reset for the dropped item, advance by 1 for all others.
87
+ * Aliasing `out.pity` against the input `pity` is safe.
88
+ */
89
+ rollInto(rollTable01: number, rollChance01: number, chancePerRoll: number, pity: DropPity<K>, thresholds: Partial<Record<K, number>>, isAllowed: (item: K) => boolean, out: DropRollOut<K>): void;
90
+ }
91
+ /**
92
+ * Creates a `DropTable` from `entries`.
93
+ * The `weightAt` accessor and scratch buffer are allocated once inside this
94
+ * factory (not per-roll).
95
+ */
96
+ declare function createDropTable<K extends string>(entries: readonly DropEntry<K>[]): DropTable<K>;
97
+ /**
98
+ * Allocating convenience wrapper. Creates a fresh pity object and returns both.
99
+ * Use `table.rollInto` on the hot path; this is for tests and cold-path setup.
100
+ */
101
+ 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>;
102
+
103
+ /**
104
+ * Prerequisite DAG for unlock/progression graphs.
105
+ *
106
+ * The graph is directed and acyclic by construction (caller contract — no runtime cycle
107
+ * detection). Nodes are string ids; edges are "requires" lists.
108
+ */
109
+ interface DagNode {
110
+ /** Unique string id for this node. */
111
+ readonly id: string;
112
+ /** Ids of nodes that must be in the cleared set before this node unlocks. */
113
+ readonly requires: readonly string[];
114
+ }
115
+ interface UnlockDag {
116
+ readonly nodes: ReadonlyMap<string, DagNode>;
117
+ /**
118
+ * Whether `id` is unlocked given the set of cleared (previously unlocked) ids.
119
+ * A node with no requirements is always unlocked.
120
+ * An unknown id returns false.
121
+ */
122
+ isUnlocked(cleared: ReadonlySet<string>, id: string): boolean;
123
+ /**
124
+ * The frontier: all nodes whose requirements are fully satisfied by `cleared`,
125
+ * but which are NOT yet in `cleared`. Returned as a sorted array (stable
126
+ * insertion order from `nodes`).
127
+ */
128
+ frontier(cleared: ReadonlySet<string>): readonly string[];
129
+ /**
130
+ * All nodes currently unlocked by `cleared` (including those already in
131
+ * `cleared`). Returned as a sorted array (stable insertion order).
132
+ */
133
+ allUnlocked(cleared: ReadonlySet<string>): readonly string[];
134
+ }
135
+ /**
136
+ * Creates an `UnlockDag` from `nodes`.
137
+ * Duplicate ids throw. Unknown `requires` ids are silently tolerated — a node
138
+ * whose prerequisite id doesn't exist in the graph is simply never satisfiable.
139
+ */
140
+ declare function createUnlockDag(nodes: readonly DagNode[]): UnlockDag;
141
+
142
+ /**
143
+ * Tier resolution: "highest threshold crossed by a running tally."
144
+ *
145
+ * The tally tiers are caller-defined (generic `T`) so the same resolver
146
+ * works for score brackets, XP thresholds, unlock gates, etc.
147
+ */
148
+ interface TierEntry<T> {
149
+ /** Minimum tally value (inclusive) required to reach this tier. */
150
+ readonly at: number;
151
+ /** The tier value associated with this threshold. */
152
+ readonly tier: T;
153
+ }
154
+ /**
155
+ * Returns the highest tier whose `at` threshold is met or exceeded by `tally`,
156
+ * or `null` when `tally` is below all thresholds.
157
+ *
158
+ * `entries` need not be sorted — the function scans all entries and returns the
159
+ * one with the largest `at` that satisfies `tally >= at`.
160
+ * Ties (identical `at`) are broken by iteration order (last entry wins).
161
+ */
162
+ declare function resolveTier<T>(entries: readonly TierEntry<T>[], tally: number): T | null;
163
+ /**
164
+ * Returns the index (0-based) of the highest satisfied tier entry,
165
+ * or -1 when `tally` is below all thresholds.
166
+ * Same tie-breaking rules as `resolveTier`.
167
+ */
168
+ declare function resolveTierIndex<T>(entries: readonly TierEntry<T>[], tally: number): number;
169
+
170
+ /**
171
+ * Collectible-unlock registry: immutable unlock-set + partition + capstone.
172
+ *
173
+ * The registry is generic over a string id type.
174
+ * All operations return new registry instances — no mutation.
175
+ */
176
+ interface CollectibleRegistry<K extends string> {
177
+ /** The complete set of collectible ids (excluding the capstone). */
178
+ readonly all: ReadonlySet<K>;
179
+ /** The capstone id, or null when no capstone is defined. */
180
+ readonly capstoneId: K | null;
181
+ /** Currently unlocked ids (a subset of `all`, plus capstone when triggered). */
182
+ readonly unlocked: ReadonlySet<K>;
183
+ /** True when every collectible in `all` is unlocked. */
184
+ readonly isComplete: boolean;
185
+ /**
186
+ * True when the capstone is in `unlocked`. Always false when `capstoneId`
187
+ * is null.
188
+ */
189
+ readonly isCapstone: boolean;
190
+ /**
191
+ * Returns a new registry with `id` added to `unlocked`. Idempotent.
192
+ * Automatically adds the capstone when `isComplete` transitions to true
193
+ * and a capstone is defined.
194
+ * Throws on unknown ids (not in `all` and not the capstoneId).
195
+ */
196
+ unlock(id: K): CollectibleRegistry<K>;
197
+ /**
198
+ * Partition the unlocked set into `{ have, missing }`.
199
+ * `have` = ids in `all` that are in `unlocked` (capstone excluded).
200
+ * `missing` = ids in `all` not yet unlocked.
201
+ */
202
+ partition(): {
203
+ have: readonly K[];
204
+ missing: readonly K[];
205
+ };
206
+ /**
207
+ * Returns all ids in `all` in insertion order.
208
+ */
209
+ list(): readonly K[];
210
+ }
211
+ /**
212
+ * Creates a `CollectibleRegistry` from `ids` (the collectible set) and an
213
+ * optional `capstoneId`.
214
+ *
215
+ * Duplicate ids in `ids` throw. `capstoneId` may equal one of the ids in `ids`
216
+ * (it is tracked as a separate gate — the capstone fires only on full completion,
217
+ * not by direct unlock through `ids` membership alone).
218
+ *
219
+ * The capstone MUST be distinct from all ids in `ids` — if not, the capstone
220
+ * unlock auto-fires on full completion regardless of whether the capstone id
221
+ * was directly unlocked via the `ids` set, which would be semantically ambiguous.
222
+ */
223
+ declare function createCollectibleRegistry<K extends string>(ids: readonly K[], capstoneId?: K): CollectibleRegistry<K>;
224
+
225
+ 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 };
@@ -0,0 +1,225 @@
1
+ /**
2
+ * Geometric upgrade track with an immutable buy operation.
3
+ * price(level) = round(base × growth^level) — the next-level cost from `level`.
4
+ * Consolidates the common geometric-cost upgrade pattern.
5
+ */
6
+ interface UpgradeTrackConfig {
7
+ /** Base price at level 0 → 1. */
8
+ readonly base: number;
9
+ /** Multiplicative growth factor per level. */
10
+ readonly growth: number;
11
+ /** Hard level cap (inclusive). */
12
+ readonly cap: number;
13
+ }
14
+ interface UpgradeBuyResult {
15
+ readonly ok: boolean;
16
+ readonly wallet: number;
17
+ readonly level: number;
18
+ }
19
+ interface UpgradeTrack {
20
+ readonly config: UpgradeTrackConfig;
21
+ /**
22
+ * Cost to advance from `currentLevel` to `currentLevel + 1`.
23
+ * Returns Infinity when at or above cap.
24
+ */
25
+ price(currentLevel: number): number;
26
+ /** Whether `wallet` is sufficient and `currentLevel` is below cap. */
27
+ canBuy(wallet: number, currentLevel: number): boolean;
28
+ /**
29
+ * Pure spend: deduct `price(currentLevel)` from `wallet` and return
30
+ * the new state. Returns `{ ok: false, wallet, level }` when blocked.
31
+ */
32
+ buy(wallet: number, currentLevel: number): UpgradeBuyResult;
33
+ /**
34
+ * Fold all per-level stat deltas into a running accumulator.
35
+ * `getLevel` is a caller-supplied reader so the resolver is unit-testable
36
+ * without any save/store dep. `deltas` maps a stat key to the per-level delta;
37
+ * `base` is the starting value for each key.
38
+ * Returns a plain Record with the accumulated values.
39
+ */
40
+ resolveStats<K extends string>(base: Record<K, number>, deltas: Record<K, number>, getLevel: (key: K) => number): Record<K, number>;
41
+ }
42
+ /**
43
+ * Returns an `UpgradeTrack` backed by `config`.
44
+ * The returned object is a plain object (no class) — safe to freeze or copy.
45
+ */
46
+ declare function createUpgradeTrack(config: UpgradeTrackConfig): UpgradeTrack;
47
+
48
+ /**
49
+ * Pity-aware weighted drop roller.
50
+ *
51
+ * `rollInto` is zero-alloc on the hot path: the `weightAt` accessor and the
52
+ * `dryPrev` scratch buffer are allocated once inside the factory closure and
53
+ * reused across calls. The `out` parameter receives the result in-place;
54
+ * aliasing `out.pity` against the input `pity` is safe because the function
55
+ * reads all input pity fields into `dryPrev` before writing any output pity
56
+ * fields.
57
+ */
58
+ interface DropEntry<K extends string> {
59
+ readonly item: K;
60
+ readonly weight: number;
61
+ }
62
+ /**
63
+ * Per-item dry-roll counters feeding the pity guarantees.
64
+ * Keys are the item ids whose pity is being tracked.
65
+ */
66
+ type DropPity<K extends string> = Record<K, number>;
67
+ interface DropRollOut<K extends string> {
68
+ item: K | 'none';
69
+ pity: DropPity<K>;
70
+ }
71
+ /**
72
+ * A `DropTable` is a factory that closes over a weight accessor to avoid
73
+ * per-call allocations. Create once; reuse across frames.
74
+ */
75
+ interface DropTable<K extends string> {
76
+ readonly entries: readonly DropEntry<K>[];
77
+ /**
78
+ * Zero-alloc weighted drop. Writes result into `out`.
79
+ *
80
+ * Algorithm:
81
+ * 1. Check pity thresholds (first matching pity item fires unconditionally).
82
+ * 2. If no pity fires and `rollChance01 >= chancePerRoll`, result = 'none'.
83
+ * 3. Otherwise pick from the weighted table filtered by `isAllowed`.
84
+ * An all-gated pool (every entry filtered out) fizzles to 'none'.
85
+ *
86
+ * `out.pity` counters reset for the dropped item, advance by 1 for all others.
87
+ * Aliasing `out.pity` against the input `pity` is safe.
88
+ */
89
+ rollInto(rollTable01: number, rollChance01: number, chancePerRoll: number, pity: DropPity<K>, thresholds: Partial<Record<K, number>>, isAllowed: (item: K) => boolean, out: DropRollOut<K>): void;
90
+ }
91
+ /**
92
+ * Creates a `DropTable` from `entries`.
93
+ * The `weightAt` accessor and scratch buffer are allocated once inside this
94
+ * factory (not per-roll).
95
+ */
96
+ declare function createDropTable<K extends string>(entries: readonly DropEntry<K>[]): DropTable<K>;
97
+ /**
98
+ * Allocating convenience wrapper. Creates a fresh pity object and returns both.
99
+ * Use `table.rollInto` on the hot path; this is for tests and cold-path setup.
100
+ */
101
+ 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>;
102
+
103
+ /**
104
+ * Prerequisite DAG for unlock/progression graphs.
105
+ *
106
+ * The graph is directed and acyclic by construction (caller contract — no runtime cycle
107
+ * detection). Nodes are string ids; edges are "requires" lists.
108
+ */
109
+ interface DagNode {
110
+ /** Unique string id for this node. */
111
+ readonly id: string;
112
+ /** Ids of nodes that must be in the cleared set before this node unlocks. */
113
+ readonly requires: readonly string[];
114
+ }
115
+ interface UnlockDag {
116
+ readonly nodes: ReadonlyMap<string, DagNode>;
117
+ /**
118
+ * Whether `id` is unlocked given the set of cleared (previously unlocked) ids.
119
+ * A node with no requirements is always unlocked.
120
+ * An unknown id returns false.
121
+ */
122
+ isUnlocked(cleared: ReadonlySet<string>, id: string): boolean;
123
+ /**
124
+ * The frontier: all nodes whose requirements are fully satisfied by `cleared`,
125
+ * but which are NOT yet in `cleared`. Returned as a sorted array (stable
126
+ * insertion order from `nodes`).
127
+ */
128
+ frontier(cleared: ReadonlySet<string>): readonly string[];
129
+ /**
130
+ * All nodes currently unlocked by `cleared` (including those already in
131
+ * `cleared`). Returned as a sorted array (stable insertion order).
132
+ */
133
+ allUnlocked(cleared: ReadonlySet<string>): readonly string[];
134
+ }
135
+ /**
136
+ * Creates an `UnlockDag` from `nodes`.
137
+ * Duplicate ids throw. Unknown `requires` ids are silently tolerated — a node
138
+ * whose prerequisite id doesn't exist in the graph is simply never satisfiable.
139
+ */
140
+ declare function createUnlockDag(nodes: readonly DagNode[]): UnlockDag;
141
+
142
+ /**
143
+ * Tier resolution: "highest threshold crossed by a running tally."
144
+ *
145
+ * The tally tiers are caller-defined (generic `T`) so the same resolver
146
+ * works for score brackets, XP thresholds, unlock gates, etc.
147
+ */
148
+ interface TierEntry<T> {
149
+ /** Minimum tally value (inclusive) required to reach this tier. */
150
+ readonly at: number;
151
+ /** The tier value associated with this threshold. */
152
+ readonly tier: T;
153
+ }
154
+ /**
155
+ * Returns the highest tier whose `at` threshold is met or exceeded by `tally`,
156
+ * or `null` when `tally` is below all thresholds.
157
+ *
158
+ * `entries` need not be sorted — the function scans all entries and returns the
159
+ * one with the largest `at` that satisfies `tally >= at`.
160
+ * Ties (identical `at`) are broken by iteration order (last entry wins).
161
+ */
162
+ declare function resolveTier<T>(entries: readonly TierEntry<T>[], tally: number): T | null;
163
+ /**
164
+ * Returns the index (0-based) of the highest satisfied tier entry,
165
+ * or -1 when `tally` is below all thresholds.
166
+ * Same tie-breaking rules as `resolveTier`.
167
+ */
168
+ declare function resolveTierIndex<T>(entries: readonly TierEntry<T>[], tally: number): number;
169
+
170
+ /**
171
+ * Collectible-unlock registry: immutable unlock-set + partition + capstone.
172
+ *
173
+ * The registry is generic over a string id type.
174
+ * All operations return new registry instances — no mutation.
175
+ */
176
+ interface CollectibleRegistry<K extends string> {
177
+ /** The complete set of collectible ids (excluding the capstone). */
178
+ readonly all: ReadonlySet<K>;
179
+ /** The capstone id, or null when no capstone is defined. */
180
+ readonly capstoneId: K | null;
181
+ /** Currently unlocked ids (a subset of `all`, plus capstone when triggered). */
182
+ readonly unlocked: ReadonlySet<K>;
183
+ /** True when every collectible in `all` is unlocked. */
184
+ readonly isComplete: boolean;
185
+ /**
186
+ * True when the capstone is in `unlocked`. Always false when `capstoneId`
187
+ * is null.
188
+ */
189
+ readonly isCapstone: boolean;
190
+ /**
191
+ * Returns a new registry with `id` added to `unlocked`. Idempotent.
192
+ * Automatically adds the capstone when `isComplete` transitions to true
193
+ * and a capstone is defined.
194
+ * Throws on unknown ids (not in `all` and not the capstoneId).
195
+ */
196
+ unlock(id: K): CollectibleRegistry<K>;
197
+ /**
198
+ * Partition the unlocked set into `{ have, missing }`.
199
+ * `have` = ids in `all` that are in `unlocked` (capstone excluded).
200
+ * `missing` = ids in `all` not yet unlocked.
201
+ */
202
+ partition(): {
203
+ have: readonly K[];
204
+ missing: readonly K[];
205
+ };
206
+ /**
207
+ * Returns all ids in `all` in insertion order.
208
+ */
209
+ list(): readonly K[];
210
+ }
211
+ /**
212
+ * Creates a `CollectibleRegistry` from `ids` (the collectible set) and an
213
+ * optional `capstoneId`.
214
+ *
215
+ * Duplicate ids in `ids` throw. `capstoneId` may equal one of the ids in `ids`
216
+ * (it is tracked as a separate gate — the capstone fires only on full completion,
217
+ * not by direct unlock through `ids` membership alone).
218
+ *
219
+ * The capstone MUST be distinct from all ids in `ids` — if not, the capstone
220
+ * unlock auto-fires on full completion regardless of whether the capstone id
221
+ * was directly unlocked via the `ids` set, which would be semantically ambiguous.
222
+ */
223
+ declare function createCollectibleRegistry<K extends string>(ids: readonly K[], capstoneId?: K): CollectibleRegistry<K>;
224
+
225
+ 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 };
package/dist/index.js ADDED
@@ -0,0 +1,239 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ createCollectibleRegistry: () => createCollectibleRegistry,
24
+ createDropTable: () => createDropTable,
25
+ createUnlockDag: () => createUnlockDag,
26
+ createUpgradeTrack: () => createUpgradeTrack,
27
+ resolveTier: () => resolveTier,
28
+ resolveTierIndex: () => resolveTierIndex,
29
+ rollDrop: () => rollDrop
30
+ });
31
+ module.exports = __toCommonJS(index_exports);
32
+
33
+ // src/upgrade-track.ts
34
+ function createUpgradeTrack(config) {
35
+ function price(currentLevel) {
36
+ if (currentLevel >= config.cap) return Number.POSITIVE_INFINITY;
37
+ return Math.round(config.base * config.growth ** currentLevel);
38
+ }
39
+ function canBuy(wallet, currentLevel) {
40
+ if (currentLevel >= config.cap) return false;
41
+ return wallet >= price(currentLevel);
42
+ }
43
+ function buy(wallet, currentLevel) {
44
+ if (!canBuy(wallet, currentLevel)) {
45
+ return { ok: false, wallet, level: currentLevel };
46
+ }
47
+ return { ok: true, wallet: wallet - price(currentLevel), level: currentLevel + 1 };
48
+ }
49
+ function resolveStats(base, deltas, getLevel) {
50
+ const out = {};
51
+ for (const key of Object.keys(base)) {
52
+ const level = Math.max(0, Math.floor(getLevel(key)));
53
+ out[key] = (base[key] ?? 0) + (deltas[key] ?? 0) * level;
54
+ }
55
+ return out;
56
+ }
57
+ return { config, price, canBuy, buy, resolveStats };
58
+ }
59
+
60
+ // src/drop-roll.ts
61
+ var import_math = require("@flare-engine/math");
62
+ function createDropTable(entries) {
63
+ var currentIsAllowed = () => true;
64
+ const weightAt = (entry) => currentIsAllowed(entry.item) ? entry.weight : 0;
65
+ const dryPrev = new Float32Array(entries.length);
66
+ function rollInto(rollTable01, rollChance01, chancePerRoll, pity, thresholds, isAllowed, out) {
67
+ let picked = "none";
68
+ for (let i = 0; i < entries.length; i++) {
69
+ dryPrev[i] = pity[entries[i].item] ?? 0;
70
+ }
71
+ for (let i = 0; i < entries.length; i++) {
72
+ const e = entries[i];
73
+ const threshold = thresholds[e.item];
74
+ if (threshold !== void 0 && isAllowed(e.item) && dryPrev[i] + 1 >= threshold) {
75
+ picked = e.item;
76
+ break;
77
+ }
78
+ }
79
+ if (picked === "none") {
80
+ if (rollChance01 < chancePerRoll) {
81
+ currentIsAllowed = isAllowed;
82
+ let allowedTotal = 0;
83
+ for (let i = 0; i < entries.length; i++) {
84
+ allowedTotal += weightAt(entries[i]);
85
+ }
86
+ if (allowedTotal > 0) {
87
+ const idx = (0, import_math.weightedIndexBy)(entries, weightAt, rollTable01);
88
+ const entry = entries[idx];
89
+ if (entry !== void 0) picked = entry.item;
90
+ }
91
+ }
92
+ }
93
+ out.item = picked;
94
+ for (let i = 0; i < entries.length; i++) {
95
+ const e = entries[i];
96
+ out.pity[e.item] = picked === e.item ? 0 : dryPrev[i] + 1;
97
+ }
98
+ }
99
+ return { entries, rollInto };
100
+ }
101
+ function rollDrop(table, rollTable01, rollChance01, chancePerRoll, pity, thresholds, isAllowed) {
102
+ const out = { item: "none", pity: { ...pity } };
103
+ table.rollInto(
104
+ rollTable01,
105
+ rollChance01,
106
+ chancePerRoll,
107
+ pity,
108
+ thresholds,
109
+ isAllowed ?? (() => true),
110
+ out
111
+ );
112
+ return out;
113
+ }
114
+
115
+ // src/unlock-dag.ts
116
+ function createUnlockDag(nodes) {
117
+ const map = /* @__PURE__ */ new Map();
118
+ for (const node of nodes) {
119
+ if (map.has(node.id)) {
120
+ throw new Error(`createUnlockDag: duplicate node id "${node.id}"`);
121
+ }
122
+ map.set(node.id, node);
123
+ }
124
+ function isUnlocked(cleared, id) {
125
+ const node = map.get(id);
126
+ if (!node) return false;
127
+ for (const req of node.requires) {
128
+ if (!cleared.has(req)) return false;
129
+ }
130
+ return true;
131
+ }
132
+ function frontier(cleared) {
133
+ const out = [];
134
+ for (const [id] of map) {
135
+ if (!cleared.has(id) && isUnlocked(cleared, id)) {
136
+ out.push(id);
137
+ }
138
+ }
139
+ return out;
140
+ }
141
+ function allUnlocked(cleared) {
142
+ const out = [];
143
+ for (const [id] of map) {
144
+ if (isUnlocked(cleared, id)) {
145
+ out.push(id);
146
+ }
147
+ }
148
+ return out;
149
+ }
150
+ return { nodes: map, isUnlocked, frontier, allUnlocked };
151
+ }
152
+
153
+ // src/tier-resolve.ts
154
+ function resolveTier(entries, tally) {
155
+ let best = null;
156
+ let bestAt = Number.NEGATIVE_INFINITY;
157
+ for (const e of entries) {
158
+ if (tally >= e.at && e.at >= bestAt) {
159
+ best = e.tier;
160
+ bestAt = e.at;
161
+ }
162
+ }
163
+ return best;
164
+ }
165
+ function resolveTierIndex(entries, tally) {
166
+ let bestIdx = -1;
167
+ let bestAt = Number.NEGATIVE_INFINITY;
168
+ for (let i = 0; i < entries.length; i++) {
169
+ const e = entries[i];
170
+ if (e !== void 0 && tally >= e.at && e.at >= bestAt) {
171
+ bestIdx = i;
172
+ bestAt = e.at;
173
+ }
174
+ }
175
+ return bestIdx;
176
+ }
177
+
178
+ // src/collectible-registry.ts
179
+ function makeRegistry(all, capstoneId, unlocked) {
180
+ const isComplete = [...all].every((id) => unlocked.has(id));
181
+ const isCapstone = capstoneId !== null && unlocked.has(capstoneId);
182
+ function unlock(id) {
183
+ if (!all.has(id) && id !== capstoneId) {
184
+ throw new Error(`CollectibleRegistry: unknown id "${String(id)}"`);
185
+ }
186
+ if (unlocked.has(id)) return reg;
187
+ const next = new Set(unlocked);
188
+ next.add(id);
189
+ if (capstoneId !== null && !next.has(capstoneId)) {
190
+ const allComplete = [...all].every((k) => next.has(k));
191
+ if (allComplete) next.add(capstoneId);
192
+ }
193
+ return makeRegistry(all, capstoneId, next);
194
+ }
195
+ function partition() {
196
+ const have = [];
197
+ const missing = [];
198
+ for (const id of all) {
199
+ if (unlocked.has(id)) have.push(id);
200
+ else missing.push(id);
201
+ }
202
+ return { have, missing };
203
+ }
204
+ function list() {
205
+ return [...all];
206
+ }
207
+ const reg = {
208
+ all,
209
+ capstoneId,
210
+ unlocked,
211
+ isComplete,
212
+ isCapstone,
213
+ unlock,
214
+ partition,
215
+ list
216
+ };
217
+ return reg;
218
+ }
219
+ function createCollectibleRegistry(ids, capstoneId) {
220
+ const all = /* @__PURE__ */ new Set();
221
+ for (const id of ids) {
222
+ if (all.has(id)) {
223
+ throw new Error(`createCollectibleRegistry: duplicate id "${String(id)}"`);
224
+ }
225
+ all.add(id);
226
+ }
227
+ return makeRegistry(all, capstoneId ?? null, /* @__PURE__ */ new Set());
228
+ }
229
+ // Annotate the CommonJS export names for ESM import in node:
230
+ 0 && (module.exports = {
231
+ createCollectibleRegistry,
232
+ createDropTable,
233
+ createUnlockDag,
234
+ createUpgradeTrack,
235
+ resolveTier,
236
+ resolveTierIndex,
237
+ rollDrop
238
+ });
239
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/upgrade-track.ts","../src/drop-roll.ts","../src/unlock-dag.ts","../src/tier-resolve.ts","../src/collectible-registry.ts"],"sourcesContent":["export {\n type UpgradeTrackConfig,\n type UpgradeBuyResult,\n type UpgradeTrack,\n createUpgradeTrack,\n} from './upgrade-track.js';\n\nexport {\n type DropEntry,\n type DropPity,\n type DropRollOut,\n type DropTable,\n createDropTable,\n rollDrop,\n} from './drop-roll.js';\n\nexport {\n type DagNode,\n type UnlockDag,\n createUnlockDag,\n} from './unlock-dag.js';\n\nexport {\n type TierEntry,\n resolveTier,\n resolveTierIndex,\n} from './tier-resolve.js';\n\nexport {\n type CollectibleRegistry,\n createCollectibleRegistry,\n} from './collectible-registry.js';\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","/**\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 // biome-ignore lint/style/noVar: intentional closure var for zero-alloc hot path\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 * 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 * 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 * 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"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACqDO,SAAS,mBAAmB,QAA0C;AAC3E,WAAS,MAAM,cAA8B;AAC3C,QAAI,gBAAgB,OAAO,IAAK,QAAO,OAAO;AAC9C,WAAO,KAAK,MAAM,OAAO,OAAO,OAAO,UAAU,YAAY;AAAA,EAC/D;AAEA,WAAS,OAAO,QAAgB,cAA+B;AAC7D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;AAC9D;","names":[]}
package/dist/index.mjs ADDED
@@ -0,0 +1,206 @@
1
+ // src/upgrade-track.ts
2
+ function createUpgradeTrack(config) {
3
+ function price(currentLevel) {
4
+ if (currentLevel >= config.cap) return Number.POSITIVE_INFINITY;
5
+ return Math.round(config.base * config.growth ** currentLevel);
6
+ }
7
+ function canBuy(wallet, currentLevel) {
8
+ if (currentLevel >= config.cap) return false;
9
+ return wallet >= price(currentLevel);
10
+ }
11
+ function buy(wallet, currentLevel) {
12
+ if (!canBuy(wallet, currentLevel)) {
13
+ return { ok: false, wallet, level: currentLevel };
14
+ }
15
+ return { ok: true, wallet: wallet - price(currentLevel), level: currentLevel + 1 };
16
+ }
17
+ function resolveStats(base, deltas, getLevel) {
18
+ const out = {};
19
+ for (const key of Object.keys(base)) {
20
+ const level = Math.max(0, Math.floor(getLevel(key)));
21
+ out[key] = (base[key] ?? 0) + (deltas[key] ?? 0) * level;
22
+ }
23
+ return out;
24
+ }
25
+ return { config, price, canBuy, buy, resolveStats };
26
+ }
27
+
28
+ // src/drop-roll.ts
29
+ import { weightedIndexBy } from "@flare-engine/math";
30
+ function createDropTable(entries) {
31
+ var currentIsAllowed = () => true;
32
+ const weightAt = (entry) => currentIsAllowed(entry.item) ? entry.weight : 0;
33
+ const dryPrev = new Float32Array(entries.length);
34
+ function rollInto(rollTable01, rollChance01, chancePerRoll, pity, thresholds, isAllowed, out) {
35
+ let picked = "none";
36
+ for (let i = 0; i < entries.length; i++) {
37
+ dryPrev[i] = pity[entries[i].item] ?? 0;
38
+ }
39
+ for (let i = 0; i < entries.length; i++) {
40
+ const e = entries[i];
41
+ const threshold = thresholds[e.item];
42
+ if (threshold !== void 0 && isAllowed(e.item) && dryPrev[i] + 1 >= threshold) {
43
+ picked = e.item;
44
+ break;
45
+ }
46
+ }
47
+ if (picked === "none") {
48
+ if (rollChance01 < chancePerRoll) {
49
+ currentIsAllowed = isAllowed;
50
+ let allowedTotal = 0;
51
+ for (let i = 0; i < entries.length; i++) {
52
+ allowedTotal += weightAt(entries[i]);
53
+ }
54
+ if (allowedTotal > 0) {
55
+ const idx = weightedIndexBy(entries, weightAt, rollTable01);
56
+ const entry = entries[idx];
57
+ if (entry !== void 0) picked = entry.item;
58
+ }
59
+ }
60
+ }
61
+ out.item = picked;
62
+ for (let i = 0; i < entries.length; i++) {
63
+ const e = entries[i];
64
+ out.pity[e.item] = picked === e.item ? 0 : dryPrev[i] + 1;
65
+ }
66
+ }
67
+ return { entries, rollInto };
68
+ }
69
+ function rollDrop(table, rollTable01, rollChance01, chancePerRoll, pity, thresholds, isAllowed) {
70
+ const out = { item: "none", pity: { ...pity } };
71
+ table.rollInto(
72
+ rollTable01,
73
+ rollChance01,
74
+ chancePerRoll,
75
+ pity,
76
+ thresholds,
77
+ isAllowed ?? (() => true),
78
+ out
79
+ );
80
+ return out;
81
+ }
82
+
83
+ // src/unlock-dag.ts
84
+ function createUnlockDag(nodes) {
85
+ const map = /* @__PURE__ */ new Map();
86
+ for (const node of nodes) {
87
+ if (map.has(node.id)) {
88
+ throw new Error(`createUnlockDag: duplicate node id "${node.id}"`);
89
+ }
90
+ map.set(node.id, node);
91
+ }
92
+ function isUnlocked(cleared, id) {
93
+ const node = map.get(id);
94
+ if (!node) return false;
95
+ for (const req of node.requires) {
96
+ if (!cleared.has(req)) return false;
97
+ }
98
+ return true;
99
+ }
100
+ function frontier(cleared) {
101
+ const out = [];
102
+ for (const [id] of map) {
103
+ if (!cleared.has(id) && isUnlocked(cleared, id)) {
104
+ out.push(id);
105
+ }
106
+ }
107
+ return out;
108
+ }
109
+ function allUnlocked(cleared) {
110
+ const out = [];
111
+ for (const [id] of map) {
112
+ if (isUnlocked(cleared, id)) {
113
+ out.push(id);
114
+ }
115
+ }
116
+ return out;
117
+ }
118
+ return { nodes: map, isUnlocked, frontier, allUnlocked };
119
+ }
120
+
121
+ // src/tier-resolve.ts
122
+ function resolveTier(entries, tally) {
123
+ let best = null;
124
+ let bestAt = Number.NEGATIVE_INFINITY;
125
+ for (const e of entries) {
126
+ if (tally >= e.at && e.at >= bestAt) {
127
+ best = e.tier;
128
+ bestAt = e.at;
129
+ }
130
+ }
131
+ return best;
132
+ }
133
+ function resolveTierIndex(entries, tally) {
134
+ let bestIdx = -1;
135
+ let bestAt = Number.NEGATIVE_INFINITY;
136
+ for (let i = 0; i < entries.length; i++) {
137
+ const e = entries[i];
138
+ if (e !== void 0 && tally >= e.at && e.at >= bestAt) {
139
+ bestIdx = i;
140
+ bestAt = e.at;
141
+ }
142
+ }
143
+ return bestIdx;
144
+ }
145
+
146
+ // src/collectible-registry.ts
147
+ function makeRegistry(all, capstoneId, unlocked) {
148
+ const isComplete = [...all].every((id) => unlocked.has(id));
149
+ const isCapstone = capstoneId !== null && unlocked.has(capstoneId);
150
+ function unlock(id) {
151
+ if (!all.has(id) && id !== capstoneId) {
152
+ throw new Error(`CollectibleRegistry: unknown id "${String(id)}"`);
153
+ }
154
+ if (unlocked.has(id)) return reg;
155
+ const next = new Set(unlocked);
156
+ next.add(id);
157
+ if (capstoneId !== null && !next.has(capstoneId)) {
158
+ const allComplete = [...all].every((k) => next.has(k));
159
+ if (allComplete) next.add(capstoneId);
160
+ }
161
+ return makeRegistry(all, capstoneId, next);
162
+ }
163
+ function partition() {
164
+ const have = [];
165
+ const missing = [];
166
+ for (const id of all) {
167
+ if (unlocked.has(id)) have.push(id);
168
+ else missing.push(id);
169
+ }
170
+ return { have, missing };
171
+ }
172
+ function list() {
173
+ return [...all];
174
+ }
175
+ const reg = {
176
+ all,
177
+ capstoneId,
178
+ unlocked,
179
+ isComplete,
180
+ isCapstone,
181
+ unlock,
182
+ partition,
183
+ list
184
+ };
185
+ return reg;
186
+ }
187
+ function createCollectibleRegistry(ids, capstoneId) {
188
+ const all = /* @__PURE__ */ new Set();
189
+ for (const id of ids) {
190
+ if (all.has(id)) {
191
+ throw new Error(`createCollectibleRegistry: duplicate id "${String(id)}"`);
192
+ }
193
+ all.add(id);
194
+ }
195
+ return makeRegistry(all, capstoneId ?? null, /* @__PURE__ */ new Set());
196
+ }
197
+ export {
198
+ createCollectibleRegistry,
199
+ createDropTable,
200
+ createUnlockDag,
201
+ createUpgradeTrack,
202
+ resolveTier,
203
+ resolveTierIndex,
204
+ rollDrop
205
+ };
206
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/upgrade-track.ts","../src/drop-roll.ts","../src/unlock-dag.ts","../src/tier-resolve.ts","../src/collectible-registry.ts"],"sourcesContent":["/**\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","/**\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 // biome-ignore lint/style/noVar: intentional closure var for zero-alloc hot path\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 * 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 * 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 * 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"],"mappings":";AAqDO,SAAS,mBAAmB,QAA0C;AAC3E,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I,IAAI,EAAE,GAAG;AACf,YAAM,IAAI,MAAM,4CAA4C,OAAO,EAAE,CAAC,GAAG;AAAA,IAC3E;AACA,QAAI,IAAI,EAAE;AAAA,EACZ;AACA,SAAO,aAAgB,KAAK,cAAc,MAAM,oBAAI,IAAO,CAAC;AAC9D;","names":[]}
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@flare-engine/progression",
3
+ "version": "0.2.0",
4
+ "description": "Meta-progression primitives: upgrade tracks, drop-roll with pity, unlock DAG, tier resolution, collectible registry",
5
+ "keywords": ["flare-engine", "progression", "upgrade", "drop", "unlock", "tier"],
6
+ "license": "MIT",
7
+ "author": "Grzegorz Otto",
8
+ "homepage": "https://github.com/grzott/flare-engine#readme",
9
+ "bugs": {
10
+ "url": "https://github.com/grzott/flare-engine/issues"
11
+ },
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git+https://github.com/grzott/flare-engine.git",
15
+ "directory": "packages/progression"
16
+ },
17
+ "main": "dist/index.js",
18
+ "module": "dist/index.mjs",
19
+ "types": "dist/index.d.ts",
20
+ "exports": {
21
+ ".": {
22
+ "types": "./dist/index.d.ts",
23
+ "import": "./dist/index.mjs",
24
+ "require": "./dist/index.js"
25
+ }
26
+ },
27
+ "files": ["dist", "README.md", "LICENSE"],
28
+ "scripts": {
29
+ "build": "tsup",
30
+ "test": "bun test",
31
+ "lint": "biome check src/",
32
+ "typecheck": "tsc --noEmit"
33
+ },
34
+ "publishConfig": {
35
+ "access": "restricted",
36
+ "registry": "https://registry.npmjs.org/"
37
+ },
38
+ "sideEffects": false,
39
+ "dependencies": {
40
+ "@flare-engine/math": "^0.2.0"
41
+ }
42
+ }