big refactoring

This commit is contained in:
Manuel Simon Hirsig
2016-08-21 06:17:53 +02:00
parent e94eaac52c
commit 40753f2ac5
31 changed files with 709 additions and 742 deletions
+20 -20
View File
@@ -16,17 +16,17 @@ g.aux_characters = {}
function LOAD()
scan_wdb()
aux.control.event_listener('MERCHANT_SHOW', on_merchant_show)
aux.control.event_listener('MERCHANT_CLOSED', on_merchant_closed)
aux.control.event_listener('MERCHANT_UPDATE', on_merchant_update)
aux.control.event_listener('BAG_UPDATE', on_bag_update)
control.event_listener('MERCHANT_SHOW', on_merchant_show)
control.event_listener('MERCHANT_CLOSED', on_merchant_closed)
control.event_listener('MERCHANT_UPDATE', on_merchant_update)
control.event_listener('BAG_UPDATE', on_bag_update)
CreateFrame('Frame', nil, MerchantFrame):SetScript('OnUpdate', merchant_on_update)
aux.control.event_listener('NEW_AUCTION_UPDATE', function()
for _, info in {aux.info.auction_sell_item()} do
for _, item_id in {aux.cache.item_id(info.name)} do
g.aux_merchant_sell[aux.cache.item_id(info.name)] = info.vendor_price / (aux.info.max_item_charges(item_id) or info.count)
control.event_listener('NEW_AUCTION_UPDATE', function()
for _, info in {info.auction_sell_item()} do
for _, item_id in {cache.item_id(info.name)} do
g.aux_merchant_sell[cache.item_id(info.name)] = info.vendor_price / (info.max_item_charges(item_id) or info.count)
end
end
end)
@@ -79,7 +79,7 @@ end
function public.merchant_info(item_id)
local buy_info
if g.aux_merchant_buy[item_id] then
buy_info = aux.persistence.read(merchant_buy_schema, g.aux_merchant_buy[item_id])
buy_info = persistence.read(merchant_buy_schema, g.aux_merchant_buy[item_id])
end
return g.aux_merchant_sell[item_id], buy_info and buy_info.unit_price, buy_info and buy_info.limited
@@ -88,7 +88,7 @@ end
function public.item_info(item_id)
local data_string = g.aux_items[item_id]
if data_string then
local cached_data = aux.persistence.read(items_schema, data_string)
local cached_data = persistence.read(items_schema, data_string)
return {
name = cached_data.name,
itemstring = 'item:'..item_id..':0:0:0',
@@ -114,10 +114,10 @@ function merchant_buy_scan()
local _, _, price, count, stock = GetMerchantItemInfo(i)
local link = GetMerchantItemLink(i)
if link then
local item_id = aux.info.parse_link(link)
local item_id = info.parse_link(link)
local new_unit_price, new_limited = price / count, stock >= 0
if g.aux_merchant_buy[item_id] then
local buy_info = aux.persistence.read(merchant_buy_schema, g.aux_merchant_buy[item_id])
local buy_info = persistence.read(merchant_buy_schema, g.aux_merchant_buy[item_id])
local unit_price
if buy_info.limited and not new_limited then
@@ -128,12 +128,12 @@ function merchant_buy_scan()
unit_price = min(buy_info.unit_price, new_unit_price)
end
g.aux_merchant_buy[item_id] = aux.persistence.write(merchant_buy_schema, {
g.aux_merchant_buy[item_id] = persistence.write(merchant_buy_schema, {
unit_price = unit_price,
limited = buy_info.limited and new_limited,
})
else
g.aux_merchant_buy[item_id] = aux.persistence.write(merchant_buy_schema, {
g.aux_merchant_buy[item_id] = persistence.write(merchant_buy_schema, {
unit_price = new_unit_price,
limited = new_limited,
})
@@ -148,7 +148,7 @@ end
function merchant_sell_scan()
for slot in inventory do
local item_info = aux.info.container_item(unpack(slot))
local item_info = info.container_item(unpack(slot))
if item_info then
g.aux_merchant_sell[item_info.item_id] = item_info.tooltip_money / item_info.aux_quantity
end
@@ -164,7 +164,7 @@ function scan_wdb(item_id)
local name, _, quality, level, class, subclass, max_stack, slot, texture = GetItemInfo(itemstring)
if name and not g.aux_item_ids[strlower(name)] then
g.aux_item_ids[strlower(name)] = item_id
g.aux_items[item_id] = aux.persistence.write(items_schema, {
g.aux_items[item_id] = persistence.write(items_schema, {
name = name,
quality = quality,
level = level,
@@ -174,8 +174,8 @@ function scan_wdb(item_id)
max_stack = max_stack,
texture = texture,
})
local tooltip = aux.info.tooltip(function(tt) tt:SetHyperlink(itemstring) end)
if aux.info.auctionable(tooltip, quality) then
local tooltip = info.tooltip(function(tt) tt:SetHyperlink(itemstring) end)
if info.auctionable(tooltip, quality) then
tinsert(g.aux_auctionable_items, strlower(name))
end
processed = processed + 1
@@ -185,7 +185,7 @@ function scan_wdb(item_id)
if item_id <= MAX_ITEM_ID then
local t0 = GetTime()
aux.control.thread(aux.control.when, function() return GetTime() - t0 > 0.1 end, scan_wdb, item_id)
control.thread(control.when, function() return GetTime() - t0 > 0.1 end, scan_wdb, item_id)
else
sort(g.aux_auctionable_items, function(a, b) return strlen(a) < strlen(b) or (strlen(a) == strlen(b) and a < b) end)
end
@@ -204,5 +204,5 @@ function public.populate_wdb(item_id)
AuxTooltip:SetHyperlink('item:'..item_id)
end
aux.control.thread(populate_wdb, item_id + 1)
control.thread(populate_wdb, item_id + 1)
end
+1 -1
View File
@@ -73,7 +73,7 @@ end
function public.value(slot, quality, level)
local expectation
for _, event in m.distribution(slot, quality, level) do
local value = aux.history.value(event.item_id..':'..0)
local value = history.value(event.item_id..':'..0)
if not value then
return
else
+3 -3
View File
@@ -14,7 +14,7 @@ function new_record()
end
function load_data()
local dataset = aux.persistence.load_dataset()
local dataset = persistence.load_dataset()
dataset.history = dataset.history or {}
return dataset.history
end
@@ -24,7 +24,7 @@ function read_record(item_key)
local record
if data[item_key] then
record = aux.persistence.read(history_schema, data[item_key])
record = persistence.read(history_schema, data[item_key])
else
record = m.new_record()
end
@@ -40,7 +40,7 @@ end
function write_record(item_key, record)
m.value_cache[item_key] = nil
local data = m.load_data()
data[item_key] = aux.persistence.write(history_schema, record)
data[item_key] = persistence.write(history_schema, record)
end
function public.process_auction(auction_record)
+8 -8
View File
@@ -8,7 +8,7 @@ function process()
local stacking_complete
local send_signal, signal_received = signal()
aux.control.when(signal_received, function()
control.when(signal_received, function()
local slot = signal_received()[1]
if slot then
return m.post_auction(slot, m.process)
@@ -17,15 +17,15 @@ function process()
end
end)
return aux.stack.start(m.state.item_key, m.state.stack_size, send_signal)
return stack.start(m.state.item_key, m.state.stack_size, send_signal)
end
return m.stop()
end
function post_auction(slot, k)
local item_info = aux.info.container_item(unpack(slot))
if item_info.item_key == m.state.item_key and aux.info.auctionable(item_info.tooltip) and item_info.aux_quantity == m.state.stack_size then
local item_info = info.container_item(unpack(slot))
if item_info.item_key == m.state.item_key and info.auctionable(item_info.tooltip) and item_info.aux_quantity == m.state.stack_size then
ClearCursor()
ClickAuctionSellItemButton()
@@ -37,13 +37,13 @@ function post_auction(slot, k)
StartAuction(max(1, round(m.state.unit_start_price * item_info.aux_quantity)), round(m.state.unit_buyout_price * item_info.aux_quantity), m.state.duration)
local send_signal, signal_received = signal()
aux.control.when(signal_received, function()
control.when(signal_received, function()
m.state.posted = m.state.posted + 1
return k()
end)
local posted
aux.control.event_listener('CHAT_MSG_SYSTEM', function(kill)
control.event_listener('CHAT_MSG_SYSTEM', function(kill)
if arg1 == ERR_AUCTION_STARTED then
send_signal()
kill()
@@ -56,7 +56,7 @@ end
function public.stop()
if m.state then
aux.control.kill_thread(m.state.thread_id)
control.kill_thread(m.state.thread_id)
local callback = m.state.callback
local posted = m.state.posted
@@ -72,7 +72,7 @@ end
function public.start(item_key, stack_size, duration, unit_start_price, unit_buyout_price, count, callback)
m.stop()
local thread_id = aux.control.thread(m.process)
local thread_id = control.thread(m.process)
m.state = {
thread_id = thread_id,
+18 -18
View File
@@ -9,7 +9,7 @@ do
for _, old_state in {scan_states[params.type]} do
abort(old_state.id)
end
local thread_id = aux.control.thread(L(wait_for_callback, params.on_scan_start, scan))
local thread_id = control.thread(L(wait_for_callback, params.on_scan_start, scan))
scan_states[params.type] = {
id = thread_id,
params = params,
@@ -21,7 +21,7 @@ do
local aborted = {}
for type, state in scan_states do
if not scan_id or state.id == scan_id then
aux.control.kill_thread(state.id)
control.kill_thread(state.id)
scan_states[type] = nil
tinsert(aborted, state)
end
@@ -38,7 +38,7 @@ do
end
function accessor.state()
local _, state = next(filter(scan_states, function(state) return state.id == aux.control.thread_id end))
local _, state = next(filter(scan_states, function(state) return state.id == control.thread_id end))
return state
end
end
@@ -66,7 +66,7 @@ function wait_for_callback(...)
send_signal()
end
return aux.control.when(signal_received, function() return k(unpack(signal_received())) end)
return control.when(signal_received, function() return k(unpack(signal_received())) end)
end
function total_pages(total_auctions)
@@ -102,7 +102,7 @@ function process_query()
end
function submit_query()
aux.control.when(function() return state.params.type ~= 'list' or CanSendAuctionQuery() end, function()
control.when(function() return state.params.type ~= 'list' or CanSendAuctionQuery() end, function()
call(state.params.on_submit_query)
state.last_query_time = GetTime()
if state.params.type == 'bidder' then
@@ -144,20 +144,20 @@ function scan_page(i)
end
end
local auction_info = aux.info.auction(i, state.params.type)
local auction_info = info.auction(i, state.params.type)
if auction_info and (auction_info.owner or state.params.ignore_owner or g.aux_ignore_owner) then
auction_info.index = i
auction_info.page = state.page
auction_info.blizzard_query = query.blizzard_query
auction_info.query_type = state.params.type
aux.history.process_auction(auction_info)
history.process_auction(auction_info)
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, L(send_signal, true))
return aux.control.thread(aux.control.when, later(GetTime(), 10), L(send_signal, false))
control.when(signal_received, recurse)
place_bid(auction_info.query_type, auction_info.index, auction_info.buyout_price, L(send_signal, true))
return control.thread(control.when, later(GetTime(), 10), L(send_signal, false))
elseif not query.validator or query.validator(auction_info) then
return wait_for_callback(state.params.on_auction, auction_info, function(removed)
if removed then
@@ -175,7 +175,7 @@ end
function wait_for_results()
local timeout = later(state.last_query_time, 10)
local send_signal, signal_received = signal()
aux.control.when(signal_received, function()
control.when(signal_received, function()
if timeout() then
return submit_query()
else
@@ -190,10 +190,10 @@ function wait_for_results()
end
end)
aux.control.thread(aux.control.when, timeout, send_signal)
control.thread(control.when, timeout, send_signal)
if state.params.type == 'bidder' then
return aux.control.thread(aux.control.when, function() return aux.bids_loaded end, send_signal)
return control.thread(control.when, function() return bids_loaded end, send_signal)
elseif state.params.type == 'owner' then
return wait_for_owner_results(send_signal)
elseif state.params.type == 'list' then
@@ -202,22 +202,22 @@ function wait_for_results()
end
function wait_for_owner_results(send_signal)
if state.page == aux.current_owner_page then
if state.page == current_owner_page then
return send_signal()
else
return aux.control.on_next_event('AUCTION_OWNED_LIST_UPDATE', send_signal)
return control.on_next_event('AUCTION_OWNED_LIST_UPDATE', send_signal)
end
end
function wait_for_list_results(send_signal, signal_received)
local updated, last_update
aux.control.event_listener('AUCTION_ITEM_LIST_UPDATE', function(kill)
control.event_listener('AUCTION_ITEM_LIST_UPDATE', function(kill)
kill(signal_received())
last_update = GetTime()
updated = true
end)
local ignore_owner = state.params.ignore_owner or g.aux_ignore_owner
return aux.control.thread(aux.control.when, function()
return control.thread(control.when, function()
-- short circuiting order important, owner_data_complete must be called iif an update has happened.
local ok = updated and (ignore_owner or owner_data_complete('list')) or last_update and GetTime() - last_update > 5
updated = false
@@ -227,7 +227,7 @@ end
function owner_data_complete(type)
for i=1,PAGE_SIZE do
local auction_info = aux.info.auction(i, type)
local auction_info = info.auction(i, type)
if auction_info and not auction_info.owner then
return false
end
+3 -3
View File
@@ -3,10 +3,10 @@ function SlashCmdList.AUX(command)
if not command then return end
local arguments = tokenize(command)
if arguments[1] == 'clear' and arguments[2] == 'history' then
aux.persistence.load_dataset().history = nil
persistence.load_dataset().history = nil
log 'History cleared.'
elseif arguments[1] == 'clear' and arguments[2] == 'post' then
aux.persistence.load_dataset().post = nil
persistence.load_dataset().post = nil
log 'Post settings cleared.'
elseif arguments[1] == 'clear' and arguments[2] == 'datasets' then
g.aux_datasets = {}
@@ -23,7 +23,7 @@ function SlashCmdList.AUX(command)
g.aux_auctionable_items = {}
log 'Item cache cleared.'
elseif arguments[1] == 'populate' and arguments[2] == 'wdb' then
aux.cache.populate_wdb()
cache.populate_wdb()
elseif arguments[1] == 'tooltip' and arguments[2] == 'value' then
g.aux_tooltip_value = not g.aux_tooltip_value
log('Historical value in tooltip '..(g.aux_tooltip_value and 'enabled' or 'disabled')..'.')
+10 -10
View File
@@ -3,22 +3,22 @@ aux.module 'stack'
state = nil
function stack_size(slot)
local container_item_info = aux.info.container_item(unpack(slot))
local container_item_info = info.container_item(unpack(slot))
return container_item_info and container_item_info.count or 0
end
function charges(slot)
local container_item_info = aux.info.container_item(unpack(slot))
local container_item_info = info.container_item(unpack(slot))
return container_item_info and container_item_info.charges
end
function max_stack(slot)
local container_item_info = aux.info.container_item(unpack(slot))
local container_item_info = info.container_item(unpack(slot))
return container_item_info and container_item_info.max_stack
end
function locked(slot)
local container_item_info = aux.info.container_item(unpack(slot))
local container_item_info = info.container_item(unpack(slot))
return container_item_info and container_item_info.locked
end
@@ -31,8 +31,8 @@ function find_item_slot(partial)
end
function matching_item(slot, partial)
local item_info = aux.info.container_item(unpack(slot))
return item_info and item_info.item_key == m.state.item_key and aux.info.auctionable(item_info.tooltip) and (not partial or item_info.count < item_info.max_stack)
local item_info = info.container_item(unpack(slot))
return item_info and item_info.item_key == m.state.item_key and info.auctionable(item_info.tooltip) and (not partial or item_info.count < item_info.max_stack)
end
function find_empty_slot()
@@ -53,7 +53,7 @@ end
function move_item(from_slot, to_slot, amount, k)
if m.locked(from_slot) or m.locked(to_slot) then
return aux.control.wait(k)
return control.wait(k)
end
amount = min(m.max_stack(from_slot) - m.stack_size(to_slot), m.stack_size(from_slot), amount)
@@ -63,7 +63,7 @@ function move_item(from_slot, to_slot, amount, k)
SplitContainerItem(from_slot[1], from_slot[2], amount)
PickupContainerItem(unpack(to_slot))
return aux.control.when(function() return m.stack_size(to_slot) == expected_size end, k)
return control.when(function() return m.stack_size(to_slot) == expected_size end, k)
end
function process()
@@ -105,7 +105,7 @@ end
function public.stop()
if m.state then
aux.control.kill_thread(m.state.thread_id)
control.kill_thread(m.state.thread_id)
local callback, slot = m.state.callback, m.state.target_slot
if slot and not m.matching_item(slot) then
slot = nil
@@ -118,7 +118,7 @@ end
function public.start(item_key, size, callback)
m.stop()
local thread_id = aux.control.thread(m.process)
local thread_id = control.thread(m.process)
m.state = {
thread_id = thread_id,
item_key = item_key,
+20 -20
View File
@@ -9,12 +9,12 @@ game_tooltip_money = nil
function LOAD()
for func, hook in game_tooltip_hooks do
local func, hook = func, hook
aux.hook(
hook(
func,
function(...)
hooked_setter = true
game_tooltip_money = 0
local results = {aux.orig[GameTooltip][func](unpack(arg)) }
local results = {orig[GameTooltip][func](unpack(arg)) }
hooked_setter = false
hook(unpack(arg))
return unpack(results)
@@ -44,13 +44,13 @@ function LOAD()
end
function extend_tooltip(tooltip, link, quantity)
local item_id, suffix_id = aux.info.parse_link(link)
local item_id, suffix_id = info.parse_link(link)
quantity = IsShiftKeyDown() and quantity or 1
if g.aux_tooltip_disenchant_source then
local color = {r=0.7, g=0.7, b=0.7}
local type, range = aux.disenchant.source(item_id)
local type, range = disenchant.source(item_id)
if type == 'CRYSTAL' then
tooltip:AddLine(format('Can disenchant from level %s |cffa335eeEpic|r and |cff0070ddRare|r items.', range), color.r, color.g, color.b, true)
@@ -63,9 +63,9 @@ function extend_tooltip(tooltip, link, quantity)
end
end
local item_info = aux.info.item(item_id)
local item_info = info.item(item_id)
if item_info then
local distribution = aux.disenchant.distribution(item_info.slot, item_info.quality, item_info.level)
local distribution = disenchant.distribution(item_info.slot, item_info.quality, item_info.level)
if getn(distribution) > 0 then
@@ -75,15 +75,15 @@ function extend_tooltip(tooltip, link, quantity)
tooltip:AddLine('Disenchants into:', color.r, color.g, color.b)
sort(distribution, function(a,b) return a.probability > b.probability end)
for _, event in distribution do
tooltip:AddLine(format(' %s%% %s (%s-%s)', event.probability * 100, aux.info.display_name(event.item_id, true) or 'item:'..event.item_id, event.min_quantity, event.max_quantity), color.r, color.g, color.b)
tooltip:AddLine(format(' %s%% %s (%s-%s)', event.probability * 100, info.display_name(event.item_id, true) or 'item:'..event.item_id, event.min_quantity, event.max_quantity), color.r, color.g, color.b)
end
end
if g.aux_tooltip_disenchant_value then
local color = {r=0.1, g=0.6, b=0.6}
local disenchant_value = aux.disenchant.value(item_info.slot, item_info.quality, item_info.level)
tooltip:AddLine('Disenchant Value: '..(disenchant_value and aux.money.to_string2(disenchant_value) or GRAY_FONT_COLOR_CODE..'---'..FONT_COLOR_CODE_CLOSE), color.r, color.g, color.b)
local disenchant_value = disenchant.value(item_info.slot, item_info.quality, item_info.level)
tooltip:AddLine('Disenchant Value: '..(disenchant_value and money.to_string2(disenchant_value) or GRAY_FONT_COLOR_CODE..'---'..FONT_COLOR_CODE_CLOSE), color.r, color.g, color.b)
end
end
end
@@ -91,33 +91,33 @@ function extend_tooltip(tooltip, link, quantity)
if g.aux_tooltip_vendor_buy then
local color = {r=0.8, g=0.5, b=0.1}
local _, price, limited = aux.cache.merchant_info(item_id)
local _, price, limited = cache.merchant_info(item_id)
if price then
tooltip:AddLine('Vendor Buy '..(limited and '(limited): ' or ': ')..aux.money.to_string2(price * quantity), color.r, color.g, color.b)
tooltip:AddLine('Vendor Buy '..(limited and '(limited): ' or ': ')..money.to_string2(price * quantity), color.r, color.g, color.b)
end
end
if g.aux_tooltip_vendor_sell then
local color = {r=0.8, g=0.5, b=0.1}
local price = aux.cache.merchant_info(item_id)
local price = cache.merchant_info(item_id)
if price ~= 0 then
tooltip:AddLine('Vendor Sell: '..(price and aux.money.to_string2(price * quantity) or GRAY_FONT_COLOR_CODE..'---'..FONT_COLOR_CODE_CLOSE), color.r, color.g, color.b)
tooltip:AddLine('Vendor Sell: '..(price and money.to_string2(price * quantity) or GRAY_FONT_COLOR_CODE..'---'..FONT_COLOR_CODE_CLOSE), color.r, color.g, color.b)
end
end
local color = {r=1, g=1, b=0.6}
local auctionable = not item_info or aux.info.auctionable(aux.info.tooltip(function(tt) tt:SetHyperlink(item_info.itemstring) end), item_info.quality)
local auctionable = not item_info or info.auctionable(info.tooltip(function(tt) tt:SetHyperlink(item_info.itemstring) end), item_info.quality)
local item_key = (item_id or 0)..':'..(suffix_id or 0)
local value = aux.history.value(item_key)
local value = history.value(item_key)
if auctionable then
if g.aux_tooltip_value then
tooltip:AddLine('Value: '..(value and aux.money.to_string2(value * quantity) or GRAY_FONT_COLOR_CODE..'---'..FONT_COLOR_CODE_CLOSE), color.r, color.g, color.b)
tooltip:AddLine('Value: '..(value and money.to_string2(value * quantity) or GRAY_FONT_COLOR_CODE..'---'..FONT_COLOR_CODE_CLOSE), color.r, color.g, color.b)
end
if g.aux_tooltip_daily then
local market_value = aux.history.market_value(item_key)
tooltip:AddLine('Today: '..(market_value and aux.money.to_string2(market_value * quantity)..' ('..aux.auction_listing.percentage_historical(round(market_value / value * 100))..')' or GRAY_FONT_COLOR_CODE..'---'..FONT_COLOR_CODE_CLOSE), color.r, color.g, color.b)
local market_value = history.market_value(item_key)
tooltip:AddLine('Today: '..(market_value and money.to_string2(market_value * quantity)..' ('..auction_listing.percentage_historical(round(market_value / value * 100))..')' or GRAY_FONT_COLOR_CODE..'---'..FONT_COLOR_CODE_CLOSE), color.r, color.g, color.b)
end
end
@@ -179,7 +179,7 @@ end
function game_tooltip_hooks:SetInboxItem(index)
local name, _, quantity = GetInboxItem(index)
local id = name and aux.cache.item_id(name)
local id = name and cache.item_id(name)
if id then
local _, itemstring, quality = GetItemInfo(id)
local _, _, _, hex = GetItemQualityColor(tonumber(quality))
@@ -243,7 +243,7 @@ function game_tooltip_hooks:SetAuctionSellItem()
if name then
for slot in inventory do
local link = GetContainerItemLink(unpack(slot))
if link and ({aux.info.parse_link(link)})[5] == name then
if link and ({info.parse_link(link)})[5] == name then
extend_tooltip(GameTooltip, link, quantity)
return
end