refactorings
This commit is contained in:
+16
-16
@@ -1,42 +1,42 @@
|
||||
local m, public, private = Aux.module'stack'
|
||||
local m, public, private = aux.module'stack'
|
||||
|
||||
private.state = nil
|
||||
|
||||
function private.stack_size(slot)
|
||||
local container_item_info = Aux.info.container_item(unpack(slot))
|
||||
local container_item_info = aux.info.container_item(unpack(slot))
|
||||
return container_item_info and container_item_info.count or 0
|
||||
end
|
||||
|
||||
function private.charges(slot)
|
||||
local container_item_info = Aux.info.container_item(unpack(slot))
|
||||
local container_item_info = aux.info.container_item(unpack(slot))
|
||||
return container_item_info and container_item_info.charges
|
||||
end
|
||||
|
||||
function private.max_stack(slot)
|
||||
local container_item_info = Aux.info.container_item(unpack(slot))
|
||||
local container_item_info = aux.info.container_item(unpack(slot))
|
||||
return container_item_info and container_item_info.max_stack
|
||||
end
|
||||
|
||||
function private.locked(slot)
|
||||
local container_item_info = Aux.info.container_item(unpack(slot))
|
||||
local container_item_info = aux.info.container_item(unpack(slot))
|
||||
return container_item_info and container_item_info.locked
|
||||
end
|
||||
|
||||
function private.find_item_slot(partial)
|
||||
for slot in Aux.util.inventory() do
|
||||
if m.matching_item(slot, partial) and not Aux.util.eq(slot, m.state.target_slot) then
|
||||
for slot in aux.util.inventory() do
|
||||
if m.matching_item(slot, partial) and not aux.util.eq(slot, m.state.target_slot) then
|
||||
return slot
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function private.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 = 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)
|
||||
end
|
||||
|
||||
function private.find_empty_slot()
|
||||
for slot, type in Aux.util.inventory() do
|
||||
for slot, type in aux.util.inventory() do
|
||||
if type == 1 and not GetContainerItemInfo(unpack(slot)) then
|
||||
return slot
|
||||
end
|
||||
@@ -44,7 +44,7 @@ function private.find_empty_slot()
|
||||
end
|
||||
|
||||
function private.find_charge_item_slot()
|
||||
for slot in Aux.util.inventory() do
|
||||
for slot in aux.util.inventory() do
|
||||
if m.matching_item(slot) and m.charges(slot) == m.state.target_size then
|
||||
return slot
|
||||
end
|
||||
@@ -53,7 +53,7 @@ end
|
||||
|
||||
function private.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 aux.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 private.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 aux.control.when(function() return m.stack_size(to_slot) == expected_size end, k)
|
||||
end
|
||||
|
||||
function private.process()
|
||||
@@ -105,20 +105,20 @@ end
|
||||
|
||||
function public.stop()
|
||||
if m.state then
|
||||
Aux.control.kill_thread(m.state.thread_id)
|
||||
aux.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
|
||||
end
|
||||
m.state = nil
|
||||
Aux.safe_call(callback, slot)
|
||||
aux.safe_call(callback, slot)
|
||||
end
|
||||
end
|
||||
|
||||
function public.start(item_key, size, callback)
|
||||
m.stop()
|
||||
|
||||
local thread_id = Aux.control.thread(m.process)
|
||||
local thread_id = aux.control.thread(m.process)
|
||||
m.state = {
|
||||
thread_id = thread_id,
|
||||
item_key = item_key,
|
||||
|
||||
Reference in New Issue
Block a user