Quantcast

Allow for additional CHAT_MSG_ADDON messages than the Ovale score.

Johnny C. Lam [06-04-14 - 20:23]
Allow for additional CHAT_MSG_ADDON messages than the Ovale score.

This changes the score messages in an incompatible way with previous
releases of Ovale.

git-svn-id: svn://svn.curseforge.net/wow/ovale/mainline/trunk@1514 d5049fe3-3747-40f7-a4b5-f36d6801af5f
Filename
.pkgmeta
Ovale.lua
OvaleScore.lua
embeds.xml
diff --git a/.pkgmeta b/.pkgmeta
index 080ca2e..2ad1858 100644
--- a/.pkgmeta
+++ b/.pkgmeta
@@ -9,6 +9,7 @@ externals:
     Libs/AceEvent-3.0: svn://svn.wowace.com/wow/ace3/mainline/trunk/AceEvent-3.0
     Libs/AceGUI-3.0: svn://svn.wowace.com/wow/ace3/mainline/trunk/AceGUI-3.0
     Libs/AceLocale-3.0: svn://svn.wowace.com/wow/ace3/mainline/trunk/AceLocale-3.0
+    Libs/AceSerializer-3.0: svn://svn.wowace.com/wow/ace3/mainline/trunk/AceSerializer-3.0
     Libs/AceTimer-3.0: svn://svn.wowace.com/wow/ace3/mainline/trunk/AceTimer-3.0
     Libs/CallbackHandler-1.0: svn://svn.wowace.com/wow/ace3/mainline/trunk/CallbackHandler-1.0
     Libs/LibBabble-CreatureType-3.0: svn://svn.wowace.com/wow/libbabble-creaturetype-3-0/mainline/trunk
diff --git a/Ovale.lua b/Ovale.lua
index 0d32e01..fdcf6e6 100644
--- a/Ovale.lua
+++ b/Ovale.lua
@@ -21,6 +21,7 @@ local select = select
 local tostring = tostring
 local wipe = table.wipe
 local API_GetTime = GetTime
+local API_RegisterAddonMessagePrefix = RegisterAddonMessagePrefix
 local API_UnitCanAttack = UnitCanAttack
 local API_UnitExists = UnitExists
 local API_UnitHasVehicleUI = UnitHasVehicleUI
@@ -29,6 +30,9 @@ local API_UnitIsDead = UnitIsDead
 local OVALE_FALSE_STRING = tostring(false)
 local OVALE_NIL_STRING = tostring(nil)
 local OVALE_TRUE_STRING = tostring(true)
+
+-- Addon message prefix.
+local OVALE_MSG_PREFIX = addonName
 --</private-static-properties>

 --<public-static-properties>
@@ -81,10 +85,14 @@ end
 --</private-static-methods>

 --<public-static-methods>
-function Ovale:OnEnable()
-    -- Called when the addon is enabled
+function Ovale:OnInitialize()
+	-- Resolve module dependencies.
 	OvaleOptions = self:GetModule("OvaleOptions")
+	-- Register message prefix for the addon.
+	API_RegisterAddonMessagePrefix(OVALE_MSG_PREFIX)
+end

+function Ovale:OnEnable()
 	self:RegisterEvent("PLAYER_REGEN_ENABLED")
 	self:RegisterEvent("PLAYER_REGEN_DISABLED")
 	self:RegisterEvent("PLAYER_TARGET_CHANGED")
@@ -94,7 +102,6 @@ function Ovale:OnEnable()
 end

 function Ovale:OnDisable()
-    -- Called when the addon is disabled
 	self:UnregisterEvent("PLAYER_REGEN_ENABLED")
 	self:UnregisterEvent("PLAYER_REGEN_DISABLED")
 	self:UnregisterEvent("PLAYER_TARGET_CHANGED")
diff --git a/OvaleScore.lua b/OvaleScore.lua
index 5d9924e..8c3921b 100644
--- a/OvaleScore.lua
+++ b/OvaleScore.lua
@@ -29,24 +29,25 @@
 ]]--

 local addonName, Ovale = ...
