Back to Home

ESO Lua File v101044

ingame/globals/commoninventoryfunctions.lua

[◄ back to folders ]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
function ZO_GetNextBagSlotIndex(bagId, slotIndex)
    if bagId == BAG_GUILDBANK then
        return GetNextGuildBankSlotId(slotIndex)
    elseif bagId == BAG_VIRTUAL then
        return GetNextVirtualBagSlotId(slotIndex)
    else
        if slotIndex == nil then
            return 0
        end
        local bagSlots
        if bagId == BAG_BUYBACK then
            bagSlots = GetNumBuybackItems()
        else
            bagSlots = GetBagSize(bagId)
        end
        if bagSlots then
            if slotIndex < (bagSlots - 1) then
                return slotIndex + 1
            else
                return nil
            end
        end
    end
end
do
    -- reminder, iterator functions take `state, index` and return `index, ...`
    local function GetNextSlotForGuildBank(_, slotIndex)
        return GetNextGuildBankSlotId(slotIndex)
    end
    local function GetNextSlotForVirtualBag(_, slotIndex)
        return GetNextVirtualBagSlotId(slotIndex)
    end
    local function GetNextSlotForSizedBag(lastSlotIndex, slotIndex)
        if slotIndex < lastSlotIndex then
            return slotIndex + 1
        else
            return nil
        end
    end
    -- reminder: this iterator factory returns `iterator, state, initialIndex`
    function ZO_IterateBagSlots(bagId)
        if bagId == BAG_GUILDBANK then
            return GetNextSlotForGuildBank, nil, nil
        elseif bagId == BAG_VIRTUAL then
            return GetNextSlotForVirtualBag, nil, nil
        else
            local lastSlotIndex
            if bagId == BAG_BUYBACK then
                lastSlotIndex = GetNumBuybackItems() - 1
            else
                lastSlotIndex = GetBagSize(bagId) - 1
            end
            return GetNextSlotForSizedBag, lastSlotIndex, -1 -- start at -1, so the first iteration is 0
        end
    end
end