pf2e-sage-stats 0.2.9 → 0.2.10

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/src/index.ts DELETED
@@ -1,612 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import { Command } from 'commander';
4
- import fs from 'fs/promises';
5
- import path from 'path';
6
- import readline from 'readline';
7
- import clipboardy from 'clipboardy';
8
-
9
- import pack from '../package.json';
10
-
11
- import { sortFolder, formatCommand, formatJSON, formatTSV, fromatMap, parseJSON, parseStatblock, stub, flatMap, formatTable, formatHP, newtracker, parseTracker, formatTracker, screenPlay, diceMap, charSchema } from './app';
12
-
13
- const program = new Command(pack.name);
14
-
15
- program
16
- .name(pack.name)
17
- .description(pack.description)
18
- .version(pack.version);
19
-
20
- program.command('stub')
21
- .description('Generte a stat JSON template')
22
- .option('-o, --output <file>', 'output json')
23
- .action(async (option) => {
24
- if (option.output) {
25
- await fs.writeFile(option.output, formatJSON(stub), { encoding: 'utf-8' })
26
- } else {
27
- console.log(formatJSON(stub));
28
- }
29
- });
30
-
31
- program.command('table')
32
- .description('Generte a table configuration string')
33
- .argument('<string>', 'table name')
34
- .option('-o, --output <file>', 'output file')
35
- .option('-t, --table <string>', 'table')
36
- .option('-s, --season <string>', 'season')
37
- .option('-c, --scenario <string>', 'scenario')
38
- .option('-g, --gm <string>', 'gm')
39
- .option('-p, --players <string>', 'players')
40
- .action(async (argument, option) => {
41
- if (option.output) {
42
- await fs.writeFile(option.output, formatTable(option.table ?? '1', option.season ?? '1', option.scenario ?? '1', argument, option.gm ?? '@lammonaaf', option.players ?? '<players>'), { encoding: 'utf-8' })
43
- } else {
44
- console.log(formatTable(option.table ?? '1', option.season ?? '1', option.scenario ?? '1', argument, option.gm ?? '@lammonaaf', option.players ?? '<players>'));
45
- }
46
- });
47
-
48
- program.command('hp')
49
- .description('Generte an hp bar')
50
- .argument('<string>', 'hp/maxhp')
51
- .action(async (argument) => {
52
- console.log(formatHP(argument));
53
- });
54
-
55
- program.command('sort')
56
- .description('Sorts log file folder and renames files')
57
- .action(async () => {
58
- console.log(await sortFolder());
59
- });
60
-
61
- program.command('convert')
62
- .description('Convert a discord export file into a txt log')
63
- .argument('<file>', 'input file')
64
- .option('-o, --output <file>', 'output file')
65
- .action(async (argument, option) => {
66
- const file = await fs.readFile(argument, { encoding: 'utf-8' });
67
-
68
- if (option.output) {
69
- await fs.writeFile(option.output, screenPlay(file), { encoding: 'utf-8' })
70
- } else {
71
- console.log(screenPlay(file));
72
- }
73
- });
74
-
75
- program.command('flat')
76
- .description('Generte a special flat npc tsv')
77
- .option('-n, --name <string>', 'npc name')
78
- .option('-o, --output <file>', 'output json')
79
- .action(async (option) => {
80
- if (option.output) {
81
- await fs.writeFile(option.output, fromatMap(option.name ?? 'flat', flatMap), { encoding: 'utf-8' })
82
- } else {
83
- console.log(fromatMap(option.name ?? 'flat', flatMap));
84
- }
85
- });
86
-
87
- program.command('dice')
88
- .description('Generte a special dice npc tsv')
89
- .option('-n, --name <string>', 'npc name')
90
- .option('-o, --output <file>', 'output json')
91
- .action(async (option) => {
92
- if (option.output) {
93
- await fs.writeFile(option.output, fromatMap(option.name ?? 'dice', diceMap), { encoding: 'utf-8' })
94
- } else {
95
- console.log(fromatMap(option.name ?? 'dice', diceMap));
96
- }
97
- });
98
-
99
- program.command('statblock')
100
- .description('Generte a stat JSON from Paizo creature statblock')
101
- .argument('<file>', 'input text file')
102
- .option('-n, --name <string>', 'creature name')
103
- .option('-a, --alias <string>', 'creature alias')
104
- .option('-b, --abbreviate', 'create alias from name')
105
- .option('-t, --tsv', 'output directly to tsv')
106
- .option('-c, --command', 'output directly to txt')
107
- .option('-s, --secretDC', 'produce secret DCs (tsv only)')
108
- .option('-d, --defaultSkills', 'produce values for untrained skills (tsv only)')
109
- .option('-o, --output <file>', 'output file name')
110
- .action(async (argument, option) => {
111
- const file = await fs.readFile(argument, { encoding: 'utf-8' });
112
-
113
- const alias = option.alias ?? (option.abbreviate ? null : (option.output ? path.parse(option.output).name : path.parse(argument).name));
114
-
115
- const stats = parseStatblock(option.name ?? null, file, alias);
116
-
117
- if (option.tsv) {
118
- const output = option.output ? option.output : path.join(path.parse(argument).dir, stats.alias + '.tsv');
119
-
120
- await fs.writeFile(output, formatTSV(stats, option.secretDC, option.defaultSkills), { encoding: 'utf-8' });
121
- } else if (option.command) {
122
- const output = option.output ? option.output : path.join(path.parse(argument).dir, stats.alias + '-command.txt');
123
-
124
- await fs.writeFile(output, formatCommand(stats, option.secretDC, option.defaultSkills), { encoding: 'utf-8' });
125
- } else {
126
- const output = option.output ? option.output : path.join(path.parse(argument).dir, stats.alias + '.json');
127
-
128
- await fs.writeFile(output, formatJSON(stats), { encoding: 'utf-8' });
129
- }
130
- });
131
-
132
- program.command('tsv')
133
- .description('Generte a tsv file from JSON')
134
- .argument('<file>', 'input json')
135
- .option('-o, --output <file>', 'output tsv')
136
- .option('-s, --secretDC', 'produce secret DCs')
137
- .option('-d, --defaultSkills', 'produce values for untrained skills')
138
- .action(async (argument, option) => {
139
- const file = await fs.readFile(argument, { encoding: 'utf-8' });
140
-
141
- const stats = parseJSON(file);
142
-
143
- const output = option.output ? option.output : path.join(path.parse(argument).dir, path.parse(argument).name + '.tsv');
144
-
145
- await fs.writeFile(output, formatTSV(stats, option.secretDC, option.defaultSkills), { encoding: 'utf-8' });
146
- });
147
-
148
- program.command('command')
149
- .description('Generte a creation command file from JSON')
150
- .argument('<file>', 'input json')
151
- .option('-o, --output <file>', 'output txt')
152
- .option('-s, --secretDC', 'produce secret DCs')
153
- .option('-d, --defaultSkills', 'produce values for untrained skills')
154
- .action(async (argument, option) => {
155
- const file = await fs.readFile(argument, { encoding: 'utf-8' });
156
-
157
- const stats = parseJSON(file);
158
-
159
- const output = option.output ? option.output : path.join(path.parse(argument).dir, path.parse(argument).name + '-command.txt');
160
-
161
- await fs.writeFile(output, formatCommand(stats, option.secretDC, option.defaultSkills), { encoding: 'utf-8' });
162
- });
163
-
164
- program.command('newtracker')
165
- .argument('<file>', 'input text file')
166
- .option('-o, --output <file>', 'output file name')
167
- .action(async (argument, option) => {
168
- const file = await fs.readFile(argument, { encoding: 'utf-8' });
169
-
170
- const tracker = newtracker(file);
171
-
172
- if (option.output) {
173
- await fs.writeFile(option.output, JSON.stringify(tracker, undefined, 2), { encoding: 'utf-8' })
174
- } else {
175
- console.log(JSON.stringify(tracker, undefined, 2));
176
- }
177
- });
178
-
179
- program.command('tracker')
180
- .argument('<file>', 'input text file')
181
- .option('-o, --output <file>', 'output file name')
182
- .action(async (argument, option) => {
183
- const file = await fs.readFile(argument, { encoding: 'utf-8' });
184
-
185
- const tracker = parseTracker(file);
186
-
187
- if (option.output) {
188
- await fs.writeFile(option.output, formatTracker(tracker), { encoding: 'utf-8' })
189
- } else {
190
- console.log(formatTracker(tracker));
191
- }
192
- });
193
-
194
- program.command('track')
195
- .argument('<file>', 'input text file')
196
- .option('-o, --output <file>', 'output file name')
197
- .action(async (argument, option) => {
198
- const iterator = fs.watch(argument);
199
-
200
- const invoke = async (filename: string) => {
201
- const file = await fs.readFile(filename, { encoding: 'utf-8' });
202
-
203
- const tracker = parseTracker(file);
204
-
205
- if (option.output) {
206
- await fs.writeFile(option.output, formatTracker(tracker), { encoding: 'utf-8' })
207
- } else {
208
- console.clear();
209
-
210
- const track = formatTracker(tracker);
211
- clipboardy.writeSync(track)
212
- console.log(track);
213
- }
214
- }
215
-
216
- await invoke(argument);
217
-
218
- await Promise.all([
219
- (async () => {
220
- for await (const value of iterator) {
221
- await invoke(value.filename ?? argument);
222
- }
223
- })(),
224
- (async () => {
225
- const rl = readline.createInterface({
226
- input: process.stdin,
227
- output: process.stdout
228
- });
229
-
230
- while (true) {
231
- await new Promise((resolve) => setTimeout(resolve, 500));
232
-
233
- let input = await new Promise<string>((resolve) => (
234
- rl.question('> ', resolve)
235
- ));
236
-
237
- const commands = [{
238
- regex: /^\s*[bB]\s*(\d+)/,
239
- map: (match: RegExpMatchArray) => ({ command: 'block' as const, index: parseInt(match[1], 10) })
240
- }, {
241
- regex: /^\s*reset/i,
242
- map: () => ({ command: 'reset' as const })
243
- }, {
244
- regex: /^\s*purge/i,
245
- map: () => ({ command: 'purge' as const })
246
- }, {
247
- regex: /^\s*blank/i,
248
- map: () => ({ command: 'blank' as const })
249
- }, {
250
- regex: /^\s*foe(\s+(\S+))?(\s+(\S+))?(\s+(\d+))?/i,
251
- map: (match: RegExpMatchArray) => ({ command: 'foe' as const, name: match[2], alias: match[4], hp: match[6] && parseInt(match[6], 10) })
252
- }, {
253
- regex: /^\s*heal/i,
254
- map: () => ({ command: 'heal' as const })
255
- }, {
256
- regex: /^\s*exit/i,
257
- map: () => ({ command: 'exit' as const })
258
- }, {
259
- regex: /^\s*([^\d\s+-]+)\s*([+-]?\d+)/,
260
- map: (match: RegExpMatchArray) => {
261
- if (match[2].match(/^[+-]/)) {
262
- return { command: 'mod-hp' as const, tag: match[1], value: parseInt(match[2]) };
263
- } else {
264
- return { command: 'set-hp' as const, tag: match[1], value: parseInt(match[2]) };
265
- }
266
- }
267
- }, {
268
- regex: /^\s*(\S+)\s+[tT]\s*([+-]?\d+)/,
269
- map: (match: RegExpMatchArray) => {
270
- if (match[2].match(/^[+-]/)) {
271
- return { command: 'mod-thp' as const, tag: match[1], value: parseInt(match[2]) };
272
- } else {
273
- return { command: 'set-thp' as const, tag: match[1], value: parseInt(match[2]) };
274
- }
275
- }
276
- }, {
277
- regex: /^\s*(\S+)\s+[iI]\s*([+-]?\d+)/,
278
- map: (match: RegExpMatchArray) => {
279
- if (match[2].match(/^[+-]/)) {
280
- return { command: 'mod-init' as const, tag: match[1], value: parseInt(match[2]) };
281
- } else {
282
- return { command: 'set-init' as const, tag: match[1], value: parseInt(match[2]) };
283
- }
284
- },
285
- }, {
286
- regex: /^\s*([^\s="+-]+)\s*=?"([^"]*)"/,
287
- map: (match: RegExpMatchArray) => {
288
- return { command: 'set-conditions' as const, tag: match[1], value: match[2] };
289
- },
290
- }, {
291
- regex: /^\s*([^\s="+-]+)\s*\+"([^"]*)"/,
292
- map: (match: RegExpMatchArray) => {
293
- return { command: 'add-conditions' as const, tag: match[1], value: match[2] };
294
- },
295
- }, {
296
- regex: /^\s*([^\s="+-]+)\s*-"([^"]*)"/,
297
- map: (match: RegExpMatchArray) => {
298
- return { command: 'rem-conditions' as const, tag: match[1], value: match[2] };
299
- },
300
- }, {
301
- regex: /^\s*([^\s="+-]+)\s*\+\+"([^"]*)"/,
302
- map: (match: RegExpMatchArray) => {
303
- return { command: 'inc-conditions' as const, tag: match[1], value: match[2] };
304
- },
305
- }, {
306
- regex: /^\s*([^\s="+-]+)\s*--"([^"]*)"/,
307
- map: (match: RegExpMatchArray) => {
308
- return { command: 'dec-conditions' as const, tag: match[1], value: match[2] };
309
- },
310
- }, {
311
- regex: /^\s*(\S+)\s+[sS]?\s*=?"([^"]*)"/,
312
- map: (match: RegExpMatchArray) => {
313
- return { command: 'set-conditions' as const, tag: match[1], value: match[2] };
314
- },
315
- }, {
316
- regex: /^\s*(\S+)\s+[sS]?\s*\+"([^"]*)"/,
317
- map: (match: RegExpMatchArray) => {
318
- return { command: 'add-conditions' as const, tag: match[1], value: match[2] };
319
- },
320
- }, {
321
- regex: /^\s*(\S+)\s+[sS]?\s*-"([^"]*)"/,
322
- map: (match: RegExpMatchArray) => {
323
- return { command: 'rem-conditions' as const, tag: match[1], value: match[2] };
324
- },
325
- }, {
326
- regex: /^\s*(\S+)\s+[sS]?\s*\+\+"([^"]*)"/,
327
- map: (match: RegExpMatchArray) => {
328
- return { command: 'inc-conditions' as const, tag: match[1], value: match[2] };
329
- },
330
- }, {
331
- regex: /^\s*(\S+)\s+[sS]?\s*--"([^"]*)"/,
332
- map: (match: RegExpMatchArray) => {
333
- return { command: 'dec-conditions' as const, tag: match[1], value: match[2] };
334
- },
335
- }, {
336
- regex: /^\s*(\S+)\s+[cC]/,
337
- map: (match: RegExpMatchArray) => ({ command: 'check' as const, tag: match[1] }),
338
- }, {
339
- regex: /^\s*(\S+)\s+[aA]/,
340
- map: (match: RegExpMatchArray) => ({ command: 'arrow' as const, tag: match[1] }),
341
- }, {
342
- regex: /^\s*(\S+)\s+[eE]/,
343
- map: (match: RegExpMatchArray) => ({ command: 'empty' as const, tag: match[1] }),
344
- }, {
345
- regex: /^\s*(\S+)\s+[xX]/,
346
- map: (match: RegExpMatchArray) => ({ command: 'cross' as const, tag: match[1] }),
347
- }, {
348
- regex: /^\s*(\S+)\s+[dD]/,
349
- map: (match: RegExpMatchArray) => ({ command: 'delete' as const, tag: match[1] }),
350
- }, {
351
- regex: /^\s*(\S+)\s+[wW]/,
352
- map: (match: RegExpMatchArray) => ({ command: 'wait' as const, tag: match[1] }),
353
- }];
354
-
355
- const actions: ReturnType<typeof commands[number]['map']>[] = [];
356
-
357
- while (true) {
358
- const command = commands.find((c) => input.match(c.regex));
359
-
360
- if (!command) {
361
- break;
362
- }
363
-
364
- const match = input.match(command.regex);
365
-
366
- if (!match) {
367
- break;
368
- }
369
-
370
- const action = command.map(match);
371
-
372
- input = input.slice(match[0].length);
373
-
374
- actions.push(action)
375
- }
376
-
377
- const file = await fs.readFile(argument, { encoding: 'utf-8' });
378
-
379
- let tracker = parseTracker(file);
380
-
381
- for (const action of actions) {
382
- if (action.command === 'block') {
383
- const sorted = [...tracker].sort((a, b) => (a.init === b.init) ? (b.foe ? 1 : 0) - (a.foe ? 1 : 0) : b.init - a.init);
384
-
385
- const blocks = [[sorted[0]]];
386
-
387
- for (let i=1; i < sorted.length; ++i) {
388
- if (sorted[i].foe === blocks[blocks.length-1][0].foe) {
389
- blocks[blocks.length-1].push(sorted[i])
390
- } else {
391
- blocks.push([sorted[i]])
392
- }
393
- }
394
-
395
- for (let i=0; i < blocks.length; ++i) {
396
- if (i < action.index) {
397
- blocks[i].forEach((b) => b.state = 'check')
398
- } else if (i === action.index) {
399
- blocks[i].forEach((b) => b.state = 'arrow')
400
- } else {
401
- blocks[i].forEach((b) => b.state = 'empty')
402
- }
403
- }
404
- } else if (action.command === 'wait') {
405
- const sorted = [...tracker].sort((a, b) => (a.init === b.init) ? (b.foe ? 1 : 0) - (a.foe ? 1 : 0) : b.init - a.init);
406
-
407
- const blocks = [[sorted[0]]];
408
-
409
- for (let i=1; i < sorted.length; ++i) {
410
- if (sorted[i].foe === blocks[blocks.length-1][0].foe) {
411
- blocks[blocks.length-1].push(sorted[i])
412
- } else {
413
- blocks.push([sorted[i]])
414
- }
415
- }
416
-
417
- const blockIndex = blocks.findIndex((b) => b.find((c) => c.id === action.tag || c.alias === action.tag || c.name == action.tag))
418
- const block = blocks[blockIndex + 1]
419
- const item = tracker.find((c) => c.id === action.tag || c.alias === action.tag || c.name == action.tag)
420
-
421
- if (block && item) {
422
- item.init = (block[block.length - 1]?.init ?? 0) - 1;
423
- }
424
- } else if (action.command === 'check') {
425
- const item = tracker.find((c) => c.id === action.tag || c.alias === action.tag || c.name == action.tag)
426
-
427
- if (item) {
428
- item.state = "check"
429
- }
430
- } else if (action.command === 'arrow') {
431
- const item = tracker.find((c) => c.id === action.tag || c.alias === action.tag || c.name == action.tag)
432
-
433
- if (item) {
434
- item.state = "arrow"
435
- }
436
- } else if (action.command === 'empty') {
437
- const item = tracker.find((c) => c.id === action.tag || c.alias === action.tag || c.name == action.tag)
438
-
439
- if (item) {
440
- item.state = "empty"
441
- }
442
- } else if (action.command === 'cross') {
443
- const item = tracker.find((c) => c.id === action.tag || c.alias === action.tag || c.name == action.tag)
444
-
445
- if (item) {
446
- item.state = "cross"
447
- }
448
- } else if (action.command === 'delete') {
449
- tracker = tracker.filter((c) => !(c.id === action.tag || c.alias === action.tag || c.name == action.tag)).map((p) => ({
450
- ...p,
451
- children: p.children.filter((c) => !(c.id === action.tag || c.alias === action.tag || c.name == action.tag)),
452
- }))
453
- } else if (action.command === 'purge') {
454
- tracker = tracker.filter((c) => !c.foe)
455
- } else if (action.command === 'exit') {
456
- process.exit(0)
457
- } else if (action.command === 'heal') {
458
- tracker.forEach((char) => {
459
- char.hp = char.maxhp
460
-
461
- char.children.forEach((child) => {
462
- child.hp = child.maxhp
463
- })
464
- })
465
- } else if (action.command === 'reset') {
466
- tracker.forEach((char) => {
467
- char.state = 'empty'
468
- })
469
- } else if (action.command === 'set-thp') {
470
- const item = tracker.find((c) => c.id === action.tag || c.alias === action.tag || c.name == action.tag) ?? (
471
- tracker.flatMap((c) => c.children).find((c) => c.id === action.tag || c.alias === action.tag || c.name == action.tag)
472
- )
473
-
474
- if (item) {
475
- item.temphp = Math.max(0, action.value)
476
- }
477
- } else if (action.command === 'set-hp') {
478
- const item = tracker.find((c) => c.id === action.tag || c.alias === action.tag || c.name == action.tag) ?? (
479
- tracker.flatMap((c) => c.children).find((c) => c.id === action.tag || c.alias === action.tag || c.name == action.tag)
480
- )
481
-
482
- if (item) {
483
- item.hp = Math.min(item.maxhp, Math.max(0, action.value))
484
- }
485
- } else if (action.command === 'set-init') {
486
- const item = tracker.find((c) => c.id === action.tag || c.alias === action.tag || c.name == action.tag)
487
-
488
- if (item) {
489
- item.init = Math.max(0, action.value)
490
- }
491
- } else if (action.command === 'blank') {
492
- tracker.forEach((item) => {
493
- item.conditions = ""
494
- })
495
- } else if (action.command === 'set-conditions') {
496
- const item = tracker.find((c) => c.id === action.tag || c.alias === action.tag || c.name == action.tag) ?? (
497
- tracker.flatMap((c) => c.children).find((c) => c.id === action.tag || c.alias === action.tag || c.name == action.tag)
498
- )
499
-
500
- if (item) {
501
- item.conditions = action.value.trim()
502
- }
503
- } else if (action.command === 'add-conditions') {
504
- const item = tracker.find((c) => c.id === action.tag || c.alias === action.tag || c.name == action.tag) ?? (
505
- tracker.flatMap((c) => c.children).find((c) => c.id === action.tag || c.alias === action.tag || c.name == action.tag)
506
- )
507
-
508
- if (item) {
509
- const conditions = [...item.conditions.split(',').map((c) => c.toLowerCase().trim()).filter((c) => c.length), action.value.toLowerCase().trim()];
510
-
511
- item.conditions = conditions.join(', ')
512
- }
513
- } else if (action.command === 'rem-conditions') {
514
- const item = tracker.find((c) => c.id === action.tag || c.alias === action.tag || c.name == action.tag) ?? (
515
- tracker.flatMap((c) => c.children).find((c) => c.id === action.tag || c.alias === action.tag || c.name == action.tag)
516
- )
517
-
518
- if (item) {
519
- const conditions = item.conditions.split(',').map((c) => c.toLowerCase().trim()).filter((c) => c.length).filter((c) => !c.includes(action.value.toLowerCase().trim()));
520
-
521
- item.conditions = conditions.join(', ')
522
- }
523
- } else if (action.command === 'inc-conditions') {
524
- const item = tracker.find((c) => c.id === action.tag || c.alias === action.tag || c.name == action.tag) ?? (
525
- tracker.flatMap((c) => c.children).find((c) => c.id === action.tag || c.alias === action.tag || c.name == action.tag)
526
- )
527
-
528
- if (item) {
529
- const conditions = item.conditions.split(',').map((c) => c.toLowerCase().trim()).filter((c) => c.length).map((c) => {
530
- if (c.includes(action.value.toLowerCase().trim())) {
531
- const match = c.match(/(.*)\s+(\d+)/);
532
-
533
- if (match && match[1] && match[2]) {
534
- return `${match[1].trim()} ${parseInt(match[2]) + 1}`
535
- }
536
- }
537
-
538
- return c;
539
- });
540
-
541
- item.conditions = conditions.join(', ')
542
- }
543
- } else if (action.command === 'dec-conditions') {
544
- const item = tracker.find((c) => c.id === action.tag || c.alias === action.tag || c.name == action.tag) ?? (
545
- tracker.flatMap((c) => c.children).find((c) => c.id === action.tag || c.alias === action.tag || c.name == action.tag)
546
- )
547
-
548
- if (item) {
549
- const conditions = item.conditions.split(',').map((c) => c.toLowerCase().trim()).filter((c) => c.length).map((c) => {
550
- if (c.includes(action.value.toLowerCase().trim())) {
551
- const match = c.match(/(.*)\s+(\d+)/);
552
-
553
- if (match && match[1] && match[2]) {
554
- if (parseInt(match[2]) > 1) {
555
- return `${match[1].trim()} ${parseInt(match[2]) - 1}`
556
- } else {
557
- return match[1].trim()
558
- }
559
- }
560
- }
561
-
562
- return c;
563
- });
564
-
565
- item.conditions = conditions.join(', ')
566
- }
567
- } else if (action.command === 'mod-thp') {
568
- const item = tracker.find((c) => c.id === action.tag || c.alias === action.tag || c.name == action.tag) ?? (
569
- tracker.flatMap((c) => c.children).find((c) => c.id === action.tag || c.alias === action.tag || c.name == action.tag)
570
- )
571
-
572
- if (item) {
573
- item.temphp = Math.max(0, item.temphp + action.value)
574
- }
575
- } else if (action.command === 'mod-hp') {
576
- const item = tracker.find((c) => c.id === action.tag || c.alias === action.tag || c.name == action.tag) ?? (
577
- tracker.flatMap((c) => c.children).find((c) => c.id === action.tag || c.alias === action.tag || c.name == action.tag)
578
- )
579
-
580
- if (item) {
581
- let hp = item.hp;
582
- let thp = item.temphp;
583
-
584
- if (action.value < 0) {
585
- thp += action.value;
586
- hp += Math.min(thp, 0)
587
- } else {
588
- hp += action.value;
589
- }
590
-
591
- item.temphp = Math.max(0, thp)
592
- item.hp = Math.min(item.maxhp, Math.max(0, hp))
593
- }
594
- } else if (action.command === 'mod-init') {
595
- const item = tracker.find((c) => c.id === action.tag || c.alias === action.tag || c.name == action.tag)
596
-
597
- if (item) {
598
- item.init = Math.max(0, item.init + action.value)
599
- }
600
- } else if (action.command === 'foe') {
601
- tracker.push(charSchema.parse({ foe: true, name: action.name, alias: action.alias, maxhp: action.hp, hp: action.hp }))
602
- }
603
- }
604
-
605
- await fs.writeFile(argument, JSON.stringify(tracker, undefined, 2), { encoding: 'utf-8' })
606
- }
607
- })(),
608
- ])
609
- });
610
-
611
-
612
- program.parse();
package/src/types.d.ts DELETED
@@ -1,5 +0,0 @@
1
- declare module 'abbreviate' {
2
- function abbreviate(s: string, options?: { length?: number }): string;
3
-
4
- export default abbreviate;
5
- }
package/test/app.test.ts DELETED
@@ -1,67 +0,0 @@
1
- import { parseJSON, stub } from '../src/app';
2
-
3
- test('stats', () => {
4
- expect(stub).toEqual({
5
- name: 'name',
6
- alias: 'nm',
7
- level: 0,
8
- maxhp: 0,
9
- attributes: {
10
- strength: 0,
11
- dextrenity: 0,
12
- constitution: 0,
13
- intelligence: 0,
14
- wisdom: 0,
15
- charisma: 0,
16
- },
17
- saves: {
18
- fortitude: 0,
19
- reflex: 0,
20
- will: 0,
21
- },
22
- ac: 10,
23
- perception: 0,
24
- skills: {
25
- acrobatics: 0,
26
- arcana: 0,
27
- athletics: 0,
28
- crafting: 0,
29
- deception: 0,
30
- diplomacy: 0,
31
- intimidation: 0,
32
- medicine: 0,
33
- nature: 0,
34
- occultism: 0,
35
- perfomance: 0,
36
- religion: 0,
37
- society: 0,
38
- stealth: 0,
39
- survival: 0,
40
- thievery: 0,
41
- },
42
- lores: {},
43
- });
44
-
45
- expect(parseJSON('{"name":"Test"}')).toEqual({
46
- name: 'Test',
47
- level: 0,
48
- maxhp: 0,
49
- attributes: {
50
- strength: 0,
51
- dextrenity: 0,
52
- constitution: 0,
53
- intelligence: 0,
54
- wisdom: 0,
55
- charisma: 0,
56
- },
57
- saves: {
58
- fortitude: 0,
59
- reflex: 0,
60
- will: 0,
61
- },
62
- ac: 10,
63
- perception: 0,
64
- skills: {},
65
- lores: {},
66
- });
67
- });