Initial commit
This commit is contained in:
87
src/main.lua
Normal file
87
src/main.lua
Normal file
@@ -0,0 +1,87 @@
|
||||
-- Copyright 2023 <omicron.me@protonmail.com>
|
||||
--
|
||||
-- This file is part of Omicron Frames
|
||||
--
|
||||
-- Omicron Frames is free software: you can redistribute it and/or modify it
|
||||
-- under the terms of the GNU General Public License as published by the Free
|
||||
-- Software Foundation, either version 3 of the License, or (at your option)
|
||||
-- any later version.
|
||||
--
|
||||
-- Omicron Frames is distributed in the hope that it will be useful, but
|
||||
-- WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
-- more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License along with
|
||||
-- Omicron Frames. If not, see <https://www.gnu.org/licenses/>.
|
||||
local AddonName, omif = ...
|
||||
omif.events = {} -- event (str) to list of handlers
|
||||
omif.db = nil
|
||||
|
||||
omif.modules = {}
|
||||
-- Simple function that creates or returns a local module table
|
||||
function omif.GetModule(name)
|
||||
if omif.modules[name] == nil then
|
||||
omif.modules[name] = {}
|
||||
end
|
||||
return omif.modules[name]
|
||||
end
|
||||
|
||||
-- Adds a given function to the event handler list for a given event
|
||||
-- This will later in the addon
|
||||
function omif.SetEventHandler(event, fn)
|
||||
if omif.events[event] == nil then
|
||||
omif.events[event] = {}
|
||||
end
|
||||
table.insert(omif.events[event], fn)
|
||||
end
|
||||
|
||||
-- The main handler receives basically every single event we want to listen to
|
||||
-- and dispatches them to more appropriate handlers
|
||||
function omif.MainEventHandler(frame, event, ...)
|
||||
local handlers = omif.events[event]
|
||||
if handlers ~= nil and next(handlers) ~= nil then
|
||||
for i, handler in ipairs(handlers) do
|
||||
handler(...)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Create the event frame and register all desired events
|
||||
function omif.SetupEvents()
|
||||
local frame = CreateFrame("Frame")
|
||||
for name, _ in pairs(omif.events) do
|
||||
if string.sub(name, 1, string.len("OMICRON")) ~= "OMICRON" then
|
||||
frame:RegisterEvent(name)
|
||||
end
|
||||
end
|
||||
frame:SetScript("OnEvent", omif.MainEventHandler)
|
||||
end
|
||||
|
||||
function omif.OnAddonLoaded(name)
|
||||
if name ~= AddonName then
|
||||
return
|
||||
end
|
||||
omif.MainEventHandler(nil, "OMICRON_LOADING")
|
||||
print("Loaded", AddonName)
|
||||
end
|
||||
omif.SetEventHandler("ADDON_LOADED", omif.OnAddonLoaded)
|
||||
|
||||
-- Fire custom event OMICRON_FULLY_LOADED. This event is fired when the player
|
||||
-- enters the world for the first time after logging in or reloading UI.
|
||||
function omif.FireFullyLoadedEvent(initialLogin, reloadUI)
|
||||
if initialLogin or reloadUI then
|
||||
omif.MainEventHandler(nil, "OMICRON_FULLY_LOADED")
|
||||
end
|
||||
end
|
||||
omif.SetEventHandler("PLAYER_ENTERING_WORLD", omif.FireFullyLoadedEvent)
|
||||
|
||||
function omif.SlashCommand(args)
|
||||
omif.cli.ToggleShow()
|
||||
end
|
||||
|
||||
function omif.SetupSlashCommands()
|
||||
_G["SLASH_OMICRON1"] = "/omicronframes"
|
||||
_G["SLASH_OMICRON2"] = "/omi"
|
||||
SlashCmdList["OMICRON"] = omif.SlashCommand
|
||||
end
|
Reference in New Issue
Block a user