Skip to content

Commit

Permalink
Prevent errors for unsupported classes
Browse files Browse the repository at this point in the history
  • Loading branch information
coolmodi committed Nov 11, 2022
1 parent 85ffc12 commit 9710cab
Show file tree
Hide file tree
Showing 10 changed files with 104 additions and 30 deletions.
4 changes: 3 additions & 1 deletion SpellCalc.toc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## Interface: 30400
## Title: SpellCalc
## Author: coolmodi
## Version: 0.18
## Version: 0.19
## Notes: Shows some numbers for spells
## SavedVariables: SpellCalc_settings
## OptionalDeps: Dominos, ElvUI, Bartender4
Expand Down Expand Up @@ -41,6 +41,7 @@ data/classes/rogue_spell.lua
data/classes/shaman_spell.lua
data/classes/warlock_spell.lua
data/classes/warrior_spell.lua
data/classes/deathknight_spell.lua
data/classes/druid_itemEffects.lua
data/classes/hunter_itemEffects.lua
data/classes/mage_itemEffects.lua
Expand Down Expand Up @@ -69,6 +70,7 @@ data/classes/rogue.lua
data/classes/shaman.lua
data/classes/warlock.lua
data/classes/warrior.lua
data/classes/deathknight.lua

data/racials.lua

Expand Down
9 changes: 9 additions & 0 deletions data/classes/deathknight.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---@class AddonEnv
local _addon = select(2, ...);
local _, playerClass = UnitClass("player");
if playerClass ~= "DEATHKNIGHT" then
return;
end

---@type TalentDataRawEntry[]
_addon.talentDataRaw = {}
27 changes: 27 additions & 0 deletions data/classes/deathknight_spell.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
-- GENERATED

---@class AddonEnv
local _addon = select(2, ...);
local _, playerClass = UnitClass("player");
if playerClass ~= "DEATHKNIGHT" then
return;
end

---@type SpellInfoTable
_addon.spellInfo = {};

---@type SpellClassSet
_addon.spellClassSet = {
[1] = {
},
[2] = {
},
[3] = {
},
[4] = {
},
};

---@type ClassGlyphs
_addon.classGlyphs = {};

2 changes: 2 additions & 0 deletions data/classes/hunter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ if playerClass ~= "HUNTER" then
return;
end

---@type TalentDataRawEntry[]
_addon.talentDataRaw = {}
18 changes: 15 additions & 3 deletions data/classes/hunter_spell.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,21 @@ if playerClass ~= "HUNTER" then
return;
end

_addon.spellBaseInfo = {};

---@type SpellInfoTable
_addon.spellInfo = {};

---@type SpellClassSet
_addon.spellClassSet = {};
_addon.spellClassSet = {
[1] = {
},
[2] = {
},
[3] = {
},
[4] = {
},
};

---@type ClassGlyphs
_addon.classGlyphs = {};

5 changes: 4 additions & 1 deletion data/classes/rogue.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@ local _addon = select(2, ...);
local _, playerClass = UnitClass("player");
if playerClass ~= "ROGUE" then
return;
end
end

---@type TalentDataRawEntry[]
_addon.talentDataRaw = {}
17 changes: 14 additions & 3 deletions data/classes/rogue_spell.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,20 @@ if playerClass ~= "ROGUE" then
return;
end

_addon.spellBaseInfo = {
};
---@type SpellInfoTable
_addon.spellInfo = {};

_addon.spellInfo = {
---@type SpellClassSet
_addon.spellClassSet = {
[1] = {
},
[2] = {
},
[3] = {
},
[4] = {
},
};

---@type ClassGlyphs
_addon.classGlyphs = {};
5 changes: 4 additions & 1 deletion data/classes/warrior.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@ local _addon = select(2, ...);
local _, playerClass = UnitClass("player");
if playerClass ~= "WARRIOR" then
return;
end
end

---@type TalentDataRawEntry[]
_addon.talentDataRaw = {}
18 changes: 14 additions & 4 deletions data/classes/warrior_spell.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,20 @@ if playerClass ~= "WARRIOR" then
return;
end

_addon.spellBaseInfo = {
};

---@type SpellInfoTable
_addon.spellInfo = {
_addon.spellInfo = {};

---@type SpellClassSet
_addon.spellClassSet = {
[1] = {
},
[2] = {
},
[3] = {
},
[4] = {
},
};

---@type ClassGlyphs
_addon.classGlyphs = {};
29 changes: 12 additions & 17 deletions events.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,6 @@ local _addonName = select(1, ...);
---@class AddonEnv
local _A = select(2, ...);

-- dirty fix to "disable" the addon preventing errors on unsupported classes
-- TODO: Remove when classes are supported
local _, class = UnitClass("player");
if class == "WARRIOR" or class == "ROGUE" or class == "HUNTER" or class == "DEATHKNIGHT" then
_A.util.PrintError("Class not (yet) supported, addon won't work!");
return;
end

local frame = CreateFrame("Frame");

---@type table<string, (fun(...:any):boolean|nil)[]>
Expand All @@ -36,6 +28,13 @@ end);
---@param event string
---@param callback fun(...:any):boolean|nil
local function Register(event, callback)
-- dirty fix to "disable" the addon preventing errors on unsupported classes
-- TODO: Remove when classes are supported
local _, class = UnitClass("player");
if class == "WARRIOR" or class == "ROGUE" or class == "HUNTER" or class == "DEATHKNIGHT" then
return;
end

handlers[event] = handlers[event] or {};
table.insert(handlers[event], callback);
if #handlers[event] == 1 then frame:RegisterEvent(event) end
Expand Down Expand Up @@ -66,16 +65,12 @@ end

Register("ADDON_LOADED", function (addonName)
if addonName ~= _addonName then return end
if not loadedCallbacks then return end
for _, f in ipairs(loadedCallbacks) do
f();
end
loadedCallbacks = nil;

if _A.spellInfo == nil or _A.talentDataRaw == nil then
_A.util.PrintError(_addonName .. ": No data for this class (yet)! Addon won't work!");
if loadedCallbacks then
for _, f in ipairs(loadedCallbacks) do
f();
end
loadedCallbacks = nil;
end

return true;
end);

Expand Down

0 comments on commit 9710cab

Please sign in to comment.