From 124433dd2f7514ce1bf8cc2ba83b6b253670f813 Mon Sep 17 00:00:00 2001 From: Manuel Simon Hirsig Date: Mon, 7 Sep 2015 23:23:54 +0200 Subject: [PATCH] factored out scan into separate file --- Auctionator.lua | 178 +----------------------------------------------- Auctionator.toc | 1 + Scan.lua | 166 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 168 insertions(+), 177 deletions(-) create mode 100644 Scan.lua diff --git a/Auctionator.lua b/Auctionator.lua index 8f7c8ce..8e6f722 100644 --- a/Auctionator.lua +++ b/Auctionator.lua @@ -957,180 +957,4 @@ end -- end -- }) --- end - ---[[*************************************************************** - - MULTI PAGE SCAN - - All the functions below here should really be in a separate - file and the locals private to that file ... - ---*****************************************************************]] - -local SCAN_STATE_IDLE = 0 -local SCAN_STATE_PREQUERY = 1 -local SCAN_STATE_POSTQUERY = 2 - -NUM_AUCTION_ITEMS_PER_PAGE = 50 - -local currentQuery -local currentPage -local scanState = SCAN_STATE_IDLE - -local scanData - ------------------------------------------ - -function Auctionator_Scan_State_Idle() - return scanState == SCAN_STATE_IDLE -end - -function Auctionator_Scan_State_Prequery() - return scanState == SCAN_STATE_PREQUERY -end - -function Auctionator_Scan_State_Postquery() - return scanState == SCAN_STATE_POSTQUERY -end - ------------------------------------------ - -function Auctionator_Scan_Complete() - - if currentQuery.onComplete then - currentQuery.onComplete(scanData); - end - - currentQuery = nil - currentPage = nil - scanData = nil - scanState = SCAN_STATE_IDLE -end - ------------------------------------------ - -function Auctionator_Scan_Abort() - - if currentQuery and currentQuery.onAbort then - currentQuery.onAbort(); - end - - currentQuery = nil - currentPage = nil - scanData = nil - scanState = SCAN_STATE_IDLE -end - ------------------------------------------ - -function Auctionator_Scan_Query() - if scanState == SCAN_STATE_PREQUERY then - - QueryAuctionItems( - currentQuery.name, - currentQuery.minLevel, - currentQuery.maxLevel, - currentQuery.invTypeIndex, - currentQuery.classIndex, - currentQuery.subclassIndex, - currentPage, - currentQuery.isUsable, - currentQuery.qualityIndex - ) - scanState = SCAN_STATE_POSTQUERY - currentPage = currentPage + 1 - end -end - ------------------------------------------ - -function Auctionator_Scan_Process() - - if scanState == SCAN_STATE_POSTQUERY then - - -- SortAuctionItems("list", "buyout") - -- if IsAuctionSortReversed("list", "buyout") then - -- SortAuctionItems("list", "buyout") - -- end - - local numBatchAuctions, totalAuctions = GetNumAuctionItems("list") - - if totalAuctions >= NUM_AUCTION_ITEMS_PER_PAGE then - Auctionator_SetMessage("Scanning auctions: page "..currentPage.." ...") - end - - for i = 1, numBatchAuctions do - - local name, texture, count, quality, canUse, level, minBid, minIncrement, buyoutPrice, bidAmount, highBidder, owner = GetAuctionItemInfo("list", i) - local duration = GetAuctionItemTimeLeft("list", i) - - local scanDatum = { - name = name, - texture = texture, - stackSize = count, - quality = quality, - canUse = canUse, - level = level, - minBid = minBid, - minIncrement = minIncrement, - buyoutPrice = buyoutPrice, - bidAmount = bidAmount, - highBidder = highBidder, - owner = owner, - duration = duration - } - - if not currentQuery.exactMatch or (currentQuery.name == scanDatum.name and scanDatum.buyoutPrice > 0) then -- TODO separate option for buyout price - tinsert(scanData, scanDatum) - if currentQuery.onReadDatum then - currentQuery.onReadDatum(scanDatum) - end - end - end - - if numBatchAuctions == NUM_AUCTION_ITEMS_PER_PAGE then - scanState = SCAN_STATE_PREQUERY - else - Auctionator_Scan_Complete() - end - end -end - ------------------------------------------ - -function Auctionator_Scan_Start(query) - - Auctionator_SetMessage("Scanning auctions ...") - - if scanState ~= SCAN_STATE_IDLE then - Auctionator_Scan_Abort() - end - - currentQuery = query - currentPage = 0 - scanData = {} - scanState = SCAN_STATE_PREQUERY -end - ------------------------------------------ - -function Auctionator_Scan_CreateQuery(parameterMap) - local query = { - name = nil, - exactMatch = false, - minLevel = "", - maxLevel = "", - invTypeIndex = nil, - classIndex = nil, - subclassIndex = nil, - isUsable = nil, - qualityIndex = nil - } - - for k,v in pairs(parameterMap) do - query[k] = v - end - - return query -end \ No newline at end of file +-- end \ No newline at end of file diff --git a/Auctionator.toc b/Auctionator.toc index 3f1ee6e..85e4303 100644 --- a/Auctionator.toc +++ b/Auctionator.toc @@ -3,6 +3,7 @@ ## Notes: A lightweight addon designed to help manage auctions ## SavedVariablesPerCharacter: AUCTIONATOR_ENABLE_ALT, AUCTIONATOR_OPEN_FIRST, AUCTIONATOR_INSTANT_BUYOUT ## SavedVariables: auctionatorEntries +Scan.lua Auctionator.xml Options.xml About.xml diff --git a/Scan.lua b/Scan.lua new file mode 100644 index 0000000..6209c87 --- /dev/null +++ b/Scan.lua @@ -0,0 +1,166 @@ +local SCAN_STATE_IDLE = 0 +local SCAN_STATE_PREQUERY = 1 +local SCAN_STATE_POSTQUERY = 2 + +NUM_AUCTION_ITEMS_PER_PAGE = 50 + +local currentQuery +local currentPage +local scanState = SCAN_STATE_IDLE + +local scanData + +----------------------------------------- + +function Auctionator_Scan_State_Idle() + return scanState == SCAN_STATE_IDLE +end + +function Auctionator_Scan_State_Prequery() + return scanState == SCAN_STATE_PREQUERY +end + +function Auctionator_Scan_State_Postquery() + return scanState == SCAN_STATE_POSTQUERY +end + +----------------------------------------- + +function Auctionator_Scan_Complete() + + if currentQuery.onComplete then + currentQuery.onComplete(scanData); + end + + currentQuery = nil + currentPage = nil + scanData = nil + scanState = SCAN_STATE_IDLE +end + +----------------------------------------- + +function Auctionator_Scan_Abort() + + if currentQuery and currentQuery.onAbort then + currentQuery.onAbort(); + end + + currentQuery = nil + currentPage = nil + scanData = nil + scanState = SCAN_STATE_IDLE +end + +----------------------------------------- + +function Auctionator_Scan_Query() + if scanState == SCAN_STATE_PREQUERY then + + QueryAuctionItems( + currentQuery.name, + currentQuery.minLevel, + currentQuery.maxLevel, + currentQuery.invTypeIndex, + currentQuery.classIndex, + currentQuery.subclassIndex, + currentPage, + currentQuery.isUsable, + currentQuery.qualityIndex + ) + scanState = SCAN_STATE_POSTQUERY + currentPage = currentPage + 1 + end +end + +----------------------------------------- + +function Auctionator_Scan_Process() + + if scanState == SCAN_STATE_POSTQUERY then + + -- SortAuctionItems("list", "buyout") + -- if IsAuctionSortReversed("list", "buyout") then + -- SortAuctionItems("list", "buyout") + -- end + + local numBatchAuctions, totalAuctions = GetNumAuctionItems("list") + + if totalAuctions >= NUM_AUCTION_ITEMS_PER_PAGE then + Auctionator_SetMessage("Scanning auctions: page "..currentPage.." ...") + end + + for i = 1, numBatchAuctions do + + local name, texture, count, quality, canUse, level, minBid, minIncrement, buyoutPrice, bidAmount, highBidder, owner = GetAuctionItemInfo("list", i) + local duration = GetAuctionItemTimeLeft("list", i) + + local scanDatum = { + name = name, + texture = texture, + stackSize = count, + quality = quality, + canUse = canUse, + level = level, + minBid = minBid, + minIncrement = minIncrement, + buyoutPrice = buyoutPrice, + bidAmount = bidAmount, + highBidder = highBidder, + owner = owner, + duration = duration + } + + if not currentQuery.exactMatch or (currentQuery.name == scanDatum.name and scanDatum.buyoutPrice > 0) then -- TODO separate option for buyout price + tinsert(scanData, scanDatum) + if currentQuery.onReadDatum then + currentQuery.onReadDatum(scanDatum) + end + end + end + + if numBatchAuctions == NUM_AUCTION_ITEMS_PER_PAGE then + scanState = SCAN_STATE_PREQUERY + else + Auctionator_Scan_Complete() + end + end +end + +----------------------------------------- + +function Auctionator_Scan_Start(query) + + Auctionator_SetMessage("Scanning auctions ...") + + if scanState ~= SCAN_STATE_IDLE then + Auctionator_Scan_Abort() + end + + currentQuery = query + currentPage = 0 + scanData = {} + scanState = SCAN_STATE_PREQUERY +end + +----------------------------------------- + +function Auctionator_Scan_CreateQuery(parameterMap) + local query = { + name = nil, + exactMatch = false, + minLevel = "", + maxLevel = "", + invTypeIndex = nil, + classIndex = nil, + subclassIndex = nil, + isUsable = nil, + qualityIndex = nil + } + + for k,v in pairs(parameterMap) do + query[k] = v + end + + return query +end \ No newline at end of file