comparison Turok.lua @ 1:766d8a40a1d6

first commit?
author Nenue
date Tue, 15 Dec 2015 08:07:21 -0500
parents
children 62f9b057c91b
comparison
equal deleted inserted replaced
0:ebbcc148a407 1:766d8a40a1d6
1
2 -- GLOBALS: DEFAULT_CHAT_FRAME, SlashCmdList, hash_SlashCmdList
3 local T = LibStub("AceAddon-3.0"):NewAddon("Turok", "AceConsole-3.0", "AceEvent-3.0")
4 local _G = _G
5 local rawset = _G.rawset
6 local time = GetTime()
7 _G.Turok = T
8 local print = function(...)
9 --_G.print('Core', ...)
10 end
11
12
13 T.mods = {}
14 T:SetDefaultModuleState(true)
15 T:SetDefaultModuleLibraries("AceEvent-3.0")
16 T:SetDefaultModulePrototype({OnInitialize = function(mod)
17 print('CORE', mod:GetName().. ' found')
18 end})
19
20 -- propagates parameter data around
21 function T:LinkTable(parent, child, pname, cname)
22 local mt = {
23 __index = function(t,k)
24 if parent[k] then
25 t[k] = parent[k]
26 end
27 print('|cFFFF8800'.. pname ..'.' .. cname .. '|r.|cFFFFFF00'.. k ..'|r inheriting value at |cFFFF8800' .. pname ..'|r.|cFFFFFF00'.. k..'|r')
28 return parent[k]
29 end,
30 __newindex = function (t, k, v)
31 rawset(t,k,v)
32 if type(v) == 'table' then
33 T:LinkTable(child, v, pname, k)
34 print('|cFFFF8800'.. pname ..'.' .. cname .. '|r.|cFFFFFF00'.. k ..'|r sub-table created')
35 end
36 end
37 }
38 print('|cFFFF8800'.. pname ..'.|cFFFFFF00'.. cname ..'|r sub-tables will be retconned')
39 setmetatable(child, mt)
40 for k, v in pairs(child) do
41 if type(v) == 'table' then
42 T:LinkTable(child, v, cname, k)
43 end
44 end
45 end
46
47 function T:OnInitialize()
48
49 local defaults = {
50 background_color = {0,0,0,0},
51 background_blend = 'BLEND',
52 foreground_color = {1,1,1,0.5},
53 foreground_blend = 'BLEND',
54 foreground_inset = -1,
55 width = 250,
56 height = 100,
57 alpha = 1,
58 alpha_ooc = 0.1,
59 strata = 'LOW',
60 label_strata = 'HIGH',
61 label_justifyH = 'LEFT',
62 label_color = {1, 1, 1, 1},
63 label_font = 'turok',
64 label_size = 14,
65 label_inset = -2,
66 label_point = 'LEFT',
67 label_outline = 'OUTLINE',
68 anchor = 'CENTER', parent = 'UIParent', anchorTo = 'CENTER',
69 focusbar = {
70 foreground_color = {1, 1, 1, 0.7},
71 background_color = {0,0,0,0.8},
72 width = 300, height = 24,
73 posX = 0, posY = -150,
74 },
75 }
76 _G.TurokData = defaults
77 if not _G.TurokData then
78 _G.TurokData = defaults
79 end
80
81 T.db = _G.TurokData
82 local db = T.db
83 for k, v in pairs(db) do
84 if type(v) == 'table' then
85 T:LinkTable(db, v, 'db', k)
86 end
87 end
88 setmetatable(db,
89 {__newindex = function (t, k, v)
90 rawset(t,k,v)
91 if type(v) == 'table' then
92 T:LinkTable(db, v, 'db', k)
93 print('CFG', '|cFFFF0000db|r.|cFF00FFFF' .. k ..'|r created at bottom level')
94 end
95 end})
96
97 options = {
98 type = 'group',
99 name = 'Turok',
100 handler = T,
101 set = function(info,value)
102 local k = db[info[1]]
103 for i = 2, #info-1 do
104 if type(k[i]) ~= 'table' then
105 print('fart')
106 end
107
108 k = k[i]
109 end
110 k[info[#info]] = value
111 end,
112 get = function(info)
113 local k = db[info[1]]
114 for i = 2, #info-1 do
115 if type(k[i]) ~= 'table' then
116 print('fart')
117 end
118
119 k = k[i]
120 end
121 return k[info[#info]]
122 end,
123 desc = '"Dinosaur" Hunter',
124 args = {
125 background_color = {
126 type = 'color',
127 name = 'Background Color',
128 hasAlpha = true,
129 }
130 }
131 }
132 LibStub("AceConfig-3.0"):RegisterOptionsTable('Turok', options, {"tk"})
133
134 end
135
136
137 function T:OnEnable()
138 local db = _G.TurokData
139
140 print('I... am Turok')
141
142 self.stats = {}
143
144
145 T.focusbar = T:CreateBar('TkFocusBar', db.focusbar)
146 local fb = T.focusbar
147 T:AddLabel(fb, db.focusbar)
148 fb:Update(UnitPower("player"), 0, UnitPowerMax("player"))
149 T:Bar_SetUpdateHandler(fb, function(self)
150 T.Bar_Update(fb, UnitPower("player"))
151 end)
152 end