Back to Home

ESO Lua File v101042

ingame/collections/itemsetcollectionsdatamanager.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
ZO_ItemSetCollectionsDataManager = ZO_CallbackObject:Subclass()
function ZO_ItemSetCollectionsDataManager:New(...)
    ITEM_SET_COLLECTIONS_DATA_MANAGER = ZO_CallbackObject.New(self)
    ITEM_SET_COLLECTIONS_DATA_MANAGER:Initialize(...)
    return ITEM_SET_COLLECTIONS_DATA_MANAGER
end
function ZO_ItemSetCollectionsDataManager:Initialize()
    self.itemSetCollections = {}
    self.itemSetPieces = {}
    self.itemSetCollectionCategories = {}
    self.topLevelCategories = {}
    self.reconstructionCurrencyOptionTypes = {}
    for currencyOptionIndex = 1, GetNumItemReconstructionCurrencyOptions() do
        table.insert(self.reconstructionCurrencyOptionTypes, GetItemReconstructionCurrencyOptionType(currencyOptionIndex))
    end
    self.queuedSlotsJustUnlocked = {}
    self:RebuildData()
end
function ZO_ItemSetCollectionsDataManager:RegisterForEvents()
    EVENT_MANAGER:RegisterForEvent("ZO_ItemSetCollectionsDataManager", EVENT_ITEM_SET_COLLECTIONS_UPDATED, function(_, ...) self:OnCollectionsUpdated(...) end)
    EVENT_MANAGER:RegisterForEvent("ZO_ItemSetCollectionsDataManager", EVENT_ITEM_SET_COLLECTION_UPDATED, function(_, ...) self:OnCollectionUpdated(...) end)
    EVENT_MANAGER:RegisterForEvent("ZO_ItemSetCollectionsDataManager", EVENT_ITEM_SET_COLLECTIONS_SEARCH_RESULTS_READY, function() self:UpdateSearchResults() end)
    EVENT_MANAGER:RegisterForEvent("ZO_ItemSetCollectionsDataManager", EVENT_ITEM_SET_COLLECTION_SLOT_NEW_STATUS_CLEARED, function(_, ...) self:OnCollectionSlotNewStatusCleared(...) end)
    EVENT_MANAGER:RegisterForEvent("ZO_ItemSetCollectionsDataManager", EVENT_LEVEL_UPDATE, function(_, ...) self:OnLevelUpdate(...) end)
    EVENT_MANAGER:AddFilterForEvent("ZO_ItemSetCollectionsDataManager", EVENT_LEVEL_UPDATE, REGISTER_FILTER_UNIT_TAG, "player")
    EVENT_MANAGER:RegisterForEvent("ZO_ItemSetCollectionsDataManager", EVENT_CHAMPION_POINT_UPDATE, function(_, ...) self:OnChampionPointUpdate(...) end)
    EVENT_MANAGER:AddFilterForEvent("ZO_ItemSetCollectionsDataManager", EVENT_CHAMPION_POINT_UPDATE, REGISTER_FILTER_UNIT_TAG, "player")
    local function OnAddOnLoaded(_, name)
        if name == "ZO_Ingame" then
            local DEFAULTS = { showLocked = true, equipmentFiltersTypes = {} }
            self.savedVars = ZO_SavedVars:New("ZO_Ingame_SavedVariables", 1, "ZO_ItemSetCollectionsDataManager", DEFAULTS)
            EVENT_MANAGER:UnregisterForEvent("ZO_ItemSetCollectionsDataManager", EVENT_ADD_ON_LOADED)
            self:FireCallbacks("ShowLockedChanged", self.savedVars.showLocked)
            self:FireCallbacks("EquipmentFilterTypesChanged", self:GetEquipmentFilterTypes())
        end
    end
    EVENT_MANAGER:RegisterForEvent("ZO_ItemSetCollectionsDataManager", EVENT_ADD_ON_LOADED, OnAddOnLoaded)
    
