module refactoring
This commit is contained in:
+15
-15
@@ -14,12 +14,12 @@ local MAX_ITEM_ID = 30000
|
||||
local items_schema = {'record', '#', {name='string'}, {quality='number'}, {level='number'}, {class='string'}, {subclass='string'}, {slot='string'}, {max_stack='number'}, {texture='string'}}
|
||||
local merchant_buy_schema = {'record', '#', {unit_price='number'}, {limited='boolean'}}
|
||||
|
||||
aux_items = t
|
||||
aux_item_ids = t
|
||||
aux_auctionable_items = t
|
||||
aux_merchant_buy = t
|
||||
aux_merchant_sell = t
|
||||
aux_characters = t
|
||||
_G.aux_items = t
|
||||
_G.aux_item_ids = t
|
||||
_G.aux_auctionable_items = t
|
||||
_G.aux_merchant_buy = t
|
||||
_G.aux_merchant_sell = t
|
||||
_G.aux_characters = t
|
||||
|
||||
function LOAD()
|
||||
scan_wdb()
|
||||
@@ -42,25 +42,25 @@ end
|
||||
|
||||
do
|
||||
local sell_scan_countdown, incomplete_buy_data
|
||||
function private.on_merchant_show()
|
||||
function on_merchant_show()
|
||||
merchant_sell_scan()
|
||||
incomplete_buy_data = not merchant_buy_scan()
|
||||
end
|
||||
function private.on_merchant_closed()
|
||||
function on_merchant_closed()
|
||||
sell_scan_countdown = nil
|
||||
incomplete_buy_data = false
|
||||
end
|
||||
function private.on_merchant_update()
|
||||
function on_merchant_update()
|
||||
if incomplete_buy_data then
|
||||
incomplete_buy_data = not merchant_buy_scan()
|
||||
end
|
||||
end
|
||||
function private.on_bag_update()
|
||||
function on_bag_update()
|
||||
if MerchantFrame:IsVisible() then
|
||||
sell_scan_countdown = 10
|
||||
end
|
||||
end
|
||||
function private.merchant_on_update()
|
||||
function merchant_on_update()
|
||||
if sell_scan_countdown == 0 then
|
||||
sell_scan_countdown = nil
|
||||
merchant_sell_scan()
|
||||
@@ -70,7 +70,7 @@ do
|
||||
end
|
||||
end
|
||||
|
||||
function private.merchant_loaded()
|
||||
function merchant_loaded()
|
||||
for i = 1, GetMerchantNumItems() do
|
||||
if not GetMerchantItemLink(i) then
|
||||
return false
|
||||
@@ -110,7 +110,7 @@ function public.item_id(item_name)
|
||||
return aux_item_ids[strlower(item_name)]
|
||||
end
|
||||
|
||||
function private.merchant_buy_scan()
|
||||
function merchant_buy_scan()
|
||||
|
||||
local incomplete_data
|
||||
for i = 1, GetMerchantNumItems() do
|
||||
@@ -149,7 +149,7 @@ function private.merchant_buy_scan()
|
||||
return not incomplete_data
|
||||
end
|
||||
|
||||
function private.merchant_sell_scan()
|
||||
function merchant_sell_scan()
|
||||
for slot in info.inventory do auto[slot] = true
|
||||
local item_info = temp-info.container_item(unpack(slot))
|
||||
if item_info then
|
||||
@@ -158,7 +158,7 @@ function private.merchant_sell_scan()
|
||||
end
|
||||
end
|
||||
|
||||
function private.scan_wdb(item_id)
|
||||
function scan_wdb(item_id)
|
||||
item_id = item_id or MIN_ITEM_ID
|
||||
|
||||
local processed = 0
|
||||
|
||||
+7
-7
@@ -11,7 +11,7 @@ local value_cache = t
|
||||
|
||||
do
|
||||
local cache
|
||||
function private.data.get()
|
||||
function get_data()
|
||||
if not cache then
|
||||
local dataset = persistence.dataset
|
||||
cache = dataset.history or t
|
||||
@@ -23,7 +23,7 @@ end
|
||||
|
||||
do
|
||||
local cache = 0
|
||||
function private.next_push.get()
|
||||
function get_next_push()
|
||||
if time() > cache then
|
||||
local date = date('*t')
|
||||
date.hour, date.min, date.sec = 24, 0, 0
|
||||
@@ -33,11 +33,11 @@ do
|
||||
end
|
||||
end
|
||||
|
||||
function private.new_record.get()
|
||||
function get_new_record()
|
||||
return T('next_push', next_push, 'data_points', t)
|
||||
end
|
||||
|
||||
function private.read_record(item_key)
|
||||
function read_record(item_key)
|
||||
local record = data[item_key] and persistence.read(history_schema, data[item_key]) or new_record
|
||||
if record.next_push <= time() then
|
||||
push_record(record)
|
||||
@@ -46,7 +46,7 @@ function private.read_record(item_key)
|
||||
return record
|
||||
end
|
||||
|
||||
function private.write_record(item_key, record)
|
||||
function write_record(item_key, record)
|
||||
value_cache[item_key] = nil
|
||||
data[item_key] = persistence.write(history_schema, record)
|
||||
end
|
||||
@@ -105,7 +105,7 @@ function calculate_market_value(item_record)
|
||||
return item_record.daily_min_buyout and min(ceil(item_record.daily_min_buyout * 1.15), item_record.daily_max_price)
|
||||
end
|
||||
|
||||
function private.weighted_median(list)
|
||||
function weighted_median(list)
|
||||
sort(list, function(a,b) return a.value < b.value end)
|
||||
local weight = 0
|
||||
for _, element in list do
|
||||
@@ -116,7 +116,7 @@ function private.weighted_median(list)
|
||||
end
|
||||
end
|
||||
|
||||
function private.push_record(item_record)
|
||||
function push_record(item_record)
|
||||
for market_value in present(calculate_market_value(item_record)) do
|
||||
tinsert(item_record.data_points, 1, T('market_value', market_value, 'time', item_record.next_push))
|
||||
while getn(item_record.data_points) > 11 do
|
||||
|
||||
+2
-2
@@ -8,7 +8,7 @@ local stack = require 'aux.core.stack'
|
||||
|
||||
local state
|
||||
|
||||
function private.process()
|
||||
function process()
|
||||
if state.posted < state.count then
|
||||
|
||||
local stacking_complete
|
||||
@@ -29,7 +29,7 @@ function private.process()
|
||||
return stop()
|
||||
end
|
||||
|
||||
function private.post_auction(slot, k)
|
||||
function post_auction(slot, k)
|
||||
local item_info = info.container_item(unpack(slot))
|
||||
if item_info.item_key == state.item_key and info.auctionable(item_info.tooltip) and item_info.aux_quantity == state.stack_size then
|
||||
|
||||
|
||||
+14
-14
@@ -37,14 +37,14 @@ do
|
||||
end
|
||||
end
|
||||
|
||||
function private.complete()
|
||||
function complete()
|
||||
local on_complete = state.params.on_complete
|
||||
scan_states[state.params.type] = nil
|
||||
-- for _ in on_complete or nop do end TODO test performance
|
||||
do (on_complete or nop)() end
|
||||
end
|
||||
|
||||
function private.state.get()
|
||||
function get_state()
|
||||
for _, state in scan_states do
|
||||
if state.id == thread_id then
|
||||
return state
|
||||
@@ -53,11 +53,11 @@ do
|
||||
end
|
||||
end
|
||||
|
||||
function private.query.get()
|
||||
function get_query()
|
||||
return state.params.queries[state.query_index]
|
||||
end
|
||||
|
||||
private.wait_for_callback = vararg-function(arg)
|
||||
wait_for_callback = vararg-function(arg)
|
||||
local send_signal, signal_received = signal()
|
||||
local suspended, ret
|
||||
|
||||
@@ -76,17 +76,17 @@ private.wait_for_callback = vararg-function(arg)
|
||||
return when(signal_received, function() return k(unpack(signal_received())) end)
|
||||
end
|
||||
|
||||
function private.total_pages(total_auctions)
|
||||
function total_pages(total_auctions)
|
||||
return ceil(total_auctions / PAGE_SIZE)
|
||||
end
|
||||
|
||||
function private.last_page(total_auctions)
|
||||
function last_page(total_auctions)
|
||||
local last_page = max(total_pages(total_auctions) - 1, 0)
|
||||
local last_page_limit = query.blizzard_query and query.blizzard_query.last_page or last_page
|
||||
return min(last_page_limit, last_page)
|
||||
end
|
||||
|
||||
function private.scan()
|
||||
function scan()
|
||||
state.query_index = state.query_index and state.query_index + 1 or 1
|
||||
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
|
||||
@@ -100,11 +100,11 @@ function private.scan()
|
||||
end
|
||||
end
|
||||
|
||||
function private.process_query()
|
||||
function process_query()
|
||||
return (query.blizzard_query and submit_query or scan_page)()
|
||||
end
|
||||
|
||||
function private.submit_query()
|
||||
function submit_query()
|
||||
when(function() return state.params.type ~= 'list' or CanSendAuctionQuery() end, function()
|
||||
do (state.params.on_submit_query or nop)() end
|
||||
state.last_query_time = GetTime()
|
||||
@@ -130,7 +130,7 @@ function private.submit_query()
|
||||
end)
|
||||
end
|
||||
|
||||
function private.scan_page(i)
|
||||
function scan_page(i)
|
||||
i = i or 1
|
||||
local recurse = function(retry)
|
||||
if i >= PAGE_SIZE then
|
||||
@@ -175,7 +175,7 @@ function private.scan_page(i)
|
||||
return recurse()
|
||||
end
|
||||
|
||||
function private.wait_for_results()
|
||||
function wait_for_results()
|
||||
local timeout = later(state.last_query_time, 10)
|
||||
local send_signal, signal_received = signal()
|
||||
when(signal_received, function()
|
||||
@@ -204,7 +204,7 @@ function private.wait_for_results()
|
||||
end
|
||||
end
|
||||
|
||||
function private.wait_for_owner_results(send_signal)
|
||||
function wait_for_owner_results(send_signal)
|
||||
if state.page == current_owner_page then
|
||||
return send_signal()
|
||||
else
|
||||
@@ -212,7 +212,7 @@ function private.wait_for_owner_results(send_signal)
|
||||
end
|
||||
end
|
||||
|
||||
function private.wait_for_list_results(send_signal, signal_received)
|
||||
function wait_for_list_results(send_signal, signal_received)
|
||||
local updated, last_update
|
||||
event_listener('AUCTION_ITEM_LIST_UPDATE', function(kill)
|
||||
kill(signal_received())
|
||||
@@ -228,7 +228,7 @@ function private.wait_for_list_results(send_signal, signal_received)
|
||||
end, send_signal)
|
||||
end
|
||||
|
||||
function private.owner_data_complete(type)
|
||||
function owner_data_complete(type)
|
||||
for i = 1, PAGE_SIZE do
|
||||
local auction_info = info.auction(i, type)
|
||||
if auction_info and not auction_info.owner then
|
||||
|
||||
+15
-15
@@ -6,7 +6,7 @@ include 'aux'
|
||||
local persistence = require 'aux.util.persistence'
|
||||
local cache = require 'aux.core.cache'
|
||||
|
||||
aux_ignore_owner = true
|
||||
_G.aux_ignore_owner = true
|
||||
|
||||
SLASH_AUX1 = '/aux'
|
||||
function SlashCmdList.AUX(command)
|
||||
@@ -19,44 +19,44 @@ function SlashCmdList.AUX(command)
|
||||
persistence.dataset.post = nil
|
||||
print 'Post settings cleared.'
|
||||
elseif arguments[1] == 'clear' and arguments[2] == 'datasets' then
|
||||
aux_datasets = t
|
||||
_G.aux_datasets = t
|
||||
print 'Datasets cleared.'
|
||||
elseif arguments[1] == 'clear' and arguments[2] == 'merchant' and arguments[3] == 'buy' then
|
||||
aux_merchant_buy = t
|
||||
_G.aux_merchant_buy = t
|
||||
print 'Merchant buy prices cleared.'
|
||||
elseif arguments[1] == 'clear' and arguments[2] == 'merchant' and arguments[3] == 'sell' then
|
||||
aux_merchant_sell = t
|
||||
_G.aux_merchant_sell = t
|
||||
print 'Merchant sell prices cleared.'
|
||||
elseif arguments[1] == 'clear' and arguments[2] == 'item' and arguments[3] == 'cache' then
|
||||
aux_items = t
|
||||
aux_item_ids = t
|
||||
aux_auctionable_items = t
|
||||
_G.aux_items = t
|
||||
_G.aux_item_ids = t
|
||||
_G.aux_auctionable_items = t
|
||||
print 'Item cache cleared.'
|
||||
elseif arguments[1] == 'populate' and arguments[2] == 'wdb' then
|
||||
cache.populate_wdb()
|
||||
elseif arguments[1] == 'tooltip' and arguments[2] == 'value' then
|
||||
aux_tooltip_value = not aux_tooltip_value
|
||||
_G.aux_tooltip_value = not aux_tooltip_value
|
||||
print('Historical value in tooltip ' .. (aux_tooltip_value and 'enabled' or 'disabled') .. '.')
|
||||
elseif arguments[1] == 'tooltip' and arguments[2] == 'daily' then
|
||||
aux_tooltip_daily = not aux_tooltip_daily
|
||||
_G.aux_tooltip_daily = not aux_tooltip_daily
|
||||
print('Market value in tooltip ' .. (aux_tooltip_daily and 'enabled' or 'disabled') .. '.')
|
||||
elseif arguments[1] == 'tooltip' and arguments[2] == 'vendor' and arguments[3] == 'buy' then
|
||||
aux_tooltip_vendor_buy = not aux_tooltip_vendor_buy
|
||||
_G.aux_tooltip_vendor_buy = not aux_tooltip_vendor_buy
|
||||
print('Vendor buy price in tooltip ' .. (aux_tooltip_vendor_buy and 'enabled' or 'disabled') .. '.')
|
||||
elseif arguments[1] == 'tooltip' and arguments[2] == 'vendor' and arguments[3] == 'sell' then
|
||||
aux_tooltip_vendor_sell = not aux_tooltip_vendor_sell
|
||||
_G.aux_tooltip_vendor_sell = not aux_tooltip_vendor_sell
|
||||
print('Vendor sell price in tooltip ' .. (aux_tooltip_vendor_sell and 'enabled' or 'disabled') .. '.')
|
||||
elseif arguments[1] == 'tooltip' and arguments[2] == 'disenchant' and arguments[3] == 'value' then
|
||||
aux_tooltip_disenchant_value = not aux_tooltip_disenchant_value
|
||||
_G.aux_tooltip_disenchant_value = not aux_tooltip_disenchant_value
|
||||
print('Disenchant value in tooltip ' .. (aux_tooltip_disenchant_value and 'enabled' or 'disabled') .. '.')
|
||||
elseif arguments[1] == 'tooltip' and arguments[2] == 'disenchant' and arguments[3] == 'distribution' then
|
||||
aux_tooltip_disenchant_distribution = not aux_tooltip_disenchant_distribution
|
||||
_G.aux_tooltip_disenchant_distribution = not aux_tooltip_disenchant_distribution
|
||||
print('Disenchant distribution in tooltip ' .. (aux_tooltip_disenchant_distribution and 'enabled' or 'disabled') .. '.')
|
||||
elseif arguments[1] == 'tooltip' and arguments[2] == 'disenchant' and arguments[3] == 'source' then
|
||||
aux_tooltip_disenchant_source = not aux_tooltip_disenchant_source
|
||||
_G.aux_tooltip_disenchant_source = not aux_tooltip_disenchant_source
|
||||
print('Disenchant source in tooltip ' .. (aux_tooltip_disenchant_source and 'enabled' or 'disabled') .. '.')
|
||||
elseif arguments[1] == 'ignore' and arguments[2] == 'owner' then
|
||||
aux_ignore_owner = not aux_ignore_owner
|
||||
_G.aux_ignore_owner = not aux_ignore_owner
|
||||
print('Ignoring of owner ' .. (aux_ignore_owner and 'enabled' or 'disabled') .. '.')
|
||||
elseif arguments[1] == 'chars' and arguments[2] == 'add' then
|
||||
local realm = GetCVar('realmName')
|
||||
|
||||
+10
-10
@@ -7,27 +7,27 @@ local info = require 'aux.util.info'
|
||||
|
||||
local state
|
||||
|
||||
function private.stack_size(slot)
|
||||
function stack_size(slot)
|
||||
local container_item_info = info.container_item(unpack(slot))
|
||||
return container_item_info and container_item_info.count or 0
|
||||
end
|
||||
|
||||
function private.charges(slot)
|
||||
function charges(slot)
|
||||
local container_item_info = info.container_item(unpack(slot))
|
||||
return container_item_info and container_item_info.charges
|
||||
end
|
||||
|
||||
function private.max_stack(slot)
|
||||
function max_stack(slot)
|
||||
local container_item_info = info.container_item(unpack(slot))
|
||||
return container_item_info and container_item_info.max_stack
|
||||
end
|
||||
|
||||
function private.locked(slot)
|
||||
function locked(slot)
|
||||
local container_item_info = info.container_item(unpack(slot))
|
||||
return container_item_info and container_item_info.locked
|
||||
end
|
||||
|
||||
function private.find_item_slot(papply)
|
||||
function find_item_slot(papply)
|
||||
for slot in info.inventory do
|
||||
if matching_item(slot, papply) and not eq(slot, state.target_slot) then
|
||||
return slot
|
||||
@@ -35,12 +35,12 @@ function private.find_item_slot(papply)
|
||||
end
|
||||
end
|
||||
|
||||
function private.matching_item(slot, papply)
|
||||
function matching_item(slot, papply)
|
||||
local item_info = info.container_item(unpack(slot))
|
||||
return item_info and item_info.item_key == state.item_key and info.auctionable(item_info.tooltip) and (not papply or item_info.count < item_info.max_stack)
|
||||
end
|
||||
|
||||
function private.find_empty_slot()
|
||||
function find_empty_slot()
|
||||
for slot, type in info.inventory do
|
||||
if type == 1 and not GetContainerItemInfo(unpack(slot)) then
|
||||
return slot
|
||||
@@ -48,7 +48,7 @@ function private.find_empty_slot()
|
||||
end
|
||||
end
|
||||
|
||||
function private.find_charge_item_slot()
|
||||
function find_charge_item_slot()
|
||||
for slot in info.inventory do
|
||||
if matching_item(slot) and charges(slot) == state.target_size then
|
||||
return slot
|
||||
@@ -56,7 +56,7 @@ function private.find_charge_item_slot()
|
||||
end
|
||||
end
|
||||
|
||||
function private.move_item(from_slot, to_slot, amount, k)
|
||||
function move_item(from_slot, to_slot, amount, k)
|
||||
if locked(from_slot) or locked(to_slot) then
|
||||
return wait(k)
|
||||
end
|
||||
@@ -71,7 +71,7 @@ function private.move_item(from_slot, to_slot, amount, k)
|
||||
return when(function() return stack_size(to_slot) == expected_size end, k)
|
||||
end
|
||||
|
||||
function private.process()
|
||||
function process()
|
||||
if not state.target_slot or not matching_item(state.target_slot) then
|
||||
state.target_slot = find_item_slot()
|
||||
if not state.target_slot then
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@ local disenchant = require 'aux.core.disenchant'
|
||||
local history = require 'aux.core.history'
|
||||
local auction_listing = require 'aux.gui.auction_listing'
|
||||
|
||||
aux_tooltip_value = true
|
||||
_G.aux_tooltip_value = true
|
||||
|
||||
local game_tooltip_hooks, game_tooltip_money = t, 0
|
||||
|
||||
|
||||
Reference in New Issue
Block a user