Rework addon loading to properly load on ADDON_LOADED
insteaad of immediately
This commit is contained in:
401
Heimdall.lua
401
Heimdall.lua
@@ -1,198 +1,245 @@
|
||||
local _, data = ...
|
||||
local addonname, data = ...
|
||||
---@cast data HeimdallData
|
||||
---@cast addonname string
|
||||
|
||||
---@class Heimdall_Data
|
||||
---@field who { data: table<string, Player> }
|
||||
if not Heimdall_Data then Heimdall_Data = {} end
|
||||
local function init()
|
||||
---@class Heimdall_Data
|
||||
---@field who { data: table<string, Player> }
|
||||
if not Heimdall_Data then Heimdall_Data = {} end
|
||||
if not Heimdall_Data.config then Heimdall_Data.config = {} end
|
||||
|
||||
-- We don't care about these persisting
|
||||
-- Actually we don't want some of them to persist
|
||||
-- For those we DO we use (global) Heimdall_Data
|
||||
-- We don't care about these persisting
|
||||
-- Actually we don't want some of them to persist
|
||||
-- For those we DO we use (global) Heimdall_Data
|
||||
|
||||
---@class HeimdallData
|
||||
---@field config HeimdallConfig
|
||||
---@field raceMap table<string, string>
|
||||
---@field classColors table<string, string>
|
||||
---@field stinkies table<string, Player>
|
||||
---@field messenger HeimdallMessengerData
|
||||
---@field who HeimdallWhoData
|
||||
---@field dumpTable fun(table: any, depth?: number): nil
|
||||
---@field utf8len fun(input: string): number
|
||||
---@field padString fun(input: string, targetLength: number, left?: boolean): string
|
||||
---@class HeimdallData
|
||||
---@field config HeimdallConfig
|
||||
---@field raceMap table<string, string>
|
||||
---@field classColors table<string, string>
|
||||
---@field stinkies table<string, Player>
|
||||
---@field messenger HeimdallMessengerData
|
||||
---@field who HeimdallWhoData
|
||||
---@field dumpTable fun(table: any, depth?: number): nil
|
||||
---@field utf8len fun(input: string): number
|
||||
---@field padString fun(input: string, targetLength: number, left?: boolean): string
|
||||
---@field GetOrDefault fun(table: table<any, any>, keys: string[], default: any): any
|
||||
---@field Whoer { Init: fun() }
|
||||
---@field Messenger { Init: fun() }
|
||||
---@field Spotter { Init: fun() }
|
||||
---@field DeathReporter { Init: fun() }
|
||||
|
||||
--- Config ---
|
||||
---@class HeimdallConfig
|
||||
---@field spotter HeimdallSpotterConfig
|
||||
---@field who HeimdallWhoConfig
|
||||
---@field messenger HeimdallMessengerConfig
|
||||
---@field whisperNotify table<string, string>
|
||||
--- Config ---
|
||||
---@class HeimdallConfig
|
||||
---@field spotter HeimdallSpotterConfig
|
||||
---@field who HeimdallWhoConfig
|
||||
---@field messenger HeimdallMessengerConfig
|
||||
---@field whisperNotify table<string, string>
|
||||
|
||||
---@class HeimdallSpotterConfig
|
||||
---@field enabled boolean
|
||||
---@field everyone boolean
|
||||
---@field hostile boolean
|
||||
---@field alliance boolean
|
||||
---@field stinky boolean
|
||||
---@field notifyChannel string
|
||||
---@field zoneOverride string?
|
||||
---@field throttleTime number
|
||||
---@class HeimdallSpotterConfig
|
||||
---@field enabled boolean
|
||||
---@field everyone boolean
|
||||
---@field hostile boolean
|
||||
---@field alliance boolean
|
||||
---@field stinky boolean
|
||||
---@field notifyChannel string
|
||||
---@field zoneOverride string?
|
||||
---@field throttleTime number
|
||||
|
||||
---@class HeimdallWhoConfig
|
||||
---@field enabled boolean
|
||||
---@field ignored table<string, boolean>
|
||||
---@field notifyChannel string
|
||||
---@field ttl number
|
||||
---@field doWhisper boolean
|
||||
---@field zoneNotifyFor table<string, boolean>
|
||||
---@class HeimdallWhoConfig
|
||||
---@field enabled boolean
|
||||
---@field ignored table<string, boolean>
|
||||
---@field notifyChannel string
|
||||
---@field ttl number
|
||||
---@field doWhisper boolean
|
||||
---@field zoneNotifyFor table<string, boolean>
|
||||
|
||||
---@class HeimdallMessengerConfig
|
||||
---@field enabled boolean
|
||||
---@class HeimdallMessengerConfig
|
||||
---@field enabled boolean
|
||||
|
||||
--- Data ---
|
||||
---@class HeimdallMessengerData
|
||||
---@field queue table<string, Message>
|
||||
---@field ticker number?
|
||||
--- Data ---
|
||||
---@class HeimdallMessengerData
|
||||
---@field queue table<string, Message>
|
||||
---@field ticker number?
|
||||
|
||||
---@class HeimdallWhoData
|
||||
---@field updateTicker number?
|
||||
---@field whoTicker number?
|
||||
---@field ignored table<string, boolean>
|
||||
---@class HeimdallWhoData
|
||||
---@field updateTicker number?
|
||||
---@field whoTicker number?
|
||||
---@field ignored table<string, boolean>
|
||||
|
||||
data.messenger = {
|
||||
queue = {}
|
||||
}
|
||||
data.who = {
|
||||
ignored = {},
|
||||
}
|
||||
data.GetOrDefault = function(table, keys, default)
|
||||
local value = default
|
||||
if not table then return value end
|
||||
if not keys then return value end
|
||||
|
||||
data.config = {
|
||||
spotter = {
|
||||
enabled = true,
|
||||
everyone = false,
|
||||
hostile = true,
|
||||
alliance = false,
|
||||
stinky = false,
|
||||
notifyChannel = "Foobar",
|
||||
zoneOverride = nil,
|
||||
throttleTime = 1
|
||||
},
|
||||
who = {
|
||||
enabled = true,
|
||||
ignored = {},
|
||||
notifyChannel = "Foobar",
|
||||
ttl = 10,
|
||||
doWhisper = true,
|
||||
zoneNotifyFor = {
|
||||
["Orgrimmar"] = true,
|
||||
["Thunder Bluff"] = true,
|
||||
["Undercity"] = true,
|
||||
["Durotar"] = true,
|
||||
["Echo Isles"] = true,
|
||||
["Valley of Trials"] = true,
|
||||
}
|
||||
},
|
||||
messenger = {
|
||||
enabled = true
|
||||
},
|
||||
whisperNotify = {
|
||||
"Extazyk",
|
||||
"Smokefire",
|
||||
"Smokemantra",
|
||||
"Хихихантер",
|
||||
"Муркот",
|
||||
"Растафаркрай",
|
||||
"Frosstmorn",
|
||||
"Pulsjkee",
|
||||
"Paskoo",
|
||||
"Totleta",
|
||||
"Healleta",
|
||||
"Deathleta",
|
||||
"Shootleta",
|
||||
"Stableta"
|
||||
local traverse = table
|
||||
for i = 1, #keys do
|
||||
local key = keys[i]
|
||||
if traverse[key] then
|
||||
traverse = traverse[key]
|
||||
else
|
||||
break
|
||||
end
|
||||
|
||||
if i == #keys then
|
||||
value = traverse
|
||||
end
|
||||
end
|
||||
return value
|
||||
end
|
||||
|
||||
data.messenger = {
|
||||
queue = {}
|
||||
}
|
||||
data.who = {
|
||||
ignored = {},
|
||||
}
|
||||
}
|
||||
|
||||
data.raceMap = {
|
||||
["Orc"] = "Horde",
|
||||
["Undead"] = "Horde",
|
||||
["Tauren"] = "Horde",
|
||||
["Troll"] = "Horde",
|
||||
["Blood Elf"] = "Horde",
|
||||
["Goblin"] = "Horde",
|
||||
["Human"] = "Alliance",
|
||||
["Dwarf"] = "Alliance",
|
||||
["Night Elf"] = "Alliance",
|
||||
["Gnome"] = "Alliance",
|
||||
["Draenei"] = "Alliance",
|
||||
["Worgen"] = "Alliance",
|
||||
["Vulpera"] = "Horde",
|
||||
["Nightborne"] = "Horde",
|
||||
["Zandalari Troll"] = "Horde",
|
||||
["Kul Tiran"] = "Alliance",
|
||||
["Dark Iron Dwarf"] = "Alliance",
|
||||
["Void Elf"] = "Alliance",
|
||||
["Lightforged Draenei"] = "Alliance",
|
||||
["Mechagnome"] = "Alliance",
|
||||
["Mag'har Orc"] = "Horde"
|
||||
}
|
||||
data.config = {
|
||||
spotter = {
|
||||
enabled = data.GetOrDefault(Heimdall_Data, { "config", "spotter", "enabled" }, true),
|
||||
everyone = data.GetOrDefault(Heimdall_Data, { "config", "spotter", "everyone" }, false),
|
||||
hostile = data.GetOrDefault(Heimdall_Data, { "config", "spotter", "hostile" }, true),
|
||||
alliance = data.GetOrDefault(Heimdall_Data, { "config", "spotter", "alliance" }, false),
|
||||
stinky = data.GetOrDefault(Heimdall_Data, { "config", "spotter", "stinky" }, false),
|
||||
notifyChannel = data.GetOrDefault(Heimdall_Data, { "config", "spotter", "notifyChannel" }, "Foobar"),
|
||||
zoneOverride = data.GetOrDefault(Heimdall_Data, { "config", "spotter", "zoneOverride" }, nil),
|
||||
throttleTime = data.GetOrDefault(Heimdall_Data, { "config", "spotter", "throttleTime" }, 1)
|
||||
},
|
||||
who = {
|
||||
enabled = data.GetOrDefault(Heimdall_Data, { "config", "who", "enabled" }, true),
|
||||
ignored = data.GetOrDefault(Heimdall_Data, { "config", "who", "ignored" }, {}),
|
||||
notifyChannel = data.GetOrDefault(Heimdall_Data, { "config", "who", "notifyChannel" }, "Foobar"),
|
||||
ttl = data.GetOrDefault(Heimdall_Data, { "config", "who", "ttl" }, 10),
|
||||
doWhisper = data.GetOrDefault(Heimdall_Data, { "config", "who", "doWhisper" }, true),
|
||||
zoneNotifyFor = data.GetOrDefault(Heimdall_Data, { "config", "who", "zoneNotifyFor" }, {
|
||||
["Orgrimmar"] = true,
|
||||
["Thunder Bluff"] = true,
|
||||
["Undercity"] = true,
|
||||
["Durotar"] = true,
|
||||
["Echo Isles"] = true,
|
||||
["Valley of Trials"] = true,
|
||||
}),
|
||||
},
|
||||
messenger = {
|
||||
enabled = data.GetOrDefault(Heimdall_Data, { "config", "messenger", "enabled" }, true),
|
||||
},
|
||||
whisperNotify = data.GetOrDefault(Heimdall_Data, { "config", "whisperNotify" }, {
|
||||
-- "Extazyk",
|
||||
-- "Smokefire",
|
||||
-- "Smokemantra",
|
||||
-- "Хихихантер",
|
||||
-- "Муркот",
|
||||
-- "Растафаркрай",
|
||||
-- "Frosstmorn",
|
||||
-- "Pulsjkee",
|
||||
-- "Paskoo",
|
||||
"Totleta",
|
||||
"Healleta",
|
||||
"Deathleta",
|
||||
"Shootleta",
|
||||
"Stableta"
|
||||
}),
|
||||
}
|
||||
--/run Heimdall_Data = {config = {who = {enabled = false}}}
|
||||
--/dump Heimdall_Data
|
||||
print("138 " .. tostring(Heimdall_Data.config.who.enabled))
|
||||
print("139 " .. tostring(data.GetOrDefault(Heimdall_Data, { "config", "who", "enabled" }, true)))
|
||||
print("140 " .. tostring(data.config.who.enabled))
|
||||
|
||||
---@type table<string, string>
|
||||
data.classColors = {
|
||||
["Warrior"] = "C69B6D",
|
||||
["Paladin"] = "F48CBA",
|
||||
["Hunter"] = "AAD372",
|
||||
["Rogue"] = "FFF468",
|
||||
["Priest"] = "FFFFFF",
|
||||
["Death Knight"] = "C41E3A",
|
||||
["Shaman"] = "0070DD",
|
||||
["Mage"] = "3FC7EB",
|
||||
["Warlock"] = "8788EE",
|
||||
["Monk"] = "00FF98",
|
||||
["Druid"] = "FF7C0A",
|
||||
["Demon Hunter"] = "A330C9"
|
||||
}
|
||||
data.raceMap = {
|
||||
["Orc"] = "Horde",
|
||||
["Undead"] = "Horde",
|
||||
["Tauren"] = "Horde",
|
||||
["Troll"] = "Horde",
|
||||
["Blood Elf"] = "Horde",
|
||||
["Goblin"] = "Horde",
|
||||
["Human"] = "Alliance",
|
||||
["Dwarf"] = "Alliance",
|
||||
["Night Elf"] = "Alliance",
|
||||
["Gnome"] = "Alliance",
|
||||
["Draenei"] = "Alliance",
|
||||
["Worgen"] = "Alliance",
|
||||
["Vulpera"] = "Horde",
|
||||
["Nightborne"] = "Horde",
|
||||
["Zandalari Troll"] = "Horde",
|
||||
["Kul Tiran"] = "Alliance",
|
||||
["Dark Iron Dwarf"] = "Alliance",
|
||||
["Void Elf"] = "Alliance",
|
||||
["Lightforged Draenei"] = "Alliance",
|
||||
["Mechagnome"] = "Alliance",
|
||||
["Mag'har Orc"] = "Horde"
|
||||
}
|
||||
|
||||
data.stinkies = {}
|
||||
data.classColors = {
|
||||
["Warrior"] = "C69B6D",
|
||||
["Paladin"] = "F48CBA",
|
||||
["Hunter"] = "AAD372",
|
||||
["Rogue"] = "FFF468",
|
||||
["Priest"] = "FFFFFF",
|
||||
["Death Knight"] = "C41E3A",
|
||||
["Shaman"] = "0070DD",
|
||||
["Mage"] = "3FC7EB",
|
||||
["Warlock"] = "8788EE",
|
||||
["Monk"] = "00FF98",
|
||||
["Druid"] = "FF7C0A",
|
||||
["Demon Hunter"] = "A330C9"
|
||||
}
|
||||
|
||||
---@param input string
|
||||
---@return number
|
||||
data.utf8len = function(input)
|
||||
if not input then
|
||||
return 0
|
||||
end
|
||||
local len = 0
|
||||
local i = 1
|
||||
local n = #input
|
||||
while i <= n do
|
||||
local c = input:byte(i)
|
||||
if c >= 0 and c <= 127 then
|
||||
i = i + 1
|
||||
elseif c >= 194 and c <= 223 then
|
||||
i = i + 2
|
||||
elseif c >= 224 and c <= 239 then
|
||||
i = i + 3
|
||||
elseif c >= 240 and c <= 244 then
|
||||
i = i + 4
|
||||
else
|
||||
i = i + 1
|
||||
data.stinkies = {}
|
||||
|
||||
---@param input string
|
||||
---@return number
|
||||
data.utf8len = function(input)
|
||||
if not input then
|
||||
return 0
|
||||
end
|
||||
len = len + 1
|
||||
end
|
||||
return len
|
||||
end
|
||||
---@param input string
|
||||
---@param targetLength number
|
||||
---@param left boolean
|
||||
---@return string
|
||||
data.padString = function(input, targetLength, left)
|
||||
left = left or false
|
||||
local len = data.utf8len(input)
|
||||
if len < targetLength then
|
||||
if left then
|
||||
input = input .. string.rep(" ", targetLength - len)
|
||||
else
|
||||
input = string.rep(" ", targetLength - len) .. input
|
||||
local len = 0
|
||||
local i = 1
|
||||
local n = #input
|
||||
while i <= n do
|
||||
local c = input:byte(i)
|
||||
if c >= 0 and c <= 127 then
|
||||
i = i + 1
|
||||
elseif c >= 194 and c <= 223 then
|
||||
i = i + 2
|
||||
elseif c >= 224 and c <= 239 then
|
||||
i = i + 3
|
||||
elseif c >= 240 and c <= 244 then
|
||||
i = i + 4
|
||||
else
|
||||
i = i + 1
|
||||
end
|
||||
len = len + 1
|
||||
end
|
||||
return len
|
||||
end
|
||||
return input
|
||||
---@param input string
|
||||
---@param targetLength number
|
||||
---@param left boolean
|
||||
---@return string
|
||||
data.padString = function(input, targetLength, left)
|
||||
left = left or false
|
||||
local len = data.utf8len(input)
|
||||
if len < targetLength then
|
||||
if left then
|
||||
input = input .. string.rep(" ", targetLength - len)
|
||||
else
|
||||
input = string.rep(" ", targetLength - len) .. input
|
||||
end
|
||||
end
|
||||
return input
|
||||
end
|
||||
|
||||
data.Whoer.Init()
|
||||
data.Messenger.Init()
|
||||
data.Spotter.Init()
|
||||
data.DeathReporter.Init()
|
||||
end
|
||||
|
||||
local loadedFrame = CreateFrame("Frame")
|
||||
loadedFrame:RegisterEvent("ADDON_LOADED")
|
||||
loadedFrame:SetScript("OnEvent", function(self, event, addonName)
|
||||
if addonName == addonname then
|
||||
init()
|
||||
end
|
||||
end)
|
||||
|
||||
Reference in New Issue
Block a user