Quantcast

Localize upgrading saved variables to the files providing the options.

Johnny C. Lam [12-18-14 - 10:48]
Localize upgrading saved variables to the files providing the options.
Filename
DataBroker.lua
Debug.lua
Options.lua
Profiler.lua
Scripts.lua
SimulationCraft.lua
SpellFlash.lua
diff --git a/DataBroker.lua b/DataBroker.lua
index a04cfce..0e5fd4b 100644
--- a/DataBroker.lua
+++ b/DataBroker.lua
@@ -72,6 +72,7 @@ do
 	for k, v in pairs(options) do
 		OvaleOptions.options.args.apparence.args[k] = v
 	end
+	OvaleOptions:RegisterOptions(OvaleDataBroker)
 end
 --</private-static-properties>

diff --git a/Debug.lua b/Debug.lua
index 4eb1811..df4194c 100644
--- a/Debug.lua
+++ b/Debug.lua
@@ -54,6 +54,7 @@ do
 	-- Add a global data type for debug options.
 	OvaleOptions.defaultDB.global = OvaleOptions.defaultDB.global or {}
 	OvaleOptions.defaultDB.global.debug = {}
+	OvaleOptions:RegisterOptions(OvaleDebug)
 end
 --</private-static-properties>

@@ -254,4 +255,47 @@ function OvaleDebug:DisplayTraceLog()
 	end
 	self_traceLog:Display()
 end
+
+do
+	local NEW_DEBUG_NAMES = {
+		action_bar = "OvaleActionBar",
+		aura = "OvaleAura",
+		combo_points = "OvaleComboPoints",
+		compile = "OvaleCompile",
+		damage_taken = "OvaleDamageTaken",
+		enemy = "OvaleEnemies",
+		guid = "OvaleGUID",
+		missing_spells = false,
+		paper_doll = "OvalePaperDoll",
+		power = "OvalePower",
+		snapshot = false,
+		spellbook = "OvaleSpellBook",
+		state = "OvaleState",
+		steady_focus = "OvaleSteadyFocus",
+		unknown_spells = false,
+	}
+
+	function OvaleDebug:UpgradeSavedVariables()
+		local global = Ovale.db.global
+		local profile = Ovale.db.profile
+
+		-- All profile-specific debug options are removed.  They are now in the global database.
+		profile.debug = nil
+
+		-- Debugging options have changed names.
+		for old, new in pairs(NEW_DEBUG_NAMES) do
+			if global.debug[old] and new then
+				global.debug[new] = global.debug[old]
+			end
+			global.debug[old] = nil
+		end
+
+		-- If a debug option is toggled off, it is "stored" as nil, not "false".
+		for k, v in pairs(global.debug) do
+			if not v then
+				global.debug[k] = nil
+			end
+		end
+	end
+end
 --</public-static-methods>
diff --git a/Options.lua b/Options.lua
index 0e45043..c152ab0 100644
--- a/Options.lua
+++ b/Options.lua
@@ -15,13 +15,18 @@ local AceConfig = LibStub("AceConfig-3.0")
 local AceConfigDialog = LibStub("AceConfigDialog-3.0")
 local L = Ovale.L

+local ipairs = ipairs
 local pairs = pairs
+local tinsert = table.insert
 local type = type
 local API_InterfaceOptionsFrame_OpenToCategory = InterfaceOptionsFrame_OpenToCategory
 local API_UnitClass = UnitClass

 -- Player's class.
 local _, self_class = API_UnitClass("player")
+
+-- List of registered modules providing options.
+local self_register = {}
 --</private-static-properties>

 --<public-static-properties>
@@ -445,6 +450,8 @@ function OvaleOptions:OnInitialize()
 	db.RegisterCallback( self, "OnProfileCopied", "HandleProfileChanges" )

 	Ovale.db = db
+
+	-- Upgrade saved variables to current format.
 	self:UpgradeSavedVariables()

 	AceConfig:RegisterOptionsTable(OVALE, self.options.args.apparence)
@@ -460,71 +467,36 @@ function OvaleOptions:OnEnable()
 	self:HandleProfileChanges()
 end

-do
-	local NEW_DEBUG_NAMES = {
-		action_bar = "OvaleActionBar",
-		aura = "OvaleAura",
-		combo_points = "OvaleComboPoints",
-		compile = "OvaleCompile",
-		damage_taken = "OvaleDamageTaken",
-		enemy = "OvaleEnemies",
-		guid = "OvaleGUID",
-		missing_spells = false,
-		paper_doll = "OvalePaperDoll",
-		power = "OvalePower",
-		snapshot = false,
-		spellbook = "OvaleSpellBook",
-		state = "OvaleState",
-		steady_focus = "OvaleSteadyFocus",
-		unknown_spells = false,
-	}
-
-	function OvaleOptions:UpgradeSavedVariables()
-		local global = Ovale.db.global
-		local profile = Ovale.db.profile
-
-		-- All profile-specific debug options are removed.  They are now in the global database.
-		profile.debug = nil
-
-		-- Debugging options have changed names.
-		for old, new in pairs(NEW_DEBUG_NAMES) do
-			if global.debug[old] and new then
-				global.debug[new] = global.debug[old]
-			end
-			global.debug[old] = nil
-		end
+function OvaleOptions:RegisterOptions(addon)
+	tinsert(self_register, addon)
+end