end
function ZO_ItemSetCollectionsDataManager:MarkDataDirty()
    self.isDataDirty = true
end
function ZO_ItemSetCollectionsDataManager:CleanData()
    if self.isDataDirty then
        self:RebuildData()
    end
end
do
    local function GetNextItemSetCollectionIdIter(_, lastItemSetId)
        return GetNextItemSetCollectionId(lastItemSetId)
    end
    function ZO_ItemSetCollectionsDataManager:RebuildData()
        self.isDataDirty = false
        ZO_ClearTable(self.itemSetCollections)
        ZO_ClearTable(self.itemSetPieces)
        ZO_ClearTable(self.itemSetCollectionCategories)
        ZO_ClearNumericallyIndexedTable(self.topLevelCategories)
        -- Load all ItemSetCollections and their associated objects.
        for itemSetId in GetNextItemSetCollectionIdIter do
            self:InternalGetOrCreateItemSetCollectionData(itemSetId)
        end
        self:SortTopLevelCategories()
        self:OnCollectionsUpdated()
    end
end
function ZO_ItemSetCollectionsDataManager:OnUpdateSlotsJustUnlocked()
    if #self.queuedSlotsJustUnlocked > 0 then
        self:FireCallbacks("SlotsJustUnlocked", self.queuedSlotsJustUnlocked)
        self:OnCollectionsUpdated()
        ZO_ClearNumericallyIndexedTable(self.queuedSlotsJustUnlocked)
    end
    EVENT_MANAGER:UnregisterForUpdate("ZO_ItemSetCollectionsDataManager_SlotsJustUnlocked")
end
function ZO_ItemSetCollectionsDataManager:GetReconstructionCurrencyOptionType(currencyOptionIndex)
    return self.reconstructionCurrencyOptionTypes[currencyOptionIndex]
end
function ZO_ItemSetCollectionsDataManager:GetReconstructionCurrencyOptionTypes()
    return self.reconstructionCurrencyOptionTypes
end
function ZO_ItemSetCollectionsDataManager:InvalidateCacheData()
    for _, itemSetCollectionCategoryData in ipairs(self.topLevelCategories) do
        itemSetCollectionCategoryData:InvalidateCacheData()
    end
end
function ZO_ItemSetCollectionsDataManager:OnCollectionsUpdated(itemSetIds)
    self:FireCallbacks("CollectionsUpdated", itemSetIds)
end
function ZO_ItemSetCollectionsDataManager:OnCollectionUpdated(itemSetId, slotsJustUnlockedMask)
    local slotsJustUnlocked = { GetItemSetCollectionSlotsInMask(slotsJustUnlockedMask) }
    if #slotsJustUnlocked > 0 then
        for _, slotJustUnlocked in ipairs(slotsJustUnlocked) do
            table.insert(self.queuedSlotsJustUnlocked,
            {
                itemSetId = itemSetId,
                slot = slotJustUnlocked,
            })
        end
        EVENT_MANAGER:RegisterForUpdate("ZO_ItemSetCollectionsDataManager_SlotsJustUnlocked", 100, function() self:OnUpdateSlotsJustUnlocked() end)
    end
    self:OnCollectionsUpdated({ itemSetId })
end
function ZO_ItemSetCollectionsDataManager:OnLevelUpdate()
end
do
    local MAX_ITEM_CHAMPION_POINTS = 160
    local ITEM_CHAMPION_RANK_INTERVAL = 10
    function ZO_ItemSetCollectionsDataManager:OnChampionPointUpdate(_, oldChampionPoints, currentChampionPoints)
        if oldChampionPoints < MAX_ITEM_CHAMPION_POINTS or currentChampionPoints < MAX_ITEM_CHAMPION_POINTS then
            if zo_floor(oldChampionPoints / ITEM_CHAMPION_RANK_INTERVAL) ~= zo_floor(currentChampionPoints / ITEM_CHAMPION_RANK_INTERVAL) then
                self:MarkAllPieceLinksDirty()
            end
        end
    end
