@flare-engine/progression 0.2.1 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -21
- package/NOTICE +2 -0
- package/README.md +2 -2
- package/dist/index.d.mts +160 -154
- package/dist/index.d.mts.map +1 -0
- package/dist/index.d.ts +160 -154
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +240 -227
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +233 -194
- package/dist/index.mjs.map +1 -1
- package/package.json +16 -8
package/dist/index.d.ts
CHANGED
|
@@ -1,50 +1,60 @@
|
|
|
1
|
+
//#region src/collectible-registry.d.ts
|
|
1
2
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
3
|
+
* Collectible-unlock registry: immutable unlock-set + partition + capstone.
|
|
4
|
+
*
|
|
5
|
+
* The registry is generic over a string id type.
|
|
6
|
+
* All operations return new registry instances — no mutation.
|
|
5
7
|
*/
|
|
6
|
-
interface
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
resolveStats<K extends string>(base: Record<K, number>, deltas: Record<K, number>, getLevel: (key: K) => number): Record<K, number>;
|
|
8
|
+
interface CollectibleRegistry<K extends string> {
|
|
9
|
+
/** The complete set of collectible ids (excluding the capstone). */
|
|
10
|
+
readonly all: ReadonlySet<K>;
|
|
11
|
+
/** The capstone id, or null when no capstone is defined. */
|
|
12
|
+
readonly capstoneId: K | null;
|
|
13
|
+
/** Currently unlocked ids (a subset of `all`, plus capstone when triggered). */
|
|
14
|
+
readonly unlocked: ReadonlySet<K>;
|
|
15
|
+
/** True when every collectible in `all` is unlocked. */
|
|
16
|
+
readonly isComplete: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* True when the capstone is in `unlocked`. Always false when `capstoneId`
|
|
19
|
+
* is null.
|
|
20
|
+
*/
|
|
21
|
+
readonly isCapstone: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Returns a new registry with `id` added to `unlocked`. Idempotent.
|
|
24
|
+
* Automatically adds the capstone when `isComplete` transitions to true
|
|
25
|
+
* and a capstone is defined.
|
|
26
|
+
* Throws on unknown ids (not in `all` and not the capstoneId).
|
|
27
|
+
*/
|
|
28
|
+
unlock(id: K): CollectibleRegistry<K>;
|
|
29
|
+
/**
|
|
30
|
+
* Partition the unlocked set into `{ have, missing }`.
|
|
31
|
+
* `have` = ids in `all` that are in `unlocked` (capstone excluded).
|
|
32
|
+
* `missing` = ids in `all` not yet unlocked.
|
|
33
|
+
*/
|
|
34
|
+
partition(): {
|
|
35
|
+
have: readonly K[];
|
|
36
|
+
missing: readonly K[];
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Returns all ids in `all` in insertion order.
|
|
40
|
+
*/
|
|
41
|
+
list(): readonly K[];
|
|
41
42
|
}
|
|
42
43
|
/**
|
|
43
|
-
*
|
|
44
|
-
*
|
|
44
|
+
* Creates a `CollectibleRegistry` from `ids` (the collectible set) and an
|
|
45
|
+
* optional `capstoneId`.
|
|
46
|
+
*
|
|
47
|
+
* Duplicate ids in `ids` throw. `capstoneId` may equal one of the ids in `ids`
|
|
48
|
+
* (it is tracked as a separate gate — the capstone fires only on full completion,
|
|
49
|
+
* not by direct unlock through `ids` membership alone).
|
|
50
|
+
*
|
|
51
|
+
* The capstone MUST be distinct from all ids in `ids` — if not, the capstone
|
|
52
|
+
* unlock auto-fires on full completion regardless of whether the capstone id
|
|
53
|
+
* was directly unlocked via the `ids` set, which would be semantically ambiguous.
|
|
45
54
|
*/
|
|
46
|
-
declare function
|
|
47
|
-
|
|
55
|
+
declare function createCollectibleRegistry<K extends string>(ids: readonly K[], capstoneId?: K): CollectibleRegistry<K>;
|
|
56
|
+
//#endregion
|
|
57
|
+
//#region src/drop-roll.d.ts
|
|
48
58
|
/**
|
|
49
59
|
* Pity-aware weighted drop roller.
|
|
50
60
|
*
|
|
@@ -56,8 +66,8 @@ declare function createUpgradeTrack(config: UpgradeTrackConfig): UpgradeTrack;
|
|
|
56
66
|
* fields.
|
|
57
67
|
*/
|
|
58
68
|
interface DropEntry<K extends string> {
|
|
59
|
-
|
|
60
|
-
|
|
69
|
+
readonly item: K;
|
|
70
|
+
readonly weight: number;
|
|
61
71
|
}
|
|
62
72
|
/**
|
|
63
73
|
* Per-item dry-roll counters feeding the pity guarantees.
|
|
@@ -65,28 +75,28 @@ interface DropEntry<K extends string> {
|
|
|
65
75
|
*/
|
|
66
76
|
type DropPity<K extends string> = Record<K, number>;
|
|
67
77
|
interface DropRollOut<K extends string> {
|
|
68
|
-
|
|
69
|
-
|
|
78
|
+
item: K | 'none';
|
|
79
|
+
pity: DropPity<K>;
|
|
70
80
|
}
|
|
71
81
|
/**
|
|
72
82
|
* A `DropTable` is a factory that closes over a weight accessor to avoid
|
|
73
83
|
* per-call allocations. Create once; reuse across frames.
|
|
74
84
|
*/
|
|
75
85
|
interface DropTable<K extends string> {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
86
|
+
readonly entries: readonly DropEntry<K>[];
|
|
87
|
+
/**
|
|
88
|
+
* Zero-alloc weighted drop. Writes result into `out`.
|
|
89
|
+
*
|
|
90
|
+
* Algorithm:
|
|
91
|
+
* 1. Check pity thresholds (first matching pity item fires unconditionally).
|
|
92
|
+
* 2. If no pity fires and `rollChance01 >= chancePerRoll`, result = 'none'.
|
|
93
|
+
* 3. Otherwise pick from the weighted table filtered by `isAllowed`.
|
|
94
|
+
* An all-gated pool (every entry filtered out) fizzles to 'none'.
|
|
95
|
+
*
|
|
96
|
+
* `out.pity` counters reset for the dropped item, advance by 1 for all others.
|
|
97
|
+
* Aliasing `out.pity` against the input `pity` is safe.
|
|
98
|
+
*/
|
|
99
|
+
rollInto(rollTable01: number, rollChance01: number, chancePerRoll: number, pity: DropPity<K>, thresholds: Partial<Record<K, number>>, isAllowed: (item: K) => boolean, out: DropRollOut<K>): void;
|
|
90
100
|
}
|
|
91
101
|
/**
|
|
92
102
|
* Creates a `DropTable` from `entries`.
|
|
@@ -99,46 +109,8 @@ declare function createDropTable<K extends string>(entries: readonly DropEntry<K
|
|
|
99
109
|
* Use `table.rollInto` on the hot path; this is for tests and cold-path setup.
|
|
100
110
|
*/
|
|
101
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>;
|
|
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
|
-
|
|
112
|
+
//#endregion
|
|
113
|
+
//#region src/tier-resolve.d.ts
|
|
142
114
|
/**
|
|
143
115
|
* Tier resolution: "highest threshold crossed by a running tally."
|
|
144
116
|
*
|
|
@@ -146,10 +118,10 @@ declare function createUnlockDag(nodes: readonly DagNode[]): UnlockDag;
|
|
|
146
118
|
* works for score brackets, XP thresholds, unlock gates, etc.
|
|
147
119
|
*/
|
|
148
120
|
interface TierEntry<T> {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
121
|
+
/** Minimum tally value (inclusive) required to reach this tier. */
|
|
122
|
+
readonly at: number;
|
|
123
|
+
/** The tier value associated with this threshold. */
|
|
124
|
+
readonly tier: T;
|
|
153
125
|
}
|
|
154
126
|
/**
|
|
155
127
|
* Returns the highest tier whose `at` threshold is met or exceeded by `tally`,
|
|
@@ -166,60 +138,94 @@ declare function resolveTier<T>(entries: readonly TierEntry<T>[], tally: number)
|
|
|
166
138
|
* Same tie-breaking rules as `resolveTier`.
|
|
167
139
|
*/
|
|
168
140
|
declare function resolveTierIndex<T>(entries: readonly TierEntry<T>[], tally: number): number;
|
|
169
|
-
|
|
141
|
+
//#endregion
|
|
142
|
+
//#region src/unlock-dag.d.ts
|
|
170
143
|
/**
|
|
171
|
-
*
|
|
144
|
+
* Prerequisite DAG for unlock/progression graphs.
|
|
172
145
|
*
|
|
173
|
-
* The
|
|
174
|
-
*
|
|
146
|
+
* The graph is directed and acyclic by construction (caller contract — no runtime cycle
|
|
147
|
+
* detection). Nodes are string ids; edges are "requires" lists.
|
|
175
148
|
*/
|
|
176
|
-
interface
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
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[];
|
|
149
|
+
interface DagNode {
|
|
150
|
+
/** Unique string id for this node. */
|
|
151
|
+
readonly id: string;
|
|
152
|
+
/** Ids of nodes that must be in the cleared set before this node unlocks. */
|
|
153
|
+
readonly requires: readonly string[];
|
|
154
|
+
}
|
|
155
|
+
interface UnlockDag {
|
|
156
|
+
readonly nodes: ReadonlyMap<string, DagNode>;
|
|
157
|
+
/**
|
|
158
|
+
* Whether `id` is unlocked given the set of cleared (previously unlocked) ids.
|
|
159
|
+
* A node with no requirements is always unlocked.
|
|
160
|
+
* An unknown id returns false.
|
|
161
|
+
*/
|
|
162
|
+
isUnlocked(cleared: ReadonlySet<string>, id: string): boolean;
|
|
163
|
+
/**
|
|
164
|
+
* The frontier: all nodes whose requirements are fully satisfied by `cleared`,
|
|
165
|
+
* but which are NOT yet in `cleared`. Returned as a sorted array (stable
|
|
166
|
+
* insertion order from `nodes`).
|
|
167
|
+
*/
|
|
168
|
+
frontier(cleared: ReadonlySet<string>): readonly string[];
|
|
169
|
+
/**
|
|
170
|
+
* All nodes currently unlocked by `cleared` (including those already in
|
|
171
|
+
* `cleared`). Returned as a sorted array (stable insertion order).
|
|
172
|
+
*/
|
|
173
|
+
allUnlocked(cleared: ReadonlySet<string>): readonly string[];
|
|
210
174
|
}
|
|
211
175
|
/**
|
|
212
|
-
* Creates
|
|
213
|
-
*
|
|
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.
|
|
176
|
+
* Creates an `UnlockDag` from `nodes`.
|
|
177
|
+
* Duplicate ids throw. Unknown `requires` ids are silently tolerated — a node
|
|
178
|
+
* whose prerequisite id doesn't exist in the graph is simply never satisfiable.
|
|
222
179
|
*/
|
|
223
|
-
declare function
|
|
224
|
-
|
|
180
|
+
declare function createUnlockDag(nodes: readonly DagNode[]): UnlockDag;
|
|
181
|
+
//#endregion
|
|
182
|
+
//#region src/upgrade-track.d.ts
|
|
183
|
+
/**
|
|
184
|
+
* Geometric upgrade track with an immutable buy operation.
|
|
185
|
+
* price(level) = round(base × growth^level) — the next-level cost from `level`.
|
|
186
|
+
* Consolidates the common geometric-cost upgrade pattern.
|
|
187
|
+
*/
|
|
188
|
+
interface UpgradeTrackConfig {
|
|
189
|
+
/** Base price at level 0 → 1. */
|
|
190
|
+
readonly base: number;
|
|
191
|
+
/** Multiplicative growth factor per level. */
|
|
192
|
+
readonly growth: number;
|
|
193
|
+
/** Hard level cap (inclusive). */
|
|
194
|
+
readonly cap: number;
|
|
195
|
+
}
|
|
196
|
+
interface UpgradeBuyResult {
|
|
197
|
+
readonly ok: boolean;
|
|
198
|
+
readonly wallet: number;
|
|
199
|
+
readonly level: number;
|
|
200
|
+
}
|
|
201
|
+
interface UpgradeTrack {
|
|
202
|
+
readonly config: UpgradeTrackConfig;
|
|
203
|
+
/**
|
|
204
|
+
* Cost to advance from `currentLevel` to `currentLevel + 1`.
|
|
205
|
+
* Returns Infinity when at or above cap.
|
|
206
|
+
*/
|
|
207
|
+
price(currentLevel: number): number;
|
|
208
|
+
/** Whether `wallet` is sufficient and `currentLevel` is below cap. */
|
|
209
|
+
canBuy(wallet: number, currentLevel: number): boolean;
|
|
210
|
+
/**
|
|
211
|
+
* Pure spend: deduct `price(currentLevel)` from `wallet` and return
|
|
212
|
+
* the new state. Returns `{ ok: false, wallet, level }` when blocked.
|
|
213
|
+
*/
|
|
214
|
+
buy(wallet: number, currentLevel: number): UpgradeBuyResult;
|
|
215
|
+
/**
|
|
216
|
+
* Fold all per-level stat deltas into a running accumulator.
|
|
217
|
+
* `getLevel` is a caller-supplied reader so the resolver is unit-testable
|
|
218
|
+
* without any save/store dep. `deltas` maps a stat key to the per-level delta;
|
|
219
|
+
* `base` is the starting value for each key.
|
|
220
|
+
* Returns a plain Record with the accumulated values.
|
|
221
|
+
*/
|
|
222
|
+
resolveStats<K extends string>(base: Record<K, number>, deltas: Record<K, number>, getLevel: (key: K) => number): Record<K, number>;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Returns an `UpgradeTrack` backed by `config`.
|
|
226
|
+
* The returned object is a plain object (no class) — safe to freeze or copy.
|
|
227
|
+
*/
|
|
228
|
+
declare function createUpgradeTrack(config: UpgradeTrackConfig): UpgradeTrack;
|
|
229
|
+
//#endregion
|
|
225
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 };
|
|
231
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +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":";;;;;;;UAOiB,oBAAoB;;WAE1B,KAAK,YAAY;;WAEjB,YAAY;;WAEZ,UAAU,YAAY;;WAEtB;;;;;WAKA;;;;;;;EAOT,OAAO,IAAI,IAAI,oBAAoB;;;;;;EAMnC;IAAe,eAAe;IAAK,kBAAkB;;;;;EAIrD,iBAAiB;;;;;;;;;;;;;;iBAiEH,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;;;;;;;iBASL,gBAAgB,kBAAkB,kBAAkB,UAAU,OAAO,UAAU;;;;;iBAuE/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;;;;;;;;;;iBAWD,YAAY,GAAG,kBAAkB,UAAU,MAAM,gBAAgB;;;;;;iBAiBjE,iBAAiB,GAAG,kBAAkB,UAAU,MAAM;;;;;;;;;UChCrD;;WAEN;;WAEA;;UAGM;WACN,OAAO,oBAAoB;;;;;;EAMpC,WAAW,SAAS,qBAAqB;;;;;;EAMzC,SAAS,SAAS;;;;;EAKlB,YAAY,SAAS;;;;;;;iBAQP,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;;;;;;iBAOI,mBAAmB,QAAQ,qBAAqB"}
|