pf2e-sage-stats 0.3.2 → 0.4.0

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.d.ts CHANGED
@@ -566,40 +566,161 @@ export declare const charSchema: zod.ZodObject<{
566
566
  }[] | undefined;
567
567
  }>;
568
568
  export type CharSchema = zod.infer<typeof charSchema>;
569
+ export declare const trackerSchema: zod.ZodObject<{
570
+ title: zod.ZodOptional<zod.ZodString>;
571
+ map: zod.ZodOptional<zod.ZodString>;
572
+ mapURL: zod.ZodOptional<zod.ZodString>;
573
+ description: zod.ZodOptional<zod.ZodString>;
574
+ chars: zod.ZodArray<zod.ZodObject<{
575
+ init: zod.ZodDefault<zod.ZodNumber>;
576
+ foe: zod.ZodDefault<zod.ZodBoolean>;
577
+ state: zod.ZodDefault<zod.ZodUnion<[zod.ZodLiteral<"empty">, zod.ZodLiteral<"arrow">, zod.ZodLiteral<"check">, zod.ZodLiteral<"cross">]>>;
578
+ name: zod.ZodDefault<zod.ZodString>;
579
+ alias: zod.ZodDefault<zod.ZodString>;
580
+ id: zod.ZodDefault<zod.ZodString>;
581
+ hp: zod.ZodDefault<zod.ZodNumber>;
582
+ temphp: zod.ZodDefault<zod.ZodNumber>;
583
+ maxhp: zod.ZodDefault<zod.ZodNumber>;
584
+ conditions: zod.ZodDefault<zod.ZodString>;
585
+ children: zod.ZodDefault<zod.ZodArray<zod.ZodObject<{
586
+ name: zod.ZodDefault<zod.ZodString>;
587
+ alias: zod.ZodDefault<zod.ZodString>;
588
+ id: zod.ZodDefault<zod.ZodString>;
589
+ hp: zod.ZodDefault<zod.ZodNumber>;
590
+ temphp: zod.ZodDefault<zod.ZodNumber>;
591
+ maxhp: zod.ZodDefault<zod.ZodNumber>;
592
+ conditions: zod.ZodDefault<zod.ZodString>;
593
+ }, "strip", zod.ZodTypeAny, {
594
+ hp: number;
595
+ name: string;
596
+ alias: string;
597
+ maxhp: number;
598
+ id: string;
599
+ temphp: number;
600
+ conditions: string;
601
+ }, {
602
+ hp?: number | undefined;
603
+ name?: string | undefined;
604
+ alias?: string | undefined;
605
+ maxhp?: number | undefined;
606
+ id?: string | undefined;
607
+ temphp?: number | undefined;
608
+ conditions?: string | undefined;
609
+ }>, "many">>;
610
+ }, "strip", zod.ZodTypeAny, {
611
+ hp: number;
612
+ name: string;
613
+ alias: string;
614
+ maxhp: number;
615
+ id: string;
616
+ temphp: number;
617
+ conditions: string;
618
+ init: number;
619
+ foe: boolean;
620
+ state: "empty" | "arrow" | "check" | "cross";
621
+ children: {
622
+ hp: number;
623
+ name: string;
624
+ alias: string;
625
+ maxhp: number;
626
+ id: string;
627
+ temphp: number;
628
+ conditions: string;
629
+ }[];
630
+ }, {
631
+ hp?: number | undefined;
632
+ name?: string | undefined;
633
+ alias?: string | undefined;
634
+ maxhp?: number | undefined;
635
+ id?: string | undefined;
636
+ temphp?: number | undefined;
637
+ conditions?: string | undefined;
638
+ init?: number | undefined;
639
+ foe?: boolean | undefined;
640
+ state?: "empty" | "arrow" | "check" | "cross" | undefined;
641
+ children?: {
642
+ hp?: number | undefined;
643
+ name?: string | undefined;
644
+ alias?: string | undefined;
645
+ maxhp?: number | undefined;
646
+ id?: string | undefined;
647
+ temphp?: number | undefined;
648
+ conditions?: string | undefined;
649
+ }[] | undefined;
650
+ }>, "many">;
651
+ }, "strip", zod.ZodTypeAny, {
652
+ chars: {
653
+ hp: number;
654
+ name: string;
655
+ alias: string;
656
+ maxhp: number;
657
+ id: string;
658
+ temphp: number;
659
+ conditions: string;
660
+ init: number;
661
+ foe: boolean;
662
+ state: "empty" | "arrow" | "check" | "cross";
663
+ children: {
664
+ hp: number;
665
+ name: string;
666
+ alias: string;
667
+ maxhp: number;
668
+ id: string;
669
+ temphp: number;
670
+ conditions: string;
671
+ }[];
672
+ }[];
673
+ title?: string | undefined;
674
+ description?: string | undefined;
675
+ map?: string | undefined;
676
+ mapURL?: string | undefined;
677
+ }, {
678
+ chars: {
679
+ hp?: number | undefined;
680
+ name?: string | undefined;
681
+ alias?: string | undefined;
682
+ maxhp?: number | undefined;
683
+ id?: string | undefined;
684
+ temphp?: number | undefined;
685
+ conditions?: string | undefined;
686
+ init?: number | undefined;
687
+ foe?: boolean | undefined;
688
+ state?: "empty" | "arrow" | "check" | "cross" | undefined;
689
+ children?: {
690
+ hp?: number | undefined;
691
+ name?: string | undefined;
692
+ alias?: string | undefined;
693
+ maxhp?: number | undefined;
694
+ id?: string | undefined;
695
+ temphp?: number | undefined;
696
+ conditions?: string | undefined;
697
+ }[] | undefined;
698
+ }[];
699
+ title?: string | undefined;
700
+ description?: string | undefined;
701
+ map?: string | undefined;
702
+ mapURL?: string | undefined;
703
+ }>;
704
+ export type Tracker = zod.infer<typeof trackerSchema>;
569
705
  export declare const flatMap: Record<string, string>;
