pf2e-sage-stats 0.2.2 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +41 -10
- package/package.json +1 -1
- package/src/index.ts +48 -11
package/dist/index.js
CHANGED
|
@@ -223,18 +223,49 @@ program.command('track')
|
|
|
223
223
|
while (true) {
|
|
224
224
|
yield new Promise((resolve) => setTimeout(resolve, 500));
|
|
225
225
|
const input = yield new Promise((resolve) => (rl.question('>', resolve)));
|
|
226
|
-
const
|
|
227
|
-
if (
|
|
228
|
-
|
|
226
|
+
const hpmod = input.match(/([^\d+-]+)\s*([+-]?\d+)/);
|
|
227
|
+
if (hpmod) {
|
|
228
|
+
const file = yield promises_1.default.readFile(argument, { encoding: 'utf-8' });
|
|
229
|
+
const tracker = (0, app_1.parseTracker)(file);
|
|
230
|
+
const index = tracker.findIndex((c) => c.alias === hpmod[1]);
|
|
231
|
+
if (index >= 0) {
|
|
232
|
+
let hp = tracker[index].hp;
|
|
233
|
+
let thp = tracker[index].temphp;
|
|
234
|
+
if (hpmod[2].match(/^[+-]/)) {
|
|
235
|
+
const delta = parseInt(hpmod[2]);
|
|
236
|
+
if (delta < 0) {
|
|
237
|
+
thp += delta;
|
|
238
|
+
hp += Math.min(thp, 0);
|
|
239
|
+
}
|
|
240
|
+
else {
|
|
241
|
+
hp += delta;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
else {
|
|
245
|
+
hp = parseInt(hpmod[2]);
|
|
246
|
+
}
|
|
247
|
+
tracker[index].temphp = Math.max(0, thp);
|
|
248
|
+
tracker[index].hp = Math.min(tracker[index].maxhp, Math.max(0, hp));
|
|
249
|
+
yield promises_1.default.writeFile(argument, JSON.stringify(tracker, undefined, 2), { encoding: 'utf-8' });
|
|
250
|
+
}
|
|
229
251
|
}
|
|
230
|
-
const
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
252
|
+
const thpmod = input.match(/(\S+)\s+[tT]\s*([+-]?\d+)/);
|
|
253
|
+
if (thpmod) {
|
|
254
|
+
const file = yield promises_1.default.readFile(argument, { encoding: 'utf-8' });
|
|
255
|
+
const tracker = (0, app_1.parseTracker)(file);
|
|
256
|
+
const index = tracker.findIndex((c) => c.alias === thpmod[1]);
|
|
257
|
+
if (index >= 0) {
|
|
258
|
+
let thp = tracker[index].temphp;
|
|
259
|
+
if (thpmod[2].match(/^[+-]/)) {
|
|
260
|
+
thp += parseInt(thpmod[2]);
|
|
261
|
+
}
|
|
262
|
+
else {
|
|
263
|
+
thp = parseInt(thpmod[2]);
|
|
264
|
+
}
|
|
265
|
+
tracker[index].temphp = Math.max(0, thp);
|
|
266
|
+
yield promises_1.default.writeFile(argument, JSON.stringify(tracker, undefined, 2), { encoding: 'utf-8' });
|
|
267
|
+
}
|
|
235
268
|
}
|
|
236
|
-
tracker[index].hp += parseInt(comm[2]);
|
|
237
|
-
yield promises_1.default.writeFile(argument, JSON.stringify(tracker, undefined, 2), { encoding: 'utf-8' });
|
|
238
269
|
}
|
|
239
270
|
}))(),
|
|
240
271
|
]);
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -218,25 +218,62 @@ program.command('track')
|
|
|
218
218
|
rl.question('>', resolve)
|
|
219
219
|
));
|
|
220
220
|
|
|
221
|
-
const
|
|
221
|
+
const hpmod = input.match(/([^\d+-]+)\s*([+-]?\d+)/);
|
|
222
222
|
|
|
223
|
-
if (
|
|
224
|
-
|
|
225
|
-
|
|
223
|
+
if (hpmod) {
|
|
224
|
+
const file = await fs.readFile(argument, { encoding: 'utf-8' });
|
|
225
|
+
|
|
226
|
+
const tracker = parseTracker(file);
|
|
227
|
+
|
|
228
|
+
const index = tracker.findIndex((c) => c.alias === hpmod[1])
|
|
226
229
|
|
|
227
|
-
|
|
230
|
+
if (index >= 0) {
|
|
231
|
+
let hp = tracker[index].hp;
|
|
232
|
+
let thp = tracker[index].temphp;
|
|
228
233
|
|
|
229
|
-
|
|
234
|
+
if (hpmod[2].match(/^[+-]/)) {
|
|
235
|
+
const delta = parseInt(hpmod[2])
|
|
230
236
|
|
|
231
|
-
|
|
237
|
+
if (delta < 0) {
|
|
238
|
+
thp += delta;
|
|
239
|
+
hp += Math.min(thp, 0)
|
|
240
|
+
} else {
|
|
241
|
+
hp += delta;
|
|
242
|
+
}
|
|
243
|
+
} else {
|
|
244
|
+
hp = parseInt(hpmod[2]);
|
|
245
|
+
}
|
|
232
246
|
|
|
233
|
-
|
|
234
|
-
|
|
247
|
+
tracker[index].temphp = Math.max(0, thp)
|
|
248
|
+
tracker[index].hp = Math.min(tracker[index].maxhp, Math.max(0, hp))
|
|
249
|
+
|
|
250
|
+
await fs.writeFile(argument, JSON.stringify(tracker, undefined, 2), { encoding: 'utf-8' })
|
|
251
|
+
}
|
|
235
252
|
}
|
|
236
253
|
|
|
237
|
-
|
|
254
|
+
const thpmod = input.match(/(\S+)\s+[tT]\s*([+-]?\d+)/);
|
|
255
|
+
|
|
256
|
+
if (thpmod) {
|
|
257
|
+
const file = await fs.readFile(argument, { encoding: 'utf-8' });
|
|
258
|
+
|
|
259
|
+
const tracker = parseTracker(file);
|
|
238
260
|
|
|
239
|
-
|
|
261
|
+
const index = tracker.findIndex((c) => c.alias === thpmod[1])
|
|
262
|
+
|
|
263
|
+
if (index >= 0) {
|
|
264
|
+
let thp = tracker[index].temphp;
|
|
265
|
+
|
|
266
|
+
if (thpmod[2].match(/^[+-]/)) {
|
|
267
|
+
thp += parseInt(thpmod[2]);
|
|
268
|
+
} else {
|
|
269
|
+
thp = parseInt(thpmod[2]);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
tracker[index].temphp = Math.max(0, thp)
|
|
273
|
+
|
|
274
|
+
await fs.writeFile(argument, JSON.stringify(tracker, undefined, 2), { encoding: 'utf-8' })
|
|
275
|
+
}
|
|
276
|
+
}
|
|
240
277
|
}
|
|
241
278
|
})(),
|
|
242
279
|
])
|