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

This commit is contained in:
2025-05-18 12:31:26 +02:00
parent 017cbf01f8
commit 565db30125
11 changed files with 2004 additions and 1929 deletions

View File

@@ -1,5 +1,6 @@
local _, shared = ... local _, shared = ...
---@cast shared HeimdallShared ---@cast shared HeimdallShared
local ModuleName = "Inviter"
---@class HeimdallInviterConfig ---@class HeimdallInviterConfig
---@field enabled boolean ---@field enabled boolean
@@ -14,8 +15,6 @@ local _, shared = ...
---@field afkThreshold number ---@field afkThreshold number
---@field listeningChannel table<string, boolean> ---@field listeningChannel table<string, boolean>
local ModuleName = "Inviter"
---@class Inviter ---@class Inviter
shared.Inviter = { shared.Inviter = {
Init = function() Init = function()

View File

@@ -1,13 +1,12 @@
local _, shared = ... local _, shared = ...
---@cast shared HeimdallShared ---@cast shared HeimdallShared
local ModuleName = "Macroer"
---@class HeimdallMacroerConfig ---@class HeimdallMacroerConfig
---@field enabled boolean ---@field enabled boolean
---@field debug boolean ---@field debug boolean
---@field priority string[] ---@field priority string[]
local ModuleName = "Macroer"
---@class Macroer ---@class Macroer
shared.Macroer = { shared.Macroer = {
Init = function() Init = function()

View File

@@ -2,14 +2,14 @@ local _, shared = ...
---@cast shared HeimdallShared ---@cast shared HeimdallShared
local ModuleName = "Messenger" local ModuleName = "Messenger"
---@diagnostic disable-next-line: missing-fields ---@class Message
shared.Messenger = {} ---@field message string
function shared.Messenger.Init() ---@field channel string
---@class Message ---@field data string
---@field message string
---@field channel string
---@field data string
---@class Messenger
shared.Messenger = {
Init = function()
local function FindOrJoinChannel(channelName, password) local function FindOrJoinChannel(channelName, password)
local channelId = GetChannelName(channelName) local channelId = GetChannelName(channelName)
if channelId == 0 then if channelId == 0 then
@@ -35,7 +35,9 @@ function shared.Messenger.Init()
if not shared.messenger.ticker then if not shared.messenger.ticker then
local function DoMessage() local function DoMessage()
if Heimdall_Data.config.messenger.debug then 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 end
if not Heimdall_Data.config.messenger.enabled then if not Heimdall_Data.config.messenger.enabled then
@@ -106,7 +108,13 @@ function shared.Messenger.Init()
local channelId = GetChannelName(message.data) local channelId = GetChannelName(message.data)
if channelId == 0 then if channelId == 0 then
if Heimdall_Data.config.messenger.debug 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 end
channelId = FindOrJoinChannel(message.data) channelId = FindOrJoinChannel(message.data)
if Heimdall_Data.config.messenger.debug then if Heimdall_Data.config.messenger.debug then
@@ -173,4 +181,5 @@ function shared.Messenger.Init()
) )
end end
print("[Heimdall] Messenger loaded") print("[Heimdall] Messenger loaded")
end end,
}

View File

@@ -1,14 +1,15 @@
local _, shared = ... local _, shared = ...
---@cast shared HeimdallShared ---@cast shared HeimdallShared
local ModuleName = "MinimapTagger" local ModuleName = "MinimapTagger"
local HeimdallRoot = "Interface\\AddOns\\Heimdall\\" local HeimdallRoot = "Interface\\AddOns\\Heimdall\\"
local SoundRoot = HeimdallRoot .. "Sounds\\" local SoundRoot = HeimdallRoot .. "Sounds\\"
local TextureRoot = HeimdallRoot .. "Texture\\" 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) --/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 ---@class MinimapTagger
shared.MinimapTagger = {} shared.MinimapTagger = {
function shared.MinimapTagger.Init() Init = function()
---@param x number ---@param x number
---@param y number ---@param y number
---@param frame Frame ---@param frame Frame
@@ -565,7 +566,5 @@ function shared.MinimapTagger.Init()
end) end)
print("[Heimdall] MinimapTagger loaded") print("[Heimdall] MinimapTagger loaded")
end end,
}
SlashCmdList["HEIMDALL_MINIMAPTAGGER"] = function(args) shared.MinimapTagger.Init() end
SLASH_HEIMDALL_MINIMAPTAGGER1 = "/mf"

