Add fabricator filler hotkeyer
This commit is contained in:
@@ -10,9 +10,10 @@ LuaUserData.MakeFieldAccessible(Descriptors["Barotrauma.CharacterInventory"], "s
|
|||||||
|
|
||||||
-- Simple configuration
|
-- Simple configuration
|
||||||
local CONFIG = {
|
local CONFIG = {
|
||||||
TRIGGER_KEY = Keys.F, -- Key to press for quick stacking
|
QUICKSTACK_KEYS = Keys.F,
|
||||||
NESTED_CONTAINERS = true, -- Whether to include nested containers
|
FABRICATOR_KEY = Keys.V,
|
||||||
DEBUG_MODE = true, -- Print debug messages
|
NESTED_CONTAINERS = true,
|
||||||
|
DEBUG_MODE = true,
|
||||||
}
|
}
|
||||||
|
|
||||||
-- MOD INFO
|
-- MOD INFO
|
||||||
@@ -375,10 +376,102 @@ end
|
|||||||
|
|
||||||
-- Hook into player control to listen for key press
|
-- Hook into player control to listen for key press
|
||||||
Hook.Patch("Barotrauma.Character", "ControlLocalPlayer", function(instance, ptable)
|
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
|
local character = instance
|
||||||
if not character then return end
|
if not character then return end
|
||||||
|
|
||||||
quickStackItems(character)
|
quickStackItems(character)
|
||||||
end, Hook.HookMethodType.After)
|
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