tiny-essentials 1.21.0 โ†’ 1.21.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.
@@ -0,0 +1,226 @@
1
+ # ๐Ÿ› ๏ธ TinyNeedBar Documentation
2
+
3
+ `TinyNeedBar` is a utility class for simulating a **"need bar" system**.
4
+ It allows tracking of values that decrease over time, with configurable decay factors.
5
+
6
+ ---
7
+
8
+ ## ๐Ÿ“ฆ Types
9
+
10
+ ### `TickResult` ๐Ÿ”„
11
+
12
+ Represents the result of one tick of decay.
13
+
14
+ | Property | Type | Description |
15
+ | ------------------- | -------- | ----------------------------------------- |
16
+ | `prevValue` | `number` | Infinite value before applying decay. |
17
+ | `removedTotal` | `number` | Total amount removed this tick. |
18
+ | `removedPercent` | `number` | Percentage of max removed this tick. |
19
+ | `currentPercent` | `number` | Current percentage relative to max. |
20
+ | `remainingValue` | `number` | Current clamped value (โ‰ฅ 0). |
21
+ | `infiniteRemaining` | `number` | Current infinite value (can be negative). |
22
+
23
+ ---
24
+
25
+ ### `BarFactor` โšก
26
+
27
+ Represents a decay factor applied to the need bar.
28
+
29
+ | Property | Type | Description |
30
+ | ------------ | -------- | --------------------------------- |
31
+ | `amount` | `number` | Base reduction value per tick. |
32
+ | `multiplier` | `number` | Multiplier applied to the amount. |
33
+
34
+ ---
35
+
36
+ ### `SerializedData` ๐Ÿ’พ
37
+
38
+ Represents the serialized state of a `TinyNeedBar` instance.
39
+ Can be used to export/import or clone bars.
40
+
41
+ | Property | Type | Description |
42
+ | --------------- | --------------------------- | ------------------------------------------- |
43
+ | `maxValue` | `number` | Maximum value of the bar at serialization. |
44
+ | `currentValue` | `number` | Current clamped value (โ‰ฅ 0). |
45
+ | `infiniteValue` | `number` | Infinite value (can be negative). |
46
+ | `factors` | `Record<string, BarFactor>` | Active decay factors indexed by their keys. |
47
+
48
+ ---
49
+
50
+ ## ๐Ÿ—๏ธ Class: `TinyNeedBar`
51
+
52
+ ### Overview
53
+
54
+ * The bar decreases over time according to **defined factors**.
55
+ * Each factor has an `amount` and a `multiplier`.
56
+ * Tracks two values:
57
+
58
+ * `currentValue` โ†’ cannot go below zero.
59
+ * `infiniteValue` โ†’ can decrease infinitely into negative numbers.
60
+
61
+ ---
62
+
63
+ ### Constructor
64
+
65
+ ```ts
66
+ constructor(maxValue = 100, baseDecay = 1, baseDecayMulti = 1)
67
+ ```
68
+
69
+ * `maxValue` โ€“ Maximum bar value (default `100`)
70
+ * `baseDecay` โ€“ Base decay per tick (default `1`)
71
+ * `baseDecayMulti` โ€“ Multiplier for base decay (default `1`)
72
+
73
+ **Example:**
74
+
75
+ ```js
76
+ const bar = new TinyNeedBar(100, 2, 1.5);
77
+ ```
78
+
79
+ ---
80
+
81
+ ### Getters
82
+
83
+ | Getter | Returns | Description |
84
+ | ---------------- | --------------------------- | ----------------------------------------- |
85
+ | `factors` | `Record<string, BarFactor>` | Snapshot of all active factors. |
86
+ | `currentPercent` | `number` | Current percentage relative to max. |
87
+ | `maxValue` | `number` | Maximum possible value of the bar. |
88
+ | `currentValue` | `number` | Current clamped value (โ‰ฅ 0). |
89
+ | `infiniteValue` | `number` | Current infinite value (can go negative). |
90
+
91
+ ---
92
+
93
+ ### Setters
94
+
95
+ | Setter | Parameters | Description |
96
+ | --------------- | --------------- | -------------------------------------------------- |
97
+ | `maxValue` | `value: number` | Update max value, clamps `currentValue` if needed. |
98
+ | `infiniteValue` | `value: number` | Update infinite value, auto-adjust `currentValue`. |
99
+
100
+ ---
101
+
102
+ ### Methods
103
+
104
+ #### `getFactor(key: string): BarFactor` ๐Ÿ”‘
105
+
106
+ Get a specific factor by key.
107
+ Throws an error if the factor does not exist.
108
+
109
+ ```js
110
+ bar.getFactor("main");
111
+ ```
112
+
113
+ ---
114
+
115
+ #### `hasFactor(key: string): boolean` โœ…
116
+
117
+ Check if a factor exists by key.
118
+
119
+ ```js
120
+ bar.hasFactor("main"); // true or false
121
+ ```
122
+
123
+ ---
124
+
125
+ #### `setFactor(key: string, amount: number, multiplier = 1)` โšก
126
+
127
+ Add or update a decay factor.
128
+
129
+ ```js
130
+ bar.setFactor("hunger", 2, 1.2);
131
+ ```
132
+
133
+ ---
134
+
135
+ #### `removeFactor(key: string)` โŒ
136
+
137
+ Remove a factor by key.
138
+
139
+ ```js
140
+ bar.removeFactor("hunger");
141
+ ```
142
+
143
+ ---
144
+
145
+ #### `tick(): TickResult` โฑ๏ธ
146
+
147
+ Execute one tick of decay using all active factors.
148
+
149
+ ```js
150
+ const result = bar.tick();
151
+ console.log(result.remainingValue);
152
+ ```
153
+
154
+ ---
155
+
156
+ #### `toJSON(): SerializedData` ๐Ÿ’พ
157
+
158
+ Serialize the current state to a JSON-compatible object.
159
+
160
+ ```js
161
+ const data = bar.toJSON();
162
+ ```
163
+
164
+ ---
165
+
166
+ #### `static fromJSON(data: SerializedData): TinyNeedBar` ๐Ÿ“ค
167
+
168
+ Restore a `TinyNeedBar` from serialized data.
169
+
170
+ ```js
171
+ const newBar = TinyNeedBar.fromJSON(data);
172
+ ```
173
+
174
+ ---
175
+
176
+ #### `clone(): TinyNeedBar` ๐Ÿงฌ
177
+
178
+ Deep clone the bar.
179
+
180
+ ```js
181
+ const cloned = bar.clone();
182
+ ```
183
+
184
+ ---
185
+
186
+ #### `clearFactors()` ๐Ÿงน
187
+
188
+ Remove all factors.
189
+
190
+ ```js
191
+ bar.clearFactors();
192
+ ```
193
+
194
+ ---
195
+
196
+ ### โœ… Example Usage
197
+
198
+ ```js
199
+ const bar = new TinyNeedBar(100, 2, 1.5);
200
+
201
+ // Add extra factors
202
+ bar.setFactor("energy", 1, 1.2);
203
+ bar.setFactor("fun", 0.5, 1);
204
+
205
+ // Tick simulation
206
+ setInterval(() => {
207
+ const result = bar.tick();
208
+ console.log(`Value: ${result.remainingValue} (${result.currentPercent}%)`);
209
+ }, 1000);
210
+
211
+ // Export / Import
212
+ const json = bar.toJSON();
213
+ const restored = TinyNeedBar.fromJSON(json);
214
+
215
+ // Clone
216
+ const clone = bar.clone();
217
+ ```
218
+
219
+ ---
220
+
221
+ ### ๐ŸŽจ Notes
222
+
223
+ * Designed for simulation & testing.
224
+ * Can handle multiple independent decay factors.
225
+ * `infiniteValue` is useful for simulations that allow negative overflow.
226
+ * Fully serializable for state saving/loading.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tiny-essentials",
3
- "version": "1.21.0",
3
+ "version": "1.21.1",
4
4
  "description": "Collection of small, essential scripts designed to be used across various projects. These simple utilities are crafted for speed, ease of use, and versatility.",
5
5
  "scripts": {
6
6
  "test": "npm run test:mjs && npm run test:cjs && npm run test:js",