Replace calls to utils for factored out functions
This commit is contained in:
@@ -2,105 +2,10 @@
|
|||||||
local quickstack = require("Cyka.quickstack")
|
local quickstack = require("Cyka.quickstack")
|
||||||
local utils = require("Cyka.utils")
|
local utils = require("Cyka.utils")
|
||||||
|
|
||||||
-- There is actually no need to recurse deep
|
|
||||||
-- Because we can only have an item in the inventory open
|
|
||||||
-- And not an item in an item in the inventory
|
|
||||||
-- So in theory we only need to recurse 1 deep
|
|
||||||
---@param inventory Barotrauma.Inventory
|
|
||||||
---@param slots InventorySlot[]
|
|
||||||
---@param depth number
|
|
||||||
---@return InventorySlot[], string?
|
|
||||||
local function getMouseoverSlots(inventory, slots, depth)
|
|
||||||
slots = slots or {}
|
|
||||||
depth = depth or 0
|
|
||||||
if depth > 1 then return slots, nil end
|
|
||||||
|
|
||||||
local visualSlots = inventory.visualSlots
|
|
||||||
if not visualSlots then return nil, "Inventory has no visual slots" end
|
|
||||||
|
|
||||||
for i, visualSlot in ipairs(visualSlots) do
|
|
||||||
local item
|
|
||||||
local itemInventory
|
|
||||||
-- local err
|
|
||||||
|
|
||||||
local slot = inventory.slots[i]
|
|
||||||
if not slot then
|
|
||||||
-- MyModGlobal.debugPrint("Slot is not a valid slot")
|
|
||||||
goto continue
|
|
||||||
end
|
|
||||||
|
|
||||||
if #slot.items == 0 then
|
|
||||||
goto mouseover
|
|
||||||
end
|
|
||||||
|
|
||||||
item = slot.items[1]
|
|
||||||
if not item then
|
|
||||||
goto mouseover
|
|
||||||
end
|
|
||||||
|
|
||||||
itemInventory = item.OwnInventory
|
|
||||||
if not itemInventory then
|
|
||||||
goto mouseover
|
|
||||||
end
|
|
||||||
|
|
||||||
-- print("Before: " .. #slots)--
|
|
||||||
getMouseoverSlots(itemInventory, slots, depth + 1)
|
|
||||||
-- if err then
|
|
||||||
-- MyModGlobal.debugPrint(string.format("Error getting mouseover slots: %s", err))
|
|
||||||
-- end
|
|
||||||
-- print("After: " .. #slots)
|
|
||||||
|
|
||||||
::mouseover::
|
|
||||||
if visualSlot:MouseOn() then
|
|
||||||
slots[#slots + 1] = {
|
|
||||||
inventory = inventory,
|
|
||||||
slotIndex = i,
|
|
||||||
slot = slot
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
::continue::
|
|
||||||
end
|
|
||||||
|
|
||||||
return slots, nil
|
|
||||||
end
|
|
||||||
|
|
||||||
---@return InventorySlot[], string?
|
|
||||||
local function getInventorySlotsUnderCursor()
|
|
||||||
-- Make sure we have a controlled character
|
|
||||||
local controlledCharacter = Character.Controlled
|
|
||||||
if not controlledCharacter then return nil, "No controlled character" end
|
|
||||||
|
|
||||||
local inventory = controlledCharacter.Inventory
|
|
||||||
if not inventory then return nil, "No inventory" end
|
|
||||||
|
|
||||||
local mouseoverSlots, err = getMouseoverSlots(inventory)
|
|
||||||
if err then return mouseoverSlots, err end
|
|
||||||
|
|
||||||
local openContainers = quickstack.getOpenContainers()
|
|
||||||
for _, container in ipairs(openContainers) do
|
|
||||||
local containerInventories = container.OwnInventories
|
|
||||||
for containerInventory in containerInventories do
|
|
||||||
for i, visualSlot in ipairs(containerInventory.visualSlots) do
|
|
||||||
if visualSlot:MouseOn() then
|
|
||||||
local slot = containerInventory.slots[i]
|
|
||||||
mouseoverSlots[#mouseoverSlots + 1] = {
|
|
||||||
inventory = containerInventory,
|
|
||||||
slotIndex = i,
|
|
||||||
slot = slot
|
|
||||||
}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
return mouseoverSlots, nil
|
|
||||||
end
|
|
||||||
|
|
||||||
local targetInventory = nil
|
local targetInventory = nil
|
||||||
local slotThrottle = {}
|
local slotThrottle = {}
|
||||||
local function tryStackCursorItem()
|
local function tryStackCursorItem()
|
||||||
local slots, err = getInventorySlotsUnderCursor()
|
local slots, err = utils.getSlotsUnderCursor()
|
||||||
if err then
|
if err then
|
||||||
-- MyModGlobal.debugPrint(string.format("Error getting inventory slot: %s", err))
|
-- MyModGlobal.debugPrint(string.format("Error getting inventory slot: %s", err))
|
||||||
return
|
return
|
||||||
@@ -181,8 +86,7 @@ local function tryStackCursorItem()
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function setTargetInventory()
|
local function setTargetInventory()
|
||||||
---@type InventorySlot[]
|
local slots, err = utils.getSlotsUnderCursor()
|
||||||
local slots, err = getInventorySlotsUnderCursor()
|
|
||||||
if err then
|
if err then
|
||||||
MyModGlobal.debugPrint(string.format("Error getting inventory slot: %s", err))
|
MyModGlobal.debugPrint(string.format("Error getting inventory slot: %s", err))
|
||||||
return
|
return
|
||||||
@@ -224,5 +128,4 @@ end
|
|||||||
return {
|
return {
|
||||||
tryStackCursorItem = tryStackCursorItem,
|
tryStackCursorItem = tryStackCursorItem,
|
||||||
setTargetInventory = setTargetInventory,
|
setTargetInventory = setTargetInventory,
|
||||||
getInventorySlotsUnderCursor = getInventorySlotsUnderCursor
|
|
||||||
}
|
}
|
||||||
|
@@ -146,7 +146,13 @@ local function tryStackFabricator(character)
|
|||||||
-- dump(itemsOnSubmarine)
|
-- dump(itemsOnSubmarine)
|
||||||
-- MyModGlobal.DumpTable(toGet)
|
-- MyModGlobal.DumpTable(toGet)
|
||||||
|
|
||||||
local items = utils.enqueueInventory(bagItem.OwnInventory, {}, filter)
|
local items, _ = utils.enqueueAllOwnedItems({}, filter)
|
||||||
|
-- if err then
|
||||||
|
-- print(string.format("Error enqueueing all owned items: %s", err))
|
||||||
|
-- return
|
||||||
|
-- end
|
||||||
|
-- dump(items)
|
||||||
|
|
||||||
-- MyModGlobal.DumpTable(items)
|
-- MyModGlobal.DumpTable(items)
|
||||||
-- TODO: This might explode... Oh well?
|
-- TODO: This might explode... Oh well?
|
||||||
local inputInventory = fabricator.item.OwnInventories[1]
|
local inputInventory = fabricator.item.OwnInventories[1]
|
||||||
@@ -157,49 +163,6 @@ local function tryStackFabricator(character)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- If we looked at all items we have on person and still are missing some
|
|
||||||
-- Look at all the items on the submarine
|
|
||||||
local hasAny = false
|
|
||||||
for _, itemInfo in pairs(toFind) do
|
|
||||||
if itemInfo.amount > 0 then
|
|
||||||
hasAny = true
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if hasAny then
|
|
||||||
local submarine = character.Submarine
|
|
||||||
local found
|
|
||||||
if not submarine then
|
|
||||||
MyModGlobal.debugPrint("Submarine not found.")
|
|
||||||
goto done
|
|
||||||
end
|
|
||||||
for item in submarine.GetItems(false) do
|
|
||||||
if remaining == 0 then goto done end
|
|
||||||
for i, itemInfo in pairs(toFind) do
|
|
||||||
found = false
|
|
||||||
for _, prefab in ipairs(itemInfo.prefabs) do
|
|
||||||
-- MyModGlobal.debugPrint(string.format("Checking %s against %s", item.Prefab.Identifier.Value, prefab))
|
|
||||||
if tostring(item.Prefab.Identifier.Value) == prefab then
|
|
||||||
-- MyModGlobal.debugPrint(string.format("That'll do %s %s", item.Prefab.Identifier.Value, prefab))
|
|
||||||
items[#items + 1] = item
|
|
||||||
itemInfo.amount = itemInfo.amount - 1
|
|
||||||
found = true
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if itemInfo.amount <= 0 then
|
|
||||||
-- MyModGlobal.debugPrint(string.format("Removing %s from toFind", itemInfo.prefabs[1]))
|
|
||||||
toFind[i] = nil
|
|
||||||
remaining = remaining - 1
|
|
||||||
end
|
|
||||||
if found then break end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
::done::
|
|
||||||
end
|
|
||||||
|
|
||||||
local slot = -1
|
local slot = -1
|
||||||
local previous = nil
|
local previous = nil
|
||||||
for _, item in ipairs(items) do
|
for _, item in ipairs(items) do
|
||||||
|
@@ -26,16 +26,15 @@ local function getSlots(inventory)
|
|||||||
return slots
|
return slots
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param from Barotrauma.ItemInventory
|
|
||||||
---@param slots InventorySlot[]
|
---@param slots InventorySlot[]
|
||||||
---@return table<InventorySlot, Barotrauma.Item[]>
|
---@return table<InventorySlot, Barotrauma.Item[]>
|
||||||
local function getItemsPerSlot(from, slots)
|
local function getItemsPerSlot(slots)
|
||||||
-- How many items can we move to what slot
|
-- How many items can we move to what slot
|
||||||
-- We don't yet know what can fit into what slot
|
-- We don't yet know what can fit into what slot
|
||||||
---@type table<InventorySlot, Barotrauma.Item[]>
|
---@type table<InventorySlot, Barotrauma.Item[]>
|
||||||
local movableBySlot = {}
|
local movableBySlot = {}
|
||||||
-- Get all the items and then we will sort them by condition and shit
|
-- Get all the items and then we will sort them by condition and shit
|
||||||
utils.enqueueInventory(from, {}, function(ititem, itemRef)
|
utils.enqueueAllPlayerItems({}, function(ititem, itemRef)
|
||||||
-- We don't want to take oxygen out of our diving suit to load our plasma cutter
|
-- We don't want to take oxygen out of our diving suit to load our plasma cutter
|
||||||
-- Most loadable items have 1 capacity
|
-- Most loadable items have 1 capacity
|
||||||
-- But some have 2 or 3 (coil speargun)
|
-- But some have 2 or 3 (coil speargun)
|
||||||
@@ -108,17 +107,6 @@ local function tryReloadSlot(slot, preferMinCondition)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local character = Character.Controlled
|
|
||||||
if not character then
|
|
||||||
MyModGlobal.debugPrint("No character")
|
|
||||||
return
|
|
||||||
end
|
|
||||||
local characterInventory = character.Inventory
|
|
||||||
if not characterInventory then
|
|
||||||
MyModGlobal.debugPrint("No character inventory")
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
---@type InventorySlot[]
|
---@type InventorySlot[]
|
||||||
local slots = getSlots(inventory)
|
local slots = getSlots(inventory)
|
||||||
if #slots == 0 then
|
if #slots == 0 then
|
||||||
@@ -129,7 +117,7 @@ local function tryReloadSlot(slot, preferMinCondition)
|
|||||||
-- dump(slots)
|
-- dump(slots)
|
||||||
|
|
||||||
---@type table<InventorySlot, Barotrauma.Item[]>
|
---@type table<InventorySlot, Barotrauma.Item[]>
|
||||||
local movableBySlot = getItemsPerSlot(characterInventory, slots)
|
local movableBySlot = getItemsPerSlot(slots)
|
||||||
-- MyModGlobal.debugPrint("Movable by slot:")
|
-- MyModGlobal.debugPrint("Movable by slot:")
|
||||||
-- dump(movableBySlot)
|
-- dump(movableBySlot)
|
||||||
|
|
||||||
@@ -186,16 +174,11 @@ local function tryReloadSlot(slot, preferMinCondition)
|
|||||||
MyModGlobal.debugPrint(string.format("Moved %d items to load %s", numMoved, tostring(item.Prefab.Identifier.Value)))
|
MyModGlobal.debugPrint(string.format("Moved %d items to load %s", numMoved, tostring(item.Prefab.Identifier.Value)))
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param minCondition boolean Prefer items with lowest condition
|
---@param preferMinCondition boolean Prefer items with lowest condition
|
||||||
local function tryReloadCursorItem(preferMinCondition)
|
local function tryReloadCursorItem(preferMinCondition)
|
||||||
local slots, err = cursormacroer.getInventorySlotsUnderCursor()
|
local slots, err = utils.getSlotsUnderCursor()
|
||||||
if err then
|
if err then
|
||||||
-- MyModGlobal.debugPrint(string.format("Error getting inventory slot: %s", err))
|
MyModGlobal.debugPrint(string.format("Error getting slots under cursor: %s", err))
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
if not slots or #slots == 0 then
|
|
||||||
-- MyModGlobal.debugPrint("No items in slot")
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@@ -106,7 +106,7 @@ local function tryUnloadSlot(slot)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function tryUnloadCursorItem()
|
local function tryUnloadCursorItem()
|
||||||
local slots, err = cursormacroer.getInventorySlotsUnderCursor()
|
local slots, err = utils.getSlotsUnderCursor()
|
||||||
if err then
|
if err then
|
||||||
-- MyModGlobal.debugPrint(string.format("Error getting inventory slot: %s", err))
|
-- MyModGlobal.debugPrint(string.format("Error getting inventory slot: %s", err))
|
||||||
return
|
return
|
||||||
|
Reference in New Issue
Block a user