pf2e-sage-stats 0.2.10 → 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/dist/app.js CHANGED
@@ -1,26 +1,17 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
14
5
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.screenPlay = exports.sortFolder = exports.formatTracker = exports.newtracker = exports.formatHP = exports.formatTable = exports.formatCommand = exports.formatTSV = exports.flatten = exports.parseStatblock = exports.parseTracker = exports.parseJSON = exports.formatJSON = exports.fromatMap = exports.diceMap = exports.flatMap = exports.charSchema = exports.stub = void 0;
6
+ exports.sortFolder = exports.formatTracker = exports.newtracker = exports.formatHP = exports.formatTable = exports.formatCommand = exports.formatTSV = exports.flatten = exports.parseStatblock = exports.parseTracker = exports.parseJSON = exports.formatJSON = exports.fromatMap = exports.diceMap = exports.flatMap = exports.charSchema = exports.stub = void 0;
16
7
  const zod_1 = __importDefault(require("zod"));
17
8
  const tsv_1 = require("tsv");
9
+ const promises_1 = require("fs/promises");
18
10
  const lodash_1 = require("lodash");
19
11
  const dedent_js_1 = __importDefault(require("dedent-js"));
20
12
  const abbreviate_1 = __importDefault(require("abbreviate"));
21
13
  const pluralize_1 = __importDefault(require("pluralize"));
