advanced-poe-filter-parser 0.9.0 → 0.9.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.
@@ -1,1173 +0,0 @@
1
- import test from "ava"
2
- import outdent from "outdent"
3
-
4
- import { parse } from "../lib/parser.mjs"
5
-
6
- test("parse : blank and comment lines", (t) => {
7
- const script = [
8
- "# This is a comment",
9
- "# This is a comment",
10
- 'Hide "Hide Map Section"',
11
- ' Class "Maps"',
12
- " MapTier <= 4",
13
- " ",
14
- "# This is a comment",
15
- 'Show "Flask Section"',
16
- " # This is a comment",
17
- ' Class "Life Flasks" "Mana Flasks" "Hybrid Flasks"',
18
- " SetBorderColor 250 251 252",
19
- " PlayAlertSound 1 300",
20
- " ",
21
- 'Hide "Remain Section"',
22
- "",
23
- ].join("\n")
24
-
25
- const expected = [
26
- {
27
- id: "0001",
28
- name: "Hide Map Section",
29
- activity: "Hide",
30
- conditions: {
31
- Class: { ope: "=", vals: ["Maps"] },
32
- MapTier: "<= 4",
33
- },
34
- actions: {},
35
- branches: [],
36
- location: {
37
- start: {
38
- line: 1,
39
- column: 1,
40
- offset: 0,
41
- },
42
- end: {
43
- line: 8,
44
- column: 1,
45
- offset: 136,
46
- },
47
- },
48
- },
49
- {
50
- id: "0001",
51
- name: "Flask Section",
52
- activity: "Show",
53
- conditions: {
54
- Class: { ope: "=", vals: ["Life Flasks", "Mana Flasks", "Hybrid Flasks"] },
55
- },
56
- actions: {
57
- SetBorderColor: { rgb: { r: 250, g: 251, b: 252 }, alpha: 255 },
58
- PlayAlertSound: { id: "1", volume: 300 },
59
- },
60
- branches: [],
61
- location: {
62
- start: {
63
- line: 8,
64
- column: 1,
65
- offset: 136,
66
- },
67
- end: {
68
- line: 14,
69
- column: 1,
70
- offset: 317,
71
- },
72
- },
73
- },
74
- {
75
- id: "0001",
76
- name: "Remain Section",
77
- activity: "Hide",
78
- conditions: {},
79
- actions: {},
80
- branches: [],
81
- location: {
82
- start: {
83
- line: 14,
84
- column: 1,
85
- offset: 317,
86
- },
87
- end: {
88
- line: 15,
89
- column: 1,
90
- offset: 339,
91
- },
92
- },
93
- },
94
- ]
95
-
96
- const result = parse(script)
97
-
98
- t.deepEqual(result, expected)
99
- })
100
-
101
- test("parse : all actions and conditions", (t) => {
102
- const script = outdent`
103
- Show "Section1"
104
- Class "Maps"
105
- BaseType "Sacrificial Garb"
106
- DropLevel > 85
107
- ItemLevel >= 70
108
- AreaLevel < 30
109
- GemLevel = 10
110
- GemQualityType "Superior"
111
- StackSize < 11
112
- MapTier <= 12
113
- Quality = 15
114
- LinkedSockets = 6
115
- Sockets = 5
116
- SocketGroup RGB
117
- Rarity = Rare
118
- BaseDefencePercentile > 50
119
- BaseArmour > 40
120
- BaseEnergyShield > 41
121
- BaseEvasion > 42
122
- BaseWard > 43
123
- FracturedItem False
124
- SynthesisedItem False
125
- Corrupted True
126
- Mirrored True
127
- Identified True
128
- Scourged True
129
- ShapedMap True
130
- ElderMap True
131
- BlightedMap True
132
- UberBlightedMap True
133
- Height > 1
134
- Width > 2
135
- CorruptedMods >= 1
136
- EnchantmentPassiveNum > 5
137
- HasExplicitMod "Foo" "Bar"
138
- HasImplicitMod True
139
- HasEaterOfWorldsImplicit >= 4
140
- HasSearingExarchImplicit >= 4
141
- AnyEnchantment True
142
- HasEnchantment "Foo" "Bar"
143
- HasInfluence "Shaper" "Elder"
144
- EnchantmentPassiveNode "Damage while you have a Herald" "Projectile Damage"
145
- AlternateQuality True
146
- Replica True
147
- SetBorderColor 100 101 102
148
- SetTextColor 103 104 105
149
- SetBackgroundColor 106 107 108
150
- SetFontSize 30
151
- PlayAlertSound 16 300
152
- EnableDropSound
153
- CustomAlertSound "C\\foobar\\sound.mp3" 300
154
- MinimapIcon 0 Red Circle
155
- PlayEffect Red
156
- ArchnemesisMod "Toxic"
157
- HasCruciblePassiveTree True
158
- Show "Section2"
159
- Class "Life Flasks" "Mana Flasks" "Hybrid Flasks"
160
- BaseType "Two-Toned Boots" "Spiked Gloves" "Gripped Gloves" "Fingerless Silk Gloves" "Bone Helmet"
161
- SocketGroup W
162
- Rarity Rare
163
- HasExplicitMod == "Foo" "Bar"
164
- HasEnchantment == "Foo" "Bar"
165
- HasInfluence == "Shaper" "Elder"
166
- SetBorderColor 100 101 102 200
167
- SetTextColor 103 104 105 201
168
- SetBackgroundColor 106 107 108 202
169
- PlayAlertSound 2
170
- DisableDropSound
171
- CustomAlertSound "C\\foobar\\sound.mp3"
172
- MinimapIcon Medium Red Circle
173
- PlayEffect Blue Temp
174
- Show "Section3"
175
- HasExplicitMod >= 2 "Foo" "Bar"
176
- HasEnchantment >= 2 "Foo" "Bar"
177
- HasInfluence None
178
- SetBorderColor Negate()
179
- SetTextColor Grayscale()
180
- SetBackgroundColor Lighten(10%)
181
- SetFontSize Plus(5)
182
- PlayAlertSoundPositional ShAlchemy 200
183
- Ignore "Section4"
184
- SetBorderColor Darken(20%)
185
- SetTextColor Whiten(31%)
186
- SetBackgroundColor Blacken(100%)
187
- SetFontSize Minus(6)
188
- PlayAlertSoundPositional ShBlessed
189
- Hide "Section5"
190
- SetBorderColor Saturate(42%)
191
- SetTextColor Desaturate(53%)
192
- SetBackgroundColor Hex(123)
193
- Unset "Section6"
194
- SetBorderColor Saturation(64%)
195
- SetTextColor Lightness(75%)
196
-
197
- `
198
-
199
- const expected = [
200
- {
201
- id: "0001",
202
- name: "Section1",
203
- activity: "Show",
204
- conditions: {
205
- Class: { ope: "=", vals: ["Maps"] },
206
- BaseType: { ope: "=", vals: ["Sacrificial Garb"] },
207
- DropLevel: "> 85",
208
- ItemLevel: ">= 70",
209
- AreaLevel: "< 30",
210
- GemLevel: "= 10",
211
- GemQualityType: { ope: "=", vals: ["Superior"] },
212
- StackSize: "< 11",
213
- MapTier: "<= 12",
214
- Quality: "= 15",
215
- LinkedSockets: "= 6",
216
- Sockets: "= 5",
217
- SocketGroup: "RGB",
218
- Rarity: "= Rare",
219
- BaseDefencePercentile: "> 50",
220
- BaseArmour: "> 40",
221
- BaseEnergyShield: "> 41",
222
- BaseEvasion: "> 42",
223
- BaseWard: "> 43",
224
- FracturedItem: false,
225
- SynthesisedItem: false,
226
- Corrupted: true,
227
- Mirrored: true,
228
- Identified: true,
229
- Scourged: true,
230
- ShapedMap: true,
231
- ElderMap: true,
232
- BlightedMap: true,
233
- UberBlightedMap: true,
234
- Height: "> 1",
235
- Width: "> 2",
236
- CorruptedMods: ">= 1",
237
- EnchantmentPassiveNum: "> 5",
238
- HasExplicitMod: { ope: "=", vals: ["Foo", "Bar"] },
239
- HasImplicitMod: true,
240
- HasEaterOfWorldsImplicit: ">= 4",
241
- HasSearingExarchImplicit: ">= 4",
242
- AnyEnchantment: true,
243
- HasEnchantment: { ope: "=", vals: ["Foo", "Bar"] },
244
- HasInfluence: { ope: "=", vals: ["Shaper", "Elder"] },
245
- EnchantmentPassiveNode: {
246
- ope: "=",
247
- vals: ["Damage while you have a Herald", "Projectile Damage"],
248
- },
249
- AlternateQuality: true,
250
- Replica: true,
251
- ArchnemesisMod: { ope: "=", vals: ["Toxic"] },
252
- HasCruciblePassiveTree: true,
253
- },
254
- actions: {
255
- SetBorderColor: { rgb: { r: 100, g: 101, b: 102 }, alpha: 255 },
256
- SetTextColor: { rgb: { r: 103, g: 104, b: 105 }, alpha: 255 },
257
- SetBackgroundColor: { rgb: { r: 106, g: 107, b: 108 }, alpha: 255 },
258
- SetFontSize: 30,
259
- PlayAlertSound: { id: "16", volume: 300 },
260
- EnableDropSound: true,
261
- CustomAlertSound: { filePath: "C\\foobar\\sound.mp3", volume: 300 },
262
- MinimapIcon: { size: "Largest", color: "Red", shape: "Circle" },
263
- PlayEffect: { color: "Red", temp: false },
264
- },
265
- branches: [],
266
- location: {
267
- start: {
268
- line: 1,
269
- column: 1,
270
- offset: 0,
271
- },
272
- end: {
273
- line: 56,
274
- column: 1,
275
- offset: 1600,
276
- },
277
- },
278
- },
279
- {
280
- id: "0001",
281
- name: "Section2",
282
- activity: "Show",
283
- conditions: {
284
- Class: {
285
- ope: "=",
286
- vals: ["Life Flasks", "Mana Flasks", "Hybrid Flasks"],
287
- },
288
- BaseType: {
289
- ope: "=",
290
- vals: ["Two-Toned Boots", "Spiked Gloves", "Gripped Gloves", "Fingerless Silk Gloves", "Bone Helmet"],
291
- },
292
- SocketGroup: "W",
293
- Rarity: "Rare",
294
- HasExplicitMod: { ope: "==", vals: ["Foo", "Bar"] },
295
- HasEnchantment: { ope: "==", vals: ["Foo", "Bar"] },
296
- HasInfluence: { ope: "==", vals: ["Shaper", "Elder"] },
297
- },
298
- actions: {
299
- SetBorderColor: { rgb: { r: 100, g: 101, b: 102 }, alpha: 200 },
300
- SetTextColor: { rgb: { r: 103, g: 104, b: 105 }, alpha: 201 },
301
- SetBackgroundColor: { rgb: { r: 106, g: 107, b: 108 }, alpha: 202 },
302
- PlayAlertSound: { id: "2", volume: undefined },
303
- DisableDropSound: true,
304
- CustomAlertSound: {
305
- filePath: "C\\foobar\\sound.mp3",
306
- volume: undefined,
307
- },
308
- MinimapIcon: { size: "Medium", color: "Red", shape: "Circle" },
309
- PlayEffect: { color: "Blue", temp: true },
310
- },
311
- branches: [],
312
- location: {
313
- start: {
314
- line: 56,
315
- column: 1,
316
- offset: 1600,
317
- },
318
- end: {
319
- line: 72,
320
- column: 1,
321
- offset: 2263,
322
- },
323
- },
324
- },
325
- {
326
- id: "0001",
327
- name: "Section3",
328
- activity: "Show",
329
- conditions: {
330
- HasExplicitMod: {
331
- numeric: { ope: ">=", val: 2 },
332
- vals: ["Foo", "Bar"],
333
- },
334
- HasEnchantment: {
335
- numeric: { ope: ">=", val: 2 },
336
- vals: ["Foo", "Bar"],
337
- },
338
- HasInfluence: { ope: undefined, val: "None" },
339
- },
340
- actions: {
341
- SetBorderColor: { function: "Negate", val: undefined },
342
- SetTextColor: { function: "Grayscale", val: undefined },
343
- SetBackgroundColor: { function: "Lighten", val: 0.1 },
344
- SetFontSize: { function: "Plus", val: 5 },
345
- PlayAlertSoundPositional: { id: "ShAlchemy", volume: 200 },
346
- },
347
- branches: [],
348
- location: {
349
- start: {
350
- line: 72,
351
- column: 1,
352
- offset: 2263,
353
- },
354
- end: {
355
- line: 81,
356
- column: 1,
357
- offset: 2574,
358
- },
359
- },
360
- },
361
- {
362
- id: "0001",
363
- name: "Section4",
364
- activity: "Ignore",
365
- conditions: {},
366
- actions: {
367
- SetBorderColor: { function: "Darken", val: 0.2 },
368
- SetTextColor: { function: "Whiten", val: 0.31 },
369
- SetBackgroundColor: { function: "Blacken", val: 1 },
370
- SetFontSize: { function: "Minus", val: 6 },
371
- PlayAlertSoundPositional: { id: "ShBlessed", volume: undefined },
372
- },
373
- branches: [],
374
- location: {
375
- start: {
376
- line: 81,
377
- column: 1,
378
- offset: 2574,
379
- },
380
- end: {
381
- line: 87,
382
- column: 1,
383
- offset: 2794,
384
- },
385
- },
386
- },
387
- {
388
- id: "0001",
389
- name: "Section5",
390
- activity: "Hide",
391
- conditions: {},
392
- actions: {
393
- SetBorderColor: { function: "Saturate", val: 0.42 },
394
- SetTextColor: { function: "Desaturate", val: 0.53 },
395
- SetBackgroundColor: { function: "Hex", val: 123 },
396
- },
397
- branches: [],
398
- location: {
399
- start: {
400
- line: 87,
401
- column: 1,
402
- offset: 2794,
403
- },
404
- end: {
405
- line: 91,
406
- column: 1,
407
- offset: 2936,
408
- },
409
- },
410
- },
411
- {
412
- id: "0001",
413
- name: "Section6",
414
- activity: "Unset",
415
- conditions: {},
416
- actions: {
417
- SetBorderColor: { function: "Saturationv", val: 64 },
418
- SetTextColor: { function: "Lightness", val: 75 },
419
- },
420
- branches: [],
421
- location: {
422
- start: {
423
- line: 91,
424
- column: 1,
425
- offset: 2936,
426
- },
427
- end: {
428
- line: 94,
429
- column: 1,
430
- offset: 3042,
431
- },
432
- },
433
- },
434
- ]
435
-
436
- const result = parse(script)
437
-
438
- t.deepEqual(result, expected)
439
- })
440
-
441
- test("parse : empty section", (t) => {
442
- const script = outdent`
443
- Hide "All Section"
444
-
445
- `
446
-
447
- const expected = [
448
- {
449
- id: "0001",
450
- name: "All Section",
451
- activity: "Hide",
452
- conditions: {},
453
- actions: {},
454
- branches: [],
455
- location: {
456
- start: {
457
- line: 1,
458
- column: 1,
459
- offset: 0,
460
- },
461
- end: {
462
- line: 2,
463
- column: 1,
464
- offset: 19,
465
- },
466
- },
467
- },
468
- ]
469
-
470
- const result = parse(script)
471
-
472
- t.deepEqual(result, expected)
473
- })
474
-
475
- test("parse : single section", (t) => {
476
- const script = outdent`
477
- Show "Map Section"
478
- Class "Maps"
479
- MapTier > 3
480
- SetBorderColor 250 251 252
481
- PlayAlertSound 1 300
482
-
483
- `
484
-
485
- const expected = [
486
- {
487
- id: "0001",
488
- name: "Map Section",
489
- activity: "Show",
490
- conditions: {
491
- Class: { ope: "=", vals: ["Maps"] },
492
- MapTier: "> 3",
493
- },
494
- actions: {
495
- SetBorderColor: { rgb: { r: 250, g: 251, b: 252 }, alpha: 255 },
496
- PlayAlertSound: { id: "1", volume: 300 },
497
- },
498
- branches: [],
499
- location: {
500
- start: {
501
- line: 1,
502
- column: 1,
503
- offset: 0,
504
- },
505
- end: {
506
- line: 6,
507
- column: 1,
508
- offset: 108,
509
- },
510
- },
511
- },
512
- ]
513
-
514
- const result = parse(script)
515
-
516
- t.deepEqual(result, expected)
517
- })
518
-
519
- test("parse : multi section", (t) => {
520
- const script = outdent`
521
- Hide "Hide Map Section"
522
- Class "Maps"
523
- MapTier <= 4
524
-
525
- Show "Flask Section"
526
- Class "Life Flasks" "Mana Flasks" "Hybrid Flasks"
527
- SetBorderColor 250 251 252
528
- PlayAlertSound 1 300
529
-
530
- Hide "Remain Section"
531
-
532
- `
533
-
534
- const expected = [
535
- {
536
- id: "0001",
537
- name: "Hide Map Section",
538
- activity: "Hide",
539
- conditions: {
540
- Class: { ope: "=", vals: ["Maps"] },
541
- MapTier: "<= 4",
542
- },
543
- actions: {},
544
- branches: [],
545
- location: {
546
- start: {
547
- line: 1,
548
- column: 1,
549
- offset: 0,
550
- },
551
- end: {
552
- line: 5,
553
- column: 1,
554
- offset: 59,
555
- },
556
- },
557
- },
558
- {
559
- id: "0001",
560
- name: "Flask Section",
561
- activity: "Show",
562
- conditions: {
563
- Class: { ope: "=", vals: ["Life Flasks", "Mana Flasks", "Hybrid Flasks"] },
564
- },
565
- actions: {
566
- SetBorderColor: { rgb: { r: 250, g: 251, b: 252 }, alpha: 255 },
567
- PlayAlertSound: { id: "1", volume: 300 },
568
- },
569
- branches: [],
570
- location: {
571
- start: {
572
- line: 5,
573
- column: 1,
574
- offset: 59,
575
- },
576
- end: {
577
- line: 10,
578
- column: 1,
579
- offset: 191,
580
- },
581
- },
582
- },
583
- {
584
- id: "0001",
585
- name: "Remain Section",
586
- activity: "Hide",
587
- conditions: {},
588
- actions: {},
589
- branches: [],
590
- location: {
591
- start: {
592
- line: 10,
593
- column: 1,
594
- offset: 191,
595
- },
596
- end: {
597
- line: 11,
598
- column: 1,
599
- offset: 213,
600
- },
601
- },
602
- },
603
- ]
604
-
605
- const result = parse(script)
606
-
607
- t.deepEqual(result, expected)
608
- })
609
-
610
- test("parse : single fork", (t) => {
611
- const script = outdent`
612
- Show "Map Section"
613
- Class "Maps"
614
- MapTier > 3
615
- SetBorderColor 250 251 252
616
- PlayAlertSound 1 300
617
-
618
- Fork "Rarity"
619
- Show "Rare"
620
- Rarity Rare
621
- SetBackgroundColor 255 0 0 100
622
-
623
- Hide "Magic"
624
- Rarity Magic
625
-
626
- `
627
-
628
- const expected = [
629
- {
630
- id: "0003",
631
- name: "Map Section",
632
- activity: "Show",
633
- conditions: {
634
- Class: { ope: "=", vals: ["Maps"] },
635
- MapTier: "> 3",
636
- },
637
- actions: {
638
- SetBorderColor: { rgb: { r: 250, g: 251, b: 252 }, alpha: 255 },
639
- PlayAlertSound: { id: "1", volume: 300 },
640
- },
641
- branches: [
642
- {
643
- name: "Rarity",
644
- type: "Fork",
645
- blocks: [
646
- {
647
- id: "0001",
648
- name: "Rare",
649
- activity: "Show",
650
- conditions: { Rarity: "Rare" },
651
- actions: { SetBackgroundColor: { rgb: { r: 255, g: 0, b: 0 }, alpha: 100 } },
652
- branches: [],
653
- location: {
654
- start: {
655
- line: 8,
656
- column: 9,
657
- offset: 135,
658
- },
659
- end: {
660
- line: 12,
661
- column: 1,
662
- offset: 215,
663
- },
664
- },
665
- },
666
- {
667
- id: "0002",
668
- name: "Magic",
669
- activity: "Hide",
670
- conditions: { Rarity: "Magic" },
671
- actions: {},
672
- branches: [],
673
- location: {
674
- start: {
675
- line: 12,
676
- column: 9,
677
- offset: 223,
678
- },
679
- end: {
680
- line: 14,
681
- column: 1,
682
- offset: 261,
683
- },
684
- },
685
- },
686
- ],
687
- location: {
688
- start: {
689
- line: 7,
690
- column: 5,
691
- offset: 113,
692
- },
693
- end: {
694
- line: 14,
695
- column: 1,
696
- offset: 261,
697
- },
698
- },
699
- },
700
- ],
701
- location: {
702
- start: {
703
- line: 1,
704
- column: 1,
705
- offset: 0,
706
- },
707
- end: {
708
- line: 14,
709
- column: 1,
710
- offset: 261,
711
- },
712
- },
713
- },
714
- ]
715
-
716
- const result = parse(script)
717
-
718
- t.deepEqual(result, expected)
719
- })
720
-
721
- test("parse : single mixin", (t) => {
722
- const script = outdent`
723
- Show "Map Section"
724
- Class "Maps"
725
- MapTier > 3
726
- SetBorderColor 250 251 252
727
- PlayAlertSound 1 300
728
-
729
- Mixin "Rarity"
730
- Show "Rare"
731
- Rarity Rare
732
- SetBackgroundColor 255 0 0 100
733
-
734
- Hide "Magic"
735
- Rarity Magic
736
-
737
- `
738
-
739
- const expected = [
740
- {
741
- id: "0003",
742
- name: "Map Section",
743
- activity: "Show",
744
- conditions: {
745
- Class: { ope: "=", vals: ["Maps"] },
746
- MapTier: "> 3",
747
- },
748
- actions: {
749
- SetBorderColor: { rgb: { r: 250, g: 251, b: 252 }, alpha: 255 },
750
- PlayAlertSound: { id: "1", volume: 300 },
751
- },
752
- branches: [
753
- {
754
- name: "Rarity",
755
- type: "Mixin",
756
- blocks: [
757
- {
758
- id: "0001",
759
- name: "Rare",
760
- activity: "Show",
761
- conditions: { Rarity: "Rare" },
762
- actions: { SetBackgroundColor: { rgb: { r: 255, g: 0, b: 0 }, alpha: 100 } },
763
- branches: [],
764
- location: {
765
- start: {
766
- line: 8,
767
- column: 9,
768
- offset: 136,
769
- },
770
- end: {
771
- line: 12,
772
- column: 1,
773
- offset: 216,
774
- },
775
- },
776
- },
777
- {
778
- id: "0002",
779
- name: "Magic",
780
- activity: "Hide",
781
- conditions: { Rarity: "Magic" },
782
- actions: {},
783
- branches: [],
784
- location: {
785
- start: {
786
- line: 12,
787
- column: 9,
788
- offset: 224,
789
- },
790
- end: {
791
- line: 14,
792
- column: 1,
793
- offset: 262,
794
- },
795
- },
796
- },
797
- ],
798
- location: {
799
- start: {
800
- line: 7,
801
- column: 5,
802
- offset: 113,
803
- },
804
- end: {
805
- line: 14,
806
- column: 1,
807
- offset: 262,
808
- },
809
- },
810
- },
811
- ],
812
- location: {
813
- start: {
814
- line: 1,
815
- column: 1,
816
- offset: 0,
817
- },
818
- end: {
819
- line: 14,
820
- column: 1,
821
- offset: 262,
822
- },
823
- },
824
- },
825
- ]
826
-
827
- const result = parse(script)
828
-
829
- t.deepEqual(result, expected)
830
- })
831
-
832
- test("parse : multi mixin", (t) => {
833
- const script = outdent`
834
- Show "Map Section"
835
- Class "Maps"
836
-
837
- Mixin "Rarity"
838
- Show "Rare"
839
- Rarity Rare
840
- SetBackgroundColor 255 0 0 100
841
-
842
- Hide "Magic"
843
- Rarity Magic
844
-
845
- Mixin "Tier"
846
- Show "High Tier"
847
- MapTier >= 11
848
- PlayAlertSound 1 300
849
-
850
- Show "Middle Tier"
851
- MapTier >= 6
852
- PlayAlertSound 2 300
853
-
854
- `
855
-
856
- const expected = [
857
- {
858
- id: "0005",
859
- name: "Map Section",
860
- activity: "Show",
861
- conditions: {
862
- Class: { ope: "=", vals: ["Maps"] },
863
- },
864
- actions: {},
865
- branches: [
866
- {
867
- name: "Rarity",
868
- type: "Mixin",
869
- blocks: [
870
- {
871
- id: "0001",
872
- name: "Rare",
873
- activity: "Show",
874
- conditions: { Rarity: "Rare" },
875
- actions: { SetBackgroundColor: { rgb: { r: 255, g: 0, b: 0 }, alpha: 100 } },
876
- branches: [],
877
- location: {
878
- start: {
879
- line: 5,
880
- column: 9,
881
- offset: 64,
882
- },
883
- end: {
884
- line: 9,
885
- column: 1,
886
- offset: 144,
887
- },
888
- },
889
- },
890
- {
891
- id: "0002",
892
- name: "Magic",
893
- activity: "Hide",
894
- conditions: { Rarity: "Magic" },
895
- actions: {},
896
- branches: [],
897
- location: {
898
- start: {
899
- line: 9,
900
- column: 9,
901
- offset: 152,
902
- },
903
- end: {
904
- line: 12,
905
- column: 1,
906
- offset: 191,
907
- },
908
- },
909
- },
910
- ],
911
- location: {
912
- start: {
913
- line: 4,
914
- column: 5,
915
- offset: 41,
916
- },
917
- end: {
918
- line: 12,
919
- column: 1,
920
- offset: 191,
921
- },
922
- },
923
- },
924
- {
925
- name: "Tier",
926
- type: "Mixin",
927
- blocks: [
928
- {
929
- id: "0003",
930
- name: "High Tier",
931
- activity: "Show",
932
- conditions: { MapTier: ">= 11" },
933
- actions: { PlayAlertSound: { id: "1", volume: 300 } },
934
- branches: [],
935
- location: {
936
- start: {
937
- line: 13,
938
- column: 9,
939
- offset: 216,
940
- },
941
- end: {
942
- line: 17,
943
- column: 1,
944
- offset: 294,
945
- },
946
- },
947
- },
948
- {
949
- id: "0004",
950
- name: "Middle Tier",
951
- activity: "Show",
952
- conditions: { MapTier: ">= 6" },
953
- actions: { PlayAlertSound: { id: "2", volume: 300 } },
954
- branches: [],
955
- location: {
956
- start: {
957
- line: 17,
958
- column: 9,
959
- offset: 302,
960
- },
961
- end: {
962
- line: 20,
963
- column: 1,
964
- offset: 380,
965
- },
966
- },
967
- },
968
- ],
969
- location: {
970
- start: {
971
- line: 12,
972
- column: 5,
973
- offset: 195,
974
- },
975
- end: {
976
- line: 20,
977
- column: 1,
978
- offset: 380,
979
- },
980
- },
981
- },
982
- ],
983
- location: {
984
- start: {
985
- line: 1,
986
- column: 1,
987
- offset: 0,
988
- },
989
- end: {
990
- line: 20,
991
- column: 1,
992
- offset: 380,
993
- },
994
- },
995
- },
996
- ]
997
-
998
- const result = parse(script)
999
-
1000
- t.deepEqual(result, expected)
1001
- })
1002
-
1003
- test("parse : nested mixin", (t) => {
1004
- const script = outdent`
1005
- Show "Map Section"
1006
- Class "Maps"
1007
-
1008
- Mixin "Rarity"
1009
- Show "Rare"
1010
- Rarity Rare
1011
- SetBackgroundColor 255 0 0 100
1012
-
1013
- Hide "Magic"
1014
- Rarity Magic
1015
-
1016
- Mixin "Tier"
1017
- Show "High Tier"
1018
- MapTier >= 11
1019
- PlayAlertSound 1 300
1020
-
1021
- Show "Middle Tier"
1022
- MapTier >= 6
1023
- PlayAlertSound 2 300
1024
-
1025
- `
1026
-
1027
- const expected = [
1028
- {
1029
- id: "0005",
1030
- name: "Map Section",
1031
- activity: "Show",
1032
- conditions: {
1033
- Class: { ope: "=", vals: ["Maps"] },
1034
- },
1035
- actions: {},
1036
- branches: [
1037
- {
1038
- name: "Rarity",
1039
- type: "Mixin",
1040
- blocks: [
1041
- {
1042
- id: "0001",
1043
- name: "Rare",
1044
- activity: "Show",
1045
- conditions: { Rarity: "Rare" },
1046
- actions: { SetBackgroundColor: { rgb: { r: 255, g: 0, b: 0 }, alpha: 100 } },
1047
- branches: [],
1048
- location: {
1049
- start: {
1050
- line: 5,
1051
- column: 9,
1052
- offset: 64,
1053
- },
1054
- end: {
1055
- line: 9,
1056
- column: 1,
1057
- offset: 144,
1058
- },
1059
- },
1060
- },
1061
- {
1062
- id: "0004",
1063
- name: "Magic",
1064
- activity: "Hide",
1065
- conditions: { Rarity: "Magic" },
1066
- actions: {},
1067
- branches: [
1068
- {
1069
- name: "Tier",
1070
- type: "Mixin",
1071
- blocks: [
1072
- {
1073
- id: "0002",
1074
- name: "High Tier",
1075
- activity: "Show",
1076
- conditions: { MapTier: ">= 11" },
1077
- actions: { PlayAlertSound: { id: "1", volume: 300 } },
1078
- branches: [],
1079
- location: {
1080
- start: {
1081
- line: 13,
1082
- column: 17,
1083
- offset: 232,
1084
- },
1085
- end: {
1086
- line: 17,
1087
- column: 1,
1088
- offset: 326,
1089
- },
1090
- },
1091
- },
1092
- {
1093
- id: "0003",
1094
- name: "Middle Tier",
1095
- activity: "Show",
1096
- conditions: { MapTier: ">= 6" },
1097
- actions: { PlayAlertSound: { id: "2", volume: 300 } },
1098
- branches: [],
1099
- location: {
1100
- start: {
1101
- line: 17,
1102
- column: 17,
1103
- offset: 342,
1104
- },
1105
- end: {
1106
- line: 20,
1107
- column: 1,
1108
- offset: 436,
1109
- },
1110
- },
1111
- },
1112
- ],
1113
- location: {
1114
- start: {
1115
- line: 12,
1116
- column: 13,
1117
- offset: 203,
1118
- },
1119
- end: {
1120
- line: 20,
1121
- column: 1,
1122
- offset: 436,
1123
- },
1124
- },
1125
- },
1126
- ],
1127
- location: {
1128
- start: {
1129
- line: 9,
1130
- column: 9,
1131
- offset: 152,
1132
- },
1133
- end: {
1134
- line: 20,
1135
- column: 1,
1136
- offset: 436,
1137
- },
1138
- },
1139
- },
1140
- ],
1141
- location: {
1142
- start: {
1143
- line: 4,
1144
- column: 5,
1145
- offset: 41,
1146
- },
1147
- end: {
1148
- line: 20,
1149
- column: 1,
1150
- offset: 436,
1151
- },
1152
- },
1153
- },
1154
- ],
1155
- location: {
1156
- start: {
1157
- line: 1,
1158
- column: 1,
1159
- offset: 0,
1160
- },
1161
- end: {
1162
- line: 20,
1163
- column: 1,
1164
- offset: 436,
1165
- },
1166
- },
1167
- },
1168
- ]
1169
-
1170
- const result = parse(script)
1171
-
1172
- t.deepEqual(result, expected)
1173
- })