Mercurial > wow > devian
diff 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 |
line wrap: on
line diff
--- a/Devian.lua Tue Jul 19 13:50:56 2016 -0400 +++ b/Devian.lua Tue Jul 26 01:45:30 2016 -0400 @@ -134,6 +134,53 @@ return db.profiles[db.current_profile].workspace end +local profileTemplate = { + name = function(id, name) return name end, + workspace = function(id, name) return (id ~= 1) end, + current_channel = 1, + default_channel = 1, + num_channels = 1, + max_channel = 1, -- the highest created channel id + enabled = true, -- allow enabled consoles to appear + channels = { + { + index = 1, + signature = 'Main', + x = 100, y = 800, + height = 500, width = 600, + enabled = true + } + }, + loadouts = {}, + global = {}, + tags = {}, + char = { + [playerRealm] = {} + }, + unlisted = {} +} + +--- Applies complex template tables +-- If he value is a function, then it will invoke f(...) and use whatever gets returned +function D.DeepCopy(src, dest, ...) + + for k,v in pairs(src) do + if not dest[k] then + oldprint('Rebuilding conf value', k) + if type(v) == 'table' then + dest[k] = {} + D.DeepCopy(v, dest[k], ...) + + else + if type(v) == 'function' then + v = v(...) + end + dest[k] = v + end + end + end +end + D.Profile = function (id, name) if name and not id and db.profilesName[name] then @@ -158,37 +205,22 @@ name = newName print('Generated profile name: |cFF00FF00'..newName..'|r') end + + + print('Creating profile') db.profilesName[name] = id - db.profiles[id] = { - name = name, - workspace = (id ~= 1), - current_channel = 1, - default_channel = 1, - num_channels = 1, - max_channel = 1, -- the highest created channel id - enabled = true, -- allow enabled consoles to appear - channels = { - { - index = 1, - signature = 'Main', - x = 100, y = 800, - height = 500, width = 600, - enabled = true - } - }, - loadouts = {}, - global = {}, - tags = {}, - char = { - [playerRealm] = {} - }, - unlisted = {} - } + db.profiles[id] = {} end + + D.currentProfile = db.profiles[id] currentProfile = D.currentProfile + + D.DeepCopy(profileTemplate, currentProfile, id, name) + + currentProfile.char[playerRealm] = currentProfile.char[playerRealm] or {} if currentProfile.workspace then DEVIAN_WORKSPACE = true @@ -216,18 +248,27 @@ end local targetGlobal, targetChar -D.Command = function (self, cmd, ...) +D.Command = function (cmd) local list_id, scan_func, reload + local args = {} - local arg, n = D:GetArgs(cmd, 1) - while arg do - insert(args, arg) - arg, n = D:GetArgs(cmd,1,n) + if cmd then + local i, j = 0, 0 + repeat + i, j = cmd:find("%S+", j+1) + if i and j then + tinsert(args, cmd:sub(i, j)) + end + + until not(i or j) end local mode, tag, dest = unpack(args) + -- no args, toggle ui - if mode == 'stack' then + if mode == 'rc' then + return D.ResetChannels(self, tag) + elseif mode == 'stack' then return D:StackFrames() elseif mode == 'grid' then return D:DistributeFrames() @@ -378,6 +419,16 @@ end end +D.ResetChannels = function(self, profile) + currentProfile.current_channel = 1 + currentProfile.primary_channel = 1 + currentProfile.channels = {} + D.DeepCopy(profileTemplate.channels, currentProfile.channels) + currentProfile.tags = {} + D.LoadMessage('Profile reset.') + ReloadUI() +end + D.New = function(self, tag) if tag and not self.sigID[tag] then local id = D.max_channel + 1 @@ -449,7 +500,8 @@ -- color me timbers local pcolor if (not db.tagcolor[prefix]) and byName then - if prefix:match('^%d+%.%d+$') then + -- numbers, use white + if prefix:match('^%d+%.%d+') then pcolor = 'FFFFFF' else local c = { @@ -564,7 +616,8 @@ ['dvg'] = "ConfigCommand" } for cmd, func in pairs(cmdlist) do - self:RegisterChatCommand(cmd, func, true) + _G['SLASH_' .. cmd:upper() .. '1'] = "/"..cmd + SlashCmdList[cmd:upper()] = D[func] end end @@ -593,9 +646,12 @@ D:Print('Using profile |cFFFFFF00'.. id ..'|r: |cFF00FF00'..currentProfile.name..'|r') if currentProfile.workspace then D:Print('Workspace: '.. (#currentProfile.channels) .. ' channels, ' .. #currentProfile.tags .. ' tags.') - D:Print('Default channel: |cFFFFFF00'..currentProfile.default_channel..'|r: |cFF00FFFF'.. D.channels[currentProfile.default_channel].signature..'|r') + if D.channels[currentProfile.default_channel] then + D:Print('Default channel: |cFFFFFF00'..currentProfile.default_channel..'|r: |cFF00FFFF'.. D.channels[currentProfile.default_channel].signature..'|r') + end end + for i, cinfo in pairs(D.channels) do i = tonumber(i) if not D.primary_channel then @@ -604,6 +660,7 @@ D:SetChannel(cinfo, i) D.num_channels = D.num_channels + 1 end + D.primary_channel = D.primary_channel or 1 D.max_channel = max(D.max_channel, currentProfile.max_channel) if currentProfile.max_channel < D.max_channel then