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,
|
||||
macro = PickupMacro,
|
||||
companion = PickupSpell,
|
||||
equipmentset = PickupEquipmentSet
|
||||
equipmentset = PickupEquipmentSet,
|
||||
summonmount = C_MountJournal.Pickup
|
||||
}
|
||||
|
||||
local function RestoreActionButton(self, index, actionButton)
|
||||
@@ -295,6 +296,85 @@ local function Partition(text, size, deliminer)
|
||||
return ret
|
||||
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)
|
||||
local set = ActionBarSaverReloaded.sets[setName]
|
||||
if not set then
|
||||
@@ -318,18 +398,16 @@ function ExportSet(setName)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local exported = {table.concat(stringified, "ž")}
|
||||
for name, macro in pairs(macros) do
|
||||
local content = B64.Encode(macro)
|
||||
local cpartitions = Partition(content, 160, "|")
|
||||
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)
|
||||
exported[#exported + 1] = string.format("Mž%sž%dž%s", name, idx, content)
|
||||
end
|
||||
local str = table.concat(exported, "\n")
|
||||
importExportFrame:Show()
|
||||
importExportFrameTextBox:SetText(str)
|
||||
importExportFrameTextBox:SetFocus()
|
||||
end
|
||||
|
||||
local function ParseAction(action)
|
||||
@@ -367,11 +445,37 @@ local function ParseAction(action)
|
||||
}
|
||||
end
|
||||
|
||||
local macroParts = {}
|
||||
function ImportSet(setName, str)
|
||||
if not setName or setName == "" then
|
||||
print("Must provide a valid set name")
|
||||
return
|
||||
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 {}
|
||||
-- if set then
|
||||
-- print(string.format("Set '%s' already exists", setName))
|
||||
@@ -379,7 +483,7 @@ function ImportSet(setName, str)
|
||||
-- end
|
||||
|
||||
str = strtrim(str)
|
||||
local data = {strsplit("|", str)}
|
||||
local data = {strsplit("ž", str)}
|
||||
for _, action in ipairs(data) do
|
||||
local paction = ParseAction(action)
|
||||
if paction then
|
||||
|
69
B64.lua
69
B64.lua
@@ -1,39 +1,46 @@
|
||||
if not B64 then B64 = {} end
|
||||
local encode, decode = {}, { [strbyte("=")] = false }
|
||||
if not B64 then
|
||||
B64 = {}
|
||||
end
|
||||
local encode, decode = {}, {
|
||||
[strbyte("=")] = false
|
||||
}
|
||||
for value = 0, 63 do
|
||||
local char = strsub('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/', value+1, value+1)
|
||||
encode[value] = char
|
||||
decode[strbyte(char)] = value
|
||||
local char = strsub('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/', value + 1, value + 1)
|
||||
encode[value] = char
|
||||
decode[strbyte(char)] = value
|
||||
end
|
||||
|
||||
local t = {}
|
||||
function B64.Encode(str)
|
||||
local j = 1
|
||||
for i = 1, strlen(str), 3 do
|
||||
local a, b, c = strbyte(str, i, i+2)
|
||||
t[j] = encode[bit.rshift(a, 2)]
|
||||
t[j+1] = encode[bit.band(bit.lshift(a, 4) + bit.rshift(b or 0, 4), 0x3F)]
|
||||
t[j+2] = b and encode[bit.band(bit.lshift(b, 2) + bit.rshift(c or 0, 6), 0x3F)] or "="
|
||||
t[j+3] = c and encode[bit.band(c, 0x3F)] or "="
|
||||
j = j + 4
|
||||
end
|
||||
return table.concat(t, "", 1, j-1)
|
||||
local j = 1
|
||||
for i = 1, strlen(str), 3 do
|
||||
local a, b, c = strbyte(str, i, i + 2)
|
||||
t[j] = encode[bit.rshift(a, 2)]
|
||||
t[j + 1] = encode[bit.band(bit.lshift(a, 4) + bit.rshift(b or 0, 4), 0x3F)]
|
||||
t[j + 2] = b and encode[bit.band(bit.lshift(b, 2) + bit.rshift(c or 0, 6), 0x3F)] or "="
|
||||
t[j + 3] = c and encode[bit.band(c, 0x3F)] or "="
|
||||
j = j + 4
|
||||
end
|
||||
return table.concat(t, "", 1, j - 1)
|
||||
end
|
||||
|
||||
function B64Decode(str)
|
||||
local j = 1
|
||||
assert(strlen(str) % 4 == 0, format("invalid data length: %d", strlen(str)))
|
||||
for i = 1, strlen(str), 4 do
|
||||
local ba, bb, bc, bd = strbyte(str, i, i+3)
|
||||
local a, b, c, d = decode[ba], decode[bb], decode[bc], decode[bd]
|
||||
assert(a ~= nil, format("invalid data at position %d: '%s'", i, ba))
|
||||
assert(b ~= nil, format("invalid data at position %d: '%s'", i+1, bb))
|
||||
assert(c ~= nil, format("invalid data at position %d: '%s'", i+2, bc))
|
||||
assert(d ~= nil, format("invalid data at position %d: '%s'", i+3, bd))
|
||||
t[j] = strchar(bit.lshift(a, 2) + bit.rshift(b, 4))
|
||||
t[j+1] = c and strchar(bit.band(bit.lshift(b, 4) + bit.rshift(c, 2), 0xFF)) or ""
|
||||
t[j+2] = d and strchar(bit.band(bit.lshift(c, 6) + d, 0xFF)) or ""
|
||||
j = j + 3
|
||||
end
|
||||
return table.concat(t, "", 1, j-1)
|
||||
function B64.Decode(str)
|
||||
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)))
|
||||
for i = 1, strlen(str), 4 do
|
||||
local ba, bb, bc, bd = strbyte(str, i, i + 3)
|
||||
local a, b, c, d = decode[ba], decode[bb], decode[bc], decode[bd]
|
||||
assert(a ~= nil, format("invalid data at position %d: '%s'", i, ba))
|
||||
assert(b ~= nil, format("invalid data at position %d: '%s'", i + 1, bb))
|
||||
assert(c ~= nil, format("invalid data at position %d: '%s'", i + 2, bc))
|
||||
assert(d ~= nil, format("invalid data at position %d: '%s'", i + 3, bd))
|
||||
t[j] = strchar(bit.lshift(a, 2) + bit.rshift(b, 4))
|
||||
t[j + 1] = c and strchar(bit.band(bit.lshift(b, 4) + bit.rshift(c, 2), 0xFF)) or ""
|
||||
t[j + 2] = d and strchar(bit.band(bit.lshift(c, 6) + d, 0xFF)) or ""
|
||||
j = j + 3
|
||||
end
|
||||
return table.concat(t, "", 1, j - 1)
|
||||
end
|
||||
|
Reference in New Issue
Block a user