comparison Devian.lua @ 86:6e27274da4d9

- /dvn rc resets the current workspace channels and tags - command argument parse code revised
author Nenue
date Tue, 26 Jul 2016 01:45:30 -0400
parents c85459c5bb16
children e80723841888
comparison
equal deleted inserted replaced
85:ee27780b9863 86:6e27274da4d9
132 132
133 D.InWorkspace = function () 133 D.InWorkspace = function ()
134 return db.profiles[db.current_profile].workspace 134 return db.profiles[db.current_profile].workspace
135 end 135 end
136 136
137 local profileTemplate = {
138 name = function(id, name) return name end,
139 workspace = function(id, name) return (id ~= 1) end,
140 current_channel = 1,
141 default_channel = 1,
142 num_channels = 1,
143 max_channel = 1, -- the highest created channel id
144 enabled = true, -- allow enabled consoles to appear
145 channels = {
146 {
147 index = 1,
148 signature = 'Main',
149 x = 100, y = 800,
150 height = 500, width = 600,
151 enabled = true
152 }
153 },
154 loadouts = {},
155 global = {},
156 tags = {},
157 char = {
158 [playerRealm] = {}
159 },
160 unlisted = {}
161 }
162
163 --- Applies complex template tables
164 -- If he value is a function, then it will invoke f(...) and use whatever gets returned
165 function D.DeepCopy(src, dest, ...)
166
167 for k,v in pairs(src) do
168 if not dest[k] then
169 oldprint('Rebuilding conf value', k)
170 if type(v) == 'table' then
171 dest[k] = {}
172 D.DeepCopy(v, dest[k], ...)
173
174 else
175 if type(v) == 'function' then
176 v = v(...)
177 end
178 dest[k] = v
179 end
180 end
181 end
182 end
183
137 D.Profile = function (id, name) 184 D.Profile = function (id, name)
138 185
139 if name and not id and db.profilesName[name] then 186 if name and not id and db.profilesName[name] then
140 id = db.profilesName[name] 187 id = db.profilesName[name]
141 print('ID located by name, |cFF00FF00'..name..'|r is |cFFFFFF00'.. id..'|r') 188 print('ID located by name, |cFF00FF00'..name..'|r is |cFFFFFF00'.. id..'|r')
156 newName = prefix .. i 203 newName = prefix .. i
157 end 204 end
158 name = newName 205 name = newName
159 print('Generated profile name: |cFF00FF00'..newName..'|r') 206 print('Generated profile name: |cFF00FF00'..newName..'|r')
160 end 207 end
208
209
210
161 print('Creating profile') 211 print('Creating profile')
162 db.profilesName[name] = id 212 db.profilesName[name] = id
163 db.profiles[id] = { 213 db.profiles[id] = {}
164 name = name, 214 end
165 workspace = (id ~= 1), 215
166 current_channel = 1, 216
167 default_channel = 1,
168 num_channels = 1,
169 max_channel = 1, -- the highest created channel id
170 enabled = true, -- allow enabled consoles to appear
171 channels = {
172 {
173 index = 1,
174 signature = 'Main',
175 x = 100, y = 800,
176 height = 500, width = 600,
177 enabled = true
178 }
179 },
180 loadouts = {},
181 global = {},
182 tags = {},
183 char = {
184 [playerRealm] = {}
185 },
186 unlisted = {}
187 }
188 end
189 217
190 D.currentProfile = db.profiles[id] 218 D.currentProfile = db.profiles[id]
191 currentProfile = D.currentProfile 219 currentProfile = D.currentProfile
220
221 D.DeepCopy(profileTemplate, currentProfile, id, name)
222
223
192 currentProfile.char[playerRealm] = currentProfile.char[playerRealm] or {} 224 currentProfile.char[playerRealm] = currentProfile.char[playerRealm] or {}
193 if currentProfile.workspace then 225 if currentProfile.workspace then
194 DEVIAN_WORKSPACE = true 226 DEVIAN_WORKSPACE = true
195 setprinthandler(D.Message) 227 setprinthandler(D.Message)
196 else 228 else
214 246
215 return id, name 247 return id, name
216 end 248 end
217 249
218 local targetGlobal, targetChar 250 local targetGlobal, targetChar
219 D.Command = function (self, cmd, ...) 251 D.Command = function (cmd)
220 local list_id, scan_func, reload 252 local list_id, scan_func, reload
253
221 local args = {} 254 local args = {}
222 local arg, n = D:GetArgs(cmd, 1) 255 if cmd then
223 while arg do 256 local i, j = 0, 0
224 insert(args, arg) 257 repeat
225 arg, n = D:GetArgs(cmd,1,n) 258 i, j = cmd:find("%S+", j+1)
259 if i and j then
260 tinsert(args, cmd:sub(i, j))
261 end
262
263 until not(i or j)
226 end 264 end
227 local mode, tag, dest = unpack(args) 265 local mode, tag, dest = unpack(args)
228 266
267
229 -- no args, toggle ui 268 -- no args, toggle ui
230 if mode == 'stack' then 269 if mode == 'rc' then
270 return D.ResetChannels(self, tag)
271 elseif mode == 'stack' then
231 return D:StackFrames() 272 return D:StackFrames()
232 elseif mode == 'grid' then 273 elseif mode == 'grid' then
233 return D:DistributeFrames() 274 return D:DistributeFrames()
234 elseif mode == 'tag' then -- tagging 275 elseif mode == 'tag' then -- tagging
235 return D.Tag(self, tag, dest) 276 return D.Tag(self, tag, dest)
376 else 417 else
377 D:Print(L['Command tag help']) 418 D:Print(L['Command tag help'])
378 end 419 end
379 end 420 end
380 421
422 D.ResetChannels = function(self, profile)
423 currentProfile.current_channel = 1
424 currentProfile.primary_channel = 1
425 currentProfile.channels = {}
426 D.DeepCopy(profileTemplate.channels, currentProfile.channels)
427 currentProfile.tags = {}
428 D.LoadMessage('Profile reset.')
429 ReloadUI()
430 end
431
381 D.New = function(self, tag) 432 D.New = function(self, tag)
382 if tag and not self.sigID[tag] then 433 if tag and not self.sigID[tag] then
383 local id = D.max_channel + 1 434 local id = D.max_channel + 1
384 D.SetChannel(tag, id) 435 D.SetChannel(tag, id)
385 end 436 end
447 end 498 end
448 499
449 -- color me timbers 500 -- color me timbers
450 local pcolor 501 local pcolor
451 if (not db.tagcolor[prefix]) and byName then 502 if (not db.tagcolor[prefix]) and byName then
452 if prefix:match('^%d+%.%d+$') then 503 -- numbers, use white
504 if prefix:match('^%d+%.%d+') then
453 pcolor = 'FFFFFF' 505 pcolor = 'FFFFFF'
454 else 506 else
455 local c = { 507 local c = {
456 rand(64,255), rand(64,255), rand(64,255) 508 rand(64,255), rand(64,255), rand(64,255)
457 } 509 }
562 ['cleandvn'] = "SetDefaultsAll", 614 ['cleandvn'] = "SetDefaultsAll",
563 ['resetdvn'] = "SetDefaults", 615 ['resetdvn'] = "SetDefaults",
564 ['dvg'] = "ConfigCommand" 616 ['dvg'] = "ConfigCommand"
565 } 617 }
566 for cmd, func in pairs(cmdlist) do 618 for cmd, func in pairs(cmdlist) do
567 self:RegisterChatCommand(cmd, func, true) 619 _G['SLASH_' .. cmd:upper() .. '1'] = "/"..cmd
620 SlashCmdList[cmd:upper()] = D[func]
568 end 621 end
569 end 622 end
570 623
571 function D:OnInitialize() 624 function D:OnInitialize()
572 L = D.L 625 L = D.L
591 --- initialize the current profile 644 --- initialize the current profile
592 local id, name = D.Profile(db.current_profile or 1) 645 local id, name = D.Profile(db.current_profile or 1)
593 D:Print('Using profile |cFFFFFF00'.. id ..'|r: |cFF00FF00'..currentProfile.name..'|r') 646 D:Print('Using profile |cFFFFFF00'.. id ..'|r: |cFF00FF00'..currentProfile.name..'|r')
594 if currentProfile.workspace then 647 if currentProfile.workspace then
595 D:Print('Workspace: '.. (#currentProfile.channels) .. ' channels, ' .. #currentProfile.tags .. ' tags.') 648 D:Print('Workspace: '.. (#currentProfile.channels) .. ' channels, ' .. #currentProfile.tags .. ' tags.')
596 D:Print('Default channel: |cFFFFFF00'..currentProfile.default_channel..'|r: |cFF00FFFF'.. D.channels[currentProfile.default_channel].signature..'|r') 649 if D.channels[currentProfile.default_channel] then
597 end 650 D:Print('Default channel: |cFFFFFF00'..currentProfile.default_channel..'|r: |cFF00FFFF'.. D.channels[currentProfile.default_channel].signature..'|r')
651 end
652 end
653
598 654
599 for i, cinfo in pairs(D.channels) do 655 for i, cinfo in pairs(D.channels) do
600 i = tonumber(i) 656 i = tonumber(i)
601 if not D.primary_channel then 657 if not D.primary_channel then
602 D.primary_channel = i 658 D.primary_channel = i
603 end 659 end
604 D:SetChannel(cinfo, i) 660 D:SetChannel(cinfo, i)
605 D.num_channels = D.num_channels + 1 661 D.num_channels = D.num_channels + 1
606 end 662 end
663 D.primary_channel = D.primary_channel or 1
607 664
608 D.max_channel = max(D.max_channel, currentProfile.max_channel) 665 D.max_channel = max(D.max_channel, currentProfile.max_channel)
609 if currentProfile.max_channel < D.max_channel then 666 if currentProfile.max_channel < D.max_channel then
610 for i = currentProfile.max_channel, D.max_channel do 667 for i = currentProfile.max_channel, D.max_channel do
611 D.console[i]:Hide() 668 D.console[i]:Hide()