Refactor code structure for improved readability and maintainability

This commit is contained in:
Torsten Brendgen
2026-04-28 23:09:04 +02:00
parent cf78405148
commit f97b7556cd
16 changed files with 1841 additions and 9 deletions

View File

@@ -40,6 +40,7 @@ local MSG_SYNC_REQUEST = "SRQ"
local MSG_SYNC_RESPONSE = "SRS" -- SRS|version|protocol|class|spec|talentHash|knownSpellIds|cd1:t1:d1;...
local MSG_RAID_TIMELINE = "RTL" -- RTL|encounterId|time|spellId|leadTime|alertText
local MSG_RAID_TIMELINE_TEST = "RTS" -- RTS|encounterId|difficultyId|serverStartTime|duration
local MSG_LURA_RUNES = "LUR" -- LUR|slot1,slot2,slot3,slot4,slot5
local MSG_RELIABLE = "REL" -- REL|messageId|innerPayload
local MSG_ACK = "ACK" -- ACK|messageId
local COMM_PREFIX = "HMGT"
@@ -85,6 +86,7 @@ HMGT.MSG_RELIABLE = MSG_RELIABLE
HMGT.MSG_ACK = MSG_ACK
HMGT.MSG_RAID_TIMELINE = MSG_RAID_TIMELINE
HMGT.MSG_RAID_TIMELINE_TEST = MSG_RAID_TIMELINE_TEST
HMGT.MSG_LURA_RUNES = MSG_LURA_RUNES
-- ── Standardwerte ─────────────────────────────────────────────
local defaults = {
@@ -119,6 +121,34 @@ local defaults = {
alertColor = { r = 1, g = 0.82, b = 0.15, a = 1 },
encounters = {},
},
encounterAlerts = {
enabled = false,
luraRunes = {
enabled = false,
unlocked = false,
posX = 0,
posY = -120,
iconSize = 44,
backgroundAlpha = 0.14,
showLabels = true,
actionBar = {
shown = false,
autoShow = true,
unlocked = false,
posX = 0,
posY = -300,
iconSize = 42,
iconSpacing = 8,
orientation = "horizontal",
border = {
enabled = false,
width = 2,
color = { r = 1, g = 0.82, b = 0.1, a = 0.9 },
},
},
slots = {},
},
},
notes = {
enabled = true,
mainText = "",
@@ -196,6 +226,7 @@ local DEBUG_SCOPE_LABELS = {
PowerSpend = "Power Spend",
RaidTimeline = "Raid Timeline",
Notes = "Notes",
EncounterAlerts = "Encounter Alerts",
}
local DEBUG_LEVELS = {
error = 1,
@@ -1458,6 +1489,67 @@ local function NormalizeRaidTimelineSettings(settings)
settings.encounters = normalizedEncounters
end
local VALID_LURA_RUNE_KEYS = {
circle = true,
cross = true,
diamond = true,
t = true,
triangle = true,
}
local function NormalizeLuraRuneKey(value)
local key = tostring(value or ""):lower()
if VALID_LURA_RUNE_KEYS[key] then
return key
end
return ""
end
local function NormalizeLuraRunesSettings(settings)
if type(settings) ~= "table" then return end
settings.enabled = settings.enabled == true
settings.unlocked = settings.unlocked == true
settings.posX = math.floor(NormalizeLayoutValue(settings.posX, -1200, 1200, 0) + 0.5)
settings.posY = math.floor(NormalizeLayoutValue(settings.posY, -900, 900, -120) + 0.5)
settings.iconSize = math.floor(NormalizeLayoutValue(settings.iconSize, 28, 80, 44) + 0.5)
settings.backgroundAlpha = NormalizeLayoutValue(settings.backgroundAlpha, 0, 0.8, 0.14)
settings.showLabels = settings.showLabels ~= false
settings.actionBar = type(settings.actionBar) == "table" and settings.actionBar or {}
settings.actionBar.shown = settings.actionBar.shown == true
settings.actionBar.autoShow = settings.actionBar.autoShow ~= false
settings.actionBar.unlocked = settings.actionBar.unlocked == true
settings.actionBar.posX = math.floor(NormalizeLayoutValue(settings.actionBar.posX, -1200, 1200, 0) + 0.5)
settings.actionBar.posY = math.floor(NormalizeLayoutValue(settings.actionBar.posY, -900, 900, -300) + 0.5)
settings.actionBar.iconSize = math.floor(NormalizeLayoutValue(settings.actionBar.iconSize, 28, 80, 42) + 0.5)
settings.actionBar.iconSpacing = math.floor(NormalizeLayoutValue(settings.actionBar.iconSpacing, 0, 80, 8) + 0.5)
settings.actionBar.orientation = tostring(settings.actionBar.orientation or "horizontal")
if settings.actionBar.orientation ~= "vertical" then
settings.actionBar.orientation = "horizontal"
end
settings.actionBar.border = type(settings.actionBar.border) == "table" and settings.actionBar.border or {}
settings.actionBar.border.enabled = settings.actionBar.border.enabled == true
settings.actionBar.border.width = math.floor(NormalizeLayoutValue(settings.actionBar.border.width, 1, 12, 2) + 0.5)
settings.actionBar.border.color = type(settings.actionBar.border.color) == "table" and settings.actionBar.border.color or {}
settings.actionBar.border.color.r = NormalizeLayoutValue(settings.actionBar.border.color.r, 0, 1, 1)
settings.actionBar.border.color.g = NormalizeLayoutValue(settings.actionBar.border.color.g, 0, 1, 0.82)
settings.actionBar.border.color.b = NormalizeLayoutValue(settings.actionBar.border.color.b, 0, 1, 0.1)
settings.actionBar.border.color.a = NormalizeLayoutValue(settings.actionBar.border.color.a, 0, 1, 0.9)
local slots = type(settings.slots) == "table" and settings.slots or {}
local normalizedSlots = {}
for slot = 1, 5 do
normalizedSlots[slot] = NormalizeLuraRuneKey(slots[slot])
end
settings.slots = normalizedSlots
end
local function NormalizeEncounterAlertsSettings(settings)
if type(settings) ~= "table" then return end
settings.enabled = settings.enabled == true
settings.luraRunes = type(settings.luraRunes) == "table" and settings.luraRunes or {}
NormalizeLuraRunesSettings(settings.luraRunes)
end
local function NormalizeNotesSettings(settings)
if type(settings) ~= "table" then return end
settings.enabled = settings.enabled ~= false
@@ -1762,6 +1854,8 @@ function HMGT:MigrateProfileSettings()
p.personalAuras = nil
p.raidTimeline = p.raidTimeline or {}
NormalizeRaidTimelineSettings(p.raidTimeline)
p.encounterAlerts = p.encounterAlerts or {}
NormalizeEncounterAlertsSettings(p.encounterAlerts)
p.notes = p.notes or {}
NormalizeNotesSettings(p.notes)
p.minimap = p.minimap or {}
@@ -3029,6 +3123,7 @@ function HMGT:GetHealthStatusLines()
AuraExpiry = self.AuraExpiry ~= nil,
MapOverlay = self.MapOverlay ~= nil,
RaidTimeline = self.RaidTimeline ~= nil,
EncounterAlerts = self.EncounterAlerts ~= nil,
Notes = self.Notes ~= nil,
}
local moduleParts = {}
@@ -3108,6 +3203,12 @@ function HMGT:SlashCommand(input)
else
self:OpenConfig()
end
elseif input:find("^lura") == 1 then
if self.EncounterAlerts and self.EncounterAlerts.HandleSlashCommand then
self.EncounterAlerts:HandleSlashCommand(input)
else
self:OpenConfig()
end
elseif input:find("^debugdump") == 1 then
local n = tonumber(input:match("^debugdump%s+(%d+)$"))
if self.DumpDevToolsLog then