-
Notifications
You must be signed in to change notification settings - Fork 1
/
Core.lua
1177 lines (1051 loc) · 36.8 KB
/
Core.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 addonName = ...
local chatCommand = addonName:lower()
local addon = LibStub("AceAddon-3.0"):NewAddon(addonName, "AceConsole-3.0", "AceEvent-3.0")
local L = LibStub("AceLocale-3.0"):GetLocale(addonName, false)
-- _G[addonName] = addon -- uncomment for debugging purposes
local LDB = LibStub("LibDataBroker-1.1", true)
local LDBIcon = LibStub("LibDBIcon-1.0", true)
local defaults = {
profile = {
minimapIcon = {
showInCompartment = WOW_PROJECT_ID == WOW_PROJECT_MAINLINE,
},
fileFormat = "csv";
removeRealmFromName = true,
adjustRankIndex = true,
lastOnlineHours = false,
autoExport = false,
indentation = {
style = "spaces",
depth = 4,
},
csv = {
header = true,
delimiter = ',',
enclosure = '"',
},
html = {
tableHeader = true,
minify = false,
wp = {
enabled = false,
stripedStyle = false,
fixedWidth = false,
},
},
json = {
minify = false,
},
xml = {
rootElementName = "GuildRoster",
recordElementName = "Character",
minify = false,
},
yaml = {
quotationMark = "single",
minify = false,
},
columns = {
{enabled = true, name = "name"}, -- 1
{enabled = true, name = "rankName"}, -- 2
{enabled = true, name = "rankIndex"}, -- 3
{enabled = true, name = "level"}, -- 4
{enabled = true, name = "class"}, -- 5
{enabled = false, name = "zone"}, -- 6
{enabled = false, name = "note"}, -- 7
{enabled = false, name = "officerNote"}, -- 8
{enabled = false, name = "isOnline"}, -- 9
{enabled = false, name = "status"}, -- 10
{enabled = false, name = "classFileName"}, -- 11
{enabled = false, name = "achievementPoints"}, -- 12
{enabled = false, name = "achievementRank"}, -- 13
{enabled = false, name = "isMobile"}, -- 14
{enabled = false, name = "isSoREligible"}, -- 15
{enabled = false, name = "repStandingID"}, -- 16
{enabled = false, name = "GUID"}, -- 17
{enabled = false, name = "lastOnline"}, -- 18
},
ranks = {
true, -- 1
true, -- 2
true, -- 3
true, -- 4
true, -- 5
true, -- 6
true, -- 7
true, -- 8
true, -- 9
true, -- 10
},
exportFrame = {
position = {
"CENTER", -- point
nil, -- relativeTo
"CENTER", -- relativePoint
0, -- xOfs
0, -- yOfs
},
size = {
700, -- Width
450, -- Height
},
maxLetters = 2000000,
},
}
}
local columnDescriptions = {
L["String - Name of character with realm (e.g. \"Arthas-Silvermoon\"). This addon defaults to removing the realm name."], -- 1
L["String - Name of character's guild rank."], -- 2
L["Number - Index of rank, starting at 0 for Guild Master. This addon defaults to adjusting that to 1."], -- 3
L["Number - Character's level."], -- 4
L["String - Localised class name."], -- 5
L["String - Character's location (last location if offline)."], -- 6
L["String - Character's public note. Empty if you can't view notes."], -- 7
L["String - Character's officer note. Empty if you can't view officer notes."], -- 8
L["Boolean - true: online; false: offline."], -- 9
L["Number - 0: none; 1: AFK; 2: Busy."], -- 10
L["String - Upper-case, localisation-independent class name."], -- 11
L["Number - Character's achievement points."], -- 12
L["Number - Where the character ranks in guild in terms of achievement points."], -- 13
L["Boolean - true: player logged in via mobile app."], -- 14
L["Boolean - Scroll of Resurrection eligible."], -- 15
L["Number - Standing ID for character's guild reputation"], -- 16
L["String - Character's Globally Unique Identifier."], -- 17
L["Number - UNIX timestamp. Note that since Blizzard's API doesn't return minutes this timestamp may be wrong by an hour."], -- 18
}
--[[
Supported file formats.
Used in options table.
The lower case name is used for setting the value in addon.db.profile.fileFormat
The upper case name is displayed in the options menu.
--]]
local supportedFileFormats = {
["csv"] = L["CSV"],
["html"] = L["HTML"],
["json"] = L["JSON"],
["xml"] = L["XML"],
["yaml"] = L["YAML"],
}
local sounds = {
openOptions = 88, -- "GAMEDIALOGOPEN"
closeOptions = 624, -- "GAMEGENERICBUTTONPRESS"
closeExportFrame = SOUNDKIT.GS_TITLE_OPTION_EXIT
}
local options = {
name = addonName,
childGroups = "tree",
type = "group",
plugins = {},
args = {
minimapIcon = {
order = 1,
type = "toggle",
width = 1.0225,
name = L["Minimap icon"],
desc = L["Show an icon to open the config at the Minimap."],
get = function() return not addon.db.profile.minimapIcon.hide end,
set = function(info, value) addon.db.profile.minimapIcon.hide = not value; LDBIcon[value and "Show" or "Hide"](LDBIcon, addonName) end,
disabled = function() return not LDBIcon end,
},
fileFormat = {
order = 2,
type = "select",
style = "dropdown",
width = "half",
name = "",
values = supportedFileFormats,
get = function() return addon.db.profile.fileFormat end,
set = function(info, value) addon.db.profile.fileFormat = value end,
},
exportButton = {
order = 3,
type = "execute",
desc = L["WARNING! Large exports may freeze your game for several seconds!"],
name = L["Export"],
width = "half",
func = function() LibStub("AceConfigDialog-3.0"):Close(addonName); addon:ExportData() end,
},
settings = {
order = 4,
type = "group",
name = L["Settings"],
args = {
columns = {
order = 1,
type = "group",
name = L["Columns"],
guiInline = true,
args = {},
},
ranks = {
order = 2,
type = "group",
name = L["Ranks"],
guiInline = true,
args = {},
},
global = {
order = 3,
type = "group",
name = L["Global"],
args = {
removeRealmName = {
order = 1,
type = "toggle",
name = L["Remove realm name in column #1"],
width = "full",
get = function() return addon.db.profile.removeRealmFromName end,
set = function(info, value) addon.db.profile.removeRealmFromName = value end,
},
adjustRankIndex = {
order = 2,
type = "toggle",
width = "full",
name = L["Adjust rank index in column #3"],
desc = L["The index normally starts at 0, but this setting adjust that to 1."] ,
get = function() return addon.db.profile.adjustRankIndex end,
set = function(info, value) addon.db.profile.adjustRankIndex = value end,
},
lastOnlineHours = {
order = 3,
type = "toggle",
width = "full",
name = L["Use hours since last online in column #18"],
desc = L["Calculates how many hours since last being online."] ,
get = function() return addon.db.profile.lastOnlineHours end,
set = function(info, value) addon.db.profile.lastOnlineHours = value end,
},
autoExport = {
order = 4,
type = "toggle",
name = L["Auto export"],
desc = L["Automatically do an export whenever the guild roster updates and save it in this character's database profile, which is stored within this addon's saved variable. The export frame won't be shown."],
get = function() return addon.db.profile.autoExport end,
set = function(info, value) addon.db.profile.autoExport = value; addon.db.profile.autoExportSave = nil end,
},
exportFrame = {
order = 5,
type = "group",
guiInline = true,
name = L["Export frame"],
args = {
maxLetters = {
order = 1,
type = "input",
width = "normal",
name = L["Maximum letters"],
desc = L["Set the maximum number of letters that the export window can show. Set to empty or 0 to use Blizzard's default."],
get = function() return addon.db.profile.exportFrame.maxLetters > 0 and tostring(addon.db.profile.exportFrame.maxLetters) or "" end,
set = function(info, value) value = value == "" and 0 or tonumber(value) or addon.db.profile.exportFrame.maxLetters if value >= 0 then addon.db.profile.exportFrame.maxLetters = value end end,
},
},
},
indentation = {
order = 6,
type = "group",
guiInline = true,
name = L["Indentation"],
args = {
style = {
order = 1,
type = "select",
style = "radio",
width = "half",
name = L["Style"],
desc = L["Select what style to use when exporting HTML, JSON, and XML."],
values = {["tabs"] = L["Tabs"], ["spaces"] = L["Spaces"]},
get = function() return addon.db.profile.indentation.style end,
set = function(info, value) addon.db.profile.indentation.style = value end,
},
infoText = {
order = 2,
type = "description",
name = L["Spaces are the default indentation style because tabs may be displayed as a strange symbol in the export window. However, copying the tabs work just fine and will be displayed correctly in a text editor."],
},
spacer1 = {
order = 3,
width = "full",
type = "description",
name = "",
},
depth = {
order = 4,
type = "range",
min = 0,
max = 8,
step = 1,
width = "normal",
name = L["Depth"],
desc = L["Set the depth used when spaces are set as indentation style. Smaller depth shortens the time before the data is displayed."],
get = function() return addon.db.profile.indentation.depth end,
set = function(info, value) addon.db.profile.indentation.depth = value; end,
disabled = function() return addon.db.profile.indentation.style ~= "spaces" end,
},
},
},
},
},
csv = {
order = 4,
type = "group",
name = supportedFileFormats["csv"],
-- guiInline = true,
args = {
header = {
order = 1,
type = "toggle",
width = "full",
name = L["Header"] ,
desc = "",
get = function() return addon.db.profile.csv.header end,
set = function(info, value) addon.db.profile.csv.header = value end,
},
delimiter = {
order = 2,
type = "input",
width = "half",
name = L["Delimiter"],
get = function() return addon.db.profile.csv.delimiter end,
set = function(info, value) if value ~= "" then addon.db.profile.csv.delimiter = value end end,
},
spacer1 = {
order = 3,
width = "full",
type = "description",
name = "",
},
enclosure = {
order = 4,
type = "input",
width = "half",
name = L["Enclosure"],
get = function() return addon.db.profile.csv.enclosure end,
set = function(info, value) if value ~= "" then addon.db.profile.csv.enclosure = value end end,
},
},
},
html = {
order = 5,
type = "group",
name = supportedFileFormats["html"],
-- guiInline = true,
args = {
tableHeader = {
order = 1,
type = "toggle",
width = "full",
name = L["Table header"] ,
desc = "",
get = function() return addon.db.profile.html.tableHeader end,
set = function(info, value) addon.db.profile.html.tableHeader = value end,
},
minify = {
order = 2,
type = "toggle",
width = "full",
name = L["Minify"],
desc = "",
get = function() return addon.db.profile.html.minify end,
set = function(info, value) addon.db.profile.html.minify = value end,
},
wp = {
order = 4,
type = "group",
name = L["WordPress"],
guiInline = true,
args = {
desc = {
order = 1,
type = "description",
width = "full",
name = L["Output as a WordPress block (Gutenberg editor)."],
},
enabled = {
order = 2,
type = "toggle",
width = "full",
name = L["Enabled"],
desc = L["Only use this if you know what you're doing. It requires you to edit the post's code directly. This will also minify the HTML code."],
get = function() return addon.db.profile.html.wp.enabled end,
set = function(info, value) addon.db.profile.html.wp.enabled = value end,
},
stripedStyle = {
order = 3,
type = "toggle",
width = "full",
name = L["Striped style"],
get = function() return addon.db.profile.html.wp.stripedStyle end,
set = function(info, value) addon.db.profile.html.wp.stripedStyle = value end,
-- disabled = function() return not addon.db.profile.html.wp.enabled end,
},
fixedWidth = {
order = 4,
type = "toggle",
width = "full",
name = L["Fixed width table cells"],
get = function() return addon.db.profile.html.wp.fixedWidth end,
set = function(info, value) addon.db.profile.html.wp.fixedWidth = value end,
-- disabled = function() return not addon.db.profile.html.wp.enabled end,
},
},
},
},
},
json = {
order = 6,
type = "group",
name = supportedFileFormats["json"],
-- guiInline = true,
args = {
minify = {
order = 1,
type = "toggle",
width = "full",
name = L["Minify"],
desc = "",
get = function() return addon.db.profile.json.minify end,
set = function(info, value) addon.db.profile.json.minify = value end,
}
},
},
xml = {
order = 7,
type = "group",
name = supportedFileFormats["xml"],
-- guiInline = true,
args = {
delimiter = {
order = 1,
type = "input",
width = "normal",
name = L["Root element name"],
get = function() return addon.db.profile.xml.rootElementName end,
set = function(info, value) if value ~= "" then addon.db.profile.xml.rootElementName = value end end,
},
spacer1 = {
order = 2,
width = "full",
type = "description",
name = "",
},
enclosure = {
order = 3,
type = "input",
width = "normal",
name = L["Each record's element name"],
get = function() return addon.db.profile.xml.recordElementName end,
set = function(info, value) if value ~= "" then addon.db.profile.xml.recordElementName = value end end,
},
minify = {
order = 4,
type = "toggle",
width = "full",
name = L["Minify"],
desc = "",
get = function() return addon.db.profile.xml.minify end,
set = function(info, value) addon.db.profile.xml.minify = value end,
}
},
},
yaml = {
order = 8,
type = "group",
name = supportedFileFormats["yaml"],
-- guiInline = true,
args = {
quotationMark = {
order = 1,
type = "select",
style = "radio",
width = "half",
name = L["Quotation mark"],
desc = L["What type of quotation mark to use when strings need to be put in quotes."],
values = {["double"] = L["Double"], ["single"] = L["Single"]},
get = function() return addon.db.profile.yaml.quotationMark end,
set = function(info, value) addon.db.profile.yaml.quotationMark = value end,
},
minify = {
order = 2,
type = "toggle",
width = "full",
name = L["Minify"],
desc = "",
get = function() return addon.db.profile.yaml.minify end,
set = function(info, value) addon.db.profile.yaml.minify = value end,
}
},
},
},
},
},
}
for k, v in ipairs(defaults.profile.columns) do
options.args.settings.args.columns.args[v.name] = {
order = k,
type = "group",
width = "full",
name = "",
guiInline = true,
args = {
name = {
order = 1,
type = "input",
name = tostring(k),
desc = string.format(L["%1$s Default column name: \"%2$s\"."], columnDescriptions[k], v.name ),
get = function() return addon.db.profile.columns[k].name end,
set = function(info, value) addon.db.profile.columns[k].name = value end,
},
toggle = {
order = 2,
type = "toggle",
name = "",
get = function() return addon.db.profile.columns[k].enabled end,
set = function(info, value) addon.db.profile.columns[k].enabled = value end,
},
},
}
end
local function insertGuildRanksIntoOptions()
for k, v in ipairs(defaults.profile.ranks) do
local rankName = GuildControlGetRankName(k)
if rankName == "" then
rankName = L["Unknown"]
end
rankName = string.format("%1$s - %2$s", k, rankName)
options.args.settings.args.ranks.args["rank"..tostring(k)] = {
order = k,
type = "toggle",
name = rankName,
get = function() return addon.db.profile.ranks[k] end,
set = function(info, value) addon.db.profile.ranks[k] = value end,
}
end
end
local function CreateExportFrame()
-- Main Frame
local f = CreateFrame("Frame", nil, UIParent, BackdropTemplateMixin and "BackdropTemplate" or nil)
f:Hide()
f:ClearAllPoints()
f:SetPoint(unpack(addon.db.profile.exportFrame.position))
f:SetSize(unpack(addon.db.profile.exportFrame.size))
f:SetBackdrop({
bgFile = "Interface\\Tooltips\\UI-Tooltip-Background",
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
tile = true,
tileEdge = true,
tileSize = 16,
edgeSize = 16,
insets = { left = 5, right = 5, top = 5, bottom = 5 },
})
f:SetBackdropColor(0,0,0,0.75)
f:SetMovable(true)
f:SetScript("OnMouseDown", function(self, button)
if button == "LeftButton" then
self:StartMoving()
end
end)
f:SetScript("OnMouseUp", function(self, button)
self:StopMovingOrSizing()
addon.db.profile.exportFrame.position = {self:GetPoint()}
end)
-- Buttons
local closeButton = CreateFrame("Button", nil, f, "GameMenuButtonTemplate")
closeButton:SetPoint("BOTTOM", f, "BOTTOM", -75, 7.5)
closeButton:SetScript("OnClick", function(self, button) f.text:SetText(""); f:Hide(); PlaySound(sounds.closeExportFrame) end)
closeButton:SetText(L["Close"])
local closeAndReturnButton = CreateFrame("Button", nil, f, "GameMenuButtonTemplate")
closeAndReturnButton:SetPoint("BOTTOM", f, "BOTTOM", 75, 7.5)
closeAndReturnButton:SetScript("OnClick", function(self, button) f.text:SetText(""); addon:ToggleOptions() end)
closeAndReturnButton:SetText(L["Close & Return"])
-- Scroll frame
local sf = CreateFrame("ScrollFrame", nil, f, "UIPanelScrollFrameTemplate")
sf:SetPoint("TOP", 0, -19.5)
sf:SetPoint("LEFT", 18.5, 0)
sf:SetPoint("RIGHT", -42, 0)
sf:SetPoint("BOTTOM", closeButton, "TOP", 0, 2.5)
-- Edit box
local eb = CreateFrame("EditBox", nil, sf)
eb:SetSize(sf:GetSize())
eb:SetMultiLine(true)
eb:SetAutoFocus(true)
eb:SetFontObject("ChatFontNormal")
eb:SetScript("OnEscapePressed", function() f.text:SetText(""); f:Hide() end)
sf:SetScrollChild(eb)
f.text = eb
-- Resizing
f:SetResizable(true)
-- :SetMinResize removed in patch 10.0.0.
if f.SetResizeBounds then
f:SetResizeBounds(340, 110)
else
-- Backwards compatibility with any client not using the new method yet.
f:SetMinResize(340, 110)
end
local rb = CreateFrame("Button", nil, f)
rb:SetPoint("BOTTOMRIGHT", -4, 4)
rb:SetSize(16, 16)
rb:SetNormalTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
rb:SetHighlightTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Highlight")
rb:SetPushedTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Down")
rb:SetScript("OnMouseDown", function(self, button)
if button == "LeftButton" then
f:StartSizing("BOTTOMRIGHT")
self:GetHighlightTexture():Hide() -- more noticeable
end
end)
rb:SetScript("OnMouseUp", function(self, button)
f:StopMovingOrSizing()
self:GetHighlightTexture():Show()
eb:SetWidth(sf:GetWidth())
addon.db.profile.exportFrame.size = {f:GetSize()}
end)
return f
end
function addon:OnInitialize()
self.db = LibStub("AceDB-3.0"):New(addonName.."DB", defaults)
self.db.RegisterCallback(self, "OnProfileChanged", "UpdateConfigs")
self.db.RegisterCallback(self, "OnProfileCopied", "UpdateConfigs")
self.db.RegisterCallback(self, "OnProfileReset", "UpdateConfigs")
self:ConvertOldConfig()
self:SetupOptions()
self.exportFrame = CreateExportFrame()
self:RegisterChatCommand(chatCommand, "ChatCommand")
self:RegisterEvent("PLAYER_ENTERING_WORLD")
self:RegisterEvent("GUILD_ROSTER_UPDATE")
if LDB then
local LDBObj = LDB:NewDataObject(addonName, {
type = "launcher",
icon = "Interface\\AddOns\\"..addonName.."\\icon",
OnClick = function(_, mouseButton)
if mouseButton == "LeftButton" or mouseButton == "RightButton" then
self:ToggleOptions()
end
end,
OnTooltipShow = function(tooltip)
if not (tooltip and tooltip.AddLine) then return end
tooltip:AddDoubleLine(addonName, GetAddOnMetadata(addonName, "Version"))
tooltip:AddLine(string.format(L["%sClick%s to toggle options."], "|cffffff00", "|r"))
tooltip:AddLine(string.format(L["Or use /%s"], chatCommand))
end,
})
if LDBIcon then
LDBIcon:Register(addonName, LDBObj, self.db.profile.minimapIcon)
end
end
end
function addon:PLAYER_ENTERING_WORLD()
if self.db.profile.autoExport then
-- Request updated guild roster data from the server. This will trigger "GUILD_ROSTER_UPDATE".
C_GuildInfo.GuildRoster()
end
end
function addon:GUILD_ROSTER_UPDATE()
if self.db.profile.autoExport then
self:ExportData(nil, true)
end
end
function addon:ConvertOldConfig()
self.db.profile.exportFrame.maxLetters = self.db.profile.maxLetters or self.db.profile.exportFrame.maxLetters
self.db.profile.maxLetters = nil
self.db.profile.indentation.style = self.db.profile.indentationStyle or self.db.profile.indentation.style
self.db.profile.indentation.depth = self.db.profile.spacesIndentationDepth or self.db.profile.indentation.depth
self.db.profile.indentationStyle = nil
self.db.profile.spacesIndentationDepth = nil
self.db.profile.csv.delimiter = self.db.profile.csvDelimiter or self.db.profile.csv.delimiter
self.db.profile.csv.enclosure = self.db.profile.csvEnclosure or self.db.profile.csv.enclosure
self.db.profile.csvDelimiter = nil
self.db.profile.csvEnclosure = nil
self.db.profile.json.minify = self.db.profile.jsonMinify or self.db.profile.json.minify
self.db.profile.jsonMinify = nil
self.db.profile.xml.rootElementName = self.db.profile.xmlRootElementName or self.db.profile.xml.rootElementName
self.db.profile.xml.recordElementName = self.db.profile.xmlRecordElementName or self.db.profile.xml.recordElementName
self.db.profile.xml.minify = self.db.profile.xmlMinify or self.db.profile.xml.minify
self.db.profile.xmlRootElementName = nil
self.db.profile.xmlRecordElementName = nil
self.db.profile.xmlMinify = nil
self.db.profile.yaml.minify = self.db.profile.yamlMinify or self.db.profile.yaml.minify
self.db.profile.yaml.quotationMark = self.db.profile.yamlQuotationMark or self.db.profile.yaml.quotationMark
self.db.profile.yamlMinify = nil
self.db.profile.yamlQuotationMark = nil
end
function addon:UpdateConfigs()
self:ConvertOldConfig()
-- Reset the auto export save. Don't want that when changing profile.
self.db.autoExportSave = nil
if LDB and LDBIcon then
LDBIcon:Refresh(addonName, self.db.profile.minimapIcon)
end
LibStub("AceConfigRegistry-3.0"):NotifyChange(addonName)
self.exportFrame:ClearAllPoints()
self.exportFrame:SetPoint(unpack(self.db.profile.exportFrame.position))
self.exportFrame:SetSize(unpack(self.db.profile.exportFrame.size))
end
function addon:SetupOptions()
options.plugins.profiles = { profiles = LibStub("AceDBOptions-3.0"):GetOptionsTable(self.db) }
LibStub("AceConfigRegistry-3.0"):RegisterOptionsTable(addonName, options)
-- LibStub("AceConfigDialog-3.0"):AddToBlizOptions(addonName, addonName)
end
function addon:ToggleOptions()
if self.exportFrame:IsShown() then
self.exportFrame:Hide()
end
if LibStub("AceConfigDialog-3.0").OpenFrames[addonName] then
PlaySound(sounds.closeOptions)
LibStub("AceConfigDialog-3.0"):Close(addonName)
else
insertGuildRanksIntoOptions()
PlaySound(sounds.openOptions)
LibStub("AceConfigDialog-3.0"):Open(addonName)
end
end
function addon:SystemMessageInPrimary(msg)
local color = ChatTypeInfo["SYSTEM"]
DEFAULT_CHAT_FRAME:AddMessage(msg, color.r, color.g, color.b)
end
function addon:ChatCommand(args)
local arg1, arg2 = self:GetArgs(args, 2)
arg1 = arg1 and arg1:lower()
arg2 = arg2 and arg2:lower()
if arg1 == "help" then
self:SystemMessageInPrimary(string.format("/%s - %s.", chatCommand, L["Toggle options"]))
self:SystemMessageInPrimary(string.format("/%s help - %s.", chatCommand, L["Print this help"]))
self:SystemMessageInPrimary(string.format("/%s export [%s] - %s.", chatCommand, L["file format"], L["Do an export"]))
self:SystemMessageInPrimary(L["Supported file formats:"])
local tmp = {}
for k in pairs(supportedFileFormats) do
table.insert(tmp, k)
end
table.sort(tmp)
for _,fileFormat in ipairs(tmp) do
self:SystemMessageInPrimary(string.format(" - %s", fileFormat))
end
elseif arg1 == "export" then
LibStub("AceConfigDialog-3.0"):Close(addonName);
if supportedFileFormats[arg2] then
self:ExportData(arg2)
else
self:ExportData()
end
else
self:ToggleOptions()
end
end
function addon:ExportData(fileFormat, saveToDB)
fileFormat = fileFormat or self.db.profile.fileFormat
local ranks = self.db.profile.ranks
local columns = self.db.profile.columns
local removeRealmFromName = self.db.profile.removeRealmFromName
local adjustRankIndex = self.db.profile.adjustRankIndex
local lastOnlineHours = self.db.profile.lastOnlineHours
local roster = {}
local serverTimeInfo = date("*t",GetServerTime())
local currentTime = time({day=serverTimeInfo.day, month=serverTimeInfo.month, year=serverTimeInfo.year, hour=serverTimeInfo.hour})
for i=1, GetNumGuildMembers() do
local row = { GetGuildRosterInfo(i) }
local lastOnline = currentTime
local yearsOffline, monthsOffline, daysOffline, hoursOffline = GetGuildRosterLastOnline(i)
if hoursOffline then
local dateInfo = date("*t",currentTime-(hoursOffline * 3600 + daysOffline * 86400))
local year = dateInfo.year - yearsOffline
local month = dateInfo.month - monthsOffline
local day = dateInfo.day
if month <= 0 then
year = year - 1
month = month + 12
end
lastOnline = time({day=day,month=month,year=year,hour=dateInfo.hour})
end
lastOnline = lastOnlineHours and ((currentTime-lastOnline)/3600) or lastOnline
table.insert(row, lastOnline)
local rankIndex = row[3] + 1
if ranks[rankIndex] then
for k, v in pairs(row) do
if not columns[k].enabled then
row[k] = nil
else
if removeRealmFromName and k == 1 then
row[k] = row[k]:gsub("-.+","")
end
if adjustRankIndex and k == 3 then
row[k] = rankIndex
end
end
end
table.insert(roster, row)
end
end
--[[
Doing the function call to the export function via a table key, so we can use the value of "fileFormat" to determine which function to use.
This lets us easily add more export functions. All that is needed is to add the file format to "supportedFileFormats".
]]--
if saveToDB then
self.db.profile.autoExportSave = self[fileFormat](self, roster)
else
self.exportFrame.text:SetMaxLetters(self.db.profile.exportFrame.maxLetters)
self.exportFrame.text:SetText("") -- Clear the edit box else SetMaxLetters is ignored if the edit box has been filled once before
-- Set the text in the export window's EditBox and display it.
self.exportFrame.text:SetText(self[fileFormat](self, roster))
self.exportFrame.text:HighlightText()
self.exportFrame:Show()
end
end
local function getTabSub(n)
local str = ""
for i=1, n do
str = str .. " "
end
return str
end
function addon:csv(data)
local enclosure = self.db.profile.csv.enclosure
local delimiter = self.db.profile.csv.delimiter
local header = self.db.profile.csv.header
local columns = self.db.profile.columns
local output = ""
if header then
local headerData = {}
for _, v in ipairs(columns) do
if v.enabled then
table.insert(headerData, v.name)
end
end
data[0] = headerData
end
for i=header and 0 or 1, #data do
local line = ""
for _, c in pairs(data[i]) do
if (type(c) == "string") then
c = c:gsub(enclosure, enclosure..enclosure)
end
if type(c) == "boolean" then
c = tostring(c)
end
line = string.format("%1$s%2$s%4$s%2$s%3$s", line, enclosure, delimiter, c)
end
-- Add the line to the output. The last delimiter character is removed.
output = string.format("%1$s%2$s\n", output, line:sub(1,-2))
end
return output:sub(1,-2)
end
function addon:html(data)
local columns = self.db.profile.columns
local indentationStyle = self.db.profile.indentation.style
local indentationDepth = self.db.profile.indentation.depth
local header = self.db.profile.html.tableHeader
local minify = self.db.profile.html.minify
local wp = self.db.profile.html.wp.enabled
local wpStripedStyle = self.db.profile.html.wp.stripedStyle
local wpFixedWidth = self.db.profile.html.wp.fixedWidth
local thead = ""
local tbody = ""
local output = ""
if header then
for _, v in ipairs(columns) do
if v.enabled then
thead = string.format("%s\t\t\t<th>%s</th>\n", thead, v.name)
end
end
thead = string.format("\t<thead>\n\t\t<tr>\n%s\t\t</tr>\n\t</thead>\n",thead)
end
for _, v in pairs(data) do
local cells = ""
for _, c in pairs(v) do
if type(c) == "string" then
c = c:gsub("&", '&')
c = c:gsub("<", '<')
c = c:gsub(">", '>')
end
if type(c) == "boolean" then
c = tostring(c)
end
cells = string.format("%s\t\t\t<td>%s</td>\n", cells, c)
end
-- Add the block of cells to the body as a row.
tbody = string.format("%s\n\t\t<tr>\n%s\t\t</tr>", tbody, cells)
end
output = string.format('<table%s>\n%s\t<tbody>%s\n\t</tbody>\n</table>', (wp and wpFixedWidth) and ' class="has-fixed-layout"' or "", thead, tbody)
if minify or wp then
output = output:gsub("\t", "")
output = output:gsub("\n", "")
elseif indentationStyle == "spaces" then
local tabSub = getTabSub(indentationDepth)
output = output:gsub("\t", tabSub)
end
if wp then
local attributes = ""
if wpStripedStyle or wpFixedWidth then
local tmp = {}
table.insert(tmp, wpFixedWidth and '"hasFixedLayout":true' or nil)
table.insert(tmp, wpStripedStyle and '"className":"is-style-stripes"' or nil)
attributes = string.format(" {%s}", table.concat(tmp, ","))
end
output = string.format('<!-- wp:table%s -->\n<figure class="wp-block-table%s">%s</figure>\n<!-- /wp:table -->', attributes, wpStripedStyle and " is-style-stripes" or "", output)
end
return output
end
function addon:json(data)
local columns = self.db.profile.columns
local indentationStyle = self.db.profile.indentation.style
local indentationDepth = self.db.profile.indentation.depth
local minify = self.db.profile.json.minify
local output = ""
for _, v in pairs(data) do
local lines = ""
for k, c in pairs(v) do
if (type(c) == "string") then
c = c:gsub('\\', '\\\\')
c = c:gsub('"', '\\"')
c = string.format('"%s"',c)
end
if type(c) == "boolean" then
c = tostring(c)
end
if minify then
lines = string.format("%1$s\"%2$s\":%3$s,", lines, columns[k].name, c)
else
lines = string.format("%1$s\n\t\t\"%2$s\": %3$s,", lines, columns[k].name, c)