diff --git a/src/Environment/Environment.lua b/src/Environment/Environment.lua new file mode 100644 index 0000000..74f477b --- /dev/null +++ b/src/Environment/Environment.lua @@ -0,0 +1,81 @@ +local Tinkr, Bastion = ... + +---@class Environment +local Environment = {} +Environment.__index = Environment + +local buildNum = select(4, GetBuildInfo()) +local buildName = "CLASSIC" +if buildNum > 100000 then + buildName = "RETAIL" +elseif buildNum > 40000 then + buildName = "CATA" +elseif buildNum > 30000 then + buildName = "WOTLK" +elseif buildNum > 20000 then + buildName = "TBC" +end + +function Environment:GetWoWBuildNumber() + return buildNum +end + +function Environment:GetWoWBuild() + return buildName +end + +if C_Timer == nil then + Bastion:Debug("Adding C_Timer") + C_Timer = {} + local f = CreateFrame("Frame", "C_Timer") + f.tab = {} + f:HookScript("OnUpdate", function() + for i, v in pairs(f.tab) do + if v[1] <= GetTime() then + local func = v[2] + func() + table.remove(f.tab, i) + end + end + end + ) + function C_Timer.After(time, func) + table.insert(f.tab, {GetTime() + time, func}) + end +end + +function Environment:GetCVar(name) + if C_Var and C_Cvar.GetCvar then return C_Cvar.GetCvar(name) end + if Cvar then return GetCvar(name) end + Bastion:Debug("[GetCvar] failed") + return nil +end + +function Environment:SetCVar(name, value) + if C_Var and C_Cvar.SetCvar then return C_Cvar.SetCvar(name, value) end + if Cvar then return SetCvar(name, value) end + Bastion:Debug("[SetCvar] failed") + return nil +end + +function Environment:GetItemInfo(itemId) + if itemId == nil then return nil end + if C_Item and C_Item.GetItemInfo then return C_Item.GetItemInfo(itemId) end + if GetItemInfo then return GetItemInfo(itemId) end + Bastion:Debug("[GetItemInfo] failed") + return nil +end + +function Environment:GetSpellInfo(spellId) + if spellId == nil then return nil end + if C_Spell and C_Spell.GetSpellInfo then + local tab = C_Spell.GetSpellInfo(spellId) + if tab then return tab.name, tab.rank, tab.icon, tab.castTime, tab.minRange, tab.maxRange, tab.spellId + end + end + if GetSpellInfo then return GetSpellInfo(spellId) end + Bastion:Debug("[GetSpellInfo] failed") + return nil +end + +return Environment diff --git a/src/Item/Item.lua b/src/Item/Item.lua index 5a68e98..b8b85d0 100644 --- a/src/Item/Item.lua +++ b/src/Item/Item.lua @@ -60,6 +60,8 @@ function Item:New(id) return self end +local GetItemInfo = Bastion.Environment:GetItemInfo(...) + -- Get the Items id ---@return number function Item:GetID() diff --git a/src/_bastion.lua b/src/_bastion.lua index 9386aa1..130225a 100644 --- a/src/_bastion.lua +++ b/src/_bastion.lua @@ -7,6 +7,8 @@ local Bastion = { } Bastion.__index = Bastion + + function Bastion:Require(file) -- If require starts with an @ then we require from the scripts/bastion/scripts folder if file:sub(1, 1) == '@' then @@ -56,6 +58,8 @@ end Bastion.Globals = {} +---@type Cvar +Bastion.Cvar = Bastion.require("Cvar") ---@type ClassMagic Bastion.ClassMagic = Bastion.require("ClassMagic") ---@type List