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