View File

@@ -5,6 +5,7 @@ local ModuleName = "Network"
---@class HeimdallNetworkData ---@class HeimdallNetworkData
---@field ticker Timer? ---@field ticker Timer?
---@class Network
shared.Network = { shared.Network = {
Init = function() Init = function()
if not shared.network then shared.network = {} end if not shared.network then shared.network = {} end

View File

@@ -2,9 +2,9 @@ local _, shared = ...
---@cast shared HeimdallShared ---@cast shared HeimdallShared
local ModuleName = "NetworkMessenger" local ModuleName = "NetworkMessenger"
---@diagnostic disable-next-line: missing-fields ---@class NetworkMessenger
shared.NetworkMessenger = {} shared.NetworkMessenger = {
function shared.NetworkMessenger.Init() Init = function()
RegisterAddonMessagePrefix(Heimdall_Data.config.addonPrefix) RegisterAddonMessagePrefix(Heimdall_Data.config.addonPrefix)
if not shared.networkMessenger then shared.networkMessenger = {} end 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)) -- print(string.format("[%s] Queue check - Network messages pending: %d", ModuleName, queueSize))
--end --end
DoMessage() 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 end
Tick() Tick()
end end
@@ -140,7 +141,13 @@ function shared.NetworkMessenger.Init()
local target = strtrim(tostring(parts[4])) local target = strtrim(tostring(parts[4]))
if Heimdall_Data.config.networkMessenger.debug then if Heimdall_Data.config.networkMessenger.debug then
print( 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 end
---@type Message ---@type Message
@@ -180,4 +187,5 @@ function shared.NetworkMessenger.Init()
end end
print("[Heimdall] NetworkMessenger module loaded") print("[Heimdall] NetworkMessenger module loaded")
end end,
}

View File

@@ -8,9 +8,9 @@ local ModuleName = "Noter"
---@field date string ---@field date string
---@field note string ---@field note string
---@diagnostic disable-next-line: missing-fields ---@class Noter
shared.Noter = {} shared.Noter = {
function shared.Noter.Init() Init = function()
-- ---Hopefully this will not be necessary -- ---Hopefully this will not be necessary
-- ---@param text string -- ---@param text string
-- ---@param size number -- ---@param size number
@@ -68,7 +68,9 @@ function shared.Noter.Init()
if not start then if not start then
if Heimdall_Data.config.noter.debug 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 end
return return
end end
@@ -292,4 +294,5 @@ function shared.Noter.Init()
end) end)
print("[Heimdall] Commander module loaded") print("[Heimdall] Commander module loaded")
end end,
}

View File

@@ -2,9 +2,9 @@ local _, shared = ...
---@cast shared HeimdallShared ---@cast shared HeimdallShared
local ModuleName = "Spotter" local ModuleName = "Spotter"
---@diagnostic disable-next-line: missing-fields ---@class Spotter
shared.Spotter = {} shared.Spotter = {
function shared.Spotter.Init() Init = function()
local function FormatHP(hp) local function FormatHP(hp)
if hp > 1e9 then if hp > 1e9 then
return string.format("%.1fB", hp / 1e9) 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 throttleTable[name] and time - throttleTable[name] < Heimdall_Data.config.spotter.throttleTime then
if Heimdall_Data.config.spotter.debug then if Heimdall_Data.config.spotter.debug then
local remainingTime = Heimdall_Data.config.spotter.throttleTime - (time - throttleTable[name]) 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 end
return string.format("Throttled %s", tostring(name)) return string.format("Throttled %s", tostring(name))
end end
@@ -221,4 +223,5 @@ function shared.Spotter.Init()
if Heimdall_Data.config.spotter.debug then print(string.format("[%s] Module initialized", ModuleName)) end if Heimdall_Data.config.spotter.debug then print(string.format("[%s] Module initialized", ModuleName)) end
print("[Heimdall] Spotter loaded") print("[Heimdall] Spotter loaded")
end end,
}

View File

