Add enqueueOpenContainers
This commit is contained in:
@@ -11,6 +11,23 @@
|
|||||||
---@field inventory Barotrauma.ItemInventory
|
---@field inventory Barotrauma.ItemInventory
|
||||||
---@field slotIndex number
|
---@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
|
-- We got to do this shit because enqueueInventory calls enqueueItem
|
||||||
-- And enqueueItem calls enqueueInventory
|
-- And enqueueItem calls enqueueInventory
|
||||||
-- So unless we define them both before using them
|
-- So unless we define them both before using them
|
||||||
@@ -18,6 +35,7 @@
|
|||||||
local enqueueItem
|
local enqueueItem
|
||||||
local enqueueSlot
|
local enqueueSlot
|
||||||
local enqueueInventory
|
local enqueueInventory
|
||||||
|
local enqueueOpenContainers
|
||||||
local allPlayerItems
|
local allPlayerItems
|
||||||
local allSubmarineItems
|
local allSubmarineItems
|
||||||
local allOwnedItems
|
local allOwnedItems
|
||||||
@@ -163,6 +181,30 @@ allPlayerItems = function(queue, predicate, loadRefs)
|
|||||||
return queue
|
return queue
|
||||||
end
|
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 queue Barotrauma.Item[]
|
||||||
---@param predicate? FilterPredicate
|
---@param predicate? FilterPredicate
|
||||||
---@return Barotrauma.Item[], string?
|
---@return Barotrauma.Item[], string?
|
||||||
@@ -213,23 +255,6 @@ allOwnedItems = function(queue, predicate, loadRefs)
|
|||||||
return queue
|
return queue
|
||||||
end
|
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
|
-- There is actually no need to recurse deep
|
||||||
-- Because we can only have an item in the inventory open
|
-- Because we can only have an item in the inventory open
|
||||||
-- And not an item in an item in the inventory
|
-- And not an item in an item in the inventory
|
||||||
@@ -354,6 +379,7 @@ return {
|
|||||||
enqueueAllPlayerItems = allPlayerItems,
|
enqueueAllPlayerItems = allPlayerItems,
|
||||||
enqueueAllSubmarineItems = allSubmarineItems,
|
enqueueAllSubmarineItems = allSubmarineItems,
|
||||||
enqueueAllOwnedItems = allOwnedItems,
|
enqueueAllOwnedItems = allOwnedItems,
|
||||||
|
enqueueOpenContainers = enqueueOpenContainers,
|
||||||
getOpenContainers = getOpenContainers,
|
getOpenContainers = getOpenContainers,
|
||||||
getFirstOpenContainer = getFirstOpenContainer,
|
getFirstOpenContainer = getFirstOpenContainer,
|
||||||
getSlotsUnderCursor = getSlotsUnderCursor,
|
getSlotsUnderCursor = getSlotsUnderCursor,
|
||||||
|
|||||||
Reference in New Issue
Block a user