Implement toggleable queue
This commit is contained in:
@@ -120,9 +120,9 @@ MyModGlobal.InventorySlot = {
|
||||
end,
|
||||
__tostring = function(self)
|
||||
return string.format(
|
||||
"InventorySlot(inventory=%s, slotIndex1=%d, slotIndex0=%d, item=%s, stackSize=%d, maxStackSize=%d)",
|
||||
tostring(self.inventory), self.slotIndex1, self.slotIndex0, tostring(self.item), self.stackSize,
|
||||
self.maxStackSize)
|
||||
"InventorySlot(inventory=%s, item=%s, stackSize=%d, maxStackSize=%d, slotIndex1=%d, slotIndex0=%d)",
|
||||
tostring(self.inventory), tostring(self.item), self.stackSize, self.maxStackSize, self.slotIndex1,
|
||||
self.slotIndex0)
|
||||
end,
|
||||
---@param self InventorySlot
|
||||
---@param predicate? fun(slot: InventorySlot): boolean
|
||||
@@ -216,11 +216,13 @@ do
|
||||
local itemMoveQueue = {}
|
||||
---@type table<Barotrauma.Item, boolean>
|
||||
local itemLookup = {}
|
||||
local rate = 100
|
||||
local perIteration = 6
|
||||
local rate = 500
|
||||
local perIteration = 30
|
||||
local noQueue = true
|
||||
-- rate / 1000 is ms to seconds and *perIteraion is number of items per second
|
||||
local maxQueueSize = 10 * (1000 / rate * perIteration)
|
||||
local function processQueue()
|
||||
if noQueue then return end
|
||||
-- MyModGlobal.debugPrint("Processing queue")
|
||||
Timer.Wait(processQueue, rate)
|
||||
if not enabled then return end
|
||||
@@ -234,7 +236,7 @@ do
|
||||
moveRequest.allowCombine = moveRequest.allowCombine or false
|
||||
moveRequest.allowSwap = moveRequest.allowSwap or false
|
||||
local success = moveRequest.where.inventory.TryPutItem(moveRequest.what, moveRequest.where.slotIndex0,
|
||||
moveRequest.allowSwap, moveRequest.allowCombine, Character.Controlled, true)
|
||||
moveRequest.allowSwap, moveRequest.allowCombine, nil)
|
||||
if not success then
|
||||
MyModGlobal.debugPrint(string.format("Failed moving item from %s to %s", tostring(moveRequest.what),
|
||||
tostring(moveRequest.where:__tostring())))
|
||||
@@ -249,6 +251,17 @@ do
|
||||
---@param allowSwap? boolean
|
||||
---@param allowCombine? boolean
|
||||
enqueueMove = function(what, where, allowSwap, allowCombine)
|
||||
allowCombine = allowCombine == true
|
||||
allowSwap = allowSwap == true
|
||||
if noQueue then
|
||||
local success = where.inventory.TryPutItem(what, where.slotIndex0,
|
||||
allowSwap, allowCombine, nil)
|
||||
if not success then
|
||||
MyModGlobal.debugPrint(string.format("Failed moving item from %s to %s", tostring(what),
|
||||
tostring(where:__tostring())))
|
||||
end
|
||||
where:pretendMoved(what)
|
||||
else
|
||||
if #itemMoveQueue >= maxQueueSize then
|
||||
MyModGlobal.debugPrint("Queue is full, skipping move")
|
||||
return
|
||||
@@ -269,6 +282,7 @@ do
|
||||
-- We will very optimistically pretend that this will 100% for sure work
|
||||
where:pretendMoved(what)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user