diff --git a/ItemScanner.lua b/ItemScanner.lua
index 048259d..12f08b9 100644
--- a/ItemScanner.lua
+++ b/ItemScanner.lua
@@ -186,7 +186,7 @@ local function OnUpdate(self)
end
local startTime, roundStartTime, numProcessed, roundNumProcessed, valid, roundValid
-local function genericCoroutine(start, min, max, name, linkTemplate, delay, statusVars, tooltip, threadNumber)
+local function genericCoroutine(start, min, max, name, func, delay, statusVars, threadNumber)
if not threadNumber or threadNumber == 1 then
statusVars.scan_active = true
statusVars.finished = false
@@ -203,7 +203,7 @@ local function genericCoroutine(start, min, max, name, linkTemplate, delay, stat
local function scan(i, scanningAll)
statusVars.last_scanned = i
local itemStartTime = GetTime()
- if scanItemLink(string.format(linkTemplate, i), tooltip, threadNumber) then
+ if func(i, threadNumber) then
if scanningAll then
if statusVars.invalid[i] ~= false then
valid, roundValid = valid + 1, roundValid + 1
@@ -276,78 +276,6 @@ local function genericCoroutine(start, min, max, name, linkTemplate, delay, stat
return true
end
-local function gemParseCoroutine(start)
- IS_status.gems.scan_active = true
- IS_status.gems.finished = false
- coroutine.yield()
- local startTime = GetTime()
- local roundStartTime = startTime
- local numProcessed, roundNumProcessed, valid, roundValid = 0, 0, 0, 0
- print(string.format("ItemScanner: starting scan at gem %d", start))
-
- local function scan(i, scanningAll)
- IS_status.gems.last_scanned = i
- local itemStartTime = GetTime()
- if scanGem(i) then
- if scanningAll then
- if IS_status.gems.invalid[i] ~= false then
- valid, roundValid = valid + 1, roundValid + 1
- end
- else
- IS_status.gems.last_valid = i
- valid, roundValid = valid + 1, roundValid + 1
- end
- -- Reset invalid count
- IS_status.gems.invalid[i] = false
- else
- -- start with 3 if no previous value
- IS_status.gems.invalid[i] = (IS_status.gems.invalid[i] or 2) + 1
- end
- while GetTime() - itemStartTime < VALID_DELAY do
- coroutine.yield()
- end
- numProcessed = numProcessed + 1
- roundNumProcessed = roundNumProcessed + 1
-
- local currentTime = GetTime()
- if currentTime - roundStartTime >= 120 then
- local elapsedTime = currentTime - startTime
- print(string.format("ItemScanner: at gem %d, %d in %.1f sec. (%.2f/min.) (%d valid), %d this round (%d valid)", i, numProcessed, elapsedTime, numProcessed / elapsedTime * 60, valid, roundNumProcessed, roundValid))
- roundStartTime = roundStartTime + 120
- roundNumProcessed, roundValid = 0, 0
- end
- end
-
- for i = start, maxGem do
- if not IS_status.gems.invalid[i] or (type(IS_status.gems.invalid[i]) == "number" and IS_status.gems.invalid[i] < CONSECUTIVE_INVALID_TO_IGNORE) then
- if not IS_status.gems.scan_active then
- break
- end
- scan(i, false)
- end
- end
- IS_status.gems.finished = true
- while IS_status.gems.scan_active do
- local i = (IS_status.gems.last_invalid or minGem - 1)
- repeat
- i = i + 1
- if i > maxGem then
- i = minGem
- end
- until IS_status.gems.invalid[i] ~= true
- IS_status.gems.last_invalid = i
- scan(i, true)
- end
-
- local elapsedTime = GetTime() - startTime
- if elapsedTime == 0 then
- elapsedTime = 0.001
- end
- print(string.format("ItemScanner: scan stopped at gem %d, %d in %.1f sec. (%.2f/min.) (%d valid)", IS_status.gems.last_scanned, numProcessed, elapsedTime, numProcessed / elapsedTime * 60, valid))
-
- return true
-end
-
local function commandHandler(msg)
if string.match(msg, "^all") then
commandHandler(string.gsub(msg, "all", "items"))
@@ -412,8 +340,8 @@ local function commandHandler(msg)
print(" stop stops scanning but leaves existing data intact")
return
end
- frame.gemco = coroutine.wrap(gemParseCoroutine)
- frame.gemco(start)
+ frame.gemco = coroutine.wrap(genericCoroutine)
+ frame.gemco(start, minGem, maxGem, "gem", scanGem, VALID_DELAY, IS_status.gems)
frame:SetScript("OnUpdate", OnUpdate)
elseif string.match(msg, "^items") then
local start
@@ -468,8 +396,13 @@ local function commandHandler(msg)
if not tooltip then
tooltip = CreateFrame("GameTooltip", "ItemScannerHiddenTooltip" .. i, nil, "ItemScannerHiddenTooltip")
end
- table.insert(frame.itemco, coroutine.wrap(genericCoroutine))
- frame.itemco[i](start + i - 1, chunkStart, chunkEnd, "item", "item:%d:0:0:0:0:0:0:0:85", VALID_DELAY * NUM_THREADS, IS_status.items[chunkStart .. "-" .. chunkEnd], tooltip, i)
+
+ local function scanItem(i, threadNumber)
+ return scanItemLink(string.format("item:%d:0:0:0:0:0:0:0:85", i), tooltip, threadNumber)
+ end
+
+ frame.itemco[i] = coroutine.wrap(genericCoroutine)
+ frame.itemco[i](start + i - 1, chunkStart, chunkEnd, "item", scanItem, VALID_DELAY * NUM_THREADS, IS_status.items[chunkStart .. "-" .. chunkEnd], i)
end
frame:SetScript("OnUpdate", OnUpdate)
elseif string.match(msg, "^suffixes") then
@@ -506,8 +439,12 @@ local function commandHandler(msg)
tooltip = CreateFrame("GameTooltip", "ItemScannerHiddenTooltip1", nil, "ItemScannerHiddenTooltip")
end
+ local function scanSuffix(i)
+ return scanItemLink(string.format("item:11993:0:0:0:0:0:%d:100:85", i), tooltip)
+ end
+
frame.suffco = coroutine.wrap(genericCoroutine)
- frame.suffco(start, minSuffix, maxSuffix, "suffix", "item:11993:0:0:0:0:0:%d:100:85", VALID_DELAY, IS_status.suffixes, tooltip)
+ frame.suffco(start, minSuffix, maxSuffix, "suffix", scanSuffix, VALID_DELAY, IS_status.suffixes)
frame:SetScript("OnUpdate", OnUpdate)
else
print("Usage: /is <arg> (or /itemscanner <arg>")