refactoring

This commit is contained in:
Manuel Simon Hirsig
2016-07-15 23:39:55 +02:00
parent 1ad8193434
commit 24dd973053
9 changed files with 111 additions and 117 deletions
+13 -13
View File
@@ -1,15 +1,15 @@
local m, public, private = Aux.module'post'
local state
private.state = nil
function private.process()
if state.posted < state.count then
if m.state.posted < m.state.count then
local stacking_complete, target_slot
Aux.stack.start(
state.item_key,
state.stack_size,
m.state.item_key,
m.state.stack_size,
function(slot)
stacking_complete = true
target_slot = slot
@@ -30,7 +30,7 @@ end
function private.post_auction(slot, k)
local item_info = Aux.info.container_item(unpack(slot))
if item_info.item_key == state.item_key and Aux.info.auctionable(item_info.tooltip) and item_info.aux_quantity == state.stack_size then
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
ClearCursor()
ClickAuctionSellItemButton()
@@ -39,7 +39,7 @@ function private.post_auction(slot, k)
ClickAuctionSellItemButton()
ClearCursor()
StartAuction(max(1, Aux.round(state.unit_start_price * item_info.aux_quantity)), Aux.round(state.unit_buyout_price * item_info.aux_quantity), state.duration)
StartAuction(max(1, Aux.round(m.state.unit_start_price * item_info.aux_quantity)), Aux.round(m.state.unit_buyout_price * item_info.aux_quantity), m.state.duration)
local posted
local listener = Aux.control.event_listener('CHAT_MSG_SYSTEM')
@@ -51,7 +51,7 @@ function private.post_auction(slot, k)
end)
listener:start()
Aux.control.wait_until(function() return posted end, function()
state.posted = state.posted + 1
m.state.posted = m.state.posted + 1
return k()
end)
@@ -61,13 +61,13 @@ function private.post_auction(slot, k)
end
function public.stop()
if state then
Aux.control.kill_thread(state.thread_id)
if m.state then
Aux.control.kill_thread(m.state.thread_id)
local callback = state.callback
local posted = state.posted
local callback = m.state.callback
local posted = m.state.posted
state = nil
m.state = nil
if callback then
callback(posted)
@@ -80,7 +80,7 @@ function public.start(item_key, stack_size, duration, unit_start_price, unit_buy
local thread_id = Aux.control.new_thread(m.process)
state = {
m.state = {
thread_id = thread_id,
item_key = item_key,
stack_size = stack_size,
+8 -9
View File
@@ -2,8 +2,7 @@ local m, public, private = Aux.module'scan'
local PAGE_SIZE = 50
local state
local threads = {}
private.threads = {}
function private.total_pages(total_auctions)
return math.ceil(total_auctions / PAGE_SIZE)
@@ -20,7 +19,7 @@ function private.current_query()
end
function private.current_thread()
for _, thread in threads do
for _, thread in m.threads do
if thread.id == Aux.control.thread_id then
return thread
end
@@ -28,14 +27,14 @@ function private.current_thread()
end
function public.start(params)
if threads[params.type] then
m.abort(threads[params.type].id)
if m.threads[params.type] then
m.abort(m.threads[params.type].id)
end
local thread_id = Aux.control.new_thread(function()
return m.wait_for_callback(m.current_thread().params.on_scan_start, m.scan)
end)
threads[params.type] = {
m.threads[params.type] = {
id = thread_id,
params = params,
}
@@ -44,10 +43,10 @@ end
function public.abort(scan_id)
local aborted_threads = {}
for t, thread in threads do
for t, thread in m.threads do
if not scan_id or thread.id == scan_id then
Aux.control.kill_thread(thread.id)
threads[t] = nil
m.threads[t] = nil
tinsert(aborted_threads, thread)
end
end
@@ -146,7 +145,7 @@ function private.scan()
m.wait_for_callback(m.current_thread().params.on_start_query, m.current_thread().query_index, m.process_query)
else
local on_complete = m.current_thread().params.on_complete
threads[m.current_thread().params.type] = nil
m.threads[m.current_thread().params.type] = nil
if on_complete then
return on_complete()
end
+20 -20
View File
@@ -1,6 +1,6 @@
local m, public, private = Aux.module'stack'
local state
private.state = nil
function private.stack_size(slot)
local container_item_info = Aux.info.container_item(unpack(slot))
@@ -24,7 +24,7 @@ end
function private.find_item_slot(partial)
for slot in Aux.util.inventory() do
if m.matching_item(slot, partial) and not Aux.util.table_eq(slot, state.target_slot) then
if m.matching_item(slot, partial) and not Aux.util.table_eq(slot, m.state.target_slot) then
return slot
end
end
@@ -32,7 +32,7 @@ end
function private.matching_item(slot, partial)
local item_info = Aux.info.container_item(unpack(slot))
return item_info and item_info.item_key == state.item_key and Aux.info.auctionable(item_info.tooltip) and (not partial or item_info.count < item_info.max_stack)
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)
end
function private.find_empty_slot()
@@ -45,7 +45,7 @@ end
function private.find_charge_item_slot()
for slot in Aux.util.inventory() do
if m.matching_item(slot) and m.charges(slot) == state.target_size then
if m.matching_item(slot) and m.charges(slot) == m.state.target_size then
return slot
end
end
@@ -69,35 +69,35 @@ end
function private.process()
if not state.target_slot or not m.matching_item(state.target_slot) then
state.target_slot = m.find_item_slot()
if not state.target_slot then
if not m.state.target_slot or not m.matching_item(m.state.target_slot) then
m.state.target_slot = m.find_item_slot()
if not m.state.target_slot then
return m.stop()
end
end
if m.charges(state.target_slot) then
state.target_slot = m.find_charge_item_slot()
if m.charges(m.state.target_slot) then
m.state.target_slot = m.find_charge_item_slot()
return m.stop()
end
if m.stack_size(state.target_slot) > state.target_size then
if m.stack_size(m.state.target_slot) > m.state.target_size then
local slot = m.find_item_slot(true) or m.find_empty_slot()
if slot then
return m.move_item(
state.target_slot,
m.state.target_slot,
slot,
m.stack_size(state.target_slot) - state.target_size,
m.stack_size(m.state.target_slot) - m.state.target_size,
m.process
)
end
elseif m.stack_size(state.target_slot) < state.target_size then
elseif m.stack_size(m.state.target_slot) < m.state.target_size then
local slot = m.find_item_slot()
if slot then
return m.move_item(
slot,
state.target_slot,
state.target_size - m.stack_size(state.target_slot),
m.state.target_slot,
m.state.target_size - m.stack_size(m.state.target_slot),
m.process
)
end
@@ -107,15 +107,15 @@ function private.process()
end
function public.stop()
if state then
Aux.control.kill_thread(state.thread_id)
if m.state then
Aux.control.kill_thread(m.state.thread_id)
local callback, slot = state.callback, state.target_slot
local callback, slot = m.state.callback, m.state.target_slot
if slot and not m.matching_item(slot) then
slot = nil
end
state = nil
m.state = nil
if callback then
callback(slot)
@@ -128,7 +128,7 @@ function public.start(item_key, size, callback)
local thread_id = Aux.control.new_thread(m.process)
state = {
m.state = {
thread_id = thread_id,
item_key = item_key,
target_size = size,
+24 -24
View File
@@ -2,20 +2,20 @@ local m, public, private = Aux.module'tooltip'
aux_tooltip_value = true
local game_tooltip_hooks = {}
local hooked_setter
local game_tooltip_money
private.game_tooltip_hooks = {}
private.hooked_setter = nil
private.game_tooltip_money = nil
function public.LOAD()
for func, hook in game_tooltip_hooks do
for func, hook in m.game_tooltip_hooks do
local func, hook = func, hook
Aux.hook(
func,
function(...)
hooked_setter = true
game_tooltip_money = 0
m.hooked_setter = true
m.game_tooltip_money = 0
local results = {Aux.orig[GameTooltip][func](unpack(arg)) }
hooked_setter = false
m.hooked_setter = false
hook(unpack(arg))
return unpack(results)
end,
@@ -35,8 +35,8 @@ function public.LOAD()
end
local orig = GameTooltip:GetScript('OnTooltipAddMoney')
GameTooltip:SetScript('OnTooltipAddMoney', function(...)
if hooked_setter then
game_tooltip_money = arg1
if m.hooked_setter then
m.game_tooltip_money = arg1
else
return orig(unpack(arg))
end
@@ -121,13 +121,13 @@ function private.extend_tooltip(tooltip, hyperlink, quantity)
end
end
if tooltip == GameTooltip and game_tooltip_money > 0 then
SetTooltipMoney(tooltip, game_tooltip_money)
if tooltip == GameTooltip and m.game_tooltip_money > 0 then
SetTooltipMoney(tooltip, m.game_tooltip_money)
end
tooltip:Show()
end
function game_tooltip_hooks:SetHyperlink(itemstring)
function m.game_tooltip_hooks:SetHyperlink(itemstring)
local name, _, quality = GetItemInfo(itemstring)
if name then
local _, _, _, hex = GetItemQualityColor(quality)
@@ -136,7 +136,7 @@ function game_tooltip_hooks:SetHyperlink(itemstring)
end
end
function game_tooltip_hooks:SetAuctionItem(type, index)
function m.game_tooltip_hooks:SetAuctionItem(type, index)
local link = GetAuctionItemLink(type, index)
if link then
local _, _, quantity = GetAuctionItemInfo(type, index)
@@ -144,7 +144,7 @@ function game_tooltip_hooks:SetAuctionItem(type, index)
end
end
function game_tooltip_hooks:SetLootItem(slot)
function m.game_tooltip_hooks:SetLootItem(slot)
local link = GetLootSlotLink(slot)
if link then
local _, _, quantity = GetLootSlotInfo(slot)
@@ -152,7 +152,7 @@ function game_tooltip_hooks:SetLootItem(slot)
end
end
function game_tooltip_hooks:SetQuestItem(qtype, slot)
function m.game_tooltip_hooks:SetQuestItem(qtype, slot)
local link = GetQuestItemLink(qtype, slot)
if link then
local _, _, quantity = GetQuestItemInfo(qtype, slot)
@@ -160,7 +160,7 @@ function game_tooltip_hooks:SetQuestItem(qtype, slot)
end
end
function game_tooltip_hooks:SetQuestLogItem(qtype, slot)
function m.game_tooltip_hooks:SetQuestLogItem(qtype, slot)
local link = GetQuestLogItemLink(qtype, slot)
if link then
local _, _, quantity = GetQuestLogRewardInfo(slot)
@@ -168,7 +168,7 @@ function game_tooltip_hooks:SetQuestLogItem(qtype, slot)
end
end
function game_tooltip_hooks:SetBagItem(bag, slot)
function m.game_tooltip_hooks:SetBagItem(bag, slot)
local link = GetContainerItemLink(bag, slot)
if link then
local _, quantity = GetContainerItemInfo(bag, slot)
@@ -176,7 +176,7 @@ function game_tooltip_hooks:SetBagItem(bag, slot)
end
end
function game_tooltip_hooks:SetInboxItem(index)
function m.game_tooltip_hooks:SetInboxItem(index)
local name, _, quantity = GetInboxItem(index)
local id = name and Aux.cache.item_id(name)
@@ -188,14 +188,14 @@ function game_tooltip_hooks:SetInboxItem(index)
end
end
function game_tooltip_hooks:SetInventoryItem(unit, slot)
function m.game_tooltip_hooks:SetInventoryItem(unit, slot)
local link = GetInventoryItemLink(unit, slot)
if link then
m.extend_tooltip(GameTooltip, link, 1)
end
end
function game_tooltip_hooks:SetMerchantItem(slot)
function m.game_tooltip_hooks:SetMerchantItem(slot)
local link = GetMerchantItemLink(slot)
if link then
local _, _, _, quantity = GetMerchantItemInfo(slot)
@@ -203,7 +203,7 @@ function game_tooltip_hooks:SetMerchantItem(slot)
end
end
function game_tooltip_hooks:SetCraftItem(skill, slot)
function m.game_tooltip_hooks:SetCraftItem(skill, slot)
local link, quantity
if slot then
link = GetCraftReagentItemLink(skill, slot)
@@ -217,14 +217,14 @@ function game_tooltip_hooks:SetCraftItem(skill, slot)
end
end
function game_tooltip_hooks:SetCraftSpell(slot)
function m.game_tooltip_hooks:SetCraftSpell(slot)
local link = GetCraftItemLink(slot)
if link then
m.extend_tooltip(GameTooltip, link, 1)
end
end
function game_tooltip_hooks:SetTradeSkillItem(skill, slot)
function m.game_tooltip_hooks:SetTradeSkillItem(skill, slot)
local link, quantity
if slot then
link = GetTradeSkillReagentItemLink(skill, slot)
@@ -238,7 +238,7 @@ function game_tooltip_hooks:SetTradeSkillItem(skill, slot)
end
end
function game_tooltip_hooks:SetAuctionSellItem()
function m.game_tooltip_hooks:SetAuctionSellItem()
local name, _, quantity, _, _, _ = GetAuctionSellItemInfo()
if name then
for slot in Aux.util.inventory() do