|
|
|
@@ -130,6 +130,7 @@ local function tryMoveItem(item, itemTree, force)
|
|
|
|
|
true)
|
|
|
|
|
if moved then
|
|
|
|
|
itemLocation.maxFits = itemLocation.inventory.HowManyCanBePut(item.Prefab, itemLocation.slotIndex)
|
|
|
|
|
break
|
|
|
|
|
end
|
|
|
|
|
-- if moved then
|
|
|
|
|
-- MyModGlobal.debugPrint(string.format("Moved item to existing stack at slot index: %d", itemLocation .slotIndex))
|
|
|
|
@@ -144,6 +145,9 @@ local function tryMoveItem(item, itemTree, force)
|
|
|
|
|
-- Then move to any of the empty slots
|
|
|
|
|
if not moved then
|
|
|
|
|
-- MyModGlobal.debugPrint("No existing stacks found, trying empty slots...")
|
|
|
|
|
if not itemTree['empty'] then
|
|
|
|
|
return "No empty slots found"
|
|
|
|
|
end
|
|
|
|
|
for _, itemLocation in ipairs(itemTree['empty']) do
|
|
|
|
|
local maxFits = itemLocation.maxFits
|
|
|
|
|
-- These empty slots are not guranteed to be empty, ironically
|
|
|
|
@@ -160,6 +164,7 @@ local function tryMoveItem(item, itemTree, force)
|
|
|
|
|
true)
|
|
|
|
|
if moved then
|
|
|
|
|
itemLocation.maxFits = itemLocation.inventory.HowManyCanBePut(item.Prefab, itemLocation.slotIndex)
|
|
|
|
|
break
|
|
|
|
|
end
|
|
|
|
|
-- if moved then
|
|
|
|
|
-- MyModGlobal.debugPrint(string.format("Moved item to empty slot at index: %d", itemLocation.slotIndex))
|
|
|
|
@@ -227,6 +232,52 @@ local function tryBuildCharacterItemTree(character)
|
|
|
|
|
return itemTree, nil
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
---@param item Barotrauma.Item
|
|
|
|
|
---@return string?
|
|
|
|
|
local function stackToContainer(item)
|
|
|
|
|
MyModGlobal.debugPrint(string.format("Attempting to stack items to container: %s", tostring(item)))
|
|
|
|
|
local itemInventory = item.OwnInventory
|
|
|
|
|
if not itemInventory then
|
|
|
|
|
return "Item has no own inventory"
|
|
|
|
|
end
|
|
|
|
|
local parentInventory = item.ParentInventory
|
|
|
|
|
if not parentInventory then
|
|
|
|
|
return "Item has no parent inventory"
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local itemTree = buildItemTree(itemInventory)
|
|
|
|
|
itemTree = sortItemTree(itemTree)
|
|
|
|
|
|
|
|
|
|
local toMove = {}
|
|
|
|
|
local total = 0
|
|
|
|
|
utils.enqueueInventory(parentInventory, toMove, function(iterationItem)
|
|
|
|
|
total = total + 1
|
|
|
|
|
-- Get all items that aren't our mouseover item
|
|
|
|
|
if iterationItem.Equals(item) then
|
|
|
|
|
-- MyModGlobal.debugPrint(string.format("Skipping item: %s", iterationItem.Prefab.Identifier.Value))
|
|
|
|
|
return false
|
|
|
|
|
end
|
|
|
|
|
-- This won't work for nested containers
|
|
|
|
|
-- But making it work with nested containers is a pain in the ass
|
|
|
|
|
-- So we'll just not do that for now
|
|
|
|
|
if iterationItem.ParentInventory and iterationItem.ParentInventory.Equals(itemInventory) then
|
|
|
|
|
-- MyModGlobal.debugPrint(string.format("Skipping item: %s", iterationItem.Prefab.Identifier.Value))
|
|
|
|
|
return false
|
|
|
|
|
end
|
|
|
|
|
if total >= 10000 then
|
|
|
|
|
MyModGlobal.debugPrint("Too many items to stack, stopping")
|
|
|
|
|
return false, true
|
|
|
|
|
end
|
|
|
|
|
return true
|
|
|
|
|
end)
|
|
|
|
|
MyModGlobal.debugPrint(string.format("Enqueued %d items to stack", #toMove))
|
|
|
|
|
-- dump(toMove)
|
|
|
|
|
|
|
|
|
|
local errors = tryMoveItems(toMove, itemTree)
|
|
|
|
|
for _, error in ipairs(errors) do
|
|
|
|
|
MyModGlobal.debugPrint(string.format("Error stacking item: %s", error))
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
-- Function to quickly stack items from inventory to containers
|
|
|
|
|
-- 6 and 7 are hands
|
|
|
|
|
-- 9..18 are main slots
|
|
|
|
@@ -234,6 +285,24 @@ local inventorySlotsToStack = { 6, 7, }
|
|
|
|
|
-- local inventorySlotsToStack = { 6, 7, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18 }
|
|
|
|
|
---@param character Barotrauma.Character
|
|
|
|
|
local function quickStackItems(character)
|
|
|
|
|
MyModGlobal.debugPrint("Quick stack function called")
|
|
|
|
|
-- If we are mousing over an item that has an inventory (ie. is a container)
|
|
|
|
|
-- Then stack all items from the parent inventory into the mouseover container
|
|
|
|
|
local mouseover = utils.getFirstSlotUnderCursor()
|
|
|
|
|
if mouseover then
|
|
|
|
|
---@type Barotrauma.Item
|
|
|
|
|
local slotItem = mouseover.slot.items[1]
|
|
|
|
|
local itemInventory = slotItem.OwnInventory
|
|
|
|
|
if itemInventory then
|
|
|
|
|
MyModGlobal.debugPrint(string.format("Item inventory found: %s", tostring(itemInventory)))
|
|
|
|
|
local err = stackToContainer(slotItem)
|
|
|
|
|
if err then
|
|
|
|
|
MyModGlobal.debugPrint(string.format("Error stacking items to container: %s", err))
|
|
|
|
|
end
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if not character then
|
|
|
|
|
MyModGlobal.debugPrint("No character found")
|
|
|
|
|
return
|
|
|
|
@@ -245,16 +314,6 @@ local function quickStackItems(character)
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- for i, slot in ipairs(inventory.slots) do
|
|
|
|
|
-- if #slot.items > 0 then
|
|
|
|
|
-- local item = slot.items[1]
|
|
|
|
|
-- local identifier = item.Prefab.Identifier.Value
|
|
|
|
|
-- print(string.format("Item at slot %d is %s", i, identifier))
|
|
|
|
|
-- end
|
|
|
|
|
-- end
|
|
|
|
|
|
|
|
|
|
MyModGlobal.debugPrint("Quick stack function called")
|
|
|
|
|
|
|
|
|
|
local itemTree, err = tryBuildCharacterItemTree(character)
|
|
|
|
|
if err then
|
|
|
|
|
MyModGlobal.debugPrint(string.format("Error building item tree: %s", err))
|
|
|
|
|