22
- const jsdom_1 = require("jsdom");
23
- const promises_1 = require("fs/promises");
14
+ const lines_1 = require("./lines");
24
15
  const schema = zod_1.default.object({
25
16
  name: zod_1.default.string(),
26
17
  alias: zod_1.default.string().optional(),
@@ -208,10 +199,34 @@ exports.charSchema = zod_1.default.object({
208
199
  conditions: zod_1.default.string().default(''),
209
200
  children: zod_1.default.array(childSchema).default([]),
210
201
  });
211
- exports.flatMap = Object.assign(Object.assign({}, ([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20].map((v) => ([`${v}`, `d20 >= ${v} flat;`])).reduce((p, [k, v]) => { p[k] = v; return p; }, {}))), { c: 'd20 >= 5 flat;', concealed: 'd20 >= 5 flat;', h: 'd20 >= 11 flat;', hidden: 'd20 >= 11 flat;' });
212
- exports.diceMap = Object.assign(Object.assign({}, ([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20].map((v) => ([`${v}`, `(${v})`])).reduce((p, [k, v]) => { p[k] = v; return p; }, {}))), { a: '+2', adv: '+2', advantage: '+2', d: '-2', dis: '-2', disadvantage: '-2', f: '+2', for: '+2', fort: '+2', fortune: '+2', m: '-2', mis: '-2', misfortune: '-2' });
202
+ exports.flatMap = {
203
+ ...([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20].map((v) => ([`${v}`, `d20 >= ${v} flat;`])).reduce((p, [k, v]) => { p[k] = v; return p; }, {})),
204
+ c: 'd20 >= 5 flat;',
205
+ concealed: 'd20 >= 5 flat;',
206
+ h: 'd20 >= 11 flat;',
207
+ hidden: 'd20 >= 11 flat;',
208
+ };
209
+ exports.diceMap = {
210
+ ...([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20].map((v) => ([`${v}`, `(${v})`])).reduce((p, [k, v]) => { p[k] = v; return p; }, {})),
211
+ a: '+2',
212
+ adv: '+2',
213
+ advantage: '+2',
214
+ d: '-2',
215
+ dis: '-2',
216
+ disadvantage: '-2',
217
+ f: '+2',
218
+ for: '+2',
219
+ fort: '+2',
220
+ fortune: '+2',
221
+ m: '-2',
222
+ mis: '-2',
223
+ misfortune: '-2',
224
+ };
213
225
  const fromatMap = (name, map) => {
214
- return tsv_1.TSV.stringify([Object.assign({ name }, map)]);
226
+ return tsv_1.TSV.stringify([{
227
+ name,
228
+ ...map,
229
+ }]);
215
230
  };
216
231
  exports.fromatMap = fromatMap;
217
232
  const dcByLevel = [13, 14, 15, 16, 18, 19, 20, 22, 23, 24, 26, 27, 28, 30, 31, 32, 34, 35, 36, 38, 39, 40, 42, 44, 46, 48, 50];
@@ -237,7 +252,7 @@ const locateInt = (name, statblock, section = null, signed = true, alias) => {
237
252
  return null;
238
253
  };
239
254
  const locateInts = (statblock, section, alias, signed = true) => {
240
- const regex = new RegExp(`(${section}|,)([^,]*?)${alias}\\s+(${signed ? '[+-]' : '-?'}\\d+)`, 'g');
255
+ const regex = new RegExp(`(${section}|,)((?:(?!${section})[^,])*?)${alias}\\s+(${signed ? '[+-]' : '-?'}\\d+)`, 'g');
241
256
  let matches = null;
242
257
  const output = [];
243
258
  // eslint-disable-next-line no-cond-assign
@@ -271,7 +286,7 @@ const locateIntsAfter = (statblock, alias, signed = true) => {
271
286
  return output.reduce((p, [key, name, value]) => { p[key] = { mod: value, name: name, info: [] }; return p; }, {});
272
287
  };
273
288
  const locateStrikes = (statblock, alias) => {
274
- const regex = new RegExp(`${alias}(\\s+\\[.+\\])?\\s+(.+?)\\s+(\\(x\\d+\\)\\s+)?([+-]\\d+)\\s*([\\S\\s]*?),\\s+(Damage|Effect)\\s+(\\S+\\s+\\S+.*?)(?=$|\\s+Melee|\\s+Ranged)`, 'gm');
289
+ const regex = new RegExp(`${alias}(\\s+\\[.+\\])?\\s+(.+?)\\s+(\\(x\\d+\\)\\s+)?([+-]\\d+)\\s*([\\S\\s]*?)[,;]?\\s+(Damage|Effect)\\s+(\\S+\\s+\\S+.*?)(?=$|\\s+Melee|\\s+Ranged)`, 'gm');
275
290
  let matches = null;
276
291
  const output = [];
277
292
  // eslint-disable-next-line no-cond-assign
@@ -343,21 +358,86 @@ const locateStrikes = (statblock, alias) => {
343
358
  const locateSpells = (statblock) => {
344
359
  const match = statblock.match(new RegExp(/Spells\s+DC\s+(\d+)(,\s+[Aa]ttack\s+([+-]\d+))?/));
345
360
  if (match && match[1]) {
346
- return Object.assign({ dc: parseInt(match[1]) }, (match[3] ? { attack: parseInt(match[3]) } : null));
361
+ return {
362
+ dc: parseInt(match[1]),
363
+ ...(match[3] ? { attack: parseInt(match[3]) } : null)
364
+ };
347
365
  }
348
366
  return null;
349
367
  };
350
368
  const parseStatblock = (name, _statblock, alias) => {
351
369
  var _a;
352
370
  const defaults = schema.parse({ name: name !== null && name !== void 0 ? name : 'Unknown' });
353
- const improvisation = _statblock.match(/Untrained\s+Improvisation/);
354
- const plate = _statblock.match(/Full\s+Plate/);
355
- const statblock = _statblock
356
- .replace(/^Items.*$/m, '')
357
- .replace('', '')
358
- .replace(/–/g, '-') + '\n';
359
- const basic = locateName(statblock);
360
- const result = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, defaults), basic), (name && { name: name })), { alias: alias !== null && alias !== void 0 ? alias : (0, abbreviate_1.default)((_a = name !== null && name !== void 0 ? name : basic === null || basic === void 0 ? void 0 : basic.name) !== null && _a !== void 0 ? _a : defaults.name, { length: 3 }).toLowerCase() }), locateInt('perception', statblock)), locateInt('ac', statblock, null, false, 'AC')), locateInt('maxhp', statblock, null, false, 'HP')), { attributes: Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, defaults.attributes), locateInt('strength', statblock, null, true, 'Str')), locateInt('dexterity', statblock, null, true, 'Dex')), locateInt('constitution', statblock, null, true, 'Con')), locateInt('intelligence', statblock, null, true, 'Int')), locateInt('wisdom', statblock, null, true, 'Wis')), locateInt('charisma', statblock, null, true, 'Cha')), saves: Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, defaults.saves), locateInt('fortitude', statblock, null, true, 'Fortitude')), locateInt('reflex', statblock, null, true, 'Reflex')), locateInt('fortitude', statblock, null, true, 'Fort')), locateInt('reflex', statblock, null, true, 'Ref')), locateInt('will', statblock, null, true, 'Will')), skills: Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, defaults.skills), locateInt('acrobatics', statblock, 'Skills')), locateInt('arcana', statblock, 'Skills')), locateInt('athletics', statblock, 'Skills')), locateInt('crafting', statblock, 'Skills')), locateInt('deception', statblock, 'Skills')), locateInt('diplomacy', statblock, 'Skills')), locateInt('intimidation', statblock, 'Skills')), locateInt('medicine', statblock, 'Skills')), locateInt('nature', statblock, 'Skills')), locateInt('occultism', statblock, 'Skills')), locateInt('performance', statblock, 'Skills')), locateInt('religion', statblock, 'Skills')), locateInt('society', statblock, 'Skills')), locateInt('stealth', statblock, 'Skills')), locateInt('survival', statblock, 'Skills')), locateInt('thievery', statblock, 'Skills')), locateInt('piloting', statblock, 'Skills')), locateInt('computers', statblock, 'Skills')), lores: Object.assign(Object.assign({}, locateInts(statblock, 'Skills', 'Lore')), locateIntsAfter(statblock, 'Lore:')), melee: Object.assign({}, locateStrikes(statblock, 'Melee')), ranged: Object.assign({}, locateStrikes(statblock, 'Ranged')), spells: Object.assign({}, locateSpells(statblock)), extra: {}, extraDCs: Object.assign({}, locateInt('stealth', statblock, null, false, 'Stealth DC')), extraDice: {} });
371
+ const lines = (0, lines_1.classifyStatblockLines)(_statblock);
372
+ const improvisation = (0, lines_1.getLine)(lines, 'feats').match(/Untrained\s+Improvisation/);
373
+ const plate = (0, lines_1.getLine)(lines, 'items').match(/Full\s+Plate/);
374
+ const basic = locateName((0, lines_1.getLine)(lines, 'title'));
375
+ const result = {
376
+ ...defaults,
377
+ ...basic,
378
+ ...(name && { name: name }),
379
+ ...{ alias: alias !== null && alias !== void 0 ? alias : (0, abbreviate_1.default)((_a = name !== null && name !== void 0 ? name : basic === null || basic === void 0 ? void 0 : basic.name) !== null && _a !== void 0 ? _a : defaults.name, { length: 3 }).toLowerCase() },
380
+ ...locateInt('perception', (0, lines_1.getLine)(lines, 'perception')),
381
+ ...locateInt('ac', (0, lines_1.getLine)(lines, 'defence'), null, false, 'AC'),
382
+ ...locateInt('maxhp', (0, lines_1.getLine)(lines, 'hp'), null, false, 'HP'),
383
+ attributes: {
384
+ ...defaults.attributes,
385
+ ...locateInt('strength', (0, lines_1.getLine)(lines, 'attributes'), null, true, 'Str'),
386
+ ...locateInt('dexterity', (0, lines_1.getLine)(lines, 'attributes'), null, true, 'Dex'),
387
+ ...locateInt('constitution', (0, lines_1.getLine)(lines, 'attributes'), null, true, 'Con'),
388
+ ...locateInt('intelligence', (0, lines_1.getLine)(lines, 'attributes'), null, true, 'Int'),
389
+ ...locateInt('wisdom', (0, lines_1.getLine)(lines, 'attributes'), null, true, 'Wis'),
390
+ ...locateInt('charisma', (0, lines_1.getLine)(lines, 'attributes'), null, true, 'Cha'),
391
+ },
392
+ saves: {
393
+ ...defaults.saves,
394
+ ...locateInt('fortitude', (0, lines_1.getLine)(lines, 'defence'), null, true, 'Fortitude'),
395
+ ...locateInt('reflex', (0, lines_1.getLine)(lines, 'defence'), null, true, 'Reflex'),
396
+ ...locateInt('fortitude', (0, lines_1.getLine)(lines, 'defence'), null, true, 'Fort'),
397
+ ...locateInt('reflex', (0, lines_1.getLine)(lines, 'defence'), null, true, 'Ref'),
398
+ ...locateInt('will', (0, lines_1.getLine)(lines, 'defence'), null, true, 'Will'),
399
+ },
400
+ skills: {
401
+ ...defaults.skills,
402
+ ...locateInt('acrobatics', (0, lines_1.getLine)(lines, 'skills'), 'Skills'),
403
+ ...locateInt('arcana', (0, lines_1.getLine)(lines, 'skills'), 'Skills'),
404
+ ...locateInt('athletics', (0, lines_1.getLine)(lines, 'skills'), 'Skills'),
405
+ ...locateInt('crafting', (0, lines_1.getLine)(lines, 'skills'), 'Skills'),
406
+ ...locateInt('deception', (0, lines_1.getLine)(lines, 'skills'), 'Skills'),
407
+ ...locateInt('diplomacy', (0, lines_1.getLine)(lines, 'skills'), 'Skills'),
408
+ ...locateInt('intimidation', (0, lines_1.getLine)(lines, 'skills'), 'Skills'),
409
+ ...locateInt('medicine', (0, lines_1.getLine)(lines, 'skills'), 'Skills'),
410
+ ...locateInt('nature', (0, lines_1.getLine)(lines, 'skills'), 'Skills'),
411
+ ...locateInt('occultism', (0, lines_1.getLine)(lines, 'skills'), 'Skills'),
412
+ ...locateInt('performance', (0, lines_1.getLine)(lines, 'skills'), 'Skills'),
413
+ ...locateInt('religion', (0, lines_1.getLine)(lines, 'skills'), 'Skills'),
414
+ ...locateInt('society', (0, lines_1.getLine)(lines, 'skills'), 'Skills'),
415
+ ...locateInt('stealth', (0, lines_1.getLine)(lines, 'skills'), 'Skills'),
416
+ ...locateInt('stealth', (0, lines_1.getLine)(lines, 'stealth'), 'Skills'),
417
+ ...locateInt('survival', (0, lines_1.getLine)(lines, 'skills'), 'Skills'),
418
+ ...locateInt('thievery', (0, lines_1.getLine)(lines, 'skills'), 'Skills'),
419
+ ...locateInt('piloting', (0, lines_1.getLine)(lines, 'skills'), 'Skills'),
420
+ ...locateInt('computers', (0, lines_1.getLine)(lines, 'skills'), 'Skills'),
421
+ },
422
+ lores: {
423
+ ...locateInts((0, lines_1.getLine)(lines, 'skills'), 'Skills', 'Lore'),
424
+ ...locateIntsAfter((0, lines_1.getLine)(lines, 'skills'), 'Lore:')
425
+ },
426
+ melee: {
427
+ ...locateStrikes((0, lines_1.listLines)(lines, 'strike'), 'Melee'),
428
+ },
429
+ ranged: {
430
+ ...locateStrikes((0, lines_1.listLines)(lines, 'strike'), 'Ranged'),
431
+ },
432
+ spells: {
433
+ ...locateSpells((0, lines_1.listLines)(lines, 'spells')),
434
+ },
435
+ extra: {},
436
+ extraDCs: {
437
+ ...locateInt('stealth', (0, lines_1.getLine)(lines, 'stealth'), null, false, 'Stealth DC'),
438
+ },
439
+ extraDice: {},
440
+ };
361
441
  result.untrained = improvisation ? (result.level >= 7 ? result.level : result.level >= 5 ? result.level - 1 : result.level - 2) : 0;
