Make G work with open containers too
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
if not CLIENT then return end
|
if not CLIENT then return end
|
||||||
|
|
||||||
local utils = require("Cyka.utils")
|
local utils = require("Cyka.utils")
|
||||||
|
local dump = require("Cyka.dump")
|
||||||
|
|
||||||
---@class ItemLocation
|
---@class ItemLocation
|
||||||
---@field inventory Barotrauma.ItemInventory
|
---@field inventory Barotrauma.ItemInventory
|
||||||
@@ -124,7 +125,9 @@ local function tryMoveItem(item, itemTree, force)
|
|||||||
-- MyModGlobal.debugPrint(string.format("Can be put in slot %d: %s", itemLocation.slotIndex, tostring(canBePut)))
|
-- MyModGlobal.debugPrint(string.format("Can be put in slot %d: %s", itemLocation.slotIndex, tostring(canBePut)))
|
||||||
|
|
||||||
if itemLocation.maxFits > 0 and canBePut then
|
if itemLocation.maxFits > 0 and canBePut then
|
||||||
moved = moved or itemLocation.inventory.TryPutItem(item, itemLocation.slotIndex, false, true, Character.Controlled, true)
|
moved = moved or
|
||||||
|
itemLocation.inventory.TryPutItem(item, itemLocation.slotIndex, false, true, Character.Controlled,
|
||||||
|
true)
|
||||||
if moved then
|
if moved then
|
||||||
itemLocation.maxFits = itemLocation.inventory.HowManyCanBePut(item.Prefab, itemLocation.slotIndex)
|
itemLocation.maxFits = itemLocation.inventory.HowManyCanBePut(item.Prefab, itemLocation.slotIndex)
|
||||||
end
|
end
|
||||||
@@ -152,7 +155,9 @@ local function tryMoveItem(item, itemTree, force)
|
|||||||
|
|
||||||
if maxFits > 0 then
|
if maxFits > 0 then
|
||||||
-- MyModGlobal.debugPrint(string.format("Trying to move item to empty slot at index: %d", itemLocation.slotIndex))
|
-- MyModGlobal.debugPrint(string.format("Trying to move item to empty slot at index: %d", itemLocation.slotIndex))
|
||||||
moved = moved or itemLocation.inventory.TryPutItem(item, itemLocation.slotIndex, true, false, Character.Controlled, true)
|
moved = moved or
|
||||||
|
itemLocation.inventory.TryPutItem(item, itemLocation.slotIndex, true, false, Character.Controlled,
|
||||||
|
true)
|
||||||
if moved then
|
if moved then
|
||||||
itemLocation.maxFits = itemLocation.inventory.HowManyCanBePut(item.Prefab, itemLocation.slotIndex)
|
itemLocation.maxFits = itemLocation.inventory.HowManyCanBePut(item.Prefab, itemLocation.slotIndex)
|
||||||
end
|
end
|
||||||
@@ -225,7 +230,9 @@ end
|
|||||||
-- Function to quickly stack items from inventory to containers
|
-- Function to quickly stack items from inventory to containers
|
||||||
-- 6 and 7 are hands
|
-- 6 and 7 are hands
|
||||||
-- 9..18 are main slots
|
-- 9..18 are main slots
|
||||||
local inventorySlotsToStack = { 6, 7, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18 }
|
local inventorySlotsToStack = { 6, 7, }
|
||||||
|
-- local inventorySlotsToStack = { 6, 7, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18 }
|
||||||
|
---@param character Barotrauma.Character
|
||||||
local function quickStackItems(character)
|
local function quickStackItems(character)
|
||||||
if not character then
|
if not character then
|
||||||
MyModGlobal.debugPrint("No character found")
|
MyModGlobal.debugPrint("No character found")
|
||||||
@@ -257,30 +264,37 @@ local function quickStackItems(character)
|
|||||||
--DumpTable(itemTree)
|
--DumpTable(itemTree)
|
||||||
local toMove = {}
|
local toMove = {}
|
||||||
|
|
||||||
for _, slotid in ipairs(inventorySlotsToStack) do
|
for item in character.HeldItems do
|
||||||
MyModGlobal.debugPrint(string.format("Processing inventory slot: %d", slotid))
|
MyModGlobal.debugPrint(string.format("Item: %s", item.Prefab.Identifier.Value))
|
||||||
local slot = inventory.slots[slotid]
|
if item.OwnInventory then
|
||||||
if #slot.items > 0 then
|
toMove = utils.enqueueInventory(item.OwnInventory, toMove)
|
||||||
local item = slot.items[1]
|
|
||||||
local tags = item.Prefab.Tags
|
|
||||||
local shouldSuss = true
|
|
||||||
for tag in tags do
|
|
||||||
if tag.value:find("tool") or tag.value:find("weapon") then
|
|
||||||
MyModGlobal.debugPrint(string.format("Item '%s' is a tool or weapon, skipping", item.Name))
|
|
||||||
shouldSuss = false
|
|
||||||
break
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if shouldSuss then
|
-- for _, slotid in ipairs(inventorySlotsToStack) do
|
||||||
local before = #toMove
|
-- MyModGlobal.debugPrint(string.format("Processing inventory slot: %d", slotid))
|
||||||
toMove = utils.enqueueSlot(slot, toMove)
|
-- local slot = inventory.slots[slotid]
|
||||||
local after = #toMove
|
-- if #slot.items > 0 then
|
||||||
MyModGlobal.debugPrint(string.format("Enqueued %d items from the inventory slot %d", after - before,
|
-- -- local item = slot.items[1]
|
||||||
slotid))
|
-- -- local tags = item.Prefab.Tags
|
||||||
end
|
-- local shouldSuss = true
|
||||||
end
|
-- -- for tag in tags do
|
||||||
end
|
-- -- if tag.value:find("tool") or tag.value:find("weapon") then
|
||||||
|
-- -- MyModGlobal.debugPrint(string.format("Item '%s' is a tool or weapon, skipping", item.Name))
|
||||||
|
-- -- shouldSuss = false
|
||||||
|
-- -- break
|
||||||
|
-- -- end
|
||||||
|
-- -- end
|
||||||
|
|
||||||
|
-- if shouldSuss then
|
||||||
|
-- local before = #toMove
|
||||||
|
-- toMove = utils.enqueueSlot(slot, toMove)
|
||||||
|
-- local after = #toMove
|
||||||
|
-- MyModGlobal.debugPrint(string.format("Enqueued %d items from the inventory slot %d", after - before,
|
||||||
|
-- slotid))
|
||||||
|
-- end
|
||||||
|
-- end
|
||||||
|
-- end
|
||||||
|
|
||||||
local openContainers = utils.getOpenContainers()
|
local openContainers = utils.getOpenContainers()
|
||||||
for _, container in ipairs(openContainers) do
|
for _, container in ipairs(openContainers) do
|
||||||
@@ -308,16 +322,8 @@ local function stackToCursor()
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
for _, slot in ipairs(slots) do
|
local item, slot
|
||||||
local item
|
local function predicate(ititem)
|
||||||
if not slot.slot.items or #slot.slot.items == 0 then
|
|
||||||
MyModGlobal.debugPrint("No items in slot")
|
|
||||||
goto continue
|
|
||||||
end
|
|
||||||
|
|
||||||
item = slot.slot.items[1]
|
|
||||||
MyModGlobal.debugPrint(string.format("Stacking all player items to %s", item.Prefab.Identifier.Value))
|
|
||||||
utils.enqueueAllPlayerItems({}, function(ititem)
|
|
||||||
if ititem.Prefab.Identifier.Value == item.Prefab.Identifier.Value then
|
if ititem.Prefab.Identifier.Value == item.Prefab.Identifier.Value then
|
||||||
if item == ititem then return false end
|
if item == ititem then return false end
|
||||||
-- We are moving items in the predicate because we expect to only
|
-- We are moving items in the predicate because we expect to only
|
||||||
@@ -328,7 +334,8 @@ local function stackToCursor()
|
|||||||
-- UPDATE: OK well that was a stupid idea, it returns an error for other shit as well
|
-- UPDATE: OK well that was a stupid idea, it returns an error for other shit as well
|
||||||
-- What other shit? Wish I knew
|
-- What other shit? Wish I knew
|
||||||
-- So we'll use HowManyCanBePut instead...
|
-- So we'll use HowManyCanBePut instead...
|
||||||
local moved = slot.inventory.TryPutItem(ititem, slot.slotIndex - 1, false, true, Character.Controlled, true)
|
local moved = slot.inventory.TryPutItem(ititem, slot.slotIndex - 1, false, true, Character.Controlled,
|
||||||
|
true)
|
||||||
if not moved then
|
if not moved then
|
||||||
MyModGlobal.debugPrint(string.format("Failed to move item %s to slot %d", ititem.Name, slot
|
MyModGlobal.debugPrint(string.format("Failed to move item %s to slot %d", ititem.Name, slot
|
||||||
.slotIndex - 1))
|
.slotIndex - 1))
|
||||||
@@ -341,8 +348,22 @@ local function stackToCursor()
|
|||||||
return false, true
|
return false, true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end
|
||||||
|
|
||||||
|
-- We gotta do a little juggling...
|
||||||
|
for _, sslot in ipairs(slots) do
|
||||||
|
slot = sslot
|
||||||
|
local items
|
||||||
|
if not slot.slot.items or #slot.slot.items == 0 then
|
||||||
|
MyModGlobal.debugPrint("No items in slot")
|
||||||
|
goto continue
|
||||||
|
end
|
||||||
|
|
||||||
|
item = slot.slot.items[1]
|
||||||
|
MyModGlobal.debugPrint(string.format("Stacking all player items to %s", item.Prefab.Identifier.Value))
|
||||||
|
items = {}
|
||||||
|
utils.enqueueAllPlayerItems(items, predicate)
|
||||||
|
utils.enqueueOpenContainers(items, predicate)
|
||||||
::continue::
|
::continue::
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -374,7 +395,8 @@ local function stackAllToCursor()
|
|||||||
-- UPDATE: OK well that was a stupid idea, it returns an error for other shit as well
|
-- UPDATE: OK well that was a stupid idea, it returns an error for other shit as well
|
||||||
-- What other shit? Wish I knew
|
-- What other shit? Wish I knew
|
||||||
-- So we'll use HowManyCanBePut instead...
|
-- So we'll use HowManyCanBePut instead...
|
||||||
local moved = slot.inventory.TryPutItem(ititem, slot.slotIndex - 1, false, true, Character.Controlled, true)
|
local moved = slot.inventory.TryPutItem(ititem, slot.slotIndex - 1, false, true, Character.Controlled,
|
||||||
|
true)
|
||||||
if not moved then
|
if not moved then
|
||||||
MyModGlobal.debugPrint(string.format("Failed to move item %s to slot %d", ititem.Name, slot
|
MyModGlobal.debugPrint(string.format("Failed to move item %s to slot %d", ititem.Name, slot
|
||||||
.slotIndex - 1))
|
.slotIndex - 1))
|
||||||
|
|||||||
Reference in New Issue
Block a user