refactoring
This commit is contained in:
+45
-42
@@ -1,10 +1,20 @@
|
||||
local private, public = {}, {}
|
||||
Aux.bids_frame = public
|
||||
local m, private, public = Aux.tab(4, 'bids_frame')
|
||||
|
||||
local auction_records
|
||||
|
||||
function public.on_load()
|
||||
public.create_frames(private, public)
|
||||
function public.FRAMES(f)
|
||||
private.create_frames = f
|
||||
end
|
||||
|
||||
function public.LOAD()
|
||||
m.create_frames(m, private, public)
|
||||
end
|
||||
|
||||
function public.OPEN()
|
||||
m.scan_bids()
|
||||
end
|
||||
|
||||
function public.CLOSE()
|
||||
end
|
||||
|
||||
function private.update_listing()
|
||||
@@ -12,41 +22,34 @@ function private.update_listing()
|
||||
return
|
||||
end
|
||||
|
||||
private.listing:SetDatabase(auction_records)
|
||||
end
|
||||
|
||||
function public.on_open()
|
||||
public.scan_bids()
|
||||
end
|
||||
|
||||
function public.on_close()
|
||||
m.listing:SetDatabase(auction_records)
|
||||
end
|
||||
|
||||
function public.scan_bids()
|
||||
|
||||
private.status_bar:update_status(0,0)
|
||||
private.status_bar:set_text('Scanning auctions...')
|
||||
m.status_bar:update_status(0,0)
|
||||
m.status_bar:set_text('Scanning auctions...')
|
||||
|
||||
auction_records = {}
|
||||
private.update_listing()
|
||||
m.update_listing()
|
||||
Aux.scan.start{
|
||||
type = 'bidder',
|
||||
queries = {{ blizzard_query = {} }},
|
||||
on_page_loaded = function(page, total_pages)
|
||||
private.status_bar:update_status(100 * (page - 1) / total_pages, 0)
|
||||
private.status_bar:set_text(format('Scanning (Page %d / %d)', page, total_pages))
|
||||
m.status_bar:update_status(100 * (page - 1) / total_pages, 0)
|
||||
m.status_bar:set_text(format('Scanning (Page %d / %d)', page, total_pages))
|
||||
end,
|
||||
on_auction = function(auction_record)
|
||||
tinsert(auction_records, auction_record)
|
||||
end,
|
||||
on_complete = function()
|
||||
private.status_bar:update_status(100, 100)
|
||||
private.status_bar:set_text('Done Scanning')
|
||||
private.update_listing()
|
||||
m.status_bar:update_status(100, 100)
|
||||
m.status_bar:set_text('Done Scanning')
|
||||
m.update_listing()
|
||||
end,
|
||||
on_abort = function()
|
||||
private.status_bar:update_status(100, 100)
|
||||
private.status_bar:set_text('Done Scanning')
|
||||
m.status_bar:update_status(100, 100)
|
||||
m.status_bar:set_text('Done Scanning')
|
||||
end,
|
||||
}
|
||||
end
|
||||
@@ -60,7 +63,7 @@ end
|
||||
|
||||
function private.record_remover(record)
|
||||
return function()
|
||||
private.listing:RemoveAuctionRecord(record)
|
||||
m.listing:RemoveAuctionRecord(record)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -71,7 +74,7 @@ do
|
||||
local found_index
|
||||
|
||||
function private.find_auction(record)
|
||||
if not private.listing:ContainsRecord(record) then
|
||||
if not m.listing:ContainsRecord(record) then
|
||||
return
|
||||
end
|
||||
|
||||
@@ -79,37 +82,37 @@ do
|
||||
state = SEARCHING
|
||||
scan_id = Aux.scan_util.find(
|
||||
record,
|
||||
private.status_bar,
|
||||
m.status_bar,
|
||||
function()
|
||||
state = IDLE
|
||||
end,
|
||||
function()
|
||||
state = IDLE
|
||||
private.record_remover(record)()
|
||||
m.record_remover(record)()
|
||||
end,
|
||||
function(index)
|
||||
state = FOUND
|
||||
found_index = index
|
||||
|
||||
if not record.high_bidder then
|
||||
private.bid_button:SetScript('OnClick', function()
|
||||
if private.test(record)(index) and private.listing:ContainsRecord(record) then
|
||||
m.bid_button:SetScript('OnClick', function()
|
||||
if m.test(record)(index) and m.listing:ContainsRecord(record) then
|
||||
Aux.place_bid('bidder', index, record.bid_price, record.bid_price < record.buyout_price and function()
|
||||
Aux.info.bid_update(record)
|
||||
private.listing:SetDatabase()
|
||||
end or private.record_remover(record))
|
||||
m.listing:SetDatabase()
|
||||
end or m.record_remover(record))
|
||||
end
|
||||
end)
|
||||
private.bid_button:Enable()
|
||||
m.bid_button:Enable()
|
||||
end
|
||||
|
||||
if record.buyout_price > 0 then
|
||||
private.buyout_button:SetScript('OnClick', function()
|
||||
if private.test(record)(index) and private.listing:ContainsRecord(record) then
|
||||
Aux.place_bid('bidder', index, record.buyout_price, private.record_remover(record))
|
||||
m.buyout_button:SetScript('OnClick', function()
|
||||
if m.test(record)(index) and m.listing:ContainsRecord(record) then
|
||||
Aux.place_bid('bidder', index, record.buyout_price, m.record_remover(record))
|
||||
end
|
||||
end)
|
||||
private.buyout_button:Enable()
|
||||
m.buyout_button:Enable()
|
||||
end
|
||||
end
|
||||
)
|
||||
@@ -117,22 +120,22 @@ do
|
||||
|
||||
function public.on_update()
|
||||
if state == IDLE or state == SEARCHING then
|
||||
private.buyout_button:Disable()
|
||||
private.bid_button:Disable()
|
||||
m.buyout_button:Disable()
|
||||
m.bid_button:Disable()
|
||||
end
|
||||
|
||||
if state == SEARCHING then
|
||||
return
|
||||
end
|
||||
|
||||
local selection = private.listing:GetSelection()
|
||||
local selection = m.listing:GetSelection()
|
||||
if not selection then
|
||||
state = IDLE
|
||||
elseif selection and state == IDLE then
|
||||
private.find_auction(selection.record)
|
||||
elseif state == FOUND and not private.test(selection.record)(found_index) then
|
||||
private.buyout_button:Disable()
|
||||
private.bid_button:Disable()
|
||||
m.find_auction(selection.record)
|
||||
elseif state == FOUND and not m.test(selection.record)(found_index) then
|
||||
m.buyout_button:Disable()
|
||||
m.bid_button:Disable()
|
||||
if not Aux.bid_in_progress() then
|
||||
state = IDLE
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user