working on big scan/control refactoring

This commit is contained in:
Manuel Simon Hirsig
2016-02-25 15:43:18 +01:00
parent 8d888f4e96
commit 5af1b28021
6 changed files with 78 additions and 158 deletions
+2 -3
View File
@@ -1,12 +1,11 @@
AuxVersion = '2.4.31'
Aux = {
version = '2.5.0',
blizzard_ui_shown = false,
orig = {},
}
function Aux.on_load()
Aux.log('Aux v'..AuxVersion..' loaded.')
Aux.log('Aux v'..Aux.version..' loaded.')
tinsert(UISpecialFrames, 'AuxFrame')
LoadAddOn('EnhTooltip')
if IsAddOnLoaded('EnhTooltip') then
+33 -41
View File
@@ -1,16 +1,16 @@
local private, public = {}, {}
Aux.post = public
local controller = (function()
local controller
return function()
controller = controller or Aux.control.controller()
return controller
end
end)()
local state
function private.as_soon_as(p, k)
if p() then
return k()
else
return Aux.control.wait(private.as_soon_as, p, k)
end
end
function private.process()
if state.posted < state.count or state.allow_partial then
if state.posted == state.count then
@@ -28,8 +28,8 @@ function private.process()
stack_slot = slot
end
)
controller().wait(function() return stacking_complete end, function()
private.as_soon_as(function() return stacking_complete end, function()
if stack_slot and Aux.info.container_item(stack_slot.bag, stack_slot.bag_slot).aux_quantity <= state.stack_size then
private.post_auction(stack_slot, function(stack_size)
@@ -40,12 +40,12 @@ function private.process()
return private.process()
end)
else
return private.stop()
return public.stop()
end
end)
else
return private.stop()
return public.stop()
end
end
@@ -58,13 +58,15 @@ function private.post_auction(slot, k)
ClearCursor()
local stack_size = Aux.info.container_item(slot.bag, slot.bag_slot).aux_quantity
StartAuction(max(1, Aux.round(state.unit_start_price * stack_size)), Aux.round(state.unit_buyout_price * stack_size), state.duration)
controller().wait(function() return not GetContainerItemInfo(slot.bag, slot.bag_slot) end, function()
private.as_soon_as(function() return not GetContainerItemInfo(slot.bag, slot.bag_slot) end, function()
return k(stack_size)
end)
end
function private.stop()
function public.stop()
if state then
Aux.control.kill(state.thread_id)
local callback = state.callback
local posted = state.posted
local partial_stack = state.partial_stack
@@ -77,32 +79,22 @@ function private.stop()
end
end
function public.stop(k)
controller().wait(function()
private.stop()
if k then
return k()
end
end)
end
function public.start(item_key, stack_size, duration, unit_start_price, unit_buyout_price, count, allow_partial, callback)
controller().wait(function()
private.stop()
state = {
item_key = item_key,
stack_size = stack_size,
duration = duration,
unit_start_price = unit_start_price,
unit_buyout_price = unit_buyout_price,
count = count,
allow_partial = allow_partial,
posted = 0,
callback = callback,
}
return private.process()
end)
public.stop()
local thread_id = Aux.control.new(private.process)
state = {
thread_id = thread_id,
item_key = item_key,
stack_size = stack_size,
duration = duration,
unit_start_price = unit_start_price,
unit_buyout_price = unit_buyout_price,
count = count,
allow_partial = allow_partial,
posted = 0,
callback = callback,
}
end
+22 -24
View File
@@ -679,32 +679,31 @@ function private.set_item(item)
return
end
Aux.scan.abort(function()
Aux.scan.abort('list')
selected_item = item
refresh = true
selected_item = item
refresh = true
UIDropDownMenu_Initialize(private.duration_dropdown, private.initialize_duration_dropdown) -- TODO, wtf, why is this needed
UIDropDownMenu_SetSelectedValue(private.duration_dropdown, settings.duration)
UIDropDownMenu_Initialize(private.duration_dropdown, private.initialize_duration_dropdown) -- TODO, wtf, why is this needed
UIDropDownMenu_SetSelectedValue(private.duration_dropdown, settings.duration)
UIDropDownMenu_Initialize(private.pricing_model_dropdown, private.initialize_pricing_model_dropdown)
UIDropDownMenu_SetSelectedValue(private.pricing_model_dropdown, settings.pricing_model)
UIDropDownMenu_Initialize(private.pricing_model_dropdown, private.initialize_pricing_model_dropdown)
UIDropDownMenu_SetSelectedValue(private.pricing_model_dropdown, settings.pricing_model)
private.hide_checkbox:SetChecked(settings.hidden)
private.post_all_checkbox:SetChecked(settings.post_all)
private.hide_checkbox:SetChecked(settings.hidden)
private.post_all_checkbox:SetChecked(settings.post_all)
private.stack_size_slider:SetMinMaxValues(1, selected_item.charges and 5 or selected_item.max_stack)
private.stack_size_slider:SetValue(settings.stack_size)
private.quantity_update()
private.stack_count_slider:SetValue(selected_item.aux_quantity) -- reduced to max possible
private.stack_size_slider:SetMinMaxValues(1, selected_item.charges and 5 or selected_item.max_stack)
private.stack_size_slider:SetValue(settings.stack_size)
private.quantity_update()
private.stack_count_slider:SetValue(selected_item.aux_quantity) -- reduced to max possible
if not existing_auctions[selected_item.key] then
private.refresh_entries()
end
if not existing_auctions[selected_item.key] then
private.refresh_entries()
end
private.update_recommendation()
refresh = true
end)
private.update_recommendation()
refresh = true
end
@@ -822,11 +821,10 @@ function private.set_auction(entry)
end
function private.refresh()
Aux.scan.abort(function()
private.refresh_entries()
private.update_recommendation()
refresh = true
end)
Aux.scan.abort('list')
private.refresh_entries()
private.update_recommendation()
refresh = true
end
function private.record_auction(key, aux_quantity, unit_buyout_price, duration, owner)
+2 -10
View File
@@ -28,7 +28,7 @@ function current_thread()
end
function public.start(params)
private.abort(params.type)
public.abort(params.type)
local thread_id = Aux.control.new(private.scan)
threads[params.type] = {
@@ -37,15 +37,7 @@ function public.start(params)
}
end
function public.abort(k)
private.abort()
if k then
return k()
end
end
function private.abort(type)
function public.abort(type)
for t, thread in pairs(threads) do
if not type or type == t then
if thread.params.on_abort then
-54
View File
@@ -1,54 +0,0 @@
local private, public = {}, {}
Aux.history_frame = public
function public.on_close()
end
function public.on_open()
end
function public.start_scan()
-- if not AuxHistoryScanButton:IsVisible() then
-- return
-- end
-- AuxHistoryScanButton:Hide()
-- AuxHistoryStopButton:Show()
-- private.scanned_signatures = Aux.util.set()
Aux.log('Scanning auctions ...')
Aux.scan.start{
type = 'list',
queries = {{
start_page = 0,
}},
on_page_loaded = function(page, total_pages)
Aux.log('Scanning page '..(page+1)..' out of '..total_pages..' ...')
end,
-- on_read_auction = function(auction_info)
-- private.process_auction(auction_info)
-- end,
on_complete = function()
Aux.log('Scan complete.')
-- AuxHistoryStopButton:Hide()
-- AuxHistoryScanButton:Show()
end,
on_abort = function()
Aux.log('Scan aborted.')
-- AuxHistoryStopButton:Hide()
-- AuxHistoryScanButton:Show()
end,
}
end
function public.stop_scan()
Aux.scan.abort()
end
--function private.process_auction(auction_info)
-- private.scanned_signatures.add(auction_info.signature)
--end
+19 -26
View File
@@ -1,13 +1,13 @@
local private, public = {}, {}
Aux.stack = public
local controller = (function()
local controller
return function()
controller = controller or Aux.control.controller()
return controller
function private.as_soon_as(p, k)
if p() then
return k()
else
return Aux.control.wait(private.as_soon_as, p, k)
end
end)()
end
local state
@@ -47,7 +47,7 @@ function private.move_item(from_slot, to_slot, amount, k)
SplitContainerItem(from_slot.bag, from_slot.bag_slot, amount)
PickupContainerItem(to_slot.bag, to_slot.bag_slot)
return controller().wait(function() return private.stack_size(to_slot) == size_before + amount end, k)
return private.as_soon_as(function() return private.stack_size(to_slot) == size_before + amount end, k)
end
function private.item_key(slot)
@@ -104,7 +104,7 @@ function private.process()
end
end
return private.stop()
return public.stop()
end
function private.max_stack(slot)
@@ -112,8 +112,10 @@ function private.max_stack(slot)
return container_item_info and container_item_info.max_stack
end
function private.stop()
function public.stop()
if state then
Aux.control.kill(state.thread_id)
local callback, slot = state.callback, state.target_slot
state = nil
@@ -124,24 +126,17 @@ function private.stop()
end
end
function public.stop(k)
controller().wait(function()
private.stop()
if k then
return k()
end
end)
end
function public.start(item_key, size, callback)
controller().wait(function()
private.stop()
private.as_soon_as(function()
public.stop()
local slots = private.item_slots(item_key)
local target_slot = slots()
local thread_id = Aux.control.new(private.process)
state = {
thread_id = thread_id,
target_size = size,
target_slot = target_slot,
other_slots = slots,
@@ -149,12 +144,10 @@ function public.start(item_key, size, callback)
}
if not target_slot then
return private.stop()
public.stop()
elseif private.item_charges(target_slot) then
state.target_slot = private.find_charges_item_slot(item_key, size)
return private.stop()
else
return private.process()
public.stop()
end
end)
end