Fix up some other warnings

This commit is contained in:
2025-04-01 20:10:36 +02:00
parent 21eda6a5ac
commit bb7dc1da32
2 changed files with 17 additions and 12 deletions

View File

@@ -3,7 +3,7 @@ if not CLIENT then return end
local utils = require("Cyka.utils") local utils = require("Cyka.utils")
local dump = require("Cyka.dump") local dump = require("Cyka.dump")
---@return {item: Barotrauma.Item, fabricator: Barotrauma.FabricatorComponent}, string? ---@return {item: Barotrauma.Item, fabricator: Barotrauma.Items.Components.Fabricator}?, string?
local function getOpenFabricator() local function getOpenFabricator()
-- Get the controlled character -- Get the controlled character
local controlledCharacter = Character.Controlled local controlledCharacter = Character.Controlled
@@ -29,8 +29,8 @@ end
---@field targetItem {identifier: string, name: string, amount: number} ---@field targetItem {identifier: string, name: string, amount: number}
---@field requiredItems {amount: number, minCondition: number, maxCondition: number, prefabs: string[]}[] ---@field requiredItems {amount: number, minCondition: number, maxCondition: number, prefabs: string[]}[]
---@param fabricator Barotrauma.FabricatorComponent ---@param fabricator Barotrauma.Items.Components.Fabricator
---@return RecipeInfo, string? ---@return RecipeInfo?, string?
local function getSelectedRecipeRequirements(fabricator) local function getSelectedRecipeRequirements(fabricator)
-- local openFabricator, err = getOpenFabricator() -- local openFabricator, err = getOpenFabricator()
-- if err then return nil, err end -- if err then return nil, err end
@@ -73,7 +73,7 @@ local function tryStackFabricator(character)
MyModGlobal.debugPrint("Character inventory is nil.") MyModGlobal.debugPrint("Character inventory is nil.")
return return
end end
---@type Barotrauma.ItemInventory.Slot ---@type Barotrauma.Inventory.ItemSlot
local bagSlot = inventory.slots[MyModGlobal.BAG_SLOT] local bagSlot = inventory.slots[MyModGlobal.BAG_SLOT]
if not bagSlot then if not bagSlot then
MyModGlobal.debugPrint("Bag slot not found.") MyModGlobal.debugPrint("Bag slot not found.")
@@ -91,14 +91,14 @@ local function tryStackFabricator(character)
end end
local fabricator, err = getOpenFabricator() local fabricator, err = getOpenFabricator()
if err then if err or not fabricator then
print(string.format("Error getting open fabricator: %s", err)) print(string.format("Error getting open fabricator: %s", err))
return return
end end
local recipe local recipe
recipe, err = getSelectedRecipeRequirements(fabricator.fabricator) recipe, err = getSelectedRecipeRequirements(fabricator.fabricator)
if err then if err or not recipe then
print(string.format("Error getting selected recipe requirements: %s", err)) print(string.format("Error getting selected recipe requirements: %s", err))
return return
end end
@@ -147,7 +147,10 @@ local function tryStackFabricator(character)
-- dump(itemsOnSubmarine) -- dump(itemsOnSubmarine)
-- MyModGlobal.DumpTable(toGet) -- MyModGlobal.DumpTable(toGet)
local items, _ = utils.enqueueAllOwnedItems({}, filter) local items, _ = utils.enqueueAllOwnedItems({
recurse = true,
itemPredicate = filter
})
-- if err then -- if err then
-- print(string.format("Error enqueueing all owned items: %s", err)) -- print(string.format("Error enqueueing all owned items: %s", err))
-- return -- return

View File

@@ -4,12 +4,12 @@ if not CLIENT then return end
---@return Barotrauma.Location.StoreInfo[], string? ---@return Barotrauma.Location.StoreInfo[], string?
local function getCurrentStore() local function getCurrentStore()
if not Game or not Game.GameSession or not Game.GameSession.Campaign then if not Game or not Game.GameSession or not Game.GameSession.Campaign then
return nil, "No game session found" return {}, "No game session found"
end end
local map = Game.GameSession.Campaign.Map local map = Game.GameSession.Campaign.Map
if not map or not map.CurrentLocation or not map.CurrentLocation.Stores then if not map or not map.CurrentLocation or not map.CurrentLocation.Stores then
return nil, "No map found" return {}, "No map found"
end end
local location = map.CurrentLocation local location = map.CurrentLocation
@@ -17,13 +17,13 @@ local function getCurrentStore()
-- Otherwise, determine which store is active by checking the cargo manager -- Otherwise, determine which store is active by checking the cargo manager
local cargoManager = Game.GameSession.Campaign.CargoManager local cargoManager = Game.GameSession.Campaign.CargoManager
if not cargoManager then if not cargoManager then
return nil, "No cargo manager found" return {}, "No cargo manager found"
end end
-- Find which store has items in the cart -- Find which store has items in the cart
local stores = {} local stores = {}
for _, store in pairs(location.Stores) do for _, store in pairs(location.Stores) do
if #cargoManager:GetBuyCrateItems(store) > 0 then if #cargoManager:GetBuyCrateItems() > 0 then
stores[#stores + 1] = store stores[#stores + 1] = store
end end
end end
@@ -47,7 +47,7 @@ local function tryBuy()
for _, store in ipairs(stores) do for _, store in ipairs(stores) do
local toAdd = {} local toAdd = {}
-- Get items available at the store -- Get items available at the store
local items = cargoManager:GetBuyCrateItems(store) local items = cargoManager:GetBuyCrateItems()
for item in items do for item in items do
-- We have already added this many of item -- We have already added this many of item
toAdd[item.ItemPrefab.Identifier.Value] = { toAdd[item.ItemPrefab.Identifier.Value] = {
@@ -55,6 +55,7 @@ local function tryBuy()
prefab = item.ItemPrefab -- Store the ItemPrefab object prefab = item.ItemPrefab -- Store the ItemPrefab object
} }
end end
---@diagnostic disable-next-line: undefined-field
for item in store.Stock do for item in store.Stock do
-- So if we add the total amount available -- So if we add the total amount available
-- We get the amount we have to add to buy entire stock -- We get the amount we have to add to buy entire stock
@@ -68,6 +69,7 @@ local function tryBuy()
if info.quantity > 0 then if info.quantity > 0 then
MyModGlobal.debugPrint(string.format("Adding %d of %s to the buy crate", info.quantity, idValue)) MyModGlobal.debugPrint(string.format("Adding %d of %s to the buy crate", info.quantity, idValue))
-- Use the stored ItemPrefab object, not the string identifier -- Use the stored ItemPrefab object, not the string identifier
---@diagnostic disable-next-line: undefined-field
cargoManager:ModifyItemQuantityInBuyCrate(store.Identifier, info.prefab, info.quantity) cargoManager:ModifyItemQuantityInBuyCrate(store.Identifier, info.prefab, info.quantity)
end end
end end