end
function ZO_ItemSetCollectionsDataManager:MarkAllPieceLinksDirty()
    for _, itemSetCollectionPieceData in self:ItemSetCollectionPieceIterator() do
        itemSetCollectionPieceData:MarkItemLinkDirty()
    end
    self:FireCallbacks("PieceLinksDirty")
end
function ZO_ItemSetCollectionsDataManager:SortTopLevelCategories()
    table.sort(self.topLevelCategories, ZO_ItemSetCollectionCategoryData.CompareTo)
    for _, itemSetCollectionCategoryData in ipairs(self.topLevelCategories) do
        itemSetCollectionCategoryData:SortChildren()
    end
end
-- ZO_ItemSetCollectionPiece
function ZO_ItemSetCollectionsDataManager:ItemSetCollectionPieceIterator(filterFunctions)
    self:CleanData()
    return ZO_FilteredNonContiguousTableIterator(self.itemSetPieces, filterFunctions)
end
function ZO_ItemSetCollectionsDataManager:GetItemSetCollectionPieceData(pieceId)
    self:CleanData()
    return self.itemSetPieces[pieceId]
end
function ZO_ItemSetCollectionsDataManager:GetOrCreateItemSetCollectionPieceData(pieceId, itemSetCollectionSlot)
    if pieceId and pieceId ~= 0 then
        local itemSetCollectionPieceData = self:GetItemSetCollectionPieceData(pieceId)
        if not itemSetCollectionPieceData then
            itemSetCollectionPieceData = ZO_ItemSetCollectionPieceData:New(pieceId, itemSetCollectionSlot)
            self.itemSetPieces[pieceId] = itemSetCollectionPieceData
        end
        return itemSetCollectionPieceData
    end
end
-- ZO_ItemSetCollection
function ZO_ItemSetCollectionsDataManager:ItemSetCollectionIterator(filterFunctions)
    self:CleanData()
    return ZO_FilteredNonContiguousTableIterator(self.itemSetCollections, filterFunctions)
end
function ZO_ItemSetCollectionsDataManager:GetItemSetCollectionData(itemSetId)
    self:CleanData()
    return self.itemSetCollections[itemSetId]
end
function ZO_ItemSetCollectionsDataManager:InternalGetOrCreateItemSetCollectionData(itemSetId)
    if itemSetId and itemSetId ~= 0 then
        local itemSetCollectionData = self:GetItemSetCollectionData(itemSetId)
        if not itemSetCollectionData then
            itemSetCollectionData = ZO_ItemSetCollectionData:New(itemSetId)
            self.itemSetCollections[itemSetId] = itemSetCollectionData
        end
        return itemSetCollectionData
    end
end
-- ZO_ItemSetCollectionCategory
function ZO_ItemSetCollectionsDataManager:ItemSetCollectionCategoryIterator(filterFunctions)
    self:CleanData()
    return ZO_FilteredNonContiguousTableIterator(self.itemSetCollections, filterFunctions)
end
function ZO_ItemSetCollectionsDataManager:TopLevelItemSetCollectionCategoryIterator(filterFunctions)
    self:CleanData()
    return ZO_FilteredNumericallyIndexedTableIterator(self.topLevelCategories, filterFunctions)
end
function ZO_ItemSetCollectionsDataManager:GetItemSetCollectionCategoryData(categoryId)
    self:CleanData()
    return self.itemSetCollectionCategories[categoryId]
