flickerstreak@25: --[[ flickerstreak@25: flickerstreak@25: ReAction Add-On main file. flickerstreak@25: flickerstreak@25: Performs add-on and library initialization and setup. flickerstreak@25: flickerstreak@25: --]] flickerstreak@25: flickerstreak@25: flickerstreak@25: -- 'ReAction' is exported as a global. flickerstreak@25: ReAction = AceLibrary("AceAddon-2.0"):new( flickerstreak@25: "AceModuleCore-2.0", flickerstreak@25: "AceEvent-2.0", flickerstreak@25: "AceDB-2.0" flickerstreak@25: ) flickerstreak@25: flickerstreak@25: local ReAction = ReAction flickerstreak@25: local L = AceLibrary("AceLocale-2.2"):new("ReAction") flickerstreak@25: local AceOO = AceLibrary("AceOO-2.0") flickerstreak@25: flickerstreak@25: flickerstreak@25: ReAction.revision = tonumber(("$Revision: 1 $"):match("%d+")) flickerstreak@25: ReAction.L = L flickerstreak@25: flickerstreak@25: -- global variable strings for integration with WoW keybindings dialog (see bindings.xml) flickerstreak@25: BINDING_HEADER_REACTION = L["ReAction"] flickerstreak@25: BINDING_NAME_REACTION_TOGGLELOCK = L["Toggle ReAction Bar Lock"] flickerstreak@25: BINDING_NAME_REACTION_TOGGLEKEYBIND = L["ReAction Keybinding Mode"] flickerstreak@25: flickerstreak@25: -- from AceAddon-2.0 flickerstreak@25: function ReAction:OnInitialize() flickerstreak@25: self:RegisterDB("ReActionDB") flickerstreak@25: end flickerstreak@25: flickerstreak@25: -- from AceAddon-2.0 flickerstreak@25: function ReAction:OnEnable() flickerstreak@25: flickerstreak@25: end flickerstreak@25: flickerstreak@25: -- from AceAddon-2.0 flickerstreak@25: function ReAction:OnDisable() flickerstreak@25: flickerstreak@25: end flickerstreak@25: flickerstreak@25: -- from AceDB-2.0 flickerstreak@25: function ReAction:OnProfileEnable() flickerstreak@25: flickerstreak@25: end flickerstreak@25: flickerstreak@25: -- from AceDB-2.0 flickerstreak@25: function ReAction:OnProfileDisable() flickerstreak@25: flickerstreak@25: end flickerstreak@25: flickerstreak@25: -- from AceModuleCore-2.0 flickerstreak@25: function ReAction:OnModuleEnable(module) flickerstreak@25: -- this handles initialization ordering issues with ReAction_Bar flickerstreak@25: local barMod = self:GetModule("Bar") flickerstreak@25: if barMod and module.ApplyToBar then flickerstreak@25: for _, b in pairs(barMod.bars) do flickerstreak@25: if b then flickerstreak@25: module:ApplyToBar(b) flickerstreak@25: end flickerstreak@25: end flickerstreak@25: end flickerstreak@25: end flickerstreak@25: flickerstreak@25: -- from AceModuleCore-2.0 flickerstreak@25: function ReAction:OnModuleDisable(module) flickerstreak@25: local barMod = self:GetModule("Bar") flickerstreak@25: if barMod and module.RemoveFromBar then flickerstreak@25: for _, b in pairs(barMod.bars) do flickerstreak@25: if b then flickerstreak@25: module:RemoveFromBar(b) flickerstreak@25: end flickerstreak@25: end flickerstreak@25: end flickerstreak@25: end flickerstreak@25: flickerstreak@25: --[[ flickerstreak@25: Module API (see bar.lua for usage) flickerstreak@25: flickerstreak@25: module:ApplyToBar(bar) flickerstreak@25: module:RemoveFromBar(bar) flickerstreak@25: module:RefreshBar(bar) flickerstreak@25: module:ApplyConfigMode(mode,listOfBars) flickerstreak@25: module:GetBarNameModifier(bar) flickerstreak@25: module:EraseBarConfig(barName) flickerstreak@25: ]]-- flickerstreak@25: flickerstreak@25: flickerstreak@25: -- debugging flickerstreak@25: ReAction.debug = true flickerstreak@25: if ReAction.debug then flickerstreak@25: ReAction.print = function(msg) flickerstreak@25: DEFAULT_CHAT_FRAME:AddMessage(msg) flickerstreak@25: end flickerstreak@25: --seterrorhandler(ReAction.print) flickerstreak@25: else flickerstreak@25: ReAction.print = function() end flickerstreak@25: end flickerstreak@25: flickerstreak@25: flickerstreak@25: -- utility flickerstreak@25: local newTable, recycle, deepCopy, deepDelete, varName flickerstreak@25: do flickerstreak@25: local pool = setmetatable( { }, {__mode="kv"} ) flickerstreak@25: flickerstreak@25: function newTable(...) flickerstreak@25: local t = table.remove(pool) or { } flickerstreak@25: for i = 1, select('#',...), 2 do flickerstreak@25: local k = select(i,...) flickerstreak@25: local v = select(i+1,...) flickerstreak@25: if k and v then flickerstreak@25: t[k] = v flickerstreak@25: end flickerstreak@25: end flickerstreak@25: return t flickerstreak@25: end flickerstreak@25: flickerstreak@25: function recycle(t) flickerstreak@25: if type(t) == "table" then flickerstreak@25: table.insert(pool,t) flickerstreak@25: end flickerstreak@25: end flickerstreak@25: flickerstreak@25: function deepCopy( x ) flickerstreak@25: if type(x) ~= "table" then flickerstreak@25: return x flickerstreak@25: end flickerstreak@25: local r = newTable() flickerstreak@25: for k,v in pairs(x) do flickerstreak@25: r[k] = deepCopy(v) flickerstreak@25: end flickerstreak@25: return r flickerstreak@25: end flickerstreak@25: flickerstreak@25: function deepDelete( x ) flickerstreak@25: if type(x) == "table" and x.IsObjectType == nil and not(AceOO.inherits(x,AceOO.Object)) then -- don't want to delete WoW or AceOO objects! flickerstreak@25: for k,v in pairs(x) do flickerstreak@25: x[k] = deepDelete(v) flickerstreak@25: end flickerstreak@25: recycle(x) flickerstreak@25: end flickerstreak@25: end flickerstreak@25: flickerstreak@25: function varName(s) flickerstreak@25: return tostring(s):gsub("[^a-zA-Z0-9_]","_") flickerstreak@25: end flickerstreak@25: flickerstreak@25: local u = setmetatable( { }, {__newindex = function(self,k,v) rawset(self,#self+1,v) ; rawset(self,k,v) end} ) flickerstreak@25: u.deepCopy = deepCopy flickerstreak@25: u.deepDelete = deepDelete flickerstreak@25: u.newTable = newTable flickerstreak@25: u.recycle = recycle flickerstreak@25: u.varName = varName flickerstreak@25: flickerstreak@25: ReAction.util = u flickerstreak@25: end flickerstreak@25: flickerstreak@25: function ReAction:GetUtilFuncs() flickerstreak@25: return unpack(self.util) flickerstreak@25: end flickerstreak@25: