You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

420 lines
17 KiB

4 years ago
--[[ Spell Cache store all spells shown on frames and make able to change spells name, icons, etc... ]]
do
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
3 years ago
--On The Fly SpellCache
4 years ago
local _detalhes = _G._detalhes
3 years ago
local Loc = LibStub("AceLocale-3.0"):GetLocale ( "Details" )
4 years ago
local _
local rawget = rawget
local rawset = rawset
local setmetatable = setmetatable
4 years ago
local _GetSpellInfo = GetSpellInfo
local _unpack = unpack
3 years ago
--is this a timewalking exp?
4 years ago
local is_classic_exp = DetailsFramework.IsClassicWow()
3 years ago
--default container
4 years ago
_detalhes.spellcache = {}
3 years ago
local unknowSpell = {Loc ["STRING_UNKNOWSPELL"], _, "Interface\\Icons\\Ability_Druid_Eclipse"} --localize-me
4 years ago
local AllSpellNames
if (is_classic_exp) then
AllSpellNames = {}
local GetSpellInfo = GetSpellInfo
for i = 1, 60000 do
local name, _, icon = GetSpellInfo(i)
if name and icon and icon ~= 136235 and not AllSpellNames[name] then
AllSpellNames[name] = icon
end
end
end
local GetSpellInfoClassic = function(spell)
local spellName, _, spellIcon
if (spell == 0) then
spellName = ATTACK or "It's Blizzard Fault!"
spellIcon = [[Interface\ICONS\INV_Sword_04]]
elseif (spell == "!Melee" or spell == 1) then
spellName = ATTACK or "It's Blizzard Fault!"
spellIcon = [[Interface\ICONS\INV_Sword_04]]
elseif (spell == "!Autoshot" or spell == 2) then
spellName = Loc ["STRING_AUTOSHOT"]
spellIcon = [[Interface\ICONS\INV_Weapon_Bow_07]]
else
3 years ago
spellName, _, spellIcon = GetSpellInfo(spell)
4 years ago
end
if (not spellName) then
return spell, _, AllSpellNames [spell] or defaultSpellIcon
end
return spellName, _, AllSpellNames [spell] or spellIcon
end
3 years ago
--reset spell cache
4 years ago
function _detalhes:ClearSpellCache()
_detalhes.spellcache = setmetatable({},
3 years ago
{__index = function(tabela, valor)
local esta_magia = rawget (tabela, valor)
4 years ago
if (esta_magia) then
return esta_magia
end
3 years ago
--should save only icon and name, other values are not used
if (valor) then --check if spell is valid before
4 years ago
local cache
if (is_classic_exp) then
cache = {GetSpellInfoClassic(valor)}
else
3 years ago
cache = {_GetSpellInfo(valor)}
4 years ago
end
tabela [valor] = cache
return cache
else
return unknowSpell
end
end})
3 years ago
--default overwrites
--rawset (_detalhes.spellcache, 1, {Loc ["STRING_MELEE"], 1, "Interface\\AddOns\\Details\\images\\melee.tga"})
--rawset (_detalhes.spellcache, 2, {Loc ["STRING_AUTOSHOT"], 1, "Interface\\AddOns\\Details\\images\\autoshot.tga"})
4 years ago
3 years ago
--built-in overwrites
for spellId, spellTable in pairs(_detalhes.SpellOverwrite) do
local name, _, icon = _GetSpellInfo(spellId)
rawset (_detalhes.spellcache, spellId, {spellTable.name or name, 1, spellTable.icon or icon})
4 years ago
end
3 years ago
--user overwrites
4 years ago
-- [1] spellid [2] spellname [3] spellicon
3 years ago
for index, spellTable in ipairs(_detalhes.savedCustomSpells) do
rawset (_detalhes.spellcache, spellTable [1], {spellTable [2], 1, spellTable [3]})
4 years ago
end
end
3 years ago
local lightOfTheMartyr_Name, _, lightOfTheMartyr_Icon = _GetSpellInfo(196917)
4 years ago
lightOfTheMartyr_Name = lightOfTheMartyr_Name or "Deprecated Spell - Light of the Martyr"
lightOfTheMartyr_Icon = lightOfTheMartyr_Icon or ""
local defaultSpellCustomization = {}
if (DetailsFramework.IsClassicWow()) then
defaultSpellCustomization = {
[1] = {name = Loc ["STRING_MELEE"], icon = [[Interface\ICONS\INV_Sword_04]]},
[2] = {name = Loc ["STRING_AUTOSHOT"], icon = [[Interface\ICONS\INV_Weapon_Bow_07]]},
[3] = {name = Loc ["STRING_ENVIRONMENTAL_FALLING"], icon = [[Interface\ICONS\Spell_Magic_FeatherFall]]},
[4] = {name = Loc ["STRING_ENVIRONMENTAL_DROWNING"], icon = [[Interface\ICONS\Ability_Suffocate]]},
[5] = {name = Loc ["STRING_ENVIRONMENTAL_FATIGUE"], icon = [[Interface\ICONS\Spell_Arcane_MindMastery]]},
[6] = {name = Loc ["STRING_ENVIRONMENTAL_FIRE"], icon = [[Interface\ICONS\INV_SummerFest_FireSpirit]]},
[7] = {name = Loc ["STRING_ENVIRONMENTAL_LAVA"], icon = [[Interface\ICONS\Ability_Rhyolith_Volcano]]},
[8] = {name = Loc ["STRING_ENVIRONMENTAL_SLIME"], icon = [[Interface\ICONS\Ability_Creature_Poison_02]]},
}
elseif (DetailsFramework.IsTBCWow()) then
defaultSpellCustomization = {
[1] = {name = _G["MELEE"], icon = [[Interface\ICONS\INV_Sword_04]]},
[2] = {name = Loc ["STRING_AUTOSHOT"], icon = [[Interface\ICONS\INV_Weapon_Bow_07]]},
[3] = {name = Loc ["STRING_ENVIRONMENTAL_FALLING"], icon = [[Interface\ICONS\Spell_Magic_FeatherFall]]},
[4] = {name = Loc ["STRING_ENVIRONMENTAL_DROWNING"], icon = [[Interface\ICONS\Ability_Suffocate]]},
[5] = {name = Loc ["STRING_ENVIRONMENTAL_FATIGUE"], icon = [[Interface\ICONS\Spell_Arcane_MindMastery]]},
[6] = {name = Loc ["STRING_ENVIRONMENTAL_FIRE"], icon = [[Interface\ICONS\INV_SummerFest_FireSpirit]]},
[7] = {name = Loc ["STRING_ENVIRONMENTAL_LAVA"], icon = [[Interface\ICONS\Ability_Rhyolith_Volcano]]},
[8] = {name = Loc ["STRING_ENVIRONMENTAL_SLIME"], icon = [[Interface\ICONS\Ability_Creature_Poison_02]]},
}
3 years ago
elseif (DetailsFramework.IsWotLKWow()) then
defaultSpellCustomization = {
[1] = {name = _G["MELEE"], icon = [[Interface\ICONS\INV_Sword_04]]},
[2] = {name = Loc ["STRING_AUTOSHOT"], icon = [[Interface\ICONS\INV_Weapon_Bow_07]]},
[3] = {name = Loc ["STRING_ENVIRONMENTAL_FALLING"], icon = [[Interface\ICONS\Spell_Magic_FeatherFall]]},
[4] = {name = Loc ["STRING_ENVIRONMENTAL_DROWNING"], icon = [[Interface\ICONS\Ability_Suffocate]]},
[5] = {name = Loc ["STRING_ENVIRONMENTAL_FATIGUE"], icon = [[Interface\ICONS\Spell_Arcane_MindMastery]]},
[6] = {name = Loc ["STRING_ENVIRONMENTAL_FIRE"], icon = [[Interface\ICONS\INV_SummerFest_FireSpirit]]},
[7] = {name = Loc ["STRING_ENVIRONMENTAL_LAVA"], icon = [[Interface\ICONS\Ability_Rhyolith_Volcano]]},
[8] = {name = Loc ["STRING_ENVIRONMENTAL_SLIME"], icon = [[Interface\ICONS\Ability_Creature_Poison_02]]},
}
elseif (DetailsFramework.IsShadowlandsWow()) then
4 years ago
defaultSpellCustomization = {
[1] = {name = Loc ["STRING_MELEE"], icon = [[Interface\ICONS\INV_Sword_04]]},
[2] = {name = Loc ["STRING_AUTOSHOT"], icon = [[Interface\ICONS\INV_Weapon_Bow_07]]},
[3] = {name = Loc ["STRING_ENVIRONMENTAL_FALLING"], icon = [[Interface\ICONS\Spell_Magic_FeatherFall]]},
[4] = {name = Loc ["STRING_ENVIRONMENTAL_DROWNING"], icon = [[Interface\ICONS\Ability_Suffocate]]},
[5] = {name = Loc ["STRING_ENVIRONMENTAL_FATIGUE"], icon = [[Interface\ICONS\Spell_Arcane_MindMastery]]},
[6] = {name = Loc ["STRING_ENVIRONMENTAL_FIRE"], icon = [[Interface\ICONS\INV_SummerFest_FireSpirit]]},
[7] = {name = Loc ["STRING_ENVIRONMENTAL_LAVA"], icon = [[Interface\ICONS\Ability_Rhyolith_Volcano]]},
[8] = {name = Loc ["STRING_ENVIRONMENTAL_SLIME"], icon = [[Interface\ICONS\Ability_Creature_Poison_02]]},
[98021] = {name = Loc ["STRING_SPIRIT_LINK_TOTEM"]},
3 years ago
[108271] = {name = GetSpellInfo(108271), icon = "Interface\\Addons\\Details\\images\\icon_astral_shift"},
4 years ago
[196917] = {name = lightOfTheMartyr_Name .. " (" .. Loc ["STRING_DAMAGE"] .. ")", icon = lightOfTheMartyr_Icon},
[77535] = {name = GetSpellInfo(77535), icon = "Interface\\Addons\\Details\\images\\icon_blood_shield"},
4 years ago
3 years ago
--bfa trinkets (deprecated)
[278155] = {name = GetSpellInfo(278155) .. " (Trinket)"}, --[Twitching Tentacle of Xalzaix]
[279664] = {name = GetSpellInfo(279664) .. " (Trinket)"}, --[Vanquished Tendril of G'huun]
[278227] = {name = GetSpellInfo(278227) .. " (Trinket)"}, --[T'zane's Barkspines]
[278383] = {name = GetSpellInfo(278383) .. " (Trinket)"}, --[Azurethos' Singed Plumage]
[278862] = {name = GetSpellInfo(278862) .. " (Trinket)"}, --[Drust-Runed Icicle]
[278359] = {name = GetSpellInfo(278359) .. " (Trinket)"}, --[Doom's Hatred]
[278812] = {name = GetSpellInfo(278812) .. " (Trinket)"}, --[Lion's Grace]
[270827] = {name = GetSpellInfo(270827) .. " (Trinket)"}, --[Vessel of Skittering Shadows]
[271071] = {name = GetSpellInfo(271071) .. " (Trinket)"}, --[Conch of Dark Whispers]
[270925] = {name = GetSpellInfo(270925) .. " (Trinket)"}, --[Hadal's Nautilus]
[271115] = {name = GetSpellInfo(271115) .. " (Trinket)"}, --[Ignition Mage's Fuse]
[271462] = {name = GetSpellInfo(271462) .. " (Trinket)"}, --[Rotcrusted Voodoo Doll]
[271465] = {name = GetSpellInfo(271465) .. " (Trinket)"}, --[Rotcrusted Voodoo Doll]
[268998] = {name = GetSpellInfo(268998) .. " (Trinket)"}, --[Balefire Branch]
[271671] = {name = GetSpellInfo(271671) .. " (Trinket)"}, --[Lady Waycrest's Music Box]
[277179] = {name = GetSpellInfo(277179) .. " (Trinket)"}, --[Dread Gladiator's Medallion]
[277187] = {name = GetSpellInfo(277187) .. " (Trinket)"}, --[Dread Gladiator's Emblem]
[277181] = {name = GetSpellInfo(277181) .. " (Trinket)"}, --[Dread Gladiator's Insignia]
[277185] = {name = GetSpellInfo(277185) .. " (Trinket)"}, --[Dread Gladiator's Badge]
[278057] = {name = GetSpellInfo(278057) .. " (Trinket)"}, --[Vigilant's Bloodshaper]
4 years ago
}
else
--retail
defaultSpellCustomization = {
[1] = {name = Loc ["STRING_MELEE"], icon = [[Interface\ICONS\INV_Sword_04]]},
[2] = {name = Loc ["STRING_AUTOSHOT"], icon = [[Interface\ICONS\INV_Weapon_Bow_07]]},
[3] = {name = Loc ["STRING_ENVIRONMENTAL_FALLING"], icon = [[Interface\ICONS\Spell_Magic_FeatherFall]]},
[4] = {name = Loc ["STRING_ENVIRONMENTAL_DROWNING"], icon = [[Interface\ICONS\Ability_Suffocate]]},
[5] = {name = Loc ["STRING_ENVIRONMENTAL_FATIGUE"], icon = [[Interface\ICONS\Spell_Arcane_MindMastery]]},
[6] = {name = Loc ["STRING_ENVIRONMENTAL_FIRE"], icon = [[Interface\ICONS\INV_SummerFest_FireSpirit]]},
[7] = {name = Loc ["STRING_ENVIRONMENTAL_LAVA"], icon = [[Interface\ICONS\Ability_Rhyolith_Volcano]]},
[8] = {name = Loc ["STRING_ENVIRONMENTAL_SLIME"], icon = [[Interface\ICONS\Ability_Creature_Poison_02]]},
[98021] = {name = Loc ["STRING_SPIRIT_LINK_TOTEM"]},
[108271] = {name = GetSpellInfo(108271), icon = "Interface\\Addons\\Details\\images\\icon_astral_shift"},
[196917] = {name = lightOfTheMartyr_Name .. " (" .. Loc ["STRING_DAMAGE"] .. ")", icon = lightOfTheMartyr_Icon},
[77535] = {name = GetSpellInfo(77535), icon = "Interface\\Addons\\Details\\images\\icon_blood_shield"},
}
4 years ago
end
if (LIB_OPEN_RAID_SPELL_CUSTOM_NAMES) then
for spellId, customTable in pairs(LIB_OPEN_RAID_SPELL_CUSTOM_NAMES) do
local name = customTable.name
if (name) then
defaultSpellCustomization[spellId] = name
end
end
end
function _detalhes:UserCustomSpellUpdate (index, name, icon)
local t = _detalhes.savedCustomSpells[index]
if (t) then
t [2], t [3] = name or t [2], icon or t [3]
return rawset (_detalhes.spellcache, t [1], {t [2], 1, t [3]})
4 years ago
else
return false
end
end
function _detalhes:UserCustomSpellReset (index)
local t = _detalhes.savedCustomSpells[index]
if (t) then
local spellid = t [1]
3 years ago
local name, _, icon = _GetSpellInfo(spellid)
4 years ago
if (defaultSpellCustomization [spellid]) then
name = defaultSpellCustomization [spellid].name
icon = defaultSpellCustomization [spellid].icon or icon or [[Interface\InventoryItems\WoWUnknownItem01]]
end
if (not name) then
name = "Unknown"
end
if (not icon) then
icon = [[Interface\InventoryItems\WoWUnknownItem01]]
end
rawset (_detalhes.spellcache, spellid, {name, 1, icon})
4 years ago
t[2] = name
t[3] = icon
end
end
function _detalhes:FillUserCustomSpells()
3 years ago
for spellid, t in pairs(defaultSpellCustomization) do
4 years ago
local already_have
3 years ago
for index, spelltable in ipairs(_detalhes.savedCustomSpells) do
4 years ago
if (spelltable [1] == spellid) then
already_have = spelltable
end
end
if (not already_have) then
3 years ago
local name, _, icon = GetSpellInfo(spellid)
4 years ago
_detalhes:UserCustomSpellAdd (spellid, t.name or name or "Unknown", t.icon or icon or [[Interface\InventoryItems\WoWUnknownItem01]])
end
end
for i = #_detalhes.savedCustomSpells, 1, -1 do
local spelltable = _detalhes.savedCustomSpells [i]
local spellid = spelltable [1]
if (spellid > 10) then
3 years ago
local exists = _GetSpellInfo(spellid)
4 years ago
if (not exists) then
3 years ago
tremove(_detalhes.savedCustomSpells, i)
4 years ago
end
end
end
end
function _detalhes:UserCustomSpellAdd (spellid, name, icon)
local is_overwrite = false
3 years ago
for index, t in ipairs(_detalhes.savedCustomSpells) do
4 years ago
if (t [1] == spellid) then
t[2] = name
t[3] = icon
is_overwrite = true
break
end
end
if (not is_overwrite) then
3 years ago
tinsert(_detalhes.savedCustomSpells, {spellid, name, icon})
4 years ago
end
return rawset (_detalhes.spellcache, spellid, {name, 1, icon})
4 years ago
end
function _detalhes:UserCustomSpellRemove (index)
local t = _detalhes.savedCustomSpells [index]
if (t) then
local spellid = t [1]
3 years ago
local name, _, icon = _GetSpellInfo(spellid)
4 years ago
if (name) then
rawset (_detalhes.spellcache, spellid, {name, 1, icon})
4 years ago
end
3 years ago
return tremove(_detalhes.savedCustomSpells, index)
4 years ago
end
return false
end
3 years ago
--overwrite for API GetSpellInfo function
4 years ago
3 years ago
_detalhes.getspellinfo = function(spellid) return _unpack(_detalhes.spellcache[spellid]) end
4 years ago
_detalhes.GetSpellInfo = _detalhes.getspellinfo
3 years ago
--overwrite SpellInfo if the spell is a DoT, so Details.GetSpellInfo will return the name modified
4 years ago
function _detalhes:SpellIsDot (spellid)
3 years ago
local spellName, rank, spellIcon = _GetSpellInfo(spellid)
4 years ago
if (spellName) then
rawset (_detalhes.spellcache, spellid, {spellName .. Loc ["STRING_DOT"], rank, spellIcon})
4 years ago
else
rawset (_detalhes.spellcache, spellid, {"Unknown DoT Spell? " .. Loc ["STRING_DOT"], rank, [[Interface\InventoryItems\WoWUnknownItem01]]})
4 years ago
end
end
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
3 years ago
--Cache All Spells
4 years ago
function _detalhes:BuildSpellListSlow()
local load_frame = _G.DetailsLoadSpellCache
if (load_frame and (load_frame.completed or load_frame.inprogress)) then
return false
end
local step = 1
local max = 160000
if (not load_frame) then
3 years ago
load_frame = CreateFrame("frame", "DetailsLoadSpellCache", UIParent)
load_frame:SetFrameStrata("DIALOG")
4 years ago
3 years ago
local progress_label = load_frame:CreateFontString("DetailsLoadSpellCacheProgress", "overlay", "GameFontHighlightSmall")
progress_label:SetText("Loading Spells: 0%")
4 years ago
function _detalhes:BuildSpellListSlowTick()
3 years ago
progress_label:SetText("Loading Spells: " .. load_frame:GetProgress() .. "%")
4 years ago
end
load_frame.tick = _detalhes:ScheduleRepeatingTimer ("BuildSpellListSlowTick", 1)
function load_frame:GetProgress()
3 years ago
return math.floor(step / max * 100)
4 years ago
end
end
local SpellCache = {a={}, b={}, c={}, d={}, e={}, f={}, g={}, h={}, i={}, j={}, k={}, l={}, m={}, n={}, o={}, p={}, q={}, r={}, s={}, t={}, u={}, v={}, w={}, x={}, y={}, z={}}
local _string_lower = string.lower
local _string_sub = string.sub
local blizzGetSpellInfo = GetSpellInfo
load_frame.inprogress = true
_detalhes.spellcachefull = SpellCache
3 years ago
load_frame:SetScript("OnUpdate", function()
4 years ago
for spellid = step, step+500 do
local name, _, icon = blizzGetSpellInfo (spellid)
if (name) then
3 years ago
local LetterIndex = _string_lower (_string_sub (name, 1, 1)) --get the first letter
4 years ago
local CachedIndex = SpellCache [LetterIndex]
if (CachedIndex) then
CachedIndex [spellid] = {name, icon}
end
end
end
step = step + 500
if (step > max) then
step = max
_G.DetailsLoadSpellCache.completed = true
_G.DetailsLoadSpellCache.inprogress = false
3 years ago
_detalhes:CancelTimer(_G.DetailsLoadSpellCache.tick)
4 years ago
DetailsLoadSpellCacheProgress:Hide()
3 years ago
load_frame:SetScript("OnUpdate", nil)
4 years ago
end
end)
return true
end
function _detalhes:BuildSpellList()
local SpellCache = {a={}, b={}, c={}, d={}, e={}, f={}, g={}, h={}, i={}, j={}, k={}, l={}, m={}, n={}, o={}, p={}, q={}, r={}, s={}, t={}, u={}, v={}, w={}, x={}, y={}, z={}}
local _string_lower = string.lower
local _string_sub = string.sub
local blizzGetSpellInfo = GetSpellInfo
for spellid = 1, 160000 do
local name, rank, icon = blizzGetSpellInfo (spellid)
if (name) then
local index = _string_lower (_string_sub (name, 1, 1))
local CachedIndex = SpellCache [index]
if (CachedIndex) then
CachedIndex [spellid] = {name, icon, rank}
end
end
end
_detalhes.spellcachefull = SpellCache
return true
end
function _detalhes:ClearSpellList()
_detalhes.spellcachefull = nil
collectgarbage()
end
end