CLOSES #1396, CLOSES #1398, CLOSES #1400, CLOSES #1401, CLOSES #1406, CLOSES #1407, CLOSES #1411, CLOSES #1413, CLOSES #1415, CLOSES #1416, CLOSES #1417, CLOSES #1419, CLOSES #1421, CLOSES #1422, CLOSES #1423, CLOSES #1424, CLOSES #1425, CLOSES #1427, CLOSES #1428, CLOSES #1429, CLOSES #1431, CLOSES #1432, CLOSES #1433, CLOSES #1435, CLOSES #1437, CLOSES #1440, CLOSES #1441, CLOSES #1442, CLOSES #1443, CLOSES #1447, CLOSES #1449, CLOSES #1456, CLOSES #1464, CLOSES #1465, CLOSES #1468, CLOSES #1469, CLOSES #1470

This commit is contained in:
bryanthaboi
2026-08-17 10:15:06 -04:00
parent 3cca70608f
commit 45519ad550
61 changed files with 2481 additions and 255 deletions
+31 -2
View File
@@ -68,14 +68,20 @@ end
-- Acquisition-ordered id list (wBagItems). Rebuilt sorted once for
-- saves from before the order existed, then maintained incrementally.
function Bag.order(save)
function Bag.order(save, data)
local order = save.bagOrder
if not order then
local items = (data or require("src.core.Data")).items
order = {}
for id in pairs(save.inventory) do
if not isBadge(id) then table.insert(order, id) end
end
table.sort(order)
table.sort(order, function(a, b)
local ia = (items and items[a] and items[a].index) or math.huge
local ib = (items and items[b] and items[b].index) or math.huge
if ia ~= ib then return ia < ib end
return a < b
end)
save.bagOrder = order
end
-- drop stale ids, append unknown ones (defensive against direct
@@ -95,6 +101,29 @@ function Bag.order(save)
return order
end
-- engine/items/switch_items.asm:38 SwitchItemsInBag .below / .above -- the
-- rotate the PACK's SELECT performs, over the rows of ONE pocket.
function Bag.move(save, id, pocket, toIndex, data)
local order = Bag.order(save, data)
local slots, ids = {}, {}
for i = 1, #order do
if pocketOf(order[i], data) == pocket then
slots[#slots + 1] = i
ids[#ids + 1] = order[i]
end
end
local from
for i = 1, #ids do
if ids[i] == id then from = i break end
end
if not from then return false end
local to = math.max(1, math.min(math.floor(tonumber(toIndex) or from), #ids))
if to == from then return false end
table.insert(ids, to, table.remove(ids, from))
for i = 1, #slots do order[slots[i]] = ids[i] end
return true
end
-- Add qty of an item; returns false (and adds nothing) when a new slot
-- is needed and the bag is full, or when the stack would pass 99
-- (AddItemToInventory's per-slot quantity cap).