Files
barotrauma-localmods/QuickStackToBag/Lua/Autorun/init.lua

166 lines
6.4 KiB
Lua

if SERVER then return end
-- Docs: https://evilfactory.github.io/LuaCsForBarotrauma/lua-docs/manual/common-questions/
---@class MyModGlobal
---@field CONFIG {QUICKSTACK_KEYS: Keys, FABRICATOR_KEY: Keys, MAX_BUY: Keys, NESTED_CONTAINERS: boolean, DEBUG_MODE: boolean}
---@field MOD_NAME string
---@field MOD_VERSION string
---@field DumpTable fun(table: table, depth?: number)
---@field debugPrint fun(message: string)
MyModGlobal = {
CONFIG = {
QUICKSTACK_KEYS = Keys.F,
FABRICATOR_KEY = Keys.V,
MAX_BUY = Keys.B,
NESTED_CONTAINERS = true,
DEBUG_MODE = true,
},
MOD_NAME = "Quick Stack To Containers",
MOD_VERSION = "1.1.0",
BAG_SLOT = 8,
}
---@param table table
---@param depth number?
MyModGlobal.DumpTable = function(table, depth)
if depth == nil then
depth = 0
end
if (depth > 200) then
print("Error: Depth > 200 in dumpTable()")
return
end
for k, v in pairs(table) do
if (type(v) == "table") then
print(string.rep(" ", depth) .. k .. ":")
MyModGlobal.DumpTable(v, depth + 1)
else
print(string.rep(" ", depth) .. k .. ": ", v)
end
end
end
-- Debugging helper function
MyModGlobal.debugPrint = function(message)
if MyModGlobal.CONFIG.DEBUG_MODE then
print("[" .. MyModGlobal.MOD_NAME .. "] " .. message)
end
end
require("Cyka.quickstack")
print(MyModGlobal.MOD_NAME .. " v" .. MyModGlobal.MOD_VERSION .. " loaded!")
-- Register necessary types and make fields accessible
LuaUserData.RegisterType("Barotrauma.Items.Components.ItemContainer+SlotRestrictions")
LuaUserData.RegisterType(
'System.Collections.Immutable.ImmutableArray`1[[Barotrauma.Items.Components.ItemContainer+SlotRestrictions, Barotrauma]]')
LuaUserData.MakeFieldAccessible(Descriptors['Barotrauma.Items.Components.ItemContainer'], 'slotRestrictions')
LuaUserData.MakeFieldAccessible(Descriptors['Barotrauma.ItemInventory'], 'slots')
LuaUserData.MakeFieldAccessible(Descriptors["Barotrauma.CharacterInventory"], "slots")
LuaUserData.RegisterType("Barotrauma.Store")
LuaUserData.RegisterType("Barotrauma.GUIComponent")
LuaUserData.RegisterType("Barotrauma.PurchasedItem")
LuaUserData.RegisterType("Barotrauma.ItemPrefab")
LuaUserData.RegisterType("Barotrauma.Location+StoreInfo")
LuaUserData.MakeMethodAccessible(Descriptors["Barotrauma.CargoManager"], "GetConfirmedSoldEntities")
-- -- Register necessary type to access VisualSlot
-- LuaUserData.RegisterType("Barotrauma.VisualSlot")
--
-- ---@return Barotrauma.VisualSlot|nil, Barotrauma.ItemInventory|nil, Barotrauma.Item|nil
-- local function getInventorySlotUnderCursor()
-- -- Make sure we have a controlled character
-- local controlledCharacter = Character.Controlled
-- if not controlledCharacter then return nil, nil, nil end
--
-- -- Check player inventory first
-- local charInventory = controlledCharacter.Inventory
-- if charInventory and charInventory.visualSlots then
-- for i, visualSlot in ipairs(charInventory.visualSlots) do
-- -- Check if mouse is over this slot
-- if visualSlot:MouseOn() then
-- local slot = charInventory.slots[i]
-- local item = nil
-- if #slot.items > 0 then
-- item = slot.items[1]
-- end
-- return visualSlot, charInventory, item
-- end
-- end
-- end
--
-- -- Check if selected item has inventory (containers, etc.)
-- local selectedItem = controlledCharacter.SelectedItem
-- if selectedItem and selectedItem.OwnInventory and selectedItem.OwnInventory.visualSlots then
-- local itemInv = selectedItem.OwnInventory
-- for i, visualSlot in ipairs(itemInv.visualSlots) do
-- if visualSlot:MouseOn() then
-- local slot = itemInv.slots[i]
-- local item = nil
-- if #slot.items > 0 then
-- item = slot.items[1]
-- end
-- return visualSlot, itemInv, item
-- end
-- end
-- end
--
-- -- Check open containers or other items with visible inventories
-- for item in Item.ItemList do
-- if item and item.OwnInventory and item.OwnInventory.visualSlots then
-- local itemInv = item.OwnInventory
-- for i, visualSlot in ipairs(itemInv.visualSlots) do
-- if visualSlot:MouseOn() then
-- local slot = itemInv.slots[i]
-- local slotItem = nil
-- if #slot.items > 0 then
-- slotItem = slot.items[1]
-- end
-- return visualSlot, itemInv, slotItem
-- end
-- end
-- end
-- end
--
-- return nil, nil, nil
-- end
-- -- Register necessary types for detecting repairable objects
-- LuaUserData.RegisterType("Barotrauma.Items.Components.Repairable")
-- LuaUserData.MakeFieldAccessible(Descriptors["Barotrauma.Items.Components.Repairable"], "RepairButton")
--
-- ---@return Barotrauma.Item|nil, Barotrauma.Items.Components.Repairable|nil
-- local function getRepairableObjectInFocus()
-- -- Make sure we have a controlled character
-- local controlledCharacter = Character.Controlled
-- if not controlledCharacter then return nil, nil end
--
-- -- Check if we have a selected item - this is necessary for repair interfaces to show
-- local selectedItem = controlledCharacter.SelectedItem
-- if not selectedItem then return nil, nil end
--
-- -- Check if the selected item is in fact the repairable object itself
-- for _, component in pairs(selectedItem.Components) do
-- if component.name == "Repairable" then
-- -- Check if repair interface should be shown
-- if component:ShouldDrawHUD(controlledCharacter) then
-- return selectedItem, component
-- end
-- end
-- end
--
-- -- Nothing found
-- return nil, nil
-- end
--
-- ---@return boolean
-- local function isRepairButtonVisible()
-- local _, repairableComponent = getRepairableObjectInFocus()
-- if not repairableComponent then return false end
--
-- -- Check if the repair button exists and is visible
-- local repairButton = repairableComponent.RepairButton
-- return repairButton ~= nil and repairButton.Visible
-- end