Quantcast

Added mass filter option

p3lim-52096 [02-08-09 - 17:13]
Added mass filter option
Added additional options to slash handler
Added smarter database system

git-svn-id: svn://svn.wowinterface.com/pError-161/trunk@13 7a612bb6-1b7b-4f5f-b58b-e1cc54d1b6b6
Filename
pError/pError.lua
pError/pError.toc
diff --git a/pError/pError.lua b/pError/pError.lua
index d9d16d6..50a6fed 100644
--- a/pError/pError.lua
+++ b/pError/pError.lua
@@ -1,17 +1,12 @@
-local addon = CreateFrame('Frame')
-local defaults = {
-	[ERR_OUT_OF_ENERGY] = true,
-	[ERR_SPELL_COOLDOWN] = true,
-	[ERR_OUT_OF_RANGE] = true,
-	[ERR_BADATTACKPOS] = true,
-	[ERR_ABILITY_COOLDOWN] = true,
-}
-
 local function OnEvent(self, event, ...)
 	if(event == 'UI_ERROR_MESSAGE') then
 		local str = ...
-		for k,v in pairs(pErrorDB) do
-			if(string.find(string.lower(str), string.lower(k)) and v) then return end
+		if(pErrorDB2.all) then
+			return
+		else
+			for k,v in ipairs(pErrorDB2.blacklist) do
+				if(string.find(string.lower(str), string.lower(v))) then return end
+			end
 		end
 	end

@@ -21,43 +16,57 @@ end
 local function OnLoad(self, event, addon)
 	if(addon ~= 'pError') then return end

-	pErrorDB = pErrorDB or {}
-	for k,v in pairs(defaults) do
-		if(type(pErrorDB[k]) == 'nil') then
-			pErrorDB[k] = v
-		end
-	end
+	pErrorDB2 = pErrorDB2 or {all = false, blacklist = {}}

 	UIErrorsFrame:SetScript('OnEvent', OnEvent)
-
 	self:UnregisterEvent(event)
 end

+local function pprint(...)
+	print(string.format('|cffff8080pError:|r %s', ...))
+end
+
+local addon = CreateFrame('Frame')
 addon:RegisterEvent('ADDON_LOADED')
 addon:SetScript('OnEvent', OnLoad)

 SLASH_PERROR1 = '/perror'
 SlashCmdList.PERROR = function(str)
 	if(str == 'reset') then
-		pErrorDB = {}
-		print('|cffff8080pError:|r Savedvariables is now reset')
+		pErrorDB2 = {all = false, blacklist = {}}
+		pprint('Savedvariables is now reset')
+	elseif(str == 'all') then
+		pErrorDB2.all = not pErrorDB2.all
+		pprint(string.format('Filtering of all events turned %s', pErrorDB2.all and 'on' or 'off'))
 	elseif(str == 'list') then
-		print('|cffff8080pError:|r Listing database of events and their states:')
-		for k,v in pairs(pErrorDB) do
-			print(format('"%s"   %s', k, v and '|cff00ff00Enabled|r' or '|cffff0000Disabled|r'))
+		if(pErrorDB2.all) then
+			pprint('Filtering all events!')
+		elseif(not pErrorDB2.blacklist[1]) then
+			pprint('Database is empty')
+		else
+			pprint('Listing database of events:')
+			for k,v in pairs(pErrorDB2.blacklist) do
+				pprint(format('  \'%s\'', v))
+			end
 		end
 	elseif(#str > 0) then
-		for k,v in pairs(pErrorDB) do
-			if(string.find(string.lower(str), string.lower(k))) then
-				pErrorDB[k] = not v
-				print(format('|cffff8080pError:|r %s "%s"', v and '|cffff0000Disabled|r' or '|cff00ff00Enabled|r', k))
-				return
+		if(pErrorDB2.all) then
+			pprint('Can\'t add to database, pError is filtering all events')
+		else
+			local num = 0
+			for k,v in ipairs(pErrorDB2.blacklist) do
+				num = num + 1
+				if(string.find(string.lower(str), string.lower(v))) then
+					table.remove(pErrorDB2.blacklist, num)
+					pprint(format('\'%s\' removed', v))
+					return
+				end
 			end
-		end

-		pErrorDB[str] = true
-		print(format('|cffff8080pError:|r Added "%s" to the database', str))
+			table.insert(pErrorDB2.blacklist, str)
+			pprint(format('Added \'%s\' to the database', str))
+		end
 	else
-		print('|cffff8080pError:|r Please provide an error string')
+		pprint('Please provide an error string')
 	end
 end
\ No newline at end of file
diff --git a/pError/pError.toc b/pError/pError.toc
index 45187c7..ff70943 100644
--- a/pError/pError.toc
+++ b/pError/pError.toc
@@ -3,6 +3,6 @@
 ## Version: 30000.wowi:revision
 ## Title: |cffff6000p|rError
 ## Notes: Hide those pesky errors!
-## SavedVariables: pErrorDB
+## SavedVariables: pErrorDB2

 pError.lua
\ No newline at end of file