pf2e-sage-stats 0.3.1 → 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 +231 -23
- package/dist/app.js +344 -8
- package/dist/index.js +11 -342
- package/package.json +1 -1
package/dist/app.d.ts
CHANGED
|
@@ -566,40 +566,248 @@ 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) =>
|
|
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
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
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;
|
|
724
|
+
export type TrackerCommand = {
|
|
725
|
+
command: 'block';
|
|
726
|
+
index: number;
|
|
727
|
+
} | {
|
|
728
|
+
command: 'reset';
|
|
729
|
+
} | {
|
|
730
|
+
command: 'purge';
|
|
731
|
+
} | {
|
|
732
|
+
command: 'blank';
|
|
733
|
+
} | {
|
|
734
|
+
command: 'foe';
|
|
735
|
+
name?: string;
|
|
736
|
+
alias?: string;
|
|
737
|
+
hp?: number;
|
|
738
|
+
} | {
|
|
739
|
+
command: 'heal';
|
|
740
|
+
} | {
|
|
741
|
+
command: 'exit';
|
|
742
|
+
} | {
|
|
743
|
+
command: 'mod-hp';
|
|
744
|
+
tag: string;
|
|
745
|
+
value: number;
|
|
746
|
+
} | {
|
|
747
|
+
command: 'set-hp';
|
|
748
|
+
tag: string;
|
|
749
|
+
value: number;
|
|
750
|
+
} | {
|
|
751
|
+
command: 'mod-thp';
|
|
752
|
+
tag: string;
|
|
753
|
+
value: number;
|
|
754
|
+
} | {
|
|
755
|
+
command: 'set-thp';
|
|
756
|
+
tag: string;
|
|
757
|
+
value: number;
|
|
758
|
+
} | {
|
|
759
|
+
command: 'mod-init';
|
|
760
|
+
tag: string;
|
|
761
|
+
value: number;
|
|
762
|
+
} | {
|
|
763
|
+
command: 'set-init';
|
|
764
|
+
tag: string;
|
|
765
|
+
value: number;
|
|
766
|
+
} | {
|
|
767
|
+
command: 'set-conditions';
|
|
768
|
+
tag: string;
|
|
769
|
+
value: string;
|
|
770
|
+
} | {
|
|
771
|
+
command: 'add-conditions';
|
|
772
|
+
tag: string;
|
|
773
|
+
value: string;
|
|
774
|
+
} | {
|
|
775
|
+
command: 'rem-conditions';
|
|
776
|
+
tag: string;
|
|
777
|
+
value: string;
|
|
778
|
+
} | {
|
|
779
|
+
command: 'inc-conditions';
|
|
780
|
+
tag: string;
|
|
781
|
+
value: string;
|
|
782
|
+
} | {
|
|
783
|
+
command: 'dec-conditions';
|
|
784
|
+
tag: string;
|
|
785
|
+
value: string;
|
|
786
|
+
} | {
|
|
787
|
+
command: 'check';
|
|
788
|
+
tag: string;
|
|
789
|
+
} | {
|
|
790
|
+
command: 'arrow';
|
|
791
|
+
tag: string;
|
|
792
|
+
} | {
|
|
793
|
+
command: 'empty';
|
|
794
|
+
tag: string;
|
|
795
|
+
} | {
|
|
796
|
+
command: 'cross';
|
|
797
|
+
tag: string;
|
|
798
|
+
} | {
|
|
799
|
+
command: 'delete';
|
|
800
|
+
tag: string;
|
|
801
|
+
} | {
|
|
802
|
+
command: 'wait';
|
|
803
|
+
tag: string;
|
|
804
|
+
};
|
|
805
|
+
export type TrackerUpdate = {
|
|
806
|
+
tracker: Tracker;
|
|
807
|
+
exit: boolean;
|
|
808
|
+
};
|
|
809
|
+
export declare const parseTrackerCommands: (line: string) => TrackerCommand[];
|
|
810
|
+
export declare const applyTrackerCommands: (tracker: Tracker, actions: TrackerCommand[]) => TrackerUpdate;
|
|
603
811
|
export declare const sortFolder: () => Promise<{
|
|
604
812
|
oldname: string;
|
|
605
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.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) =>
|
|
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,10 +697,338 @@ 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
|
};
|
|
695
715
|
exports.formatTracker = formatTracker;
|
|
716
|
+
const trackerCommands = [{
|
|
717
|
+
regex: /^\s*[bB]\s*(\d+)/,
|
|
718
|
+
map: (match) => { var _a; return ({ command: 'block', index: parseInt((_a = match[1]) !== null && _a !== void 0 ? _a : '', 10) }); },
|
|
719
|
+
}, {
|
|
720
|
+
regex: /^\s*reset/i,
|
|
721
|
+
map: () => ({ command: 'reset' }),
|
|
722
|
+
}, {
|
|
723
|
+
regex: /^\s*purge/i,
|
|
724
|
+
map: () => ({ command: 'purge' }),
|
|
725
|
+
}, {
|
|
726
|
+
regex: /^\s*blank/i,
|
|
727
|
+
map: () => ({ command: 'blank' }),
|
|
728
|
+
}, {
|
|
729
|
+
regex: /^\s*foe(\s+(\S+))?(\s+(\S+))?(\s+(\d+))?/i,
|
|
730
|
+
map: (match) => ({ command: 'foe', name: match[2], alias: match[4], hp: match[6] ? parseInt(match[6], 10) : undefined }),
|
|
731
|
+
}, {
|
|
732
|
+
regex: /^\s*heal/i,
|
|
733
|
+
map: () => ({ command: 'heal' }),
|
|
734
|
+
}, {
|
|
735
|
+
regex: /^\s*exit/i,
|
|
736
|
+
map: () => ({ command: 'exit' }),
|
|
737
|
+
}, {
|
|
738
|
+
regex: /^\s*([^\d\s+-]+)\s*([+-]?\d+)/,
|
|
739
|
+
map: (match) => {
|
|
740
|
+
var _a, _b;
|
|
741
|
+
const tag = (_a = match[1]) !== null && _a !== void 0 ? _a : '';
|
|
742
|
+
const raw = (_b = match[2]) !== null && _b !== void 0 ? _b : '';
|
|
743
|
+
if (raw.match(/^[+-]/)) {
|
|
744
|
+
return { command: 'mod-hp', tag, value: parseInt(raw, 10) };
|
|
745
|
+
}
|
|
746
|
+
return { command: 'set-hp', tag, value: parseInt(raw, 10) };
|
|
747
|
+
},
|
|
748
|
+
}, {
|
|
749
|
+
regex: /^\s*(\S+)\s+[tT]\s*([+-]?\d+)/,
|
|
750
|
+
map: (match) => {
|
|
751
|
+
var _a, _b;
|
|
752
|
+
const tag = (_a = match[1]) !== null && _a !== void 0 ? _a : '';
|
|
753
|
+
const raw = (_b = match[2]) !== null && _b !== void 0 ? _b : '';
|
|
754
|
+
if (raw.match(/^[+-]/)) {
|
|
755
|
+
return { command: 'mod-thp', tag, value: parseInt(raw, 10) };
|
|
756
|
+
}
|
|
757
|
+
return { command: 'set-thp', tag, value: parseInt(raw, 10) };
|
|
758
|
+
},
|
|
759
|
+
}, {
|
|
760
|
+
regex: /^\s*(\S+)\s+[iI]\s*([+-]?\d+)/,
|
|
761
|
+
map: (match) => {
|
|
762
|
+
var _a, _b;
|
|
763
|
+
const tag = (_a = match[1]) !== null && _a !== void 0 ? _a : '';
|
|
764
|
+
const raw = (_b = match[2]) !== null && _b !== void 0 ? _b : '';
|
|
765
|
+
if (raw.match(/^[+-]/)) {
|
|
766
|
+
return { command: 'mod-init', tag, value: parseInt(raw, 10) };
|
|
767
|
+
}
|
|
768
|
+
return { command: 'set-init', tag, value: parseInt(raw, 10) };
|
|
769
|
+
},
|
|
770
|
+
}, {
|
|
771
|
+
regex: /^\s*([^\s="+-]+)\s*=?"([^"]*)"/,
|
|
772
|
+
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 : '' }); },
|
|
773
|
+
}, {
|
|
774
|
+
regex: /^\s*([^\s="+-]+)\s*\+"([^"]*)"/,
|
|
775
|
+
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 : '' }); },
|
|
776
|
+
}, {
|
|
777
|
+
regex: /^\s*([^\s="+-]+)\s*-"([^"]*)"/,
|
|
778
|
+
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 : '' }); },
|
|
779
|
+
}, {
|
|
780
|
+
regex: /^\s*([^\s="+-]+)\s*\+\+"([^"]*)"/,
|
|
781
|
+
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 : '' }); },
|
|
782
|
+
}, {
|
|
783
|
+
regex: /^\s*([^\s="+-]+)\s*--"([^"]*)"/,
|
|
784
|
+
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 : '' }); },
|
|
785
|
+
}, {
|
|
786
|
+
regex: /^\s*(\S+)\s+[sS]?\s*=?"([^"]*)"/,
|
|
787
|
+
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 : '' }); },
|
|
788
|
+
}, {
|
|
789
|
+
regex: /^\s*(\S+)\s+[sS]?\s*\+"([^"]*)"/,
|
|
790
|
+
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 : '' }); },
|
|
791
|
+
}, {
|
|
792
|
+
regex: /^\s*(\S+)\s+[sS]?\s*-"([^"]*)"/,
|
|
793
|
+
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 : '' }); },
|
|
794
|
+
}, {
|
|
795
|
+
regex: /^\s*(\S+)\s+[sS]?\s*\+\+"([^"]*)"/,
|
|
796
|
+
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 : '' }); },
|
|
797
|
+
}, {
|
|
798
|
+
regex: /^\s*(\S+)\s+[sS]?\s*--"([^"]*)"/,
|
|
799
|
+
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 : '' }); },
|
|
800
|
+
}, {
|
|
801
|
+
regex: /^\s*(\S+)\s+[cC]/,
|
|
802
|
+
map: (match) => { var _a; return ({ command: 'check', tag: (_a = match[1]) !== null && _a !== void 0 ? _a : '' }); },
|
|
803
|
+
}, {
|
|
804
|
+
regex: /^\s*(\S+)\s+[aA]/,
|
|
805
|
+
map: (match) => { var _a; return ({ command: 'arrow', tag: (_a = match[1]) !== null && _a !== void 0 ? _a : '' }); },
|
|
806
|
+
}, {
|
|
807
|
+
regex: /^\s*(\S+)\s+[eE]/,
|
|
808
|
+
map: (match) => { var _a; return ({ command: 'empty', tag: (_a = match[1]) !== null && _a !== void 0 ? _a : '' }); },
|
|
809
|
+
}, {
|
|
810
|
+
regex: /^\s*(\S+)\s+[xX]/,
|
|
811
|
+
map: (match) => { var _a; return ({ command: 'cross', tag: (_a = match[1]) !== null && _a !== void 0 ? _a : '' }); },
|
|
812
|
+
}, {
|
|
813
|
+
regex: /^\s*(\S+)\s+[dD]/,
|
|
814
|
+
map: (match) => { var _a; return ({ command: 'delete', tag: (_a = match[1]) !== null && _a !== void 0 ? _a : '' }); },
|
|
815
|
+
}, {
|
|
816
|
+
regex: /^\s*(\S+)\s+[wW]/,
|
|
817
|
+
map: (match) => { var _a; return ({ command: 'wait', tag: (_a = match[1]) !== null && _a !== void 0 ? _a : '' }); },
|
|
818
|
+
}];
|
|
819
|
+
const parseTrackerCommands = (line) => {
|
|
820
|
+
const actions = [];
|
|
821
|
+
let input = line;
|
|
822
|
+
while (input.length > 0) {
|
|
823
|
+
const command = trackerCommands.find((entry) => input.match(entry.regex));
|
|
824
|
+
if (!command) {
|
|
825
|
+
break;
|
|
826
|
+
}
|
|
827
|
+
const match = input.match(command.regex);
|
|
828
|
+
if (!match) {
|
|
829
|
+
break;
|
|
830
|
+
}
|
|
831
|
+
actions.push(command.map(match));
|
|
832
|
+
input = input.slice(match[0].length);
|
|
833
|
+
}
|
|
834
|
+
return actions;
|
|
835
|
+
};
|
|
836
|
+
exports.parseTrackerCommands = parseTrackerCommands;
|
|
837
|
+
const sameTag = (entry, tag) => (entry.id === tag || entry.alias === tag || entry.name === tag);
|
|
838
|
+
const findCharacter = (tracker, tag) => (tracker.chars.find((entry) => sameTag(entry, tag)));
|
|
839
|
+
const findCharacterOrChild = (tracker, tag) => {
|
|
840
|
+
var _a;
|
|
841
|
+
return ((_a = findCharacter(tracker, tag)) !== null && _a !== void 0 ? _a : tracker.chars.flatMap((entry) => entry.children).find((entry) => sameTag(entry, tag)));
|
|
842
|
+
};
|
|
843
|
+
const initiativeBlocks = (tracker) => {
|
|
844
|
+
const sorted = [...tracker.chars].sort((a, b) => (a.init === b.init) ? (b.foe ? 1 : 0) - (a.foe ? 1 : 0) : b.init - a.init);
|
|
845
|
+
const blocks = [[sorted[0]]];
|
|
846
|
+
for (let i = 1; i < sorted.length; ++i) {
|
|
847
|
+
if (sorted[i].foe === blocks[blocks.length - 1][0].foe) {
|
|
848
|
+
blocks[blocks.length - 1].push(sorted[i]);
|
|
849
|
+
}
|
|
850
|
+
else {
|
|
851
|
+
blocks.push([sorted[i]]);
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
return blocks;
|
|
855
|
+
};
|
|
856
|
+
const updateConditions = (tracker, tag, update) => {
|
|
857
|
+
const item = findCharacterOrChild(tracker, tag);
|
|
858
|
+
if (item) {
|
|
859
|
+
const conditions = item.conditions.split(',').map((condition) => condition.toLowerCase().trim()).filter((condition) => condition.length);
|
|
860
|
+
item.conditions = update(conditions).join(', ');
|
|
861
|
+
}
|
|
862
|
+
};
|
|
863
|
+
const numberedCondition = (condition, name, next) => {
|
|
864
|
+
if (!condition.includes(name)) {
|
|
865
|
+
return condition;
|
|
866
|
+
}
|
|
867
|
+
const match = condition.match(/(.*)\s+(\d+)/);
|
|
868
|
+
if (match && match[1] && match[2]) {
|
|
869
|
+
return next(match[1].trim(), parseInt(match[2], 10));
|
|
870
|
+
}
|
|
871
|
+
return condition;
|
|
872
|
+
};
|
|
873
|
+
const unexpectedTrackerCommand = (action) => {
|
|
874
|
+
throw new Error(`Unexpected tracker command: ${JSON.stringify(action)}`);
|
|
875
|
+
};
|
|
876
|
+
const applyTrackerCommand = (tracker, action) => {
|
|
877
|
+
var _a, _b;
|
|
878
|
+
switch (action.command) {
|
|
879
|
+
case 'block': {
|
|
880
|
+
const blocks = initiativeBlocks(tracker);
|
|
881
|
+
for (let i = 0; i < blocks.length; ++i) {
|
|
882
|
+
const state = i < action.index ? 'check' : i === action.index ? 'arrow' : 'empty';
|
|
883
|
+
blocks[i].forEach((entry) => {
|
|
884
|
+
entry.state = state;
|
|
885
|
+
});
|
|
886
|
+
}
|
|
887
|
+
return tracker;
|
|
888
|
+
}
|
|
889
|
+
case 'wait': {
|
|
890
|
+
const blocks = initiativeBlocks(tracker);
|
|
891
|
+
const blockIndex = blocks.findIndex((block) => block.find((entry) => sameTag(entry, action.tag)));
|
|
892
|
+
const block = blocks[blockIndex + 1];
|
|
893
|
+
const item = findCharacter(tracker, action.tag);
|
|
894
|
+
if (block && item) {
|
|
895
|
+
item.init = ((_b = (_a = block[block.length - 1]) === null || _a === void 0 ? void 0 : _a.init) !== null && _b !== void 0 ? _b : 0) - 1;
|
|
896
|
+
}
|
|
897
|
+
return tracker;
|
|
898
|
+
}
|
|
899
|
+
case 'check':
|
|
900
|
+
case 'arrow':
|
|
901
|
+
case 'empty':
|
|
902
|
+
case 'cross': {
|
|
903
|
+
const item = findCharacter(tracker, action.tag);
|
|
904
|
+
if (item) {
|
|
905
|
+
item.state = action.command;
|
|
906
|
+
}
|
|
907
|
+
return tracker;
|
|
908
|
+
}
|
|
909
|
+
case 'delete':
|
|
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
|
+
};
|
|
917
|
+
case 'purge':
|
|
918
|
+
return {
|
|
919
|
+
...tracker,
|
|
920
|
+
chars: tracker.chars.filter((entry) => !entry.foe),
|
|
921
|
+
};
|
|
922
|
+
case 'heal':
|
|
923
|
+
tracker.chars.forEach((char) => {
|
|
924
|
+
char.hp = char.maxhp;
|
|
925
|
+
char.children.forEach((child) => {
|
|
926
|
+
child.hp = child.maxhp;
|
|
927
|
+
});
|
|
928
|
+
});
|
|
929
|
+
return tracker;
|
|
930
|
+
case 'reset':
|
|
931
|
+
tracker.chars.forEach((char) => {
|
|
932
|
+
char.state = 'empty';
|
|
933
|
+
});
|
|
934
|
+
return tracker;
|
|
935
|
+
case 'set-thp': {
|
|
936
|
+
const item = findCharacterOrChild(tracker, action.tag);
|
|
937
|
+
if (item) {
|
|
938
|
+
item.temphp = Math.max(0, action.value);
|
|
939
|
+
}
|
|
940
|
+
return tracker;
|
|
941
|
+
}
|
|
942
|
+
case 'set-hp': {
|
|
943
|
+
const item = findCharacterOrChild(tracker, action.tag);
|
|
944
|
+
if (item) {
|
|
945
|
+
item.hp = Math.min(item.maxhp, Math.max(0, action.value));
|
|
946
|
+
}
|
|
947
|
+
return tracker;
|
|
948
|
+
}
|
|
949
|
+
case 'set-init': {
|
|
950
|
+
const item = findCharacter(tracker, action.tag);
|
|
951
|
+
if (item) {
|
|
952
|
+
item.init = Math.max(0, action.value);
|
|
953
|
+
}
|
|
954
|
+
return tracker;
|
|
955
|
+
}
|
|
956
|
+
case 'blank':
|
|
957
|
+
tracker.chars.forEach((item) => {
|
|
958
|
+
item.conditions = '';
|
|
959
|
+
item.children.forEach((child) => {
|
|
960
|
+
child.conditions = '';
|
|
961
|
+
});
|
|
962
|
+
});
|
|
963
|
+
return tracker;
|
|
964
|
+
case 'set-conditions': {
|
|
965
|
+
const item = findCharacterOrChild(tracker, action.tag);
|
|
966
|
+
if (item) {
|
|
967
|
+
item.conditions = action.value.trim();
|
|
968
|
+
}
|
|
969
|
+
return tracker;
|
|
970
|
+
}
|
|
971
|
+
case 'add-conditions':
|
|
972
|
+
updateConditions(tracker, action.tag, (conditions) => [...conditions, action.value.toLowerCase().trim()]);
|
|
973
|
+
return tracker;
|
|
974
|
+
case 'rem-conditions':
|
|
975
|
+
updateConditions(tracker, action.tag, (conditions) => conditions.filter((condition) => !condition.includes(action.value.toLowerCase().trim())));
|
|
976
|
+
return tracker;
|
|
977
|
+
case 'inc-conditions':
|
|
978
|
+
updateConditions(tracker, action.tag, (conditions) => conditions.map((condition) => (numberedCondition(condition, action.value.toLowerCase().trim(), (label, value) => `${label} ${value + 1}`))));
|
|
979
|
+
return tracker;
|
|
980
|
+
case 'dec-conditions':
|
|
981
|
+
updateConditions(tracker, action.tag, (conditions) => conditions.map((condition) => (numberedCondition(condition, action.value.toLowerCase().trim(), (label, value) => (value > 1 ? `${label} ${value - 1}` : label)))));
|
|
982
|
+
return tracker;
|
|
983
|
+
case 'mod-thp': {
|
|
984
|
+
const item = findCharacterOrChild(tracker, action.tag);
|
|
985
|
+
if (item) {
|
|
986
|
+
item.temphp = Math.max(0, item.temphp + action.value);
|
|
987
|
+
}
|
|
988
|
+
return tracker;
|
|
989
|
+
}
|
|
990
|
+
case 'mod-hp': {
|
|
991
|
+
const item = findCharacterOrChild(tracker, action.tag);
|
|
992
|
+
if (item) {
|
|
993
|
+
let hp = item.hp;
|
|
994
|
+
let thp = item.temphp;
|
|
995
|
+
if (action.value < 0) {
|
|
996
|
+
thp += action.value;
|
|
997
|
+
hp += Math.min(thp, 0);
|
|
998
|
+
}
|
|
999
|
+
else {
|
|
1000
|
+
hp += action.value;
|
|
1001
|
+
}
|
|
1002
|
+
item.temphp = Math.max(0, thp);
|
|
1003
|
+
item.hp = Math.min(item.maxhp, Math.max(0, hp));
|
|
1004
|
+
}
|
|
1005
|
+
return tracker;
|
|
1006
|
+
}
|
|
1007
|
+
case 'mod-init': {
|
|
1008
|
+
const item = findCharacter(tracker, action.tag);
|
|
1009
|
+
if (item) {
|
|
1010
|
+
item.init = Math.max(0, item.init + action.value);
|
|
1011
|
+
}
|
|
1012
|
+
return tracker;
|
|
1013
|
+
}
|
|
1014
|
+
case 'foe':
|
|
1015
|
+
tracker.chars.push(exports.charSchema.parse({ foe: true, name: action.name, alias: action.alias, maxhp: action.hp, hp: action.hp }));
|
|
1016
|
+
return tracker;
|
|
1017
|
+
default:
|
|
1018
|
+
return unexpectedTrackerCommand(action);
|
|
1019
|
+
}
|
|
1020
|
+
};
|
|
1021
|
+
const applyTrackerCommands = (tracker, actions) => {
|
|
1022
|
+
let next = tracker;
|
|
1023
|
+
for (const action of actions) {
|
|
1024
|
+
if (action.command === 'exit') {
|
|
1025
|
+
return { tracker: next, exit: true };
|
|
1026
|
+
}
|
|
1027
|
+
next = applyTrackerCommand(next, action);
|
|
1028
|
+
}
|
|
1029
|
+
return { tracker: next, exit: false };
|
|
1030
|
+
};
|
|
1031
|
+
exports.applyTrackerCommands = applyTrackerCommands;
|
|
696
1032
|
const sortFolder = async () => {
|
|
697
1033
|
const dir = await (0, promises_1.readdir)('.');
|
|
698
1034
|
const summary = await Promise.all(dir.map(async (file) => {
|
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
|
}
|
|
@@ -188,355 +192,20 @@ program.command('track')
|
|
|
188
192
|
}
|
|
189
193
|
})(),
|
|
190
194
|
(async () => {
|
|
191
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
192
195
|
const rl = readline_1.default.createInterface({
|
|
193
196
|
input: process.stdin,
|
|
194
197
|
output: process.stdout
|
|
195
198
|
});
|
|
196
199
|
while (true) {
|
|
197
200
|
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
198
|
-
|
|
199
|
-
const commands = [{
|
|
200
|
-
regex: /^\s*[bB]\s*(\d+)/,
|
|
201
|
-
map: (match) => ({ command: 'block', index: parseInt(match[1], 10) })
|
|
202
|
-
}, {
|
|
203
|
-
regex: /^\s*reset/i,
|
|
204
|
-
map: () => ({ command: 'reset' })
|
|
205
|
-
}, {
|
|
206
|
-
regex: /^\s*purge/i,
|
|
207
|
-
map: () => ({ command: 'purge' })
|
|
208
|
-
}, {
|
|
209
|
-
regex: /^\s*blank/i,
|
|
210
|
-
map: () => ({ command: 'blank' })
|
|
211
|
-
}, {
|
|
212
|
-
regex: /^\s*foe(\s+(\S+))?(\s+(\S+))?(\s+(\d+))?/i,
|
|
213
|
-
map: (match) => ({ command: 'foe', name: match[2], alias: match[4], hp: match[6] && parseInt(match[6], 10) })
|
|
214
|
-
}, {
|
|
215
|
-
regex: /^\s*heal/i,
|
|
216
|
-
map: () => ({ command: 'heal' })
|
|
217
|
-
}, {
|
|
218
|
-
regex: /^\s*exit/i,
|
|
219
|
-
map: () => ({ command: 'exit' })
|
|
220
|
-
}, {
|
|
221
|
-
regex: /^\s*([^\d\s+-]+)\s*([+-]?\d+)/,
|
|
222
|
-
map: (match) => {
|
|
223
|
-
if (match[2].match(/^[+-]/)) {
|
|
224
|
-
return { command: 'mod-hp', tag: match[1], value: parseInt(match[2]) };
|
|
225
|
-
}
|
|
226
|
-
else {
|
|
227
|
-
return { command: 'set-hp', tag: match[1], value: parseInt(match[2]) };
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
}, {
|
|
231
|
-
regex: /^\s*(\S+)\s+[tT]\s*([+-]?\d+)/,
|
|
232
|
-
map: (match) => {
|
|
233
|
-
if (match[2].match(/^[+-]/)) {
|
|
234
|
-
return { command: 'mod-thp', tag: match[1], value: parseInt(match[2]) };
|
|
235
|
-
}
|
|
236
|
-
else {
|
|
237
|
-
return { command: 'set-thp', tag: match[1], value: parseInt(match[2]) };
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
}, {
|
|
241
|
-
regex: /^\s*(\S+)\s+[iI]\s*([+-]?\d+)/,
|
|
242
|
-
map: (match) => {
|
|
243
|
-
if (match[2].match(/^[+-]/)) {
|
|
244
|
-
return { command: 'mod-init', tag: match[1], value: parseInt(match[2]) };
|
|
245
|
-
}
|
|
246
|
-
else {
|
|
247
|
-
return { command: 'set-init', tag: match[1], value: parseInt(match[2]) };
|
|
248
|
-
}
|
|
249
|
-
},
|
|
250
|
-
}, {
|
|
251
|
-
regex: /^\s*([^\s="+-]+)\s*=?"([^"]*)"/,
|
|
252
|
-
map: (match) => {
|
|
253
|
-
return { command: 'set-conditions', tag: match[1], value: match[2] };
|
|
254
|
-
},
|
|
255
|
-
}, {
|
|
256
|
-
regex: /^\s*([^\s="+-]+)\s*\+"([^"]*)"/,
|
|
257
|
-
map: (match) => {
|
|
258
|
-
return { command: 'add-conditions', tag: match[1], value: match[2] };
|
|
259
|
-
},
|
|
260
|
-
}, {
|
|
261
|
-
regex: /^\s*([^\s="+-]+)\s*-"([^"]*)"/,
|
|
262
|
-
map: (match) => {
|
|
263
|
-
return { command: 'rem-conditions', tag: match[1], value: match[2] };
|
|
264
|
-
},
|
|
265
|
-
}, {
|
|
266
|
-
regex: /^\s*([^\s="+-]+)\s*\+\+"([^"]*)"/,
|
|
267
|
-
map: (match) => {
|
|
268
|
-
return { command: 'inc-conditions', tag: match[1], value: match[2] };
|
|
269
|
-
},
|
|
270
|
-
}, {
|
|
271
|
-
regex: /^\s*([^\s="+-]+)\s*--"([^"]*)"/,
|
|
272
|
-
map: (match) => {
|
|
273
|
-
return { command: 'dec-conditions', tag: match[1], value: match[2] };
|
|
274
|
-
},
|
|
275
|
-
}, {
|
|
276
|
-
regex: /^\s*(\S+)\s+[sS]?\s*=?"([^"]*)"/,
|
|
277
|
-
map: (match) => {
|
|
278
|
-
return { command: 'set-conditions', tag: match[1], value: match[2] };
|
|
279
|
-
},
|
|
280
|
-
}, {
|
|
281
|
-
regex: /^\s*(\S+)\s+[sS]?\s*\+"([^"]*)"/,
|
|
282
|
-
map: (match) => {
|
|
283
|
-
return { command: 'add-conditions', tag: match[1], value: match[2] };
|
|
284
|
-
},
|
|
285
|
-
}, {
|
|
286
|
-
regex: /^\s*(\S+)\s+[sS]?\s*-"([^"]*)"/,
|
|
287
|
-
map: (match) => {
|
|
288
|
-
return { command: 'rem-conditions', tag: match[1], value: match[2] };
|
|
289
|
-
},
|
|
290
|
-
}, {
|
|
291
|
-
regex: /^\s*(\S+)\s+[sS]?\s*\+\+"([^"]*)"/,
|
|
292
|
-
map: (match) => {
|
|
293
|
-
return { command: 'inc-conditions', tag: match[1], value: match[2] };
|
|
294
|
-
},
|
|
295
|
-
}, {
|
|
296
|
-
regex: /^\s*(\S+)\s+[sS]?\s*--"([^"]*)"/,
|
|
297
|
-
map: (match) => {
|
|
298
|
-
return { command: 'dec-conditions', tag: match[1], value: match[2] };
|
|
299
|
-
},
|
|
300
|
-
}, {
|
|
301
|
-
regex: /^\s*(\S+)\s+[cC]/,
|
|
302
|
-
map: (match) => ({ command: 'check', tag: match[1] }),
|
|
303
|
-
}, {
|
|
304
|
-
regex: /^\s*(\S+)\s+[aA]/,
|
|
305
|
-
map: (match) => ({ command: 'arrow', tag: match[1] }),
|
|
306
|
-
}, {
|
|
307
|
-
regex: /^\s*(\S+)\s+[eE]/,
|
|
308
|
-
map: (match) => ({ command: 'empty', tag: match[1] }),
|
|
309
|
-
}, {
|
|
310
|
-
regex: /^\s*(\S+)\s+[xX]/,
|
|
311
|
-
map: (match) => ({ command: 'cross', tag: match[1] }),
|
|
312
|
-
}, {
|
|
313
|
-
regex: /^\s*(\S+)\s+[dD]/,
|
|
314
|
-
map: (match) => ({ command: 'delete', tag: match[1] }),
|
|
315
|
-
}, {
|
|
316
|
-
regex: /^\s*(\S+)\s+[wW]/,
|
|
317
|
-
map: (match) => ({ command: 'wait', tag: match[1] }),
|
|
318
|
-
}];
|
|
319
|
-
const actions = [];
|
|
320
|
-
while (true) {
|
|
321
|
-
const command = commands.find((c) => input.match(c.regex));
|
|
322
|
-
if (!command) {
|
|
323
|
-
break;
|
|
324
|
-
}
|
|
325
|
-
const match = input.match(command.regex);
|
|
326
|
-
if (!match) {
|
|
327
|
-
break;
|
|
328
|
-
}
|
|
329
|
-
const action = command.map(match);
|
|
330
|
-
input = input.slice(match[0].length);
|
|
331
|
-
actions.push(action);
|
|
332
|
-
}
|
|
201
|
+
const input = await new Promise((resolve) => (rl.question('> ', resolve)));
|
|
333
202
|
const file = await promises_1.default.readFile(argument, { encoding: 'utf-8' });
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
const blocks = [[sorted[0]]];
|
|
339
|
-
for (let i = 1; i < sorted.length; ++i) {
|
|
340
|
-
if (sorted[i].foe === blocks[blocks.length - 1][0].foe) {
|
|
341
|
-
blocks[blocks.length - 1].push(sorted[i]);
|
|
342
|
-
}
|
|
343
|
-
else {
|
|
344
|
-
blocks.push([sorted[i]]);
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
for (let i = 0; i < blocks.length; ++i) {
|
|
348
|
-
if (i < action.index) {
|
|
349
|
-
blocks[i].forEach((b) => b.state = 'check');
|
|
350
|
-
}
|
|
351
|
-
else if (i === action.index) {
|
|
352
|
-
blocks[i].forEach((b) => b.state = 'arrow');
|
|
353
|
-
}
|
|
354
|
-
else {
|
|
355
|
-
blocks[i].forEach((b) => b.state = 'empty');
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
else if (action.command === 'wait') {
|
|
360
|
-
const sorted = [...tracker].sort((a, b) => (a.init === b.init) ? (b.foe ? 1 : 0) - (a.foe ? 1 : 0) : b.init - a.init);
|
|
361
|
-
const blocks = [[sorted[0]]];
|
|
362
|
-
for (let i = 1; i < sorted.length; ++i) {
|
|
363
|
-
if (sorted[i].foe === blocks[blocks.length - 1][0].foe) {
|
|
364
|
-
blocks[blocks.length - 1].push(sorted[i]);
|
|
365
|
-
}
|
|
366
|
-
else {
|
|
367
|
-
blocks.push([sorted[i]]);
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
const blockIndex = blocks.findIndex((b) => b.find((c) => c.id === action.tag || c.alias === action.tag || c.name == action.tag));
|
|
371
|
-
const block = blocks[blockIndex + 1];
|
|
372
|
-
const item = tracker.find((c) => c.id === action.tag || c.alias === action.tag || c.name == action.tag);
|
|
373
|
-
if (block && item) {
|
|
374
|
-
item.init = ((_b = (_a = block[block.length - 1]) === null || _a === void 0 ? void 0 : _a.init) !== null && _b !== void 0 ? _b : 0) - 1;
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
else if (action.command === 'check') {
|
|
378
|
-
const item = tracker.find((c) => c.id === action.tag || c.alias === action.tag || c.name == action.tag);
|
|
379
|
-
if (item) {
|
|
380
|
-
item.state = "check";
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
else if (action.command === 'arrow') {
|
|
384
|
-
const item = tracker.find((c) => c.id === action.tag || c.alias === action.tag || c.name == action.tag);
|
|
385
|
-
if (item) {
|
|
386
|
-
item.state = "arrow";
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
|
-
else if (action.command === 'empty') {
|
|
390
|
-
const item = tracker.find((c) => c.id === action.tag || c.alias === action.tag || c.name == action.tag);
|
|
391
|
-
if (item) {
|
|
392
|
-
item.state = "empty";
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
else if (action.command === 'cross') {
|
|
396
|
-
const item = tracker.find((c) => c.id === action.tag || c.alias === action.tag || c.name == action.tag);
|
|
397
|
-
if (item) {
|
|
398
|
-
item.state = "cross";
|
|
399
|
-
}
|
|
400
|
-
}
|
|
401
|
-
else if (action.command === 'delete') {
|
|
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
|
-
}));
|
|
406
|
-
}
|
|
407
|
-
else if (action.command === 'purge') {
|
|
408
|
-
tracker = tracker.filter((c) => !c.foe);
|
|
409
|
-
}
|
|
410
|
-
else if (action.command === 'exit') {
|
|
411
|
-
process.exit(0);
|
|
412
|
-
}
|
|
413
|
-
else if (action.command === 'heal') {
|
|
414
|
-
tracker.forEach((char) => {
|
|
415
|
-
char.hp = char.maxhp;
|
|
416
|
-
char.children.forEach((child) => {
|
|
417
|
-
child.hp = child.maxhp;
|
|
418
|
-
});
|
|
419
|
-
});
|
|
420
|
-
}
|
|
421
|
-
else if (action.command === 'reset') {
|
|
422
|
-
tracker.forEach((char) => {
|
|
423
|
-
char.state = 'empty';
|
|
424
|
-
});
|
|
425
|
-
}
|
|
426
|
-
else if (action.command === 'set-thp') {
|
|
427
|
-
const item = (_c = tracker.find((c) => c.id === action.tag || c.alias === action.tag || c.name == action.tag)) !== null && _c !== void 0 ? _c : (tracker.flatMap((c) => c.children).find((c) => c.id === action.tag || c.alias === action.tag || c.name == action.tag));
|
|
428
|
-
if (item) {
|
|
429
|
-
item.temphp = Math.max(0, action.value);
|
|
430
|
-
}
|
|
431
|
-
}
|
|
432
|
-
else if (action.command === 'set-hp') {
|
|
433
|
-
const item = (_d = tracker.find((c) => c.id === action.tag || c.alias === action.tag || c.name == action.tag)) !== null && _d !== void 0 ? _d : (tracker.flatMap((c) => c.children).find((c) => c.id === action.tag || c.alias === action.tag || c.name == action.tag));
|
|
434
|
-
if (item) {
|
|
435
|
-
item.hp = Math.min(item.maxhp, Math.max(0, action.value));
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
else if (action.command === 'set-init') {
|
|
439
|
-
const item = tracker.find((c) => c.id === action.tag || c.alias === action.tag || c.name == action.tag);
|
|
440
|
-
if (item) {
|
|
441
|
-
item.init = Math.max(0, action.value);
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
else if (action.command === 'blank') {
|
|
445
|
-
tracker.forEach((item) => {
|
|
446
|
-
item.conditions = "";
|
|
447
|
-
item.children.forEach((child) => {
|
|
448
|
-
child.conditions = "";
|
|
449
|
-
});
|
|
450
|
-
});
|
|
451
|
-
}
|
|
452
|
-
else if (action.command === 'set-conditions') {
|
|
453
|
-
const item = (_e = tracker.find((c) => c.id === action.tag || c.alias === action.tag || c.name == action.tag)) !== null && _e !== void 0 ? _e : (tracker.flatMap((c) => c.children).find((c) => c.id === action.tag || c.alias === action.tag || c.name == action.tag));
|
|
454
|
-
if (item) {
|
|
455
|
-
item.conditions = action.value.trim();
|
|
456
|
-
}
|
|
457
|
-
}
|
|
458
|
-
else if (action.command === 'add-conditions') {
|
|
459
|
-
const item = (_f = tracker.find((c) => c.id === action.tag || c.alias === action.tag || c.name == action.tag)) !== null && _f !== void 0 ? _f : (tracker.flatMap((c) => c.children).find((c) => c.id === action.tag || c.alias === action.tag || c.name == action.tag));
|
|
460
|
-
if (item) {
|
|
461
|
-
const conditions = [...item.conditions.split(',').map((c) => c.toLowerCase().trim()).filter((c) => c.length), action.value.toLowerCase().trim()];
|
|
462
|
-
item.conditions = conditions.join(', ');
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
else if (action.command === 'rem-conditions') {
|
|
466
|
-
const item = (_g = tracker.find((c) => c.id === action.tag || c.alias === action.tag || c.name == action.tag)) !== null && _g !== void 0 ? _g : (tracker.flatMap((c) => c.children).find((c) => c.id === action.tag || c.alias === action.tag || c.name == action.tag));
|
|
467
|
-
if (item) {
|
|
468
|
-
const conditions = item.conditions.split(',').map((c) => c.toLowerCase().trim()).filter((c) => c.length).filter((c) => !c.includes(action.value.toLowerCase().trim()));
|
|
469
|
-
item.conditions = conditions.join(', ');
|
|
470
|
-
}
|
|
471
|
-
}
|
|
472
|
-
else if (action.command === 'inc-conditions') {
|
|
473
|
-
const item = (_h = tracker.find((c) => c.id === action.tag || c.alias === action.tag || c.name == action.tag)) !== null && _h !== void 0 ? _h : (tracker.flatMap((c) => c.children).find((c) => c.id === action.tag || c.alias === action.tag || c.name == action.tag));
|
|
474
|
-
if (item) {
|
|
475
|
-
const conditions = item.conditions.split(',').map((c) => c.toLowerCase().trim()).filter((c) => c.length).map((c) => {
|
|
476
|
-
if (c.includes(action.value.toLowerCase().trim())) {
|
|
477
|
-
const match = c.match(/(.*)\s+(\d+)/);
|
|
478
|
-
if (match && match[1] && match[2]) {
|
|
479
|
-
return `${match[1].trim()} ${parseInt(match[2]) + 1}`;
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
return c;
|
|
483
|
-
});
|
|
484
|
-
item.conditions = conditions.join(', ');
|
|
485
|
-
}
|
|
486
|
-
}
|
|
487
|
-
else if (action.command === 'dec-conditions') {
|
|
488
|
-
const item = (_j = tracker.find((c) => c.id === action.tag || c.alias === action.tag || c.name == action.tag)) !== null && _j !== void 0 ? _j : (tracker.flatMap((c) => c.children).find((c) => c.id === action.tag || c.alias === action.tag || c.name == action.tag));
|
|
489
|
-
if (item) {
|
|
490
|
-
const conditions = item.conditions.split(',').map((c) => c.toLowerCase().trim()).filter((c) => c.length).map((c) => {
|
|
491
|
-
if (c.includes(action.value.toLowerCase().trim())) {
|
|
492
|
-
const match = c.match(/(.*)\s+(\d+)/);
|
|
493
|
-
if (match && match[1] && match[2]) {
|
|
494
|
-
if (parseInt(match[2]) > 1) {
|
|
495
|
-
return `${match[1].trim()} ${parseInt(match[2]) - 1}`;
|
|
496
|
-
}
|
|
497
|
-
else {
|
|
498
|
-
return match[1].trim();
|
|
499
|
-
}
|
|
500
|
-
}
|
|
501
|
-
}
|
|
502
|
-
return c;
|
|
503
|
-
});
|
|
504
|
-
item.conditions = conditions.join(', ');
|
|
505
|
-
}
|
|
506
|
-
}
|
|
507
|
-
else if (action.command === 'mod-thp') {
|
|
508
|
-
const item = (_k = tracker.find((c) => c.id === action.tag || c.alias === action.tag || c.name == action.tag)) !== null && _k !== void 0 ? _k : (tracker.flatMap((c) => c.children).find((c) => c.id === action.tag || c.alias === action.tag || c.name == action.tag));
|
|
509
|
-
if (item) {
|
|
510
|
-
item.temphp = Math.max(0, item.temphp + action.value);
|
|
511
|
-
}
|
|
512
|
-
}
|
|
513
|
-
else if (action.command === 'mod-hp') {
|
|
514
|
-
const item = (_l = tracker.find((c) => c.id === action.tag || c.alias === action.tag || c.name == action.tag)) !== null && _l !== void 0 ? _l : (tracker.flatMap((c) => c.children).find((c) => c.id === action.tag || c.alias === action.tag || c.name == action.tag));
|
|
515
|
-
if (item) {
|
|
516
|
-
let hp = item.hp;
|
|
517
|
-
let thp = item.temphp;
|
|
518
|
-
if (action.value < 0) {
|
|
519
|
-
thp += action.value;
|
|
520
|
-
hp += Math.min(thp, 0);
|
|
521
|
-
}
|
|
522
|
-
else {
|
|
523
|
-
hp += action.value;
|
|
524
|
-
}
|
|
525
|
-
item.temphp = Math.max(0, thp);
|
|
526
|
-
item.hp = Math.min(item.maxhp, Math.max(0, hp));
|
|
527
|
-
}
|
|
528
|
-
}
|
|
529
|
-
else if (action.command === 'mod-init') {
|
|
530
|
-
const item = tracker.find((c) => c.id === action.tag || c.alias === action.tag || c.name == action.tag);
|
|
531
|
-
if (item) {
|
|
532
|
-
item.init = Math.max(0, item.init + action.value);
|
|
533
|
-
}
|
|
534
|
-
}
|
|
535
|
-
else if (action.command === 'foe') {
|
|
536
|
-
tracker.push(app_1.charSchema.parse({ foe: true, name: action.name, alias: action.alias, maxhp: action.hp, hp: action.hp }));
|
|
537
|
-
}
|
|
203
|
+
const tracker = (0, app_1.parseTracker)(file);
|
|
204
|
+
const { tracker: next, exit } = (0, app_1.applyTrackerCommands)(tracker, (0, app_1.parseTrackerCommands)(input));
|
|
205
|
+
if (exit) {
|
|
206
|
+
process.exit(0);
|
|
538
207
|
}
|
|
539
|
-
await promises_1.default.writeFile(argument, JSON.stringify(
|
|
208
|
+
await promises_1.default.writeFile(argument, JSON.stringify(next, undefined, 2), { encoding: 'utf-8' });
|
|
540
209
|
}
|
|
541
210
|
})(),
|
|
542
211
|
]);
|