Release Candidate 1
This commit is contained in:
+129
-28
@@ -19,6 +19,10 @@ local CONST_COOLDOWN_TYPE_DEFENSIVE_RAID = 4
|
||||
local CONST_COOLDOWN_TYPE_UTILITY = 5
|
||||
local CONST_COOLDOWN_TYPE_INTERRUPT = 6
|
||||
|
||||
--hold spellIds and which custom caches the spell is in
|
||||
--map[spellId] = map[filterName] = true
|
||||
local spellsWithCustomFiltersCache = {}
|
||||
|
||||
--simple non recursive table copy
|
||||
function openRaidLib.TCopy(tableToReceive, tableToCopy)
|
||||
if (not tableToCopy) then
|
||||
@@ -137,8 +141,9 @@ function openRaidLib.GetUnitID(playerName)
|
||||
return openRaidLib.UnitIDCache[playerName] or playerName
|
||||
end
|
||||
|
||||
|
||||
local filterStringToCooldownType = { --report: "filterStringToCooldownType doesn't include the new filters."
|
||||
--report: "filterStringToCooldownType doesn't include the new filters."
|
||||
--answer: custom filter does not have a cooldown type, it is a mesh of spells
|
||||
local filterStringToCooldownType = {
|
||||
["defensive-raid"] = CONST_COOLDOWN_TYPE_DEFENSIVE_RAID,
|
||||
["defensive-target"] = CONST_COOLDOWN_TYPE_DEFENSIVE_TARGET,
|
||||
["defensive-personal"] = CONST_COOLDOWN_TYPE_DEFENSIVE_PERSONAL,
|
||||
@@ -147,34 +152,116 @@ local filterStringToCooldownType = { --report: "filterStringToCooldownType doesn
|
||||
["interrupt"] = CONST_COOLDOWN_TYPE_INTERRUPT,
|
||||
}
|
||||
|
||||
function openRaidLib.CooldownManager.DoesSpellPassFilters(spellId, filters)
|
||||
local allCooldownsData = LIB_OPEN_RAID_COOLDOWNS_INFO
|
||||
local cooldownData = allCooldownsData[spellId]
|
||||
if (cooldownData) then
|
||||
for filter in filters:gmatch("([^,%s]+)") do
|
||||
local cooldownType = filterStringToCooldownType[filter]
|
||||
if (cooldownData.type == cooldownType) then
|
||||
return true
|
||||
elseif (cooldownData[filter]) then --custom filter
|
||||
return true
|
||||
end
|
||||
end
|
||||
else
|
||||
return false
|
||||
local filterStringToCooldownTypeReverse = {
|
||||
[CONST_COOLDOWN_TYPE_DEFENSIVE_RAID] = "defensive-raid",
|
||||
[CONST_COOLDOWN_TYPE_DEFENSIVE_TARGET] = "defensive-target",
|
||||
[CONST_COOLDOWN_TYPE_DEFENSIVE_PERSONAL] = "defensive-personal",
|
||||
[CONST_COOLDOWN_TYPE_OFFENSIVE] = "ofensive",
|
||||
[CONST_COOLDOWN_TYPE_UTILITY] = "utility",
|
||||
[CONST_COOLDOWN_TYPE_INTERRUPT] = "interrupt",
|
||||
}
|
||||
|
||||
local removeSpellFromCustomFilterCache = function(spellId, filterName)
|
||||
local spellFilterCache = spellsWithCustomFiltersCache[spellId]
|
||||
if (spellFilterCache) then
|
||||
spellFilterCache[filterName] = nil
|
||||
end
|
||||
end
|
||||
|
||||
local addSpellToCustomFilterCache = function(spellId, filterName)
|
||||
local spellFilterCache = spellsWithCustomFiltersCache[spellId]
|
||||
if (not spellFilterCache) then
|
||||
spellFilterCache = {}
|
||||
spellsWithCustomFiltersCache[spellId] = spellFilterCache
|
||||
end
|
||||
spellFilterCache[filterName] = true
|
||||
end
|
||||
|
||||
local getSpellCustomFiltersFromCache = function(spellId)
|
||||
local spellFilterCache = spellsWithCustomFiltersCache[spellId]
|
||||
local result = {}
|
||||
if (spellFilterCache) then
|
||||
for filterName in pairs(spellFilterCache) do
|
||||
result[filterName] = true
|
||||
end
|
||||
end
|
||||
return result
|
||||
end
|
||||
|
||||
--LIB_OPEN_RAID_COOLDOWNS_INFO store all registered cooldowns in the file ThingsToMantain_<game version>
|
||||
function openRaidLib.CooldownManager.GetAllRegisteredCooldowns()
|
||||
return LIB_OPEN_RAID_COOLDOWNS_INFO
|
||||
end
|
||||
|
||||
function openRaidLib.CooldownManager.GetCooldownInfo(spellId)
|
||||
return openRaidLib.CooldownManager.GetAllRegisteredCooldowns()[spellId]
|
||||
end
|
||||
|
||||
--return a map of filter names which the spell is in, map: {[filterName] = true}
|
||||
--API Call documented in the docs.txt as openRaidLib.GetSpellFilters() the declaration is on the main file of the lib
|
||||
function openRaidLib.CooldownManager.GetSpellFilters(spellId, defaultFilterOnly, customFiltersOnly)
|
||||
local result = {}
|
||||
|
||||
if (not customFiltersOnly) then
|
||||
local thisCooldownInfo = openRaidLib.CooldownManager.GetCooldownInfo(spellId)
|
||||
local cooldownTypeFilter = filterStringToCooldownTypeReverse[thisCooldownInfo.type]
|
||||
if (cooldownTypeFilter) then
|
||||
result[cooldownTypeFilter] = true
|
||||
end
|
||||
end
|
||||
|
||||
if (defaultFilterOnly) then
|
||||
return result
|
||||
end
|
||||
|
||||
local customFilters = getSpellCustomFiltersFromCache(spellId)
|
||||
for filterName in pairs(customFilters) do
|
||||
result[filterName] = true
|
||||
end
|
||||
|
||||
return result
|
||||
end
|
||||
|
||||
function openRaidLib.CooldownManager.DoesSpellPassFilters(spellId, filters)
|
||||
--table with information about a single cooldown
|
||||
local thisCooldownInfo = openRaidLib.CooldownManager.GetCooldownInfo(spellId)
|
||||
--check if this spell is registered as a cooldown
|
||||
if (thisCooldownInfo) then
|
||||
for filter in filters:gmatch("([^,%s]+)") do
|
||||
--filterStringToCooldownType is a map where the key is the filter name and value is the cooldown type
|
||||
local cooldownType = filterStringToCooldownType[filter]
|
||||
--cooldown type is a number from 1 to 8 telling its type
|
||||
if (cooldownType == thisCooldownInfo.type) then
|
||||
return true
|
||||
|
||||
--check for custom filter, the custom filter name is set as a key in the cooldownInfo: cooldownInfo[filterName] = true
|
||||
elseif (thisCooldownInfo[filter]) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
local getCooldownsForFilter = function(unitName, allCooldowns, unitDataFilteredCache, filter)
|
||||
local allCooldownsData = LIB_OPEN_RAID_COOLDOWNS_INFO
|
||||
local allCooldownsData = openRaidLib.CooldownManager.GetAllRegisteredCooldowns()
|
||||
local filterTable = unitDataFilteredCache[filter]
|
||||
--if the unit already sent its full list of cooldowns, the cache can be built
|
||||
--when NeedRebuildFilters is true, HasFullCooldownList is always true
|
||||
|
||||
--bug: filterTable is nil and HasFullCooldownList is also nil, happening after leaving a grou´p internal callback
|
||||
if ((not filterTable and openRaidLib.CooldownManager.HasFullCooldownList[unitName]) or openRaidLib.CooldownManager.NeedRebuildFilters[unitName]) then
|
||||
--bug: filterTable is nil and HasFullCooldownList is also nil, happening after leaving a group internal callback
|
||||
--November 06, 2022 note: is this bug still happening?
|
||||
|
||||
local doesNotHaveFilterYet = not filterTable and openRaidLib.CooldownManager.HasFullCooldownList[unitName]
|
||||
local isDirty = openRaidLib.CooldownManager.NeedRebuildFilters[unitName]
|
||||
|
||||
if (doesNotHaveFilterYet or isDirty) then
|
||||
--reset the filterTable
|
||||
filterTable = {}
|
||||
unitDataFilteredCache[filter] = filterTable
|
||||
|
||||
--
|
||||
for spellId, cooldownInfo in pairs(allCooldowns) do
|
||||
local cooldownData = allCooldownsData[spellId]
|
||||
if (cooldownData) then
|
||||
@@ -190,27 +277,41 @@ local getCooldownsForFilter = function(unitName, allCooldowns, unitDataFilteredC
|
||||
return filterTable
|
||||
end
|
||||
|
||||
--API Call
|
||||
--@filterName: a string representing a name of the filter
|
||||
--@spells: an array of spellIds
|
||||
--important: a spell can be part of any amount of custom filters,
|
||||
--declaring a spell on a new filter does NOT remove it from other filters where it was previously added
|
||||
function openRaidLib.AddCooldownFilter(filterName, spells)
|
||||
--integrity check
|
||||
if (type(filterName) ~= "string") then
|
||||
openRaidLib.DiagnosticError("Usage: openRaidLib.AddFilter(string: filterName, table: spells)", debugstack())
|
||||
return false
|
||||
end
|
||||
|
||||
if (type(spells) ~= "table") then
|
||||
elseif (type(spells) ~= "table") then
|
||||
openRaidLib.DiagnosticError("Usage: openRaidLib.AddFilter(string: filterName, table: spells)", debugstack())
|
||||
return false
|
||||
end
|
||||
|
||||
--clear previous filter spell table of the same name
|
||||
for spellId, cooldownData in pairs(LIB_OPEN_RAID_COOLDOWNS_INFO) do
|
||||
local allCooldownsData = openRaidLib.CooldownManager.GetAllRegisteredCooldowns()
|
||||
|
||||
--iterate among the all cooldowns table and erase the filterName from all spells
|
||||
for spellId, cooldownData in pairs(allCooldownsData) do
|
||||
cooldownData[filterName] = nil
|
||||
removeSpellFromCustomFilterCache(spellId, filterName)
|
||||
end
|
||||
|
||||
local allCooldownsData = LIB_OPEN_RAID_COOLDOWNS_INFO
|
||||
--iterate among spells passed within the spells table and set the new filter on them
|
||||
--problem: the filter is set directly into the global cooldown table
|
||||
--this could in rare cases make an addon to override settings of another addon
|
||||
for spellIndex, spellId in ipairs(spells) do
|
||||
local cooldownData = allCooldownsData[spellId]
|
||||
cooldownData[filterName] = true
|
||||
if (cooldownData) then
|
||||
cooldownData[filterName] = true
|
||||
addSpellToCustomFilterCache(spellId, filterName)
|
||||
else
|
||||
openRaidLib.DiagnosticError("A spellId on your spell list for openRaidLib.AddFilter isn't registered as cooldown:", spellId, debugstack())
|
||||
end
|
||||
end
|
||||
|
||||
--tag all cache filters as dirt
|
||||
@@ -222,8 +323,9 @@ function openRaidLib.AddCooldownFilter(filterName, spells)
|
||||
return true
|
||||
end
|
||||
|
||||
--@allCooldowns: all cooldowns sent by an unit, {[spellId] = cooldownInfo}
|
||||
--@filters: string with filters, "defensive-raid, "defensive-personal"
|
||||
--API Call
|
||||
--@allCooldowns: all cooldowns sent by a unit, map{[spellId] = cooldownInfo}
|
||||
--@filters: string with filter names: array{"defensive-raid, "defensive-personal"}
|
||||
function openRaidLib.FilterCooldowns(unitName, allCooldowns, filters)
|
||||
local allDataFiltered = openRaidLib.CooldownManager.UnitDataFilterCache --["unitName"] = {defensive-raid = {[spellId = cooldownInfo]}}
|
||||
local unitDataFilteredCache = allDataFiltered[unitName]
|
||||
@@ -238,7 +340,6 @@ function openRaidLib.FilterCooldowns(unitName, allCooldowns, filters)
|
||||
return filterAlreadyInCache
|
||||
end
|
||||
|
||||
local allCooldownsData = LIB_OPEN_RAID_COOLDOWNS_INFO
|
||||
local resultFilters = {}
|
||||
|
||||
--break the string into pieces and filter cooldowns
|
||||
|
||||
Reference in New Issue
Block a user