Gladdy-TBC/Libs/LibClassAuras-1.0/LibClassAuras-1.0.lua

117 lines
3.2 KiB
Lua
Raw Normal View History

2021-05-17 16:49:54 +02:00
local type, ipairs, pairs, tinsert = type, ipairs, pairs, tinsert
local GetSpellInfo = GetSpellInfo
2021-05-18 18:31:03 +02:00
local AURA_TYPE_DEBUFF, AURA_TYPE_BUFF = AURA_TYPE_DEBUFF, AURA_TYPE_BUFF
2021-05-17 16:49:54 +02:00
local LibClassAuras = LibStub:NewLibrary("LibClassAuras-1.0", 1)
LibClassAuras.debuffs = {}
LibClassAuras.debuffToId = {}
LibClassAuras.buffs = {}
LibClassAuras.buffToId = {}
LibClassAuras.altNames = {}
2021-05-17 16:49:54 +02:00
2022-08-01 18:28:16 +02:00
LibClassAuras.gameExpansion = ({
[WOW_PROJECT_MAINLINE] = "retail",
[WOW_PROJECT_CLASSIC] = "classic",
[WOW_PROJECT_BURNING_CRUSADE_CLASSIC or 5] = "tbc"
})[WOW_PROJECT_ID]
2021-05-17 16:49:54 +02:00
local function Spell(id, opts, class, spellTable, idTable)
if not opts or not class then
return
end
2022-08-01 18:28:16 +02:00
local spellName
2021-05-17 16:49:54 +02:00
if type(id) == "table" then
2022-08-01 18:28:16 +02:00
local realIds = {}
for i = 1, #id do
if GetSpellInfo(id[i]) then
tinsert(realIds, id[i])
spellName = GetSpellInfo(id[i])
end
end
id = realIds
2021-05-17 16:49:54 +02:00
else
2022-08-01 18:28:16 +02:00
spellName = GetSpellInfo(id)
2021-05-17 16:49:54 +02:00
end
2022-08-01 18:28:16 +02:00
2021-05-17 16:49:54 +02:00
if not spellName then
return
end
if opts.altName then
for _,v in ipairs(id) do
LibClassAuras.altNames[v] = opts.altName
end
if idTable[opts.altName] then
tinsert(idTable[opts.altName], {id = id , class = class})
else
idTable[opts.altName] = {[1] = {id = id , class = class}}
end
2021-05-17 16:49:54 +02:00
else
if idTable[spellName] then
tinsert(idTable[spellName], {id = id , class = class})
else
idTable[spellName] = {[1] = {id = id , class = class}}
end
2021-05-17 16:49:54 +02:00
end
if type(id) == "table" then
for _, spellID in ipairs(id) do
spellTable[spellID] = opts
spellTable[spellID].class = class
end
else
spellTable[id] = opts
spellTable[id].class = class
end
end
local function Debuff(id, opts, class)
Spell(id, opts, class, LibClassAuras.debuffs, LibClassAuras.debuffToId)
end
LibClassAuras.Debuff = Debuff
local function Buff(id, opts, class)
Spell(id, opts, class, LibClassAuras.buffs, LibClassAuras.buffToId)
end
LibClassAuras.Buff = Buff
local function getClassDebuffs(class)
local classSpells = {}
for name, spells in pairs(LibClassAuras.debuffToId) do
for _, spellInfo in ipairs(spells) do
if spellInfo.class == class then
tinsert(classSpells, {name = name, id = spellInfo.id})
end
2021-05-17 16:49:54 +02:00
end
end
return classSpells
end
LibClassAuras.GetClassDebuffs = getClassDebuffs
local function getClassBuffs(class)
local classSpells = {}
for name, spells in pairs(LibClassAuras.buffToId) do
for _, spellInfo in ipairs(spells) do
if spellInfo.class == class then
tinsert(classSpells, {name = name, id = spellInfo.id})
end
2021-05-17 16:49:54 +02:00
end
end
return classSpells
end
2021-05-18 18:31:03 +02:00
LibClassAuras.GetClassBuffs = getClassBuffs
local function getSpellNameToId(auraType)
if auraType == AURA_TYPE_DEBUFF then
return LibClassAuras.debuffToId
else
return LibClassAuras.buffToId
end
end
LibClassAuras.GetSpellNameToId = getSpellNameToId
local function getAltName(spellID)
return LibClassAuras.altNames[spellID]
end
LibClassAuras.GetAltName = getAltName