pf2e-sage-stats 0.3.0 → 0.3.2

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
@@ -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.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.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");
@@ -11,6 +11,7 @@ const lodash_1 = require("lodash");
11
11
  const dedent_js_1 = __importDefault(require("dedent-js"));
12
12
  const abbreviate_1 = __importDefault(require("abbreviate"));
13
13
  const pluralize_1 = __importDefault(require("pluralize"));
14
+ const lines_1 = require("./lines");
14
15
  const schema = zod_1.default.object({
15
16
  name: zod_1.default.string(),
16
17
  alias: zod_1.default.string().optional(),
@@ -367,75 +368,73 @@ const locateSpells = (statblock) => {
367
368
  const parseStatblock = (name, _statblock, alias) => {
368
369
  var _a;
369
370
  const defaults = schema.parse({ name: name !== null && name !== void 0 ? name : 'Unknown' });
370
- const improvisation = _statblock.match(/Untrained\s+Improvisation/);
371
- const plate = _statblock.match(/Full\s+Plate/);
372
- const statblock = _statblock
373
- .replace(/^Items.*$/m, '')
374
- .replace('', '')
375
- .replace(/–/g, '-') + '\n';
376
- const basic = locateName(statblock);
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'));
377
375
  const result = {
378
376
  ...defaults,
379
377
  ...basic,
380
378
  ...(name && { name: name }),
381
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() },
382
- ...locateInt('perception', statblock),
383
- ...locateInt('ac', statblock, null, false, 'AC'),
384
- ...locateInt('maxhp', statblock, null, false, 'HP'),
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'),
385
383
  attributes: {
386
384
  ...defaults.attributes,
387
- ...locateInt('strength', statblock, null, true, 'Str'),
388
- ...locateInt('dexterity', statblock, null, true, 'Dex'),
389
- ...locateInt('constitution', statblock, null, true, 'Con'),
390
- ...locateInt('intelligence', statblock, null, true, 'Int'),
391
- ...locateInt('wisdom', statblock, null, true, 'Wis'),
392
- ...locateInt('charisma', statblock, null, true, 'Cha'),
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'),
393
391
  },
394
392
  saves: {
395
393
  ...defaults.saves,
396
- ...locateInt('fortitude', statblock, null, true, 'Fortitude'),
397
- ...locateInt('reflex', statblock, null, true, 'Reflex'),
398
- ...locateInt('fortitude', statblock, null, true, 'Fort'),
399
- ...locateInt('reflex', statblock, null, true, 'Ref'),
400
- ...locateInt('will', statblock, null, true, 'Will'),
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'),
401
399
  },
402
400
  skills: {
403
401
  ...defaults.skills,
404
- ...locateInt('acrobatics', statblock, 'Skills'),
405
- ...locateInt('arcana', statblock, 'Skills'),
406
- ...locateInt('athletics', statblock, 'Skills'),
407
- ...locateInt('crafting', statblock, 'Skills'),
408
- ...locateInt('deception', statblock, 'Skills'),
409
- ...locateInt('diplomacy', statblock, 'Skills'),
410
- ...locateInt('intimidation', statblock, 'Skills'),
411
- ...locateInt('medicine', statblock, 'Skills'),
412
- ...locateInt('nature', statblock, 'Skills'),
413
- ...locateInt('occultism', statblock, 'Skills'),
414
- ...locateInt('performance', statblock, 'Skills'),
415
- ...locateInt('religion', statblock, 'Skills'),
416
- ...locateInt('society', statblock, 'Skills'),
417
- ...locateInt('stealth', statblock, 'Skills'),
418
- ...locateInt('survival', statblock, 'Skills'),
419
- ...locateInt('thievery', statblock, 'Skills'),
420
- ...locateInt('piloting', statblock, 'Skills'),
421
- ...locateInt('computers', statblock, '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'),
422
421
  },
423
422
  lores: {
424
- ...locateInts(statblock, 'Skills', 'Lore'),
425
- ...locateIntsAfter(statblock, 'Lore:')
423
+ ...locateInts((0, lines_1.getLine)(lines, 'skills'), 'Skills', 'Lore'),
424
+ ...locateIntsAfter((0, lines_1.getLine)(lines, 'skills'), 'Lore:')
426
425
  },
427
426
  melee: {
428
- ...locateStrikes(statblock, 'Melee'),
427
+ ...locateStrikes((0, lines_1.listLines)(lines, 'strike'), 'Melee'),
429
428
  },
430
429
  ranged: {
431
- ...locateStrikes(statblock, 'Ranged'),
430
+ ...locateStrikes((0, lines_1.listLines)(lines, 'strike'), 'Ranged'),
432
431
  },
433
432
  spells: {
434
- ...locateSpells(statblock),
433
+ ...locateSpells((0, lines_1.listLines)(lines, 'spells')),
435
434
  },
436
435
  extra: {},
437
436
  extraDCs: {
438
- ...locateInt('stealth', statblock, null, false, 'Stealth DC'),
437
+ ...locateInt('stealth', (0, lines_1.getLine)(lines, 'stealth'), null, false, 'Stealth DC'),
439
438
  },
440
439
  extraDice: {},
441
440
  };
@@ -694,6 +693,316 @@ const formatTracker = (tracker) => {
694
693
  return lines.join('\n');
695
694
  };
696
695
  exports.formatTracker = formatTracker;
696
+ const trackerCommands = [{
697
+ regex: /^\s*[bB]\s*(\d+)/,
698
+ map: (match) => { var _a; return ({ command: 'block', index: parseInt((_a = match[1]) !== null && _a !== void 0 ? _a : '', 10) }); },
699
+ }, {
700
+ regex: /^\s*reset/i,
701
+ map: () => ({ command: 'reset' }),
702
+ }, {
703
+ regex: /^\s*purge/i,
704
+ map: () => ({ command: 'purge' }),
705
+ }, {
706
+ regex: /^\s*blank/i,
707
+ map: () => ({ command: 'blank' }),
708
+ }, {
709
+ regex: /^\s*foe(\s+(\S+))?(\s+(\S+))?(\s+(\d+))?/i,
710
+ map: (match) => ({ command: 'foe', name: match[2], alias: match[4], hp: match[6] ? parseInt(match[6], 10) : undefined }),
711
+ }, {
712
+ regex: /^\s*heal/i,
713
+ map: () => ({ command: 'heal' }),
714
+ }, {
715
+ regex: /^\s*exit/i,
716
+ map: () => ({ command: 'exit' }),
717
+ }, {
718
+ regex: /^\s*([^\d\s+-]+)\s*([+-]?\d+)/,
719
+ map: (match) => {
720
+ var _a, _b;
721
+ const tag = (_a = match[1]) !== null && _a !== void 0 ? _a : '';
722
+ const raw = (_b = match[2]) !== null && _b !== void 0 ? _b : '';
723
+ if (raw.match(/^[+-]/)) {
724
+ return { command: 'mod-hp', tag, value: parseInt(raw, 10) };
725
+ }
726
+ return { command: 'set-hp', tag, value: parseInt(raw, 10) };
727
+ },
728
+ }, {
729
+ regex: /^\s*(\S+)\s+[tT]\s*([+-]?\d+)/,
730
+ map: (match) => {
731
+ var _a, _b;
732
+ const tag = (_a = match[1]) !== null && _a !== void 0 ? _a : '';
733
+ const raw = (_b = match[2]) !== null && _b !== void 0 ? _b : '';
734
+ if (raw.match(/^[+-]/)) {
735
+ return { command: 'mod-thp', tag, value: parseInt(raw, 10) };
736
+ }
737
+ return { command: 'set-thp', tag, value: parseInt(raw, 10) };
738
+ },
739
+ }, {
740
+ regex: /^\s*(\S+)\s+[iI]\s*([+-]?\d+)/,
741
+ map: (match) => {
742
+ var _a, _b;
743
+ const tag = (_a = match[1]) !== null && _a !== void 0 ? _a : '';
744
+ const raw = (_b = match[2]) !== null && _b !== void 0 ? _b : '';
745
+ if (raw.match(/^[+-]/)) {
746
+ return { command: 'mod-init', tag, value: parseInt(raw, 10) };
747
+ }
748
+ return { command: 'set-init', tag, value: parseInt(raw, 10) };
749
+ },
750
+ }, {
751
+ regex: /^\s*([^\s="+-]+)\s*=?"([^"]*)"/,
752
+ 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 : '' }); },
753
+ }, {
754
+ regex: /^\s*([^\s="+-]+)\s*\+"([^"]*)"/,
755
+ 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 : '' }); },
756
+ }, {
757
+ regex: /^\s*([^\s="+-]+)\s*-"([^"]*)"/,
758
+ 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 : '' }); },
759
+ }, {
760
+ regex: /^\s*([^\s="+-]+)\s*\+\+"([^"]*)"/,
761
+ 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 : '' }); },
762
+ }, {
763
+ regex: /^\s*([^\s="+-]+)\s*--"([^"]*)"/,
764
+ 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 : '' }); },
765
+ }, {
766
+ regex: /^\s*(\S+)\s+[sS]?\s*=?"([^"]*)"/,
767
+ 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 : '' }); },
768
+ }, {
769
+ regex: /^\s*(\S+)\s+[sS]?\s*\+"([^"]*)"/,
770
+ 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 : '' }); },
771
+ }, {
772
+ regex: /^\s*(\S+)\s+[sS]?\s*-"([^"]*)"/,
773
+ 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 : '' }); },
774
+ }, {
775
+ regex: /^\s*(\S+)\s+[sS]?\s*\+\+"([^"]*)"/,
776
+ 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 : '' }); },
777
+ }, {
778
+ regex: /^\s*(\S+)\s+[sS]?\s*--"([^"]*)"/,
779
+ 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 : '' }); },
780
+ }, {
781
+ regex: /^\s*(\S+)\s+[cC]/,
782
+ map: (match) => { var _a; return ({ command: 'check', tag: (_a = match[1]) !== null && _a !== void 0 ? _a : '' }); },
783
+ }, {
784
+ regex: /^\s*(\S+)\s+[aA]/,
785
+ map: (match) => { var _a; return ({ command: 'arrow', tag: (_a = match[1]) !== null && _a !== void 0 ? _a : '' }); },
786
+ }, {
787
+ regex: /^\s*(\S+)\s+[eE]/,
788
+ map: (match) => { var _a; return ({ command: 'empty', tag: (_a = match[1]) !== null && _a !== void 0 ? _a : '' }); },
789
+ }, {
790
+ regex: /^\s*(\S+)\s+[xX]/,
791
+ map: (match) => { var _a; return ({ command: 'cross', tag: (_a = match[1]) !== null && _a !== void 0 ? _a : '' }); },
792
+ }, {
793
+ regex: /^\s*(\S+)\s+[dD]/,
794
+ map: (match) => { var _a; return ({ command: 'delete', tag: (_a = match[1]) !== null && _a !== void 0 ? _a : '' }); },
795
+ }, {
796
+ regex: /^\s*(\S+)\s+[wW]/,
797
+ map: (match) => { var _a; return ({ command: 'wait', tag: (_a = match[1]) !== null && _a !== void 0 ? _a : '' }); },
798
+ }];
799
+ const parseTrackerCommands = (line) => {
800
+ const actions = [];
801
+ let input = line;
802
+ while (input.length > 0) {
803
+ const command = trackerCommands.find((entry) => input.match(entry.regex));
804
+ if (!command) {
805
+ break;
806
+ }
807
+ const match = input.match(command.regex);
808
+ if (!match) {
809
+ break;
810
+ }
811
+ actions.push(command.map(match));
812
+ input = input.slice(match[0].length);
813
+ }
814
+ return actions;
815
+ };
816
+ exports.parseTrackerCommands = parseTrackerCommands;
817
+ const sameTag = (entry, tag) => (entry.id === tag || entry.alias === tag || entry.name === tag);
818
+ const findCharacter = (tracker, tag) => (tracker.find((entry) => sameTag(entry, tag)));
819
+ const findCharacterOrChild = (tracker, tag) => {
820
+ var _a;
821
+ return ((_a = findCharacter(tracker, tag)) !== null && _a !== void 0 ? _a : tracker.flatMap((entry) => entry.children).find((entry) => sameTag(entry, tag)));
822
+ };
823
+ 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);
825
+ const blocks = [[sorted[0]]];
826
+ for (let i = 1; i < sorted.length; ++i) {
827
+ if (sorted[i].foe === blocks[blocks.length - 1][0].foe) {
828
+ blocks[blocks.length - 1].push(sorted[i]);
829
+ }
830
+ else {
831
+ blocks.push([sorted[i]]);
832
+ }
833
+ }
834
+ return blocks;
835
+ };
836
+ const updateConditions = (tracker, tag, update) => {
837
+ const item = findCharacterOrChild(tracker, tag);
838
+ if (item) {
839
+ const conditions = item.conditions.split(',').map((condition) => condition.toLowerCase().trim()).filter((condition) => condition.length);
840
+ item.conditions = update(conditions).join(', ');
841
+ }
842
+ };
843
+ const numberedCondition = (condition, name, next) => {
844
+ if (!condition.includes(name)) {
845
+ return condition;
846
+ }
847
+ const match = condition.match(/(.*)\s+(\d+)/);
848
+ if (match && match[1] && match[2]) {
849
+ return next(match[1].trim(), parseInt(match[2], 10));
850
+ }
851
+ return condition;
852
+ };
853
+ const unexpectedTrackerCommand = (action) => {
854
+ throw new Error(`Unexpected tracker command: ${JSON.stringify(action)}`);
855
+ };
856
+ const applyTrackerCommand = (tracker, action) => {
857
+ var _a, _b;
858
+ switch (action.command) {
859
+ case 'block': {
860
+ const blocks = initiativeBlocks(tracker);
861
+ for (let i = 0; i < blocks.length; ++i) {
862
+ const state = i < action.index ? 'check' : i === action.index ? 'arrow' : 'empty';
863
+ blocks[i].forEach((entry) => {
864
+ entry.state = state;
865
+ });
866
+ }
867
+ return tracker;
868
+ }
869
+ case 'wait': {
870
+ const blocks = initiativeBlocks(tracker);
871
+ const blockIndex = blocks.findIndex((block) => block.find((entry) => sameTag(entry, action.tag)));
872
+ const block = blocks[blockIndex + 1];
873
+ const item = findCharacter(tracker, action.tag);
874
+ if (block && item) {
875
+ item.init = ((_b = (_a = block[block.length - 1]) === null || _a === void 0 ? void 0 : _a.init) !== null && _b !== void 0 ? _b : 0) - 1;
876
+ }
877
+ return tracker;
878
+ }
879
+ case 'check':
880
+ case 'arrow':
881
+ case 'empty':
882
+ case 'cross': {
883
+ const item = findCharacter(tracker, action.tag);
884
+ if (item) {
885
+ item.state = action.command;
886
+ }
887
+ return tracker;
888
+ }
889
+ 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
+ }));
894
+ case 'purge':
895
+ return tracker.filter((entry) => !entry.foe);
896
+ case 'heal':
897
+ tracker.forEach((char) => {
898
+ char.hp = char.maxhp;
899
+ char.children.forEach((child) => {
900
+ child.hp = child.maxhp;
901
+ });
902
+ });
903
+ return tracker;
904
+ case 'reset':
905
+ tracker.forEach((char) => {
906
+ char.state = 'empty';
907
+ });
908
+ return tracker;
909
+ case 'set-thp': {
910
+ const item = findCharacterOrChild(tracker, action.tag);
911
+ if (item) {
912
+ item.temphp = Math.max(0, action.value);
913
+ }
914
+ return tracker;
915
+ }
916
+ case 'set-hp': {
917
+ const item = findCharacterOrChild(tracker, action.tag);
918
+ if (item) {
919
+ item.hp = Math.min(item.maxhp, Math.max(0, action.value));
920
+ }
921
+ return tracker;
922
+ }
923
+ case 'set-init': {
924
+ const item = findCharacter(tracker, action.tag);
925
+ if (item) {
926
+ item.init = Math.max(0, action.value);
927
+ }
928
+ return tracker;
929
+ }
930
+ case 'blank':
931
+ tracker.forEach((item) => {
932
+ item.conditions = '';
933
+ item.children.forEach((child) => {
934
+ child.conditions = '';
935
+ });
936
+ });
937
+ return tracker;
938
+ case 'set-conditions': {
939
+ const item = findCharacterOrChild(tracker, action.tag);
940
+ if (item) {
941
+ item.conditions = action.value.trim();
942
+ }
943
+ return tracker;
944
+ }
945
+ case 'add-conditions':
946
+ updateConditions(tracker, action.tag, (conditions) => [...conditions, action.value.toLowerCase().trim()]);
947
+ return tracker;
948
+ case 'rem-conditions':
949
+ updateConditions(tracker, action.tag, (conditions) => conditions.filter((condition) => !condition.includes(action.value.toLowerCase().trim())));
950
+ return tracker;
951
+ case 'inc-conditions':
952
+ updateConditions(tracker, action.tag, (conditions) => conditions.map((condition) => (numberedCondition(condition, action.value.toLowerCase().trim(), (label, value) => `${label} ${value + 1}`))));
953
+ return tracker;
954
+ case 'dec-conditions':
955
+ updateConditions(tracker, action.tag, (conditions) => conditions.map((condition) => (numberedCondition(condition, action.value.toLowerCase().trim(), (label, value) => (value > 1 ? `${label} ${value - 1}` : label)))));
956
+ return tracker;
957
+ case 'mod-thp': {
958
+ const item = findCharacterOrChild(tracker, action.tag);
959
+ if (item) {
960
+ item.temphp = Math.max(0, item.temphp + action.value);
961
+ }
962
+ return tracker;
963
+ }
964
+ case 'mod-hp': {
965
+ const item = findCharacterOrChild(tracker, action.tag);
966
+ if (item) {
967
+ let hp = item.hp;
968
+ let thp = item.temphp;
969
+ if (action.value < 0) {
970
+ thp += action.value;
971
+ hp += Math.min(thp, 0);
972
+ }
973
+ else {
974
+ hp += action.value;
975
+ }
976
+ item.temphp = Math.max(0, thp);
977
+ item.hp = Math.min(item.maxhp, Math.max(0, hp));
978
+ }
979
+ return tracker;
980
+ }
981
+ case 'mod-init': {
982
+ const item = findCharacter(tracker, action.tag);
983
+ if (item) {
984
+ item.init = Math.max(0, item.init + action.value);
985
+ }
986
+ return tracker;
987
+ }
988
+ case 'foe':
989
+ tracker.push(exports.charSchema.parse({ foe: true, name: action.name, alias: action.alias, maxhp: action.hp, hp: action.hp }));
990
+ return tracker;
991
+ default:
992
+ return unexpectedTrackerCommand(action);
993
+ }
994
+ };
995
+ const applyTrackerCommands = (tracker, actions) => {
996
+ let next = tracker;
997
+ for (const action of actions) {
998
+ if (action.command === 'exit') {
999
+ return { tracker: next, exit: true };
1000
+ }
1001
+ next = applyTrackerCommand(next, action);
1002
+ }
1003
+ return { tracker: next, exit: false };
1004
+ };
1005
+ exports.applyTrackerCommands = applyTrackerCommands;
697
1006
  const sortFolder = async () => {
698
1007
  const dir = await (0, promises_1.readdir)('.');
699
1008
  const summary = await Promise.all(dir.map(async (file) => {