570
706
  export declare const diceMap: Record<string, string>;
571
707
  export declare const fromatMap: (name: string, map: Record<string, string>) => string;
572
708
  export declare const formatJSON: (stats: Schema) => string;
573
709
  export declare const parseJSON: (json: string) => Schema;
574
- export declare const parseTracker: (json: string) => CharSchema[];
710
+ export declare const parseTracker: (json: string) => Tracker;
575
711
  export declare const parseStatblock: (name: string | null, _statblock: string, alias: string | null) => Schema;
576
712
  export declare const flatten: (stats: Schema, secretDC?: boolean, defaultSkills?: boolean) => Record<string, string | number>;
577
713
  export declare const formatTSV: (stats: Schema, secretDC?: boolean, defaultSkills?: boolean) => string;
578
714
  export declare const formatCommand: (stats: Schema, secretDC?: boolean, defaultSkills?: boolean) => string;
579
715
  export declare const formatTable: (table: string, season: string, scenario: string, _name: string, gm: string, players: string) => string;
580
716
  export declare const formatHP: (arg: string) => string;
581
- export declare const newtracker: (status: string) => {
582
- hp: number;
583
- name: string;
584
- alias: string;
585
- maxhp: number;
586
- id: string;
587
- temphp: number;
588
- conditions: string;
589
- init: number;
590
- foe: boolean;
591
- state: "empty" | "arrow" | "check" | "cross";
592
- children: {
593
- hp: number;
594
- name: string;
595
- alias: string;
596
- maxhp: number;
597
- id: string;
598
- temphp: number;
599
- conditions: string;
600
- }[];
601
- }[];
602
- export declare const formatTracker: (tracker: CharSchema[]) => string;
717
+ export declare const newtracker: (status: string, desc: {
718
+ title?: string;
719
+ map?: string;
720
+ mapURL?: string;
721
+ description?: string;
722
+ }) => Tracker;
723
+ export declare const formatTracker: (tracker: Tracker) => string;
603
724
  export type TrackerCommand = {
604
725
  command: 'block';
605
726
  index: number;
@@ -614,6 +735,23 @@ export type TrackerCommand = {
614
735
  name?: string;
615
736
  alias?: string;
616
737
  hp?: number;
738
+ } | {
739
+ command: 'friend';
740
+ name?: string;
741
+ alias?: string;
742
+ hp?: number;
743
+ } | {
744
+ command: 'update';
745
+ tag: string;
746
+ name?: string;
747
+ alias?: string;
748
+ hp?: number;
749
+ } | {
750
+ command: 'child';
751
+ tag: string;
752
+ name?: string;
753
+ alias?: string;
754
+ hp?: number;
617
755
  } | {
618
756
  command: 'heal';
619
757
  } | {
@@ -682,11 +820,11 @@ export type TrackerCommand = {
682
820
  tag: string;
683
821
  };
684
822
  export type TrackerUpdate = {
685
- tracker: CharSchema[];
823
+ tracker: Tracker;
686
824
  exit: boolean;
687
825
  };
688
826
  export declare const parseTrackerCommands: (line: string) => TrackerCommand[];
689
- export declare const applyTrackerCommands: (tracker: CharSchema[], actions: TrackerCommand[]) => TrackerUpdate;
827
+ export declare const applyTrackerCommands: (tracker: Tracker, actions: TrackerCommand[]) => TrackerUpdate;
690
828
  export declare const sortFolder: () => Promise<{
691
829
  oldname: string;
692
830
  newname: string;
package/dist/app.js CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.sortFolder = exports.applyTrackerCommands = exports.parseTrackerCommands = 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.applyTrackerCommands = exports.parseTrackerCommands = 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.trackerSchema = exports.charSchema = exports.stub = void 0;
7
7
  const zod_1 = __importDefault(require("zod"));
8
8
  const tsv_1 = require("tsv");
9
9
  const promises_1 = require("fs/promises");
@@ -199,6 +199,13 @@ exports.charSchema = zod_1.default.object({
199
199
  conditions: zod_1.default.string().default(''),
200
200
  children: zod_1.default.array(childSchema).default([]),
201
201
  });
202
+ exports.trackerSchema = zod_1.default.object({
203
+ title: zod_1.default.string().optional(),
204
+ map: zod_1.default.string().optional(),
205
+ mapURL: zod_1.default.string().optional(),
206
+ description: zod_1.default.string().optional(),
207
+ chars: zod_1.default.array(exports.charSchema),
208
+ });
202
209
  exports.flatMap = {
203
210
  ...([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
211
  c: 'd20 >= 5 flat;',
@@ -234,7 +241,7 @@ const formatJSON = (stats) => JSON.stringify(stats, undefined, 2);
234
241
  exports.formatJSON = formatJSON;
235
242
  const parseJSON = (json) => schema.parse(JSON.parse(json));
236
243
  exports.parseJSON = parseJSON;
237
- const parseTracker = (json) => zod_1.default.array(exports.charSchema).parse(JSON.parse(json));
244
+ const parseTracker = (json) => exports.trackerSchema.parse(JSON.parse(json));
238
245
  exports.parseTracker = parseTracker;
239
246
  const locateName = (statblock) => {
240
247
  const regex = /^([^()]+?)(\s+\(\d+\))?\s+\S+\s+(-?\d+)$/m;
@@ -612,7 +619,7 @@ const formatHP = (arg) => {
612
619
  return _formatHP(negative ? maxhp - hp : hp, maxhp);
613
620
  };
614
621
  exports.formatHP = formatHP;
615
- const newtracker = (status) => {
622
+ const newtracker = (status, desc) => {
616
623
  var _a, _b;
617
624
  const regex = /((.+)\s+\((\d+)\/(\d+)\s+HP\):(.*)(\n>(.+)\s+\((\d+)\/(\d+)\s+HP\):(.*))*)/gm;
618
625
  const match = status.match(regex);
@@ -638,17 +645,18 @@ const newtracker = (status) => {
638
645
  }
639
646
  tracker.push(char);
640
647
  }
641
- return tracker;
648
+ return { ...desc, chars: tracker };
642
649
  };
643
650
  exports.newtracker = newtracker;
644
651
  const formatTracker = (tracker) => {
652
+ var _a;
645
653
  const aliasSpace = (t) => (t.alias.length > 0 ? 0 : 5);
646
654
  const nameLengthWithAlias = (t) => t.name.length - aliasSpace(t);
647
- const nameLength = tracker.reduce((p, c) => {
655
+ const nameLength = tracker.chars.reduce((p, c) => {
648
656
  const length = c.children.reduce((pp, cc) => pp > nameLengthWithAlias(cc) ? pp : nameLengthWithAlias(cc), nameLengthWithAlias(c));
649
657
  return p > length ? p : length;
650
658
  }, 0);
651
- const hpLength = tracker.reduce((p, c) => {
659
+ const hpLength = tracker.chars.reduce((p, c) => {
652
660
  const hpLength = c.maxhp.toString().length + 1 + c.hp.toString().length + (c.temphp > 1 ? c.temphp.toString().length + 1 : 0);
653
661
  const length = c.children.reduce((pp, cc) => {
654
662
  const hhpLength = cc.maxhp.toString().length + 1 + cc.hp.toString().length + (cc.temphp > 1 ? cc.temphp.toString().length + 1 : 0);
@@ -669,9 +677,9 @@ const formatTracker = (tracker) => {
669
677
  ':limping:',
670
678
  ':dying:',
671
679
  ].reverse();
672
- const lines = tracker.sort((a, b) => (a.init === b.init) ? (b.foe ? 1 : 0) - (a.foe ? 1 : 0) : b.init - a.init).flatMap((char, index) => {
680
+ const lines = tracker.chars.sort((a, b) => (a.init === b.init) ? (b.foe ? 1 : 0) - (a.foe ? 1 : 0) : b.init - a.init).flatMap((char, index) => {
673
681
  const ls = [];
674
- if (tracker[index - 1] && tracker[index - 1].foe !== char.foe) {
682
+ if (tracker.chars[index - 1] && tracker.chars[index - 1].foe !== char.foe) {
675
683
  ls.push('');
676
684
  }
677
685
  const hp = !char.foe && char.hp > 0 ? (`${char.hp}${char.temphp > 0 ? `+${char.temphp}` : ''}/${char.maxhp}`.padStart(hpLength)) : char.hp > 0 ? (`-${char.maxhp - char.hp}${char.temphp > 0 ? `+${char.temphp}` : ''}`.padStart(hpLength)) : (`${char.hp}${char.temphp > 0 ? `+${char.temphp}` : ''}`.padStart(hpLength));
@@ -689,6 +697,18 @@ const formatTracker = (tracker) => {
689
697
  }
690
698
  return ls;
691
699
  });
700
+ if (tracker.description) {
701
+ lines.unshift('');
702
+ lines.unshift(`${tracker.description}`);
703
+ }
704
+ if (tracker.mapURL) {
705
+ lines.unshift('');
706
+ lines.unshift(`[**${((_a = tracker.map) !== null && _a !== void 0 ? _a : 'Map').toUpperCase()}**](${tracker.mapURL})`);
707
+ }
708
+ if (tracker.title) {
709
+ lines.unshift('');
710
+ lines.unshift(`## ${tracker.title}`);
711
+ }
692
712
  lines.push(':spacer:');
693
713
  return lines.join('\n');
694
714
  };
@@ -708,6 +728,15 @@ const trackerCommands = [{
708
728
  }, {
709
729
  regex: /^\s*foe(\s+(\S+))?(\s+(\S+))?(\s+(\d+))?/i,
710
730
  map: (match) => ({ command: 'foe', name: match[2], alias: match[4], hp: match[6] ? parseInt(match[6], 10) : undefined }),
731
+ }, {
732
+ regex: /^\s*friend(\s+(\S+))?(\s+(\S+))?(\s+(\d+))?/i,
733
+ map: (match) => ({ command: 'friend', name: match[2], alias: match[4], hp: match[6] ? parseInt(match[6], 10) : undefined }),
734
+ }, {
735
+ regex: /^\s*child\s+(\S+)(\s+(\S+))?(\s+(\S+))?(\s+(\d+))?/i,
736
+ map: (match) => ({ command: 'child', tag: match[1], name: match[3], alias: match[5], hp: match[7] ? parseInt(match[7], 10) : undefined }),
737
+ }, {
738
+ regex: /^\s*update\s+(\S+)(\s+(\S+))?(\s+(\S+))?(\s+(\d+))?/i,
739
+ map: (match) => ({ command: 'update', tag: match[1], name: match[3], alias: match[5], hp: match[7] ? parseInt(match[7], 10) : undefined }),
711
740
  }, {
712
741
  regex: /^\s*heal/i,
713
742
  map: () => ({ command: 'heal' }),
@@ -815,13 +844,13 @@ const parseTrackerCommands = (line) => {
815
844
  };
816
845
  exports.parseTrackerCommands = parseTrackerCommands;
817
846
  const sameTag = (entry, tag) => (entry.id === tag || entry.alias === tag || entry.name === tag);
818
- const findCharacter = (tracker, tag) => (tracker.find((entry) => sameTag(entry, tag)));
847
+ const findCharacter = (tracker, tag) => (tracker.chars.find((entry) => sameTag(entry, tag)));
819
848
  const findCharacterOrChild = (tracker, tag) => {
820
849
  var _a;
821
- return ((_a = findCharacter(tracker, tag)) !== null && _a !== void 0 ? _a : tracker.flatMap((entry) => entry.children).find((entry) => sameTag(entry, tag)));
850
+ return ((_a = findCharacter(tracker, tag)) !== null && _a !== void 0 ? _a : tracker.chars.flatMap((entry) => entry.children).find((entry) => sameTag(entry, tag)));
822
851
  };
823
852
  const initiativeBlocks = (tracker) => {
824
- const sorted = [...tracker].sort((a, b) => (a.init === b.init) ? (b.foe ? 1 : 0) - (a.foe ? 1 : 0) : b.init - a.init);
853
+ const sorted = [...tracker.chars].sort((a, b) => (a.init === b.init) ? (b.foe ? 1 : 0) - (a.foe ? 1 : 0) : b.init - a.init);
825
854
  const blocks = [[sorted[0]]];
826
855
  for (let i = 1; i < sorted.length; ++i) {
827
856
  if (sorted[i].foe === blocks[blocks.length - 1][0].foe) {
@@ -887,14 +916,20 @@ const applyTrackerCommand = (tracker, action) => {
887
916
  return tracker;
888
917
  }
889
918
  case 'delete':
890
- return tracker.filter((entry) => !sameTag(entry, action.tag)).map((entry) => ({
891
- ...entry,
892
- children: entry.children.filter((child) => !sameTag(child, action.tag)),
893
- }));
919
+ return {
920
+ ...tracker,
921
+ chars: tracker.chars.filter((entry) => !sameTag(entry, action.tag)).map((entry) => ({
922
+ ...entry,
923
+ children: entry.children.filter((child) => !sameTag(child, action.tag)),
924
+ })),
925
+ };
894
926
  case 'purge':
895
- return tracker.filter((entry) => !entry.foe);
927
+ return {
928
+ ...tracker,
929
+ chars: tracker.chars.filter((entry) => !entry.foe),
930
+ };
896
931
  case 'heal':
897
- tracker.forEach((char) => {
932
+ tracker.chars.forEach((char) => {
898
933
  char.hp = char.maxhp;
899
934
  char.children.forEach((child) => {
900
935
  child.hp = child.maxhp;
@@ -902,7 +937,7 @@ const applyTrackerCommand = (tracker, action) => {
902
937
  });
903
938
  return tracker;
904
939
  case 'reset':
905
- tracker.forEach((char) => {
940
+ tracker.chars.forEach((char) => {
906
941
  char.state = 'empty';
907
942
  });
908
943
  return tracker;
@@ -928,7 +963,7 @@ const applyTrackerCommand = (tracker, action) => {
928
963
  return tracker;
929
964
  }
930
965
  case 'blank':
931
- tracker.forEach((item) => {
966
+ tracker.chars.forEach((item) => {
932
967
  item.conditions = '';
933
968
  item.children.forEach((child) => {
934
969
  child.conditions = '';
@@ -986,8 +1021,34 @@ const applyTrackerCommand = (tracker, action) => {
986
1021
  return tracker;
987
1022
  }
988
1023
  case 'foe':
989
- tracker.push(exports.charSchema.parse({ foe: true, name: action.name, alias: action.alias, maxhp: action.hp, hp: action.hp }));
1024
+ tracker.chars.push(exports.charSchema.parse({ foe: true, name: action.name, alias: action.alias, maxhp: action.hp, hp: action.hp }));
1025
+ return tracker;
1026
+ case 'friend':
1027
+ tracker.chars.push(exports.charSchema.parse({ foe: false, name: action.name, alias: action.alias, maxhp: action.hp, hp: action.hp }));
1028
+ return tracker;
1029
+ case 'child': {
1030
+ const item = findCharacter(tracker, action.tag);
1031
+ if (item) {
1032
+ item.children.push(childSchema.parse({ name: action.name, alias: action.alias, maxhp: action.hp, hp: action.hp }));
1033
+ }
990
1034
  return tracker;
1035
+ }
1036
+ case 'update': {
1037
+ const item = findCharacterOrChild(tracker, action.tag);
1038
+ if (item) {
1039
+ if (action.name) {
1040
+ item.name = action.name;
1041
+ }
1042
+ if (action.alias) {
1043
+ item.alias = action.alias;
1044
+ }
1045
+ if (action.hp) {
1046
+ item.maxhp = action.hp;
1047
+ item.hp = action.hp;
1048
+ }
1049
+ }
1050
+ return tracker;
1051
+ }
991
1052
  default:
992
1053
  return unexpectedTrackerCommand(action);
993
1054
  }
package/dist/index.js CHANGED
@@ -138,9 +138,13 @@ program.command('command')
138
138
  program.command('newtracker')
139
139
  .argument('<file>', 'input text file')
140
140
  .option('-o, --output <file>', 'output file name')
141
+ .option('-t, --title <string>', 'tracker title')
142
+ .option('-m, --map <string>', 'tracker map name')
143
+ .option('-u, --mapURL <string>', 'tracker map url')
144
+ .option('-d, --description <string>', 'tracker description')
141
145
  .action(async (argument, option) => {
142
146
  const file = await promises_1.default.readFile(argument, { encoding: 'utf-8' });
143
- const tracker = (0, app_1.newtracker)(file);
147
+ const tracker = (0, app_1.newtracker)(file, { title: option.title, map: option.map, mapURL: option.mapURL, description: option.description });
144
148
  if (option.output) {
145
149
  await promises_1.default.writeFile(option.output, JSON.stringify(tracker, undefined, 2), { encoding: 'utf-8' });
146
150
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pf2e-sage-stats",
3
- "version": "0.3.2",
3
+ "version": "0.4.0",
4
4
  "description": "An RPG Sage's .tsv stat generation tool",
5
5
  "author": "ikariott@gmail.com",
6
6
  "license": "MIT",