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

View File

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