AltSystem/Core.lua
2026-05-09 02:11:24 +01:00

119 lines
3.7 KiB
Lua

-- AltSystem Core
-- Addon initialization, slash command registration, and TRP3 integration.
AltSystem = AltSystem or {}
AltSystem.State = {
selectedSkillIndex = 1,
selectedItemIndex = 1, -- 1 = No item
selectedDefenseIndex = 1, -- 1 = Base armor
shieldEnabled = false,
petSummonEnabled = false,
announceEnabled = false,
announceChannelIndex = 1, -- 1 = Emote, 2 = Party, 3 = Raid, 4 = Guild
}
-- Channel definitions for announcing rolls
AltSystem.AnnounceChannels = {
{ name = "Emote (/e)", channel = "EMOTE" },
{ name = "Party (/p)", channel = "PARTY" },
{ name = "Raid (/ra)", channel = "RAID" },
{ name = "Guild (/g)", channel = "GUILD" },
}
-- Initialization on ADDON_LOADED
local frame = CreateFrame("Frame")
frame:RegisterEvent("ADDON_LOADED")
frame:SetScript("OnEvent", function(self, event, arg1)
if event == "ADDON_LOADED" and arg1 == "AltSystem" then
AltSystem:Init()
AltSystem:RegisterTRP3Module()
end
end)
function AltSystem:Init()
-- Load saved settings
AltSystemDB = AltSystemDB or {}
if AltSystemDB.announceEnabled ~= nil then
AltSystem.State.announceEnabled = AltSystemDB.announceEnabled
end
if AltSystemDB.announceChannelIndex then
AltSystem.State.announceChannelIndex = AltSystemDB.announceChannelIndex
end
if AltSystemDB.petSummonEnabled ~= nil then
AltSystem.State.petSummonEnabled = AltSystemDB.petSummonEnabled
end
-- Register slash command /altsystem
SLASH_ALTSYSTEM1 = "/altsystem"
SlashCmdList["ALTSYSTEM"] = function()
AltSystem:ToggleWindow()
end
-- Save settings on logout
local saveFrame = CreateFrame("Frame")
saveFrame:RegisterEvent("PLAYER_LOGOUT")
saveFrame:SetScript("OnEvent", function()
AltSystemDB = AltSystemDB or {}
AltSystemDB.announceEnabled = AltSystem.State.announceEnabled
AltSystemDB.announceChannelIndex = AltSystem.State.announceChannelIndex
AltSystemDB.petSummonEnabled = AltSystem.State.petSummonEnabled
end)
print("|cff00ccffAltSystem|r loaded. Type /altsystem to open.")
end
function AltSystem:ToggleWindow()
if AltSystem.MainFrame then
if AltSystem.MainFrame:IsShown() then
AltSystem.MainFrame:Hide()
else
AltSystem.MainFrame:Show()
end
end
end
-- Register as a TRP3 module so our onStart runs in the correct lifecycle phase
-- (after the toolbar module is initialized, but before WORKFLOW_ON_FINISH locks it)
function AltSystem:RegisterTRP3Module()
if not TRP3_API or not TRP3_API.module then
return
end
local MODULE_STRUCTURE = {
["name"] = "AltSystem",
["description"] = "AltSystem rolling window toolbar button",
["version"] = 1.000,
["id"] = "altsystem_module",
["onStart"] = function()
AltSystem:RegisterTRP3Button()
end,
["minVersion"] = 3,
["requiredDeps"] = {
{"trp3_tool_bar", 1},
},
}
TRP3_API.module.registerModule(MODULE_STRUCTURE)
end
-- TRP3 toolbar button registration (called from the TRP3 module onStart)
function AltSystem:RegisterTRP3Button()
if TRP3_API and TRP3_API.toolbar then
local toolbarButton = {
id = "altsystem_toolbar_btn",
icon = "INV_Misc_Dice_01",
configText = "AltSystem",
tooltip = "AltSystem",
tooltipSub = "Open the AltSystem rolling window",
onClick = function(_, _, button)
if button == "LeftButton" then
AltSystem:ToggleWindow()
end
end,
visible = 1,
}
TRP3_API.toolbar.toolbarAddButton(toolbarButton)
end
end