-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathExportImport.lua
More file actions
112 lines (102 loc) · 3.83 KB
/
ExportImport.lua
File metadata and controls
112 lines (102 loc) · 3.83 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
---@type string, AddonTable
local addonName, addonTable = ...
local ReforgeLite = addonTable.ReforgeLite
local FRAME_NAME = addonName .. "ExportImport"
local L = addonTable.L
local print = addonTable.print
local firstInitialize
local function GetDataFrame(anchor)
if _G[FRAME_NAME] then
_G[FRAME_NAME]:Hide()
end
local AceGUI = LibStub("AceGUI-3.0")
local displayFrame = AceGUI:Create("Frame")
displayFrame:SetLayout("Flow")
displayFrame:SetStatusTable({ width = 525, height = 275 })
if anchor then
displayFrame:ClearAllPoints()
displayFrame:SetPoint("CENTER", anchor, "CENTER")
end
displayFrame:SetCallback("OnClose", function(widget)
AceGUI:Release(widget)
_G[FRAME_NAME] = nil
end)
displayFrame:SetCallback("OnEnterStatusBar", function(widget)
if widget.statustext:IsTruncated() then
GameTooltip:SetOwner(widget.statustext, "ANCHOR_LEFT")
GameTooltip:AddLine(widget.statustext:GetText())
GameTooltip:Show()
end
end)
displayFrame:SetCallback("OnLeaveStatusBar", GameTooltip_Hide)
local editbox = AceGUI:Create("MultiLineEditBox")
editbox:SetFullWidth(true)
editbox:SetFullHeight(true)
displayFrame:AddChild(editbox)
if not firstInitialize then
tinsert(UISpecialFrames, FRAME_NAME)
firstInitialize = true
end
_G[FRAME_NAME] = displayFrame
return displayFrame, editbox
end
function ReforgeLite:DisplayMessage(message, name, copyOnly)
local frame, editBox = GetDataFrame(self)
frame:SetTitle(L["Export"])
frame:SetStatusText(name or "")
editBox:DisableButton(true)
editBox:SetLabel()
editBox:SetText(message)
if copyOnly then
frame.status.message = message
editBox.editBox:SetFocus()
editBox.editBox:HighlightText()
editBox:SetCallback("OnLeave", function(widget) widget.editBox:HighlightText() widget:SetFocus() end)
editBox:SetCallback("OnEnter", function(widget) widget.editBox:HighlightText() widget:SetFocus() end)
editBox:SetCallback("OnTextChanged", function(widget) widget.editBox:SetText(widget.parent.status.message) widget.editBox:HighlightText() end)
end
end
function ReforgeLite:DebugMethod()
self:DisplayMessage(C_EncodingUtil.SerializeJSON(addonTable.methodDebug or {nty="<3"}), C_AddOns.GetAddOnMetadata(addonName, "X-Website"), true)
end
function ReforgeLite:PrintLog()
self:DisplayMessage(table.concat(addonTable.printLog, "\n"), "Print Log")
end
function ReforgeLite:ExportJSON(preset, name)
self:DisplayMessage(C_EncodingUtil.SerializeJSON(preset), name, true)
end
function ReforgeLite:ImportData(anchor)
self:Initialize()
self:UpdateItems()
local frame, editBox = GetDataFrame(not anchor and self)
frame:SetTitle(L["Import"])
if anchor then
frame:ClearAllPoints()
frame:SetPoint("TOP", anchor, "TOP")
end
editBox:SetLabel(L["Enter WoWSims JSON or Pawn string"])
editBox.editBox:SetFocus()
local function ParseUserInput(widget)
local userInput = widget:GetText()
if not userInput or userInput == "" then
widget.parent:SetStatusText("")
return
end
local validWoWSims, wowsims = self:ValidateWoWSimsString(userInput)
if validWoWSims then
self:ApplyWoWSimsImport(wowsims)
widget.parent:Hide()
return
end
local validPawn, pawn = self:ValidatePawnString(userInput)
if pawn then
self:ParsePawnString(pawn)
widget.parent:Hide()
print(L["Pawn successfully imported."])
return
end
widget.parent:SetStatusText(wowsims or ERROR_CAPS)
end
editBox.button:SetScript("OnClick", function(btn) ParseUserInput(btn.obj) end)
editBox:SetCallback("OnTextChanged", ParseUserInput)
end