Create a frame for exporting and importing
This commit is contained in:
126
Actions.lua
126
Actions.lua
@@ -36,7 +36,8 @@ local pickupActionButton = {
|
|||||||
spell = PickupSpell,
|
spell = PickupSpell,
|
||||||
macro = PickupMacro,
|
macro = PickupMacro,
|
||||||
companion = PickupSpell,
|
companion = PickupSpell,
|
||||||
equipmentset = PickupEquipmentSet
|
equipmentset = PickupEquipmentSet,
|
||||||
|
summonmount = C_MountJournal.Pickup
|
||||||
}
|
}
|
||||||
|
|
||||||
local function RestoreActionButton(self, index, actionButton)
|
local function RestoreActionButton(self, index, actionButton)
|
||||||
@@ -295,6 +296,85 @@ local function Partition(text, size, deliminer)
|
|||||||
return ret
|
return ret
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@param table table
|
||||||
|
---@param depth number?
|
||||||
|
function DumpTable(table, depth)
|
||||||
|
if depth == nil then
|
||||||
|
depth = 0
|
||||||
|
end
|
||||||
|
if (depth > 200) then
|
||||||
|
print("Error: Depth > 200 in dumpTable()")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
for k, v in pairs(table) do
|
||||||
|
if (type(v) == "table") then
|
||||||
|
print(string.rep(" ", depth) .. k .. ":")
|
||||||
|
DumpTable(v, depth + 1)
|
||||||
|
else
|
||||||
|
print(string.rep(" ", depth) .. k .. ": ", v)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local importingSet = nil
|
||||||
|
local importExportFrame = CreateFrame("Frame", "ABSImportExportFrame", UIParent)
|
||||||
|
importExportFrame:SetSize(512, 512)
|
||||||
|
importExportFrame:SetPoint("CENTER")
|
||||||
|
importExportFrame:SetFrameStrata("HIGH")
|
||||||
|
importExportFrame:EnableMouse(true)
|
||||||
|
importExportFrame:SetMovable(true)
|
||||||
|
importExportFrame:SetResizable(false)
|
||||||
|
importExportFrame:SetBackdrop({
|
||||||
|
bgFile = "Interface/Tooltips/UI-Tooltip-Background",
|
||||||
|
edgeFile = "Interface/Tooltips/UI-Tooltip-Border",
|
||||||
|
tile = true,
|
||||||
|
tileSize = 4,
|
||||||
|
edgeSize = 4,
|
||||||
|
insets = {
|
||||||
|
left = 4,
|
||||||
|
right = 4,
|
||||||
|
top = 4,
|
||||||
|
bottom = 4
|
||||||
|
}
|
||||||
|
})
|
||||||
|
importExportFrame:SetBackdropColor(0, 0, 0, 0.8)
|
||||||
|
importExportFrame:SetBackdropBorderColor(0.5, 0.5, 0.5, 1)
|
||||||
|
|
||||||
|
importExportFrame:SetMovable(true)
|
||||||
|
importExportFrame:EnableMouse(true)
|
||||||
|
importExportFrame:RegisterForDrag("LeftButton")
|
||||||
|
importExportFrame:SetScript("OnDragStart", function(self)
|
||||||
|
self:StartMoving()
|
||||||
|
end)
|
||||||
|
importExportFrame:SetScript("OnDragStop", function(self)
|
||||||
|
self:StopMovingOrSizing()
|
||||||
|
end)
|
||||||
|
importExportFrame:SetScript("OnShow", function(self)
|
||||||
|
self:SetScale(1)
|
||||||
|
end)
|
||||||
|
importExportFrame:Hide()
|
||||||
|
|
||||||
|
local importExportFrameTextBox = CreateFrame("EditBox", "ABSImportExportFrameTextBox", importExportFrame)
|
||||||
|
importExportFrameTextBox:SetSize(512, 512)
|
||||||
|
importExportFrameTextBox:SetPoint("TOPLEFT", importExportFrame, "TOPLEFT", 0, 0)
|
||||||
|
importExportFrameTextBox:SetFont("Fonts\\FRIZQT__.ttf", 12)
|
||||||
|
importExportFrameTextBox:SetTextColor(1, 1, 1, 1)
|
||||||
|
importExportFrameTextBox:SetTextInsets(20, 20, 20, 20)
|
||||||
|
importExportFrameTextBox:SetMultiLine(true)
|
||||||
|
importExportFrameTextBox:SetAutoFocus(true)
|
||||||
|
importExportFrameTextBox:SetMaxLetters(1000000)
|
||||||
|
importExportFrameTextBox:SetScript("OnEscapePressed", function(self)
|
||||||
|
importExportFrame:Hide()
|
||||||
|
if importingSet then
|
||||||
|
local lines = {strsplit("\n", self:GetText())}
|
||||||
|
print("Importing set " .. importingSet)
|
||||||
|
print(self:GetText())
|
||||||
|
DumpTable(lines)
|
||||||
|
-- ImportSet(importingSet, self:GetText())
|
||||||
|
importingSet = nil
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
function ExportSet(setName)
|
function ExportSet(setName)
|
||||||
local set = ActionBarSaverReloaded.sets[setName]
|
local set = ActionBarSaverReloaded.sets[setName]
|
||||||
if not set then
|
if not set then
|
||||||
@@ -318,18 +398,16 @@ function ExportSet(setName)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local exported = {table.concat(stringified, "ž")}
|
||||||
for name, macro in pairs(macros) do
|
for name, macro in pairs(macros) do
|
||||||
local content = B64.Encode(macro)
|
local content = B64.Encode(macro)
|
||||||
local cpartitions = Partition(content, 160, "|")
|
exported[#exported + 1] = string.format("Mž%sž%dž%s", name, idx, content)
|
||||||
for partitionIndex, partition in ipairs(cpartitions) do
|
|
||||||
print(string.format("M|%s|%d|%s", name, partitionIndex, partition))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
local str = table.concat(stringified, "|")
|
|
||||||
local partitions = Partition(str, 200, "|")
|
|
||||||
for _, partition in ipairs(partitions) do
|
|
||||||
print(partition)
|
|
||||||
end
|
end
|
||||||
|
local str = table.concat(exported, "\n")
|
||||||
|
importExportFrame:Show()
|
||||||
|
importExportFrameTextBox:SetText(str)
|
||||||
|
importExportFrameTextBox:SetFocus()
|
||||||
end
|
end
|
||||||
|
|
||||||
local function ParseAction(action)
|
local function ParseAction(action)
|
||||||
@@ -367,11 +445,37 @@ local function ParseAction(action)
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local macroParts = {}
|
||||||
function ImportSet(setName, str)
|
function ImportSet(setName, str)
|
||||||
if not setName or setName == "" then
|
if not setName or setName == "" then
|
||||||
print("Must provide a valid set name")
|
print("Must provide a valid set name")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if string.find(setName, "^Mž") then
|
||||||
|
setName = strtrim(setName)
|
||||||
|
local name, index, content = string.match(setName, "^Mž([^ž]+)ž([^ž]+)ž([^ž]+)")
|
||||||
|
if not name or not index or not content then
|
||||||
|
print("Error: Invalid macro part format")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
content = strtrim(content)
|
||||||
|
name = strtrim(name)
|
||||||
|
index = tonumber(index)
|
||||||
|
macroParts[name] = macroParts[name] or {}
|
||||||
|
macroParts[name][index] = content
|
||||||
|
|
||||||
|
local reconstructed = table.concat(macroParts[name], "")
|
||||||
|
reconstructed = B64.Decode(reconstructed)
|
||||||
|
|
||||||
|
local macroIdx = GetMacroIndexByName(name)
|
||||||
|
if macroIdx == 0 then
|
||||||
|
macroIdx = CreateMacro(name, "Interface\\Icons\\INV_Misc_Note_01", "")
|
||||||
|
end
|
||||||
|
EditMacro(macroIdx, name, nil, reconstructed)
|
||||||
|
print(string.format("Imported macro '%s' with index %d and content '%s'", name, macroIdx, reconstructed))
|
||||||
|
return
|
||||||
|
end
|
||||||
local set = ActionBarSaverReloaded.sets[setName] or {}
|
local set = ActionBarSaverReloaded.sets[setName] or {}
|
||||||
-- if set then
|
-- if set then
|
||||||
-- print(string.format("Set '%s' already exists", setName))
|
-- print(string.format("Set '%s' already exists", setName))
|
||||||
@@ -379,7 +483,7 @@ function ImportSet(setName, str)
|
|||||||
-- end
|
-- end
|
||||||
|
|
||||||
str = strtrim(str)
|
str = strtrim(str)
|
||||||
local data = {strsplit("|", str)}
|
local data = {strsplit("ž", str)}
|
||||||
for _, action in ipairs(data) do
|
for _, action in ipairs(data) do
|
||||||
local paction = ParseAction(action)
|
local paction = ParseAction(action)
|
||||||
if paction then
|
if paction then
|
||||||
|
13
B64.lua
13
B64.lua
@@ -1,5 +1,9 @@
|
|||||||
if not B64 then B64 = {} end
|
if not B64 then
|
||||||
local encode, decode = {}, { [strbyte("=")] = false }
|
B64 = {}
|
||||||
|
end
|
||||||
|
local encode, decode = {}, {
|
||||||
|
[strbyte("=")] = false
|
||||||
|
}
|
||||||
for value = 0, 63 do
|
for value = 0, 63 do
|
||||||
local char = strsub('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/', value + 1, value + 1)
|
local char = strsub('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/', value + 1, value + 1)
|
||||||
encode[value] = char
|
encode[value] = char
|
||||||
@@ -20,8 +24,11 @@ function B64.Encode(str)
|
|||||||
return table.concat(t, "", 1, j - 1)
|
return table.concat(t, "", 1, j - 1)
|
||||||
end
|
end
|
||||||
|
|
||||||
function B64Decode(str)
|
function B64.Decode(str)
|
||||||
local j = 1
|
local j = 1
|
||||||
|
if strlen(str) % 4 ~= 0 then
|
||||||
|
str = str .. string.rep("=", 4 - strlen(str) % 4)
|
||||||
|
end
|
||||||
assert(strlen(str) % 4 == 0, format("invalid data length: %d", strlen(str)))
|
assert(strlen(str) % 4 == 0, format("invalid data length: %d", strlen(str)))
|
||||||
for i = 1, strlen(str), 4 do
|
for i = 1, strlen(str), 4 do
|
||||||
local ba, bb, bc, bd = strbyte(str, i, i + 3)
|
local ba, bb, bc, bd = strbyte(str, i, i + 3)
|
||||||
|
Reference in New Issue
Block a user