Quantcast

Detect some partial loads and keep waiting

Kevin Lyles [07-07-10 - 19:24]
Detect some partial loads and keep waiting
Filename
ItemScanner.lua
diff --git a/ItemScanner.lua b/ItemScanner.lua
index a1aa139..6fd400f 100644
--- a/ItemScanner.lua
+++ b/ItemScanner.lua
@@ -3,6 +3,17 @@ local CONSECUTIVE_INVALID_TO_IGNORE = 5
 local VALID_DELAY = 0.025
 local INVALID_DELAY = 5

+local patterns = {
+	"^Design:",
+	"^Formula:",
+	"^Manual:",
+	"^Pattern:",
+	"^Plans:",
+	"^Recipe:",
+	"^Schematic:",
+	"^Technique:",
+}
+
 local function scanItemLink(link)
 	local textL, textR

@@ -11,7 +22,40 @@ local function scanItemLink(link)
 	ItemScannerHiddenTooltip:SetHyperlink(link)

 	local startTime = GetTime()
-	while ItemScannerHiddenTooltipTextLeft1:GetText():find(RETRIEVING_ITEM_INFO) do
+	local isPattern, hasReq = false, false
+	while true do
+		local numLines = ItemScannerHiddenTooltip:NumLines()
+		local done = numLines > 1
+		if done then
+			if not isPattern then
+				local text = _G["ItemScannerHiddenTooltipTextLeft1"]:GetText()
+				for _, pattern in ipairs(patterns) do
+					if text:find(pattern) then
+						isPattern = true
+						break
+					end
+				end
+			end
+			-- We can skip the first line because it will only be RETRIEVING_ITEM_INFO if we only have one line
+			for i = 2, numLines do
+				local text = _G["ItemScannerHiddenTooltipTextLeft" .. i]:GetText()
+				if text:find(RETRIEVING_ITEM_INFO) then
+					done = false
+					break
+				elseif text:find("%(%d/[01]%)$") then
+					done = false
+					break
+				elseif isPattern and not hasReq then
+					hasReq = text:find("^\nRequires")
+				end
+			end
+			if isPattern and not hasReq then
+				done = false
+			end
+			if done then
+				break
+			end
+		end
 		coroutine.yield()
 		if GetTime() - startTime >= INVALID_DELAY then
 			-- If we got anything useful, keep it