From c98bf227d2eaaf20149eecf0a5e2b5e2795be2b7 Mon Sep 17 00:00:00 2001 From: Hendrik Leppkes Date: Mon, 26 Aug 2024 21:27:22 +0200 Subject: [PATCH] AceDB-3.0: Handle unloaded namespaces in Reset/Copy/Delete functions When applying profile changes to namespaces, we should also handle namespaces that are not currently loaded. These may be from optional Load-on-Demand parts that are not currently loaded, but the expectation is that the database behaves consistent no matter what is currently active. --- AceDB-3.0/AceDB-3.0.lua | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/AceDB-3.0/AceDB-3.0.lua b/AceDB-3.0/AceDB-3.0.lua index e9c98c1..a0a8936 100644 --- a/AceDB-3.0/AceDB-3.0.lua +++ b/AceDB-3.0/AceDB-3.0.lua @@ -41,7 +41,7 @@ -- @class file -- @name AceDB-3.0.lua -- @release $Id$ -local ACEDB_MAJOR, ACEDB_MINOR = "AceDB-3.0", 29 +local ACEDB_MAJOR, ACEDB_MINOR = "AceDB-3.0", 30 local AceDB = LibStub:NewLibrary(ACEDB_MAJOR, ACEDB_MINOR) if not AceDB then return end -- No upgrade needed @@ -525,6 +525,17 @@ function DBObjectLib:DeleteProfile(name, silent) end end + -- remove from unloaded namespaces + if self.sv.namespaces then + for nsname, data in pairs(self.sv.namespaces) do + if self.children and self.children[nsname] then + -- already a mapped namespace + elseif data.profiles then + data.profiles[name] = nil + end + end + end + -- switch all characters that use this profile back to the default if self.sv.profileKeys then for key, profile in pairs(self.sv.profileKeys) do @@ -570,6 +581,20 @@ function DBObjectLib:CopyProfile(name, silent) end end + -- copy unloaded namespaces + if self.sv.namespaces then + for nsname, data in pairs(self.sv.namespaces) do + if self.children and self.children[nsname] then + -- already a mapped namespace + elseif data.profiles then + -- reset the current profile + data.profiles[self.keys.profile] = {} + -- copy data + copyTable(data.profiles[name], data.profiles[self.keys.profile]) + end + end + end + -- Callback: OnProfileCopied, database, sourceProfileKey self.callbacks:Fire("OnProfileCopied", self, name) end @@ -596,6 +621,18 @@ function DBObjectLib:ResetProfile(noChildren, noCallbacks) end end + -- reset unloaded namespaces + if self.sv.namespaces and not noChildren then + for nsname, data in pairs(self.sv.namespaces) do + if self.children and self.children[nsname] then + -- already a mapped namespace + elseif data.profiles then + -- reset the current profile + data.profiles[self.keys.profile] = nil + end + end + end + -- Callback: OnProfileReset, database if not noCallbacks then self.callbacks:Fire("OnProfileReset", self)