Add fabricator filler hotkeyer
This commit is contained in:
@@ -10,9 +10,10 @@ LuaUserData.MakeFieldAccessible(Descriptors["Barotrauma.CharacterInventory"], "s
|
||||
|
||||
-- Simple configuration
|
||||
local CONFIG = {
|
||||
TRIGGER_KEY = Keys.F, -- Key to press for quick stacking
|
||||
NESTED_CONTAINERS = true, -- Whether to include nested containers
|
||||
DEBUG_MODE = true, -- Print debug messages
|
||||
QUICKSTACK_KEYS = Keys.F,
|
||||
FABRICATOR_KEY = Keys.V,
|
||||
NESTED_CONTAINERS = true,
|
||||
DEBUG_MODE = true,
|
||||
}
|
||||
|
||||
-- MOD INFO
|
||||
@@ -375,10 +376,102 @@ end
|
||||
|
||||
-- Hook into player control to listen for key press
|
||||
Hook.Patch("Barotrauma.Character", "ControlLocalPlayer", function(instance, ptable)
|
||||
if not PlayerInput.KeyHit(CONFIG.TRIGGER_KEY) then return end
|
||||
if not PlayerInput.KeyHit(CONFIG.QUICKSTACK_KEYS) then return end
|
||||
|
||||
local character = instance
|
||||
if not character then return end
|
||||
|
||||
quickStackItems(character)
|
||||
end, Hook.HookMethodType.After)
|
||||
|
||||
----------------------------------------------------------------------------------------------------
|
||||
----------------------------------------------------------------------------------------------------
|
||||
----------------------------------------------------------------------------------------------------
|
||||
----------------------------------------------------------------------------------------------------
|
||||
----------------------------------------------------------------------------------------------------
|
||||
----------------------------------------------------------------------------------------------------
|
||||
----------------------------------------------------------------------------------------------------
|
||||
----------------------------------------------------------------------------------------------------
|
||||
----------------------------------------------------------------------------------------------------
|
||||
----------------------------------------------------------------------------------------------------
|
||||
----------------------------------------------------------------------------------------------------
|
||||
----------------------------------------------------------------------------------------------------
|
||||
----------------------------------------------------------------------------------------------------
|
||||
----------------------------------------------------------------------------------------------------
|
||||
----------------------------------------------------------------------------------------------------
|
||||
----------------------------------------------------------------------------------------------------
|
||||
|
||||
---@return {item: Barotrauma.Item, fabricator: Barotrauma.FabricatorComponent}, string?
|
||||
local function getOpenFabricator()
|
||||
-- Get the controlled character
|
||||
local controlledCharacter = Character.Controlled
|
||||
if not controlledCharacter then return nil, "No controlled character found" end
|
||||
|
||||
-- Check if the character has a selected item
|
||||
local selectedItem = controlledCharacter.SelectedItem
|
||||
if not selectedItem then return nil, "No selected item found" end
|
||||
|
||||
-- Check if the selected item has a Fabricator component
|
||||
local fabricator = Game.GetFabricatorComponent(selectedItem)
|
||||
if not fabricator then return nil, "No fabricator component found" end
|
||||
|
||||
return {
|
||||
item = selectedItem,
|
||||
fabricator = fabricator
|
||||
}
|
||||
end
|
||||
|
||||
--- Recipes can have multiple inputs, for example ammo
|
||||
--- Can be made either out of copper iron or steel, 1 of either
|
||||
---@class RecipeInfo
|
||||
---@field targetItem {identifier: string, name: string, amount: number}
|
||||
---@field requiredItems {amount: number, minCondition: number, maxCondition: number, prefabs: string[]}[]
|
||||
|
||||
---@return RecipeInfo, string?
|
||||
local function getSelectedRecipeRequirements()
|
||||
local openFabricator, err = getOpenFabricator()
|
||||
if err then return nil, err end
|
||||
|
||||
local fabricator = openFabricator.fabricator
|
||||
local selectedRecipe = fabricator.SelectedItem
|
||||
if not selectedRecipe then return nil, "No selected recipe found" end
|
||||
|
||||
local requiredItems = {}
|
||||
for _, requiredItem in pairs(selectedRecipe.RequiredItems) do
|
||||
local itemInfo = {
|
||||
amount = tonumber(requiredItem.Amount),
|
||||
minCondition = tonumber(requiredItem.MinCondition),
|
||||
maxCondition = tonumber(requiredItem.MaxCondition),
|
||||
prefabs = {}
|
||||
}
|
||||
|
||||
for prefab in requiredItem.ItemPrefabs do
|
||||
itemInfo.prefabs[#itemInfo.prefabs + 1] = prefab.Identifier
|
||||
end
|
||||
|
||||
requiredItems[#requiredItems + 1] = itemInfo
|
||||
end
|
||||
|
||||
return {
|
||||
targetItem = {
|
||||
identifier = selectedRecipe.TargetItem.Identifier,
|
||||
name = selectedRecipe.TargetItem.Name,
|
||||
amount = selectedRecipe.Amount
|
||||
},
|
||||
requiredItems = requiredItems
|
||||
}
|
||||
end
|
||||
|
||||
-- Hook into player control to listen for key press
|
||||
Hook.Patch("Barotrauma.Character", "ControlLocalPlayer", function(instance, ptable)
|
||||
if not PlayerInput.KeyHit(CONFIG.FABRICATOR_KEY) then return end
|
||||
|
||||
local character = instance
|
||||
if not character then return end
|
||||
|
||||
local recipe, err = getSelectedRecipeRequirements()
|
||||
if err then
|
||||
print(string.format("Error getting selected recipe requirements: %s", err))
|
||||
end
|
||||
DumpTable(recipe)
|
||||
end, Hook.HookMethodType.After)
|
||||
|
||||
Reference in New Issue
Block a user