Now enqueue items recursively too!
This commit is contained in:
@@ -160,11 +160,22 @@ local function tryMoveItems(items, itemTree)
|
|||||||
return errs
|
return errs
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- We got to do this shit because enqueueInventory calls enqueueItem
|
||||||
|
-- And enqueueItem calls enqueueInventory
|
||||||
|
-- So unless we define them both before using them
|
||||||
|
-- We will get an error saying either is undefined
|
||||||
|
local enqueueItem
|
||||||
|
local enqueueSlot
|
||||||
|
local enqueueInventory
|
||||||
|
|
||||||
---@param item Barotrauma.Item
|
---@param item Barotrauma.Item
|
||||||
---@param queue Barotrauma.Item[]
|
---@param queue Barotrauma.Item[]
|
||||||
---@return Barotrauma.Item[], string
|
---@return Barotrauma.Item[], string
|
||||||
local function enqueueItem(item, queue)
|
enqueueItem = function(item, queue)
|
||||||
queue = queue or {}
|
queue = queue or {}
|
||||||
|
if item.OwnInventory then
|
||||||
|
queue = enqueueInventory(item.OwnInventory, queue)
|
||||||
|
end
|
||||||
queue[#queue + 1] = item
|
queue[#queue + 1] = item
|
||||||
return queue
|
return queue
|
||||||
end
|
end
|
||||||
@@ -172,7 +183,7 @@ end
|
|||||||
---@param slot Barotrauma.ItemInventory.Slot
|
---@param slot Barotrauma.ItemInventory.Slot
|
||||||
---@param queue Barotrauma.Item[]
|
---@param queue Barotrauma.Item[]
|
||||||
---@return Barotrauma.Item[], string
|
---@return Barotrauma.Item[], string
|
||||||
local function enqueueSlot(slot, queue)
|
enqueueSlot = function(slot, queue)
|
||||||
queue = queue or {}
|
queue = queue or {}
|
||||||
-- We don't want to shadow queue
|
-- We don't want to shadow queue
|
||||||
local err
|
local err
|
||||||
@@ -190,7 +201,7 @@ end
|
|||||||
---@param inventory Barotrauma.ItemInventory
|
---@param inventory Barotrauma.ItemInventory
|
||||||
---@param queue Barotrauma.Item[]
|
---@param queue Barotrauma.Item[]
|
||||||
---@return Barotrauma.Item[], string[]
|
---@return Barotrauma.Item[], string[]
|
||||||
local function enqueueInventory(inventory, queue)
|
enqueueInventory = function(inventory, queue)
|
||||||
queue = queue or {}
|
queue = queue or {}
|
||||||
-- We don't want to shadow queue
|
-- We don't want to shadow queue
|
||||||
local err
|
local err
|
||||||
@@ -338,6 +349,7 @@ local function tryBuildItemTree(inventory)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Function to quickly stack items from inventory to containers
|
-- Function to quickly stack items from inventory to containers
|
||||||
|
local inventorySlotsToStack = {}
|
||||||
local function quickStackItems(character)
|
local function quickStackItems(character)
|
||||||
if not character then
|
if not character then
|
||||||
debugPrint("No character found")
|
debugPrint("No character found")
|
||||||
@@ -358,22 +370,20 @@ local function quickStackItems(character)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
itemTree = sortItemtreeBySlots(itemTree)
|
itemTree = sortItemtreeBySlots(itemTree)
|
||||||
|
local toMove = {}
|
||||||
|
|
||||||
local toMove = enqueueInventory(inventory)
|
-- toMove = enqueueInventory(inventory, toMove)
|
||||||
for _, item in ipairs(toMove) do
|
|
||||||
print("Item: " .. item.Prefab.Identifier.Value)
|
local openContainerInventory = getOpenContainer()
|
||||||
|
if openContainerInventory then
|
||||||
|
toMove = enqueueInventory(openContainerInventory, toMove)
|
||||||
end
|
end
|
||||||
|
|
||||||
local errors = tryMoveItems(toMove, itemTree)
|
local errors = tryMoveItems(toMove, itemTree)
|
||||||
for _, error in ipairs(errors) do
|
for _, error in ipairs(errors) do
|
||||||
print("Error stacking item: " .. error)
|
print("Error stacking item: " .. error)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- stackPlayerInventoryItems(inventory, itemTree)
|
|
||||||
-- local openContainerInventory = getOpenContainer()
|
|
||||||
-- if openContainerInventory then
|
|
||||||
-- stackInventoryItems(openContainerInventory, itemTree)
|
|
||||||
-- end
|
|
||||||
|
|
||||||
--local handItems = {}
|
--local handItems = {}
|
||||||
--for _, slotIndex in ipairs(CONFIG.HAND_SLOTS) do
|
--for _, slotIndex in ipairs(CONFIG.HAND_SLOTS) do
|
||||||
-- local slot = inventory.slots[slotIndex]
|
-- local slot = inventory.slots[slotIndex]
|
||||||
|
|||||||
Reference in New Issue
Block a user