end
function ZO_ItemSetCollectionsDataManager:GetOrCreateItemSetCollectionCategoryData(categoryId)
    if categoryId and categoryId ~= 0 then
        local itemSetCollectionCategoryData = self:GetItemSetCollectionCategoryData(categoryId)
        if not itemSetCollectionCategoryData then
            itemSetCollectionCategoryData = ZO_ItemSetCollectionCategoryData:New(categoryId)
            self.itemSetCollectionCategories[categoryId] = itemSetCollectionCategoryData
            if not itemSetCollectionCategoryData:GetParentCategoryData() then
                table.insert(self.topLevelCategories, itemSetCollectionCategoryData)
            end
        end
        return itemSetCollectionCategoryData
    end
end
function ZO_ItemSetCollectionsDataManager:OnCollectionSlotNewStatusCleared(itemSetId, itemSetCollectionSlot)
    local itemSetCollectionData = self:GetItemSetCollectionData(itemSetId)
    local itemSetCollectionPieceData = itemSetCollectionData:GetPieceDataBySlot(itemSetCollectionSlot)
    self:FireCallbacks("PieceNewStatusCleared", itemSetCollectionPieceData)
end
function ZO_ItemSetCollectionsDataManager:OnCollectionNewStatusCleared(itemSetCollectionData)
    self:FireCallbacks("CollectionNewStatusCleared", itemSetCollectionData)
end
function ZO_ItemSetCollectionsDataManager:OnCollectionCategoryNewStatusCleared(itemSetCollectionCategoryData)
    self:FireCallbacks("CategoryNewStatusCleared", itemSetCollectionCategoryData)
end
function ZO_ItemSetCollectionsDataManager:HasAnyNewPieces()
end
function ZO_ItemSetCollectionsDataManager:GetShowLocked()
    return self.savedVars.showLocked
end
function ZO_ItemSetCollectionsDataManager:SetShowLocked(showLocked)
    if self.savedVars.showLocked ~= showLocked then
        self.savedVars.showLocked = showLocked
        self:FireCallbacks("ShowLockedChanged", showLocked)
    end
end
function ZO_ItemSetCollectionsDataManager:GetEquipmentFilterTypes()
    if not self.savedVars.equipmentFilterTypes then
        self.savedVars.equipmentFilterTypes = {}
    end
    return self.savedVars.equipmentFilterTypes
end
function ZO_ItemSetCollectionsDataManager:SetEquipmentFilterTypes(equipmentFilterTypes)
    if not ZO_AreNumericallyIndexedTablesEqual(self:GetEquipmentFilterTypes(), equipmentFilterTypes) then
        self.savedVars.equipmentFilterTypes = equipmentFilterTypes
        self:FireCallbacks("EquipmentFilterTypesChanged", equipmentFilterTypes)
    end
end
do
    local APPAREL_FILTER_TYPES =
    {
        EQUIPMENT_FILTER_TYPE_LIGHT,
        EQUIPMENT_FILTER_TYPE_MEDIUM,
        EQUIPMENT_FILTER_TYPE_HEAVY,
        EQUIPMENT_FILTER_TYPE_NECK,
        EQUIPMENT_FILTER_TYPE_RING,
        EQUIPMENT_FILTER_TYPE_SHIELD,
    }
    function ZO_ItemSetCollectionsDataManager.GetApparelFilterTypes()
        return APPAREL_FILTER_TYPES
    end
    local WEAPON_FILTER_TYPES =
    {
        EQUIPMENT_FILTER_TYPE_ONE_HANDED,
        EQUIPMENT_FILTER_TYPE_TWO_HANDED,
        EQUIPMENT_FILTER_TYPE_DESTRO_STAFF,
        EQUIPMENT_FILTER_TYPE_RESTO_STAFF,
        EQUIPMENT_FILTER_TYPE_BOW,
    }
    function ZO_ItemSetCollectionsDataManager.GetWeaponFilterTypes()
        return WEAPON_FILTER_TYPES
    end
end
-- Global singleton
-- The global singleton moniker is assigned by the Data Manager's constructor in order to
-- allow data objects to reference the singleton during their construction.
ZO_ItemSetCollectionsDataManager:New()