more refactoring

This commit is contained in:
Manuel Simon Hirsig
2016-08-19 17:44:19 +02:00
parent fc91332865
commit 012ccfb21d
14 changed files with 168 additions and 194 deletions
+2 -2
View File
@@ -195,12 +195,12 @@ function public.populate_wdb(item_id)
item_id = item_id or MIN_ITEM_ID
if item_id > MAX_ITEM_ID then
aux.log('Cache populated.')
log('Cache populated.')
return
end
if not GetItemInfo('item:'..item_id) then
aux.log('Fetching item '..item_id..'.')
log('Fetching item '..item_id..'.')
AuxTooltip:SetHyperlink('item:'..item_id)
end
+5 -5
View File
@@ -27,14 +27,14 @@ do
end
end
for _, state in aborted do
aux.call(state.params.on_abort)
call(state.params.on_abort)
end
end
function complete()
local on_complete = state.params.on_complete
scan_states[state.params.type] = nil
aux.call(on_complete)
call(on_complete)
end
function accessor.state()
@@ -81,7 +81,7 @@ end
function scan()
state.query_index = state.query_index and state.query_index + 1 or 1
if query and (aux.index(query.blizzard_query, 'first_page') or 0) <= (aux.index(query.blizzard_query, 'last_page') or aux.huge) then
if query and (index(query.blizzard_query, 'first_page') or 0) <= (index(query.blizzard_query, 'last_page') or huge) then
if query.blizzard_query then
state.page = query.blizzard_query.first_page or 0
else
@@ -103,7 +103,7 @@ end
function submit_query()
aux.control.when(function() return state.params.type ~= 'list' or CanSendAuctionQuery() end, function()
aux.call(state.params.on_submit_query)
call(state.params.on_submit_query)
state.last_query_time = GetTime()
if state.params.type == 'bidder' then
GetBidderAuctionItems(state.page)
@@ -153,7 +153,7 @@ function scan_page(i)
aux.history.process_auction(auction_info)
if aux.call(state.params.auto_buy_validator, auction_info) then
if call(state.params.auto_buy_validator, auction_info) then
local send_signal, signal_received = signal()
aux.control.when(signal_received, recurse)
aux.place_bid(auction_info.query_type, auction_info.index, auction_info.buyout_price, aux.C(send_signal, true))
+19 -19
View File
@@ -4,50 +4,50 @@ function SlashCmdList.AUX(command)
local arguments = tokenize(command)
if arguments[1] == 'clear' and arguments[2] == 'history' then
aux.persistence.load_dataset().history = nil
aux.log 'History cleared.'
log 'History cleared.'
elseif arguments[1] == 'clear' and arguments[2] == 'post' then
aux.persistence.load_dataset().post = nil
aux.log 'Post settings cleared.'
log 'Post settings cleared.'
elseif arguments[1] == 'clear' and arguments[2] == 'datasets' then
g.aux_datasets = {}
aux.log 'Datasets cleared.'
log 'Datasets cleared.'
elseif arguments[1] == 'clear' and arguments[2] == 'merchant' and arguments[3] == 'buy' then
g.aux_merchant_buy = {}
aux.log 'Merchant buy prices cleared.'
log 'Merchant buy prices cleared.'
elseif arguments[1] == 'clear' and arguments[2] == 'merchant' and arguments[3] == 'sell' then
g.aux_merchant_sell = {}
aux.log 'Merchant sell prices cleared.'
log 'Merchant sell prices cleared.'
elseif arguments[1] == 'clear' and arguments[2] == 'item' and arguments[3] == 'cache' then
g.aux_items = {}
g.aux_item_ids = {}
g.aux_auctionable_items = {}
aux.log 'Item cache cleared.'
log 'Item cache cleared.'
elseif arguments[1] == 'populate' and arguments[2] == 'wdb' then
aux.cache.populate_wdb()
elseif arguments[1] == 'tooltip' and arguments[2] == 'value' then
g.aux_tooltip_value = not g.aux_tooltip_value
aux.log('Historical value in tooltip '..(g.aux_tooltip_value and 'enabled' or 'disabled')..'.')
log('Historical value in tooltip '..(g.aux_tooltip_value and 'enabled' or 'disabled')..'.')
elseif arguments[1] == 'tooltip' and arguments[2] == 'daily' then
g.aux_tooltip_daily = not g.aux_tooltip_daily
aux.log('Market value in tooltip '..(g.aux_tooltip_daily and 'enabled' or 'disabled')..'.')
log('Market value in tooltip '..(g.aux_tooltip_daily and 'enabled' or 'disabled')..'.')
elseif arguments[1] == 'tooltip' and arguments[2] == 'vendor' and arguments[3] == 'buy' then
g.aux_tooltip_vendor_buy = not g.aux_tooltip_vendor_buy
aux.log('Vendor buy price in tooltip '..(g.aux_tooltip_vendor_buy and 'enabled' or 'disabled')..'.')
log('Vendor buy price in tooltip '..(g.aux_tooltip_vendor_buy and 'enabled' or 'disabled')..'.')
elseif arguments[1] == 'tooltip' and arguments[2] == 'vendor' and arguments[3] == 'sell' then
g.aux_tooltip_vendor_sell = not g.aux_tooltip_vendor_sell
aux.log('Vendor sell price in tooltip '..(g.aux_tooltip_vendor_sell and 'enabled' or 'disabled')..'.')
log('Vendor sell price in tooltip '..(g.aux_tooltip_vendor_sell and 'enabled' or 'disabled')..'.')
elseif arguments[1] == 'tooltip' and arguments[2] == 'disenchant' and arguments[3] == 'value' then
g.aux_tooltip_disenchant_value = not g.aux_tooltip_disenchant_value
aux.log('Disenchant value in tooltip '..(g.aux_tooltip_disenchant_value and 'enabled' or 'disabled')..'.')
log('Disenchant value in tooltip '..(g.aux_tooltip_disenchant_value and 'enabled' or 'disabled')..'.')
elseif arguments[1] == 'tooltip' and arguments[2] == 'disenchant' and arguments[3] == 'distribution' then
g.aux_tooltip_disenchant_distribution = not g.aux_tooltip_disenchant_distribution
aux.log('Disenchant distribution in tooltip '..(g.aux_tooltip_disenchant_distribution and 'enabled' or 'disabled')..'.')
log('Disenchant distribution in tooltip '..(g.aux_tooltip_disenchant_distribution and 'enabled' or 'disabled')..'.')
elseif arguments[1] == 'tooltip' and arguments[2] == 'disenchant' and arguments[3] == 'source' then
g.aux_tooltip_disenchant_source = not g.aux_tooltip_disenchant_source
aux.log('Disenchant source in tooltip '..(g.aux_tooltip_disenchant_source and 'enabled' or 'disabled')..'.')
log('Disenchant source in tooltip '..(g.aux_tooltip_disenchant_source and 'enabled' or 'disabled')..'.')
elseif arguments[1] == 'ignore' and arguments[2] == 'owner' then
g.aux_ignore_owner = not g.aux_ignore_owner
aux.log('Ignoring of owner '..(g.aux_ignore_owner and 'enabled' or 'disabled')..'.')
log('Ignoring of owner '..(g.aux_ignore_owner and 'enabled' or 'disabled')..'.')
elseif arguments[1] == 'chars' and arguments[2] == 'add' then
local realm = GetCVar 'realmName'
g.aux_characters[realm] = g.aux_characters[realm] or {}
@@ -55,7 +55,7 @@ function SlashCmdList.AUX(command)
local name = string.gsub(strlower(arguments[i]), '^%l', strupper)
if not g.aux_characters[realm][name] then
g.aux_characters[realm][name] = true
aux.log('Character "'..name..'" added.')
log('Character "'..name..'" added.')
end
end
elseif arguments[1] == 'chars' and arguments[2] == 'remove' then
@@ -67,7 +67,7 @@ function SlashCmdList.AUX(command)
local name = string.gsub(strlower(arguments[i]), '^%l', strupper)
if g.aux_characters[realm][name] then
g.aux_characters[realm][name] = nil
aux.log('Character "'..name..'" removed.')
log('Character "'..name..'" removed.')
end
end
elseif arguments[1] == 'chars' then
@@ -77,11 +77,11 @@ function SlashCmdList.AUX(command)
tinsert(chars, name)
end
if getn(chars) > 0 then
aux.log('Your characters: "'..table.concat(chars, ', ')..'".')
log('Your characters: "'..table.concat(chars, ', ')..'".')
else
aux.log 'You don\'t have any additional characters. To add your characters type "/aux chars add NAME1 NAME2 NAME3...".'
log 'You don\'t have any additional characters. To add your characters type "/aux chars add NAME1 NAME2 NAME3...".'
end
else
aux.log('Unknown command: "'..command..'"')
log('Unknown command: "'..command..'"')
end
end
+1 -1
View File
@@ -111,7 +111,7 @@ function public.stop()
slot = nil
end
m.state = nil
aux.call(callback, slot)
call(callback, slot)
end
end
+56 -131
View File
@@ -4,44 +4,6 @@ public.bids_loaded = false
public.current_owner_page = nil
public.last_owner_page_requested = nil
do
local data = {}
local mt = {
__newindex = function(self, key, value)
data[self].getter{public=self, private=data[self].state}[key] = value
end,
__index = function(self, key)
return data[self].getter{public=self, private=data[self].state}[key]
end,
}
function public.dynamic_table(state, getter)
local self = {}
data[self] = {getter=getter, state=state}
return setmetatable(self, mt)
end
end
do
local _state = setmetatable({}, {__mode='kv'})
local __index = function(self, key)
return _state[self].handler({public=self, private=_state[self].state}, key)
end
function public.index_function(state, handler)
local state, self = {handler=handler, state=state}, {}
_state[self] = state
return setmetatable(self, {__metatable=false, __index=__index, state=state})
end
end
function public.temp(object)
getfenv(2).__ = object
return object
end
function public.L(body_string)
return loadstring 'function()'
end
tabs = {}
function public.tab(index, name)
local module_env = getfenv(2)
@@ -61,16 +23,16 @@ do
end
function on_tab_click(index)
if active_tab_index then
m.call(active_tab.env.CLOSE)
call(active_tab.env.CLOSE)
end
active_tab_index = index
if active_tab_index then
m.call(active_tab.env.OPEN)
call(active_tab.env.OPEN)
end
end
end
function public.VARIABLES_LOADED()
function VARIABLES_LOADED()
do
local frame = CreateFrame('Frame', aux.gui.name, UIParent)
tinsert(UISpecialFrames, 'aux_frame1')
@@ -103,8 +65,8 @@ function public.VARIABLES_LOADED()
public.frame = frame
end
do
local tabs = m.gui.tabs(m.frame, 'DOWN')
tabs._on_select = m.on_tab_click
local tabs = gui.tabs(frame, 'DOWN')
tabs._on_select = on_tab_click
for _, tab in m.tabs do
tabs:create_tab(tab.name)
end
@@ -113,17 +75,17 @@ function public.VARIABLES_LOADED()
end
end
do
local btn = m.gui.button(m.frame, 16)
local btn = gui.button(frame, 16)
btn:SetPoint('BOTTOMRIGHT', -6, 6)
btn:SetWidth(65)
btn:SetHeight(24)
btn:SetText 'Close'
btn:SetScript('OnClick', m.C(m.frame.Hide, m.frame))
btn:SetScript('OnClick', C(frame.Hide, frame))
public.close_button = btn
end
do
local btn = m.gui.button(m.frame, 16)
btn:SetPoint('RIGHT', m.close_button, 'LEFT' , -5, 0)
local btn = gui.button(frame, 16)
btn:SetPoint('RIGHT', close_button, 'LEFT' , -5, 0)
btn:SetWidth(65)
btn:SetHeight(24)
btn:SetText 'Default UI'
@@ -139,43 +101,43 @@ end
function AUCTION_HOUSE_SHOW()
AuctionFrame:Hide()
m.frame:Show()
m.set_tab(1)
frame:Show()
set_tab(1)
end
function AUCTION_HOUSE_CLOSED()
m.bids_loaded = false
m.current_owner_page = nil
m.post.stop()
m.stack.stop()
m.scan.abort()
m.set_tab()
m.frame:Hide()
bids_loaded = false
current_owner_page = nil
post.stop()
stack.stop()
scan.abort()
set_tab()
frame:Hide()
end
function AUCTION_BIDDER_LIST_UPDATE()
m.bids_loaded = true
bids_loaded = true
end
function AUCTION_OWNED_LIST_UPDATE()
m.current_owner_page = m.last_owner_page_requested or 0
current_owner_page = last_owner_page_requested or 0
end
function m.ADDON_LOADED.Blizzard_AuctionUI()
function ADDON_LOADED.Blizzard_AuctionUI()
AuctionFrame:UnregisterEvent('AUCTION_HOUSE_SHOW')
AuctionFrame:SetScript('OnHide', nil)
m.hook('ShowUIPanel', function(...)
hook('ShowUIPanel', function(...)
if arg[1] == AuctionFrame then
return AuctionFrame:Show()
end
return m.orig.ShowUIPanel(unpack(arg))
return orig.ShowUIPanel(unpack(arg))
end)
m.hook('GetOwnerAuctionItems', m.GetOwnerAuctionItems)
m.hook('SetItemRef', m.SetItemRef)
m.hook('UseContainerItem', m.UseContainerItem)
m.hook('AuctionFrameAuctions_OnEvent', m.AuctionFrameAuctions_OnEvent)
hook('GetOwnerAuctionItems', GetOwnerAuctionItems)
hook('SetItemRef', SetItemRef)
hook('UseContainerItem', UseContainerItem)
hook('AuctionFrameAuctions_OnEvent', AuctionFrameAuctions_OnEvent)
end
do
@@ -186,9 +148,9 @@ do
return label
end
function m.ADDON_LOADED.Blizzard_CraftUI()
m.hook('CraftFrame_SetSelection', function(...)
local results = {m.orig.CraftFrame_SetSelection(unpack(arg)) }
function ADDON_LOADED.Blizzard_CraftUI()
hook('CraftFrame_SetSelection', function(...)
local results = {orig.CraftFrame_SetSelection(unpack(arg))}
local id = GetCraftSelectionIndex()
local reagent_count = GetCraftNumReagents(id)
@@ -200,10 +162,10 @@ do
total_cost = nil
break
end
local item_id, suffix_id = m.info.parse_link(link)
local item_id, suffix_id = info.parse_link(link)
local count = select(3, GetCraftReagentInfo(id, i))
local _, price, limited = m.cache.merchant_info(item_id)
local value = price and not limited and price or m.history.value(item_id..':'..suffix_id)
local _, price, limited = cache.merchant_info(item_id)
local value = price and not limited and price or history.value(item_id..':'..suffix_id)
if not value then
total_cost = nil
break
@@ -218,9 +180,9 @@ do
end)
end
function m.ADDON_LOADED.Blizzard_TradeSkillUI()
m.hook('TradeSkillFrame_SetSelection', function(...)
local results = {m.orig.TradeSkillFrame_SetSelection(unpack(arg)) }
function ADDON_LOADED.Blizzard_TradeSkillUI()
hook('TradeSkillFrame_SetSelection', function(...)
local results = {orig.TradeSkillFrame_SetSelection(unpack(arg))}
local id = GetTradeSkillSelectionIndex()
local reagent_count = GetTradeSkillNumReagents(id)
@@ -232,10 +194,10 @@ do
total_cost = nil
break
end
local item_id, suffix_id = m.info.parse_link(link)
local item_id, suffix_id = info.parse_link(link)
local count = select(3, GetTradeSkillReagentInfo(id, i))
local _, price, limited = m.cache.merchant_info(item_id)
local value = price and not limited and price or m.history.value(item_id..':'..suffix_id)
local _, price, limited = cache.merchant_info(item_id)
local value = price and not limited and price or history.value(item_id..':'..suffix_id)
if not value then
total_cost = nil
break
@@ -270,55 +232,50 @@ end
function GetOwnerAuctionItems(...)
local page = arg[1]
m.last_owner_page_requested = page
return m.orig.GetOwnerAuctionItems(unpack(arg))
last_owner_page_requested = page
return orig.GetOwnerAuctionItems(unpack(arg))
end
function AuctionFrameAuctions_OnEvent(...)
if AuctionFrameAuctions:IsVisible() then
return m.orig.AuctionFrameAuctions_OnEvent(unpack(arg))
return orig.AuctionFrameAuctions_OnEvent(unpack(arg))
end
end
function SetItemRef(...)
if arg[3] ~= 'RightButton' or not m.index(active_tab, 'env', 'CLICK_LINK') or not strfind(arg[1], '^item:%d+') then
return m.orig.SetItemRef(unpack(arg))
if arg[3] ~= 'RightButton' or not index(active_tab, 'env', 'CLICK_LINK') or not strfind(arg[1], '^item:%d+') then
return orig.SetItemRef(unpack(arg))
end
for item_info in present(m.info.item(tonumber(({strfind(arg[1], '^item:(%d+)')})[3]))) do
return m.active_tab.env.CLICK_LINK(item_info)
for item_info in present(info.item(tonumber(({strfind(arg[1], '^item:(%d+)')})[3]))) do
return active_tab.env.CLICK_LINK(item_info)
end
end
function UseContainerItem(...)
if m.modified() or not m.index(active_tab, 'env', 'USE_ITEM') then
return m.orig.UseContainerItem(unpack(arg))
if modified or not index(active_tab, 'env', 'USE_ITEM') then
return orig.UseContainerItem(unpack(arg))
end
for item_info in present(m.info.container_item(arg[1], arg[2])) do
return m.active_tab.env.USE_ITEM(item_info)
for item_info in present(info.container_item(arg[1], arg[2])) do
return active_tab.env.USE_ITEM(item_info)
end
end
do
local locked
function public.bid_in_progress()
return locked
end
function public.place_bid(type, index, amount, on_success)
if locked then
return
end
local money = GetMoney()
PlaceAuctionBid(type, index, amount)
if money >= amount then
locked = true
m.control.event_listener('CHAT_MSG_SYSTEM', function(kill)
control.event_listener('CHAT_MSG_SYSTEM', function(kill)
if arg1 == ERR_AUCTION_BID_PLACED then
m.call(on_success)
call(on_success)
locked = false
kill()
end
@@ -329,23 +286,18 @@ end
do
local locked
function public.cancel_in_progress()
return locked
end
function public.cancel_auction(index, on_success)
if locked then
return
end
locked = true
CancelAuction(index)
m.control.event_listener('CHAT_MSG_SYSTEM', function(kill)
control.event_listener('CHAT_MSG_SYSTEM', function(kill)
if arg1 == ERR_AUCTION_REMOVED then
aux.call(on_success)
call(on_success)
locked = false
kill()
end
@@ -364,7 +316,7 @@ do
local function call(f, arg1, arg2)
local params = {}
for i=1,arg1.n do
if arg1[i] == m._this then
if arg1[i] == _this then
tinsert(params, this)
elseif formal_parameters[arg1[i]] then
tinsert(params, arg2[formal_parameters[arg1[i]]])
@@ -382,36 +334,9 @@ do
end
end
function public.call(f, ...)
if f then
return f(unpack(arg))
end
end
function public.index(t, ...)
for i=1,arg.n do
t = t and t[arg[i]]
end
return t
end
public.huge = 1.8*10^308
function public.log(...)
local msg = '[aux]'
for i=1,arg.n do
msg = msg..' '..tostring(arg[i])
end
DEFAULT_CHAT_FRAME:AddMessage(LIGHTYELLOW_FONT_COLOR_CODE..msg)
end
function public.is_player(name, current)
local realm = GetCVar 'realmName'
return not current and m.index(g.aux_characters, realm, name) or UnitName 'player' == name
end
function public.modified()
return IsShiftKeyDown() or IsControlKeyDown() or IsAltKeyDown()
return not current and index(g.aux_characters, realm, name) or UnitName 'player' == name
end
function public.neutral_faction()
+3 -3
View File
@@ -44,7 +44,7 @@ do
end
function color_accessor(callback)
return function()
return aux.index_function({callback=callback, table=config.colors}, index_handler)
return index_function({callback=callback, table=config.colors}, index_handler)
end
end
end
@@ -336,7 +336,7 @@ do
function mt.__index:select(id)
self._selected = id
self:update()
aux.call(self._on_select, id)
call(self._on_select, id)
end
function mt.__index:update()
for _, tab in self._tabs do
@@ -389,7 +389,7 @@ function public.editbox(parent)
end)
editbox:SetScript('OnTextChanged', function()
this.last_change = GetTime()
this.text:SetText(aux.call(this.formatter, this:GetText()) or this:GetText())
this.text:SetText(call(this.formatter, this:GetText()) or this:GetText())
this.cursor:SetPoint('LEFT', this.text, 'LEFT', max(0, this.text:GetStringWidth() - 2), 1)
end)
do
+3 -2
View File
@@ -1,4 +1,5 @@
setglobal('aux', aux_module('core'))
import 'util'
public.version = '4.0.0'
@@ -40,8 +41,8 @@ event_frame:SetScript('OnEvent', function()
m[event]()
if event == 'VARIABLES_LOADED' then
for _, env in module_envs do
if env.m.LOAD then
env.m.LOAD()
if env.LOAD then
env.LOAD()
end
end
log('v'..version..' loaded.')
+10 -10
View File
@@ -11,7 +11,7 @@ local AUCTION_PCT_COLORS = {
{color=aux.gui.inline_color.green, value=80},
{color=aux.gui.inline_color.yellow, value=110},
{color=aux.gui.inline_color.orange, value=135},
{color=aux.gui.inline_color.red, value=aux.huge},
{color=aux.gui.inline_color.red, value=huge},
}
local TIME_LEFT_STRINGS = {
@@ -198,8 +198,8 @@ public.search_config = {
cmp = function(record_a, record_b, desc)
local price_a = g.aux_price_per_unit and record_a.unit_buyout_price or record_a.buyout_price
local price_b = g.aux_price_per_unit and record_b.unit_buyout_price or record_b.buyout_price
price_a = price_a > 0 and price_a or (desc and -aux.huge or aux.huge)
price_b = price_b > 0 and price_b or (desc and -aux.huge or aux.huge)
price_a = price_a > 0 and price_a or (desc and -huge or huge)
price_b = price_b > 0 and price_b or (desc and -huge or huge)
return aux.sorting.compare(price_a, price_b, desc)
end,
@@ -213,8 +213,8 @@ public.search_config = {
cell:SetText((pct or bidPct) and percentage_historical(pct or bidPct, not pct) or '---')
end,
cmp = function(record_a, record_b, desc)
local pct_a = record_percentage(record_a) or (desc and -aux.huge or aux.huge)
local pct_b = record_percentage(record_b) or (desc and -aux.huge or aux.huge)
local pct_a = record_percentage(record_a) or (desc and -huge or huge)
local pct_b = record_percentage(record_b) or (desc and -huge or huge)
return aux.sorting.compare(pct_a, pct_b, desc)
end,
},
@@ -340,8 +340,8 @@ public.auctions_config = {
cmp = function(record_a, record_b, desc)
local price_a = g.aux_price_per_unit and record_a.unit_buyout_price or record_a.buyout_price
local price_b = g.aux_price_per_unit and record_b.unit_buyout_price or record_b.buyout_price
price_a = price_a > 0 and price_a or (desc and -aux.huge or aux.huge)
price_b = price_b > 0 and price_b or (desc and -aux.huge or aux.huge)
price_a = price_a > 0 and price_a or (desc and -huge or huge)
price_b = price_b > 0 and price_b or (desc and -huge or huge)
return aux.sorting.compare(price_a, price_b, desc)
end,
@@ -493,8 +493,8 @@ public.bids_config = {
cmp = function(record_a, record_b, desc)
local price_a = g.aux_price_per_unit and record_a.unit_buyout_price or record_a.buyout_price
local price_b = g.aux_price_per_unit and record_b.unit_buyout_price or record_b.buyout_price
price_a = price_a > 0 and price_a or (desc and -aux.huge or aux.huge)
price_b = price_b > 0 and price_b or (desc and -aux.huge or aux.huge)
price_a = price_a > 0 and price_a or (desc and -huge or huge)
price_b = price_b > 0 and price_b or (desc and -huge or huge)
return aux.sorting.compare(price_a, price_b, desc)
end,
@@ -644,7 +644,7 @@ local methods = {
DressUpItemLink(this.row.data.record.link)
elseif IsShiftKeyDown() and ChatFrameEditBox:IsVisible() then
ChatFrameEditBox:Insert(this.row.data.record.link)
elseif not aux.modified() and button == 'RightButton' then -- TODO not when alt (how?)
elseif not modified and button == 'RightButton' then -- TODO not when alt (how?)
aux.set_tab(1)
aux.search_tab.set_filter(strlower(aux.info.item(this.row.data.record.item_id).name)..'/exact')
aux.search_tab.execute(nil, false)
+2 -2
View File
@@ -155,14 +155,14 @@ function update_auction_listing()
sort(auction_rows, function(a, b)
return aux.sorting.multi_lt(
{
a.record.unit_buyout_price == 0 and aux.huge or a.record.unit_buyout_price,
a.record.unit_buyout_price == 0 and huge or a.record.unit_buyout_price,
a.record.unit_blizzard_bid,
a.record.stack_size,
b.record.own and 1 or 0,
a.record.duration,
},
{
b.record.unit_buyout_price == 0 and aux.huge or b.record.unit_buyout_price,
b.record.unit_buyout_price == 0 and huge or b.record.unit_buyout_price,
b.record.unit_blizzard_bid,
b.record.stack_size,
a.record.own and 1 or 0,
+4 -4
View File
@@ -109,7 +109,7 @@ function get_filter_builder_query()
end
local name = m.blizzard_query.name
if not aux.index(aux.filter.parse_query_string(name), 'blizzard', 'name') then
if not index(aux.filter.parse_query_string(name), 'blizzard', 'name') then
name = aux.filter.quote(name)
end
add((name ~= '' or m.blizzard_query.exact) and name)
@@ -175,7 +175,7 @@ function import_query_string()
if components then
m.set_form(components)
else
aux.log(error)
log(error)
end
end
@@ -277,7 +277,7 @@ function add_post_filter()
m.filter_input:HighlightText()
m.filter_input:SetFocus()
elseif error then
aux.log(error)
log(error)
end
end
end
@@ -325,7 +325,7 @@ function initialize_filter_dropdown()
value = filter,
func = function()
m.filter_input:SetText(this.value)
if aux.index(aux.filter.filters[this.value], 'input_type') == '' or this.value == 'not' then
if index(aux.filter.filters[this.value], 'input_type') == '' or this.value == 'not' then
m.add_post_filter()
elseif aux.filter.filters[this.value] then
m.filter_parameter_input:Show()
+4 -4
View File
@@ -118,9 +118,9 @@ function update_auto_buy_filter()
local queries = aux.filter.queries(g.aux_auto_buy_filter)
if queries then
if getn(queries) > 1 then
aux.log('Error: The automatic buyout filter may contain only one query')
log('Error: The automatic buyout filter may contain only one query')
elseif size(queries[1].blizzard_query) > 0 then
aux.log('Error: The automatic buyout filter does not support Blizzard filters')
log('Error: The automatic buyout filter does not support Blizzard filters')
else
m.auto_buy_validator = queries[1].validator
m.auto_buy_filter_button.prettified = queries[1].prettified
@@ -315,10 +315,10 @@ function public.execute(resume, real_time)
return
elseif real_time then
if getn(queries) > 1 then
aux.log('Invalid filter: The real time mode does not support multiple queries')
log('Invalid filter: The real time mode does not support multiple queries')
return
elseif queries[1].blizzard_query.first_page or queries[1].blizzard_query.last_page then
aux.log('Invalid filter: The real time mode does not support page range filters')
log('Invalid filter: The real time mode does not support page range filters')
return
end
end
+49 -1
View File
@@ -1,5 +1,53 @@
aux.module 'util'
function public.call(f, ...)
if f then
return f(unpack(arg))
end
end
function public.index(t, ...)
for i=1,arg.n do
t = t and t[arg[i]]
end
return t
end
public.huge = 1.8*10^308
function public.log(...)
local msg = '[aux]'
for i=1,arg.n do
msg = msg..' '..tostring(arg[i])
end
DEFAULT_CHAT_FRAME:AddMessage(LIGHTYELLOW_FONT_COLOR_CODE..msg)
end
function public.accessor.modified()
return IsShiftKeyDown() or IsControlKeyDown() or IsAltKeyDown()
end
do
local _state = setmetatable({}, {__mode='kv'})
local __index = function(self, key)
return _state[self].handler({public=self, private=_state[self].state}, key)
end
function public.index_function(state, handler)
local state, self = {handler=handler, state=state}, {}
_state[self] = state
return setmetatable(self, {__metatable=false, __index=__index, state=state})
end
end
function public.temp(object)
getfenv(2).__ = object
return object
end
function public.L(body_string)
return loadstring 'function()'
end
function public.present(...)
local called
return function()
@@ -211,7 +259,7 @@ function public.accessor.inventory()
end
if bag <= 4 then
return {bag, slot}, m.bag_type(bag)
return {bag, slot}, bag_type(bag)
end
end
end
+9 -9
View File
@@ -235,8 +235,8 @@ do
end
for _, parser in {
{'class', aux.info.item_class_index},
{'subclass', aux.C(aux.info.item_subclass_index, aux.index(self.class, 2) or 0, aux._1)},
{'slot', aux.C(aux.info.item_slot_index, aux.index(self.class, 2) or 0, aux.index(self.subclass, 2) or 0, aux._1)},
{'subclass', aux.C(aux.info.item_subclass_index, index(self.class, 2) or 0, aux._1)},
{'slot', aux.C(aux.info.item_slot_index, index(self.class, 2) or 0, index(self.subclass, 2) or 0, aux._1)},
{'quality', aux.info.item_quality_index},
} do
if not self[parser[1]] then
@@ -285,9 +285,9 @@ function public.parse_query_string(str)
local i = 1
while parts[i] do
if aux.temp(m.operator(parts[i])) then
if temp(m.operator(parts[i])) then
tinsert(post_filter, __)
elseif aux.temp(m.filters[parts[i]]) then
elseif temp(m.filters[parts[i]]) then
local input_type = __.input_type
if input_type ~= '' then
if not parts[i + 1] or not m.parse_parameter(input_type, parts[i + 1]) then
@@ -362,7 +362,7 @@ function public.queries(query_string)
local query, _, error = m.query(str)
if not query then
aux.log('Invalid filter:', error)
log('Invalid filter:', error)
return
else
tinsert(queries, query)
@@ -397,14 +397,14 @@ function suggestions(components)
-- subclasses
if not components.blizzard.subclass then
for _, subclass in {GetAuctionItemSubClasses(aux.index(components.blizzard.class, 2) or 0)} do
for _, subclass in {GetAuctionItemSubClasses(index(components.blizzard.class, 2) or 0)} do
tinsert(suggestions, subclass)
end
end
-- slots
if not components.blizzard.slot then
for _, invtype in {GetAuctionInvTypes(aux.index(components.blizzard.class, 2) or 0, aux.index(components.blizzard.subclass, 2) or 0)} do
for _, invtype in {GetAuctionInvTypes(index(components.blizzard.class, 2) or 0, index(components.blizzard.subclass, 2) or 0)} do
tinsert(suggestions, getglobal(invtype))
end
end
@@ -511,7 +511,7 @@ function blizzard_query(components)
local query = {name=filters.name and filters.name[2]}
local item_info, class_index, subclass_index, slot_index
if filters.exact and aux.temp(aux.cache.item_id(filters.name[2])) and aux.temp(aux.info.item(__)) then
if filters.exact and temp(aux.cache.item_id(filters.name[2])) and temp(aux.info.item(__)) then
item_info = __
class_index = aux.info.item_class_index(item_info.class)
subclass_index = aux.info.item_subclass_index(class_index or 0, item_info.subclass)
@@ -528,7 +528,7 @@ function blizzard_query(components)
query.quality = item_info.quality
else
for _, key in {'min_level', 'max_level', 'class', 'subclass', 'slot', 'usable', 'quality'} do
query[key] = aux.index(filters[key], 2)
query[key] = index(filters[key], 2)
end
end
return query
+1 -1
View File
@@ -113,7 +113,7 @@ function public.to_string(money, pad, trim, decimal_points, color, no_color)
end
function public.from_string(value)
if aux.temp(tonumber(value)) and __ >= 0 then
if temp(tonumber(value)) and __ >= 0 then
return __ * COPPER_PER_GOLD
end