@@ -1,11 +1,10 @@
local addonname, shared = ... local _, shared = ...
---@cast shared HeimdallShared ---@cast shared HeimdallShared
---@cast addonname string
local ModuleName = "StinkyCache" local ModuleName = "StinkyCache"
---@diagnostic disable-next-line: missing-fields ---@class StinkyCache
shared.StinkyCache = {} shared.StinkyCache = {
function shared.StinkyCache.Init() Init = function()
shared.stinkyCache = { shared.stinkyCache = {
stinkies = {}, stinkies = {},
} }
@@ -64,9 +63,12 @@ function shared.StinkyCache.Init()
__index = function(self, key) __index = function(self, key)
local value = rawget(self, key) local value = rawget(self, key)
local now = GetTime() 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) return rawget(self, key)
end, end,
}) })
print("[Heimdall] StinkyCache module loaded") print("[Heimdall] StinkyCache module loaded")
end end,
}

View File

@@ -2,9 +2,9 @@ local _, shared = ...
---@cast shared HeimdallShared ---@cast shared HeimdallShared
local ModuleName = "Whoer" local ModuleName = "Whoer"
---@diagnostic disable-next-line: missing-fields ---@class Whoer
shared.Whoer = {} shared.Whoer = {
function shared.Whoer.Init() Init = function()
if not Heimdall_Data.who then Heimdall_Data.who = {} end if not Heimdall_Data.who then Heimdall_Data.who = {} end
if not Heimdall_Data.who.data then Heimdall_Data.who.data = {} 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)) print(string.format("[%s] ShouldNotifyForZone %s", ModuleName, inputZone))
end end
for zone, _ in pairs(Heimdall_Data.config.who.zoneNotifyFor) do 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 zone == "*" then return true end
if string.find(inputZone, zone) then if string.find(inputZone, zone) then
if not Heimdall_Data.config.who.debug then if not Heimdall_Data.config.who.debug then
print( 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 end
return true return true
@@ -269,7 +276,11 @@ function shared.Whoer.Init()
--if not Heimdall_Data.config.who.zoneNotifyFor[player.zone] then --if not Heimdall_Data.config.who.zoneNotifyFor[player.zone] then
if Heimdall_Data.config.who.debug then if Heimdall_Data.config.who.debug then
print( 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 end
return string.format("Not notifying for zone %s", tostring(player.zone)) 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, ...) frame:SetScript("OnEvent", function(self, event, ...)
if Heimdall_Data.config.who.debug then if Heimdall_Data.config.who.debug then
print(string.format("[%s] WHO list update received", ModuleName)) 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 end
if not Heimdall_Data.config.who.enabled then 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) local name, guild, level, race, class, zone = GetWhoInfo(i)
if Heimdall_Data.config.who.debug then if Heimdall_Data.config.who.debug then
print( 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 end
@@ -470,13 +491,25 @@ function shared.Whoer.Init()
for _, filter in pairs(filters) do for _, filter in pairs(filters) do
if Heimdall_Data.config.who.debug then if Heimdall_Data.config.who.debug then
print( 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 end
if not filter.Run(name, guild, level, race, class, zone) then if not filter.Run(name, guild, level, race, class, zone) then
if Heimdall_Data.config.who.debug then if Heimdall_Data.config.who.debug then
print( 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 end
continue = true continue = true
@@ -502,7 +535,9 @@ function shared.Whoer.Init()
local player = HeimdallStinkies[name] local player = HeimdallStinkies[name]
if not player then if not player then
if Heimdall_Data.config.who.debug 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 end
player = Player.new(name, guild, race, class, zone) player = Player.new(name, guild, race, class, zone)
@@ -530,7 +565,14 @@ function shared.Whoer.Init()
if player.firstSeen == "never" then if player.firstSeen == "never" then
player.firstSeen = timestamp player.firstSeen = timestamp
if Heimdall_Data.config.who.debug then 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
end end
@@ -548,7 +590,12 @@ function shared.Whoer.Init()
local err = Notify(player) local err = Notify(player)
if err then if err then
print( 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 end
@@ -571,7 +618,9 @@ function shared.Whoer.Init()
) )
end end
local err = NotifyZoneChanged(player, zone) 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 end
player.zone = zone player.zone = zone
player.lastSeen = timestamp player.lastSeen = timestamp
@@ -610,7 +659,9 @@ function shared.Whoer.Init()
local query = shared.WhoQueryService.queries[whoQueryIdx] local query = shared.WhoQueryService.queries[whoQueryIdx]
if not query then if not query then
if Heimdall_Data.config.who.debug 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 end
return return
end end
@@ -645,4 +696,5 @@ function shared.Whoer.Init()
end end
print("[Heimdall] Whoer loaded") print("[Heimdall] Whoer loaded")
end end,
}