Quantcast

Minor code cleanup

Erik L. Vonderscheer [07-18-09 - 04:22]
Minor code cleanup
Added AceTimer lib for repeat function table recycling
Filename
.pkgmeta
Docs/changelog.txt
Docs/main.txt
TradeFilter3.lua
TradeFilter3.toc
TradeFilter3Options.lua
diff --git a/.pkgmeta b/.pkgmeta
index fee2ff9..e8370b4 100644
--- a/.pkgmeta
+++ b/.pkgmeta
@@ -40,6 +40,9 @@ externals:
  libs/AceGUI-3.0:
   url: svn://svn.wowace.com/wow/ace3/mainline/trunk/AceGUI-3.0
   tag: latest
+ libs/AceTimer-3.0:
+  url: svn://svn.wowace.com/wow/ace3/mainline/trunk/AceTimer-3.0
+  tag: latest
  libs/AceAddon-3.0:
   url: svn://svn.wowace.com/wow/ace3/mainline/trunk/AceAddon-3.0
   tag: latest
diff --git a/Docs/changelog.txt b/Docs/changelog.txt
index 3f65086..614dffe 100644
--- a/Docs/changelog.txt
+++ b/Docs/changelog.txt
@@ -1,4 +1,7 @@
 == ChangeLog
+*r148
+**++Minor code cleanup++\\
+**++AceTimer lib added for repeat table recycling++\\
 *r145
 **++Rewrite on DB functions, Repeat Function and Friends functions++\\
 **++Show repeat count with ability to reset count++\\
diff --git a/Docs/main.txt b/Docs/main.txt
index cd91fd7..2df0294 100644
--- a/Docs/main.txt
+++ b/Docs/main.txt
@@ -35,10 +35,10 @@ lfg,
 Adding a set, e.g. [xXyY], will attempt to find a match for any character given in a set. Example: lf[wWeEmM] will match for lfw, lfe and lfm.

 === Black and White Lists
