diff ReagentMaker.lua @ 17:5336b3a19d4f

Throttle the scanning to avoid freezing wow
author contrebasse
date Fri, 08 Apr 2011 01:01:00 +0200
parents cc56799582f2
children c37c2a46723c
line wrap: on
line diff
--- a/ReagentMaker.lua	Wed Apr 06 00:32:00 2011 +0200
+++ b/ReagentMaker.lua	Fri Apr 08 01:01:00 2011 +0200
@@ -27,8 +27,14 @@
 ---------------------------------------------------
 A.EventsFrame = CreateFrame("Frame")
 
-A.EventsFrame:SetScript("OnEvent", function(self, event, ...)
-	if event == "TRADE_SKILL_UPDATE" then
+local SCAN_DELAY = 0.2
+local t_throttle = SCAN_DELAY
+local function throttleScan(self, t_elapsed)
+	t_throttle = t_throttle - t_elapsed
+	if t_throttle<0 then
+		self:SetScript("OnUpdate", nil)
+		print("go")
+		
 		-- Close the external window if the tradeskill changed
 		if A.currentTradeSkill ~= GetTradeSkillLine() then
 			A.MenuFrame:Hide()
@@ -41,12 +47,30 @@
 
 		-- Scan availabe recipes
 		A:ScanSimpleRecipes()
+	end
+end
+A.EventsFrame:SetScript("OnEvent", function(self, event)
+	print(self,event)
+	if event == "TRADE_SKILL_UPDATE" then
+		t_throttle = SCAN_DELAY
+		self:SetScript("OnUpdate", throttleScan)
+		
+		--[[
+		-- Close the external window if the tradeskill changed
+		if A.currentTradeSkill ~= GetTradeSkillLine() then
+			A.MenuFrame:Hide()
+		end
 
-	elseif event == "TRADE_SKILL_SHOW" then
 		if IsTradeSkillGuild() or IsTradeSkillLinked() then
 			A.MenuFrame:Hide()
 			return
 		end
+
+		-- Scan availabe recipes
+		A:ScanSimpleRecipes()
+		--]]
+
+	elseif event == "TRADE_SKILL_SHOW" then
 		A:Initialize()
 		A.EventsFrame:UnregisterEvent("TRADE_SKILL_SHOW")
 	end -- if