-
Notifications
You must be signed in to change notification settings - Fork 6
/
WowSimsExporter.lua
102 lines (84 loc) · 3.8 KB
/
WowSimsExporter.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
-- Author : generalwrex (Natop on Myzrael TBC)
-- Create Date : 1/28/2022 9:30:08 AM
--
-- Update Date : 2023-04-16 Riotdog-GehennasEU: v2.5 - exporting bag items for bulk sim, fixes use of legacy APIs in libs and corrects link order (LibStub must come first).
-- Update Date : 2024-02-04 coolmodi(FelixPflaum) v2.6 - Added rune exporting and split the addon for classic/wotlk
-- Update Date : 2024-02-04 generalwrex (Natop on Old Blanchy) v2.6 - Minor fixes and version change
local addonName, Env = ...
local LibParse = LibStub("LibParse")
local WowSimsExporter = LibStub("AceAddon-3.0"):NewAddon("WowSimsExporter", "AceConsole-3.0", "AceEvent-3.0")
local defaults = {
profile = {},
}
local options = {
name = addonName,
handler = WowSimsExporter,
type = "group",
args = {
openExporterButton = {
type = "execute",
name = "Open Exporter Window",
desc = "Opens the exporter window",
func = function() WowSimsExporter:OpenWindow() end
},
},
}
function WowSimsExporter:OnInitialize()
self.db = LibStub("AceDB-3.0"):New("WSEDB", defaults, true)
LibStub("AceConfig-3.0"):RegisterOptionsTable("WowSimsExporter", options)
self.optionsFrame = LibStub("AceConfigDialog-3.0"):AddToBlizOptions("WowSimsExporter", "WowSimsExporter")
local profiles = LibStub("AceDBOptions-3.0"):GetOptionsTable(self.db)
LibStub("AceConfig-3.0"):RegisterOptionsTable("WowSimsExporter_Profiles", profiles)
LibStub("AceConfigDialog-3.0"):AddToBlizOptions("WowSimsExporter_Profiles", "Profiles", "WowSimsExporter")
self:RegisterChatCommand("wse", "OpenWindow")
self:RegisterChatCommand("wowsimsexporter", "OpenWindow")
self:RegisterChatCommand("wsexporter", "OpenWindow")
Env.UI:CreateCharacterPanelButton(options.args.openExporterButton.func)
self:Print(addonName .. " " .. Env.VERSION .. " Initialized. use /wse For Window.")
if not Env.IS_CLIENT_SUPPORTED then
self:Print("WARNING: Sim does not support your game version! Supported versions are:\n" ..
table.concat(Env.supportedClientNames, "\n"))
end
end
function WowSimsExporter:OpenWindow(input)
if not input or input:trim() == "" then
self:CreateWindow()
elseif (input == "export") then
self:CreateWindow(true)
elseif (input == "options") then
InterfaceOptionsFrame_OpenToCategory(self.optionsFrame)
InterfaceOptionsFrame_OpenToCategory(self.optionsFrame)
end
end
local function GenerateOutput(character, exportBags)
character:FillForExport()
return LibParse:JSONEncode(character)
end
local function GenerateOutputBags()
local equipmentSpecBags = Env.CreateEquipmentSpec()
equipmentSpecBags:FillFromBagItems()
DEFAULT_CHAT_FRAME:AddMessage(("[|cffFFFF00WowSimsExporter|r] Exported %d items from bags."):format(#
equipmentSpecBags.items))
return LibParse:JSONEncode(equipmentSpecBags)
end
function WowSimsExporter:CreateWindow(generate)
local character = Env.CreateCharacter()
character:SetUnit("player")
local classIsSupported = table.contains(Env.supportedClasses, character.class)
local linkToSim = Env.prelink .. select(2, Env.GetSpec("player"))
Env.UI:CreateMainWindow(classIsSupported, linkToSim)
if not classIsSupported then return end
if generate then Env.UI:SetOutput(GenerateOutput(character)) end
end
Env.UI:SetOutputGenerator(function()
local character = Env.CreateCharacter()
character:SetUnit("player")
local output = GenerateOutput(character)
return output
end)
Env.UI:SetOutputGeneratorBags(function()
local character = Env.CreateCharacter()
character:SetUnit("player")
local output = GenerateOutputBags()
return output
end)