Quantcast

Simplify handling the user clicking on the broker

KyrosKrane [06-06-18 - 23:22]
Simplify handling the user clicking on the broker
Filename
Broker_RaidMakeup.lua
diff --git a/Broker_RaidMakeup.lua b/Broker_RaidMakeup.lua
index d6d9f74..f64c24f 100644
--- a/Broker_RaidMakeup.lua
+++ b/Broker_RaidMakeup.lua
@@ -436,6 +436,41 @@ function BRM:UpdateComposition()
 end -- BRM:UpdateComposition()


+-- This function handles refreshing the role counts and checking for count errors
+function BRM:RefreshCounts()
+	-- I'm trying to capture which situations don't result in an automatic update.
+	-- That essentially indicates either an event I missed coding for, or some kind of bug that resulted in invalid role counts.
+	local old_TankCount = BRM.TankCount
+	local old_HealerCount = BRM.HealerCount
+	local old_DPSCount = BRM.DPSCount
+	local old_UnknownCount = BRM.UnknownCount
+	local old_TotalCount = BRM.TotalCount
+
+	-- Refresh the counts
+	BRM:UpdateComposition()
+
+	-- Check if the counts changed, indicating the error above.
+	if old_TankCount ~= BRM.TankCount
+		or old_HealerCount ~= BRM.HealerCount
+		or old_DPSCount ~= BRM.DPSCount
+		or old_UnknownCount ~= BRM.UnknownCount
+		or old_TotalCount ~= BRM.TotalCount
+		then
+			BRM:DebugPrint("Counts are different after click.")
+			BRM:DebugPrint("old_TankCount is "		.. (old_TankCount		or "nil") .. ", new TankCount is "		.. (BRM.TankCount		or "nil"))
+			BRM:DebugPrint("old_HealerCount is "	.. (old_HealerCount		or "nil") .. ", new DPSCount is "		.. (BRM.DPSCount		or "nil"))
+			BRM:DebugPrint("old_DPSCount is "		.. (old_DPSCount		or "nil") .. ", new DPSCount is "		.. (BRM.DPSCount		or "nil"))
+			BRM:DebugPrint("old_UnknownCount is "	.. (old_UnknownCount	or "nil") .. ", new UnknownCount is "	.. (BRM.UnknownCount	or "nil"))
+			BRM:DebugPrint("old_TotalCount is "		.. (old_TotalCount		or "nil") .. ", new TotalCount is "		.. (BRM.TotalCount		or "nil"))
+
+			-- @TODO: Capture some info and give the player a way to report it.
+
+			-- Also schedule an update in five seconds to ensure we capture any additional changes
+			C_Timer.After(5, function() BRM:UpdateComposition() end)
+	end
+end -- BRM:RefreshCounts()
+
+
 --#########################################
 --# Actual LibDataBroker object
 --#########################################
@@ -465,43 +500,13 @@ function BRM.LDO:OnClick(button)

 	if button == "LeftButton" then
 		BRM:DebugPrint("Got left button")
+		BRM:RefreshCounts()
 	elseif button == "RightButton" then
 		BRM:DebugPrint("Got right button")
 	else
 		BRM:DebugPrint("Got some other button")
 	end

-	-- I'm trying to capture which situations don't result in an automatic update.
-	-- That essentially indicates either an event I missed coding for, or some kind of bug that resulted in invalid role counts.
-	local old_TankCount = BRM.TankCount
-	local old_HealerCount = BRM.HealerCount
-	local old_DPSCount = BRM.DPSCount
-	local old_UnknownCount = BRM.UnknownCount
-	local old_TotalCount = BRM.TotalCount
-
-	-- Refresh the counts
-	BRM:UpdateComposition()
-
-	-- Check if the counts changed, indicating the error above.
-	if old_TankCount ~= BRM.TankCount
-		or old_HealerCount ~= BRM.HealerCount
-		or old_DPSCount ~= BRM.DPSCount
-		or old_UnknownCount ~= BRM.UnknownCount
-		or old_TotalCount ~= BRM.TotalCount
-		then
-			BRM:DebugPrint("Counts are different after click.")
-			BRM:DebugPrint("old_TankCount is "		.. (old_TankCount		or "nil") .. ", new TankCount is "		.. (BRM.TankCount		or "nil"))
-			BRM:DebugPrint("old_HealerCount is "	.. (old_HealerCount		or "nil") .. ", new DPSCount is "		.. (BRM.DPSCount		or "nil"))
-			BRM:DebugPrint("old_DPSCount is "		.. (old_DPSCount		or "nil") .. ", new DPSCount is "		.. (BRM.DPSCount		or "nil"))
-			BRM:DebugPrint("old_UnknownCount is "	.. (old_UnknownCount	or "nil") .. ", new UnknownCount is "	.. (BRM.UnknownCount	or "nil"))
-			BRM:DebugPrint("old_TotalCount is "		.. (old_TotalCount		or "nil") .. ", new TotalCount is "		.. (BRM.TotalCount		or "nil"))
-
-			-- @TODO: Capture some info and give the player a way to report it.
-
-			-- Also schedule an update in five seconds to ensure we capture any additional changes
-			C_Timer.After(5, function() BRM:UpdateComposition() end)
-	end
-
 end -- BRM.LDO:OnClick()