-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUtils_Module.lua
More file actions
74 lines (64 loc) · 2.48 KB
/
Utils_Module.lua
File metadata and controls
74 lines (64 loc) · 2.48 KB
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
-- upvalue the globals
local _G = getfenv(0)
local LibStub = _G.LibStub
local C_LFGList = _G.C_LFGList
local ipairs = _G.ipairs
local name = ...
local currentPatch = select(4, GetBuildInfo())
--- @class LazyCurve
local LazyCurve = LibStub('AceAddon-3.0'):GetAddon(name)
if not LazyCurve then return end
local ModuleUtil = {}
LazyCurve.utils.module = ModuleUtil
ModuleUtil.moduleInfoTables = {}
--- @param module LazyCurveModule
--- @return LazyCurveActivityTable_enriched
function ModuleUtil:GetLatestModuleRaid(module)
return self:GetModuleInfoTable(module)[1]
end
--- @param module LazyCurveModule
--- @return boolean
function ModuleUtil:ModuleHasLatestRaid(module)
return LazyCurve.CURRENT_EXPANSION == module.EXPANSION and module.type == LazyCurve.MODULE_TYPE_RAID
end
--- @param module LazyCurveModule
--- @param groupId number
--- @return LazyCurveActivityTable_enriched|false
function ModuleUtil:GetModuleInfoTableByActivityGroup(module, groupId)
for _, activityTable in ipairs(self:GetModuleInfoTable(module)) do
if activityTable.groupId == groupId then
return activityTable
end
end
return false
end
--- @param module LazyCurveModule
--- @return LazyCurveActivityTable_enriched[]
function ModuleUtil:GetModuleInfoTable(module)
local moduleName = module.moduleName
if not self.moduleInfoTables[moduleName] then
local firstValidTable = nil
--- @class LazyCurveActivityTable_enriched[]: LazyCurveActivityTable[]
local infoTable = module:GetInfoTable()
for i, activityTable in ipairs(infoTable) do
if activityTable.minPatch and currentPatch < activityTable.minPatch then
-- Skip activities that are not available in the current patch
infoTable[i] = nil
else
firstValidTable = firstValidTable or activityTable
local localName, _ = C_LFGList.GetActivityGroupInfo(activityTable.groupId)
activityTable.longName = localName or activityTable.shortName
activityTable.module = module
activityTable.isLatest = self:ModuleHasLatestRaid(module) and firstValidTable == activityTable
end
end
-- Remove nil entries from the table
for i = #infoTable, 1, -1 do
if not infoTable[i] then
table.remove(infoTable, i)
end
end
self.moduleInfoTables[moduleName] = infoTable
end
return self.moduleInfoTables[moduleName]
end