Skip to content

Commit

Permalink
Added support to register&load profiles provided by other addons.
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelnpsp committed Dec 8, 2023
1 parent a554b2f commit ca0dbe3
Show file tree
Hide file tree
Showing 2 changed files with 145 additions and 85 deletions.
209 changes: 132 additions & 77 deletions database.lua
Original file line number Diff line number Diff line change
Expand Up @@ -149,83 +149,138 @@ for i=1,6 do
}
end


-- profile database maintenance operations
addon:SetupOptions( 'Profiles', 'Operations', {
newDesc = {
type = 'description',
order = 0.5,
name = "\nYou can create a new profile by entering a name in the editbox.",
},
newProfile = {
type = 'input',
name = 'New Profile Name',
order = 1,
get = function() end,
set = function(info,name)
addon:CreateNewProfile(name)
end,
validate = function(info,name)
name = strtrim(name)
return strlen(name)>2 and not addon.__db.profiles[name]
end,
},
copyDesc = {
type = 'description',
order = 1.5,
name = "\nCopy the settings from one existing profile into the currently active profile.",
},
copyProfile = {
type = 'select',
order = 2,
name = 'Copy From',
desc = "Copy the settings from one existing profile into the currently active profile.",
get = function() end,
set = function(_, key)
local profiles = addon.__db.profiles
profiles[addon.__profileKey] = addon.CopyTable( profiles[key] )
addon.__profileKey = nil
addon:PLAYER_TALENT_UPDATE()
end,
confirm = function() return "Selected profile will be copied into the current profile and current profile settings will be lost. Are you sure ?" end,
values = function()
wipe(values)
for key in pairs(addon.__db.profiles) do
if key ~= addon.__profileKey then
values[key] = key
do
local kwpLoaded
local profilesRepo
local profilesValues = { [0] = "Basic" }
local newProfileIndex

addon:SetupOptions( 'Profiles', 'Operations', {
newDesc = {
type = 'description',
order = 0.5,
name = "\nYou can create a new profile based on the selected profile template.",
},
newProfileImage = {
type = "execute",
width= "full",
order = 0.8,
name = "",
imageWidth= 512,
imageHeight= 64,
image = function() return profilesRepo[newProfileIndex].banner end,
func = function() end,
hidden = function()
if kwpLoaded==nil then
kwpLoaded = LoadAddOn("KiwiPlatesProfiles") or false
end
end
return values
end,
},
deleteDesc = {
type = 'description',
order = 2.5,
name = "\nYou can delete unused profiles from the database to save space.",
},
deleteProfile = {
type = 'select',
order = 3,
name = 'Delete Profile',
desc = "Unlisted profiles are in use by some toon and cannot be deleted.",
get = function() end,
set = function(_, key)
addon.__db.profiles[key] = nil
addon:Update()
end,
values = function()
wipe(values)
wipe(undeletable)
for _,specs in pairs(addon.__db.profileChars) do
for _,key in pairs(specs) do
undeletable[key] = true
return (newProfileIndex or 0) == 0
end,
},
newProfileTemplate = {
type = 'select',
name = 'Profile Template',
order = 0.9,
get = function()
return newProfileIndex
end,
set = function(info,v)
newProfileIndex = v
end,
values = function()
return profilesValues
end,
hidden = function() return profilesRepo == nil end,
},
newProfileName = {
type = 'input',
name = 'New Profile Name',
order = 1,
get = function() end,
set = function(info,name)
local profile = profilesRepo and profilesRepo[newProfileIndex or 0]
if profile then
local data = profile[1]
addon:ImportProfile( type(data)=='function' and data(profile.name) or data, name, true)
newProfileIndex = nil
else
addon:CreateNewProfile(name)
end
end,
validate = function(info,name)
name = strtrim(name)
return strlen(name)>2 and not addon.__db.profiles[name]
end,
hidden = function() return profilesRepo and newProfileIndex==nil end,
},
copyDesc = {
type = 'description',
order = 1.5,
name = "\nCopy the settings from one existing profile into the currently active profile.",
},
copyProfile = {
type = 'select',
order = 2,
name = 'Copy From',
desc = "Copy the settings from one existing profile into the currently active profile.",
get = function() end,
set = function(_, key)
local profiles = addon.__db.profiles
profiles[addon.__profileKey] = addon.CopyTable( profiles[key] )
addon.__profileKey = nil
addon:PLAYER_TALENT_UPDATE()
end,
confirm = function() return "Selected profile will be copied into the current profile and current profile settings will be lost. Are you sure ?" end,
values = function()
wipe(values)
for key in pairs(addon.__db.profiles) do
if key ~= addon.__profileKey then
values[key] = key
end
end
return values
end,
},
deleteDesc = {
type = 'description',
order = 2.5,
name = "\nYou can delete unused profiles from the database to save space.",
},
deleteProfile = {
type = 'select',
order = 3,
name = 'Delete Profile',
desc = "Unlisted profiles are in use by some toon and cannot be deleted.",
get = function() end,
set = function(_, key)
addon.__db.profiles[key] = nil
addon:Update()
end,
values = function()
wipe(values)
wipe(undeletable)
for _,specs in pairs(addon.__db.profileChars) do
for _,key in pairs(specs) do
undeletable[key] = true
end
end
end
for key in pairs(addon.__db.profiles) do
if not undeletable[key] then values[key] = key end
end
return values
end,
confirm = function(_,key) return "Are you sure you want to delete the selected profile?" end,
},
footer = { type = "description", order = 100, name = " " },
} )
for key in pairs(addon.__db.profiles) do
if not undeletable[key] then values[key] = key end
end
return values
end,
confirm = function(_,key) return "Are you sure you want to delete the selected profile?" end,
},
footer = { type = "description", order = 100, name = " " },
} )

function addon:RegisterProfile(data)
profilesRepo = profilesRepo or {}
profilesRepo[#profilesRepo+1] = data
profilesValues[#profilesRepo] = data.name
end

end

21 changes: 13 additions & 8 deletions expimp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,20 @@ local function Export(data)
return str
end

local function Import(str)
local function Import(str, name, silent)
local sucess, data = LibStub("AceSerializer-3.0"):Deserialize( base64decode( gsub(str,'%s','') ) )
if sucess and type(data)=='table' and data.__addonName == 'KiwiPlates' and data.__profileName then
local borders = data.__classicBorders
local name = addon:GetUniqueProfileName(data.__profileName)
name = name or addon:GetUniqueProfileName(data.__profileName)
data.__addonName, data.__profileName, data.__classicBorders = nil, nil, nil
addon:CreateNewProfile(name, data)
print("KiwiPlates, New Profile imported:", name)
if not silent then
print("KiwiPlates, New Profile imported:", name)
end
collectgarbage()
if borders and not addon.__db.global.classicBorders then
addon:ConfirmDialog("This profile uses textures for the borders, do you want to enable Blizzard Border Textures ?\nThe UI will be reloaded.", function()
addon.__db.global.classicBorders = true
ReloadUI()
end)
if not borders ~= not addon.__db.global.classicBorders then
addon.__db.global.classicBorders = borders or nil
addon:ConfirmDialog("The UI must be reloaded to activate this profile. Are your sure?", ReloadUI )
end
else
print("KiwiPlates: Error Importing Profile, Wrong Data")
Expand Down Expand Up @@ -130,3 +130,8 @@ addon:SetupOptions( 'Profiles', 'Import&Export', {
end,
},
} )

-- publish some functions

addon.ImportProfile = function(self, ...) Import(...) end
addon.ExportProfile = function(self, ...) Export(...) end

0 comments on commit ca0dbe3

Please sign in to comment.