Quantcast

Added a generic effect handler

Kevin Lyles [02-19-10 - 03:04]
Added a generic effect handler
Filename
Regexps.lua
WeightsWatcher.lua
diff --git a/Regexps.lua b/Regexps.lua
index 8d6cc6e..e86b450 100644
--- a/Regexps.lua
+++ b/Regexps.lua
@@ -2,6 +2,59 @@ if not WeightsWatcher then
 	WeightsWatcher = AceLibrary("AceAddon-2.0"):new("AceEvent-2.0", "AceHook-2.1")
 end

+function WeightsWatcher.handleEffects(text, matchLines, ignoreLines, unweightedLines, preprocessLines, affixLines, section)
+	local match = false
+	for _, pattern in ipairs(matchLines) do
+		if string.find(text, pattern) then
+			match = true
+			break
+		end
+	end
+	if not match then
+		return false
+	end
+
+	local origText = text
+
+	for _, pattern in ipairs(ignoreLines) do
+		if string.find(text, pattern) then
+			ww_ignored_lines[text][pattern] = true
+			return true
+		end
+	end
+	for _, pattern in ipairs(unweightedLines) do
+		if string.find(text, pattern) then
+			ww_unweighted_lines[text][pattern] = true
+			return true
+		end
+	end
+	for _, regex in ipairs(preprocessLines) do
+		local pattern, replacement = unpack(regex)
+		if string.find(text, pattern) then
+			text = string.gsub(text, pattern, replacement)
+		end
+	end
+	for _, pattern in ipairs(affixLines) do
+		if string.find(text, pattern) then
+			text = string.gsub(text, pattern, "")
+		end
+		if text == "" then
+			break
+		end
+	end
+	if text == "" then
+		ww_ignored_lines[origText] = true
+		return true
+	end
+	local stat = WeightsWatcher.parseStats(text)
+	if stat then
+		return stat
+	end
+end
+
+EffectHandlers = {
+}
+
 function WeightsWatcher.twoStats(text, pattern)
 	local start, _, stat1, stat2 = string.find(text, pattern)
 	if start then
diff --git a/WeightsWatcher.lua b/WeightsWatcher.lua
index ffe8f40..d177da1 100644
--- a/WeightsWatcher.lua
+++ b/WeightsWatcher.lua
@@ -236,6 +236,7 @@ function WeightsWatcher.ResetTables()
 	end

 	ww_unparsed_lines = setmetatable({}, metatable)
+	ww_handle_effects_unparsed_lines = setmetatable({}, metatable)
 	ww_ignored_lines = setmetatable({}, metatable)
 	ww_temp_ignored_lines = setmetatable({}, metatable)
 	ww_unparsed_items = setmetatable({}, metatable)
@@ -988,6 +989,17 @@ function WeightsWatcher.parseLine(textL, textR, link)
 	if stats then
 		return stats
 	end
+
+	for _, args in ipairs(EffectHandlers) do
+		local stats = WeightsWatcher.handleEffects(textL, unpack(args))
+		if stats then
+			if stats == true then
+				return
+			end
+			return stats
+		end
+	end
+
 	local stats = WeightsWatcher.parseStats(textL)
 	if stats then
 		return stats