view ReAction.lua @ 25:bf997ea151ca

yet another attempt to add missing files
author Flick <flickerstreak@gmail.com>
date Fri, 07 Mar 2008 22:19:03 +0000
parents
children f1e838841ce1
line wrap: on
line source
--[[

  ReAction Add-On main file. 
  
  Performs add-on and library initialization and setup.

--]]


-- 'ReAction' is exported as a global.
ReAction = AceLibrary("AceAddon-2.0"):new(
  "AceModuleCore-2.0",
  "AceEvent-2.0",
  "AceDB-2.0"
)

local ReAction = ReAction
local L = AceLibrary("AceLocale-2.2"):new("ReAction")
local AceOO = AceLibrary("AceOO-2.0")


ReAction.revision = tonumber(("$Revision: 1 $"):match("%d+"))
ReAction.L = L

-- global variable strings for integration with WoW keybindings dialog (see bindings.xml)
BINDING_HEADER_REACTION             = L["ReAction"]
BINDING_NAME_REACTION_TOGGLELOCK    = L["Toggle ReAction Bar Lock"]
BINDING_NAME_REACTION_TOGGLEKEYBIND = L["ReAction Keybinding Mode"]

-- from AceAddon-2.0
function ReAction:OnInitialize()
  self:RegisterDB("ReActionDB")
end

-- from AceAddon-2.0
function ReAction:OnEnable()

end

-- from AceAddon-2.0
function ReAction:OnDisable()

end

-- from AceDB-2.0
function ReAction:OnProfileEnable()

end

-- from AceDB-2.0
function ReAction:OnProfileDisable()

end

-- from AceModuleCore-2.0
function ReAction:OnModuleEnable(module)
  -- this handles initialization ordering issues with ReAction_Bar
  local barMod = self:GetModule("Bar")
  if barMod and module.ApplyToBar then
    for _, b in pairs(barMod.bars) do
      if b then
        module:ApplyToBar(b)
      end
    end
  end
end

-- from AceModuleCore-2.0
function ReAction:OnModuleDisable(module)
  local barMod = self:GetModule("Bar")
  if barMod and module.RemoveFromBar then
    for _, b in pairs(barMod.bars) do
      if b then
        module:RemoveFromBar(b)
      end
    end
  end
end

--[[
  Module API (see bar.lua for usage)

  module:ApplyToBar(bar)
  module:RemoveFromBar(bar)
  module:RefreshBar(bar)
  module:ApplyConfigMode(mode,listOfBars)
  module:GetBarNameModifier(bar)
  module:EraseBarConfig(barName)
]]--


-- debugging
ReAction.debug = true
if ReAction.debug then
  ReAction.print = function(msg)
    DEFAULT_CHAT_FRAME:AddMessage(msg)
  end
  --seterrorhandler(ReAction.print)
else
  ReAction.print = function() end
end


-- utility
local newTable, recycle, deepCopy, deepDelete, varName
do
  local pool = setmetatable( { }, {__mode="kv"} )

  function newTable(...)
    local t = table.remove(pool) or { }
    for i = 1, select('#',...), 2 do
      local k = select(i,...)
      local v = select(i+1,...)
      if k and v then
        t[k] = v
      end
    end
    return t
  end

  function recycle(t)
    if type(t) == "table" then
      table.insert(pool,t)
    end
  end

  function deepCopy( x )
    if type(x) ~= "table" then
      return x
    end
    local r = newTable()
    for k,v in pairs(x) do
      r[k] = deepCopy(v)
    end
    return r
  end

  function deepDelete( x )
    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!
      for k,v in pairs(x) do
        x[k] = deepDelete(v)
      end
      recycle(x)
    end
  end

  function varName(s)
    return tostring(s):gsub("[^a-zA-Z0-9_]","_")
  end

  local u = setmetatable( { }, {__newindex = function(self,k,v) rawset(self,#self+1,v) ; rawset(self,k,v) end} )
  u.deepCopy = deepCopy
  u.deepDelete = deepDelete
  u.newTable = newTable
  u.recycle = recycle
  u.varName = varName

  ReAction.util = u
end

function ReAction:GetUtilFuncs()
  return unpack(self.util)
end