Repository navigation
Expand file tree
/
Copy pathTalented.lua
More file actions
2520 lines (2305 loc) · 65.3 KB
/
Copy pathTalented.lua
File metadata and controls
2520 lines (2305 loc) · 65.3 KB
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 Talented = LibStub("AceAddon-3.0"):NewAddon("Talented", "AceEvent-3.0", "AceHook-3.0", "AceConsole-3.0", "AceComm-3.0", "AceSerializer-3.0")
_G.Talented = Talented
local L = LibStub("AceLocale-3.0"):GetLocale("Talented")
-------------------------------------------------------------------------------
-- core.lua
--
do
Talented.prev_Print = Talented.Print
function Talented:Print(s, ...)
if type(s) == "string" and s:find("%", nil, true) then
self:prev_Print(s:format(...))
else
self:prev_Print(s, ...)
end
end
function Talented:Debug(...)
if not self.db or self.db.profile.debug then
self:Print(...)
end
end
function Talented:MakeTarget(targetName)
local name = self.db.char.targets[targetName]
local src = name and self.db.global.templates[name]
if not src then
if name then
self.db.char.targets[targetName] = nil
end
return
end
local target = self.target
if not target then
target = {}
self.target = target
end
self:CopyPackedTemplate(src, target)
if
not self:ValidateTemplate(target) or
(RAID_CLASS_COLORS[target.class] and target.class ~= select(2, UnitClass "player")) or
(not RAID_CLASS_COLORS[target.class] and (not self.GetPetClass or target.class ~= self:GetPetClass()))
then
self.db.char.targets[targetName] = nil
return nil
end
target.name = name
return target
end
function Talented:GetMode()
return self.mode
end
function Talented:SetMode(mode)
if self.mode ~= mode then
self.mode = mode
if mode == "apply" then
self:ApplyCurrentTemplate()
elseif self.base and self.base.view then
self.base.view:SetViewMode(mode)
end
end
local cb = self.base and self.base.checkbox
if cb then
cb:SetChecked(mode == "edit")
end
end
function Talented:OnInitialize()
self.db = LibStub("AceDB-3.0"):New("TalentedDB", self.defaults)
self:UpgradeOptions()
self:LoadTemplates()
local AceDBOptions = LibStub("AceDBOptions-3.0", true)
if AceDBOptions then
self.options.args.profiles = AceDBOptions:GetOptionsTable(self.db)
self.options.args.profiles.order = 200
end
LibStub("AceConfig-3.0"):RegisterOptionsTable("Talented", self.options)
self.optionsFrame = LibStub("AceConfigDialog-3.0"):AddToBlizOptions("Talented", "Talented")
self:RegisterChatCommand("talented", "OnChatCommand")
self:RegisterComm("Talented")
if self.InitializePet then
self:InitializePet()
end
self.OnInitialize = nil
end
function Talented:OnChatCommand(input)
if not input or input:trim() == "" then
self:OpenOptionsFrame()
else
LibStub("AceConfigCmd-3.0").HandleCommand(self, "talented", "Talented", input)
end
end
function Talented:DeleteCurrentTemplate()
local template = self.template
if template.talentGroup then return end
local templates = self.db.global.templates
templates[template.name] = nil
self:SetTemplate()
end
function Talented:UpdateTemplateName(template, newname)
if self.db.global.templates[newname] or template.talentGroup or type(newname) ~= "string" or newname == "" then return end
local oldname = template.name
template.name = newname
local t = self.db.global.templates
t[newname] = template
t[oldname] = nil
end
do
local function new(templates, name, class)
local count = 0
local template = {name = name, class = class}
while templates[template.name] do
count = count + 1
template.name = format(L["%s (%d)"], name, count)
end
templates[template.name] = template
return template
end
local function copy(dst, src)
dst.class = src.class
if src.code then
dst.code = src.code
return
else
for tab, tree in ipairs(Talented:UncompressSpellData(src.class)) do
local s, d = src[tab], {}
dst[tab] = d
for index = 1, #tree do
d[index] = s[index]
end
end
end
end
function Talented:ImportFromOther(name, src)
if not self:UncompressSpellData(src.class) then
return
end
local dst = new(self.db.global.templates, name, src.class)
copy(dst, src)
self:OpenTemplate(dst)
return dst
end
function Talented:CopyTemplate(src)
local dst = new(self.db.global.templates, format(L["Copy of %s"], src.name), src.class)
copy(dst, src)
return dst
end
function Talented:CreateEmptyTemplate(class)
class = class or select(2, UnitClass "player")
local template = new(self.db.global.templates, L["Empty"], class)
local info = self:UncompressSpellData(class)
for tab, tree in ipairs(info) do
local t = {}
template[tab] = t
for index = 1, #tree do
t[index] = 0
end
end
return template
end
Talented.importers = {}
Talented.exporters = {}
function Talented:ImportTemplate(url)
local dst, result = new(self.db.global.templates, L["Imported"])
for pattern, method in pairs(self.importers) do
if url:find(pattern) then
result = method(self, url, dst)
if result then
break
end
end
end
if result then
if not self:ValidateTemplate(dst) then
self:Print(L["The given template is not a valid one!"])
self.db.global.templates[dst.name] = nil
else
return dst
end
else
self:Print(L['"%s" does not appear to be a valid URL!'], url)
self.db.global.templates[dst.name] = nil
end
end
end
function Talented:OpenTemplate(template)
self:UnpackTemplate(template)
if not self:ValidateTemplate(template, true) then
local name = template.name
self.db.global.templates[name] = nil
self:Print(L["The template '%s' is no longer valid and has been removed."], name)
return
end
local base = self:CreateBaseFrame()
if not self.alternates then
self:UpdatePlayerSpecs()
end
self:SetTemplate(template)
if not base:IsVisible() then
ShowUIPanel(base)
end
end
function Talented:SetTemplate(template)
if not template then
template = assert(self:GetActiveSpec())
end
local view = self:CreateBaseFrame().view
local old = view.template
if template ~= old then
if template.talentGroup then
if not template.pet then
view:SetTemplate(template, self:MakeTarget(template.talentGroup))
else
view:SetTemplate(template, self:MakeTarget(UnitName "PET"))
end
else
view:SetTemplate(template)
end
self.template = template
end
if not template.talentGroup then
self.db.profile.last_template = template.name
end
self:SetMode(self:GetDefaultMode())
-- self:UpdateView()
end
function Talented:GetDefaultMode()
return self.db.profile.always_edit and "edit" or "view"
end
function Talented:OnEnable()
self:RawHook("ToggleTalentFrame", true)
self:RawHook("ToggleGlyphFrame", true)
self:SecureHook("UpdateMicroButtons")
self:CheckHookInspectUI()
self:RegisterEvent("PLAYER_ENTERING_WORLD")
UIParent:UnregisterEvent("USE_GLYPH")
UIParent:UnregisterEvent("CONFIRM_TALENT_WIPE")
self:RegisterEvent("USE_GLYPH")
self:RegisterEvent("CONFIRM_TALENT_WIPE")
self:RegisterEvent("CHARACTER_POINTS_CHANGED")
self:RegisterEvent("PLAYER_TALENT_UPDATE")
TalentMicroButton:SetScript("OnClick", ToggleTalentFrame)
end
function Talented:OnDisable()
self:UnhookInspectUI()
UIParent:RegisterEvent("USE_GLYPH")
UIParent:RegisterEvent("CONFIRM_TALENT_WIPE")
end
function Talented:PLAYER_ENTERING_WORLD()
local E = ElvUI and unpack(ElvUI)
if E then
-- spec tabs
E.callbacks:Fire("Talented_SpecTabs")
-- glyph frame
self:CreateGlyphFrame()
E.callbacks:Fire("Talented_GlyphFrame")
end
end
function Talented:PLAYER_TALENT_UPDATE()
self:UpdatePlayerSpecs()
end
function Talented:CONFIRM_TALENT_WIPE(_, cost)
local dialog = StaticPopup_Show("CONFIRM_TALENT_WIPE")
if dialog then
MoneyFrame_Update(dialog:GetName() .. "MoneyFrame", cost)
self:SetTemplate()
local frame = self.base
if not frame or not frame:IsVisible() then
self:Update()
ShowUIPanel(self.base)
end
dialog:SetFrameLevel(frame:GetFrameLevel() + 5)
end
end
function Talented:CHARACTER_POINTS_CHANGED()
self:UpdatePlayerSpecs()
self:UpdateView()
if self.mode == "apply" then
self:CheckTalentPointsApplied()
end
end
function Talented:UpdateMicroButtons()
local button = TalentMicroButton
if self.db.profile.donthide and UnitLevel "player" < button.minLevel then
button:Enable()
end
if self.base and self.base:IsShown() then
button:SetButtonState("PUSHED", 1)
else
button:SetButtonState("NORMAL")
end
end
function Talented:ToggleTalentFrame()
local frame = self.base
if not frame or not frame:IsVisible() then
self:Update()
ShowUIPanel(self.base)
else
HideUIPanel(frame)
end
end
function Talented:Update()
self:CreateBaseFrame()
self:UpdatePlayerSpecs()
if not self.template then
self:SetTemplate()
end
self:UpdateView()
end
function Talented:LoadTemplates()
local db = self.db.global.templates
local invalid = {}
for name, code in pairs(db) do
if type(code) == "string" then
local class = self:GetTemplateStringClass(code)
if class then
db[name] = {
name = name,
code = code,
class = class
}
else
db[name] = nil
invalid[#invalid + 1] = name
end
elseif not self:ValidateTemplate(code) then
db[name] = nil
invalid[#invalid + 1] = name
end
end
if next(invalid) then
table.sort(invalid)
self:Print(L["The following templates are no longer valid and have been removed:"])
self:Print(table.concat(invalid, ", "))
end
self.OnDatabaseShutdown = function(self, event, db)
local _db = db.global.templates
for name, template in pairs(_db) do
template.talentGroup = nil
Talented:PackTemplate(template)
if template.code then
_db[name] = template.code
end
end
self.db = nil
end
self.db.RegisterCallback(self, "OnDatabaseShutdown")
self.LoadTemplates = nil
end
end
-------------------------------------------------------------------------------
-- spell.lua
--
do
local function handle_ranks(...)
local result = {}
local first = (...)
local pos, row, column, req = 1
local c = string.byte(first, pos)
if c == 42 then
row, column = nil, -1
pos = pos + 1
c = string.byte(first, pos)
elseif c > 32 and c <= 40 then
column = c - 32
if column > 4 then
row = true
column = column - 4
end
pos = pos + 1
c = string.byte(first, pos)
end
if c >= 65 and c <= 90 then
req = c - 64
pos = pos + 1
elseif c >= 97 and c <= 122 then
req = 96 - c
pos = pos + 1
end
result[1] = tonumber(first:sub(pos))
for i = 2, select("#", ...) do
result[i] = tonumber((select(i, ...)))
end
local entry = {
ranks = result,
row = row,
column = column,
req = req
}
if not result[1] then
entry.req = nil
entry.ranks = nil
entry.inactive = true
end
return entry
end
local function next_talent_pos(row, column)
column = column + 1
if column >= 5 then
return row + 1, 1
else
return row, column
end
end
local function handle_talents(...)
local result = {}
for talent = 1, select("#", ...) do
result[talent] = handle_ranks(strsplit(";", (select(talent, ...))))
end
local row, column = 1, 1
for index, talent in ipairs(result) do
local drow, dcolumn = talent.row, talent.column
if dcolumn == -1 then
talent.row, talent.column = result[index - 1].row, result[index - 1].column
talent.inactive = true
elseif dcolumn then
if drow then
row = row + 1
column = dcolumn
else
column = column + dcolumn
end
talent.row, talent.column = row, column
else
talent.row, talent.column = row, column
end
if dcolumn ~= -1 or drow then
row, column = next_talent_pos(row, column)
end
if talent.req then
talent.req = talent.req + index
assert(talent.req > 0 and talent.req <= #result)
end
end
return result
end
local function handle_tabs(...)
local result = {}
for tab = 1, select("#", ...) do
result[tab] = handle_talents(strsplit(",", (select(tab, ...))))
end
return result
end
function Talented:UncompressSpellData(class)
local data = self.spelldata[class]
if type(data) == "table" then
return data
end
self:Debug("UNCOMPRESS CLASSDATA", class)
data = handle_tabs(strsplit("|", data))
self.spelldata[class] = data
if class == select(2, UnitClass("player")) and self.CheckSpellData then
self:CheckSpellData(class)
end
return data
end
local spellTooltip
local function CreateSpellTooltip()
local tt = CreateFrame "GameTooltip"
local lefts, rights = {}, {}
for i = 1, 5 do
local left, right = tt:CreateFontString(), tt:CreateFontString()
left:SetFontObject(GameFontNormal)
right:SetFontObject(GameFontNormal)
tt:AddFontStrings(left, right)
lefts[i], rights[i] = left, right
end
tt.lefts, tt.rights = lefts, rights
function tt:SetSpell(spell)
self:SetOwner(_G.TalentedFrame)
self:ClearLines()
self:SetHyperlink("spell:" .. spell)
return self:NumLines()
end
local index
if _G.CowTip then
index = function(self, key)
if not key then
return ""
end
local lines = tt:SetSpell(key)
if not lines then
return ""
end
local value
if lines == 2 and not tt.rights[2]:GetText() then
value = tt.lefts[2]:GetText()
else
value = {}
for i = 2, tt:NumLines() do
value[i - 1] = {
left = tt.lefts[i]:GetText(),
right = tt.rights[i]:GetText()
}
end
end
tt:Hide() -- CowTip forces the Tooltip to Show, for some reason
self[key] = value
return value
end
else
index = function(self, key)
if not key then
return ""
end
local lines = tt:SetSpell(key)
if not lines then
return ""
end
local value
if lines == 2 and not tt.rights[2]:GetText() then
value = tt.lefts[2]:GetText()
else
value = {}
for i = 2, tt:NumLines() do
value[i - 1] = {
left = tt.lefts[i]:GetText(),
right = tt.rights[i]:GetText()
}
end
end
self[key] = value
return value
end
end
Talented.spellDescCache = setmetatable({}, {__index = index})
CreateSpellTooltip = nil
return tt
end
function Talented:GetTalentName(class, tab, index)
local spell = self:UncompressSpellData(class)[tab][index].ranks[1]
return (GetSpellInfo(spell))
end
function Talented:GetTalentIcon(class, tab, index)
local spell = self:UncompressSpellData(class)[tab][index].ranks[1]
return (select(3, GetSpellInfo(spell)))
end
function Talented:GetTalentDesc(class, tab, index, rank)
if not spellTooltip then
spellTooltip = CreateSpellTooltip()
end
local spell = self:UncompressSpellData(class)[tab][index].ranks[rank]
return self.spellDescCache[spell]
end
function Talented:GetTalentPos(class, tab, index)
local talent = self:UncompressSpellData(class)[tab][index]
return talent.row, talent.column
end
function Talented:GetTalentPrereqs(class, tab, index)
local talent = self:UncompressSpellData(class)[tab][index]
return talent.req
end
function Talented:GetTalentRanks(class, tab, index)
local talent = self:UncompressSpellData(class)[tab][index]
return #talent.ranks
end
function Talented:GetTalentLink(template, tab, index, rank)
local data = self:UncompressSpellData(template.class)
rank = rank or (template[tab] and template[tab][index])
if not rank or rank == 0 then
rank = 1
end
return ("|cff71d5ff|Hspell:%d|h[%s]|h|r"):format(
data[tab][index].ranks[rank],
self:GetTalentName(template.class, tab, index)
)
end
end
-------------------------------------------------------------------------------
-- check.lua
--
do
local function DisableTalented(s, ...)
if s:find("%", nil, true) then
local ok, res = pcall(string.format, s, ...)
if ok then s = res else s = tostring(s) end
end
if DEFAULT_CHAT_FRAME then
DEFAULT_CHAT_FRAME:AddMessage("|cffff7700[Talented Note]: |r" .. tostring(s))
else
print("Talented:", s)
end
end
function Talented:CheckSpellData(class)
if GetNumTalentTabs() < 1 then return end -- postpone checking without failing
local spelldata, tabdata = self.spelldata[class], self.tabdata[class]
if not spelldata or not tabdata then return end
-- Dynamic Alignment: Match each client tab to the corresponding spelldata/tabdata tree by background texture
local tabs_by_bg = {}
for orig_tab, orig_info in ipairs(tabdata) do
if orig_info.background then
tabs_by_bg[orig_info.background] = {
talents = spelldata[orig_tab],
tabinfo = orig_info
}
end
end
local needs_realign = false
for tab = 1, GetNumTalentTabs() do
local _, _, _, background = GetTalentTabInfo(tab)
if tabdata[tab] and tabdata[tab].background ~= background and tabs_by_bg[background] then
needs_realign = true
break
end
end
if needs_realign then
local new_spelldata = {}
local new_tabdata = {}
for tab = 1, GetNumTalentTabs() do
local tabname, _, _, background = GetTalentTabInfo(tab)
if tabs_by_bg[background] then
new_spelldata[tab] = tabs_by_bg[background].talents
new_tabdata[tab] = tabs_by_bg[background].tabinfo
new_tabdata[tab].name = tabname or new_tabdata[tab].name
new_tabdata[tab].background = background or new_tabdata[tab].background
else
new_spelldata[tab] = spelldata[tab]
new_tabdata[tab] = tabdata[tab]
end
end
for tab = 1, GetNumTalentTabs() do
spelldata[tab] = new_spelldata[tab]
tabdata[tab] = new_tabdata[tab]
end
else
for tab = 1, GetNumTalentTabs() do
local tabname, _, _, background = GetTalentTabInfo(tab)
if tabdata[tab] then
tabdata[tab].name = tabname or tabdata[tab].name
tabdata[tab].background = background or tabdata[tab].background
end
end
end
local invalid
if #spelldata > GetNumTalentTabs() then
invalid = true
for i = #spelldata, GetNumTalentTabs() + 1, -1 do
spelldata[i] = nil
end
end
for tab = 1, GetNumTalentTabs() do
local talents = spelldata[tab]
if not talents then
invalid = true
talents = {}
spelldata[tab] = talents
end
if #talents > GetNumTalents(tab) then
invalid = true
for i = #talents, GetNumTalents(tab) + 1, -1 do
talents[i] = nil
end
end
for index = 1, GetNumTalents(tab) do
local talent = talents[index]
if not talent then
talent = { ranks = {}, row = 1, column = 1 }
talents[index] = talent
invalid = true
end
local name, icon, row, column, _, ranks = GetTalentInfo(tab, index)
if not name then
if not talent.inactive then
talent.inactive = true
invalid = true
end
else
if talent.inactive then
talent.inactive = nil
invalid = true
end
local found
for _, spell in ipairs(talent.ranks) do
if GetSpellInfo(spell) == name then
found = true
break
end
end
if not found then
invalid = true
end
if row ~= talent.row then
invalid = true
talent.row = row
end
if column ~= talent.column then
invalid = true
talent.column = column
end
if ranks > #talent.ranks then
invalid = true
local lastSpell = talent.ranks[#talent.ranks] or 0
for i = #talent.ranks + 1, ranks do
talent.ranks[i] = lastSpell
end
end
if ranks < #talent.ranks then
invalid = true
for i = #talent.ranks, ranks + 1, -1 do
talent.ranks[i] = nil
end
end
local req_row, req_column, _, _, req2 = GetTalentPrereqs(tab, index)
if req2 then
invalid = true
end
if not req_row then
if talent.req then
invalid = true
talent.req = nil
end
else
local req = talents[talent.req]
if not req or req.row ~= req_row or req.column ~= req_column then
invalid = true
talent.req = 0
end
end
end
end
for index = 1, GetNumTalents(tab) do
local talent = talents[index]
if talent.req == 0 then
local row, column = GetTalentPrereqs(tab, index)
for j = 1, GetNumTalents(tab) do
if talents[j].row == row and talents[j].column == column then
talent.req = j
break
end
end
end
end
end
self.spellDataChecked = self.spellDataChecked or {}
self.spellDataChecked[class] = true
end
end
-------------------------------------------------------------------------------
-- encode.lua
--
do
local assert, ipairs, modf, fmod = assert, ipairs, math.modf, math.fmod
local stop = "Z"
local talented_map = "012345abcdefABCDEFmnopqrMNOPQRtuvwxy*"
local classmap = {
"DRUID",
"HUNTER",
"MAGE",
"PALADIN",
"PRIEST",
"ROGUE",
"SHAMAN",
"WARLOCK",
"WARRIOR",
"DEATHKNIGHT",
"Ferocity",
"Cunning",
"Tenacity"
}
function Talented:GetTemplateStringClass(code, nmap)
nmap = nmap or talented_map
if code:len() <= 0 then return end
local index = modf((nmap:find(code:sub(1, 1), nil, true) - 1) / 3) + 1
if not index or index > #classmap then return end
return classmap[index]
end
local function get_point_string(class, tabs, primary)
if type(tabs) == "number" then
return " - |cffffd200" .. tabs .. "|r"
end
local start = " - |cffffd200"
if primary then
start = start .. Talented.tabdata[class][primary].name .. " "
tabs[primary] = "|cffffffff" .. tostring(tabs[primary]) .. "|cffffd200"
end
return start .. table.concat(tabs, "/", 1, 3) .. "|r"
end
local temp_tabcount = {}
local function GetTemplateStringInfo(code)
if code:len() <= 0 then return end
local index = modf((talented_map:find(code:sub(1, 1), nil, true) - 1) / 3) + 1
if not index or index > #classmap then return end
local class = classmap[index]
local talents = Talented:UncompressSpellData(class)
local tabs, count, t = 1, 0, 0
for i = 2, code:len() do
local char = code:sub(i, i)
if char == stop then
if t >= #talents[tabs] then
temp_tabcount[tabs] = count
tabs = tabs + 1
count, t = 0, 0
end
temp_tabcount[tabs] = count
tabs = tabs + 1
count, t = 0, 0
else
index = talented_map:find(char, nil, true) - 1
if not index then
return
end
local b = fmod(index, 6)
local a = (index - b) / 6
if t >= #talents[tabs] then
temp_tabcount[tabs] = count
tabs = tabs + 1
count, t = 0, 0
end
t = t + 2
count = count + a + b
end
end
if count > 0 then
temp_tabcount[tabs] = count
else
tabs = tabs - 1
end
for i = tabs + 1, #talents do
temp_tabcount[i] = 0
end
tabs = #talents
if tabs == 1 then
return get_point_string(class, temp_tabcount[1])
else -- tab == 3
local primary, min, max, total = 0, 0, 0, 0
for i = 1, tabs do
local points = temp_tabcount[i]
if points < min then
min = points
end
if points > max then
primary, max = i, points
end
total = total + points
end
local middle = total - min - max
if 3 * (middle - min) >= 2 * (max - min) then
primary = nil
end
return get_point_string(class, temp_tabcount, primary)
end
end
function Talented:GetTemplateInfo(template)
self:Debug("GET TEMPLATE INFO", template.name)
if template.code then
return GetTemplateStringInfo(template.code)
else
local tabs = #template
if tabs == 1 then
return get_point_string(template.class, self:GetPointCount(template))
else
local primary, min, max, total = 0, 0, 0, 0
for i = 1, tabs do
local points = 0
for _, value in ipairs(template[i]) do
points = points + value
end
temp_tabcount[i] = points
if points < min then
min = points
end
if points > max then
primary, max = i, points
end
total = total + points
end
local middle = total - min - max
if 3 * (middle - min) >= 2 * (max - min) then
primary = nil
end
return get_point_string(template.class, temp_tabcount, primary)
end
end
end
function Talented:StringToTemplate(code, template, nmap)
nmap = nmap or talented_map
if code:len() <= 0 then return end
local index = modf((nmap:find(code:sub(1, 1), nil, true) - 1) / 3) + 1
assert(index and index <= #classmap, "Unknown class code")
local class = classmap[index]
template = template or {}
template.class = class
local talents = self:UncompressSpellData(class)
assert(talents)
local tab = 1
local t = wipe(template[tab] or {})
template[tab] = t
for i = 2, code:len() do
local char = code:sub(i, i)
if char == stop then
if #t >= #talents[tab] then
tab = tab + 1
t = wipe(template[tab] or {})
template[tab] = t
end
tab = tab + 1
t = wipe(template[tab] or {})
template[tab] = t
else
index = nmap:find(char, nil, true) - 1
if not index then
return
end
local b = fmod(index, 6)
local a = (index - b) / 6
if #t >= #talents[tab] then
tab = tab + 1
t = wipe(template[tab] or {})
template[tab] = t
end
t[#t + 1] = a
if #t < #talents[tab] then
t[#t + 1] = b
else
assert(b == 0)
end
end
end
assert(#template <= #talents, "Too many branches")
do
for tb, tree in ipairs(talents) do
local _t = template[tb] or {}