pf2e-sage-stats 0.3.2 → 0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/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;
@@ -682,11 +803,11 @@ export type TrackerCommand = {
682
803
  tag: string;
683
804
  };
684
805
  export type TrackerUpdate = {
685
- tracker: CharSchema[];
806
+ tracker: Tracker;
686
807
  exit: boolean;
687
808
  };
688
809
  export declare const parseTrackerCommands: (line: string) => TrackerCommand[];
689
- export declare const applyTrackerCommands: (tracker: CharSchema[], actions: TrackerCommand[]) => TrackerUpdate;
810
+ export declare const applyTrackerCommands: (tracker: Tracker, actions: TrackerCommand[]) => TrackerUpdate;
690
811
  export declare const sortFolder: () => Promise<{
691
812
  oldname: string;
692
813
  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
  };
@@ -815,13 +835,13 @@ const parseTrackerCommands = (line) => {
815
835
  };
816
836
  exports.parseTrackerCommands = parseTrackerCommands;
817
837
  const sameTag = (entry, tag) => (entry.id === tag || entry.alias === tag || entry.name === tag);
818
- const findCharacter = (tracker, tag) => (tracker.find((entry) => sameTag(entry, tag)));
838
+ const findCharacter = (tracker, tag) => (tracker.chars.find((entry) => sameTag(entry, tag)));
819
839
  const findCharacterOrChild = (tracker, tag) => {
820
840
  var _a;
821
- return ((_a = findCharacter(tracker, tag)) !== null && _a !== void 0 ? _a : tracker.flatMap((entry) => entry.children).find((entry) => sameTag(entry, tag)));
841
+ return ((_a = findCharacter(tracker, tag)) !== null && _a !== void 0 ? _a : tracker.chars.flatMap((entry) => entry.children).find((entry) => sameTag(entry, tag)));
822
842
  };
823
843
  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);
844
+ const sorted = [...tracker.chars].sort((a, b) => (a.init === b.init) ? (b.foe ? 1 : 0) - (a.foe ? 1 : 0) : b.init - a.init);
825
845
  const blocks = [[sorted[0]]];
826
846
  for (let i = 1; i < sorted.length; ++i) {
827
847
  if (sorted[i].foe === blocks[blocks.length - 1][0].foe) {
@@ -887,14 +907,20 @@ const applyTrackerCommand = (tracker, action) => {
887
907
  return tracker;
888
908
  }
889
909
  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
- }));
910
+ return {
911
+ ...tracker,
912
+ chars: tracker.chars.filter((entry) => !sameTag(entry, action.tag)).map((entry) => ({
913
+ ...entry,
914
+ children: entry.children.filter((child) => !sameTag(child, action.tag)),
915
+ })),
916
+ };
894
917
  case 'purge':
895
- return tracker.filter((entry) => !entry.foe);
918
+ return {
919
+ ...tracker,
920
+ chars: tracker.chars.filter((entry) => !entry.foe),
921
+ };
896
922
  case 'heal':
897
- tracker.forEach((char) => {
923
+ tracker.chars.forEach((char) => {
898
924
  char.hp = char.maxhp;
899
925
  char.children.forEach((child) => {
900
926
  child.hp = child.maxhp;
@@ -902,7 +928,7 @@ const applyTrackerCommand = (tracker, action) => {
902
928
  });
903
929
  return tracker;
904
930
  case 'reset':
905
- tracker.forEach((char) => {
931
+ tracker.chars.forEach((char) => {
906
932
  char.state = 'empty';
907
933
  });
908
934
  return tracker;
@@ -928,7 +954,7 @@ const applyTrackerCommand = (tracker, action) => {
928
954
  return tracker;
929
955
  }
930
956
  case 'blank':
931
- tracker.forEach((item) => {
957
+ tracker.chars.forEach((item) => {
932
958
  item.conditions = '';
933
959
  item.children.forEach((child) => {
934
960
  child.conditions = '';
@@ -986,7 +1012,7 @@ const applyTrackerCommand = (tracker, action) => {
986
1012
  return tracker;
987
1013
  }
988
1014
  case 'foe':
989
- tracker.push(exports.charSchema.parse({ foe: true, name: action.name, alias: action.alias, maxhp: action.hp, hp: action.hp }));
1015
+ tracker.chars.push(exports.charSchema.parse({ foe: true, name: action.name, alias: action.alias, maxhp: action.hp, hp: action.hp }));
990
1016
  return tracker;
991
1017
  default:
992
1018
  return unexpectedTrackerCommand(action);
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.3.3",
4
4
  "description": "An RPG Sage's .tsv stat generation tool",
5
5
  "author": "ikariott@gmail.com",
6
6
  "license": "MIT",