Quantcast

Add facility to print one-time messages (per session).

Johnny C. Lam [07-13-14 - 11:32]
Add facility to print one-time messages (per session).

Use one-time messages to print warnings for scripts using deprecated
features.

git-svn-id: svn://svn.curseforge.net/wow/ovale/mainline/trunk@1550 d5049fe3-3747-40f7-a4b5-f36d6801af5f
Filename
Ovale.lua
OvaleAura.lua
OvaleCompile.lua
OvaleFrame.lua
diff --git a/Ovale.lua b/Ovale.lua
index f6aa3a4..e77b3b2 100644
--- a/Ovale.lua
+++ b/Ovale.lua
@@ -43,6 +43,8 @@ local OVALE_MSG_PREFIX = addonName
 local self_bug = false
 -- If "traced" flag is set, then the public "trace" property is toggled before the next frame refresh.
 local self_traced = false
+-- Table of strings to display once per session.
+local self_oneTimeMessage = {}
 --</private-static-properties>

 --<public-static-properties>
@@ -102,6 +104,7 @@ end

 function Ovale:OnEnable()
 	self:RegisterEvent("CHAT_MSG_ADDON")
+	self:RegisterEvent("PLAYER_ENTERING_WORLD")
 	self:RegisterEvent("PLAYER_REGEN_ENABLED")
 	self:RegisterEvent("PLAYER_REGEN_DISABLED")
 	self:RegisterEvent("PLAYER_TARGET_CHANGED")
@@ -112,6 +115,7 @@ end

 function Ovale:OnDisable()
 	self:UnregisterEvent("CHAT_MSG_ADDON")
+	self:UnregisterEvent("PLAYER_ENTERING_WORLD")
 	self:UnregisterEvent("PLAYER_REGEN_ENABLED")
 	self:UnregisterEvent("PLAYER_REGEN_DISABLED")
 	self:UnregisterEvent("PLAYER_TARGET_CHANGED")
@@ -163,6 +167,10 @@ end
 --Called when the player target change
 --Used to update the visibility e.g. if the user chose
 --to hide Ovale if a friendly unit is targeted
+function Ovale:PLAYER_ENTERING_WORLD()
+	self:ClearOneTimeMessages()
+end
+
 function Ovale:PLAYER_TARGET_CHANGED()
 	self.refreshNeeded.target = true
 	self:UpdateVisibility()
@@ -377,4 +385,24 @@ function Ovale:Logf(...)
 		self.traceLog[#self.traceLog + 1] = self:Format(...)
 	end
 end
+
+function Ovale:OneTimeMessage(...)
+	local s = Ovale:Format(...)
+	if not self_oneTimeMessage[s] then
+		self_oneTimeMessage[s] = true
+	end
+end
+
+function Ovale:ClearOneTimeMessages()
+	wipe(self_oneTimeMessage)
+end
+
+function Ovale:PrintOneTimeMessages()
+	for s in pairs(self_oneTimeMessage) do
+		if self_oneTimeMessage[s] ~= "printed" then
+			Ovale:Print(s)
+			self_oneTimeMessage[s] = "printed"
+		end
+	end
+end
 --</public-static-methods>
diff --git a/OvaleAura.lua b/OvaleAura.lua
index 4fc37cb..c5bd524 100644
--- a/OvaleAura.lua
+++ b/OvaleAura.lua
@@ -957,6 +957,7 @@ statePrototype.ApplySpellAuras = function(state, spellId, guid, startCast, endCa
 				-- Deprecated after transition.
 				if not (si and si.duration) and spellData > 0 then
 					-- Aura doesn't have duration SpellInfo(), so treat spell data as duration.
+					Ovale:OneTimeMessage("Warning: '%s=%d' is deprecated for spell ID %d; aura ID %s should have duration information.", auraId, spellData, spellId, auraId)
 					duration = spellData
 					stacks = 1
 				end
diff --git a/OvaleCompile.lua b/OvaleCompile.lua
index bb00ba8..770a144 100644
--- a/OvaleCompile.lua
+++ b/OvaleCompile.lua
@@ -108,6 +108,7 @@ local function TestConditions(parameters)
 	end
 	-- Deprecated: mastery -> specialization
 	if boolean and parameters.mastery then
+		Ovale:OneTimeMessage("Warning: 'mastery' is deprecated; use 'specialization' instead.")
 		local spec, required = RequireValue(parameters.mastery)
 		local isSpec = OvalePaperDoll:IsSpecialization(spec)
 		boolean = (required and isSpec) or (not required and not isSpec)
@@ -147,6 +148,7 @@ local function TestConditions(parameters)
 		end
 		-- Deprecated: checkboxon
 		if boolean and parameters.checkboxon then
+			Ovale:OneTimeMessage("Warning: 'checkboxon=name' is deprecated; use 'checkbox=name' instead.")
 			-- Flag this checkbox as triggering a script evaluation.
 			local name = parameters.checkboxon
 			local checkBox = Ovale.casesACocher[name] or {}
@@ -158,6 +160,7 @@ local function TestConditions(parameters)
 		end
 		-- Deprecated: checkboxoff
 		if boolean and parameters.checkboxoff then
+			Ovale:OneTimeMessage("Warning: 'checkboxoff=name' is deprecated; use 'checkbox=!name' instead.")
 			-- Flag this checkbox as triggering a script evaluation.
 			local name = parameters.checkboxon
 			local checkBox = Ovale.casesACocher[name] or {}
diff --git a/OvaleFrame.lua b/OvaleFrame.lua
index 58df1e3..1fbd443 100644
--- a/OvaleFrame.lua
+++ b/OvaleFrame.lua
@@ -282,6 +282,7 @@ do

 		wipe(Ovale.refreshNeeded)
 		Ovale:PostRefresh()
+		Ovale:PrintOneTimeMessages()
 	end

 	local function UpdateIcons(self)