Mercurial > wow > devian
comparison Devian.lua @ 57:0d2967941745
localization internals
message prefix is forced to string before used on table lookups
| author | Nenue |
|---|---|
| date | Fri, 08 Jan 2016 10:15:09 -0500 |
| parents | 4b1b301cf8d4 |
| children | 0a9a6740ea5d |
comparison
equal
deleted
inserted
replaced
| 56:4b1b301cf8d4 | 57:0d2967941745 |
|---|---|
| 3 -- @project-revision@ @project-hash@ | 3 -- @project-revision@ @project-hash@ |
| 4 -- @file-revision@ @file-hash@ | 4 -- @file-revision@ @file-hash@ |
| 5 if not LibStub then | 5 if not LibStub then |
| 6 print('Something has happened...') | 6 print('Something has happened...') |
| 7 end | 7 end |
| 8 local MAJOR, MINOR = 'Devian-2.0', 'r@project-revision@' | |
| 8 Devian = LibStub("AceAddon-3.0"):NewAddon("Devian", "AceConsole-3.0", "AceEvent-3.0") | 9 Devian = LibStub("AceAddon-3.0"):NewAddon("Devian", "AceConsole-3.0", "AceEvent-3.0") |
| 9 local D = _G.Devian | 10 local D = _G.Devian |
| 10 D:SetDefaultModuleState(false) | 11 D:SetDefaultModuleState(false) |
| 11 | 12 D.L = {} |
| 13 setmetatable(D.L, {__index= function(t,k) return k end, __call = function(t,k,...) return string.format((t[k] or k) , ...) end}) | |
| 14 local L = D.L | |
| 12 local pairs, tostring, tonumber, ipairs, type = pairs, tostring, tonumber, ipairs, type | 15 local pairs, tostring, tonumber, ipairs, type = pairs, tostring, tonumber, ipairs, type |
| 13 local max, rand, format = math.max, math.random, string.format | 16 local max, rand, format = math.max, math.random, string.format |
| 14 local insert, wipe, concat = table.insert, table.wipe, table.concat | 17 local insert, wipe, concat = table.insert, table.wipe, table.concat |
| 15 local select, unpack = select, unpack | 18 local select, unpack = select, unpack |
| 16 local GetNumAddOns, GetAddOnInfo, GetAddOnEnableState, EnableAddOn = GetNumAddOns, GetAddOnInfo, GetAddOnEnableState, EnableAddOn | 19 local GetNumAddOns, GetAddOnInfo, GetAddOnEnableState, EnableAddOn = GetNumAddOns, GetAddOnInfo, GetAddOnEnableState, EnableAddOn |
| 17 local UnitName, DisableAddOn = UnitName, DisableAddOn | 20 local UnitName, DisableAddOn = UnitName, DisableAddOn |
| 18 local MAJOR, MINOR = 'Devian-2.0', 'r@project-revision@' | |
| 19 local MSG_NEED_DEV_MODE = 'Must be in development mode to use this function.' | |
| 20 local WORKSPACE_ON, WORKSPACE_OFF = 1, 2 | 21 local WORKSPACE_ON, WORKSPACE_OFF = 1, 2 |
| 21 local PLAYER_REALM = UnitName("player") .. '-' .. GetRealmName() | 22 local PLAYER_REALM = UnitName("player") .. '-' .. GetRealmName() |
| 22 local print = _G.print | 23 local print = _G.print |
| 23 local db | 24 local db |
| 24 local defaults = { | 25 local defaults = { |
| 97 end | 98 end |
| 98 local mode, tag, dest = unpack(args) | 99 local mode, tag, dest = unpack(args) |
| 99 | 100 |
| 100 | 101 |
| 101 -- no args, toggle ui | 102 -- no args, toggle ui |
| 102 if mode == 'dock' then | 103 if mode == 'stack' then |
| 103 if db.workspace == 1 then | 104 if db.workspace == 1 then |
| 104 D:Print('Must be in dev mode to use this.') | 105 return D:Print(L['Need devmode']) |
| 105 return | |
| 106 end | |
| 107 if #args <= 2 then | |
| 108 D:Print("Not enough arguments for dock command.") | |
| 109 return | |
| 110 end | |
| 111 | |
| 112 local target | |
| 113 local worklist = {} | |
| 114 for i = 2, #args do | |
| 115 local ch | |
| 116 local k = tostring(args[i]) | |
| 117 local j = tonumber(args[i]) | |
| 118 if db.channels[j] then | |
| 119 ch = db.channels[j] | |
| 120 elseif D.sig[k] then | |
| 121 ch = D.sig[k] | |
| 122 elseif D.sigID[k] then | |
| 123 ch = db.channels[D.sigID[k]] | |
| 124 elseif db.tags[k] and db.tags[k][1] then | |
| 125 ch = db.channels[db.tags[j][1]] | |
| 126 -- last resort | |
| 127 else | |
| 128 D:Print('No entry for argument #'..i..': '..tostring(args[i])) | |
| 129 return | |
| 130 end | |
| 131 --@debug@ | |
| 132 --print(i, '->', ch.index, '-', ch.signature)--@end-debug@ | |
| 133 if i > 2 then | |
| 134 insert(worklist, ch.index) | |
| 135 else | |
| 136 target = ch | |
| 137 | |
| 138 --@debug@ | |
| 139 --print('arg1', args[2], target)--@end-debug@ | |
| 140 end | |
| 141 end | |
| 142 D:Print("Docking |cFF88FFFF"..concat(worklist, "|r, |cFF88FFFF").."|r with |cFFFFFF00"..target.index..', '..target.signature.."|r.") | |
| 143 return D:DockFrame(target.index, unpack(worklist)) | |
| 144 | |
| 145 | |
| 146 elseif mode == 'stack' then | |
| 147 if db.workspace == 1 then | |
| 148 return D:Print(MSG_NEED_DEV_MODE) | |
| 149 end | 106 end |
| 150 return D:StackFrames() | 107 return D:StackFrames() |
| 151 elseif mode == 'grid' then | 108 elseif mode == 'grid' then |
| 152 if db.workspace == 1 then | 109 if db.workspace == 1 then |
| 153 return D:Print(MSG_NEED_DEV_MODE) | 110 return D:Print(L['Need devmode']) |
| 154 end | 111 end |
| 155 return D:DistributeFrames() | 112 return D:DistributeFrames() |
| 156 elseif mode == 'tag' then -- tagging | 113 elseif mode == 'tag' then -- tagging |
| 157 if db.workspace == 1 then | 114 if db.workspace == 1 then |
| 158 return D:Print(MSG_NEED_DEV_MODE) | 115 return D:Print(L['Need devmode']) |
| 159 end | 116 end |
| 160 | 117 |
| 161 local sig | 118 local sig |
| 162 if tag ~= nil and dest ~= nil then | 119 if tag ~= nil and dest ~= nil then |
| 163 --@debug@ | 120 --@debug@ |
| 179 | 136 |
| 180 -- make a new channel? | 137 -- make a new channel? |
| 181 local channel | 138 local channel |
| 182 if not D.db.channels[dest] then | 139 if not D.db.channels[dest] then |
| 183 dest = D.max_channel + 1 | 140 dest = D.max_channel + 1 |
| 184 D:Print('Created channel |cFF88FFFF'.. (sig and (dest..':'..sig) or dest ) .. '|r') | 141 D:Print(L('New channel created', sig and (dest..':'..sig) or dest )) |
| 185 channel = D:SetChannel(sig or tag,dest) | 142 channel = D:SetChannel(sig or tag,dest) |
| 186 else | 143 else |
| 187 | 144 |
| 188 channel = D.db.channels[dest] | 145 channel = D.db.channels[dest] |
| 189 end | 146 end |
| 194 db.tags[tag] = {} | 151 db.tags[tag] = {} |
| 195 end | 152 end |
| 196 | 153 |
| 197 if db.tags[tag][dest] then -- is tag set? | 154 if db.tags[tag][dest] then -- is tag set? |
| 198 db.tags[tag][dest] = nil | 155 db.tags[tag][dest] = nil |
| 199 D:Print('Hiding |cFF88FFFF'..tag..'|r messages in |cFFFFFF00'..db.channels[dest].index ..':'.. db.channels[dest].signature) | 156 D:Print(L('Tag removed from channel', tag, db.channels[dest].index, db.channels[dest].signature)) |
| 200 else | 157 else |
| 201 db.tags[tag][dest] = dest | 158 db.tags[tag][dest] = dest |
| 202 D:Print('Showing |cFF88FFFF'..tag..'|r messages in |cFFFFFF00'..db.channels[dest].index ..':'.. db.channels[dest].signature) | 159 D:Print(L('Tag added to channel', tag, db.channels[dest].index, db.channels[dest].signature)) |
| 203 end | 160 end |
| 204 D:UpdateDock() | 161 D:UpdateDock() |
| 205 else | 162 else |
| 206 D:Print('Usage: /dvn tag <prefix> <console name or number>') | 163 D:Print(L['Command tag help']) |
| 207 end | 164 end |
| 208 return | 165 return |
| 209 elseif tonumber(mode) ~= nil or mode == 'save' then | 166 elseif tonumber(mode) ~= nil or mode == 'save' then |
| 210 -- iterating for something | 167 -- iterating for something |
| 211 if mode == 'save' then | 168 if mode == 'save' then |
| 212 if tonumber(tag) == nil then | 169 if tonumber(tag) == nil then |
| 213 T:Print('Save ID is invalid:', tag) | 170 T:Print(L('Invalid ID from arg', tag)) |
| 214 end | 171 end |
| 215 list_state = tonumber(tag) | 172 list_state = tonumber(tag) |
| 216 else | 173 else |
| 217 list_state = tonumber(mode) | 174 list_state = tonumber(mode) |
| 218 db.workspace = list_state | 175 db.workspace = list_state |
| 222 | 179 |
| 223 end | 180 end |
| 224 elseif mode == nil then | 181 elseif mode == nil then |
| 225 list_state = (db.workspace == 1) and db.last_workspace or 1 | 182 list_state = (db.workspace == 1) and db.last_workspace or 1 |
| 226 db.workspace = list_state | 183 db.workspace = list_state |
| 227 db.load_message = "quick swapped workspace #"..list_state | |
| 228 else | 184 else |
| 229 return D:PrintHelp() | 185 return D:PrintHelp() |
| 230 end | 186 end |
| 231 | 187 |
| 232 -- start the iterating | 188 -- start the iterating |
| 275 | 231 |
| 276 end | 232 end |
| 277 end | 233 end |
| 278 | 234 |
| 279 if mode ~= 'save' then | 235 if mode ~= 'save' then |
| 280 --db.load_message = "AddOn profile ".. list_state .." was loaded." | 236 db.load_message = (mode == nil) and L("Toggled to profile", list_state) or L('Switched to profile number', list_state) |
| 281 ReloadUI() | 237 ReloadUI() |
| 282 else | 238 else |
| 283 D:Print('Profile #'.. (list_state)..' saved.') | 239 |
| 284 if list_state == 1 then | 240 if list_state == 1 then |
| 285 D:Print('This will be your main AddOn list.') | 241 D:Print(L['Profile main saved']) |
| 286 elseif list_state == db.default_list then | 242 else |
| 287 db.last_workspace = list_state | 243 db.last_workspace = list_state |
| 288 D:Print('This will be your default workspace') | 244 D:Print(L('Profile number saved', list_state, list_state)) |
| 289 end | 245 end |
| 290 end | 246 end |
| 291 end | 247 end |
| 292 | 248 |
| 293 | 249 |
| 299 -- @param ... Output contents. | 255 -- @param ... Output contents. |
| 300 local function Message(prefix, ...) | 256 local function Message(prefix, ...) |
| 301 if db.workspace == 1 then | 257 if db.workspace == 1 then |
| 302 return D.oldprint(prefix, ...) | 258 return D.oldprint(prefix, ...) |
| 303 end | 259 end |
| 304 | 260 prefix = tostring(prefix) |
| 305 if tostring(prefix) == nil then | 261 if prefix == nil then |
| 306 prefix = 'nil*' | 262 prefix = 'nil*' |
| 307 end | 263 end |
| 308 | 264 |
| 309 local sendq = {} | 265 local sendq = {} |
| 310 local tag, id, tagged | 266 local tag, id, tagged |
| 386 end | 342 end |
| 387 | 343 |
| 388 | 344 |
| 389 | 345 |
| 390 function D:OnEnable() | 346 function D:OnEnable() |
| 391 print(MAJOR, MINOR) | |
| 392 | 347 |
| 393 if db.unlisted and #db.unlisted > 0 then | 348 if db.unlisted and #db.unlisted > 0 then |
| 394 D:Print('New AddOns have been found since the last profile update: '.. concat(db.unlisted, ', ')) | 349 D:Print('New AddOns have been found since the last profile update: '.. concat(db.unlisted, ', ')) |
| 395 wipe(db.unlisted) | 350 wipe(db.unlisted) |
| 396 end | 351 end |
| 397 | 352 |
| 398 if db.workspace == 1 then | 353 if db.workspace == 1 then |
| 399 D:Print('Gameplay mode active (list #'..db.workspace..'). Print handling turned |cFFFFFF00OFF|r.') | 354 D:Print(L('Devian loaded on standby',MAJOR, MINOR)) |
| 400 else | 355 else |
| 401 D:Print('Development mode active (list #'..db.workspace..'). Print handling |cFF00FF00ON|r.') | 356 D:Print(L('Devian loaded in workspace', MAJOR, MINOR, db.workspace)) |
| 402 -- movement fading | 357 -- movement fading |
| 403 if db.movement_fade then | 358 if db.movement_fade then |
| 404 self:RegisterEvent('PLAYER_STARTED_MOVING', function() | 359 self:RegisterEvent('PLAYER_STARTED_MOVING', function() |
| 405 for k, v in pairs(self.console) do | 360 for k, v in pairs(self.console) do |
| 406 if v.enabled then | 361 if v.enabled then |
