diff core.lua @ 99:966d06c8d9c9

- Brought plugin handling code up to date. SVs are kept in DB namespaces like they should have been. - Removed/commented all datarev code, until it becomes necessary after MoP. - Textgen special blocks for plugins do not automatically get a "reset&reload" button anymore. - New method to register option pages on the main tab. No sub-entry pages supported yet. Titles and reset&reload added here instead.
author Farmbuyer of US-Kilrogg <farmbuyer@gmail.com>
date Sun, 29 Jul 2012 23:12:18 +0000
parents b5a55c69ef67
children a57133ee3c9b
line wrap: on
line diff
--- a/core.lua	Fri Jul 27 19:09:29 2012 +0000
+++ b/core.lua	Sun Jul 29 23:12:18 2012 +0000
@@ -109,8 +109,8 @@
 ------ Constants
 local RAID_ROSTER_UPDATE_EVENT =
 	(select(4,GetBuildInfo()) >= 50000) and 'GROUP_ROSTER_UPDATE' or 'RAID_ROSTER_UPDATE'
-local option_defaults = {
-	['datarev'] = 20,    -- cheating, this isn't actually an option
+local option_defaults = { profile = {
+	--['datarev'] = 20,    -- cheating, this isn't actually an option
 	['popup_on_join'] = true,
 	['register_slash_synonyms'] = false,
 	['slash_synonyms'] = '/ol,/oloot',
@@ -137,7 +137,7 @@
 	['chatty_on_remote_changes_frame'] = 1,
 	['itemfilter'] = {},
 	['itemvault'] = {},
-}
+} }
 local virgin = "First time loaded?  Hi!  Use the /ouroloot command"
 	.." to show the main display.  You should probably browse the instructions"
 	.." if you've never used this before; %s to display the help window.  This"
@@ -154,6 +154,7 @@
 	..[[|cffffff00to see what can be done by software alone.  You may still]]
 	..[[ need to do a "/reload" afterwards, or even restart the game client.]]
 local unique_collision = "Item '%s' was carrying unique tag <%s>, but that was already in use; tried to generate a new tag and failed!|n|nRemote sender was '%s', previous cache entry was <%s/%s>.|n|nThis may require a live human to figure out; the loot in question has not been stored."
+local new_profile_warning = [[Be aware that profiles only store addon & plugin settings from the <Options> tab; loot and generated text is account-wide data, unrelated to your current profile.]]
 local remote_chatty = "|cff00ff00%s|r changed %d/%s from %s to %s"
 local qualnames = {
 	['gray'] = 0, ['grey'] = 0, ['poor'] = 0, ['trash'] = 0,
@@ -730,8 +731,10 @@
 	else
 		virgin = nil
 	end
-	self.db = _G.LibStub("AceDB-3.0"):New("OuroLootOptsDB",
-		{ profile = option_defaults } , --[[Default=]]true)
+	self.db = _G.LibStub("AceDB-3.0"):New("OuroLootOptsDB", option_defaults , --[[Default=]]true)
+	self.db.RegisterCallback (self, "OnNewProfile", function()
+		self:Print(new_profile_warning)
+	end)
 	self.db.RegisterCallback (self, "OnProfileChanged", "DBProfileRefresh")
 	self.db.RegisterCallback (self, "OnProfileCopied", "DBProfileRefresh")
 	self.db.RegisterCallback (self, "OnProfileReset", "DBProfileRefresh")
@@ -954,6 +957,15 @@
 --function addon:OnDisable() end
 
 do
+	--[[
+	Module support (aka plugins).  Field names with special meanings:
+	- option_defaults:  (IN) Standard AceDB-style table.  Use a profiles key!
+	- db:  (OUT) AceDB object, set during init.
+	- opts:  (OUT) Pointer to plugin's "db.profile" subtable.
+
+	OnInitialize, [default_]OnEnable, register_text_generator, register_tab_control
+	are all inherited.
+	]]
 	local prototype = {}
 	local registry
 
@@ -976,27 +988,35 @@
 		end
 	end
 
-	local function module_OnEnable (plugin)
+	local function module_OnInit (plugin)
 		if plugin.option_defaults then
-			local SVname = 'OuroLoot'..plugin:GetName()..'_opts'
-			if not _G[SVname] then
-				_G[SVname] = {}
-				if type(plugin.OnFirstTime) == 'function' then
-					plugin:OnFirstTime()
-				end
-			end
-			plugin.opts = _G[SVname]
-			for option,default in pairs(plugin.option_defaults) do
-				if plugin.opts[option] == nil then
-					plugin.opts[option] = default
-				end
-			end
-			plugin.option_defaults = nil
+			plugin.db = addon.db:RegisterNamespace (plugin.moduleName, plugin.option_defaults)
+			plugin.opts = plugin.db.profile
+			--plugin:SetEnabledState(plugin.db.profile.enabled)  if that flag is needed later
 		end
 	end
 
+	local function module_OnEnable (plugin)
+	end
+
+	local function module_GetOption (plugin, info)
+		local name = info[#info]
+		return plugin.db.profile[name]
+	end
+	local function module_SetOption (plugin, info, value)
+		local name = info[#info]
+		plugin.db.profile[name] = value
+		local arg = info.arg
+		if type(arg) == 'function' then
+			plugin[arg](plugin,info)
+		end
+	end
+
+	prototype.OnInitialize = module_OnInit
 	prototype.OnEnable = module_OnEnable
 	prototype.default_OnEnable = module_OnEnable
+	prototype.GetOption = module_GetOption
+	prototype.SetOption = module_SetOption
 
 	addon:SetDefaultModuleLibraries("AceConsole-3.0")
 	addon:SetDefaultModulePrototype(prototype)
@@ -1014,11 +1034,11 @@
 					"commrev "..self.commrev.." older than minimum "..mincomm)
 				return false
 			end
-			if mindata and tonumber(mindata) > opts.datarev then
+			--[[if mindata and tonumber(mindata) > opts.datarev then
 				self:Print(err,modname,
 					"datarev "..opts.datarev.." older than minimum "..mindata)
 				return false
-			end
+			end]]
 		end
 		return self:NewModule(modname)
 	end