-		-- If a debug option is toggled off, it is "stored" as nil, not "false".
-		for k, v in pairs(global.debug) do
-			if not v then
-				global.debug[k] = nil
-			end
-		end
+function OvaleOptions:UpgradeSavedVariables()
+	local profile = Ovale.db.profile

-		-- Merge two options that had the same meaning.
-		if profile.display ~= nil then
-			profile.apparence.enableIcons = profile.display
-			profile.display = nil
-		end
+	-- Merge two options that had the same meaning.
+	if profile.display ~= nil and type(profile.display) == "boolean" then
+		profile.apparence.enableIcons = profile.display
+		profile.display = nil
+	end

-		-- The frame position settings changed from left/top to offsetX/offsetY.
-		if profile.left or profile.top then
-			profile.left = nil
-			profile.top = nil
-			Ovale:OneTimeMessage("The Ovale icon frames position has been reset.")
-		end
+	-- The frame position settings changed from left/top to offsetX/offsetY.
+	if profile.left or profile.top then
+		profile.left = nil
+		profile.top = nil
+		Ovale:OneTimeMessage("The Ovale icon frames position has been reset.")
+	end

-		-- SpellFlash options have been moved and renamed.
-		if profile.apparence.spellFlash and type(profile.apparence.spellFlash) ~= "table" then
-			local enabled = profile.apparence.spellFlash
-			profile.apparence.spellFlash = {}
-			profile.apparence.spellFlash.enabled = enabled
+	-- Invoke module-specific upgrade for Saved Variables.
+	for _, addon in ipairs(self_register) do
+		if addon.UpgradeSavedVariables then
+			addon:UpgradeSavedVariables()
 		end
-
-		-- Re-register defaults so that any tables created during the upgrade are "populated"
-		-- by the default database automatically.
-		Ovale.db:RegisterDefaults(self.defaultDB)
 	end
+
+	-- Re-register defaults so that any tables created during the upgrade are "populated"
+	-- by the default database automatically.
+	Ovale.db:RegisterDefaults(self.defaultDB)
 end

 function OvaleOptions:HandleProfileChanges()
diff --git a/Profiler.lua b/Profiler.lua
index d9e8ae5..f79558b 100644
--- a/Profiler.lua
+++ b/Profiler.lua
@@ -58,6 +58,7 @@ do
 	-- Add a global data type for debug options.
 	OvaleOptions.defaultDB.global = OvaleOptions.defaultDB.global or {}
 	OvaleOptions.defaultDB.global.profiler = {}
+	OvaleOptions:RegisterOptions(OvaleProfiler)
 end
 --</private-static-properties>

diff --git a/Scripts.lua b/Scripts.lua
index 3dc6c62..348f634 100644
--- a/Scripts.lua
+++ b/Scripts.lua
@@ -46,6 +46,7 @@ do
 	for k, v in pairs(actions) do
 		OvaleOptions.options.args.actions.args[k] = v
 	end
+	OvaleOptions:RegisterOptions(OvaleScripts)
 end
 --</private-static-properties>

diff --git a/SimulationCraft.lua b/SimulationCraft.lua
index 0c58550..e3caf25 100644
--- a/SimulationCraft.lua
+++ b/SimulationCraft.lua
@@ -232,6 +232,7 @@ do
 	for k, v in pairs(actions) do
 		OvaleOptions.options.args.actions.args[k] = v
 	end
+	OvaleOptions:RegisterOptions(OvaleSimulationCraft)
 end
 --</private-static-properties>

diff --git a/SpellFlash.lua b/SpellFlash.lua
index 667ccd8..b1d56ff 100644
--- a/SpellFlash.lua
+++ b/SpellFlash.lua
@@ -18,6 +18,7 @@ local OvaleSpellBook = nil
 local OvaleStance = nil

 local pairs = pairs
+local type = type
 local API_UnitHasVehicleUI = UnitHasVehicleUI
 local API_UnitExists = UnitExists
 local API_UnitIsDead = UnitIsDead
@@ -211,6 +212,7 @@ do
 	for k, v in pairs(options) do
 		OvaleOptions.options.args.apparence.args[k] = v
 	end
+	OvaleOptions:RegisterOptions(OvaleSpellFlash)
 end
 --</private-static-properties>

@@ -336,4 +338,15 @@ function OvaleSpellFlash:Flash(state, node, element, start, now)
 		end
 	end
 end
+
+function OvaleSpellFlash:UpgradeSavedVariables()
+	local profile = Ovale.db.profile
+
+	-- SpellFlash options have been moved and renamed.
+	if profile.apparence.spellFlash and type(profile.apparence.spellFlash) ~= "table" then
+		local enabled = profile.apparence.spellFlash
+		profile.apparence.spellFlash = {}
+		profile.apparence.spellFlash.enabled = enabled
+	end
+end
 --</public-static-methods>