view Turok.lua @ 1:766d8a40a1d6

first commit?
author Nenue
date Tue, 15 Dec 2015 08:07:21 -0500
parents
children 62f9b057c91b
line wrap: on
line source

-- GLOBALS: DEFAULT_CHAT_FRAME, SlashCmdList, hash_SlashCmdList
local T = LibStub("AceAddon-3.0"):NewAddon("Turok", "AceConsole-3.0", "AceEvent-3.0")
local _G = _G
local rawset = _G.rawset
local time = GetTime()
_G.Turok = T
local print = function(...)
  --_G.print('Core', ...)
end


T.mods = {}
T:SetDefaultModuleState(true)
T:SetDefaultModuleLibraries("AceEvent-3.0")
T:SetDefaultModulePrototype({OnInitialize = function(mod)
  print('CORE', mod:GetName().. ' found')
end})

-- propagates parameter data around
function T:LinkTable(parent, child, pname, cname)
  local mt = {
    __index = function(t,k)
      if parent[k] then
        t[k] = parent[k]
        end
      print('|cFFFF8800'.. pname ..'.' .. cname .. '|r.|cFFFFFF00'.. k ..'|r inheriting value at |cFFFF8800' .. pname ..'|r.|cFFFFFF00'.. k..'|r')
      return parent[k]
    end,
    __newindex = function (t, k, v)
      rawset(t,k,v)
      if type(v) == 'table' then
        T:LinkTable(child, v, pname, k)
        print('|cFFFF8800'.. pname ..'.' .. cname .. '|r.|cFFFFFF00'.. k ..'|r sub-table created')
      end
    end
  }
  print('|cFFFF8800'.. pname ..'.|cFFFFFF00'.. cname ..'|r sub-tables will be retconned')
  setmetatable(child, mt)
  for k, v in  pairs(child) do
    if type(v) == 'table' then
      T:LinkTable(child, v, cname, k)
    end
  end
end

function T:OnInitialize()

  local defaults = {
    background_color = {0,0,0,0},
    background_blend = 'BLEND',
    foreground_color = {1,1,1,0.5},
    foreground_blend = 'BLEND',
    foreground_inset = -1,
    width = 250,
    height = 100,
    alpha = 1,
    alpha_ooc = 0.1,
    strata = 'LOW',
    label_strata = 'HIGH',
    label_justifyH = 'LEFT',
    label_color = {1, 1, 1, 1},
    label_font = 'turok',
    label_size = 14,
    label_inset = -2,
    label_point = 'LEFT',
    label_outline = 'OUTLINE',
    anchor = 'CENTER', parent = 'UIParent', anchorTo = 'CENTER',
    focusbar = {
      foreground_color = {1, 1, 1, 0.7},
      background_color = {0,0,0,0.8},
      width = 300, height = 24,
      posX = 0, posY = -150,
    },
  }
  _G.TurokData = defaults
  if not _G.TurokData then
    _G.TurokData = defaults
  end

  T.db = _G.TurokData
  local db = T.db
  for k, v in pairs(db) do
    if type(v) == 'table' then
      T:LinkTable(db, v, 'db', k)
    end
  end
  setmetatable(db,
    {__newindex = function (t, k, v)
    rawset(t,k,v)
    if type(v) == 'table' then
      T:LinkTable(db, v, 'db', k)
      print('CFG', '|cFFFF0000db|r.|cFF00FFFF' .. k ..'|r created at bottom level')
    end
    end})

  options = {
    type = 'group',
    name = 'Turok',
    handler = T,
    set = function(info,value)
      local k = db[info[1]]
      for i = 2, #info-1 do
        if type(k[i]) ~= 'table' then
          print('fart')
        end

        k = k[i]
      end
      k[info[#info]] = value
    end,
    get = function(info)
      local k = db[info[1]]
      for i = 2, #info-1 do
        if type(k[i]) ~= 'table' then
          print('fart')
        end

        k = k[i]
      end
      return k[info[#info]]
    end,
    desc = '"Dinosaur" Hunter',
    args = {
      background_color = {
        type = 'color',
        name = 'Background Color',
        hasAlpha = true,
      }
    }
  }
  LibStub("AceConfig-3.0"):RegisterOptionsTable('Turok', options, {"tk"})

end


function T:OnEnable()
  local db = _G.TurokData

  print('I... am Turok')

  self.stats = {}


  T.focusbar = T:CreateBar('TkFocusBar', db.focusbar)
  local fb = T.focusbar
  T:AddLabel(fb, db.focusbar)
  fb:Update(UnitPower("player"), 0, UnitPowerMax("player"))
  T:Bar_SetUpdateHandler(fb, function(self)
      T.Bar_Update(fb, UnitPower("player"))
  end)
end