diff --git a/QuickStackToBag/Lua/Autorun/init.lua b/QuickStackToBag/Lua/Autorun/init.lua index 8c33fb1..8b4e868 100644 --- a/QuickStackToBag/Lua/Autorun/init.lua +++ b/QuickStackToBag/Lua/Autorun/init.lua @@ -160,11 +160,22 @@ local function tryMoveItems(items, itemTree) return errs 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 queue Barotrauma.Item[] ---@return Barotrauma.Item[], string -local function enqueueItem(item, queue) +enqueueItem = function(item, queue) queue = queue or {} + if item.OwnInventory then + queue = enqueueInventory(item.OwnInventory, queue) + end queue[#queue + 1] = item return queue end @@ -172,7 +183,7 @@ end ---@param slot Barotrauma.ItemInventory.Slot ---@param queue Barotrauma.Item[] ---@return Barotrauma.Item[], string -local function enqueueSlot(slot, queue) +enqueueSlot = function(slot, queue) queue = queue or {} -- We don't want to shadow queue local err @@ -190,7 +201,7 @@ end ---@param inventory Barotrauma.ItemInventory ---@param queue Barotrauma.Item[] ---@return Barotrauma.Item[], string[] -local function enqueueInventory(inventory, queue) +enqueueInventory = function(inventory, queue) queue = queue or {} -- We don't want to shadow queue local err @@ -338,6 +349,7 @@ local function tryBuildItemTree(inventory) end -- Function to quickly stack items from inventory to containers +local inventorySlotsToStack = {} local function quickStackItems(character) if not character then debugPrint("No character found") @@ -358,22 +370,20 @@ local function quickStackItems(character) return end itemTree = sortItemtreeBySlots(itemTree) + local toMove = {} - local toMove = enqueueInventory(inventory) - for _, item in ipairs(toMove) do - print("Item: " .. item.Prefab.Identifier.Value) + -- toMove = enqueueInventory(inventory, toMove) + + local openContainerInventory = getOpenContainer() + if openContainerInventory then + toMove = enqueueInventory(openContainerInventory, toMove) end + local errors = tryMoveItems(toMove, itemTree) for _, error in ipairs(errors) do print("Error stacking item: " .. error) end - -- stackPlayerInventoryItems(inventory, itemTree) - -- local openContainerInventory = getOpenContainer() - -- if openContainerInventory then - -- stackInventoryItems(openContainerInventory, itemTree) - -- end - --local handItems = {} --for _, slotIndex in ipairs(CONFIG.HAND_SLOTS) do -- local slot = inventory.slots[slotIndex]