-TradeFilter also has a build in Black and White list. A sentence, or "string". that contains a black list match will cease to be checked any more and be filtered out completely. A string found that contains a white list match will also cease to be checked and will be allowed to passed un-filtered.
+TradeFilter also has a built in Black and White list. Refer to the {{http://www.wowace.com/addons/trade-filter/#w-filtering-priorities|Filtering Priorities}} for how Black and White lists are checked.

 === Filtering Priorities
-{{http://static.wowace.com/uploads/19/16/157/TradeFilter_Flowchart.png}}
+{{http://static.wowace.com/uploads/19/16/173/TradeFilter_Flowchart.png}}

 === Configuration
 <<code php>>/tf or /filter<</code>>
@@ -51,8 +51,8 @@ Nothing planned

 === Supported Translations
 //Please help localize this project// [[http://www.wowace.com/projects/trade-filter/localization/|HERE]]\\
-German - 92.1%\\
-French - 64.9%\\
-Simplified Chinese - 43%\\
-Traditional Chinese - 22.8%\\
-Korean - 19.3%\\
+German - 97.4%\\
+French - 63.2%\\
+Simplified Chinese - 41.9%\\
+Traditional Chinese - 22.2%\\
+Korean - 47.9%\\
diff --git a/TradeFilter3.lua b/TradeFilter3.lua
index 47c869f..de3816f 100644
--- a/TradeFilter3.lua
+++ b/TradeFilter3.lua
@@ -32,7 +32,7 @@ File Date: @file-date-iso@
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 --]]

-TradeFilter3 = LibStub("AceAddon-3.0"):NewAddon("TradeFilter3", "AceConsole-3.0", "AceEvent-3.0")
+TradeFilter3 = LibStub("AceAddon-3.0"):NewAddon("TradeFilter3", "AceConsole-3.0", "AceEvent-3.0", "AceTimer-3.0")
 local L =  LibStub("AceLocale-3.0"):GetLocale("TradeFilter3", true)
 local friends = LibStub("LibFriends-1.0")
 local TF3 = TradeFilter3
@@ -43,12 +43,12 @@ TF3.version = MAJOR_VERSION .. "." .. MINOR_VERSION
 TF3.date = string.sub("$Date: @file-date-iso@ $", 8, 17)

 --[[ Locals ]]--
-local _G = _G
-local ipairs = _G.ipairs
-local find = _G.string.find
-local sub = _G.string.gsub
-local lower = _G.string.lower
-local formatIt = _G.string.format
+local ipairs = ipairs
+local find = string.find
+local sub = string.gsub
+local lower = string.lower
+local formatIt = string.format
+local timerCount = 0
 local repeatdata = {}
 local currentFriend
 local redirectFrame = L["redirectFrame"]
@@ -140,26 +140,57 @@ function TF3:IsLoggedIn()
 	self:RegisterEvent("FRIENDLIST_UPDATE", "GetFriends")
 	friends.RegisterCallback(self, "Added")
 	friends.RegisterCallback(self, "Removed")
+	self:ScheduleRepeatingTimer("RecycleTables", 1800, repeatdata)
 	self:UnregisterEvent("PLAYER_LOGIN")
 end

---[[ DB Functions ]]--
-function TF3:WipeTable(tbl)
-	if tbl ~= nil and type(tbl) == "table" then
-		wipe(tbl)
+--[[ Helper Functions ]]--
+function TF3:WipeTable(t)
+	if (t ~= nil and type(t) == "table") then
+		wipe(t)
 	end
 end

-function TF3:CopyTable(tbl)
-  local new_tbl = {}
-  for k, v in pairs(tbl) do
+function TF3:CopyTable(t)
+  local new_t = {}
+  for k, v in pairs(t) do
     if (type(v) == "table") then
-      new_tbl[k] = copyTable(v)
+      new_t[k] = TF3:CopyTable(v)
     else
-			new_tbl[k] = v
+			new_t[k] = v
     end
   end
-  return new_tbl
+  return new_t
+end
+
+function TF3:GetNumElements(t)
+ local count = 0
+ for _ in pairs(t) do
+  count = count + 1
+ end
+ return count
+end
+
+function TF3:RecycleTables(t, state)
+	local gtime = math.floor(GetTime()*math.pow(10,0)+0.5) / math.pow(10,0)
+	if (t ~= nil and type(t) == "table" and TF3:GetNumElements(t) >= 100) then
+		local key, value = next(t, state)
+		if key then
+			for k,v in pairs(value) do
+				if(k == "lastIndex" and gtime - v > 1800) then
+					if (TF3.db.profile.debug) then
+						TF3:FindFrame(debugFrame, "|cFFFFFF80" .. L["RMVRT1"] .. "|r |cFF33FF99" .. key .. "|r |cFFFFFF80" .. L["RMVRT2"] .. "|r")
+					end
+					t[key] = nil
+				end
+			end
+			return value, TF3:RecycleTables(t, key)
+		end
+		timerCount = timerCount + 1
+		if (TF3.db.profile.debug) then
+			TF3:FindFrame(debugFrame, ("%d " .. L["SECPSD"]):format(1800 * timerCount))
+		end
+	end
 end

 --[[ Friends Functions ]]--
@@ -167,15 +198,13 @@ function TF3:GetFriends()
 	local friends = TF3.db.profile.friendslist
 	local numFriends = GetNumFriends()
 	if (#friends ~= numFriends) then
-		print(L["TFFR"])
+		print("|cFF33FF99" .. L["TFFR"] .. "|r")
 		TF3:WipeTable(friends)
 		for i=1, numFriends do
 			local name = GetFriendInfo(i)
 			if name then
 				friends[i] = name
-				if (TF3.db.profile.debug) then
-					print("|cFFFFFF80" .. name .. " " .. L["FADD"] .. "|r")
-				end
+				print("|cFFFFFF80" .. name .. " " .. L["FADD"] .. "|r")
 			end
 		end
 	end
@@ -187,7 +216,7 @@ function TF3:Added(event, name)
 	if name ~= UnitName("player") then
 		friends[#friends + 1] = name
 		if (TF3.db.profile.debug) then
-			print("|cFFFFFF80" .. name .. " " .. L["FADD"] .. "|r")
+			TF3:FindFrame(debugFrame, "|cFFFFFF80" .. name .. " " .. L["FADD"] .. "|r")
 		end
 	end
 	if currentFriend then
@@ -202,7 +231,7 @@ function TF3:Removed(event, name)
 			if find(name,v) then
 				friends[k] = nil
 				if (TF3.db.profile.debug) then
-					print("|cFFFFFF80" .. name .. " " .. L["FREM"] .. "|r")
+					TF3:FindFrame(debugFrame, "|cFFFFFF80" .. name .. " " .. L["FREM"] .. "|r")
 				end
 			end
 		end
@@ -212,7 +241,6 @@ function TF3:Removed(event, name)
 	end
 end

---[[ IsFriend Func ]]--
 function TF3:IsFriend(userID)
 	local friends = self.db.profile.friendslist
 	for _,name in ipairs(friends) do
@@ -231,7 +259,6 @@ function TF3:BlackList(msg, userID, msgID)
 	if (TF3.db.profile.blacklist_enable) then
 		for _,word in pairs(blword) do
 			if (find(msg,word)) then
-				--@alpha@
 				if (TF3.db.profile.debug) then
 					if (msgID ~= lastmsgID) then
 						TF3:FindFrame(debugFrame, "|cFFFF0000[" .. L["bLists"] .. "]|r |cFFD9D9D9[" .. userID .. "]:|r |cFFC08080" .. msg .. "|r")
@@ -241,7 +268,6 @@ function TF3:BlackList(msg, userID, msgID)
 						end
 					end
 				end
-				--@end-alpha@
 				if (TF3.db.profile.redirect_blacklist) then
 					if (msgID ~= lastmsgID) then
 						TF3:FindFrame(redirectFrame, "|cFFFF0000[" .. L["bLists"] .. "]|r |cFFD9D9D9[" .. userID .. "]:|r |cFFC08080" .. msg .. "|r")
@@ -285,19 +311,13 @@ function TF3:FindRepeat(msg, userID, msgID)
 	if (msgID ~= repeatdata[userID].lastmsgID and msg == repeatdata[userID].lastmsg and gtime - repeatdata[userID].lastIndex < tonumber(TF3.db.profile.time_repeats)) then
 		repeatdata[userID].repeats = repeatdata[userID].repeats + 1
 		if (repeatdata[userID].repeats >= tonumber(TF3.db.profile.num_repeats)) then
-			--@alpha@
 			if (TF3.db.profile.debug) then
-			--@end-alpha@
 				if (msg ~= lastmsg) then
-					--@alpha@
 					TF3:FindFrame(repeatFrame, "|cFFFF8C00[" .. L["#RPT"] .. "]|r |cFFD9D9D9[" .. msgID .. "]|r |cFFD9D9D9[" .. userID .. "]:|r |cFFC08080" .. msg .. "|r")
-					--@end-alpha@
 					TF3.db.profile.repeats_blocked = TF3.db.profile.repeats_blocked + 1
 					lastmsg = msg
 				end
-			--@alpha@
 			end
-			--@end-alpha@
 			return true
 		end
 	elseif (msg ~= repeatdata[userID].lastmsg) then
@@ -534,63 +554,51 @@ function TF3:FilterFunc(...)
 	end
 	if (filterFuncList and TF3.db.profile.turnOn) then
 		filtered = true
-		--@alpha@
 		if (TF3.db.profile.debug) then
 			if (lastmsg ~= msg or lastuserID ~= userID) then
 				TF3:FindFrame(debugFrame, "|cFFC08080[" .. chan .. "]|r |cFFD9D9D9[" .. userID .. "]:|r |cFFC08080" .. msg .. "|r")
 			end
 		end
-		--@end-alpha@
 		if (zoneID == 2) then
 			for i,v in pairs(TF3.db.profile.filters.TRADE) do
-				--@alpha@
 				if (TF3.db.profile.debug and not TF3.db.profile.debug_checking) then
 					if (lastmsg ~= msg or lastuserID ~= userID) then
 						TF3:FindFrame(debugFrame, L["CFM"] .. " " .. v)
 					end
 				end
-				--@end-alpha@
 				if (find(msg,v)) then
-					--@alpha@
 					if (TF3.db.profile.debug) then
 						if (lastmsg ~= msg or lastuserID ~= userID) then
 							TF3:FindFrame(debugFrame, L["MATCHED"] .. " |cffff8080" .. v .. "|r")
 							lastmsg, lastuserID = msg, userID
 						end
 					end
-					--@end-alpha@
 					filtered = false
 				end
 			end
 		else
 			for i,v in pairs(TF3.db.profile.filters.BASE) do
-				--@alpha@
 				if (TF3.db.profile.debug and not TF3.db.profile.debug_checking) then
 					if (lastmsg ~= msg or lastuserID ~= userID) then
 						TF3:FindFrame(debugFrame, L["CFM"] .. " " .. v)
 					end
 				end
-				--@end-alpha@
 				if (find(msg,v)) then
-					--@alpha@
 					if (TF3.db.profile.debug) then
 						if (lastmsg ~= msg or lastuserID ~= userID) then
 							TF3:FindFrame(debugFrame, L["MATCHED"] .. " |cffff8080" .. v .. "|r")
 							lastmsg, lastuserID = msg, userID
 						end
 					end
-					--@end-alpha@
 					filtered = false
 					end
 				end
 			end
 		if (filtered == true) then
 			if (lastmsg ~= msg or lastuserID ~= userID) then
-				--@alpha@
 				if (TF3.db.profile.debug) then
 					TF3:FindFrame(debugFrame, L["NOMATCH"])
 				end
-				--@end-alpha@
 				if (TF3.db.profile.redirect) then
 					TF3:FindFrame(redirectFrame, "|cFFC08080[" .. chan .. "]|r |cFFD9D9D9[" .. userID .. "]:|r |cFFC08080" .. msg .. "|r")
 				end
diff --git a/TradeFilter3.toc b/TradeFilter3.toc
index d18caca..5fcd0a2 100644
--- a/TradeFilter3.toc
+++ b/TradeFilter3.toc
@@ -39,6 +39,7 @@ libs\AceConsole-3.0\AceConsole-3.0.xml
 libs\AceDB-3.0\AceDB-3.0.xml
 libs\AceDBOptions-3.0\AceDBOptions-3.0.xml
 libs\AceEvent-3.0\AceEvent-3.0.xml
+libs\AceTimer-3.0\AceTimer-3.0.xml
 libs\AceGUI-3.0\AceGUI-3.0.xml
 libs\AceLocale-3.0\AceLocale-3.0.xml
 libs\AceConfig-3.0\AceConfig-3.0.xml
diff --git a/TradeFilter3Options.lua b/TradeFilter3Options.lua
index 024394e..1bc88c0 100644
--- a/TradeFilter3Options.lua
+++ b/TradeFilter3Options.lua
@@ -149,7 +149,7 @@ options = {
 							end,
 							multiline = 8,
 							order = 5,
-							width = "double",
+							width = "full",
 							name = L["BTF"],
 --~ 							desc = L["BTF"],
 							get = function(info)
@@ -196,7 +196,7 @@ options = {
 							end,
 							multiline = 8,
 							order = 8,
-							width = "double",
+							width = "full",
 							name = L["BCF"],
 							desc = L["BCFD"],
 							get = function(info)
@@ -286,7 +286,7 @@ options = {
 							end,
 							multiline = 8,
 							order = 7,
-							width = "double",
+							width = "full",
 							name = L["bLists"],
 							get = function(info)
 								local ret = ""
@@ -331,7 +331,7 @@ options = {
 							end,
 							multiline = 8,
 							order = 10,
-							width = "double",
+							width = "full",
 							name = L["wLists"],
 							get = function(info)
 								local ret = ""
@@ -385,7 +385,7 @@ options = {
 								return not TF3.db.profile.repeat_enable
 							end,
 							order = 3,
-							width = "double",
+							width = "full",
 							name = L["#RPT"],
 							desc = L["#RPTD"],
 							usage = L["RPTU"],
@@ -398,14 +398,13 @@ options = {
 								return not TF3.db.profile.repeat_enable
 							end,
 							order = 4,
-							width = "double",
+							width = "full",
 							name = L["TRPT"],
 							desc = L["TRPTD"],
 							usage = L["RPTU"],
 							get = function(info) return TF3.db.profile.time_repeats end,
 							set = function(info, value) TF3.db.profile.time_repeats = value end,
 						},
-						--@alpha@
 						repeats_blocked = {
 							type = 'input',
 							disabled = true,
@@ -423,7 +422,6 @@ options = {
 							desc = L["RPTRESETD"],
 							func = function() TF3.db.profile.repeats_blocked = 0 end,
 						},
-						--@end-alpha@
 					},
 				},
 				outputGroup = {