-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathmain.lua
2825 lines (2387 loc) · 92.9 KB
/
main.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
local _, addonTable = ...
-- -----------
-- [ globals ]
-- -----------
local wow = {
C_ChatBubbles = _G['C_ChatBubbles'],
C_GossipInfo = _G['C_GossipInfo'],
C_Seasons = _G['C_Seasons'],
C_Timer = _G['C_Timer'],
ChatFrame_AddMessageEventFilter = _G['ChatFrame_AddMessageEventFilter'],
ChatTypeInfo = _G['ChatTypeInfo'],
CreateFrame = _G['CreateFrame'],
DEFAULT_CHAT_FRAME = _G['DEFAULT_CHAT_FRAME'],
DevTools_Dump = _G['DevTools_Dump'],
Enum = _G['Enum'],
GameTooltip = _G['GameTooltip'],
GetAddOnInfo = _G['GetAddOnInfo'],
GetAddOnMemoryUsage = _G['GetAddOnMemoryUsage'],
GetAddOnMetadata = _G['GetAddOnMetadata'],
GetBuildInfo = _G['GetBuildInfo'],
GetMouseFoci = _G['GetMouseFoci'],
GetMouseFocus = _G['GetMouseFocus'],
GetNumAddOns = _G['GetNumAddOns'],
GetQuestID = _G['GetQuestID'],
GetQuestLogSelection = _G['GetQuestLogSelection'],
GetQuestLogTitle = _G['GetQuestLogTitle'],
GetTalentInfo = _G['GetTalentInfo'],
GossipFrame = _G['GossipFrame'],
hooksecurefunc = _G['hooksecurefunc'],
InterfaceAddOnsList_Update = _G['InterfaceAddOnsList_Update'],
InterfaceOptions_AddCategory = _G['InterfaceOptions_AddCategory'],
InterfaceOptionsFrame_OpenToCategory = _G['InterfaceOptionsFrame_OpenToCategory'],
ItemRefTooltip = _G['ItemRefTooltip'],
ItemTextGetPage = _G['ItemTextGetPage'],
ItemTextGetText = _G['ItemTextGetText'],
ItemTextScrollFrame = _G['ItemTextScrollFrame'],
MinimapZoneText = _G['MinimapZoneText'],
PVPArenaTextString = _G['PVPArenaTextString'],
PVPInfoTextString = _G['PVPInfoTextString'],
QuestFrame = _G['QuestFrame'],
QuestFrameDetailPanel = _G['QuestFrameDetailPanel'],
QuestFrameProgressPanel = _G['QuestFrameProgressPanel'],
QuestFrameRewardPanel = _G['QuestFrameRewardPanel'],
QuestLogDetailScrollFrame = _G['QuestLogDetailScrollFrame'],
TargetFrame = _G['TargetFrame'],
UnitAura = _G['UnitAura'],
UnitClass = _G['UnitClass'],
UnitFactionGroup = _G['UnitFactionGroup'],
UnitGUID = _G['UnitGUID'],
UnitName = _G['UnitName'],
UnitRace = _G['UnitRace'],
UnitSex = _G['UnitSex'],
UpdateAddOnMemoryUsage = _G['UpdateAddOnMemoryUsage'],
ReloadUI = _G['ReloadUI'],
Settings = _G['Settings'],
ShoppingTooltip1 = _G['ShoppingTooltip1'],
ShoppingTooltip2 = _G['ShoppingTooltip2'],
ShouldShowName = _G['ShouldShowName'],
SlashCmdList = _G['SlashCmdList'],
StaticPopup_Show = _G['StaticPopup_Show'],
StaticPopupDialogs = _G['StaticPopupDialogs'],
SubZoneTextString = _G['SubZoneTextString'],
WorldMapTooltip = _G['WorldMapTooltip'],
WorldFrame = _G['WorldFrame'],
WorldMapFrame = _G['WorldMapFrame'],
ZoneTextString = _G['ZoneTextString'],
}
local build_info = wow.GetBuildInfo()
local is_classic = string.byte(build_info, 1) == string.byte("1")
local is_classic_sod = is_classic and wow.C_Seasons and wow.C_Seasons.HasActiveSeason() and wow.C_Seasons.GetActiveSeason() == wow.Enum.SeasonID.SeasonOfDiscovery
local is_tbc = string.byte(build_info, 1) == string.byte("2")
local is_wrath = string.byte(build_info, 1) == string.byte("3")
local is_cata = string.byte(build_info, 1) == string.byte("4")
local asset_ua_code = "|TInterface\\AddOns\\ClassicUA\\assets\\ua:0|t"
local asset_font1_path = "Interface\\AddOns\\ClassicUA\\assets\\Morpheus_UA.ttf"
local asset_font2_path = "Interface\\AddOns\\ClassicUA\\assets\\FRIZQT_UA.ttf"
---@class options_class
local options = nil
---@class Frame
local options_frame = nil
-- ---------
-- [ utils ]
-- ---------
local function game_expansion_key()
if is_classic then
return is_classic_sod and "sod" or "classic"
elseif is_tbc then
return "tbc"
elseif is_wrath then
return "wrath"
elseif is_cata then
return "cata"
else
return "???"
end
end
local function dump(value)
if type(wow.DevTools_Dump) == "function" then
wow.DevTools_Dump(value)
else
print("[dump]", value)
end
end
local function copy_table(target, source)
for k, v in pairs(source) do target[k] = v end
return target
end
local function table_string_keys(table)
local result = {}
for k, _ in pairs(table) do
if type(k) == "string" then
result[#result + 1] = k
end
end
return result
end
local function table_keys_count(table)
local count = 0
for _ in pairs(table) do count = count + 1 end
return count
end
local function capitalize(text)
local b1 = string.byte(text, 1)
if b1 >= 208 and b1 <= 210 then -- this is utf8 character, 2 bytes long
local b2 = string.byte(text, 2)
if b1 == 209 and b2 == 148 then
return 'Є' .. text:sub(3)
elseif b1 == 209 and b2 == 150 then
return 'І' .. text:sub(3)
elseif b1 == 209 and b2 == 151 then
return 'Ї' .. text:sub(3)
elseif b1 == 210 and b2 == 145 then
return 'Ґ' .. text:sub(3)
else -- run out of special cases -- let default upper() handle it
return text:sub(1, 2):upper() .. text:sub(3)
end
else
return text:sub(1, 1):upper() .. text:sub(2)
end
end
local function upper(str)
return str:upper():gsub("ї", "Ї"):gsub("є", "Є"):gsub("і", "І"):gsub("ґ", "Ґ")
end
local function lower(str)
return str:lower():gsub("Ї", "ї"):gsub("Є", "є"):gsub("І", "і"):gsub("Ґ", "ґ")
end
local function esc(x) -- https://stackoverflow.com/questions/9790688/escaping-strings-for-gsub
return x:gsub('%%', '%%%%')
:gsub('^%^', '%%^')
:gsub('%$$', '%%$')
:gsub('%(', '%%(')
:gsub('%)', '%%)')
:gsub('%.', '%%.')
:gsub('%[', '%%[')
:gsub('%]', '%%]')
:gsub('%*', '%%*')
:gsub('%+', '%%+')
:gsub('%-', '%%-')
:gsub('%?', '%%?')
end
local function fix_float_number(value)
local result = value:gsub(",", "")
-- fix floating-point number without leading "0", e.g. ",2"
if #result > 1 and result:sub(1, 1) == "," then
result = "0" .. result
end
return result
end
local function strip_color_codes(text)
if type(text) == "string" then
text = text:gsub("|c%x%x%x%x%x%x%x%x", "")
text = text:gsub("|c%x%x%x%x%x%x %x", "")
text = text:gsub("|r", "")
end
return text
end
local function first_line_only(text)
if type(text) == "string" then
local lines = { string.split("\n\r", text) }
local esc_nl_pos = lines[1]:find("|n")
if esc_nl_pos then
return lines[1]:sub(1, esc_nl_pos - 1)
else
return lines[1]
end
else
return text
end
end
local function tooltip_lines(tooltip, is_right)
local lines = {}
for j = 1, tooltip:NumLines() do
local k = tooltip:GetName() .. (is_right and "TextRight" or "TextLeft") .. j
lines[#lines + 1] = _G[k]:GetText()
end
return lines
end
local function tooltip_title_line(tooltip)
local num_lines = tooltip:NumLines()
if num_lines == 0 then
return ""
end
local text = _G[tooltip:GetName() .. "TextLeft1"]:GetText()
-- check special case for item tooltip when showing currently equipped
if text == "Currently Equipped" and num_lines > 1 then
text = _G[tooltip:GetName() .. "TextLeft2"]:GetText()
end
return text
end
-- unit_id is one of https://warcraft.wiki.gg/wiki/UnitId
local function npc_id_from_unit_id(unit_id)
if type(unit_id) == "string" then
local guid = wow.UnitGUID(unit_id)
if guid then
local kind, _, _, _, _, id, _ = string.split("-", guid)
if id and (kind == "Creature" or kind == "Vehicle") then
return tonumber(id)
end
end
end
end
local function chat_bubble_font_string_with_text(text)
local bubbles = wow.C_ChatBubbles:GetAllChatBubbles()
for _, bubble in pairs(bubbles) do
if not bubble:IsForbidden() then
local frame = select(1, bubble:GetChildren())
for i = 1, frame:GetNumRegions() do
local region = select(i, frame:GetRegions())
if region:GetObjectType() == "FontString" and region:GetText() == text then
return region
end
end
end
end
end
local function mouse_hover_frame()
if wow.GetMouseFocus then
return wow.GetMouseFocus()
elseif wow.GetMouseFoci then
return wow.GetMouseFoci()[1]
end
end
local get_text_code_replace_seq = {}
local function prepare_get_text_code_replace_seq(player_name)
local at = addonTable
local rs = get_text_code_replace_seq
-- player races
rs[#rs + 1] = "<race>"
for _, w in ipairs(table_string_keys(at.race)) do
rs[#rs + 1] = w:lower()
end
-- player classes
rs[#rs + 1] = "<class>"
for _, w in ipairs(table_string_keys(at.class)) do
rs[#rs + 1] = w:lower()
end
-- player name
rs[#rs + 1] = "<name>"
rs[#rs + 1] = player_name:lower()
end
-- [!] Any changes made to get_text_code() func must be kept in sync with Python impl in utils.py
local function get_text_code(text)
local result = { "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_" }
local result_len = #result
text = text:lower()
for _, w in ipairs(get_text_code_replace_seq) do
text = text:gsub(w, "")
end
local result_fill_idx = 1
for word in string.gmatch(text, "%w+") do
if #word > 0 then
if result_fill_idx > result_len then
break
end
for i = 1, #word do
result[result_fill_idx] = string.sub(word, i, i)
result_fill_idx = result_fill_idx + 1
if result_fill_idx > result_len then
break
end
end
end
end
local result_idx = 1
local result_rewind = 1
for word in string.gmatch(text, "%w+") do
if #word > 0 then
result[result_idx] = string.sub(word, 1, 1)
result_idx = result_idx + 1
if result_idx > result_len then
result_rewind = result_rewind < result_len and result_rewind + 1 or result_len - 3
result_idx = result_rewind
end
end
end
return table.concat(result)
end
local known_gossip_dynamic_seq_with_multiple_words_for_get_text_code = {
{"night elf", "nightelf"},
{"blood elf", "bloodelf"},
{"death knight", "deathknight"},
{"demon hunter", "demonhunter"},
{"void elf", "voidelf"},
{"lightforged draenei", "lightforgeddraenei"},
{"dark iron dwarf", "darkirondwarf"},
{"kul tiran", "kultiran"},
{"highmountain tauren", "highmountaintauren"},
{"mag'har orc", "magharorc"},
{"zandalari troll", "zandalaritroll"},
}
-- [!] Any changes made to get_text_code() func must be kept in sync with Python impl in utils.py
local function get_text_code_for_chat(text)
local text_low_case = text:lower()
local seq_pairs = known_gossip_dynamic_seq_with_multiple_words_for_get_text_code
for i = 1, #seq_pairs do
text_low_case = text_low_case:gsub(seq_pairs[i][1], seq_pairs[i][2])
end
local result = {}
for word in string.gmatch(text_low_case, "%w+") do
if #word > 0 then
result[#result+1] = word:sub(1, 1)
result[#result+1] = word:sub(-1)
end
end
return table.concat(result)
end
local function fuzzy_match_text_code(code, candidates, minimum_match_ratio)
if not minimum_match_ratio then
minimum_match_ratio = 0.5
end
local best_match = false
local best_match_ratio = 0.0
for i = 1, #candidates do
local matches = 0
if #code == #candidates[i] then
for j = 1, #candidates[i] do
if string.sub(code, j, j) == string.sub(candidates[i], j, j) then
matches = matches + 1
end
end
end
local ratio = matches/#code
if ratio >= minimum_match_ratio and ratio > best_match_ratio then
best_match = candidates[i]
best_match_ratio = ratio
end
end
return best_match
end
local function match_text_code(code, candidates)
for _, candidate in ipairs(candidates) do
if code:match('^'..candidate..'$') then
return candidate
end
end
return false
end
-- -----------
-- [ dev log ]
-- -----------
---@class dev_log_class
local dev_log = nil
local default_dev_log = {
addon_version = "???",
game_version = "???",
game_expansion = "???",
missing_quests = {},
missing_npcs = {},
missing_items = {},
missing_spells = {},
missing_books = {},
missing_gossips = {},
missing_chats = {},
missing_zones = {},
missing_objects = {},
missing_sod_engravings = {},
issues = {}
}
local function dev_log_print(text)
wow.DEFAULT_CHAT_FRAME:AddMessage(asset_ua_code .. " |cff4488aa[Розробка] " .. text .. "|r")
end
local function dev_log_init()
dev_log.addon_version = wow.GetAddOnMetadata("ClassicUA", "Version")
dev_log.game_version = build_info
dev_log.game_expansion = game_expansion_key()
if not dev_log.missing_quests then dev_log.missing_quests = {} end
if not dev_log.missing_npcs then dev_log.missing_npcs = {} end
if not dev_log.missing_items then dev_log.missing_items = {} end
if not dev_log.missing_spells then dev_log.missing_spells = {} end
if not dev_log.missing_books then dev_log.missing_books = {} end
if not dev_log.missing_gossips then dev_log.missing_gossips = {} end
if not dev_log.missing_chats then dev_log.missing_chats = {} end
if not dev_log.missing_zones then dev_log.missing_zones = {} end
if not dev_log.missing_objects then dev_log.missing_objects = {} end
if not dev_log.missing_sod_engravings then dev_log.missing_sod_engravings = {} end
if not dev_log.issues then dev_log.issues = {} end
end
local function dev_log_print_stats()
dev_log_print("-------- Статистика накопичених даних --------")
dev_log_print("Відсутні завдання: " .. table_keys_count(dev_log.missing_quests))
dev_log_print("Відсутні персонажі: " .. table_keys_count(dev_log.missing_npcs))
dev_log_print("Відсутні предмети: " .. table_keys_count(dev_log.missing_items))
dev_log_print("Відсутні закляття: " .. table_keys_count(dev_log.missing_spells))
dev_log_print("Відсутні книжки: " .. table_keys_count(dev_log.missing_books))
dev_log_print("Відсутні плітки: " .. table_keys_count(dev_log.missing_gossips))
dev_log_print("Відсутні чати: " .. table_keys_count(dev_log.missing_chats))
dev_log_print("Відсутні зони: " .. table_keys_count(dev_log.missing_zones))
dev_log_print("Відсутні об'єкти: " .. table_keys_count(dev_log.missing_objects))
if is_classic_sod then
dev_log_print("Відсутні SOD гравіювання: " .. table_keys_count(dev_log.missing_sod_engravings))
end
dev_log_print("Помилки: " .. table_keys_count(dev_log.issues))
dev_log_print("----------------------------------------------")
end
local function dev_log_reset()
ClassicUA_DevLog = copy_table({}, default_dev_log)
dev_log = ClassicUA_DevLog
dev_log_init()
dev_log_print("Всі накопичені дані скинуто.")
end
local function dev_log_issue(key, data)
key = string.trim(key or "???")
if not options.dev_mode or dev_log.issues[key] then
return
end
if options.dev_mode_notify_activity then
dev_log_print("Помилка: " .. key)
end
dev_log.issues[key] = data and data or true
end
local function dev_log_issue_entry(entry_type, entry_id, key, data)
dev_log_issue(entry_type .. "#" .. tostring(entry_id) .. ": " .. key, data)
end
local function dev_log_missing_quest(quest_id)
quest_id = tonumber(quest_id)
if not quest_id then
return
end
if dev_log.missing_quests[quest_id] then
return
end
if options.dev_mode_notify_activity then
dev_log_print("Відсутнє завдання #" .. tostring(quest_id))
end
dev_log.missing_quests[quest_id] = true
end
local function dev_log_missing_npc(npc_id, npc_name)
npc_id = tonumber(npc_id)
if not npc_id then
return
end
if dev_log.missing_npcs[npc_id] then
return
end
if options.dev_mode_notify_activity then
dev_log_print("Відсутній персонаж #" .. tostring(npc_id) .. " " .. npc_name)
end
dev_log.missing_npcs[npc_id] = npc_name
end
local function dev_log_missing_item(item_id, item_name)
item_id = tonumber(item_id)
if not item_id then
return
end
if dev_log.missing_items[item_id] then
return
end
if options.dev_mode_notify_activity then
dev_log_print("Відсутній предмет #" .. tostring(item_id) .. " " .. item_name)
end
dev_log.missing_items[item_id] = item_name
end
local function dev_log_missing_spell(spell_id, spell_name)
spell_id = tonumber(spell_id)
if not spell_id then
return
end
if dev_log.missing_spells[spell_id] then
return
end
if options.dev_mode_notify_activity then
dev_log_print("Відсутнє закляття #" .. tostring(spell_id) .. " " .. spell_name)
end
dev_log.missing_spells[spell_id] = spell_name
end
local function dev_log_missing_sod_engraving(sod_engraving_id, sod_engraving_name)
sod_engraving_id = tonumber(sod_engraving_id)
if not sod_engraving_id then
return
end
if dev_log.missing_sod_engravings[sod_engraving_id] then
return
end
if options.dev_mode_notify_activity then
dev_log_print("Відсутнє SOD гравіювання #" .. tostring(sod_engraving_id) .. " " .. sod_engraving_name)
end
dev_log.missing_sod_engravings[sod_engraving_id] = sod_engraving_name
end
local function dev_log_missing_book_page(book_id, page_number, page_text)
book_id = tonumber(book_id)
if not book_id then
return
end
if not dev_log.missing_books[book_id] then
dev_log.missing_books[book_id] = {}
end
local page_number_text = tostring(page_number)
local page_key = "page_" .. page_number_text
if dev_log.missing_books[book_id][page_key] then
return
end
if options.dev_mode_notify_activity then
dev_log_print("Відсутня сторінка " .. page_number_text .. " книги #" .. book_id)
end
dev_log.missing_books[book_id][page_key] = page_text
end
local function dev_log_missing_gossip(npc_id, gossip_code, gossip_text_en)
npc_id = tonumber(npc_id)
if not npc_id then
return
end
if not dev_log.missing_gossips[npc_id] then
dev_log.missing_gossips[npc_id] = {}
end
if dev_log.missing_gossips[npc_id][gossip_code] then
return
end
if options.dev_mode_notify_activity then
dev_log_print("Відсутня плітка \"" .. gossip_code .. "\" для персонажа #" .. npc_id)
end
dev_log.missing_gossips[npc_id][gossip_code] = gossip_text_en
end
local function dev_log_missing_chat_text(npc_name, chat_text_code, chat_text_en)
if not dev_log.missing_chats[npc_name] then
dev_log.missing_chats[npc_name] = {}
end
if dev_log.missing_chats[npc_name][chat_text_code] then
return
end
if options.dev_mode_notify_activity then
dev_log_print("Відсутній чат \"" .. chat_text_code .. "\" для " .. npc_name)
end
dev_log.missing_chats[npc_name][chat_text_code] = chat_text_en
end
local function dev_log_missing_zone(zone_name)
zone_name = string.trim(zone_name or "???")
if not string.match(zone_name, "%w") then
-- skip non-English zone name
return
end
if dev_log.missing_zones[zone_name] then
return
end
if options.dev_mode_notify_activity then
dev_log_print("Відсутня зона \"" .. zone_name .. "\"")
end
dev_log.missing_zones[zone_name] = true
end
local function dev_log_missing_object(object_name)
object_name = string.trim(object_name or "???")
if dev_log.missing_objects[object_name] then
return
end
if options.dev_mode_notify_activity then
dev_log_print("Відсутній об'єкт \"" .. object_name .. "\"")
end
dev_log.missing_objects[object_name] = true
end
-- -----------
-- [ options ]
-- -----------
local default_options = {
dev_mode = false,
dev_mode_notify_activity = false,
quest_text_size = 13,
book_text_size = 15
}
---@class character_options_class
---@field name_cases table
local character_options = nil
local default_character_options = {
name_cases = {}
}
local function prepare_options()
ClassicUA_Options = ClassicUA_Options or copy_table({}, default_options)
options = ClassicUA_Options
ClassicUA_Character_Options = ClassicUA_Character_Options or copy_table({}, default_character_options)
character_options = ClassicUA_Character_Options
ClassicUA_DevLog = ClassicUA_DevLog or copy_table({}, default_dev_log)
dev_log = ClassicUA_DevLog
dev_log_init()
-- clean up unknown/deprecated keys
for _, v in pairs({
{ options, default_options },
{ character_options, default_character_options },
{ dev_log, default_dev_log },
}) do
for k, _ in pairs(v[1]) do
if v[2][k] == nil then
v[1][k] = nil
end
end
end
end
local function reset_options()
ClassicUA_Options = copy_table({}, default_options)
options = ClassicUA_Options
if options_frame then
options_frame.refresh()
end
end
-- -----------
-- [ entries ]
-- -----------
local function get_stats()
local at = addonTable
local stats = {}
for _, v in ipairs({
"quest_alliance",
"quest_horde",
"quest_both",
"book",
"item",
"spell",
"npc",
"object",
"zone"
}) do
if at[v .. '_stats'] then
stats[v] = at[v .. '_stats'].count
else
stats[v] = 0
for _, _ in pairs(at[v]) do stats[v] = stats[v] + 1 end
end
end
return stats
end
local function prepare_talent_tree(class)
-- keep only player class tree
addonTable.talent_tree = addonTable.talent_tree[class]
end
local function prepare_quests(is_alliance)
-- init faction quests reference
addonTable.quest_faction = is_alliance and addonTable.quest_alliance or addonTable.quest_horde
-- drop opposite faction quests
addonTable[ is_alliance and "quest_horde" or "quest_alliance" ] = nil
end
local function prepare_glossary()
local at = addonTable
local glossary = {}
-- collect text-key entries: text, zone, object
for _, entry_type in pairs({ "text", "zone", "object" }) do
for entry_key, entry_value in pairs(at[entry_type]) do
local glossary_key = string.trim(entry_key:lower())
if not glossary[glossary_key] then
glossary[glossary_key] = entry_value
end
-- if key starts with "the " part, add key without it
if glossary_key:find("^the ") and #glossary_key > 8 then
local glossary_key_no_the = glossary_key:sub(5)
if not glossary[glossary_key_no_the] then
glossary[glossary_key_no_the] = entry_value
end
else
-- if key doesn't start with "the ", add key that does
local glossary_key_with_the = "the " .. glossary_key
if not glossary[glossary_key_with_the] then
glossary[glossary_key_with_the] = entry_value
end
end
end
end
-- collect id-key entries: quest, npc
for _, entry_type in pairs({ "quest_faction", "quest_both", "npc" }) do
for _, entry_value in pairs(at[entry_type]) do
if entry_value.en then
local glossary_key = string.trim(entry_value.en:lower())
if not glossary[glossary_key] then
glossary[glossary_key] = entry_value[1]
end
end
end
end
at.glossary = glossary
end
local function prepare_codes(name, race, class, is_male)
local at = addonTable
local sex = is_male and 1 or 2
local cases = { "н", "р", "д", "з", "о", "м", "к" }
local name_cases = character_options.name_cases
local codes = {}
local race_lower = race:lower()
-- name
for _, c in ipairs(cases) do
local t = name_cases[c] or ""
if t == "" then
t = name_cases["н"] or ""
if t == "" then
t = name
end
end
codes["{ім'я:" .. c .. "}"] = t
codes["{Ім'я:" .. c .. "}"] = capitalize(t)
codes["{ІМ'Я:" .. c .. "}"] = string.upper(t)
if c == "н" then -- "н" is default grammatical case
codes["{ім'я}"] = codes["{ім'я:н}"]
codes["{Ім'я}"] = codes["{Ім'я:н}"]
codes["{ІМ'Я}"] = codes["{ІМ'Я:н}"]
end
end
-- race
if not at.race[race_lower] then
-- use some default value in case race is unknown/unsupported
race = "Human"
end
for _, c in ipairs(cases) do
local t = at.race[race_lower][c][sex]
codes["{раса:" .. c .. "}"] = t
codes["{Раса:" .. c .. "}"] = capitalize(t)
codes["{РАСА:" .. c .. "}"] = string.upper(t)
if c == "н" then -- "н" is default grammatical case
codes["{раса}"] = codes["{раса:н}"]
codes["{Раса}"] = codes["{Раса:н}"]
codes["{РАСА}"] = codes["{РАСА:н}"]
end
end
-- class
if not at.class[class] then
-- use some default value in case class is unknown/unsupported
class = "WARRIOR"
end
for _, c in ipairs(cases) do
local t = at.class[class][c][sex]
codes["{клас:" .. c .. "}"] = t
codes["{Клас:" .. c .. "}"] = capitalize(t)
codes["{КЛАС:" .. c .. "}"] = string.upper(t)
if c == "н" then -- "н" is default grammatical case
codes["{клас}"] = codes["{клас:н}"]
codes["{Клас}"] = codes["{Клас:н}"]
codes["{КЛАС}"] = codes["{КЛАС:н}"]
end
end
-- sex
-- only "стать" is needed, but we make possible to use any letter casing
-- (even if it has nothing to do with the letter case of the result, as text gets shown as is)
codes["{стать:(.-):(.-)}"] = function (a, b) return is_male and a or b end
codes["{Стать:(.-):(.-)}"] = function (a, b) return is_male and a or b end
codes["{СТАТЬ:(.-):(.-)}"] = function (a, b) return is_male and a or b end
at.codes = codes
end
local function make_text(text)
if not text then
return nil
end
for k, v in pairs(addonTable.codes) do
text = text:gsub(k, v)
end
return text
end
local function make_text_array(array)
if not array then
return nil
end
local result = {}
for i = 1, #array do
result[i] = make_text(array[i])
end
return result
end
local function make_chat_text(original, translation)
local known_templates = { ["name"] = true, ["race"] = true, ["class"] = true, ["target"] = true }
local at = addonTable
local sex = wow.UnitSex("player") == 2 and 1 or 2 -- UnitSex("player") == 2 - male
if not translation then
return nil
end
local translation_split = { string.split("#", translation) }
if #translation_split == 1 then
return translation_split[1]
end
translation = translation_split[1]
local text_templates = {}
for i = 2, #translation_split do
local template = translation_split[i]
-- TODO: Instead of one-placeholder-per-template remember placeholders types, allowing to have few placeholders in one template
local template_type = template:match("<(.+)>")
if known_templates[template_type] then
text_templates[template_type] = template
elseif template_type:match("/") then
local match_male, match_female = template_type:match("^(%w+)/(%w+)$")
if original:match(template:gsub("<"..template_type..">", match_male)) then
sex = 1
elseif original:match(template:gsub("<"..template_type..">", match_female)) then
sex = 2
else
error("Error. Unknown sex.")
end
else
error("Error. Unknown template type: " .. tostring(template_type))
end
end
local template_matches = {}
for template_type, template in pairs(text_templates) do
local template_expression = esc(template):gsub("<" .. template_type .. ">", "(.-)")
local match = original:match(template_expression)
template_matches[template_type] = match
end
for pattern_uk in translation:gmatch("{(.-)}") do
local pattern_uk_split = { string.split(":", pattern_uk) }
local pattern_uk_type = pattern_uk_split[1]
local case = pattern_uk_split[2] or "н"
pattern_uk = "{" .. pattern_uk .. "}"
if lower(pattern_uk_type) == "ім'я" then
local name_en = template_matches["name"]
local name_uk
if name_en == wow.UnitName("player") then
name_uk = character_options.name_cases and character_options.name_cases[case] or name_en
else
name_uk = name_en
end
name_uk = name_uk and pattern_uk_type == "Ім'я" and capitalize(name_uk) or name_uk -- TODO: check these operators and maybe optimize their usage
name_uk = name_uk and pattern_uk_type == "ІМ'Я" and upper(name_uk) or name_uk
translation = translation:gsub(pattern_uk, name_uk)
end
if pattern_uk_type:lower() == "раса" then
local race_en = template_matches["race"]
local race_key = race_en:lower():gsub(" ", "")
if race_key == "scourge" then
-- Player's race called "scourge", but NPCs call them "undead"
race_key = "undead"
end
local race_uk = at.race[race_key] and at.race[race_key][case][sex]
race_uk = race_uk and pattern_uk_type == "Раса" and capitalize(race_uk) or race_uk
race_uk = race_uk and pattern_uk_type == "РАСА" and upper(race_uk) or race_uk
translation = translation:gsub(pattern_uk, race_uk or race_en)
end
if pattern_uk_type:lower() == "клас" then
local class_en = template_matches["class"]
local class_key = class_en:upper():gsub(" ", "")
local class_uk = at.class[class_key] and at.class[class_key][case][sex]
class_uk = class_uk and pattern_uk_type == "Клас" and capitalize(class_uk) or class_uk
class_uk = class_uk and pattern_uk_type == "КЛАС" and upper(class_uk) or class_uk
translation = translation:gsub(pattern_uk, class_uk or class_en)
end
if lower(pattern_uk_type) == "ціль" then
local target_en = template_matches["target"]