pf2e-sage-stats 0.2.5 → 0.2.7

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 CHANGED
@@ -24,6 +24,7 @@ const commander_1 = require("commander");
24
24
  const promises_1 = __importDefault(require("fs/promises"));
25
25
  const path_1 = __importDefault(require("path"));
26
26
  const readline_1 = __importDefault(require("readline"));
27
+ const clipboardy_1 = __importDefault(require("clipboardy"));
27
28
  const package_json_1 = __importDefault(require("../package.json"));
28
29
  const app_1 = require("./app");
29
30
  const program = new commander_1.Command(package_json_1.default.name);
@@ -71,6 +72,19 @@ program.command('sort')
71
72
  .action(() => __awaiter(void 0, void 0, void 0, function* () {
72
73
  console.log(yield (0, app_1.sortFolder)());
73
74
  }));
75
+ program.command('convert')
76
+ .description('Convert a discord export file into a txt log')
77
+ .argument('<file>', 'input file')
78
+ .option('-o, --output <file>', 'output file')
79
+ .action((argument, option) => __awaiter(void 0, void 0, void 0, function* () {
80
+ const file = yield promises_1.default.readFile(argument, { encoding: 'utf-8' });
81
+ if (option.output) {
82
+ yield promises_1.default.writeFile(option.output, (0, app_1.screenPlay)(file), { encoding: 'utf-8' });
83
+ }
84
+ else {
85
+ console.log((0, app_1.screenPlay)(file));
86
+ }
87
+ }));
74
88
  program.command('flat')
75
89
  .description('Generte a special flat npc tsv')
76
90
  .option('-n, --name <string>', 'npc name')
@@ -78,23 +92,23 @@ program.command('flat')
78
92
  .action((option) => __awaiter(void 0, void 0, void 0, function* () {
79
93
  var _a, _b;
80
94
  if (option.output) {
81
- yield promises_1.default.writeFile(option.output, (0, app_1.fromatMap)((_a = option.name) !== null && _a !== void 0 ? _a : 'flat', app_1.prediceateMap), { encoding: 'utf-8' });
95
+ yield promises_1.default.writeFile(option.output, (0, app_1.fromatMap)((_a = option.name) !== null && _a !== void 0 ? _a : 'flat', app_1.flatMap), { encoding: 'utf-8' });
82
96
  }
83
97
  else {
84
- console.log((0, app_1.fromatMap)((_b = option.name) !== null && _b !== void 0 ? _b : 'flat', app_1.prediceateMap));
98
+ console.log((0, app_1.fromatMap)((_b = option.name) !== null && _b !== void 0 ? _b : 'flat', app_1.flatMap));
85
99
  }
86
100
  }));
87
- program.command('adjustment')
88
- .description('Generte a special adjustment npc tsv')
101
+ program.command('dice')
102
+ .description('Generte a special dice npc tsv')
89
103
  .option('-n, --name <string>', 'npc name')
90
104
  .option('-o, --output <file>', 'output json')
91
105
  .action((option) => __awaiter(void 0, void 0, void 0, function* () {
92
106
  var _a, _b;
93
107
  if (option.output) {
94
- yield promises_1.default.writeFile(option.output, (0, app_1.fromatMap)((_a = option.name) !== null && _a !== void 0 ? _a : 'adjustment', (0, app_1.adjustmentMap)()), { encoding: 'utf-8' });
108
+ yield promises_1.default.writeFile(option.output, (0, app_1.fromatMap)((_a = option.name) !== null && _a !== void 0 ? _a : 'dice', app_1.diceMap), { encoding: 'utf-8' });
95
109
  }
96
110
  else {
97
- console.log((0, app_1.fromatMap)((_b = option.name) !== null && _b !== void 0 ? _b : 'adjustment', (0, app_1.adjustmentMap)()));
111
+ console.log((0, app_1.fromatMap)((_b = option.name) !== null && _b !== void 0 ? _b : 'dice', app_1.diceMap));
98
112
  }
99
113
  }));
