Quantcast

Split much of ProcessedLines off into IgnoredLines and SingleStatLines

Kevin Lyles [09-13-09 - 07:35]
Split much of ProcessedLines off into IgnoredLines and SingleStatLines

Special cases and multiple stats yet to come
Filename
Regexps.lua
WeightsWatcher.lua
diff --git a/Regexps.lua b/Regexps.lua
index bced151..e5cf417 100644
--- a/Regexps.lua
+++ b/Regexps.lua
@@ -8,27 +8,23 @@ Preprocess = {
 	{"^Use: Teaches you how to permanently enchant ", "Use: Permanently enchant "},
 }

-ProcessedLines = {
-	-- TODO: split this into min and max damage
-	{"(%d+) %- (%d+) Damage",
-		function(text, pattern)
-			local start, val1, val2
-			start, _, val1, val2 = string.find(text, pattern)
-			if start then
-				return {"Damage", val1 .. "-" .. val2}
-			end
-		end},
+IgnoredLines = {
+	"^Soulbound$",
+	"^Binds when equipped$",
+	"^Binds when picked up$",
+	"^Binds when used$",
+	"^Durability %d+ / %d+$",
+	"^<.+>$",
+	"^\".+\"$",
+	"^Use: Restores %d+ %a[%a ]+ over %d+ sec%.  Must remain seated while %a+ing%.",
+	"^Use: Heals %d+ damage over %d+ sec%.$",
+}

+SingleStatLines = {
 	{"^Rune of the Stoneskin Gargoyle",
 		function()
 			return {"Defense", "25"}
 		end},
-	"^(Classes): (%a[%a ,]+)",
-	"(Requires %a[%a ]+) %((%d+)%)",
-
-	-- TODO: figure out how to properly handle this and other multi-stat lines
-	"^Use: .*%.  If you spend at least %d+ seconds eating you will become well fed and gain ([%a%d][%a%d, ]+) for .*%.",
-
 	{"Restores (%d+) mana per 5 sec%.",
 		function(text, pattern)
 			local start, value
@@ -37,8 +33,6 @@ ProcessedLines = {
 				return {"MP5", value}
 			end
 		end},
-	"^Use: Restores .*%.",
-	"^Use: Heals %d+ damage over %d+ sec%.",
 	{"^%((%d[%d.]+) damage per second%)$",
 		function(text, pattern)
 			local start, value
@@ -49,22 +43,47 @@ ProcessedLines = {
 		end},
 	{"^%+?(%d+) (%a[%a ]+)",
 		function(text, pattern)
-			local start, name, value
-			start, _, value, name = string.find(text, pattern)
+			local start, _, value, name = string.find(text, pattern)
 			if start then
 				return {name, value}
 			end
 		end},
+
 	"^(%a[%a ]+) (%d+)",
 	"^Equip: Increases (%a[%a ]+) by (%d+)%.",
 	"^Use: Increases (%a[%a ]+) by (%d+) for .*%.",
-	"^Soulbound$",
-	"^Binds when equipped$",
-	"^Binds when picked up$",
-	"^Binds when used$",
-	"^Durability %d+ / %d+$",
-	"^<.+>$",
-	"^\".+\"$",
+	"^Use: Permanently increase the (%a[%a ]+) of .* by (%d+)%..*",
+	"^Use: Permanently enchant .* to increase (%a[%a ]+) by (%d+)%..*",
+	"^Use: When applied to your fishing pole, increases (Fishing) by (%d+) for ",
+	{"^Use: Increases mana regeneration by (%d+) mana per 5 seconds for ",
+		function(text, pattern)
+			local start, value
+			start, _, value = string.find(text, pattern)
+			if start then
+				return {"MP5", value}
+			end
+		end},
+	"^Use: Permanently increase the (%a[%a ]+) of .* by (%d+)%.",
+	"^Use: Permanently enchant .* to increase (%a[%a ]+) by (%d+)%.",
+}
+
+ProcessedLines = {
+	-- TODO: split this into min and max damage
+	{"(%d+) %- (%d+) Damage",
+		function(text, pattern)
+			local start, val1, val2
+			start, _, val1, val2 = string.find(text, pattern)
+			if start then
+				return {"Damage", val1 .. "-" .. val2}
+			end
+		end},
+
+	"^(Classes): (%a[%a ,]+)",
+	"^(Requires %a[%a ]+) %((%d+)%)",
+
+	-- TODO: figure out how to properly handle this and other multi-stat lines
+	"^Use: .*%.  If you spend at least %d+ seconds eating you will become well fed and gain ([%a%d][%a%d, ]+) for .*%.",
+
 	"^(Unique)$",
 	"^(Head)$",
 	"^(Neck)$",
@@ -86,15 +105,4 @@ ProcessedLines = {
 	"^(Relic)$",
 	"^(Ranged)$",
 	"^(Two Hand)$",
-	"^Use: When applied to your fishing pole, increases (Fishing) by (%d+) for ",
-	{"^Use: Increases mana regeneration by (%d+) mana per 5 seconds for ",
-		function(text, pattern)
-			local start, value
-			start, _, value = string.find(text, pattern)
-			if start then
-				return {"MP5", value}
-			end
-		end},
-	"^Use: Permanently increase the (%a[%a ]+) of .* by (%d+)%.",
-	"^Use: Permanently enchant .* to increase (%a[%a ]+) by (%d+)%.",
 }
diff --git a/WeightsWatcher.lua b/WeightsWatcher.lua
index b9d9a5c..547e3a0 100644
--- a/WeightsWatcher.lua
+++ b/WeightsWatcher.lua
@@ -87,29 +87,59 @@ function DisplayItemInfo(tooltip, ttname)
 			text = WeightsWatcher:preprocess(origText)

 			matched = false
-			for _, regex in pairs(ProcessedLines) do
-				if type(regex) == "table" then
-					pattern, func = unpack(regex)
-					if string.find(text, pattern) then
-						stat = func(text, pattern)
-						if stat then
-							tooltip:AddDoubleLine(unpack(stat))
+			for _, regex in pairs(IgnoredLines) do
+				if string.find(origText, regex) then
+					matched = true
+					break
+				end
+			end
+			if not matched then
+				for _, regex in pairs(SingleStatLines) do
+					if type(regex) == "table" then
+						pattern, func = unpack(regex)
+						if string.find(text, pattern) then
+							stat = func(text, pattern)
+							if stat then
+								tooltip:AddDoubleLine(unpack(stat))
+								matched = true
+								break
+							end
+						end
+					else
+						start, _, name, value = string.find(text, regex)
+						if start then
+							tooltip:AddDoubleLine(name, value)
 							matched = true
 							break
 						end
 					end
-				else
-					start, _, name, value = string.find(text, regex)
-					if start then
-						tooltip:AddDoubleLine(name, value)
-						matched = true
-						break
+				end
+				if not matched then
+					for _, regex in pairs(ProcessedLines) do
+						if type(regex) == "table" then
+							pattern, func = unpack(regex)
+							if string.find(text, pattern) then
+								stat = func(text, pattern)
+								if stat then
+									tooltip:AddDoubleLine(unpack(stat))
+									matched = true
+									break
+								end
+							end
+						else
+							start, _, name, value = string.find(text, regex)
+							if start then
+								tooltip:AddDoubleLine(name, value)
+								matched = true
+								break
+							end
+						end
+					end
+					if not matched then
+						ttline:SetText(origText .. " *")
 					end
 				end
 			end
-			if not matched then
-				ttline:SetText(origText .. " *")
-			end
 		end
 		tooltip:Show()
 	end