diff --git a/README.md b/README.md index b806c2a..c0fcdd9 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,10 @@ NotGrid is a party and raid frame addon for Vanilla World of Warcraft (1.12.1). Use */notgrid* or */ng* to show the config menu. Use */notgrid grid* to generate a style similar to the original grid. Use */notgrid reset* to restore the default settings. +Use */notgrid profile save * to save current settings as a profile (account-wide). +Use */notgrid profile load * to load a saved profile (account-wide). +Use */notgrid profile delete * to delete a saved profile (account-wide). +Use */notgrid profile list* to show all available profiles (account-wide). Use / for separating multiple Buffs/Debuffs to track on one icon. Use */ngcast spellname(Rank X)* in macros for mouseover casting. diff --git a/core.lua b/core.lua index affc2a8..785ff89 100644 --- a/core.lua +++ b/core.lua @@ -1,6 +1,7 @@ local L = AceLibrary("AceLocale-2.2"):new("NotGrid") NotGrid = AceLibrary("AceAddon-2.0"):new("AceEvent-2.0") NotGridOptions = {} -- After the addon is fully initialized WoW will fill this up with its saved variables if any +-- NotGridProfiles will be initialized safely in OnEnable after saved variables are loaded function NotGrid:OnInitialize() self.HealComm = AceLibrary("HealComm-1.0") @@ -20,6 +21,11 @@ function NotGrid:OnInitialize() end function NotGrid:OnEnable() + -- Initialize profiles after saved variables are loaded + if not NotGridProfiles then + NotGridProfiles = {} + end + self.o = NotGridOptions -- Need to wait for addon to be fully initialized and saved variables loaded before I set this self:SetDefaultOptions() -- if NotGridOptions is empty(no saved variables) this will fill it up with defaults self:DoDropDown() diff --git a/notgrid.toc b/notgrid.toc index 546ef94..9fbed1d 100644 --- a/notgrid.toc +++ b/notgrid.toc @@ -3,6 +3,7 @@ ## Notes: It's Not Grid ## Notes-ruRU: Это не Grid ## SavedVariablesPerCharacter: NotGridOptions +## SavedVariables: NotGridProfiles Libs\AceLibrary\AceLibrary.lua Libs\AceLocale-2.2\AceLocale-2.2.lua diff --git a/options.lua b/options.lua index 4acddb9..72c9464 100644 --- a/options.lua +++ b/options.lua @@ -1,5 +1,20 @@ local L = AceLibrary("AceLocale-2.2"):new("NotGrid") +local function deepcopy(orig) + local orig_type = type(orig) + local copy + if orig_type == 'table' then + copy = {} + for orig_key, orig_value in next, orig, nil do + copy[deepcopy(orig_key)] = deepcopy(orig_value) + end + setmetatable(copy, deepcopy(getmetatable(orig))) + else -- number, string, boolean, function + copy = orig + end + return copy +end + local DefaultOptions = { ["version"] = 1.132, -- will be the commit number from now on. ["versionchecking"] = true, @@ -159,6 +174,91 @@ function SlashCmdList.NOTGRID(msg, editbox) NotGrid.o.colorunithealthbarbyclass = false NotGrid.o.colorunithealthbarbgbyclass = true ReloadUI() + elseif type(msg) == "string" and string.find(msg, "^profile") then + local _, args = string.match(msg, "^(profile)%s*(.*)") + local action = "list" + local profileName = nil + + if args and args ~= "" then + local words = {} + for word in string.gmatch(args, "%S+") do + table.insert(words, word) + end + + if words[1] then + action = words[1] + profileName = words[2] + end + end + + if action == "save" then + if profileName then + -- Validate that profiles table exists before saving + if not NotGridProfiles then + DEFAULT_CHAT_FRAME:AddMessage("NotGrid: Error - Profile system not initialized!") + return + end + NotGridProfiles[profileName] = deepcopy(NotGrid.o) + DEFAULT_CHAT_FRAME:AddMessage("NotGrid profile '" .. profileName .. "' saved.") + else + DEFAULT_CHAT_FRAME:AddMessage("Usage: /ng profile save ") + end + elseif action == "load" then + if profileName then + -- Validate that profiles table exists before loading + if not NotGridProfiles then + DEFAULT_CHAT_FRAME:AddMessage("NotGrid: Error - Profile system not initialized!") + return + end + if NotGridProfiles[profileName] then + for k in pairs(NotGrid.o) do NotGrid.o[k] = nil end + for k, v in pairs(NotGridProfiles[profileName]) do NotGrid.o[k] = deepcopy(v) end + NotGrid:SetDefaultOptions() + ReloadUI() + DEFAULT_CHAT_FRAME:AddMessage("NotGrid profile '" .. profileName .. "' loaded.") + else + DEFAULT_CHAT_FRAME:AddMessage("NotGrid profile '" .. profileName .. "' not found.") + end + else + DEFAULT_CHAT_FRAME:AddMessage("Usage: /ng profile load ") + end + elseif action == "delete" then + if profileName then + -- Validate that profiles table exists before deleting + if not NotGridProfiles then + DEFAULT_CHAT_FRAME:AddMessage("NotGrid: Error - Profile system not initialized!") + return + end + if NotGridProfiles[profileName] then + NotGridProfiles[profileName] = nil + DEFAULT_CHAT_FRAME:AddMessage("NotGrid profile '" .. profileName .. "' deleted.") + else + DEFAULT_CHAT_FRAME:AddMessage("NotGrid profile '" .. profileName .. "' not found.") + end + else + DEFAULT_CHAT_FRAME:AddMessage("Usage: /ng profile delete ") + end + elseif action == "list" then + -- Validate that profiles table exists before listing + if not NotGridProfiles then + DEFAULT_CHAT_FRAME:AddMessage("NotGrid: Error - Profile system not initialized!") + return + end + local profileCount = 0 + local profileList = "" + for name in pairs(NotGridProfiles) do + if profileList ~= "" then profileList = profileList .. ", " end + profileList = profileList .. name + profileCount = profileCount + 1 + end + if profileCount > 0 then + DEFAULT_CHAT_FRAME:AddMessage("Available NotGrid profiles: " .. profileList) + else + DEFAULT_CHAT_FRAME:AddMessage("No NotGrid profiles saved.") + end + else + DEFAULT_CHAT_FRAME:AddMessage("Invalid profile action. Usage: /ng profile [save|load|delete ] or /ng profile list") + end else NotGridOptionsMenu:Show() end