362
442
  result.bullwark = plate ? Math.max(3 - result.attributes.dexterity, 0) : 0;
363
443
  return result;
@@ -381,12 +461,35 @@ const toRanged = ([key, value]) => [
381
461
  const flatten = (stats, secretDC = false, defaultSkills = false) => {
382
462
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
383
463
  const untrained = stats.untrained;
384
- const skills = defaultSkills ? Object.assign({ acrobatics: untrained + stats.attributes.dexterity, arcana: untrained + stats.attributes.intelligence, athletics: untrained + stats.attributes.strength, crafting: untrained + stats.attributes.intelligence, deception: untrained + stats.attributes.charisma, diplomacy: untrained + stats.attributes.charisma, intimidation: untrained + stats.attributes.charisma, medicine: untrained + stats.attributes.wisdom, nature: untrained + stats.attributes.wisdom, occultism: untrained + stats.attributes.intelligence, performance: untrained + stats.attributes.charisma, religion: untrained + stats.attributes.wisdom, society: untrained + stats.attributes.intelligence, stealth: untrained + stats.attributes.dexterity, survival: untrained + stats.attributes.wisdom, thievery: untrained + stats.attributes.dexterity, piloting: untrained + stats.attributes.dexterity, computers: untrained + stats.attributes.intelligence }, stats.skills) : stats.skills;
385
- const lores = defaultSkills ? Object.assign(Object.assign({}, stats.lores), { other: {
464
+ const skills = defaultSkills ? {
465
+ acrobatics: untrained + stats.attributes.dexterity,
466
+ arcana: untrained + stats.attributes.intelligence,
467
+ athletics: untrained + stats.attributes.strength,
468
+ crafting: untrained + stats.attributes.intelligence,
469
+ deception: untrained + stats.attributes.charisma,
470
+ diplomacy: untrained + stats.attributes.charisma,
471
+ intimidation: untrained + stats.attributes.charisma,
472
+ medicine: untrained + stats.attributes.wisdom,
473
+ nature: untrained + stats.attributes.wisdom,
474
+ occultism: untrained + stats.attributes.intelligence,
475
+ performance: untrained + stats.attributes.charisma,
476
+ religion: untrained + stats.attributes.wisdom,
477
+ society: untrained + stats.attributes.intelligence,
478
+ stealth: untrained + stats.attributes.dexterity,
479
+ survival: untrained + stats.attributes.wisdom,
480
+ thievery: untrained + stats.attributes.dexterity,
481
+ piloting: untrained + stats.attributes.dexterity,
482
+ computers: untrained + stats.attributes.intelligence,
483
+ ...stats.skills,
484
+ } : stats.skills;
485
+ const lores = defaultSkills ? {
486
+ ...stats.lores,
487
+ other: {
386
488
  mod: untrained + stats.attributes.intelligence,
387
489
  name: "Other",
388
490
  info: ['untrained']
389
- } }) : stats.lores;
491
+ }
492
+ } : stats.lores;
390
493
  let melee = (0, lodash_1.entries)(stats.melee).map(([k, v]) => {
391
494
  var _a;
392
495
  return [k, {
@@ -416,7 +519,10 @@ const flatten = (stats, secretDC = false, defaultSkills = false) => {
416
519
  ];
417
520
  }
418
521
  const maxhp = stats.bump.default > 0 ? (stats.bump.hp ? (stats.bump.hp + stats.maxhp) : Math.max(Math.floor(stats.maxhp * 1.1), stats.maxhp + 10)) : stats.maxhp;
419
- const saveInfo = Object.assign(Object.assign({}, stats.saveInfo), { reflex: stats.bullwark > 0 ? [...stats.saveInfo.reflex, `+${stats.bullwark} more vs damage`] : stats.saveInfo.reflex });
522
+ const saveInfo = {
523
+ ...stats.saveInfo,
524
+ reflex: stats.bullwark > 0 ? [...stats.saveInfo.reflex, `+${stats.bullwark} more vs damage`] : stats.saveInfo.reflex,
525
+ };
420
526
  const untrainedSkillInfo = (0, lodash_1.entries)((0, lodash_1.mapValues)((0, lodash_1.groupBy)((0, lodash_1.difference)((0, lodash_1.keys)(skills), (0, lodash_1.keys)(stats.skills)), (k) => k), () => ['untrained']));
421
527
  const specifiedSkillInfo = (0, lodash_1.entries)(stats.skillInfo);
422
528
  const skillInfo = (0, lodash_1.mapValues)((0, lodash_1.groupBy)([...untrainedSkillInfo, ...specifiedSkillInfo], ([k]) => k), (list) => list.reduce((p, [, v]) => [...p, ...v], []));
@@ -435,7 +541,7 @@ const flatten = (stats, secretDC = false, defaultSkills = false) => {
435
541
  ['fort', stats.saves.fortitude + ((_c = stats.bump.saves) !== null && _c !== void 0 ? _c : stats.bump.default)],
436
542
  ['ref', stats.saves.reflex + ((_d = stats.bump.saves) !== null && _d !== void 0 ? _d : stats.bump.default)],
437
543
  ['perception', stats.perception + ((_e = stats.bump.perception) !== null && _e !== void 0 ? _e : stats.bump.default)],
438
- ...(0, lodash_1.entries)(skills.performance ? Object.assign(Object.assign({}, skills), { perfomance: skills.performance }) : skills).map(([k, v]) => { var _a; return [k, v + ((_a = stats.bump.skills) !== null && _a !== void 0 ? _a : stats.bump.default)]; }),
544
+ ...(0, lodash_1.entries)(skills.performance ? { ...skills, perfomance: skills.performance } : skills).map(([k, v]) => { var _a; return [k, v + ((_a = stats.bump.skills) !== null && _a !== void 0 ? _a : stats.bump.default)]; }),
439
545
  ...(0, lodash_1.entries)(lores).map(toLoreMod).map(([k, v]) => { var _a; return [k, v + ((_a = stats.bump.skills) !== null && _a !== void 0 ? _a : stats.bump.default)]; }),
440
546
  ...(0, lodash_1.entries)(lores).map(toLoreName),
441
547
  ...(0, lodash_1.entries)(lores).filter(([, v]) => v.info.length > 0).map(toLoreInfo),
@@ -587,56 +693,19 @@ const formatTracker = (tracker) => {
587
693
  return lines.join('\n');
588
694
  };
589
695
  exports.formatTracker = formatTracker;
590
- const sortFolder = () => __awaiter(void 0, void 0, void 0, function* () {
591
- const dir = yield (0, promises_1.readdir)('.');
592
- const summary = yield Promise.all(dir.map((file) => __awaiter(void 0, void 0, void 0, function* () {
593
- const stats = yield (0, promises_1.stat)(file);
696
+ const sortFolder = async () => {
697
+ const dir = await (0, promises_1.readdir)('.');
698
+ const summary = await Promise.all(dir.map(async (file) => {
699
+ const stats = await (0, promises_1.stat)(file);
594
700
  const timestamp = parseInt(stats.birthtimeMs.toFixed(0));
595
701
  return { file, timestamp };
596
- })));
702
+ }));
597
703
  const transformed = summary.sort((a, b) => a.timestamp - b.timestamp).map((s, index) => {
598
704
  const prefix = String(index + 1).padStart(3, '0');
599
705
  const name = s.file.replace('RU PFS Online - ', '').replace(/\s\[.+\]/, '');
600
706
  return { oldname: s.file, newname: name.startsWith('ooc') ? name : `${prefix} ${name}` };
601
707
  });
602
- yield Promise.all(transformed.map((t) => __awaiter(void 0, void 0, void 0, function* () { return (0, promises_1.rename)(t.oldname, t.newname); })));
708
+ await Promise.all(transformed.map(async (t) => (0, promises_1.rename)(t.oldname, t.newname)));
603
709
  return transformed;
604
- });
605
- exports.sortFolder = sortFolder;
606
- const screenPlay = (htmlContent) => {
607
- const dom = new jsdom_1.JSDOM(htmlContent);
608
- const document = dom.window.document;
609
- const outputLines = [];
610
- const preambleEntry = document.querySelector('.preamble__entry');
611
- if (preambleEntry) {
612
- outputLines.push(`SCENE: ${preambleEntry.textContent}`);
613
- outputLines.push('');
614
- }
615
- // Process all chatlog messages
616
- const messages = document.querySelectorAll('.chatlog__message');
617
- messages.forEach(message => {
618
- var _a, _b, _c, _d;
619
- const authorElement = message.querySelector('.chatlog__author');
620
- const contentElement = message.querySelector('.chatlog__content');
621
- if (!authorElement || !contentElement)
622
- return;
623
- const author = (_b = (_a = authorElement.textContent) === null || _a === void 0 ? void 0 : _a.trim()) !== null && _b !== void 0 ? _b : '';
624
- const content = (_d = (_c = contentElement.textContent) === null || _c === void 0 ? void 0 : _c.trim()) !== null && _d !== void 0 ? _d : '';
625
- // Skip bot tags in character names
626
- const characterName = author.replace(/\s*BOT$/, '');
627
- // Add character line
628
- outputLines.push(`${characterName.toUpperCase()}`);
629
- // Add dialogue/content (wrap long lines)
630
- const lines = content.split('\n').map((c) => (c
631
- .replace(/(—|--)/g, '-')
632
- // eslint-disable-next-line no-irregular-whitespace
633
- .replace(/(​|​)/g, '')
634
- .trim())).filter((c) => c.length);
635
- for (const line of lines) {
636
- outputLines.push(` ${line}`);
637
- }
638
- outputLines.push('');
639
- });
640
- return outputLines.join('\n');
641
710
  };
642
- exports.screenPlay = screenPlay;
711
+ exports.sortFolder = sortFolder;
package/dist/index.js CHANGED
@@ -1,21 +1,5 @@
1
1
  #!/usr/bin/env node
2
2
  "use strict";
3
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
4
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
5
- return new (P || (P = Promise))(function (resolve, reject) {
6
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
7
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
8
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
9
- step((generator = generator.apply(thisArg, _arguments || [])).next());
10
- });
11
- };
12
- var __asyncValues = (this && this.__asyncValues) || function (o) {
13
- if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
14
- var m = o[Symbol.asyncIterator], i;
15
- return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
16
- function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
17
- function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
18
- };
19
3
  var __importDefault = (this && this.__importDefault) || function (mod) {
20
4
  return (mod && mod.__esModule) ? mod : { "default": mod };
21
5
  };
@@ -35,14 +19,14 @@ program
35
19
  program.command('stub')
36
20
  .description('Generte a stat JSON template')
37
21
  .option('-o, --output <file>', 'output json')
38
- .action((option) => __awaiter(void 0, void 0, void 0, function* () {
22
+ .action(async (option) => {
39
23
  if (option.output) {
40
- yield promises_1.default.writeFile(option.output, (0, app_1.formatJSON)(app_1.stub), { encoding: 'utf-8' });
24
+ await promises_1.default.writeFile(option.output, (0, app_1.formatJSON)(app_1.stub), { encoding: 'utf-8' });
41
25
  }
42
26
  else {
43
27
  console.log((0, app_1.formatJSON)(app_1.stub));
44
28
  }
45
- }));
29
+ });
46
30
  program.command('table')
47
31
  .description('Generte a table configuration string')
48
32
  .argument('<string>', 'table name')
@@ -52,65 +36,52 @@ program.command('table')
52
36
  .option('-c, --scenario <string>', 'scenario')
53
37
  .option('-g, --gm <string>', 'gm')
54
38
  .option('-p, --players <string>', 'players')
55
- .action((argument, option) => __awaiter(void 0, void 0, void 0, function* () {
39
+ .action(async (argument, option) => {
56
40
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
57
41
  if (option.output) {
58
- yield promises_1.default.writeFile(option.output, (0, app_1.formatTable)((_a = option.table) !== null && _a !== void 0 ? _a : '1', (_b = option.season) !== null && _b !== void 0 ? _b : '1', (_c = option.scenario) !== null && _c !== void 0 ? _c : '1', argument, (_d = option.gm) !== null && _d !== void 0 ? _d : '@lammonaaf', (_e = option.players) !== null && _e !== void 0 ? _e : '<players>'), { encoding: 'utf-8' });
42
+ await promises_1.default.writeFile(option.output, (0, app_1.formatTable)((_a = option.table) !== null && _a !== void 0 ? _a : '1', (_b = option.season) !== null && _b !== void 0 ? _b : '1', (_c = option.scenario) !== null && _c !== void 0 ? _c : '1', argument, (_d = option.gm) !== null && _d !== void 0 ? _d : '@lammonaaf', (_e = option.players) !== null && _e !== void 0 ? _e : '<players>'), { encoding: 'utf-8' });
59
43
  }
60
44
  else {
61
45
  console.log((0, app_1.formatTable)((_f = option.table) !== null && _f !== void 0 ? _f : '1', (_g = option.season) !== null && _g !== void 0 ? _g : '1', (_h = option.scenario) !== null && _h !== void 0 ? _h : '1', argument, (_j = option.gm) !== null && _j !== void 0 ? _j : '@lammonaaf', (_k = option.players) !== null && _k !== void 0 ? _k : '<players>'));
62
46
  }
63
- }));
47
+ });
64
48
  program.command('hp')
65
49
  .description('Generte an hp bar')
66
50
  .argument('<string>', 'hp/maxhp')
67
- .action((argument) => __awaiter(void 0, void 0, void 0, function* () {
51
+ .action(async (argument) => {
68
52
  console.log((0, app_1.formatHP)(argument));
69
- }));
53
+ });
70
54
  program.command('sort')
71
55
  .description('Sorts log file folder and renames files')
72
- .action(() => __awaiter(void 0, void 0, void 0, function* () {
73
- console.log(yield (0, app_1.sortFolder)());
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
- }));
56
+ .action(async () => {
57
+ console.log(await (0, app_1.sortFolder)());
58
+ });
88
59
  program.command('flat')
89
60
  .description('Generte a special flat npc tsv')
90
61
  .option('-n, --name <string>', 'npc name')
91
62
  .option('-o, --output <file>', 'output json')
92
- .action((option) => __awaiter(void 0, void 0, void 0, function* () {
63
+ .action(async (option) => {
93
64
  var _a, _b;
94
65
  if (option.output) {
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' });
66
+ await 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' });
96
67
  }
97
68
  else {
98
69
  console.log((0, app_1.fromatMap)((_b = option.name) !== null && _b !== void 0 ? _b : 'flat', app_1.flatMap));
99
70
  }
100
- }));
71
+ });
101
72
  program.command('dice')
102
73
  .description('Generte a special dice npc tsv')
103
74
  .option('-n, --name <string>', 'npc name')
104
75
  .option('-o, --output <file>', 'output json')
105
- .action((option) => __awaiter(void 0, void 0, void 0, function* () {
76
+ .action(async (option) => {
106
77
  var _a, _b;
107
78
  if (option.output) {
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' });
79
+ await 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' });
109
80
  }
110
81
  else {
111
82
  console.log((0, app_1.fromatMap)((_b = option.name) !== null && _b !== void 0 ? _b : 'dice', app_1.diceMap));
112
83
  }
113
- }));
84
+ });
114
85
  program.command('statblock')
115
86
  .description('Generte a stat JSON from Paizo creature statblock')
116
87
  .argument('<file>', 'input text file')
@@ -122,84 +93,84 @@ program.command('statblock')
122
93
  .option('-s, --secretDC', 'produce secret DCs (tsv only)')
123
94
  .option('-d, --defaultSkills', 'produce values for untrained skills (tsv only)')
124
95
  .option('-o, --output <file>', 'output file name')
125
- .action((argument, option) => __awaiter(void 0, void 0, void 0, function* () {
96
+ .action(async (argument, option) => {
126
97
  var _a, _b;
127
- const file = yield promises_1.default.readFile(argument, { encoding: 'utf-8' });
98
+ const file = await promises_1.default.readFile(argument, { encoding: 'utf-8' });
128
99
  const alias = (_a = option.alias) !== null && _a !== void 0 ? _a : (option.abbreviate ? null : (option.output ? path_1.default.parse(option.output).name : path_1.default.parse(argument).name));
129
100
  const stats = (0, app_1.parseStatblock)((_b = option.name) !== null && _b !== void 0 ? _b : null, file, alias);
130
101
  if (option.tsv) {
131
102
  const output = option.output ? option.output : path_1.default.join(path_1.default.parse(argument).dir, stats.alias + '.tsv');
132
- yield promises_1.default.writeFile(output, (0, app_1.formatTSV)(stats, option.secretDC, option.defaultSkills), { encoding: 'utf-8' });
103
+ await promises_1.default.writeFile(output, (0, app_1.formatTSV)(stats, option.secretDC, option.defaultSkills), { encoding: 'utf-8' });
133
104
  }
134
105
  else if (option.command) {
135
106
  const output = option.output ? option.output : path_1.default.join(path_1.default.parse(argument).dir, stats.alias + '-command.txt');
136
- yield promises_1.default.writeFile(output, (0, app_1.formatCommand)(stats, option.secretDC, option.defaultSkills), { encoding: 'utf-8' });
107
+ await promises_1.default.writeFile(output, (0, app_1.formatCommand)(stats, option.secretDC, option.defaultSkills), { encoding: 'utf-8' });
137
108
  }
138
109
  else {
139
110
  const output = option.output ? option.output : path_1.default.join(path_1.default.parse(argument).dir, stats.alias + '.json');
140
- yield promises_1.default.writeFile(output, (0, app_1.formatJSON)(stats), { encoding: 'utf-8' });
111
+ await promises_1.default.writeFile(output, (0, app_1.formatJSON)(stats), { encoding: 'utf-8' });
141
112
  }
142
- }));
113
+ });
143
114
  program.command('tsv')
144
115
  .description('Generte a tsv file from JSON')
145
116
  .argument('<file>', 'input json')
146
117
  .option('-o, --output <file>', 'output tsv')
147
118
  .option('-s, --secretDC', 'produce secret DCs')
148
119
  .option('-d, --defaultSkills', 'produce values for untrained skills')
149
- .action((argument, option) => __awaiter(void 0, void 0, void 0, function* () {
150
- const file = yield promises_1.default.readFile(argument, { encoding: 'utf-8' });
120
+ .action(async (argument, option) => {
121
+ const file = await promises_1.default.readFile(argument, { encoding: 'utf-8' });
151
122
  const stats = (0, app_1.parseJSON)(file);
152
123
  const output = option.output ? option.output : path_1.default.join(path_1.default.parse(argument).dir, path_1.default.parse(argument).name + '.tsv');
153
- yield promises_1.default.writeFile(output, (0, app_1.formatTSV)(stats, option.secretDC, option.defaultSkills), { encoding: 'utf-8' });
154
- }));
124
+ await promises_1.default.writeFile(output, (0, app_1.formatTSV)(stats, option.secretDC, option.defaultSkills), { encoding: 'utf-8' });
125
+ });
155
126
  program.command('command')
156
127
  .description('Generte a creation command file from JSON')
157
128
  .argument('<file>', 'input json')
158
129
  .option('-o, --output <file>', 'output txt')
159
130
  .option('-s, --secretDC', 'produce secret DCs')
160
131
  .option('-d, --defaultSkills', 'produce values for untrained skills')
161
- .action((argument, option) => __awaiter(void 0, void 0, void 0, function* () {
162
- const file = yield promises_1.default.readFile(argument, { encoding: 'utf-8' });
132
+ .action(async (argument, option) => {
133
+ const file = await promises_1.default.readFile(argument, { encoding: 'utf-8' });
163
134
  const stats = (0, app_1.parseJSON)(file);
164
135
  const output = option.output ? option.output : path_1.default.join(path_1.default.parse(argument).dir, path_1.default.parse(argument).name + '-command.txt');
165
- yield promises_1.default.writeFile(output, (0, app_1.formatCommand)(stats, option.secretDC, option.defaultSkills), { encoding: 'utf-8' });
166
- }));
136
+ await promises_1.default.writeFile(output, (0, app_1.formatCommand)(stats, option.secretDC, option.defaultSkills), { encoding: 'utf-8' });
137
+ });
167
138
  program.command('newtracker')
168
139
  .argument('<file>', 'input text file')
169
140
  .option('-o, --output <file>', 'output file name')
170
- .action((argument, option) => __awaiter(void 0, void 0, void 0, function* () {
171
- const file = yield promises_1.default.readFile(argument, { encoding: 'utf-8' });
141
+ .action(async (argument, option) => {
142
+ const file = await promises_1.default.readFile(argument, { encoding: 'utf-8' });
172
143
  const tracker = (0, app_1.newtracker)(file);
173
144
  if (option.output) {
174
- yield promises_1.default.writeFile(option.output, JSON.stringify(tracker, undefined, 2), { encoding: 'utf-8' });
145
+ await promises_1.default.writeFile(option.output, JSON.stringify(tracker, undefined, 2), { encoding: 'utf-8' });
175
146
  }
176
147
  else {
177
148
  console.log(JSON.stringify(tracker, undefined, 2));
178
149
  }
179
- }));
150
+ });
180
151
  program.command('tracker')
181
152
  .argument('<file>', 'input text file')
182
153
  .option('-o, --output <file>', 'output file name')
183
- .action((argument, option) => __awaiter(void 0, void 0, void 0, function* () {
184
- const file = yield promises_1.default.readFile(argument, { encoding: 'utf-8' });
154
+ .action(async (argument, option) => {
155
+ const file = await promises_1.default.readFile(argument, { encoding: 'utf-8' });
185
156
  const tracker = (0, app_1.parseTracker)(file);
186
157
  if (option.output) {
187
- yield promises_1.default.writeFile(option.output, (0, app_1.formatTracker)(tracker), { encoding: 'utf-8' });
158
+ await promises_1.default.writeFile(option.output, (0, app_1.formatTracker)(tracker), { encoding: 'utf-8' });
188
159
  }
189
160
  else {
190
161
  console.log((0, app_1.formatTracker)(tracker));
191
162
  }
192
- }));
163
+ });
193
164
  program.command('track')
194
165
  .argument('<file>', 'input text file')
195
166
  .option('-o, --output <file>', 'output file name')
196
- .action((argument, option) => __awaiter(void 0, void 0, void 0, function* () {
167
+ .action(async (argument, option) => {
197
168
  const iterator = promises_1.default.watch(argument);
198
- const invoke = (filename) => __awaiter(void 0, void 0, void 0, function* () {
199
- const file = yield promises_1.default.readFile(filename, { encoding: 'utf-8' });
169
+ const invoke = async (filename) => {
170
+ const file = await promises_1.default.readFile(filename, { encoding: 'utf-8' });
200
171
  const tracker = (0, app_1.parseTracker)(file);
201
172
  if (option.output) {
202
- yield promises_1.default.writeFile(option.output, (0, app_1.formatTracker)(tracker), { encoding: 'utf-8' });
173
+ await promises_1.default.writeFile(option.output, (0, app_1.formatTracker)(tracker), { encoding: 'utf-8' });
203
174
  }
204
175
  else {
205
176
  console.clear();
@@ -207,37 +178,24 @@ program.command('track')
207
178
  clipboardy_1.default.writeSync(track);
208
179
  console.log(track);
209
180
  }
210
- });
211
- yield invoke(argument);
212
- yield Promise.all([
213
- (() => __awaiter(void 0, void 0, void 0, function* () {
214
- var _a, e_1, _b, _c;
215
- var _d;
216
- try {
217
- for (var _e = true, iterator_1 = __asyncValues(iterator), iterator_1_1; iterator_1_1 = yield iterator_1.next(), _a = iterator_1_1.done, !_a; _e = true) {
218
- _c = iterator_1_1.value;
219
- _e = false;
220
- const value = _c;
221
- yield invoke((_d = value.filename) !== null && _d !== void 0 ? _d : argument);
222
- }
223
- }
224
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
225
- finally {
226
- try {
227
- if (!_e && !_a && (_b = iterator_1.return)) yield _b.call(iterator_1);
228
- }
229
- finally { if (e_1) throw e_1.error; }
181
+ };
182
+ await invoke(argument);
183
+ await Promise.all([
184
+ (async () => {
185
+ var _a;
186
+ for await (const value of iterator) {
187
+ await invoke((_a = value.filename) !== null && _a !== void 0 ? _a : argument);
230
188
  }
231
- }))(),
232
- (() => __awaiter(void 0, void 0, void 0, function* () {
189
+ })(),
190
+ (async () => {
233
191
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
234
192
  const rl = readline_1.default.createInterface({
235
193
  input: process.stdin,
236
194
  output: process.stdout
237
195
  });
238
196
  while (true) {
239
- yield new Promise((resolve) => setTimeout(resolve, 500));
240
- let input = yield new Promise((resolve) => (rl.question('> ', resolve)));
197
+ await new Promise((resolve) => setTimeout(resolve, 500));
198
+ let input = await new Promise((resolve) => (rl.question('> ', resolve)));
241
199
  const commands = [{
242
200
  regex: /^\s*[bB]\s*(\d+)/,
243
201
  map: (match) => ({ command: 'block', index: parseInt(match[1], 10) })
@@ -372,7 +330,7 @@ program.command('track')
372
330
  input = input.slice(match[0].length);
373
331
  actions.push(action);
374
332
  }
375
- const file = yield promises_1.default.readFile(argument, { encoding: 'utf-8' });
333
+ const file = await promises_1.default.readFile(argument, { encoding: 'utf-8' });
376
334
  let tracker = (0, app_1.parseTracker)(file);
377
335
  for (const action of actions) {
378
336
  if (action.command === 'block') {
@@ -441,7 +399,10 @@ program.command('track')
441
399
  }
442
400
  }
443
401
  else if (action.command === 'delete') {
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)) })));
402
+ tracker = tracker.filter((c) => !(c.id === action.tag || c.alias === action.tag || c.name == action.tag)).map((p) => ({
403
+ ...p,
404
+ children: p.children.filter((c) => !(c.id === action.tag || c.alias === action.tag || c.name == action.tag)),
405
+ }));
445
406
  }
446
407
  else if (action.command === 'purge') {
447
408
  tracker = tracker.filter((c) => !c.foe);
@@ -575,9 +536,9 @@ program.command('track')
575
536
  tracker.push(app_1.charSchema.parse({ foe: true, name: action.name, alias: action.alias, maxhp: action.hp, hp: action.hp }));
576
537
  }
577
538
  }
578
- yield promises_1.default.writeFile(argument, JSON.stringify(tracker, undefined, 2), { encoding: 'utf-8' });
539
+ await promises_1.default.writeFile(argument, JSON.stringify(tracker, undefined, 2), { encoding: 'utf-8' });
579
540
  }
580
- }))(),
541
+ })(),
581
542
  ]);
582
- }));
543
+ });
583
544
  program.parse();
@@ -0,0 +1,13 @@
1
+ export interface NormalisedLine {
2
+ text: string;
3
+ }
4
+ export interface ClassifiedLine {
5
+ text: string;
6
+ kind: string;
7
+ lineFrom: number;
8
+ lineTo: number;
9
+ }
10
+ export declare function normaliseStatblockLines(source: string): NormalisedLine[];
11
+ export declare function classifyStatblockLines(source: string): ClassifiedLine[];
12
+ export declare function getLine(lines: ClassifiedLine[], kind: string): string;
13
+ export declare function listLines(lines: ClassifiedLine[], kind: string): string;