100
114
  program.command('statblock')
@@ -131,26 +145,24 @@ program.command('tsv')
131
145
  .argument('<file>', 'input json')
132
146
  .option('-o, --output <file>', 'output tsv')
133
147
  .option('-s, --secretDC', 'produce secret DCs')
134
- .option('-r, --recallDC', 'produce recall DCs')
135
148
  .option('-d, --defaultSkills', 'produce values for untrained skills')
136
149
  .action((argument, option) => __awaiter(void 0, void 0, void 0, function* () {
137
150
  const file = yield promises_1.default.readFile(argument, { encoding: 'utf-8' });
138
151
  const stats = (0, app_1.parseJSON)(file);
139
152
  const output = option.output ? option.output : path_1.default.join(path_1.default.parse(argument).dir, path_1.default.parse(argument).name + '.tsv');
140
- yield promises_1.default.writeFile(output, (0, app_1.formatTSV)(stats, option.secretDC, option.defaultSkills, option.recallDC), { encoding: 'utf-8' });
153
+ yield promises_1.default.writeFile(output, (0, app_1.formatTSV)(stats, option.secretDC, option.defaultSkills), { encoding: 'utf-8' });
141
154
  }));
142
155
  program.command('command')
143
156
  .description('Generte a creation command file from JSON')
144
157
  .argument('<file>', 'input json')
145
158
  .option('-o, --output <file>', 'output txt')
146
159
  .option('-s, --secretDC', 'produce secret DCs')
147
- .option('-r, --recallDC', 'produce recall DCs')
148
160
  .option('-d, --defaultSkills', 'produce values for untrained skills')
149
161
  .action((argument, option) => __awaiter(void 0, void 0, void 0, function* () {
150
162
  const file = yield promises_1.default.readFile(argument, { encoding: 'utf-8' });
151
163
  const stats = (0, app_1.parseJSON)(file);
152
164
  const output = option.output ? option.output : path_1.default.join(path_1.default.parse(argument).dir, path_1.default.parse(argument).name + '-command.txt');
153
- yield promises_1.default.writeFile(output, (0, app_1.formatCommand)(stats, option.secretDC, option.defaultSkills, option.recallDC), { encoding: 'utf-8' });
165
+ yield promises_1.default.writeFile(output, (0, app_1.formatCommand)(stats, option.secretDC, option.defaultSkills), { encoding: 'utf-8' });
154
166
  }));
155
167
  program.command('newtracker')
156
168
  .argument('<file>', 'input text file')
@@ -191,7 +203,9 @@ program.command('track')
191
203
  }
192
204
  else {
193
205
  console.clear();
194
- console.log((0, app_1.formatTracker)(tracker));
206
+ const track = (0, app_1.formatTracker)(tracker);
207
+ clipboardy_1.default.writeSync(track);
208
+ console.log(track);
195
209
  }
196
210
  });
197
211
  yield invoke(argument);
@@ -216,7 +230,7 @@ program.command('track')
216
230
  }
217
231
  }))(),
