Add enqueueOpenContainers
This commit is contained in:
@@ -11,6 +11,23 @@
|
||||
---@field inventory Barotrauma.ItemInventory
|
||||
---@field slotIndex number
|
||||
|
||||
---@return Barotrauma.Item[], string?
|
||||
local function getOpenContainers()
|
||||
local controlledCharacter = Character.Controlled
|
||||
if not controlledCharacter then return {}, "No controlled character" end
|
||||
local selectedItem = controlledCharacter.SelectedItem
|
||||
if not selectedItem then return {}, "No selected item" end
|
||||
return { selectedItem }, nil
|
||||
end
|
||||
|
||||
---@return Barotrauma.Item, string?
|
||||
local function getFirstOpenContainer()
|
||||
local containers, err = getOpenContainers()
|
||||
if err then return nil, err end
|
||||
if #containers == 0 then return nil, "No open containers" end
|
||||
return containers[1], nil
|
||||
end
|
||||
|
||||
-- We got to do this shit because enqueueInventory calls enqueueItem
|
||||
-- And enqueueItem calls enqueueInventory
|
||||
-- So unless we define them both before using them
|
||||
@@ -18,6 +35,7 @@
|
||||
local enqueueItem
|
||||
local enqueueSlot
|
||||
local enqueueInventory
|
||||
local enqueueOpenContainers
|
||||
local allPlayerItems
|
||||
local allSubmarineItems
|
||||
local allOwnedItems
|
||||
@@ -163,6 +181,30 @@ allPlayerItems = function(queue, predicate, loadRefs)
|
||||
return queue
|
||||
end
|
||||
|
||||
---@param queue Barotrauma.Item[]
|
||||
---@param predicate? FilterPredicate
|
||||
---@param loadRefs? boolean
|
||||
---@return Barotrauma.Item[], string?
|
||||
enqueueOpenContainers = function(queue, predicate, loadRefs)
|
||||
queue = queue or {}
|
||||
predicate = predicate or function() return true end
|
||||
|
||||
local containers, err = getOpenContainers()
|
||||
if err then return queue, err end
|
||||
|
||||
for _, container in ipairs(containers) do
|
||||
local inventories = container.OwnInventories
|
||||
if not inventories then goto continue end
|
||||
for containerInventory in inventories do
|
||||
queue, err = enqueueInventory(containerInventory, queue, predicate, loadRefs)
|
||||
if err then return queue, err end
|
||||
end
|
||||
::continue::
|
||||
end
|
||||
|
||||
return queue
|
||||
end
|
||||
|
||||
---@param queue Barotrauma.Item[]
|
||||
---@param predicate? FilterPredicate
|
||||
---@return Barotrauma.Item[], string?
|
||||
@@ -213,23 +255,6 @@ allOwnedItems = function(queue, predicate, loadRefs)
|
||||
return queue
|
||||
end
|
||||
|
||||
---@return Barotrauma.Item[], string?
|
||||
local function getOpenContainers()
|
||||
local controlledCharacter = Character.Controlled
|
||||
if not controlledCharacter then return {}, "No controlled character" end
|
||||
local selectedItem = controlledCharacter.SelectedItem
|
||||
if not selectedItem then return {}, "No selected item" end
|
||||
return { selectedItem }, nil
|
||||
end
|
||||
|
||||
---@return Barotrauma.Item, string?
|
||||
local function getFirstOpenContainer()
|
||||
local containers, err = getOpenContainers()
|
||||
if err then return nil, err end
|
||||
if #containers == 0 then return nil, "No open containers" end
|
||||
return containers[1], nil
|
||||
end
|
||||
|
||||
-- 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
|
||||
@@ -354,6 +379,7 @@ return {
|
||||
enqueueAllPlayerItems = allPlayerItems,
|
||||
enqueueAllSubmarineItems = allSubmarineItems,
|
||||
enqueueAllOwnedItems = allOwnedItems,
|
||||
enqueueOpenContainers = enqueueOpenContainers,
|
||||
getOpenContainers = getOpenContainers,
|
||||
getFirstOpenContainer = getFirstOpenContainer,
|
||||
getSlotsUnderCursor = getSlotsUnderCursor,
|
||||
|
||||
Reference in New Issue
Block a user