pf2e-sage-stats 0.4.2 → 0.4.4

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
@@ -754,6 +754,8 @@ export type TrackerCommand = {
754
754
  command: 'reset';
755
755
  } | {
756
756
  command: 'purge';
757
+ } | {
758
+ command: 'expire';
757
759
  } | {
758
760
  command: 'blank';
759
761
  } | {
package/dist/app.js CHANGED
@@ -622,26 +622,28 @@ const formatHP = (arg) => {
622
622
  };
623
623
  exports.formatHP = formatHP;
624
624
  const newtracker = (status, desc) => {
625
- var _a, _b;
626
- const regex = /((.+)\s+\((\d+)\/(\d+)\s+HP\):(.*)(\n>(.+)\s+\((\d+)\/(\d+)\s+HP\):(.*))*)/gm;
625
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
626
+ const regex = /(([^[(\n]+)\s+(?:\[(\S+)\]\s+)?\((\d+)\/(\d+)\s+HP\):[^\S\n]*([^\n]*)(\n>\s*([^[(\n]+)\s+(?:\[(\S+)\]\s+)?\((\d+)\/(\d+)\s+HP\):[^\S\n]*([^\n]*))*)/gm;
627
627
  const match = status.match(regex);
628
628
  const tracker = zod_1.default.array(exports.charSchema).parse([]);
629
629
  for (const m of match !== null && match !== void 0 ? match : []) {
630
- const mmatch = m.match(/([^>]+)\s+\((\d+)\/(\d+)\s+HP\):(.*)/);
631
- const cmatch = m.match(/>\s+(\S+)\s+\((\d+)\/(\d+)\s+HP\):(.*)/g);
630
+ const mmatch = m.match(/^([^[(\n]+)\s+(?:\[(\S+)\]\s+)?\((\d+)\/(\d+)\s+HP\):[^\S\n]*([^\n]*)/);
631
+ const cmatch = m.match(/>\s*([^[(\n]+)\s+(?:\[(\S+)\]\s+)?\((\d+)\/(\d+)\s+HP\):[^\S\n]*([^\n]*)/g);
632
632
  const char = exports.charSchema.parse({
633
- name: mmatch === null || mmatch === void 0 ? void 0 : mmatch[1],
634
- hp: mmatch === null || mmatch === void 0 ? void 0 : mmatch[2],
635
- maxhp: mmatch === null || mmatch === void 0 ? void 0 : mmatch[3],
636
- conditions: (_a = mmatch === null || mmatch === void 0 ? void 0 : mmatch[4]) === null || _a === void 0 ? void 0 : _a.trim(),
633
+ name: (_a = mmatch === null || mmatch === void 0 ? void 0 : mmatch[1]) === null || _a === void 0 ? void 0 : _a.trim(),
634
+ alias: (_b = mmatch === null || mmatch === void 0 ? void 0 : mmatch[2]) === null || _b === void 0 ? void 0 : _b.trim(),
635
+ hp: (_c = mmatch === null || mmatch === void 0 ? void 0 : mmatch[3]) === null || _c === void 0 ? void 0 : _c.trim(),
636
+ maxhp: (_d = mmatch === null || mmatch === void 0 ? void 0 : mmatch[4]) === null || _d === void 0 ? void 0 : _d.trim(),
637
+ conditions: (_e = mmatch === null || mmatch === void 0 ? void 0 : mmatch[5]) === null || _e === void 0 ? void 0 : _e.trim(),
637
638
  });
638
639
  for (const c of cmatch !== null && cmatch !== void 0 ? cmatch : []) {
639
- const fmatch = c.match(/>\s+(\S+)\s+\((\d+)\/(\d+)\s+HP\):(.*)/);
640
+ const fmatch = c.match(/>\s*([^[(\n]+)\s+(?:\[(\S+)\]\s+)?\((\d+)\/(\d+)\s+HP\):[^\S\n]*([^\n]*)/);
640
641
  const child = childSchema.parse({
641
- name: fmatch === null || fmatch === void 0 ? void 0 : fmatch[1],
642
- hp: fmatch === null || fmatch === void 0 ? void 0 : fmatch[2],
643
- maxhp: fmatch === null || fmatch === void 0 ? void 0 : fmatch[3],
644
- conditions: (_b = fmatch === null || fmatch === void 0 ? void 0 : fmatch[4]) === null || _b === void 0 ? void 0 : _b.trim(),
642
+ name: (_f = fmatch === null || fmatch === void 0 ? void 0 : fmatch[1]) === null || _f === void 0 ? void 0 : _f.trim(),
643
+ alias: (_g = fmatch === null || fmatch === void 0 ? void 0 : fmatch[2]) === null || _g === void 0 ? void 0 : _g.trim(),
644
+ hp: (_h = fmatch === null || fmatch === void 0 ? void 0 : fmatch[3]) === null || _h === void 0 ? void 0 : _h.trim(),
645
+ maxhp: (_j = fmatch === null || fmatch === void 0 ? void 0 : fmatch[4]) === null || _j === void 0 ? void 0 : _j.trim(),
646
+ conditions: (_k = fmatch === null || fmatch === void 0 ? void 0 : fmatch[5]) === null || _k === void 0 ? void 0 : _k.trim(),
645
647
  });
646
648
  char.children.push(child);
647
649
  }
@@ -654,11 +656,12 @@ const formatTracker = (tracker) => {
654
656
  var _a, _b;
655
657
  const aliasSpace = (t) => (t.alias.length > 0 ? 0 : 5);
656
658
  const nameLengthWithAlias = (t) => t.name.length - aliasSpace(t);
657
- const nameLength = tracker.chars.reduce((p, c) => {
659
+ const chars = [...tracker.chars];
660
+ const nameLength = chars.reduce((p, c) => {
658
661
  const length = c.children.reduce((pp, cc) => pp > nameLengthWithAlias(cc) ? pp : nameLengthWithAlias(cc), nameLengthWithAlias(c));
659
662
  return p > length ? p : length;
660
663
  }, 0);
661
- const hpLength = tracker.chars.reduce((p, c) => {
664
+ const hpLength = chars.reduce((p, c) => {
662
665
  const hpLength = c.maxhp.toString().length + 1 + c.hp.toString().length + (c.temphp > 1 ? c.temphp.toString().length + 1 : 0);
663
666
  const length = c.children.reduce((pp, cc) => {
664
667
  const hhpLength = cc.maxhp.toString().length + 1 + cc.hp.toString().length + (cc.temphp > 1 ? cc.temphp.toString().length + 1 : 0);
@@ -679,9 +682,9 @@ const formatTracker = (tracker) => {
679
682
  ':limping:',
680
683
  ':dying:',
681
684
  ].reverse();
682
- 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) => {
685
+ const lines = chars.sort((a, b) => (a.init === b.init) ? (b.foe ? 1 : 0) - (a.foe ? 1 : 0) : b.init - a.init).flatMap((char, index) => {
683
686
  const ls = [];
684
- if (tracker.chars[index - 1] && tracker.chars[index - 1].foe !== char.foe) {
687
+ if (chars[index - 1] && chars[index - 1].foe !== char.foe) {
685
688
  ls.push('');
686
689
  }
687
690
  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));
@@ -735,10 +738,10 @@ const trackerCommands = [{
735
738
  regex: /^\s*round\s+(?:([^"\s]+)|"([^"]*)")/i,
736
739
  map: (match) => { var _a; return ({ command: 'round', round: (_a = match[1]) !== null && _a !== void 0 ? _a : match[2] }); },
737
740
  }, {
738
- regex: /^\s*desc\s+(?:([^"\s]+)|"([^"]*)")/i,
741
+ regex: /^\s*(?:desc|description)\s+(?:([^"\s]+)|"([^"]*)")/i,
739
742
  map: (match) => { var _a; return ({ command: 'desc', description: (_a = match[1]) !== null && _a !== void 0 ? _a : match[2] }); },
740
743
  }, {
741
- regex: /^\s*[bB]\s*(\d+)/,
744
+ regex: /^\s*(?:b|block)\s*(\d+)/i,
742
745
  map: (match) => { var _a; return ({ command: 'block', index: parseInt((_a = match[1]) !== null && _a !== void 0 ? _a : '', 10) }); },
743
746
  }, {
744
747
  regex: /^\s*reset/i,
@@ -747,8 +750,11 @@ const trackerCommands = [{
747
750
  regex: /^\s*purge/i,
748
751
  map: () => ({ command: 'purge' }),
749
752
  }, {
750
- regex: /^\s*blank/i,
753
+ regex: /^\s*(?:blank|blanc|clear)/i,
751
754
  map: () => ({ command: 'blank' }),
755
+ }, {
756
+ regex: /^\s*expire/i,
757
+ map: () => ({ command: 'expire' }),
752
758
  }, {
753
759
  regex: /^\s*foe\s+(?:([^"\s]+)|"([^"]*)")\s+(\S+)\s+(\d+)/i,
754
760
  map: (match) => { var _a; return ({ command: 'foe', name: (_a = match[1]) !== null && _a !== void 0 ? _a : match[2], alias: match[3], hp: parseInt(match[4], 10) }); },
@@ -774,36 +780,51 @@ const trackerCommands = [{
774
780
  regex: /^\s*exit/i,
775
781
  map: () => ({ command: 'exit' }),
776
782
  }, {
777
- regex: /^\s*([^\d\s+-]+)\s*([+-]?\d+)/,
783
+ regex: /^\s*([^\s="+-]+)\s*([+-]\d+)/,
784
+ map: (match) => {
785
+ var _a, _b;
786
+ const tag = (_a = match[1]) !== null && _a !== void 0 ? _a : '';
787
+ const raw = (_b = match[2]) !== null && _b !== void 0 ? _b : '';
788
+ return { command: 'mod-hp', tag, value: parseInt(raw, 10) };
789
+ },
790
+ }, {
791
+ regex: /^\s*([^\s="+-]+)(?:\s+|\s*=)(\d+)/,
778
792
  map: (match) => {
779
793
  var _a, _b;
780
794
  const tag = (_a = match[1]) !== null && _a !== void 0 ? _a : '';
781
795
  const raw = (_b = match[2]) !== null && _b !== void 0 ? _b : '';
782
- if (raw.match(/^[+-]/)) {
783
- return { command: 'mod-hp', tag, value: parseInt(raw, 10) };
784
- }
785
796
  return { command: 'set-hp', tag, value: parseInt(raw, 10) };
786
797
  },
787
798
  }, {
788
- regex: /^\s*(\S+)\s+[tT]\s*([+-]?\d+)/,
799
+ regex: /^\s*([^\s="+-]+)\s+[tT]\s*([+-]\d+)/,
800
+ map: (match) => {
801
+ var _a, _b;
802
+ const tag = (_a = match[1]) !== null && _a !== void 0 ? _a : '';
803
+ const raw = (_b = match[2]) !== null && _b !== void 0 ? _b : '';
804
+ return { command: 'mod-thp', tag, value: parseInt(raw, 10) };
805
+ },
806
+ }, {
807
+ regex: /^\s*([^\s="+-]+)\s+[tT]\s*=?(\d+)/,
789
808
  map: (match) => {
790
809
  var _a, _b;
791
810
  const tag = (_a = match[1]) !== null && _a !== void 0 ? _a : '';
792
811
  const raw = (_b = match[2]) !== null && _b !== void 0 ? _b : '';
793
- if (raw.match(/^[+-]/)) {
794
- return { command: 'mod-thp', tag, value: parseInt(raw, 10) };
795
- }
796
812
  return { command: 'set-thp', tag, value: parseInt(raw, 10) };
797
813
  },
798
814
  }, {
799
- regex: /^\s*(\S+)\s+[iI]\s*([+-]?\d+)/,
815
+ regex: /^\s*([^\s="+-]+)\s+[iI]\s*([+-]\d+)/,
816
+ map: (match) => {
817
+ var _a, _b;
818
+ const tag = (_a = match[1]) !== null && _a !== void 0 ? _a : '';
819
+ const raw = (_b = match[2]) !== null && _b !== void 0 ? _b : '';
820
+ return { command: 'mod-init', tag, value: parseInt(raw, 10) };
821
+ },
822
+ }, {
823
+ regex: /^\s*([^\s="+-]+)\s+[iI]\s*=?(\d+)/,
800
824
  map: (match) => {
801
825
  var _a, _b;
802
826
  const tag = (_a = match[1]) !== null && _a !== void 0 ? _a : '';
803
827
  const raw = (_b = match[2]) !== null && _b !== void 0 ? _b : '';
804
- if (raw.match(/^[+-]/)) {
805
- return { command: 'mod-init', tag, value: parseInt(raw, 10) };
806
- }
807
828
  return { command: 'set-init', tag, value: parseInt(raw, 10) };
808
829
  },
809
830
  }, {
@@ -822,34 +843,49 @@ const trackerCommands = [{
822
843
  regex: /^\s*([^\s="+-]+)\s*-"([^"]*)"/,
823
844
  map: (match) => { var _a, _b; return ({ command: 'rem-conditions', tag: (_a = match[1]) !== null && _a !== void 0 ? _a : '', value: (_b = match[2]) !== null && _b !== void 0 ? _b : '' }); },
824
845
  }, {
825
- regex: /^\s*(\S+)\s+[sS]?\s*=?"([^"]*)"/,
846
+ regex: /^\s*([^\s="+-]+)\s+[sS]\s*=?"([^"]*)"/,
826
847
  map: (match) => { var _a, _b; return ({ command: 'set-conditions', tag: (_a = match[1]) !== null && _a !== void 0 ? _a : '', value: (_b = match[2]) !== null && _b !== void 0 ? _b : '' }); },
827
848
  }, {
828
- regex: /^\s*(\S+)\s+[sS]?\s*\+\+"([^"]*)"/,
849
+ regex: /^\s*([^\s="+-]+)\s+[sS]?\s*\+\+"([^"]*)"/,
829
850
  map: (match) => { var _a, _b; return ({ command: 'inc-conditions', tag: (_a = match[1]) !== null && _a !== void 0 ? _a : '', value: (_b = match[2]) !== null && _b !== void 0 ? _b : '' }); },
830
851
  }, {
831
- regex: /^\s*(\S+)\s+[sS]?\s*--"([^"]*)"/,
852
+ regex: /^\s*([^\s="+-]+)\s+[sS]?\s*--"([^"]*)"/,
832
853
  map: (match) => { var _a, _b; return ({ command: 'dec-conditions', tag: (_a = match[1]) !== null && _a !== void 0 ? _a : '', value: (_b = match[2]) !== null && _b !== void 0 ? _b : '' }); },
833
854
  }, {
834
- regex: /^\s*(\S+)\s+[sS]?\s*\+"([^"]*)"/,
855
+ regex: /^\s*([^\s="+-]+)\s+[sS]?\s*\+"([^"]*)"/,
835
856
  map: (match) => { var _a, _b; return ({ command: 'add-conditions', tag: (_a = match[1]) !== null && _a !== void 0 ? _a : '', value: (_b = match[2]) !== null && _b !== void 0 ? _b : '' }); },
836
857
  }, {
837
- regex: /^\s*(\S+)\s+[sS]?\s*-"([^"]*)"/,
858
+ regex: /^\s*([^\s="+-]+)\s+[sS]?\s*-"([^"]*)"/,
838
859
  map: (match) => { var _a, _b; return ({ command: 'rem-conditions', tag: (_a = match[1]) !== null && _a !== void 0 ? _a : '', value: (_b = match[2]) !== null && _b !== void 0 ? _b : '' }); },
839
860
  }, {
840
- regex: /^\s*([^\s=+-]+)\s*=(\S+)/,
861
+ regex: /^\s*([^\s="+-]+)\s*=(\S+)/,
841
862
  map: (match) => { var _a, _b; return ({ command: 'set-conditions', tag: (_a = match[1]) !== null && _a !== void 0 ? _a : '', value: (_b = match[2]) !== null && _b !== void 0 ? _b : '' }); },
842
863
  }, {
843
- regex: /^\s*([^\s=+-]+)\s*\+\+(\S+)/,
864
+ regex: /^\s*([^\s="+-]+)\s*\+\+(\S+)/,
844
865
  map: (match) => { var _a, _b; return ({ command: 'inc-conditions', tag: (_a = match[1]) !== null && _a !== void 0 ? _a : '', value: (_b = match[2]) !== null && _b !== void 0 ? _b : '' }); },
845
866
  }, {
846
- regex: /^\s*([^\s=+-]+)\s*--(\S+)/,
867
+ regex: /^\s*([^\s="+-]+)\s*--(\S+)/,
847
868
  map: (match) => { var _a, _b; return ({ command: 'dec-conditions', tag: (_a = match[1]) !== null && _a !== void 0 ? _a : '', value: (_b = match[2]) !== null && _b !== void 0 ? _b : '' }); },
848
869
  }, {
849
- regex: /^\s*([^\s=+-]+)\s*\+(\S+)/,
870
+ regex: /^\s*([^\s="+-]+)\s*\+(\S+)/,
850
871
  map: (match) => { var _a, _b; return ({ command: 'add-conditions', tag: (_a = match[1]) !== null && _a !== void 0 ? _a : '', value: (_b = match[2]) !== null && _b !== void 0 ? _b : '' }); },
851
872
  }, {
852
- regex: /^\s*([^\s=+-]+)\s*-(\S+)/,
873
+ regex: /^\s*([^\s="+-]+)\s*-(\S+)/,
874
+ map: (match) => { var _a, _b; return ({ command: 'rem-conditions', tag: (_a = match[1]) !== null && _a !== void 0 ? _a : '', value: (_b = match[2]) !== null && _b !== void 0 ? _b : '' }); },
875
+ }, {
876
+ regex: /^\s*([^\s="+-]+)\s+[sS]\s*=(\S+)/,
877
+ map: (match) => { var _a, _b; return ({ command: 'set-conditions', tag: (_a = match[1]) !== null && _a !== void 0 ? _a : '', value: (_b = match[2]) !== null && _b !== void 0 ? _b : '' }); },
878
+ }, {
879
+ regex: /^\s*([^\s="+-]+)\s+[sS]\s*\+\+(\S+)/,
880
+ map: (match) => { var _a, _b; return ({ command: 'inc-conditions', tag: (_a = match[1]) !== null && _a !== void 0 ? _a : '', value: (_b = match[2]) !== null && _b !== void 0 ? _b : '' }); },
881
+ }, {
882
+ regex: /^\s*([^\s="+-]+)\s+[sS]\s*--(\S+)/,
883
+ map: (match) => { var _a, _b; return ({ command: 'dec-conditions', tag: (_a = match[1]) !== null && _a !== void 0 ? _a : '', value: (_b = match[2]) !== null && _b !== void 0 ? _b : '' }); },
884
+ }, {
885
+ regex: /^\s*([^\s="+-]+)\s+[sS]\s*\+(\S+)/,
886
+ map: (match) => { var _a, _b; return ({ command: 'add-conditions', tag: (_a = match[1]) !== null && _a !== void 0 ? _a : '', value: (_b = match[2]) !== null && _b !== void 0 ? _b : '' }); },
887
+ }, {
888
+ regex: /^\s*([^\s="+-]+)\s+[sS]\s*-(\S+)/,
853
889
  map: (match) => { var _a, _b; return ({ command: 'rem-conditions', tag: (_a = match[1]) !== null && _a !== void 0 ? _a : '', value: (_b = match[2]) !== null && _b !== void 0 ? _b : '' }); },
854
890
  }, {
855
891
  regex: /^\s*(\S+)\s+[cC]/,
@@ -973,6 +1009,14 @@ const applyTrackerCommand = (tracker, action) => {
973
1009
  ...tracker,
974
1010
  chars: tracker.chars.filter((entry) => !entry.foe),
975
1011
  };
1012
+ case 'expire':
1013
+ tracker.chars.forEach((char) => {
1014
+ char.temphp = 0;
1015
+ char.children.forEach((child) => {
1016
+ child.temphp = 0;
1017
+ });
1018
+ });
1019
+ return tracker;
976
1020
  case 'heal':
977
1021
  tracker.chars.forEach((char) => {
978
1022
  char.hp = char.maxhp;
@@ -1029,10 +1073,10 @@ const applyTrackerCommand = (tracker, action) => {
1029
1073
  updateConditions(tracker, action.tag, (conditions) => conditions.filter((condition) => !condition.includes(action.value.toLowerCase().trim())));
1030
1074
  return tracker;
1031
1075
  case 'inc-conditions':
1032
- updateConditions(tracker, action.tag, (conditions) => conditions.map((condition) => (numberedCondition(condition, action.value.toLowerCase().trim(), (label, value) => `${label} ${value + 1}`))));
1076
+ updateConditions(tracker, action.tag, (conditions) => conditions.map((condition) => (numberedCondition(condition, action.value.toLowerCase().trim(), (label, value) => `${label} ${value + 1}`))).filter((c) => c !== null));
1033
1077
  return tracker;
1034
1078
  case 'dec-conditions':
1035
- updateConditions(tracker, action.tag, (conditions) => conditions.map((condition) => (numberedCondition(condition, action.value.toLowerCase().trim(), (label, value) => (value > 1 ? `${label} ${value - 1}` : label)))));
1079
+ updateConditions(tracker, action.tag, (conditions) => conditions.map((condition) => (numberedCondition(condition, action.value.toLowerCase().trim(), (label, value) => (value > 1 ? `${label} ${value - 1}` : null)))).filter((c) => c !== null));
1036
1080
  return tracker;
1037
1081
  case 'mod-thp': {
1038
1082
  const item = findCharacterOrChild(tracker, action.tag);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pf2e-sage-stats",
3
- "version": "0.4.2",
3
+ "version": "0.4.4",
4
4
  "description": "An RPG Sage's .tsv stat generation tool",
5
5
  "author": "ikariott@gmail.com",
6
6
  "license": "MIT",