comparison Devian.lua @ 0:585221424a93

initial commit
author Nenue
date Tue, 15 Dec 2015 10:18:27 -0500
parents
children a13243a4118b
comparison
equal deleted inserted replaced
-1:000000000000 0:585221424a93
1 -- User: Krakyn
2 -- Created: 11/30/2015 7:46 AM
3 if not LibStub then
4 print('Something has happened...')
5 end
6
7 Devian = LibStub("AceAddon-3.0"):NewAddon("Devian", "AceConsole-3.0", "AceEvent-3.0")
8 local D = _G.Devian
9
10 local db
11 local msg = function(...)
12 D:Print(...)
13 end
14 local STATE_LOW, STATE_HIGH = 1, 2
15 local PLAYER_REALM = UnitName("player") .. '-' .. GetRealmName()
16 local DEVIAN_FRAME = DevianDebugInfo
17
18 local ScanAddOnList = function(args)
19 local list_state
20
21 local mode = tonumber(args:match('^%d$'))
22
23 print('ScanAddOnList(', mode, ')')
24 if mode == nil then
25 list_state = db.enabled and STATE_LOW or STATE_HIGH
26 db.enabled = (db.enabled == false) and true or false
27 print(list_state, db.enabled)
28
29 if list_state == STATE_LOW then
30 BNSetDND(true)
31 end
32
33 else
34 if mode > 2 then
35 print('ScanAddOnList(',mode,'): Something has happened.')
36 return
37 end
38 list_state = mode == STATE_LOW and STATE_LOW or STATE_HIGH
39
40 if not db.chat_size then
41 db.chat_size = {}
42 end
43 if mode == STATE_LOW or mode == STATE_HIGH then
44 db.chat_size[list_state] = ChatFrame1:GetHeight()
45 end
46
47 end
48 local char_list, global_list = db[PLAYER_REALM][list_state], db.global[list_state]
49
50 local playername = UnitName("player")
51
52 for i = 1, GetNumAddOns() do
53 local name = GetAddOnInfo(i)
54 local enableState, globalState = GetAddOnEnableState(playername, i), GetAddOnEnableState(nil, i)
55
56 if mode == STATE_LOW or mode == STATE_HIGH then
57 char_list[name] = enableState
58 global_list[name] = globalState
59 else
60
61 if char_list[name] ~= 0 and global_list[name] ~= 0 then
62 local value = false
63 if char_list[name] == 2 and global_list[name] == 1 then
64 value = UnitName("player")
65 elseif global_list[name] == 2 then
66 value = true
67 end
68 print('EnableAddOn(', i, ',', value,')')
69 EnableAddOn(i, value)
70 else
71 local value = true
72 if char_list[name] == 2 and global_list[name] == 1 then
73 value = UnitName("player")
74 end
75 print('DisableAddOn(', i, ',', value,')')
76 DisableAddOn(i,value)
77 end
78
79 end
80 end
81
82 if mode == nil then
83 ReloadUI()
84 end
85 if mode == STATE_LOW then
86 D:Print('Developement AddOn list saved.')
87 else
88 D:Print('Standard AddOn list saved.')
89 end
90 end
91
92 -- Debug info
93 local function CreateMessenger()
94 -- TODO: throw this into an XML file
95 if not DEVIAN_FRAME then
96 DEVIAN_FRAME = CreateFrame('ScrollingMessageFrame', DEVIAN_FRAME, UIParent)
97 if not db.console then
98 DEVIAN_FRAME:Hide()
99 end
100 end
101
102 local f = DEVIAN_FRAME
103 f.backdrop = f:CreateTexture('backdrop', 'BACKGROUND')
104 f.backdrop:SetTexture(1,1,1,1)
105 f.backdrop:SetGradient('HORIZONTAL', 0.2, 0.2, 0.2, 1, 1, 1)
106 f.backdrop:SetBlendMode('MOD')
107 f.backdrop:SetAllPoints(f)
108 f:AddMessage('init a thing')
109
110 f:EnableMouseWheel(true)
111 f:EnableKeyboard(true)
112 f:SetScript('OnMouseWheel', function (self, delta)
113 local up = delta > 0
114 if IsControlKeyDown() then
115 if up then self:ScrollToTop()
116 else self:ScrollToBottom() end
117 elseif IsShiftKeyDown() then
118 if up then self:PageUp()
119 else self:PageDown() end
120 else
121 if up then self:ScrollUp()
122 else self:ScrollDown() end
123 end
124 end)
125
126 f:ScrollToBottom()
127 f:SetMaxLines(100)
128 f:SetInsertMode('BOTTOM')
129 f:SetPoint('BOTTOMLEFT', GENERAL_CHAT_DOCK, 'TOPLEFT', 0, 25)
130 f:SetPoint('TOPRIGHT', UIParent, 'TOP', 0, 0- PlayerFrame:GetHeight())
131 f:SetFrameStrata('BACKGROUND')
132 f:SetFont([[Interface\Addons\Turok\Media\font\SourceCodePro-Regular.ttf]], 14, 'NONE')
133
134 f:SetFading(false)
135 f:SetTimeVisible(2147483647)
136 f:SetJustifyH('LEFT')
137
138
139 D.debug_init = true
140 end
141
142 local prefix_cache = {}
143 local function Message(prefix, ...)
144
145 -- colorize
146 if not prefix_cache[prefix] then
147 local c = {0, 0, 0 }
148 local max = string.len(prefix)
149 for i = 1, max, 3 do
150 for k, v in ipairs(c) do
151 local j = i + (k - 1)
152 c[k] = c[k] + (j <= max and string.byte(prefix,j) or 0)
153 end
154 end
155 for k,v in ipairs(c) do
156 c[k] = c[k] % 255
157 if c[k] < 64 then
158 c[k] = 0
159 elseif c[k] > 127 then
160 c[k] = 255
161 end
162 end
163 prefix_cache[prefix] = string.format('%02X%02X%02X', unpack(c))
164 end
165
166 local buffer = {'|cFF'.. prefix_cache[prefix]..prefix ..'|r'}
167 for i = 1, select('#',...) do
168 local var = select(i, ...)
169
170 if type(var) == 'table' then
171 var = '<table>'
172 elseif type(var) == 'boolean' then
173 var = var and 'true' or 'false'
174 elseif type(var) == 'function' then
175 var = '<funcref>'
176 elseif type(var) == 'nil' then
177 var = 'nil'
178 end
179
180 table.insert(buffer, var)
181 end
182 DEVIAN_FRAME:AddMessage(table.concat(buffer, ' '))
183 table.wipe(buffer)
184 end
185
186 function D:OnEnable()
187 if db.enabled then
188 DEVIAN_FRAME:Hide()
189 D:Print('Standard AddOn list active. Type /dvn to switch to development mode.')
190 else
191 D:Print('Development AddOn list active. Type /dvn to revert to regular operation.')
192 end
193 end
194
195 function D:OnInitialize()
196
197 local cherry = false
198 if not DevianDB then
199 DevianDB = {
200 ['global'] = {[STATE_LOW] = {}, [STATE_HIGH] = {}},
201 console = true,
202 dnd_status = true,
203 dnd_message = "Debugging. Your messages may get eaten.",
204 }
205 cherry = "This is probably the first time, so:\n /dvn 2 to save your regular addon list\n /dvn 1 to save your development addon list\n /dvn to switch between the two\n /dvc to toggle print() frame"
206 end
207 db = DevianDB
208
209 if not db[PLAYER_REALM] then
210 db[PLAYER_REALM] = {[STATE_LOW] = {}, [STATE_HIGH] = {} }
211 if not cherry then
212 cherry = "This character didn't have an AddOn table."
213 end
214 end
215
216 -- inform the user if we have a virgin data table
217 if cherry then
218 D:Print(cherry)
219 end
220
221 -- replace print handler and make the original available in global if possible
222
223 CreateMessenger()
224 D.oldprint = getprinthandler()
225 if not _G.oldprint then
226 _G.oldprint = D.oldprint
227 end
228 setprinthandler(Message)
229 self:RegisterChatCommand("dvn", ScanAddOnList)
230 self:RegisterChatCommand("dvc", function(args)
231 db.console = (db.console == false) and true or false
232 if db.console then
233 DEVIAN_FRAME:Show()
234 else
235 DEVIAN_FRAME:Hide()
236 end
237 end)
238
239 print('Master! I am here.')
240 end