Refactor Heimdall modules to use class-based structure for improved organization and clarity

This commit is contained in:
2025-05-18 12:28:25 +02:00
parent b16cf762ac
commit 017cbf01f8
5 changed files with 340 additions and 329 deletions

View File

@@ -1,12 +1,12 @@
local _, shared = ... local _, shared = ...
---@cast shared HeimdallShared ---@cast shared HeimdallShared
local ModuleName = "Configurator"
---@class HeimdallConfiguratorConfig ---@class HeimdallConfiguratorConfig
---@field enabled boolean ---@field enabled boolean
---@field debug boolean ---@field debug boolean
local ModuleName = "Configurator" ---@class Configurator
shared.Configurator = {
---@diagnostic disable-next-line: missing-fields Init = function() print(string.format("[Heimdall] %s module loaded", ModuleName)) end,
shared.Configurator = {} }
function shared.Configurator.Init() print(string.format("[Heimdall] %s module loaded", ModuleName)) end

View File

@@ -1,5 +1,6 @@
local _, shared = ... local _, shared = ...
---@cast shared HeimdallShared ---@cast shared HeimdallShared
local ModuleName = "DeathReporter"
---@class HeimdallDeathReporterConfig ---@class HeimdallDeathReporterConfig
---@field enabled boolean ---@field enabled boolean
@@ -10,11 +11,9 @@ local _, shared = ...
---@field zoneOverride string? ---@field zoneOverride string?
---@field duelThrottle number ---@field duelThrottle number
local ModuleName = "DeathReporter" ---@class DeathReporter
shared.DeathReporter = {
---@diagnostic disable-next-line: missing-fields Init = function()
shared.DeathReporter = {}
function shared.DeathReporter.Init()
---@type table<string, number> ---@type table<string, number>
local recentDeaths = {} local recentDeaths = {}
---@type table<string, number> ---@type table<string, number>
@@ -48,7 +47,8 @@ function shared.DeathReporter.Init()
and GetTime() - recentDeaths[destination] < Heimdall_Data.config.deathReporter.throttle and GetTime() - recentDeaths[destination] < Heimdall_Data.config.deathReporter.throttle
then then
if Heimdall_Data.config.deathReporter.debug then if Heimdall_Data.config.deathReporter.debug then
local timeLeft = Heimdall_Data.config.deathReporter.throttle - (GetTime() - recentDeaths[destination]) local timeLeft = Heimdall_Data.config.deathReporter.throttle
- (GetTime() - recentDeaths[destination])
print( print(
string.format( string.format(
"[%s] Death report throttled for %s (%.1f seconds remaining)", "[%s] Death report throttled for %s (%.1f seconds remaining)",
@@ -232,7 +232,12 @@ function shared.DeathReporter.Init()
if Heimdall_Data.config.deathReporter.debug then if Heimdall_Data.config.deathReporter.debug then
print(string.format("[%s] Received system message: %s", ModuleName, msg)) print(string.format("[%s] Received system message: %s", ModuleName, msg))
print( print(
string.format("[%s] Source: %s, Destination: %s", ModuleName, tostring(source), tostring(destination)) string.format(
"[%s] Source: %s, Destination: %s",
ModuleName,
tostring(source),
tostring(destination)
)
) )
end end
if not source or not destination then return end if not source or not destination then return end
@@ -259,4 +264,5 @@ function shared.DeathReporter.Init()
) )
end end
print("[Heimdall] DeathReporter loaded") print("[Heimdall] DeathReporter loaded")
end end,
}

View File

@@ -2,9 +2,9 @@ local _, shared = ...
---@cast shared HeimdallShared ---@cast shared HeimdallShared
local ModuleName = "Dueler" local ModuleName = "Dueler"
---@diagnostic disable-next-line: missing-fields ---@class Dueler
shared.Dueler = {} shared.Dueler = {
function shared.Dueler.Init() Init = function()
local frame = CreateFrame("Frame") local frame = CreateFrame("Frame")
frame:RegisterEvent("DUEL_REQUESTED") frame:RegisterEvent("DUEL_REQUESTED")
frame:SetScript("OnEvent", function(self, event, sender) frame:SetScript("OnEvent", function(self, event, sender)
@@ -36,7 +36,9 @@ function shared.Dueler.Init()
CancelDuel() CancelDuel()
else else
if Heimdall_Data.config.dueler.debug then if Heimdall_Data.config.dueler.debug then
print(string.format("[%s] Leaving duel request from %s for manual response", ModuleName, sender)) print(
string.format("[%s] Leaving duel request from %s for manual response", ModuleName, sender)
)
end end
end end
end end
@@ -52,4 +54,5 @@ function shared.Dueler.Init()
) )
end end
print("[Heimdall] Dueler loaded") print("[Heimdall] Dueler loaded")
end end,
}

View File

@@ -2,9 +2,9 @@ local _, shared = ...
---@cast shared HeimdallShared ---@cast shared HeimdallShared
local ModuleName = "Echoer" local ModuleName = "Echoer"
---@diagnostic disable-next-line: missing-fields ---@class Echoer
shared.Echoer = {} shared.Echoer = {
function shared.Echoer.Init() Init = function()
local frame = CreateFrame("Frame") local frame = CreateFrame("Frame")
frame:RegisterEvent("CHAT_MSG_CHANNEL") frame:RegisterEvent("CHAT_MSG_CHANNEL")
frame:SetScript("OnEvent", function(self, event, msg, sender, ...) frame:SetScript("OnEvent", function(self, event, msg, sender, ...)
@@ -55,4 +55,5 @@ function shared.Echoer.Init()
if Heimdall_Data.config.echoer.debug then print(string.format("[%s] Module initialized", ModuleName)) end if Heimdall_Data.config.echoer.debug then print(string.format("[%s] Module initialized", ModuleName)) end
print("[Heimdall] Echoer loaded") print("[Heimdall] Echoer loaded")
end end,
}

View File

@@ -2,9 +2,9 @@ local _, shared = ...
---@cast shared HeimdallShared ---@cast shared HeimdallShared
local ModuleName = "Emoter" local ModuleName = "Emoter"
---@diagnostic disable-next-line: missing-fields ---@class Emoter
shared.Emoter = {} shared.Emoter = {
function shared.Emoter.Init() Init = function()
local frame = CreateFrame("Frame") local frame = CreateFrame("Frame")
frame:RegisterEvent("CHAT_MSG_CHANNEL") frame:RegisterEvent("CHAT_MSG_CHANNEL")
frame:SetScript("OnEvent", function(self, event, msg, sender, ...) frame:SetScript("OnEvent", function(self, event, msg, sender, ...)
@@ -56,4 +56,5 @@ function shared.Emoter.Init()
if Heimdall_Data.config.emoter.debug then print(string.format("[%s] Module initialized", ModuleName)) end if Heimdall_Data.config.emoter.debug then print(string.format("[%s] Module initialized", ModuleName)) end
print("[Heimdall] Emoter loaded") print("[Heimdall] Emoter loaded")
end end,
}