Fix goto disasters
This commit is contained in:
@@ -3,7 +3,7 @@ if SERVER then return end
|
|||||||
-- Register necessary types and make fields accessible
|
-- Register necessary types and make fields accessible
|
||||||
LuaUserData.RegisterType("Barotrauma.Items.Components.ItemContainer+SlotRestrictions")
|
LuaUserData.RegisterType("Barotrauma.Items.Components.ItemContainer+SlotRestrictions")
|
||||||
LuaUserData.RegisterType(
|
LuaUserData.RegisterType(
|
||||||
'System.Collections.Immutable.ImmutableArray`1[[Barotrauma.Items.Components.ItemContainer+SlotRestrictions, Barotrauma]]')
|
'System.Collections.Immutable.ImmutableArray`1[[Barotrauma.Items.Components.ItemContainer+SlotRestrictions, Barotrauma]]')
|
||||||
LuaUserData.MakeFieldAccessible(Descriptors['Barotrauma.Items.Components.ItemContainer'], 'slotRestrictions')
|
LuaUserData.MakeFieldAccessible(Descriptors['Barotrauma.Items.Components.ItemContainer'], 'slotRestrictions')
|
||||||
LuaUserData.MakeFieldAccessible(Descriptors['Barotrauma.ItemInventory'], 'slots')
|
LuaUserData.MakeFieldAccessible(Descriptors['Barotrauma.ItemInventory'], 'slots')
|
||||||
LuaUserData.MakeFieldAccessible(Descriptors["Barotrauma.CharacterInventory"], "slots")
|
LuaUserData.MakeFieldAccessible(Descriptors["Barotrauma.CharacterInventory"], "slots")
|
||||||
@@ -62,7 +62,7 @@ local function findContainersInInventory(character)
|
|||||||
if CONFIG.CHECK_ALL_CONTAINERS then
|
if CONFIG.CHECK_ALL_CONTAINERS then
|
||||||
for slotIndex, slot in ipairs(inventory.slots) do
|
for slotIndex, slot in ipairs(inventory.slots) do
|
||||||
-- Skip the primary bag slot as we already processed it
|
-- Skip the primary bag slot as we already processed it
|
||||||
if slotIndex == CONFIG.PRIMARY_BAG_SLOT then goto continue end
|
if slotIndex == CONFIG.PRIMARY_BAG_SLOT then goto continueSlot end
|
||||||
|
|
||||||
-- Skip hand slots if configured to do so
|
-- Skip hand slots if configured to do so
|
||||||
if CONFIG.SKIP_HAND_SLOTS then
|
if CONFIG.SKIP_HAND_SLOTS then
|
||||||
@@ -73,7 +73,7 @@ local function findContainersInInventory(character)
|
|||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if isHandSlot then goto continue end
|
if isHandSlot then goto continueSlot end
|
||||||
end
|
end
|
||||||
|
|
||||||
for _, item in ipairs(slot.items) do
|
for _, item in ipairs(slot.items) do
|
||||||
@@ -82,7 +82,7 @@ local function findContainersInInventory(character)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
::continue::
|
::continueSlot::
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -124,35 +124,23 @@ local function tryStackItemInSlot(container, sourceItem, slotIndex)
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Function to quick stack items into containers
|
-- Function to process a single inventory slot
|
||||||
local function quickStackToContainers(character, containers)
|
local function processInventorySlot(playerInv, slotIndex, containers, processedCount, stackedCount)
|
||||||
if not character or #containers == 0 then return end
|
-- Check if this slot should be skipped (hand slots)
|
||||||
|
|
||||||
local playerInv = character.Inventory
|
|
||||||
local processedCount = 0
|
|
||||||
local stackedCount = 0
|
|
||||||
|
|
||||||
-- Process inventory slots
|
|
||||||
for slotIndex = 1, #playerInv.slots do
|
|
||||||
-- Skip hand slots if configured to do so
|
|
||||||
if CONFIG.SKIP_HAND_SLOTS then
|
if CONFIG.SKIP_HAND_SLOTS then
|
||||||
local isHandSlot = false
|
|
||||||
for _, handSlot in ipairs(CONFIG.HAND_SLOTS) do
|
for _, handSlot in ipairs(CONFIG.HAND_SLOTS) do
|
||||||
if slotIndex == handSlot then
|
if slotIndex == handSlot then
|
||||||
isHandSlot = true
|
return processedCount, stackedCount
|
||||||
break
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if isHandSlot then goto continue end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local slot = playerInv.slots[slotIndex]
|
local slot = playerInv.slots[slotIndex]
|
||||||
if not slot then goto continue end
|
if not slot then return processedCount, stackedCount end
|
||||||
|
|
||||||
-- Process items in the slot
|
-- Process items in the slot
|
||||||
for i = #slot.items, 1, -1 do -- Iterate backwards to safely remove
|
for i = #slot.items, 1, -1 do -- Iterate backwards to safely remove
|
||||||
local item = slot.items[i]
|
local item = slot.items[i]
|
||||||
-- Declare success variable outside any potential goto jumps
|
|
||||||
local success = false
|
local success = false
|
||||||
|
|
||||||
-- Skip containers themselves
|
-- Skip containers themselves
|
||||||
@@ -164,10 +152,9 @@ local function quickStackToContainers(character, containers)
|
|||||||
processedCount = processedCount + 1
|
processedCount = processedCount + 1
|
||||||
if processedCount > CONFIG.MAX_ITEMS_TO_PROCESS then
|
if processedCount > CONFIG.MAX_ITEMS_TO_PROCESS then
|
||||||
print("QuickStack: Safety limit reached")
|
print("QuickStack: Safety limit reached")
|
||||||
return stackedCount
|
return processedCount, stackedCount
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Try to stack the item into the containers
|
|
||||||
-- Try each container in order
|
-- Try each container in order
|
||||||
for _, container in ipairs(containers) do
|
for _, container in ipairs(containers) do
|
||||||
local containerInv = container.OwnInventory
|
local containerInv = container.OwnInventory
|
||||||
@@ -205,7 +192,26 @@ local function quickStackToContainers(character, containers)
|
|||||||
::nextItem::
|
::nextItem::
|
||||||
end
|
end
|
||||||
|
|
||||||
::continue::
|
return processedCount, stackedCount
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Function to quick stack items into containers
|
||||||
|
local function quickStackToContainers(character, containers)
|
||||||
|
if not character or #containers == 0 then return 0 end
|
||||||
|
|
||||||
|
local playerInv = character.Inventory
|
||||||
|
local processedCount = 0
|
||||||
|
local stackedCount = 0
|
||||||
|
|
||||||
|
-- Process each inventory slot
|
||||||
|
for slotIndex = 1, #playerInv.slots do
|
||||||
|
processedCount, stackedCount = processInventorySlot(
|
||||||
|
playerInv,
|
||||||
|
slotIndex,
|
||||||
|
containers,
|
||||||
|
processedCount,
|
||||||
|
stackedCount
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
return stackedCount
|
return stackedCount
|
||||||
|
|||||||
Reference in New Issue
Block a user