From 2cd1f43bc8b3d0935183a3f280ca7d9e9ac7a28f Mon Sep 17 00:00:00 2001 From: Simon Hirsig Date: Tue, 27 Oct 2015 13:23:35 +0100 Subject: [PATCH] some manage frame progress --- manage_frame.lua | 51 ++++++++++++++++++++++++++++++++++-------------- util.lua | 42 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+), 15 deletions(-) diff --git a/manage_frame.lua b/manage_frame.lua index 977a80b..2a5f06e 100644 --- a/manage_frame.lua +++ b/manage_frame.lua @@ -1,6 +1,6 @@ local on_open, on_close -local bid_records, auctions_records, create_bid_record, create_auction_record +local bid_records, auctions_records, create_maybe_bid_record, create_maybe_auction_record local bid_listing_config = { on_cell_click = function (sheet, row_index, column_index) @@ -179,31 +179,43 @@ function on_open() if not bid_records then GetBidderAuctionItems() bid_records = {} + local i = 0 + while true do + local maybe_bid_record = create_maybe_bid_record(i) + + if maybe_bid_record.present() then + tinsert(auction_records, maybe_bid_record.get()) + else + break + end + i = i + 1 + end end - AuctionFrameBid.page = 0; - AuctionFrameBid_Update(); + AuctionFrameBid.page = 0 + AuctionFrameBid_Update() if not auctions_records then GetOwnerAuctionItems() auction_records = {} + local i = 0 + while true do + local maybe_auction_record = create_maybe_auction_record(i) + + if maybe_auction_record.present() then + tinsert(auction_records, maybe_auction_record.get()) + else + break + end + i = i + 1 + end end - AuctionFrameAuctions.page = 0; - AuctionFrameAuctions_Update(); + AuctionFrameAuctions.page = 0 + AuctionFrameAuctions_Update() end function on_close() end - - - - - - - - - - Aux.manage_frame = { on_open = on_open, on_close = on_close, @@ -211,3 +223,12 @@ Aux.manage_frame = { auction_listing_config = auction_listing_config, } +function create_maybe_auction_record(index) + GetAuctionItemInfo('owner', index) +end + +function create_maybe_bid_record(index) + GetAuctionItemInfo('bidder', index) +end + + diff --git a/util.lua b/util.lua index 4decd8e..5e0efb7 100644 --- a/util.lua +++ b/util.lua @@ -356,3 +356,45 @@ function Aux.util.set() return self end + +function Aux.util.maybe(value) + local self = {} + + function self.join() + if value == nil then + return Aux.util.maybe() + else + return value + end + end + + function self.map(f) + if value == nil then + return Aux.util.maybe() + else + return maybe(f(value)) + end + end + + function self.bind(f) + return self.map(f).join() + end + + function self.get() + return value + end + + function self.or_else(default_value) + if value == nil then + return default_value + else + return value + end + end + + function self.present() + return value ~= nil + end + + return self +end