-local OvaleScore = Ovale:NewModule("OvaleScore", "AceEvent-3.0")
+local OvaleScore = Ovale:NewModule("OvaleScore", "AceEvent-3.0", "AceSerializer-3.0")
 Ovale.OvaleScore = OvaleScore

 --<private-static-properties>
 local pairs = pairs
 local strsplit = string.split
-local API_RegisterAddonMessagePrefix = RegisterAddonMessagePrefix
+local API_IsInGroup = IsInGroup
 local API_SendAddonMessage = SendAddonMessage
 local API_UnitGUID = UnitGUID
 local API_UnitName = UnitName
+local LE_PARTY_CATEGORY_INSTANCE = LE_PARTY_CATEGORY_INSTANCE

 -- Player's GUID.
 local self_guid = nil
 -- Player's name.
 local self_name = nil

--- Message prefix.
-local MSG_PREFIX = addonName
+-- Addon message prefix.
+local OVALE_MSG_PREFIX = addonName
 --</private-static-properties>

 --<public-static-properties>
@@ -66,7 +67,6 @@ OvaleScore.scoredSpell = {}
 function OvaleScore:OnEnable()
 	self_guid = API_UnitGUID("player")
 	self_name = API_UnitName("player")
-	API_RegisterAddonMessagePrefix(MSG_PREFIX)
 	self:RegisterEvent("CHAT_MSG_ADDON")
 	self:RegisterEvent("PLAYER_REGEN_ENABLED")
 	self:RegisterEvent("PLAYER_REGEN_DISABLED")
@@ -81,19 +81,21 @@ end
 -- Receive scores for damage meters from other Ovale addons in the raid.
 function OvaleScore:CHAT_MSG_ADDON(event, ...)
 	local prefix, message, channel, sender = ...
-	if prefix ~= MSG_PREFIX then return end
-	if channel ~= "RAID" and channel ~= "PARTY" then return end
-
-	local scored, scoreMax, guid = strsplit(";", message)
-	self:SendScore(sender, guid, scored, scoreMax)
+	if prefix == OVALE_MSG_PREFIX then
+		local ok, msgType, scored, scoreMax, guid = self:Deserialize(message)
+		if ok and msgType == "S" then
+			self:SendScore(sender, guid, scored, scoreMax)
+		end
+	end
 end

 function OvaleScore:PLAYER_REGEN_ENABLED()
 	-- Broadcast the player's own score for damage meters when combat ends.
 	-- Broadcast message is "score;maxScore;playerGUID"
-	if self.maxScore > 0 then
-		local message = self.score .. ";" .. self.maxScore .. ";" .. self_guid
-		API_SendAddonMessage(MSG_PREFIX, message, "RAID")
+	if self.maxScore > 0 and API_IsInGroup() then
+		local message = self:Serialize("score", self,score, self.maxScore, self_guid)
+		local channel = API_IsInGroup(LE_PARTY_CATEGORY_INSTANCE) and "INSTANCE_CHAT" or "RAID"
+		API_SendAddonMessage(OVALE_MSG_PREFIX, message, channel)
 	end
 end

diff --git a/embeds.xml b/embeds.xml
index c342e2e..e071fd3 100644
--- a/embeds.xml
+++ b/embeds.xml
@@ -11,6 +11,7 @@
   <Include file="Libs\AceEvent-3.0\AceEvent-3.0.xml" />
   <Include file="Libs\AceGUI-3.0\AceGUI-3.0.xml" />
   <Include file="Libs\AceConfig-3.0\AceConfig-3.0.xml" />
+  <Include file="Libs\AceSerializer-3.0\AceSerializer-3.0.xml" />
   <Include file="Libs\AceTimer-3.0\AceTimer-3.0.xml" />
   <Include file="Libs\LibBabble-CreatureType-3.0\lib.xml" />
   <Include file="Libs\LibDispellable-1.0\LibDispellable-1.0.lua" />