mirror of
https://github.com/Nighthawk42/wow_bejeweled.git
synced 2026-08-30 04:30:22 +00:00
134 lines
4.3 KiB
Lua
134 lines
4.3 KiB
Lua
local addonName, addon = ...
|
|
|
|
if type(addon) ~= "table" then
|
|
error("Bejeweled requires a private addon namespace")
|
|
end
|
|
|
|
addon.name = addonName
|
|
addon.runtimeVersion = "0.1.0-alpha"
|
|
|
|
function addon:Initialize(accountData, profileData)
|
|
if self.initialized then
|
|
return self
|
|
end
|
|
|
|
assert(self.SavedVariables, "SavedVariables module is not loaded")
|
|
assert(self.Grid, "Grid module is not loaded")
|
|
assert(self.Audio, "Audio module is not loaded")
|
|
assert(self.Fonts, "Fonts module is not loaded")
|
|
assert(self.Backdrops, "Backdrops module is not loaded")
|
|
assert(self.GemPool, "GemPool module is not loaded")
|
|
assert(self.Animations, "Animations module is not loaded")
|
|
assert(self.HUD, "HUD module is not loaded")
|
|
assert(self.Summary, "Summary module is not loaded")
|
|
assert(self.Skills, "Skills module is not loaded")
|
|
assert(self.Options, "Options module is not loaded")
|
|
assert(self.About, "About module is not loaded")
|
|
assert(self.Legal, "Legal module is not loaded")
|
|
assert(self.MainWindow, "MainWindow module is not loaded")
|
|
assert(self.Compartment, "Compartment module is not loaded")
|
|
assert(self.MinimapButton, "MinimapButton module is not loaded")
|
|
assert(self.Input, "Input module is not loaded")
|
|
assert(self.Session, "Session module is not loaded")
|
|
|
|
self.accountData, self.profileData = self.SavedVariables:Initialize(accountData, profileData)
|
|
self.grid = self.Grid:New()
|
|
self.audio = self.Audio:New(self.profileData.settings)
|
|
self.fonts = self.Fonts
|
|
self.backdrops = self.Backdrops
|
|
self.gemPoolFactory = self.GemPool
|
|
self.animationFactory = self.Animations
|
|
self.hudFactory = self.HUD
|
|
self.summaryFactory = self.Summary
|
|
self.skillsFactory = self.Skills
|
|
self.optionsFactory = self.Options
|
|
self.aboutFactory = self.About
|
|
self.legalFactory = self.Legal
|
|
self.mainWindowFactory = self.MainWindow
|
|
self.compartment = self.Compartment
|
|
self.minimapButtonFactory = self.MinimapButton
|
|
self.inputFactory = self.Input
|
|
self.sessionFactory = self.Session
|
|
self.initialized = true
|
|
if UIParent ~= nil and type(UnitName) == "function" and not self.runtime then
|
|
self:StartRuntime()
|
|
end
|
|
|
|
return self
|
|
end
|
|
|
|
function addon:EnsureMinimapButton(options)
|
|
if self.minimapButton then
|
|
return self.minimapButton
|
|
end
|
|
options = options or {}
|
|
local minimap = options.minimap or Minimap
|
|
local uiParent = options.uiParent or UIParent
|
|
if not minimap or not uiParent then
|
|
return nil
|
|
end
|
|
self.minimapButton = self.MinimapButton:New({
|
|
minimap = minimap,
|
|
uiParent = uiParent,
|
|
settings = self.profileData.settings,
|
|
createFrame = options.createFrame,
|
|
tooltip = options.minimapTooltip,
|
|
cursorPosition = options.cursorPosition,
|
|
runtimeProvider = function()
|
|
return self.runtime
|
|
end,
|
|
})
|
|
return self.minimapButton
|
|
end
|
|
|
|
function addon:StartRuntime(options)
|
|
assert(self.initialized, "addon must be initialized before starting the runtime")
|
|
if self.runtime then
|
|
self:EnsureMinimapButton(options)
|
|
return self.runtime
|
|
end
|
|
options = options or {}
|
|
assert(type(options) == "table", "runtime options must be a table")
|
|
local playerName = options.playerName or function()
|
|
local name = UnitName("player")
|
|
assert(type(name) == "string" and name ~= "", "player name is unavailable")
|
|
return name
|
|
end
|
|
self.runtime = self.MainWindow:New(options.uiParent or UIParent, {
|
|
createFrame = options.createFrame,
|
|
profile = self.profileData,
|
|
accountData = self.accountData,
|
|
audio = self.audio,
|
|
playerName = playerName,
|
|
grid = self.grid,
|
|
random = options.random,
|
|
timedDuration = options.timedDuration,
|
|
hintsEnabled = options.hintsEnabled,
|
|
flightOptionProvider = options.flightOptionProvider,
|
|
onFlightTimedRequested = options.onFlightTimedRequested,
|
|
onSettingsChanged = function(key, value, window)
|
|
if key == "hideMinimap" and self.minimapButton then
|
|
self.minimapButton:RefreshVisibility()
|
|
end
|
|
if options.onSettingsChanged then
|
|
return options.onSettingsChanged(key, value, window)
|
|
end
|
|
end,
|
|
})
|
|
self:EnsureMinimapButton(options)
|
|
self.runtime:Show()
|
|
return self.runtime
|
|
end
|
|
|
|
if type(CreateFrame) == "function" then
|
|
local eventFrame = CreateFrame("Frame")
|
|
eventFrame:RegisterEvent("ADDON_LOADED")
|
|
eventFrame:SetScript("OnEvent", function(self, event, loadedAddonName)
|
|
if event == "ADDON_LOADED" and loadedAddonName == addonName then
|
|
self:UnregisterEvent("ADDON_LOADED")
|
|
addon:Initialize()
|
|
end
|
|
end)
|
|
addon.eventFrame = eventFrame
|
|
end
|