forked from BigWigsMods/BigWigs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen_option_values.lua
1121 lines (1045 loc) · 32 KB
/
gen_option_values.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
-- Script to parse boss module files and output ability=>color/sound mappings
local loadstring = loadstring or load -- 5.2 compat
local opt = {}
local modules = {}
local modules_bosses = {}
local modules_locale = {}
local module_colors = {}
local module_sounds = {}
local default_options = {
altpower = {ALTPOWER = true},
infobox = {INFOBOX = true},
proximity = {PROXIMITY = true},
}
local valid_colors = {
green = true,
blue = true,
yellow = true,
orange = true,
red = true,
cyan = true,
purple = true,
}
local valid_sounds = {
info = true,
alert = true,
alarm = true,
long = true,
warning = true,
underyou = true,
}
local color_methods = {
MessageOld = 2,
Message = 2,
TargetMessageOld = 3,
TargetMessage = 2,
TargetsMessageOld = 2,
TargetsMessage = 2,
StackMessageOld = 4,
StackMessage = 2,
DelayedMessage = 3,
}
local sound_methods = {
PlaySound = 2,
MessageOld = 3,
SetPrivateAuraSound = 3,
TargetMessageOld = 4,
StackMessageOld = 5,
DelayedMessage = 6,
}
local icon_methods = {
MessageOld = 5,
Message = 4,
TargetMessageOld = 6,
TargetMessage = 5,
TargetsMessageOld = 6,
TargetsMessage = 6,
StackMessageOld = 7,
StackMessage = 7,
PersonalMessage = 4,
Bar = 4,
CDBar = 4,
CastBar = 4,
TargetBar = 5,
Flash = 2,
}
local removed_methods = {
Message2 = true,
TargetMessage2 = true,
Yell2 = true,
}
local valid_methods = {
CastBar = "CASTBAR",
PrimaryIcon = "ICON",
SecondaryIcon = "ICON",
Flash = "FLASH",
Say = "SAY",
SayCountdown = "SAY_COUNTDOWN",
CancelSayCountdown = "SAY_COUNTDOWN",
Yell = "SAY",
YellCountdown = "SAY_COUNTDOWN",
CancelYellCountdown = "SAY_COUNTDOWN",
OpenAltPower = "ALTPOWER",
CloseAltPower = "ALTPOWER",
OpenProximity = "PROXIMITY",
CloseProximity = "PROXIMITY",
OpenInfo = "INFOBOX",
SetInfoByTable = "INFOBOX",
SetInfoTitle = "INFOBOX",
SetInfo = "INFOBOX",
SetInfoBar = "INFOBOX",
CloseInfo = "INFOBOX",
NameplateBar = "NAMEPLATEBAR",
NameplateCDBar = "NAMEPLATEBAR",
PauseNameplateBar = "NAMEPLATEBAR",
ResumeNameplateBar = "NAMEPLATEBAR",
NameplateBarTimeLeft = "NAMEPLATEBAR",
StopNameplateBar = "NAMEPLATEBAR",
SetPrivateAuraSound = "PRIVATE",
}
local function add_valid_methods(t)
for k in next, t do
if not valid_methods[k] then
valid_methods[k] = true
end
end
end
add_valid_methods(color_methods)
add_valid_methods(sound_methods)
add_valid_methods(icon_methods)
add_valid_methods(removed_methods)
local log_events = {
["SWING_DAMAGE"] = true,
["SWING_MISSED"] = true,
["RANGE_DAMAGE"] = true,
["RANGE_MISSED"] = true,
["SPELL_ABSORBED"] = true,
["SPELL_AURA_APPLIED"] = true,
["SPELL_AURA_APPLIED_DOSE"] = true,
["SPELL_AURA_BROKEN"] = true,
["SPELL_AURA_BROKEN_SPELL"] = true,
["SPELL_AURA_REFRESH"] = true,
["SPELL_AURA_REMOVED"] = true,
["SPELL_AURA_REMOVED_DOSE"] = true,
["SPELL_CAST_FAILED"] = true,
["SPELL_CAST_START"] = true,
["SPELL_CAST_SUCCESS"] = true,
["SPELL_CREATE"] = true,
["SPELL_DAMAGE"] = true,
["SPELL_DISPEL"] = true,
["SPELL_DISPEL_FAILED"] = true,
["SPELL_DRAIN"] = true,
["SPELL_DURABILITY_DAMAGE"] = true,
["SPELL_DURABILITY_DAMAGE_ALL"] = true,
["SPELL_ENERGIZE"] = true,
["SPELL_EXTRA_ATTACKS"] = true,
["SPELL_HEAL"] = true,
["SPELL_INSTAKILL"] = true,
["SPELL_INTERRUPT"] = true,
["SPELL_LEECH"] = true,
["SPELL_MISSED"] = true,
["SPELL_RESURRECT"] = true,
["SPELL_STOLEN"] = true,
["SPELL_SUMMON"] = true,
["SPELL_PERIODIC_DAMAGE"] = true,
["SPELL_PERIODIC_DRAIN"] = true,
["SPELL_PERIODIC_ENERGIZE"] = true,
["SPELL_PERIODIC_HEAL"] = true,
["SPELL_PERIODIC_LEECH"] = true,
["SPELL_PERIODIC_MISSED"] = true,
["SPELL_BUILDING_DAMAGE"] = true,
["SPELL_BUILDING_HEAL"] = true,
["ENVIRONMENTAL_DAMAGE"] = true,
["DAMAGE_SHIELD"] = true,
["DAMAGE_SHIELD_MISSED"] = true,
["DAMAGE_SPLIT"] = true,
["PARTY_KILL"] = true,
["UNIT_DIED"] = true,
["UNIT_DESTROYED"] = true,
["UNIT_DISSIPATES"] = true,
}
local args_keys = {
time = true,
sourceGUID = true,
sourceName = true,
sourceFlags = true,
sourceRaidFlags = true,
destGUID = true,
destName = true,
destFlags = true,
destRaidFlags = true,
spellId = true,
spellName = true,
extraSpellId = true,
extraSpellName = true,
amount = true,
mobId = true,
}
-- Set an exit code if we show an error.
local exit_code = 0
local error, warn
if package.config:sub(1,1) == "/" then -- linux path seperator
function error(msg)
print("\27[31m" .. msg .. "\27[0m") -- red
exit_code = 1
end
function warn(msg)
print("\27[33m" .. msg .. "\27[0m") -- yellow
end
else
function error(msg)
print(msg)
exit_code = 1
end
warn = print
end
local function print(...)
if opt.quiet then return end
_G.print(...)
end
-- Return a table containing the value if value is not a table.
local function tablize(value)
if type(value) ~= "table" then
value = { value }
end
return value
end
-- Remove outer quotes.
local function unquote(str)
if type(str) == "string" then
return str:match("^%s*\"(.-)\"%s*$") or str
end
return str
end
-- Break apart and/or assignments and return the conditional results.
local function unternary(str, pattern, validate_table)
if type(str) == "string" then
local matches = {}
for m in str:gmatch(" and "..pattern) do
if not validate_table or validate_table[m] then
matches[#matches+1] = m
end
end
for m in str:gmatch(" or "..pattern) do
if not validate_table or validate_table[m] then
matches[#matches+1] = m
end
end
if #matches > 0 then
return matches
end
end
return str
end
local function contains(t, v)
for _, value in next, t do
if value == v then
return true
end
end
return false
end
-- Removes some things that break simple comma splitting.
local function clean(str)
-- :Dispeller() || :format() || UnitIsUnit()
str = str:gsub("(:?%a+)%b()", "%1")
return str
end
-- Strip whitespace from the start and end of a string.
local function strtrim(str)
return str:match("^%s*(.-)%s*$")
end
-- Split a string at commas and return a table with the results.
local function strsplit(str)
local t = {}
str:gsub("([^,]+)", function(s) t[#t+1] = strtrim(s) end)
return t
end
local function cmp(a, b)
if type(a) == "number" and type(b) == "number" then
return a < b
end
return string.lower(a) < string.lower(b)
end
local function sortKeys(keys)
local t = {}
for key in next, keys do
t[#t+1] = key
end
table.sort(t, cmp)
return t
end
-- Write out a module option values to [module dir]/Options/[value].lua
local function dumpValues(path, name, options_table)
local file = path .. name .. ".lua"
local old_data = ""
local f = io.open(file, "r")
if f then
old_data = f:read("*all")
f:close()
end
local data = ""
for _, mod in ipairs(modules) do
local options = options_table[mod] or {}
data = data .. string.format("\r\nBigWigs:Add%s(%q, {\r\n", name, mod)
for _, key in ipairs(sortKeys(options)) do
local values = options[key]
if type(key) == "string" then key = string.format("%q", key) end
if #values == 1 then
data = data .. string.format("\t[%s] = %q,\r\n", key, values[1])
else
table.sort(values, cmp)
for i = 1, #values do
values[i] = string.format("%q", values[i])
end
data = data .. string.format("\t[%s] = {%s},\r\n", key, table.concat(values, ","))
end
end
data = data .. "})\r\n"
end
if data == "" then
data = "-- Don't error because I'm empty, please.\r\n"
end
if data:gsub("\r", "") ~= old_data:gsub("\r", "") then
if not opt.dryrun then
f = io.open(file, "wb")
if not f then
error(string.format(" %s: File not found!", file))
else
f:write(data)
f:close()
warn(" Updated " .. file)
end
else
warn(" Updated " .. file .. " (skipped)")
end
end
end
local function add(module_name, option_table, keys, value)
if not option_table[module_name] then
option_table[module_name] = {}
end
for _, key in next, tablize(keys) do
key = tonumber(key) or key
if not option_table[module_name][key] then
option_table[module_name][key] = {}
end
-- Only add once per key.
local found = nil
for _, v in next, option_table[module_name][key] do
if value == v then
found = true
break
end
end
if not found then
table.insert(option_table[module_name][key], value)
end
end
end
local function findCalls(lines, start, local_func, options)
local keys = {}
local func, if_key = nil, nil
for i = start+1, #lines do
local line = lines[i]:gsub("%s*%-%-.+$", "") -- strip out comments
local res = line:match("^%s*function%s+[%w_]+[.:]([%w_]+)%s*%(")
if res then
func = res
if_key = nil
end
res = line:match("^%s*local function%s+([%w_]+)%s*%(")
if res then
func = nil
if_key = nil
if res == local_func then
-- redefined?! we shouldn't be here...
break
end
end
res = line:match("if (.+) then")
if res and line:match("spellId == %d+") then
if_key = {}
for m in res:gmatch("spellId == (%d+)") do
if_key[#if_key+1] = m
end
end
if func then -- make sure we're out of the local function
if line:match(":ScheduleTimer%(%s*"..local_func.."%s*,") or
line:match(":ScheduleRepeatingTimer%(%s*"..local_func.."%s*,") or
line:match("^%s*"..local_func.."%s*%(")
then
if func and options[func] then
for _, k in next, options[func] do
keys[#keys+1] = k
end
end
if if_key then
for _, k in next, if_key do
keys[#keys+1] = k
end
end
func, if_key = nil, nil
end
end
end
return #keys > 0 and keys or nil
end
local function parseGetOptions(file_name, lines, start)
local chunk = nil
for i = start, #lines do
if i == start and lines[i]:match("^%s*return {.+}%s*$") then
-- old style one line options
chunk = lines[i]
break
end
if lines[i]:match("^%s*},%s*{") or lines[i]:match("^%s*},%s*nil,%s*{") then
-- we don't want to parse headers or altnames (to avoid setfenv) so stop here
chunk = table.concat(lines, "\n", start, i-1) .. "\n}"
-- TODO string parse the other tables for duplicates
break
end
if lines[i]:match("^%s*end") then
chunk = table.concat(lines, "\n", start, i-1) -- no headers, so we need to back up to the }
break
end
end
if not chunk or chunk == "" then
return false, "Something is wrong."
end
local f, err = loadstring(chunk)
if err then
return false, err
end
local success, result = pcall(f)
if success then
local options, option_flags = {}, {}
for _, opt in next, result do
local flags = true
if type(opt) == "table" then
flags = {}
for i=2, #opt do
flags[opt[i]] = true
end
opt = opt[1]
end
if opt then -- marker option vars will be nil
if default_options[opt] then
flags = default_options[opt]
end
if options[opt] then
error(string.format(" %s:%d: Duplicate option key \"%s\"", file_name, start, tostring(opt)))
else
options[opt] = flags
end
end
end
return options
end
return success, result
end
local function checkForAPI(line)
for method in next, valid_methods do
if line:find(method, nil, true) then
return true
end
end
return false
end
-- Read boss module file and parse it for colors and sounds.
local function parseLua(file)
local file_name = file:match(".*/(.*)$") or file
if opt.quiet then
file_name = file
end
local f = io.open(file, "r")
if not f then
error(string.format(" \"%s\" not found!", file_name))
return
end
local data = f:read("*all")
f:close()
-- First, check to make sure this is actually a boss module file.
local module_name, module_args = data:match("\nlocal mod.*= BigWigs:NewBoss%(\"(.-)\",?%s*([^)]*)")
if not module_name then
return
end
if module_args ~= "" then
local args = strsplit(module_args)
local ej_id = tonumber(args[2])
if ej_id then
if modules_bosses[ej_id] then
error(string.format(" %s:%d: Module \"%s\" is using journal id %d, which is already used by module \"%s\"", file_name, 1, module_name, ej_id, modules_bosses[ej_id]))
else -- execution isn't stopped, don't overwrite the original module name
modules_bosses[ej_id] = module_name
end
end
end
-- `modules` is used output the boss modules in the order they were parsed.
table.insert(modules, module_name)
modules_locale[module_name] = {}
-- Split the file into a table
local lines = {}
for line in data:gmatch("(.-)\r?\n") do
lines[#lines+1] = line
end
local locale, common_locale = modules_locale[module_name], modules_locale["BigWigs: Common"]
local options, option_keys = {}, {}
local methods, registered_methods = {Win=true}, {}
local event_callbacks = {}
local current_func = nil
local rep = {}
for n, line in ipairs(lines) do
local comment = line:match("%-%-%s*(.*)") or ""
line = line:gsub("%-%-.*$", "") -- strip comments
-- locale checking
do
-- save module locale
-- multiple definitions on one line
if line:match("^%sL%.[%w_]+%s*,.+=.+") then -- we're setting things, right?
for locale_key in line:gmatch("L%.([%w_]+)%s*,%s*") do
locale[locale_key] = true
end
end
local locale_key = line:match("L%.([%w_]+)%s*=") or line:match("L%[\"(.+)\"%]%s*=")
if locale_key then
locale[locale_key] = true
end
end
-- check usage
for locale_type, locale_key, extra in line:gmatch("(C?L)%.([%w_]+)(%(?)") do
if locale_type == "CL" then
-- CL is only set in the main project
if common_locale and not common_locale[locale_key] then
error(string.format(" %s:%d: Invalid locale string \"CL.%s\"", file_name, n, locale_key))
end
elseif locale_type == "L" and not locale[locale_key] then
error(string.format(" %s:%d: Invalid locale string \"L.%s\"", file_name, n, locale_key))
end
-- trying to invoke the string (missing :format)
if extra == "(" then
error(string.format(" %s:%d: Invalid locale string format \"%s.%s%s\"", file_name, n, locale_type, locale_key, format))
end
end
--- loadstring the options table
if line == "function mod:GetOptions()" or line == "function mod:GetOptions(CL)" then
local opts, err = parseGetOptions(file_name, lines, n+1)
if not opts then
-- rip keys
error(string.format(" %s:%d: Error parsing GetOptions! %s", file_name, n, err))
-- return
else
option_keys = opts
end
end
local toggle_options = line:match("^mod%.toggleOptions = ({.+})")
if toggle_options then
local success, result = pcall(loadstring("return " .. toggle_options))
if success then
for _, opt in next, result do
local flags = true
if type(opt) == "table" then
flags = {}
for i=2, #opt do
flags[opt[i]] = true
end
opt = opt[1]
end
if opt then -- marker option vars will be nil
if default_options[opt] then
flags = default_options[opt]
end
option_keys[opt] = flags
end
end
end
end
--- Build the callback map.
-- Parse :Log calls and save the callback => spellId association so we can
-- replace args.spellId with the actual spellId(s) based on the last function
-- that was entered when a message function is called.
local event, callback, spells = line:match("self:Log%(\"(.-)\"%s*,%s*(.-)%s*,%s*([^)]*)%)")
if event then
if not log_events[event] then
error(string.format(" %s:%d: Invalid Log event \"%s\"", file_name, n, event))
end
if callback ~= "nil" then
callback = unquote(callback)
else
callback = event
end
if not options[callback] then
options[callback] = {}
end
if not event_callbacks[event] then
event_callbacks[event] = {}
end
for _, v in next, strsplit(spells) do
v = tonumber(v)
if not contains(options[callback], v) then
table.insert(options[callback], v)
end
if not contains(event_callbacks[event], v) then
table.insert(event_callbacks[event], v)
else
error(string.format(" %s:%d: Registered Log event \"%s\" with spell id \"%d\" multiple times", file_name, n, event, v))
end
end
if not next(options[callback]) then
options[callback] = nil
end
registered_methods[callback] = n
end
-- Record other registered events to check at the end
event, callback = line:match(":RegisterUnitEvent%(\"(.-)\"%s*,%s*(.-)%s*,.-%)")
-- if not event then
-- -- XXX need to filter proto methods for this
-- event, callback = line:match(":RegisterEvent%(\"(.-)\"%s*,?%s*(.*)%)")
-- end
if event then
if callback == "" or callback == "nil" then
callback = event
else
callback = unquote(callback)
end
registered_methods[callback] = n
end
--- Set spellId replacement values.
-- Record the function that was declared and use the callback map that was
-- created earlier to set the associated spellId(s).
local res = line:match("^%s*function%s+([%w_]+:[%w_]+)%s*%(")
if res then
current_func = res
local name = res:match(":(.+)")
methods[name] = true
rep = {}
rep.func_key = options[name]
end
-- For local functions, look ahead and record the key for the first function
-- that calls it.
res = line:match("^%s*local function%s+([%w_]+)%s*%(") or line:match("^%s*function%s+([%w_]+)%s*%(")
if res then
current_func = res
methods[res] = true
rep = {}
rep.local_func_key = findCalls(lines, n, current_func, options)
end
-- For UNIT functions, record the last spellId checked to use as the key.
res = line:match("if (.+) then")
if res and line:match("spellId == %d+") then
rep.if_key = {}
for m in res:gmatch("spellId == (%d+)") do
rep.if_key[#rep.if_key+1] = m
end
end
-- For expression keys used multiple times
res = line:match("%s*local spellId%s*=%s*(.+)")
if res then
-- fuck off Elerethe
local set_key = comment:match("SetOption:(.-):")
if set_key and set_key ~= "" then
rep.if_key = {}
for k, v in next, strsplit(set_key) do
rep.if_key[#rep.if_key+1] = tonumber(v) or string.format("%q", unquote(v)) -- string keys are expected to be quoted
end
else
rep.if_key = unternary(res, "(-?%d+)") -- XXX doesn't allow for string keys
end
else
res = line:match("%s*local spellId,.+=%s*(.+),")
if res then
local set_key = comment:match("SetOption:(.-):")
if set_key and set_key ~= "" then
rep.if_key = {}
for k, v in next, strsplit(set_key) do
rep.if_key[#rep.if_key+1] = tonumber(v) or string.format("%q", unquote(v)) -- string keys are expected to be quoted
end
else
rep.if_key = unternary(res, "(-?%d+)") -- XXX doesn't allow for string keys
end
end
end
--- Check callback args
for key in string.gmatch(line, "[^%w]*args%.([%w]+)[^%w]*") do
if not args_keys[key] then
error(string.format(" %s:%d: Invalid args key \"%s\"", file_name, n, key))
end
end
--- Check timer args (callback, timer)
local method, args = line:match(":(%a+Timer)(%b())")
if method == "ScheduleTimer" or method == "ScheduleRepeatingTimer" or method == "SimpleTimer" then
args = strsplit(args:sub(2, -2))
if tonumber(args[1]) then
error(string.format(" %s:%d: Invalid args for \":%s\" callback=%s, delay=%s", file_name, n, method, tostring(args[1]), tostring(args[2])))
end
end
--- Parse message calls.
-- Check for function calls that will trigger a sound, including calls
-- delayed with ScheduleTimer.
if checkForAPI(line) then
local key, sound, color, bitflag = nil, nil, nil, nil
local obj, sugar, method, args = line:match("(%w+)([.:])(.-)%(%s*(.+)%s*%)")
local offset = 0
if method == "ScheduleTimer" or method == "ScheduleRepeatingTimer" then
method = args:match("^\"(.-)\"")
offset = 2
end
if removed_methods[method] then
error(string.format(" %s:%d: Invalid API method! func=%s, method=%s", file_name, n, tostring(current_func), method))
elseif valid_methods[method] then
args = strsplit(clean(args))
key = unternary(args[1+offset], "(-?%d+)") -- XXX doesn't allow for string keys
local sound_index = sound_methods[method]
if sound_index then
sound = unternary(args[sound_index+offset], "\"(.-)\"", valid_sounds)
if method == "SetPrivateAuraSound" and not sound then
sound = "warning"
end
end
local color_index = color_methods[method]
if color_index then
color = tablize(unternary(args[color_index+offset], "\"(.-)\"", valid_colors))
if method:sub(1, 6) == "Target" or method == "StackMessageOld" or method == "StackMessage" then
color[#color+1] = "blue" -- used when on the player
end
end
if method == "PersonalMessage" then
color = {"blue"}
local locale_string = args[2+offset]
if (locale_string == "nil" or locale_string == "false") then locale_string = nil end
if common_locale and (locale_string and not common_locale[unquote(locale_string)]) then
local text = args[3+offset]
error(string.format(" %s:%d: PersonalMessage: Invalid localeString(2)! func=%s, key=%s, localeString=%s, text=%s", file_name, n, tostring(current_func), key, tostring(locale_string), tostring(text)))
end
end
local icon_index = icon_methods[method]
if icon_index then
local icon = args[icon_index+offset]
-- Make sure methods with a string key set an icon.
if type(key) == "string" and key:match('^".*"$') and icon == nil then
-- Also check if text is nil or a (formatted)string if the method isn't :Flash
local text = args[icon_index+offset-1]
if method == "Flash" or (not text or text:match('^".*"$') or text:match(":format") or text:match("C?L%.%a")) then
error(string.format(" %s:%d: Missing icon! func=%s, key=%s, text=%s, icon=%s", file_name, n, tostring(current_func), key, tostring(text), tostring(icon)))
end
end
end
if valid_methods[method] ~= true then
bitflag = valid_methods[method]
end
-- Check for method call typo (API should always be invoked with ":" syntax)
-- Note, may need to add a check for using table notation with SimpleTimer or
-- such, but local functions are typically used for repeating callbacks
if sugar == "." then
local call = obj..sugar..method
error(string.format(" %s:%d: Invalid API call \"%s\"! func=%s, key=%s", file_name, n, call, tostring(current_func), key))
end
-- Check for wrong API (Message instead of TargetMessage)
if method == "Message" and (args[3+offset] == "destName" or args[3+offset] == "args.destName" or args[3+offset] == "name" or args[3+offset] == "args.sourceName" or args[3+offset] == "sourceName") then
error(string.format(" %s:%d: Message text is a player name? func=%s, key=%s, text=%s", file_name, n, tostring(current_func), key, args[3]))
end
-- Check that noEmphUntil is set
if method == "StackMessage" and (not args[5+offset] or args[5+offset] == "nil") then
error(string.format(" %s:%d: StackMessage: Missing noEmphUntil(5)! func=%s, key=%s", file_name, n, tostring(current_func), key))
end
-- Check that voice wasn't forgotten (like the feature was >.>), passes simple expressions like `self:Dispeller("magic") and "dispel"`
if method == "PlaySound" and args[3+offset] and args[3+offset] ~= "nil" and not args[3+offset]:match("^\"(.-)\"$") and not args[3+offset]:match(" and \"(.-)\"$") then
error(string.format(" %s:%d: PlaySound: Invalid voice(3)! func=%s, key=%s, voice=%s", file_name, n, tostring(current_func), key, tostring(args[3+offset])))
end
end
-- -- SetOption:key:color:sound:
-- Handle manually setting the key, color, and sound with a comment. Has to be on the
-- same line as the function call. All three values can also be a comma seperated list
-- or left empty.
-- e.g.: -- SetOption:1234,1235:Urgent:Info,Alert: or -- SetOption:1234:::
local set_key, set_color, set_sound = comment:match("SetOption:(.*):(.*):(.*):")
if set_key then
if set_key ~= "" then
key = strsplit(set_key)
for k, v in next, key do
if not tonumber(v) then
-- string keys are expected to be quoted
key[k] = string.format("%q", unquote(v))
end
end
end
if set_color ~= "" then
color = strsplit(set_color)
end
if set_sound ~= "" then
sound = strsplit(set_sound)
end
end
local f = tostring(current_func)
if rep.func_key then f = string.format("%s(%s)", f, table.concat(rep.func_key, ",")) end
local errors = nil
local keys = {}
-- Do key replacements.
for _, k in next, tablize(key) do
if k == "args.spellId" and rep.func_key then
k = rep.func_key
end
if k == "spellId" and rep.if_key then
k = rep.if_key
end
if k == "spellId" and rep.local_func_key then
k = rep.local_func_key
end
for _, nk in next, tablize(k) do
keys[#keys+1] = nk
end
end
--- Validate keys.
for i, k in next, keys do
local key = tonumber(k) or unquote(k)
if key ~= "false" then
if not option_keys[key] then
error(string.format(" %s:%d: Invalid key! func=%s, key=%s", file_name, n, f, key))
errors = true
elseif bitflag and (type(option_keys[key]) ~= "table" or not option_keys[key][bitflag]) then
error(string.format(" %s:%d: Missing %s flag! func=%s, key=%s", file_name, n, bitflag, f, key))
errors = true
end
end
keys[i] = key
end
-- Add the color entries.
for _, c in next, tablize(color) do
c = unquote(c)
if valid_colors[c] then
if not errors then
add(module_name, module_colors, keys, c)
end
elseif c and c ~= "nil" then
-- A color was set but didn't match an actual color, so warn about it.
error(string.format(" %s:%d: Invalid color! func=%s, key=%s, color=%s", file_name, n, f, table.concat(keys, " "), c))
end
end
-- Add the sound entries.
for _, s in next, tablize(sound) do
s = unquote(s)
if valid_sounds[s] then
if not errors then
add(module_name, module_sounds, keys, s)
end
elseif s and s ~= "nil" then
-- A sound was set but didn't match an actual sound, so warn about it.
error(string.format(" %s:%d: Invalid sound! func=%s, key=%s, sound=%s", file_name, n, f, table.concat(keys, " "), s))
end
end
end
end
-- Check for callbacks that were registered but don't exist.
-- This will also error when using a local function as a callback.
for f, n in next, registered_methods do
if not methods[f] then
error(string.format(" %s:%d: %q was registered as a callback, but it does not exist.", file_name, n, f))
end
end
end
local function parseLocale(file)
local file_locale = file:match("Locales/(.-)%.lua$")
local file_name = file
if not opt.quiet then
file_name = "Locales/"..file_locale..".lua"
end
file_locale = file_locale:gsub("^.*%.", "")
local f = io.open(file, "r")
if not f then
error(string.format(" \"%s\" not found!", file))
return
end
local data = f:read("*all")
f:close()
local keys = {}
local current_module
local n = 0
for line in data:gmatch("(.-)\r?\n") do
n = n + 1
local module_name, locale
if file_locale == "esES" then
-- Handle combined es locales
local module_name2, locale2
module_name, locale, module_name2, locale2 = line:match("L = BigWigs:NewBossLocale%(\"(.-)\", \"(.-)\"%) or BigWigs:NewBossLocale%(\"(.-)\", \"(.-)\"%)")
if module_name then
-- Check :NewBossLocale args
if module_name ~= module_name2 then
error(string.format(" %s:%d: Module name mismatch! %q != %q", file_name, n, module_name, module_name2))
end
if locale2 ~= "esMX" then
error(string.format(" %s:%d: Invalid locale! %q should be %q", file_name, n, locale2, "esMX"))
end
end
end
if not module_name then
module_name, locale = line:match("L = BigWigs:NewBossLocale%(\"(.-)\", \"(.-)\"%)")
if not module_name then
module_name, locale = line:match("L = BigWigsAPI:NewLocale%(\"(.-)\", \"(.-)\"%)")
end
end
if module_name then
current_module = module_name
if not keys[module_name] then
keys[module_name] = {}
else
error(string.format(" %s:%d: Duplicate module name %q", file_name, n, module_name))
end
-- Save base keys for non-boss locales
if file_locale == "enUS" then
modules_locale[module_name] = keys[module_name]
end
end
-- Check API args
if module_name then
if locale ~= file_locale then
error(string.format(" %s:%d: Invalid locale! %q should be %q", file_name, n, locale, file_locale))
end
if not modules_locale[module_name] then
error(string.format(" %s:%d: Invalid module name %q", file_name, n, module_name))
end
end
-- Check that the string exists in enUS
if modules_locale[current_module] then
local comment, key = line:match("^%s*(%-?%-?)%s*L%.([%w_]+)%s*=")
if not key then
comment, key = line:match("^%s*(%-?%-?)%s*L%[\"(.+)\"%]%s*=")
end
if key then
keys[current_module][key] = comment == ""
if not modules_locale[current_module][key] then
error(string.format(" %s:%d: %s: Invalid locale key %q", file_name, n, current_module, key))
end
end
end
end
-- Check that all enUS strings exist in the foreign locale
if file_locale ~= "enUS" then
-- Only reverse check non-boss locales
local module_name, L = next(keys)
if module_name and module_name:match("^BigWigs") then
for key in next, modules_locale[module_name] do
if L[key] == nil then
error(string.format(" %s:%d: %s: Missing locale key %q", file_name, 1, module_name, key))
end
end
end
end
end
-- Read modules.xml and return a table of file paths.
local function parseXML(file)
local f = io.open(file, "r")
if not f then
error(" File not found!")
return
end
local list = {}
-- The includes are relative, so we need to prepend the path of the current
-- xml file for opening the file relative to the project root.
local path = file:match(".*/") or ""