Refactor multiple Heimdall modules to use class-based structure for improved organization and clarity
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
local _, shared = ...
|
||||
---@cast shared HeimdallShared
|
||||
local ModuleName = "Inviter"
|
||||
|
||||
---@class HeimdallInviterConfig
|
||||
---@field enabled boolean
|
||||
@@ -14,8 +15,6 @@ local _, shared = ...
|
||||
---@field afkThreshold number
|
||||
---@field listeningChannel table<string, boolean>
|
||||
|
||||
local ModuleName = "Inviter"
|
||||
|
||||
---@class Inviter
|
||||
shared.Inviter = {
|
||||
Init = function()
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
local _, shared = ...
|
||||
---@cast shared HeimdallShared
|
||||
local ModuleName = "Macroer"
|
||||
|
||||
---@class HeimdallMacroerConfig
|
||||
---@field enabled boolean
|
||||
---@field debug boolean
|
||||
---@field priority string[]
|
||||
|
||||
local ModuleName = "Macroer"
|
||||
|
||||
---@class Macroer
|
||||
shared.Macroer = {
|
||||
Init = function()
|
||||
|
||||
@@ -2,14 +2,14 @@ local _, shared = ...
|
||||
---@cast shared HeimdallShared
|
||||
local ModuleName = "Messenger"
|
||||
|
||||
---@diagnostic disable-next-line: missing-fields
|
||||
shared.Messenger = {}
|
||||
function shared.Messenger.Init()
|
||||
---@class Message
|
||||
---@field message string
|
||||
---@field channel string
|
||||
---@field data string
|
||||
---@class Message
|
||||
---@field message string
|
||||
---@field channel string
|
||||
---@field data string
|
||||
|
||||
---@class Messenger
|
||||
shared.Messenger = {
|
||||
Init = function()
|
||||
local function FindOrJoinChannel(channelName, password)
|
||||
local channelId = GetChannelName(channelName)
|
||||
if channelId == 0 then
|
||||
@@ -35,7 +35,9 @@ function shared.Messenger.Init()
|
||||
if not shared.messenger.ticker then
|
||||
local function DoMessage()
|
||||
if Heimdall_Data.config.messenger.debug then
|
||||
print(string.format("[%s] Processing message queue - Size: %d", ModuleName, #shared.messenger.queue))
|
||||
print(
|
||||
string.format("[%s] Processing message queue - Size: %d", ModuleName, #shared.messenger.queue)
|
||||
)
|
||||
end
|
||||
|
||||
if not Heimdall_Data.config.messenger.enabled then
|
||||
@@ -106,7 +108,13 @@ function shared.Messenger.Init()
|
||||
local channelId = GetChannelName(message.data)
|
||||
if channelId == 0 then
|
||||
if Heimdall_Data.config.messenger.debug then
|
||||
print(string.format("[%s] Channel not found, attempting to join: %s", ModuleName, message.data))
|
||||
print(
|
||||
string.format(
|
||||
"[%s] Channel not found, attempting to join: %s",
|
||||
ModuleName,
|
||||
message.data
|
||||
)
|
||||
)
|
||||
end
|
||||
channelId = FindOrJoinChannel(message.data)
|
||||
if Heimdall_Data.config.messenger.debug then
|
||||
@@ -173,4 +181,5 @@ function shared.Messenger.Init()
|
||||
)
|
||||
end
|
||||
print("[Heimdall] Messenger loaded")
|
||||
end
|
||||
end,
|
||||
}
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
local _, shared = ...
|
||||
---@cast shared HeimdallShared
|
||||
local ModuleName = "MinimapTagger"
|
||||
|
||||
local HeimdallRoot = "Interface\\AddOns\\Heimdall\\"
|
||||
local SoundRoot = HeimdallRoot .. "Sounds\\"
|
||||
local TextureRoot = HeimdallRoot .. "Texture\\"
|
||||
--/run local a=GetChannelName("Agent")local b,c=GetPlayerMapPosition("player")b,c=b*100,c*100;local d=string.format("I need help at %s (%s) [%s](%2.2f, %2.2f)",GetZoneText(),GetSubZoneText(),GetCurrentMapAreaID(),b,c)SendChatMessage(d,"CHANNEL",nil,a)
|
||||
|
||||
---@diagnostic disable-next-line: missing-fields
|
||||
shared.MinimapTagger = {}
|
||||
function shared.MinimapTagger.Init()
|
||||
---@class MinimapTagger
|
||||
shared.MinimapTagger = {
|
||||
Init = function()
|
||||
---@param x number
|
||||
---@param y number
|
||||
---@param frame Frame
|
||||
@@ -565,7 +566,5 @@ function shared.MinimapTagger.Init()
|
||||
end)
|
||||
|
||||
print("[Heimdall] MinimapTagger loaded")
|
||||
end
|
||||
|
||||
SlashCmdList["HEIMDALL_MINIMAPTAGGER"] = function(args) shared.MinimapTagger.Init() end
|
||||
SLASH_HEIMDALL_MINIMAPTAGGER1 = "/mf"
|
||||
end,
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ local ModuleName = "Network"
|
||||
---@class HeimdallNetworkData
|
||||
---@field ticker Timer?
|
||||
|
||||
---@class Network
|
||||
shared.Network = {
|
||||
Init = function()
|
||||
if not shared.network then shared.network = {} end
|
||||
|
||||
@@ -2,9 +2,9 @@ local _, shared = ...
|
||||
---@cast shared HeimdallShared
|
||||
local ModuleName = "NetworkMessenger"
|
||||
|
||||
---@diagnostic disable-next-line: missing-fields
|
||||
shared.NetworkMessenger = {}
|
||||
function shared.NetworkMessenger.Init()
|
||||
---@class NetworkMessenger
|
||||
shared.NetworkMessenger = {
|
||||
Init = function()
|
||||
RegisterAddonMessagePrefix(Heimdall_Data.config.addonPrefix)
|
||||
|
||||
if not shared.networkMessenger then shared.networkMessenger = {} end
|
||||
@@ -91,7 +91,8 @@ function shared.NetworkMessenger.Init()
|
||||
-- print(string.format("[%s] Queue check - Network messages pending: %d", ModuleName, queueSize))
|
||||
--end
|
||||
DoMessage()
|
||||
shared.networkMessenger.ticker = C_Timer.NewTimer(Heimdall_Data.config.networkMessenger.interval, Tick, 1)
|
||||
shared.networkMessenger.ticker =
|
||||
C_Timer.NewTimer(Heimdall_Data.config.networkMessenger.interval, Tick, 1)
|
||||
end
|
||||
Tick()
|
||||
end
|
||||
@@ -140,7 +141,13 @@ function shared.NetworkMessenger.Init()
|
||||
local target = strtrim(tostring(parts[4]))
|
||||
if Heimdall_Data.config.networkMessenger.debug then
|
||||
print(
|
||||
string.format("[%s] Received message command: %s %s %s", ModuleName, content, targetchannel, target)
|
||||
string.format(
|
||||
"[%s] Received message command: %s %s %s",
|
||||
ModuleName,
|
||||
content,
|
||||
targetchannel,
|
||||
target
|
||||
)
|
||||
)
|
||||
end
|
||||
---@type Message
|
||||
@@ -180,4 +187,5 @@ function shared.NetworkMessenger.Init()
|
||||
end
|
||||
|
||||
print("[Heimdall] NetworkMessenger module loaded")
|
||||
end
|
||||
end,
|
||||
}
|
||||
|
||||
@@ -8,9 +8,9 @@ local ModuleName = "Noter"
|
||||
---@field date string
|
||||
---@field note string
|
||||
|
||||
---@diagnostic disable-next-line: missing-fields
|
||||
shared.Noter = {}
|
||||
function shared.Noter.Init()
|
||||
---@class Noter
|
||||
shared.Noter = {
|
||||
Init = function()
|
||||
-- ---Hopefully this will not be necessary
|
||||
-- ---@param text string
|
||||
-- ---@param size number
|
||||
@@ -68,7 +68,9 @@ function shared.Noter.Init()
|
||||
|
||||
if not start then
|
||||
if Heimdall_Data.config.noter.debug then
|
||||
print(string.format("[%s] Invalid start range for delete note: %s", ModuleName, tostring(start)))
|
||||
print(
|
||||
string.format("[%s] Invalid start range for delete note: %s", ModuleName, tostring(start))
|
||||
)
|
||||
end
|
||||
return
|
||||
end
|
||||
@@ -292,4 +294,5 @@ function shared.Noter.Init()
|
||||
end)
|
||||
|
||||
print("[Heimdall] Commander module loaded")
|
||||
end
|
||||
end,
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@ local _, shared = ...
|
||||
---@cast shared HeimdallShared
|
||||
local ModuleName = "Spotter"
|
||||
|
||||
---@diagnostic disable-next-line: missing-fields
|
||||
shared.Spotter = {}
|
||||
function shared.Spotter.Init()
|
||||
---@class Spotter
|
||||
shared.Spotter = {
|
||||
Init = function()
|
||||
local function FormatHP(hp)
|
||||
if hp > 1e9 then
|
||||
return string.format("%.1fB", hp / 1e9)
|
||||
@@ -102,7 +102,9 @@ function shared.Spotter.Init()
|
||||
if throttleTable[name] and time - throttleTable[name] < Heimdall_Data.config.spotter.throttleTime then
|
||||
if Heimdall_Data.config.spotter.debug then
|
||||
local remainingTime = Heimdall_Data.config.spotter.throttleTime - (time - throttleTable[name])
|
||||
print(string.format("[%s] Player %s throttled for %.1f more seconds", ModuleName, name, remainingTime))
|
||||
print(
|
||||
string.format("[%s] Player %s throttled for %.1f more seconds", ModuleName, name, remainingTime)
|
||||
)
|
||||
end
|
||||
return string.format("Throttled %s", tostring(name))
|
||||
end
|
||||
@@ -221,4 +223,5 @@ function shared.Spotter.Init()
|
||||
|
||||
if Heimdall_Data.config.spotter.debug then print(string.format("[%s] Module initialized", ModuleName)) end
|
||||
print("[Heimdall] Spotter loaded")
|
||||
end
|
||||
end,
|
||||
}
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
local addonname, shared = ...
|
||||
local _, shared = ...
|
||||
---@cast shared HeimdallShared
|
||||
---@cast addonname string
|
||||
local ModuleName = "StinkyCache"
|
||||
|
||||
---@diagnostic disable-next-line: missing-fields
|
||||
shared.StinkyCache = {}
|
||||
function shared.StinkyCache.Init()
|
||||
---@class StinkyCache
|
||||
shared.StinkyCache = {
|
||||
Init = function()
|
||||
shared.stinkyCache = {
|
||||
stinkies = {},
|
||||
}
|
||||
@@ -64,9 +63,12 @@ function shared.StinkyCache.Init()
|
||||
__index = function(self, key)
|
||||
local value = rawget(self, key)
|
||||
local now = GetTime()
|
||||
if value == nil or now - value.timestamp > Heimdall_Data.config.stinkyCache.ttl then AskCommander(key) end
|
||||
if value == nil or now - value.timestamp > Heimdall_Data.config.stinkyCache.ttl then
|
||||
AskCommander(key)
|
||||
end
|
||||
return rawget(self, key)
|
||||
end,
|
||||
})
|
||||
print("[Heimdall] StinkyCache module loaded")
|
||||
end
|
||||
end,
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@ local _, shared = ...
|
||||
---@cast shared HeimdallShared
|
||||
local ModuleName = "Whoer"
|
||||
|
||||
---@diagnostic disable-next-line: missing-fields
|
||||
shared.Whoer = {}
|
||||
function shared.Whoer.Init()
|
||||
---@class Whoer
|
||||
shared.Whoer = {
|
||||
Init = function()
|
||||
if not Heimdall_Data.who then Heimdall_Data.who = {} end
|
||||
if not Heimdall_Data.who.data then Heimdall_Data.who.data = {} end
|
||||
|
||||
@@ -184,12 +184,19 @@ function shared.Whoer.Init()
|
||||
print(string.format("[%s] ShouldNotifyForZone %s", ModuleName, inputZone))
|
||||
end
|
||||
for zone, _ in pairs(Heimdall_Data.config.who.zoneNotifyFor) do
|
||||
if Heimdall_Data.config.who.debug then print(string.format("[%s] Checking zone %s", ModuleName, zone)) end
|
||||
if Heimdall_Data.config.who.debug then
|
||||
print(string.format("[%s] Checking zone %s", ModuleName, zone))
|
||||
end
|
||||
if zone == "*" then return true end
|
||||
if string.find(inputZone, zone) then
|
||||
if not Heimdall_Data.config.who.debug then
|
||||
print(
|
||||
string.format("[%s] ShouldNotifyForZone %s is true thanks to %s", ModuleName, inputZone, zone)
|
||||
string.format(
|
||||
"[%s] ShouldNotifyForZone %s is true thanks to %s",
|
||||
ModuleName,
|
||||
inputZone,
|
||||
zone
|
||||
)
|
||||
)
|
||||
end
|
||||
return true
|
||||
@@ -269,7 +276,11 @@ function shared.Whoer.Init()
|
||||
--if not Heimdall_Data.config.who.zoneNotifyFor[player.zone] then
|
||||
if Heimdall_Data.config.who.debug then
|
||||
print(
|
||||
string.format("[%s] Skipping notification - Zone '%s' not in notify list", ModuleName, player.zone)
|
||||
string.format(
|
||||
"[%s] Skipping notification - Zone '%s' not in notify list",
|
||||
ModuleName,
|
||||
player.zone
|
||||
)
|
||||
)
|
||||
end
|
||||
return string.format("Not notifying for zone %s", tostring(player.zone))
|
||||
@@ -432,7 +443,9 @@ function shared.Whoer.Init()
|
||||
frame:SetScript("OnEvent", function(self, event, ...)
|
||||
if Heimdall_Data.config.who.debug then
|
||||
print(string.format("[%s] WHO list update received", ModuleName))
|
||||
print(string.format("[%s] Query index: %d/%d", ModuleName, whoQueryIdx, #shared.WhoQueryService.queries))
|
||||
print(
|
||||
string.format("[%s] Query index: %d/%d", ModuleName, whoQueryIdx, #shared.WhoQueryService.queries)
|
||||
)
|
||||
end
|
||||
|
||||
if not Heimdall_Data.config.who.enabled then
|
||||
@@ -460,7 +473,15 @@ function shared.Whoer.Init()
|
||||
local name, guild, level, race, class, zone = GetWhoInfo(i)
|
||||
if Heimdall_Data.config.who.debug then
|
||||
print(
|
||||
string.format("[%s] Processing result %d/%d: %s/%s/%s", ModuleName, i, results, name, class, zone)
|
||||
string.format(
|
||||
"[%s] Processing result %d/%d: %s/%s/%s",
|
||||
ModuleName,
|
||||
i,
|
||||
results,
|
||||
name,
|
||||
class,
|
||||
zone
|
||||
)
|
||||
)
|
||||
end
|
||||
|
||||
@@ -470,13 +491,25 @@ function shared.Whoer.Init()
|
||||
for _, filter in pairs(filters) do
|
||||
if Heimdall_Data.config.who.debug then
|
||||
print(
|
||||
string.format("[%s] Running filter %s on %s/%s/%s", ModuleName, filter.key, name, class, zone)
|
||||
string.format(
|
||||
"[%s] Running filter %s on %s/%s/%s",
|
||||
ModuleName,
|
||||
filter.key,
|
||||
name,
|
||||
class,
|
||||
zone
|
||||
)
|
||||
)
|
||||
end
|
||||
if not filter.Run(name, guild, level, race, class, zone) then
|
||||
if Heimdall_Data.config.who.debug then
|
||||
print(
|
||||
string.format("[%s] Player %s filtered out by WHO filter %s", ModuleName, name, filter.key)
|
||||
string.format(
|
||||
"[%s] Player %s filtered out by WHO filter %s",
|
||||
ModuleName,
|
||||
name,
|
||||
filter.key
|
||||
)
|
||||
)
|
||||
end
|
||||
continue = true
|
||||
@@ -502,7 +535,9 @@ function shared.Whoer.Init()
|
||||
local player = HeimdallStinkies[name]
|
||||
if not player then
|
||||
if Heimdall_Data.config.who.debug then
|
||||
print(string.format("[%s] New player detected: %s (%s) in %s", ModuleName, name, class, zone))
|
||||
print(
|
||||
string.format("[%s] New player detected: %s (%s) in %s", ModuleName, name, class, zone)
|
||||
)
|
||||
end
|
||||
|
||||
player = Player.new(name, guild, race, class, zone)
|
||||
@@ -530,7 +565,14 @@ function shared.Whoer.Init()
|
||||
if player.firstSeen == "never" then
|
||||
player.firstSeen = timestamp
|
||||
if Heimdall_Data.config.who.debug then
|
||||
print(string.format("[%s] First time seeing player: %s at %s", ModuleName, name, timestamp))
|
||||
print(
|
||||
string.format(
|
||||
"[%s] First time seeing player: %s at %s",
|
||||
ModuleName,
|
||||
name,
|
||||
timestamp
|
||||
)
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -548,7 +590,12 @@ function shared.Whoer.Init()
|
||||
local err = Notify(player)
|
||||
if err then
|
||||
print(
|
||||
string.format("[%s] Error notifying for %s: %s", ModuleName, tostring(name), tostring(err))
|
||||
string.format(
|
||||
"[%s] Error notifying for %s: %s",
|
||||
ModuleName,
|
||||
tostring(name),
|
||||
tostring(err)
|
||||
)
|
||||
)
|
||||
end
|
||||
|
||||
@@ -571,7 +618,9 @@ function shared.Whoer.Init()
|
||||
)
|
||||
end
|
||||
local err = NotifyZoneChanged(player, zone)
|
||||
if err then print(string.format("Error notifying for %s: %s", tostring(name), tostring(err))) end
|
||||
if err then
|
||||
print(string.format("Error notifying for %s: %s", tostring(name), tostring(err)))
|
||||
end
|
||||
end
|
||||
player.zone = zone
|
||||
player.lastSeen = timestamp
|
||||
@@ -610,7 +659,9 @@ function shared.Whoer.Init()
|
||||
local query = shared.WhoQueryService.queries[whoQueryIdx]
|
||||
if not query then
|
||||
if Heimdall_Data.config.who.debug then
|
||||
print(string.format("[%s] Error: No WHO query found to run at index %d", ModuleName, whoQueryIdx))
|
||||
print(
|
||||
string.format("[%s] Error: No WHO query found to run at index %d", ModuleName, whoQueryIdx)
|
||||
)
|
||||
end
|
||||
return
|
||||
end
|
||||
@@ -645,4 +696,5 @@ function shared.Whoer.Init()
|
||||
end
|
||||
|
||||
print("[Heimdall] Whoer loaded")
|
||||
end
|
||||
end,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user