218
232
  (() => __awaiter(void 0, void 0, void 0, function* () {
219
- var _a, _b, _c, _d, _e;
233
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
220
234
  const rl = readline_1.default.createInterface({
221
235
  input: process.stdin,
222
236
  output: process.stdout
@@ -230,6 +244,15 @@ program.command('track')
230
244
  }, {
231
245
  regex: /^\s*reset/i,
232
246
  map: () => ({ command: 'reset' })
247
+ }, {
248
+ regex: /^\s*purge/i,
249
+ map: () => ({ command: 'purge' })
250
+ }, {
251
+ regex: /^\s*blank/i,
252
+ map: () => ({ command: 'blank' })
253
+ }, {
254
+ regex: /^\s*foe(\s+(\S+))?(\s+(\S+))?(\s+(\d+))?/i,
255
+ map: (match) => ({ command: 'foe', name: match[2], alias: match[4], hp: match[6] && parseInt(match[6], 10) })
233
256
  }, {
234
257
  regex: /^\s*heal/i,
235
258
  map: () => ({ command: 'heal' })
@@ -267,19 +290,73 @@ program.command('track')
267
290
  }
268
291
  },
269
292
  }, {
270
- regex: /^\s*(\S+)\s+[sS]\s*"(.*)"/,
293
+ regex: /^\s*([^\s="+-]+)\s*=?"([^"]*)"/,
294
+ map: (match) => {
295
+ return { command: 'set-conditions', tag: match[1], value: match[2] };
296
+ },
297
+ }, {
298
+ regex: /^\s*([^\s="+-]+)\s*\+"([^"]*)"/,
299
+ map: (match) => {
300
+ return { command: 'add-conditions', tag: match[1], value: match[2] };
301
+ },
302
+ }, {
303
+ regex: /^\s*([^\s="+-]+)\s*-"([^"]*)"/,
304
+ map: (match) => {
305
+ return { command: 'rem-conditions', tag: match[1], value: match[2] };
306
+ },
307
+ }, {
308
+ regex: /^\s*([^\s="+-]+)\s*\+\+"([^"]*)"/,
309
+ map: (match) => {
310
+ return { command: 'inc-conditions', tag: match[1], value: match[2] };
311
+ },
312
+ }, {
313
+ regex: /^\s*([^\s="+-]+)\s*--"([^"]*)"/,
314
+ map: (match) => {
315
+ return { command: 'dec-conditions', tag: match[1], value: match[2] };
316
+ },
317
+ }, {
318
+ regex: /^\s*(\S+)\s+[sS]?\s*=?"([^"]*)"/,
271
319
  map: (match) => {
272
320
  return { command: 'set-conditions', tag: match[1], value: match[2] };
273
321
  },
322
+ }, {
323
+ regex: /^\s*(\S+)\s+[sS]?\s*\+"([^"]*)"/,
324
+ map: (match) => {
325
+ return { command: 'add-conditions', tag: match[1], value: match[2] };
326
+ },
327
+ }, {
328
+ regex: /^\s*(\S+)\s+[sS]?\s*-"([^"]*)"/,
329
+ map: (match) => {
330
+ return { command: 'rem-conditions', tag: match[1], value: match[2] };
331
+ },
332
+ }, {
333
+ regex: /^\s*(\S+)\s+[sS]?\s*\+\+"([^"]*)"/,
334
+ map: (match) => {
335
+ return { command: 'inc-conditions', tag: match[1], value: match[2] };
336
+ },
337
+ }, {
338
+ regex: /^\s*(\S+)\s+[sS]?\s*--"([^"]*)"/,
339
+ map: (match) => {
340
+ return { command: 'dec-conditions', tag: match[1], value: match[2] };
341
+ },
274
342
  }, {
275
343
  regex: /^\s*(\S+)\s+[cC]/,
276
344
  map: (match) => ({ command: 'check', tag: match[1] }),
277
345
  }, {
278
346
  regex: /^\s*(\S+)\s+[aA]/,
279
347
  map: (match) => ({ command: 'arrow', tag: match[1] }),
348
+ }, {
349
+ regex: /^\s*(\S+)\s+[eE]/,
350
+ map: (match) => ({ command: 'empty', tag: match[1] }),
351
+ }, {
352
+ regex: /^\s*(\S+)\s+[xX]/,
353
+ map: (match) => ({ command: 'cross', tag: match[1] }),
280
354
  }, {
281
355
  regex: /^\s*(\S+)\s+[dD]/,
282
356
  map: (match) => ({ command: 'delete', tag: match[1] }),
357
+ }, {
358
+ regex: /^\s*(\S+)\s+[wW]/,
359
+ map: (match) => ({ command: 'wait', tag: match[1] }),
283
360
  }];
284
361
  const actions = [];
285
362
  while (true) {
@@ -321,6 +398,24 @@ program.command('track')
321
398
  }
322
399
  }
323
400
  }
401
+ else if (action.command === 'wait') {
402
+ const sorted = [...tracker].sort((a, b) => (a.init === b.init) ? (b.foe ? 1 : 0) - (a.foe ? 1 : 0) : b.init - a.init);
403
+ const blocks = [[sorted[0]]];
404
+ for (let i = 1; i < sorted.length; ++i) {
405
+ if (sorted[i].foe === blocks[blocks.length - 1][0].foe) {
406
+ blocks[blocks.length - 1].push(sorted[i]);
407
+ }
408
+ else {
409
+ blocks.push([sorted[i]]);
410
+ }
411
+ }
412
+ const blockIndex = blocks.findIndex((b) => b.find((c) => c.id === action.tag || c.alias === action.tag || c.name == action.tag));
413
+ const block = blocks[blockIndex + 1];
414
+ const item = tracker.find((c) => c.id === action.tag || c.alias === action.tag || c.name == action.tag);
415
+ if (block && item) {
416
+ item.init = ((_b = (_a = block[block.length - 1]) === null || _a === void 0 ? void 0 : _a.init) !== null && _b !== void 0 ? _b : 0) - 1;
417
+ }
418
+ }
324
419
  else if (action.command === 'check') {
325
420
  const item = tracker.find((c) => c.id === action.tag || c.alias === action.tag || c.name == action.tag);
326
421
  if (item) {
@@ -333,9 +428,24 @@ program.command('track')
333
428
  item.state = "arrow";
334
429
  }
335
430
  }
431
+ else if (action.command === 'empty') {
432
+ const item = tracker.find((c) => c.id === action.tag || c.alias === action.tag || c.name == action.tag);
433
+ if (item) {
434
+ item.state = "empty";
435
+ }
436
+ }
437
+ else if (action.command === 'cross') {
438
+ const item = tracker.find((c) => c.id === action.tag || c.alias === action.tag || c.name == action.tag);
439
+ if (item) {
440
+ item.state = "cross";
441
+ }
442
+ }
336
443
  else if (action.command === 'delete') {
337
444
  tracker = tracker.filter((c) => !(c.id === action.tag || c.alias === action.tag || c.name == action.tag)).map((p) => (Object.assign(Object.assign({}, p), { children: p.children.filter((c) => !(c.id === action.tag || c.alias === action.tag || c.name == action.tag)) })));
338
445
  }
446
+ else if (action.command === 'purge') {
447
+ tracker = tracker.filter((c) => !c.foe);
448
+ }
339
449
  else if (action.command === 'exit') {
340
450
  process.exit(0);
341
451
  }
@@ -353,13 +463,13 @@ program.command('track')
353
463
  });
354
464
  }
355
465
  else if (action.command === 'set-thp') {
356
- const item = (_a = tracker.find((c) => c.id === action.tag || c.alias === action.tag || c.name == action.tag)) !== null && _a !== void 0 ? _a : (tracker.flatMap((c) => c.children).find((c) => c.id === action.tag || c.alias === action.tag || c.name == action.tag));
466
+ const item = (_c = tracker.find((c) => c.id === action.tag || c.alias === action.tag || c.name == action.tag)) !== null && _c !== void 0 ? _c : (tracker.flatMap((c) => c.children).find((c) => c.id === action.tag || c.alias === action.tag || c.name == action.tag));
357
467
  if (item) {
358
468
  item.temphp = Math.max(0, action.value);
359
469
  }
360
470
  }
361
471
  else if (action.command === 'set-hp') {
362
- const item = (_b = tracker.find((c) => c.id === action.tag || c.alias === action.tag || c.name == action.tag)) !== null && _b !== void 0 ? _b : (tracker.flatMap((c) => c.children).find((c) => c.id === action.tag || c.alias === action.tag || c.name == action.tag));
472
+ const item = (_d = tracker.find((c) => c.id === action.tag || c.alias === action.tag || c.name == action.tag)) !== null && _d !== void 0 ? _d : (tracker.flatMap((c) => c.children).find((c) => c.id === action.tag || c.alias === action.tag || c.name == action.tag));
363
473
  if (item) {
364
474
  item.hp = Math.min(item.maxhp, Math.max(0, action.value));
365
475
  }
@@ -370,20 +480,74 @@ program.command('track')
370
480
  item.init = Math.max(0, action.value);
371
481
  }
372
482
  }
483
+ else if (action.command === 'blank') {
484
+ tracker.forEach((item) => {
485
+ item.conditions = "";
486
+ });
487
+ }
373
488
  else if (action.command === 'set-conditions') {
374
- const item = (_c = tracker.find((c) => c.id === action.tag || c.alias === action.tag || c.name == action.tag)) !== null && _c !== void 0 ? _c : (tracker.flatMap((c) => c.children).find((c) => c.id === action.tag || c.alias === action.tag || c.name == action.tag));
489
+ const item = (_e = tracker.find((c) => c.id === action.tag || c.alias === action.tag || c.name == action.tag)) !== null && _e !== void 0 ? _e : (tracker.flatMap((c) => c.children).find((c) => c.id === action.tag || c.alias === action.tag || c.name == action.tag));
375
490
  if (item) {
376
- item.conditions = action.value;
491
+ item.conditions = action.value.trim();
492
+ }
493
+ }
494
+ else if (action.command === 'add-conditions') {
495
+ const item = (_f = tracker.find((c) => c.id === action.tag || c.alias === action.tag || c.name == action.tag)) !== null && _f !== void 0 ? _f : (tracker.flatMap((c) => c.children).find((c) => c.id === action.tag || c.alias === action.tag || c.name == action.tag));
496
+ if (item) {
497
+ const conditions = [...item.conditions.split(',').map((c) => c.toLowerCase().trim()).filter((c) => c.length), action.value.toLowerCase().trim()];
498
+ item.conditions = conditions.join(', ');
499
+ }
500
+ }
501
+ else if (action.command === 'rem-conditions') {
502
+ const item = (_g = tracker.find((c) => c.id === action.tag || c.alias === action.tag || c.name == action.tag)) !== null && _g !== void 0 ? _g : (tracker.flatMap((c) => c.children).find((c) => c.id === action.tag || c.alias === action.tag || c.name == action.tag));
503
+ if (item) {
504
+ const conditions = item.conditions.split(',').map((c) => c.toLowerCase().trim()).filter((c) => c.length).filter((c) => !c.includes(action.value.toLowerCase().trim()));
505
+ item.conditions = conditions.join(', ');
506
+ }
507
+ }
508
+ else if (action.command === 'inc-conditions') {
509
+ const item = (_h = tracker.find((c) => c.id === action.tag || c.alias === action.tag || c.name == action.tag)) !== null && _h !== void 0 ? _h : (tracker.flatMap((c) => c.children).find((c) => c.id === action.tag || c.alias === action.tag || c.name == action.tag));
510
+ if (item) {
511
+ const conditions = item.conditions.split(',').map((c) => c.toLowerCase().trim()).filter((c) => c.length).map((c) => {
512
+ if (c.includes(action.value.toLowerCase().trim())) {
513
+ const match = c.match(/(.*)\s+(\d+)/);
514
+ if (match && match[1] && match[2]) {
515
+ return `${match[1].trim()} ${parseInt(match[2]) + 1}`;
516
+ }
517
+ }
518
+ return c;
519
+ });
520
+ item.conditions = conditions.join(', ');
521
+ }
522
+ }
523
+ else if (action.command === 'dec-conditions') {
524
+ const item = (_j = tracker.find((c) => c.id === action.tag || c.alias === action.tag || c.name == action.tag)) !== null && _j !== void 0 ? _j : (tracker.flatMap((c) => c.children).find((c) => c.id === action.tag || c.alias === action.tag || c.name == action.tag));
525
+ if (item) {
526
+ const conditions = item.conditions.split(',').map((c) => c.toLowerCase().trim()).filter((c) => c.length).map((c) => {
527
+ if (c.includes(action.value.toLowerCase().trim())) {
528
+ const match = c.match(/(.*)\s+(\d+)/);
529
+ if (match && match[1] && match[2]) {
530
+ if (parseInt(match[2]) > 1) {
531
+ return `${match[1].trim()} ${parseInt(match[2]) - 1}`;
532
+ }
533
+ else {
534
+ return match[1].trim();
535
+ }
536
+ }
537
+ }
538
+ return c;
539
+ });
540
+ item.conditions = conditions.join(', ');
377
541
  }
378
542
  }
379
543
  else if (action.command === 'mod-thp') {
380
- const item = (_d = tracker.find((c) => c.id === action.tag || c.alias === action.tag || c.name == action.tag)) !== null && _d !== void 0 ? _d : (tracker.flatMap((c) => c.children).find((c) => c.id === action.tag || c.alias === action.tag || c.name == action.tag));
544
+ const item = (_k = tracker.find((c) => c.id === action.tag || c.alias === action.tag || c.name == action.tag)) !== null && _k !== void 0 ? _k : (tracker.flatMap((c) => c.children).find((c) => c.id === action.tag || c.alias === action.tag || c.name == action.tag));
381
545
  if (item) {
382
546
  item.temphp = Math.max(0, item.temphp + action.value);
383
547
  }
384
548
  }
385
549
  else if (action.command === 'mod-hp') {
386
- const item = (_e = tracker.find((c) => c.id === action.tag || c.alias === action.tag || c.name == action.tag)) !== null && _e !== void 0 ? _e : (tracker.flatMap((c) => c.children).find((c) => c.id === action.tag || c.alias === action.tag || c.name == action.tag));
550
+ const item = (_l = tracker.find((c) => c.id === action.tag || c.alias === action.tag || c.name == action.tag)) !== null && _l !== void 0 ? _l : (tracker.flatMap((c) => c.children).find((c) => c.id === action.tag || c.alias === action.tag || c.name == action.tag));
387
551
  if (item) {
388
552
  let hp = item.hp;
389
553
  let thp = item.temphp;
@@ -404,6 +568,9 @@ program.command('track')
404
568
  item.init = Math.max(0, item.init + action.value);
405
569
  }
406
570
  }
571
+ else if (action.command === 'foe') {
572
+ tracker.push(app_1.charSchema.parse({ foe: true, name: action.name, alias: action.alias, maxhp: action.hp, hp: action.hp }));
573
+ }
407
574
  }
408
575
  yield promises_1.default.writeFile(argument, JSON.stringify(tracker, undefined, 2), { encoding: 'utf-8' });
409
576
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pf2e-sage-stats",
3
- "version": "0.2.5",
3
+ "version": "0.2.7",
4
4
  "description": "An RPG Sage's .tsv stat generation tool",
5
5
  "main": "dist/index.js",
6
6
  "author": "ikariott@gmail.com",
@@ -17,6 +17,7 @@
17
17
  "devDependencies": {
18
18
  "@eslint/js": "^9.17.0",
19
19
  "@types/jest": "^29.5.14",
20
+ "@types/jsdom": "^27.0.0",
20
21
  "@types/lodash": "^4.17.13",
21
22
  "@types/pluralize": "^0.0.33",
22
23
  "@types/tsv": "^0.2.4",
@@ -30,11 +31,14 @@
30
31
  },
31
32
  "dependencies": {
32
33
  "abbreviate": "^0.0.3",
34
+ "clipboardy": "^5.1.0",
33
35
  "commander": "^12.1.0",
34
36
  "dedent-js": "^1.0.1",
37
+ "jsdom": "^28.0.0",
35
38
  "lodash": "^4.17.21",
36
39
  "pluralize": "^8.0.0",
37
40
  "tsv": "^0.2.0",
38
41
  "zod": "^3.24.1"
39
- }
42
+ },
43
+ "packageManager": "yarn@1.22.21+sha1.1959a18351b811cdeedbd484a8f86c3cc3bbaf72"
40
44
  }