annotate libs/AceConsole-2.0/AceConsole-2.0.lua @ 1:c11ca1d8ed91

Version 0.1
author Flick <flickerstreak@gmail.com>
date Tue, 20 Mar 2007 21:03:57 +0000
parents
children
rev   line source
flickerstreak@1 1 --[[
flickerstreak@1 2 Name: AceConsole-2.0
flickerstreak@1 3 Revision: $Rev: 19865 $
flickerstreak@1 4 Developed by: The Ace Development Team (http://www.wowace.com/index.php/The_Ace_Development_Team)
flickerstreak@1 5 Inspired By: Ace 1.x by Turan (turan@gryphon.com)
flickerstreak@1 6 Website: http://www.wowace.com/
flickerstreak@1 7 Documentation: http://www.wowace.com/index.php/AceConsole-2.0
flickerstreak@1 8 SVN: http://svn.wowace.com/root/trunk/Ace2/AceConsole-2.0
flickerstreak@1 9 Description: Mixin to allow for input/output capabilities. This uses the
flickerstreak@1 10 AceOptions data table format to determine input.
flickerstreak@1 11 http://wiki.wowace.com/index.php/AceOptions_data_table
flickerstreak@1 12 Dependencies: AceLibrary, AceOO-2.0
flickerstreak@1 13 ]]
flickerstreak@1 14
flickerstreak@1 15 local MAJOR_VERSION = "AceConsole-2.0"
flickerstreak@1 16 local MINOR_VERSION = "$Revision: 19865 $"
flickerstreak@1 17
flickerstreak@1 18 if not AceLibrary then error(MAJOR_VERSION .. " requires AceLibrary.") end
flickerstreak@1 19 if not AceLibrary:IsNewVersion(MAJOR_VERSION, MINOR_VERSION) then return end
flickerstreak@1 20
flickerstreak@1 21 if not AceLibrary:HasInstance("AceOO-2.0") then error(MAJOR_VERSION .. " requires AceOO-2.0.") end
flickerstreak@1 22
flickerstreak@1 23 local MAP_ONOFF, USAGE, IS_CURRENTLY_SET_TO, IS_NOW_SET_TO, IS_NOT_A_VALID_OPTION_FOR, IS_NOT_A_VALID_VALUE_FOR, NO_OPTIONS_AVAILABLE, OPTION_HANDLER_NOT_FOUND, OPTION_HANDLER_NOT_VALID, OPTION_IS_DISABLED, KEYBINDING_USAGE
flickerstreak@1 24 if GetLocale() == "deDE" then
flickerstreak@1 25 MAP_ONOFF = { [false] = "|cffff0000Aus|r", [true] = "|cff00ff00An|r" }
flickerstreak@1 26 USAGE = "Benutzung"
flickerstreak@1 27 IS_CURRENTLY_SET_TO = "|cffffff7f%s|r steht momentan auf |cffffff7f[|r%s|cffffff7f]|r"
flickerstreak@1 28 IS_NOW_SET_TO = "|cffffff7f%s|r ist nun auf |cffffff7f[|r%s|cffffff7f]|r gesetzt"
flickerstreak@1 29 IS_NOT_A_VALID_OPTION_FOR = "[|cffffff7f%s|r] ist keine g\195\188ltige Option f\195\188r |cffffff7f%s|r"
flickerstreak@1 30 IS_NOT_A_VALID_VALUE_FOR = "[|cffffff7f%s|r] ist kein g\195\188ltiger Wert f\195\188r |cffffff7f%s|r"
flickerstreak@1 31 NO_OPTIONS_AVAILABLE = "Keine Optionen verfügbar"
flickerstreak@1 32 OPTION_HANDLER_NOT_FOUND = "Optionen handler |cffffff7f%q|r nicht gefunden."
flickerstreak@1 33 OPTION_HANDLER_NOT_VALID = "Optionen handler nicht g\195\188ltig."
flickerstreak@1 34 OPTION_IS_DISABLED = "Option |cffffff7f%s|r deaktiviert."
flickerstreak@1 35 KEYBINDING_USAGE = "<ALT-CTRL-SHIFT-KEY>" -- fix
flickerstreak@1 36 elseif GetLocale() == "frFR" then
flickerstreak@1 37 MAP_ONOFF = { [false] = "|cffff0000Inactif|r", [true] = "|cff00ff00Actif|r" }
flickerstreak@1 38 USAGE = "Utilisation"
flickerstreak@1 39 IS_CURRENTLY_SET_TO = "|cffffff7f%s|r est actuellement positionn\195\169 sur |cffffff7f[|r%s|cffffff7f]|r"
flickerstreak@1 40 IS_NOW_SET_TO = "|cffffff7f%s|r est maintenant positionn\195\169 sur |cffffff7f[|r%s|cffffff7f]|r"
flickerstreak@1 41 IS_NOT_A_VALID_OPTION_FOR = "[|cffffff7f%s|r] n'est pas une option valide pour |cffffff7f%s|r"
flickerstreak@1 42 IS_NOT_A_VALID_VALUE_FOR = "[|cffffff7f%s|r] n'est pas une valeur valide pour |cffffff7f%s|r"
flickerstreak@1 43 NO_OPTIONS_AVAILABLE = "Pas d'options disponibles"
flickerstreak@1 44 OPTION_HANDLER_NOT_FOUND = "Le gestionnaire d'option |cffffff7f%q|r n'a pas \195\169t\195\169 trouv\195\169."
flickerstreak@1 45 OPTION_HANDLER_NOT_VALID = "Le gestionnaire d'option n'est pas valide."
flickerstreak@1 46 OPTION_IS_DISABLED = "L'option |cffffff7f%s|r est d\195\169sactiv\195\169e."
flickerstreak@1 47 KEYBINDING_USAGE = "<ALT-CTRL-SHIFT-KEY>" -- fix
flickerstreak@1 48 elseif GetLocale() == "koKR" then
flickerstreak@1 49 MAP_ONOFF = { [false] = "|cffff0000끔|r", [true] = "|cff00ff00켬|r" }
flickerstreak@1 50 USAGE = "사용법"
flickerstreak@1 51 IS_CURRENTLY_SET_TO = "|cffffff7f%s|r|1은;는; 현재 상태는 |cffffff7f[|r%s|cffffff7f]|r|1으로;로; 설정되어 있습니다"
flickerstreak@1 52 IS_NOW_SET_TO = "|cffffff7f%s|r|1을;를; |cffffff7f[|r%s|cffffff7f]|r 상태로 변경합니다"
flickerstreak@1 53 IS_NOT_A_VALID_OPTION_FOR = "[|cffffff7f%s|r]|1은;는; |cffffff7f%s|r에서 사용불가능한 설정입니다"
flickerstreak@1 54 IS_NOT_A_VALID_VALUE_FOR = "[|cffffff7f%s|r]|1은;는; |cffffff7f%s|r에서 사용불가능한 설정값입니다"
flickerstreak@1 55 NO_OPTIONS_AVAILABLE = "가능한 설정이 없습니다"
flickerstreak@1 56 OPTION_HANDLER_NOT_FOUND = "설정 조정값인 |cffffff7f%q|r|1을;를; 찾지 못했습니다."
flickerstreak@1 57 OPTION_HANDLER_NOT_VALID = "설정 조정값이 올바르지 않습니다."
flickerstreak@1 58 OPTION_IS_DISABLED = "|cffffff7f%s|r 설정은 사용할 수 없습니다."
flickerstreak@1 59 KEYBINDING_USAGE = "<ALT-CTRL-SHIFT-KEY>" -- fix
flickerstreak@1 60 elseif GetLocale() == "zhCN" then
flickerstreak@1 61 MAP_ONOFF = { [false] = "|cffff0000\229\133\179\233\151\173|r", [true] = "|cff00ff00\229\188\128\229\144\175|r" }
flickerstreak@1 62 USAGE = "\231\148\168\230\179\149"
flickerstreak@1 63 IS_CURRENTLY_SET_TO = "|cffffff7f%s|r \229\189\147\229\137\141\232\162\171\232\174\190\231\189\174 |cffffff7f[|r%s|cffffff7f]|r"
flickerstreak@1 64 IS_NOW_SET_TO = "|cffffff7f%s|r \231\142\176\229\156\168\232\162\171\232\174\190\231\189\174\228\184\186 |cffffff7f[|r%s|cffffff7f]|r"
flickerstreak@1 65 IS_NOT_A_VALID_OPTION_FOR = "[|cffffff7f%s|r] \228\184\141\230\152\175\228\184\128\228\184\170\230\156\137\230\149\136\231\154\132\233\128\137\233\161\185 \228\184\186 |cffffff7f%s|r"
flickerstreak@1 66 IS_NOT_A_VALID_VALUE_FOR = "[|cffffff7f%s|r] \228\184\141\230\152\175\228\184\128\228\184\170\230\156\137\230\149\136\229\128\188 \228\184\186 |cffffff7f%s|r"
flickerstreak@1 67 NO_OPTIONS_AVAILABLE = "\230\178\161\230\156\137\233\128\137\233\161\185\229\143\175\231\148\168"
flickerstreak@1 68 OPTION_HANDLER_NOT_FOUND = "\233\128\137\233\161\185\229\164\132\231\144\134\231\168\139\229\186\143 |cffffff7f%q|r \230\178\161\230\159\165\230\137\190."
flickerstreak@1 69 OPTION_HANDLER_NOT_VALID = "\233\128\137\233\161\185\229\164\132\231\144\134\231\168\139\229\186\143 \230\151\160\230\149\136."
flickerstreak@1 70 OPTION_IS_DISABLED = "\233\128\137\233\161\185 |cffffff7f%s|r \228\184\141\229\174\140\230\149\180."
flickerstreak@1 71 KEYBINDING_USAGE = "<ALT-CTRL-SHIFT-KEY>" -- fix
flickerstreak@1 72 elseif GetLocale() == "zhTW" then
flickerstreak@1 73 MAP_ONOFF = { [false] = "|cffff0000關閉|r", [true] = "|cff00ff00開啟|r" }
flickerstreak@1 74 USAGE = "用法"
flickerstreak@1 75 IS_CURRENTLY_SET_TO = "|cffffff7f%s|r 目前的設定為 |cffffff7f[|r%s|cffffff7f]|r"
flickerstreak@1 76 IS_NOW_SET_TO = "|cffffff7f%s|r 現在被設定為 |cffffff7f[|r%s|cffffff7f]|r"
flickerstreak@1 77 IS_NOT_A_VALID_OPTION_FOR = "[|cffffff7f%s|r] 是一個不符合規定的選項,對 |cffffff7f%s|r"
flickerstreak@1 78 IS_NOT_A_VALID_VALUE_FOR = "[|cffffff7f%s|r] 是一個不符合規定的數值,對 |cffffff7f%s|r"
flickerstreak@1 79 NO_OPTIONS_AVAILABLE = "沒有可用的選項處理器。"
flickerstreak@1 80 OPTION_HANDLER_NOT_FOUND = "找不到 |cffffff7f%q|r 選項處理器。"
flickerstreak@1 81 OPTION_HANDLER_NOT_VALID = "選項處理器不符合規定。"
flickerstreak@1 82 OPTION_IS_DISABLED = "|cffffff7f%s|r 已被停用。"
flickerstreak@1 83 KEYBINDING_USAGE = "<ALT-CTRL-SHIFT-KEY>" -- fix
flickerstreak@1 84 else -- enUS
flickerstreak@1 85 MAP_ONOFF = { [false] = "|cffff0000Off|r", [true] = "|cff00ff00On|r" }
flickerstreak@1 86 USAGE = "Usage"
flickerstreak@1 87 IS_CURRENTLY_SET_TO = "|cffffff7f%s|r is currently set to |cffffff7f[|r%s|cffffff7f]|r"
flickerstreak@1 88 IS_NOW_SET_TO = "|cffffff7f%s|r is now set to |cffffff7f[|r%s|cffffff7f]|r"
flickerstreak@1 89 IS_NOT_A_VALID_OPTION_FOR = "[|cffffff7f%s|r] is not a valid option for |cffffff7f%s|r"
flickerstreak@1 90 IS_NOT_A_VALID_VALUE_FOR = "[|cffffff7f%s|r] is not a valid value for |cffffff7f%s|r"
flickerstreak@1 91 NO_OPTIONS_AVAILABLE = "No options available"
flickerstreak@1 92 OPTION_HANDLER_NOT_FOUND = "Option handler |cffffff7f%q|r not found."
flickerstreak@1 93 OPTION_HANDLER_NOT_VALID = "Option handler not valid."
flickerstreak@1 94 OPTION_IS_DISABLED = "Option |cffffff7f%s|r is disabled."
flickerstreak@1 95 KEYBINDING_USAGE = "<ALT-CTRL-SHIFT-KEY>"
flickerstreak@1 96 end
flickerstreak@1 97
flickerstreak@1 98 local NONE = NONE or "None"
flickerstreak@1 99
flickerstreak@1 100 local AceOO = AceLibrary("AceOO-2.0")
flickerstreak@1 101 local AceEvent
flickerstreak@1 102
flickerstreak@1 103 local AceConsole = AceOO.Mixin { "Print", "PrintComma", "CustomPrint", "RegisterChatCommand" }
flickerstreak@1 104 local Dewdrop
flickerstreak@1 105
flickerstreak@1 106 local _G = getfenv(0)
flickerstreak@1 107
flickerstreak@1 108 local function print(text, name, r, g, b, frame, delay)
flickerstreak@1 109 if not text or text:len() == 0 then
flickerstreak@1 110 text = " "
flickerstreak@1 111 end
flickerstreak@1 112 if not name or name == AceConsole then
flickerstreak@1 113 (frame or DEFAULT_CHAT_FRAME):AddMessage(text, r, g, b, nil, delay or 5)
flickerstreak@1 114 else
flickerstreak@1 115 (frame or DEFAULT_CHAT_FRAME):AddMessage("|cffffff78" .. tostring(name) .. ":|r " .. text, r, g, b, nil, delay or 5)
flickerstreak@1 116 end
flickerstreak@1 117 end
flickerstreak@1 118
flickerstreak@1 119 local real_tostring = tostring
flickerstreak@1 120
flickerstreak@1 121 local function tostring(t)
flickerstreak@1 122 if type(t) == "table" then
flickerstreak@1 123 if type(rawget(t, 0)) == "userdata" and type(t.GetObjectType) == "function" then
flickerstreak@1 124 return string.format("<%s:%s>", t:GetObjectType(), t:GetName() or "(anon)")
flickerstreak@1 125 end
flickerstreak@1 126 end
flickerstreak@1 127 return real_tostring(t)
flickerstreak@1 128 end
flickerstreak@1 129
flickerstreak@1 130 local function _tostring(...)
flickerstreak@1 131 if select('#', ...) < 1 then
flickerstreak@1 132 return
flickerstreak@1 133 end
flickerstreak@1 134 return tostring((...)), _tostring(select(2, ...))
flickerstreak@1 135 end
flickerstreak@1 136 function AceConsole:CustomPrint(r, g, b, frame, delay, connector, a1, ...)
flickerstreak@1 137 if tostring(a1):find("%%") and select('#', ...) >= 1 then
flickerstreak@1 138 local success, text = pcall(string.format, _tostring(a1, ...))
flickerstreak@1 139 if success then
flickerstreak@1 140 print(text, self, r, g, b, frame or self.printFrame, delay)
flickerstreak@1 141 return
flickerstreak@1 142 end
flickerstreak@1 143 end
flickerstreak@1 144 print((connector or " "):join(_tostring(a1, ...)), self, r, g, b, frame or self.printFrame, delay)
flickerstreak@1 145 end
flickerstreak@1 146
flickerstreak@1 147 function AceConsole:Print(...)
flickerstreak@1 148 return AceConsole.CustomPrint(self, nil, nil, nil, nil, nil, " ", ...)
flickerstreak@1 149 end
flickerstreak@1 150
flickerstreak@1 151 function AceConsole:PrintComma(...)
flickerstreak@1 152 return AceConsole.CustomPrint(self, nil, nil, nil, nil, nil, ", ", ...)
flickerstreak@1 153 end
flickerstreak@1 154
flickerstreak@1 155 local work
flickerstreak@1 156 local argwork
flickerstreak@1 157
flickerstreak@1 158 local function findTableLevel(self, options, chat, text, index, passTable)
flickerstreak@1 159 if not index then
flickerstreak@1 160 index = 1
flickerstreak@1 161 if work then
flickerstreak@1 162 for k,v in pairs(work) do
flickerstreak@1 163 work[k] = nil
flickerstreak@1 164 end
flickerstreak@1 165 for k,v in pairs(argwork) do
flickerstreak@1 166 argwork[k] = nil
flickerstreak@1 167 end
flickerstreak@1 168 else
flickerstreak@1 169 work = {}
flickerstreak@1 170 argwork = {}
flickerstreak@1 171 end
flickerstreak@1 172 local len = text:len()
flickerstreak@1 173 local count
flickerstreak@1 174 repeat
flickerstreak@1 175 text, count = text:gsub("(|cff%x%x%x%x%x%x|Hitem:%d-:%d-:%d-:%d-|h%[[^%]]-) (.-%]|h|r)", "%1\001%2")
flickerstreak@1 176 until count == 0
flickerstreak@1 177 text = text:gsub("(%]|h|r)(|cff%x%x%x%x%x%x|Hitem:%d-:%d-:%d-:%d-|h%[)", "%1 %2")
flickerstreak@1 178 for token in text:gmatch("([^%s]+)") do
flickerstreak@1 179 local token = token
flickerstreak@1 180 local num = tonumber(token)
flickerstreak@1 181 if num then
flickerstreak@1 182 token = num
flickerstreak@1 183 else
flickerstreak@1 184 token = token:gsub("\001", " ")
flickerstreak@1 185 end
flickerstreak@1 186 table.insert(work, token)
flickerstreak@1 187 end
flickerstreak@1 188 end
flickerstreak@1 189
flickerstreak@1 190 local path = chat
flickerstreak@1 191 for i = 1, index - 1 do
flickerstreak@1 192 path = path .. " " .. tostring(work[i])
flickerstreak@1 193 end
flickerstreak@1 194
flickerstreak@1 195 if type(options.args) == "table" then
flickerstreak@1 196 local disabled, hidden = options.disabled, options.cmdHidden or options.hidden
flickerstreak@1 197 if hidden then
flickerstreak@1 198 if type(hidden) == "function" then
flickerstreak@1 199 hidden = hidden()
flickerstreak@1 200 elseif type(hidden) == "string" then
flickerstreak@1 201 local handler = options.handler or self
flickerstreak@1 202 local f = hidden
flickerstreak@1 203 local neg = f:match("^~(.-)$")
flickerstreak@1 204 if neg then
flickerstreak@1 205 f = neg
flickerstreak@1 206 end
flickerstreak@1 207 if type(handler[f]) ~= "function" then
flickerstreak@1 208 AceConsole:error("%s: %s", handler, string.format(OPTION_HANDLER_NOT_FOUND, f))
flickerstreak@1 209 end
flickerstreak@1 210 hidden = handler[f](handler)
flickerstreak@1 211 if neg then
flickerstreak@1 212 hidden = not hidden
flickerstreak@1 213 end
flickerstreak@1 214 end
flickerstreak@1 215 end
flickerstreak@1 216 if hidden then
flickerstreak@1 217 disabled = true
flickerstreak@1 218 elseif disabled then
flickerstreak@1 219 if type(disabled) == "function" then
flickerstreak@1 220 disabled = disabled()
flickerstreak@1 221 elseif type(disabled) == "string" then
flickerstreak@1 222 local handler = options.handler or self
flickerstreak@1 223 local f = disabled
flickerstreak@1 224 local neg = f:match("^~(.-)$")
flickerstreak@1 225 if neg then
flickerstreak@1 226 f = neg
flickerstreak@1 227 end
flickerstreak@1 228 if type(handler[f]) ~= "function" then
flickerstreak@1 229 AceConsole:error("%s: %s", handler, string.format(OPTION_HANDLER_NOT_FOUND, f))
flickerstreak@1 230 end
flickerstreak@1 231 disabled = handler[f](handler)
flickerstreak@1 232 if neg then
flickerstreak@1 233 disabled = not disabled
flickerstreak@1 234 end
flickerstreak@1 235 end
flickerstreak@1 236 end
flickerstreak@1 237 if not disabled then
flickerstreak@1 238 local next = work[index] and work[index]:lower()
flickerstreak@1 239 if next then
flickerstreak@1 240 for k,v in pairs(options.args) do
flickerstreak@1 241 local good = false
flickerstreak@1 242 if k:lower() == next then
flickerstreak@1 243 good = true
flickerstreak@1 244 elseif type(v.aliases) == "table" then
flickerstreak@1 245 for _,alias in ipairs(v.aliases) do
flickerstreak@1 246 if alias:lower() == next then
flickerstreak@1 247 good = true
flickerstreak@1 248 break
flickerstreak@1 249 end
flickerstreak@1 250 end
flickerstreak@1 251 elseif type(v.aliases) == "string" and v.aliases:lower() == next then
flickerstreak@1 252 good = true
flickerstreak@1 253 end
flickerstreak@1 254 if good then
flickerstreak@1 255 return findTableLevel(options.handler or self, v, chat, text, index + 1, options.pass and options or nil)
flickerstreak@1 256 end
flickerstreak@1 257 end
flickerstreak@1 258 end
flickerstreak@1 259 end
flickerstreak@1 260 end
flickerstreak@1 261 for i = index, #work do
flickerstreak@1 262 table.insert(argwork, work[i])
flickerstreak@1 263 end
flickerstreak@1 264 return options, path, argwork, options.handler or self, passTable, passTable and work[index - 1]
flickerstreak@1 265 end
flickerstreak@1 266
flickerstreak@1 267 local function validateOptionsMethods(self, options, position)
flickerstreak@1 268 if type(options) ~= "table" then
flickerstreak@1 269 return "Options must be a table.", position
flickerstreak@1 270 end
flickerstreak@1 271 self = options.handler or self
flickerstreak@1 272 if options.type == "execute" then
flickerstreak@1 273 if options.func and type(options.func) ~= "string" and type(options.func) ~= "function" then
flickerstreak@1 274 return "func must be a string or function", position
flickerstreak@1 275 end
flickerstreak@1 276 if options.func and type(options.func) == "string" and type(self[options.func]) ~= "function" then
flickerstreak@1 277 return string.format("%q is not a proper function", options.func), position
flickerstreak@1 278 end
flickerstreak@1 279 else
flickerstreak@1 280 if options.get then
flickerstreak@1 281 if type(options.get) ~= "string" and type(options.get) ~= "function" then
flickerstreak@1 282 return "get must be a string or function", position
flickerstreak@1 283 end
flickerstreak@1 284 if type(options.get) == "string" then
flickerstreak@1 285 local f = options.get
flickerstreak@1 286 if options.type == "toggle" then
flickerstreak@1 287 f = f:match("^~(.-)$") or f
flickerstreak@1 288 end
flickerstreak@1 289 if type(self[f]) ~= "function" then
flickerstreak@1 290 return string.format("%q is not a proper function", f), position
flickerstreak@1 291 end
flickerstreak@1 292 end
flickerstreak@1 293 end
flickerstreak@1 294 if options.set then
flickerstreak@1 295 if type(options.set) ~= "string" and type(options.set) ~= "function" then
flickerstreak@1 296 return "set must be a string or function", position
flickerstreak@1 297 end
flickerstreak@1 298 if type(options.set) == "string" and type(self[options.set]) ~= "function" then
flickerstreak@1 299 return string.format("%q is not a proper function", options.set), position
flickerstreak@1 300 end
flickerstreak@1 301 end
flickerstreak@1 302 if options.validate and type(options.validate) ~= "table" and options.validate ~= "keybinding" then
flickerstreak@1 303 if type(options.validate) ~= "string" and type(options.validate) ~= "function" then
flickerstreak@1 304 return "validate must be a string or function", position
flickerstreak@1 305 end
flickerstreak@1 306 if type(options.validate) == "string" and type(self[options.validate]) ~= "function" then
flickerstreak@1 307 return string.format("%q is not a proper function", options.validate), position
flickerstreak@1 308 end
flickerstreak@1 309 end
flickerstreak@1 310 end
flickerstreak@1 311 if options.disabled and type(options.disabled) == "string" then
flickerstreak@1 312 local f = options.disabled
flickerstreak@1 313 f = f:match("^~(.-)$") or f
flickerstreak@1 314 if type(self[f]) ~= "function" then
flickerstreak@1 315 return string.format("%q is not a proper function", f), position
flickerstreak@1 316 end
flickerstreak@1 317 end
flickerstreak@1 318 if options.cmdHidden and type(options.cmdHidden) == "string" then
flickerstreak@1 319 local f = options.cmdHidden
flickerstreak@1 320 f = f:match("^~(.-)$") or f
flickerstreak@1 321 if type(self[f]) ~= "function" then
flickerstreak@1 322 return string.format("%q is not a proper function", f), position
flickerstreak@1 323 end
flickerstreak@1 324 end
flickerstreak@1 325 if options.guiHidden and type(options.guiHidden) == "string" then
flickerstreak@1 326 local f = options.guiHidden
flickerstreak@1 327 f = f:match("^~(.-)$") or f
flickerstreak@1 328 if type(self[f]) ~= "function" then
flickerstreak@1 329 return string.format("%q is not a proper function", f), position
flickerstreak@1 330 end
flickerstreak@1 331 end
flickerstreak@1 332 if options.hidden and type(options.hidden) == "string" then
flickerstreak@1 333 local f = options.hidden
flickerstreak@1 334 f = f:match("^~(.-)$") or f
flickerstreak@1 335 if type(self[f]) ~= "function" then
flickerstreak@1 336 return string.format("%q is not a proper function", f), position
flickerstreak@1 337 end
flickerstreak@1 338 end
flickerstreak@1 339 if options.type == "group" and type(options.args) == "table" then
flickerstreak@1 340 for k,v in pairs(options.args) do
flickerstreak@1 341 if type(v) == "table" then
flickerstreak@1 342 local newposition
flickerstreak@1 343 if position then
flickerstreak@1 344 newposition = position .. ".args." .. k
flickerstreak@1 345 else
flickerstreak@1 346 newposition = "args." .. k
flickerstreak@1 347 end
flickerstreak@1 348 local err, pos = validateOptionsMethods(self, v, newposition)
flickerstreak@1 349 if err then
flickerstreak@1 350 return err, pos
flickerstreak@1 351 end
flickerstreak@1 352 end
flickerstreak@1 353 end
flickerstreak@1 354 end
flickerstreak@1 355 end
flickerstreak@1 356
flickerstreak@1 357 local function validateOptions(options, position, baseOptions, fromPass)
flickerstreak@1 358 if not baseOptions then
flickerstreak@1 359 baseOptions = options
flickerstreak@1 360 end
flickerstreak@1 361 if type(options) ~= "table" then
flickerstreak@1 362 return "Options must be a table.", position
flickerstreak@1 363 end
flickerstreak@1 364 local kind = options.type
flickerstreak@1 365 if type(kind) ~= "string" then
flickerstreak@1 366 return '"type" must be a string.', position
flickerstreak@1 367 elseif kind ~= "group" and kind ~= "range" and kind ~= "text" and kind ~= "execute" and kind ~= "toggle" and kind ~= "color" and kind ~= "header" then
flickerstreak@1 368 return '"type" must either be "range", "text", "group", "toggle", "execute", "color", or "header".', position
flickerstreak@1 369 end
flickerstreak@1 370 if options.aliases then
flickerstreak@1 371 if type(options.aliases) ~= "table" and type(options.aliases) ~= "string" then
flickerstreak@1 372 return '"alias" must be a table or string', position
flickerstreak@1 373 end
flickerstreak@1 374 end
flickerstreak@1 375 if not fromPass then
flickerstreak@1 376 if kind == "execute" then
flickerstreak@1 377 if type(options.func) ~= "string" and type(options.func) ~= "function" then
flickerstreak@1 378 return '"func" must be a string or function', position
flickerstreak@1 379 end
flickerstreak@1 380 elseif kind == "range" or kind == "text" or kind == "toggle" then
flickerstreak@1 381 if type(options.set) ~= "string" and type(options.set) ~= "function" then
flickerstreak@1 382 return '"set" must be a string or function', position
flickerstreak@1 383 end
flickerstreak@1 384 if kind == "text" and options.get == false then
flickerstreak@1 385 elseif type(options.get) ~= "string" and type(options.get) ~= "function" then
flickerstreak@1 386 return '"get" must be a string or function', position
flickerstreak@1 387 end
flickerstreak@1 388 elseif kind == "group" and options.pass then
flickerstreak@1 389 if options.pass ~= true then
flickerstreak@1 390 return '"pass" must be either nil, true, or false', position
flickerstreak@1 391 end
flickerstreak@1 392 if not options.func then
flickerstreak@1 393 if type(options.set) ~= "string" and type(options.set) ~= "function" then
flickerstreak@1 394 return '"set" must be a string or function', position
flickerstreak@1 395 end
flickerstreak@1 396 if type(options.get) ~= "string" and type(options.get) ~= "function" then
flickerstreak@1 397 return '"get" must be a string or function', position
flickerstreak@1 398 end
flickerstreak@1 399 elseif type(options.func) ~= "string" and type(options.func) ~= "function" then
flickerstreak@1 400 return '"func" must be a string or function', position
flickerstreak@1 401 end
flickerstreak@1 402 end
flickerstreak@1 403 else
flickerstreak@1 404 if kind == "group" then
flickerstreak@1 405 return 'cannot have "type" = "group" as a subgroup of a passing group', position
flickerstreak@1 406 end
flickerstreak@1 407 end
flickerstreak@1 408 if options ~= baseOptions then
flickerstreak@1 409 if kind == "header" then
flickerstreak@1 410 elseif type(options.desc) ~= "string" then
flickerstreak@1 411 return '"desc" must be a string', position
flickerstreak@1 412 elseif options.desc:len() == 0 then
flickerstreak@1 413 return '"desc" cannot be a 0-length string', position
flickerstreak@1 414 end
flickerstreak@1 415 end
flickerstreak@1 416
flickerstreak@1 417 if options ~= baseOptions or kind == "range" or kind == "text" or kind == "toggle" or kind == "color" then
flickerstreak@1 418 if options.type == "header" and not options.cmdName and not options.name then
flickerstreak@1 419 elseif options.cmdName then
flickerstreak@1 420 if type(options.cmdName) ~= "string" then
flickerstreak@1 421 return '"cmdName" must be a string or nil', position
flickerstreak@1 422 elseif options.cmdName:len() == 0 then
flickerstreak@1 423 return '"cmdName" cannot be a 0-length string', position
flickerstreak@1 424 end
flickerstreak@1 425 if type(options.guiName) ~= "string" then
flickerstreak@1 426 if not options.guiNameIsMap then
flickerstreak@1 427 return '"guiName" must be a string or nil', position
flickerstreak@1 428 end
flickerstreak@1 429 elseif options.guiName:len() == 0 then
flickerstreak@1 430 return '"guiName" cannot be a 0-length string', position
flickerstreak@1 431 end
flickerstreak@1 432 else
flickerstreak@1 433 if type(options.name) ~= "string" then
flickerstreak@1 434 return '"name" must be a string', position
flickerstreak@1 435 elseif options.name:len() == 0 then
flickerstreak@1 436 return '"name" cannot be a 0-length string', position
flickerstreak@1 437 end
flickerstreak@1 438 end
flickerstreak@1 439 end
flickerstreak@1 440 if options.guiNameIsMap then
flickerstreak@1 441 if type(options.guiNameIsMap) ~= "boolean" then
flickerstreak@1 442 return '"guiNameIsMap" must be a boolean or nil', position
flickerstreak@1 443 elseif options.type ~= "toggle" then
flickerstreak@1 444 return 'if "guiNameIsMap" is true, then "type" must be set to \'toggle\'', position
flickerstreak@1 445 elseif type(options.map) ~= "table" then
flickerstreak@1 446 return '"map" must be a table', position
flickerstreak@1 447 end
flickerstreak@1 448 end
flickerstreak@1 449 if options.message and type(options.message) ~= "string" then
flickerstreak@1 450 return '"message" must be a string or nil', position
flickerstreak@1 451 end
flickerstreak@1 452 if options.error and type(options.error) ~= "string" then
flickerstreak@1 453 return '"error" must be a string or nil', position
flickerstreak@1 454 end
flickerstreak@1 455 if options.current and type(options.current) ~= "string" then
flickerstreak@1 456 return '"current" must be a string or nil', position
flickerstreak@1 457 end
flickerstreak@1 458 if options.order then
flickerstreak@1 459 if type(options.order) ~= "number" or (-1 < options.order and options.order < 0.999) then
flickerstreak@1 460 return '"order" must be a non-zero number or nil', position
flickerstreak@1 461 end
flickerstreak@1 462 end
flickerstreak@1 463 if options.disabled then
flickerstreak@1 464 if type(options.disabled) ~= "function" and type(options.disabled) ~= "string" and options.disabled ~= true then
flickerstreak@1 465 return '"disabled" must be a function, string, or boolean', position
flickerstreak@1 466 end
flickerstreak@1 467 end
flickerstreak@1 468 if options.cmdHidden then
flickerstreak@1 469 if type(options.cmdHidden) ~= "function" and type(options.cmdHidden) ~= "string" and options.cmdHidden ~= true then
flickerstreak@1 470 return '"cmdHidden" must be a function, string, or boolean', position
flickerstreak@1 471 end
flickerstreak@1 472 end
flickerstreak@1 473 if options.guiHidden then
flickerstreak@1 474 if type(options.guiHidden) ~= "function" and type(options.guiHidden) ~= "string" and options.guiHidden ~= true then
flickerstreak@1 475 return '"guiHidden" must be a function, string, or boolean', position
flickerstreak@1 476 end
flickerstreak@1 477 end
flickerstreak@1 478 if options.hidden then
flickerstreak@1 479 if type(options.hidden) ~= "function" and type(options.hidden) ~= "string" and options.hidden ~= true then
flickerstreak@1 480 return '"hidden" must be a function, string, or boolean', position
flickerstreak@1 481 end
flickerstreak@1 482 end
flickerstreak@1 483 if kind == "text" then
flickerstreak@1 484 if type(options.validate) == "table" then
flickerstreak@1 485 local t = options.validate
flickerstreak@1 486 local iTable = nil
flickerstreak@1 487 for k,v in pairs(t) do
flickerstreak@1 488 if type(k) == "number" then
flickerstreak@1 489 if iTable == nil then
flickerstreak@1 490 iTable = true
flickerstreak@1 491 elseif not iTable then
flickerstreak@1 492 return '"validate" must either have all keys be indexed numbers or strings', position
flickerstreak@1 493 elseif k < 1 or k > #t then
flickerstreak@1 494 return '"validate" numeric keys must be indexed properly. >= 1 and <= #validate', position
flickerstreak@1 495 end
flickerstreak@1 496 else
flickerstreak@1 497 if iTable == nil then
flickerstreak@1 498 iTable = false
flickerstreak@1 499 elseif iTable then
flickerstreak@1 500 return '"validate" must either have all keys be indexed numbers or strings', position
flickerstreak@1 501 end
flickerstreak@1 502 end
flickerstreak@1 503 if type(v) ~= "string" then
flickerstreak@1 504 return '"validate" values must all be strings', position
flickerstreak@1 505 end
flickerstreak@1 506 end
flickerstreak@1 507 elseif options.validate == "keybinding" then
flickerstreak@1 508
flickerstreak@1 509 else
flickerstreak@1 510 if type(options.usage) ~= "string" then
flickerstreak@1 511 return '"usage" must be a string', position
flickerstreak@1 512 elseif options.validate and type(options.validate) ~= "string" and type(options.validate) ~= "function" then
flickerstreak@1 513 return '"validate" must be a string, function, or table', position
flickerstreak@1 514 end
flickerstreak@1 515 end
flickerstreak@1 516 elseif kind == "range" then
flickerstreak@1 517 if options.min or options.max then
flickerstreak@1 518 if type(options.min) ~= "number" then
flickerstreak@1 519 return '"min" must be a number', position
flickerstreak@1 520 elseif type(options.max) ~= "number" then
flickerstreak@1 521 return '"max" must be a number', position
flickerstreak@1 522 elseif options.min >= options.max then
flickerstreak@1 523 return '"min" must be less than "max"', position
flickerstreak@1 524 end
flickerstreak@1 525 end
flickerstreak@1 526 if options.step then
flickerstreak@1 527 if type(options.step) ~= "number" then
flickerstreak@1 528 return '"step" must be a number', position
flickerstreak@1 529 elseif options.step < 0 then
flickerstreak@1 530 return '"step" must be nonnegative', position
flickerstreak@1 531 end
flickerstreak@1 532 end
flickerstreak@1 533 if options.isPercent and options.isPercent ~= true then
flickerstreak@1 534 return '"isPercent" must either be nil, true, or false', position
flickerstreak@1 535 end
flickerstreak@1 536 elseif kind == "toggle" then
flickerstreak@1 537 if options.map then
flickerstreak@1 538 if type(options.map) ~= "table" then
flickerstreak@1 539 return '"map" must be a table', position
flickerstreak@1 540 elseif type(options.map[true]) ~= "string" then
flickerstreak@1 541 return '"map[true]" must be a string', position
flickerstreak@1 542 elseif type(options.map[false]) ~= "string" then
flickerstreak@1 543 return '"map[false]" must be a string', position
flickerstreak@1 544 end
flickerstreak@1 545 end
flickerstreak@1 546 elseif kind == "color" then
flickerstreak@1 547 if options.hasAlpha and options.hasAlpha ~= true then
flickerstreak@1 548 return '"hasAlpha" must be nil, true, or false', position
flickerstreak@1 549 end
flickerstreak@1 550 elseif kind == "group" then
flickerstreak@1 551 if options.pass and options.pass ~= true then
flickerstreak@1 552 return '"pass" must be nil, true, or false', position
flickerstreak@1 553 end
flickerstreak@1 554 if type(options.args) ~= "table" then
flickerstreak@1 555 return '"args" must be a table', position
flickerstreak@1 556 end
flickerstreak@1 557 for k,v in pairs(options.args) do
flickerstreak@1 558 if type(k) ~= "string" then
flickerstreak@1 559 return '"args" keys must be strings', position
flickerstreak@1 560 elseif k:find("%s") then
flickerstreak@1 561 return string.format('"args" keys must not include spaces. %q is not appropriate.', k), position
flickerstreak@1 562 elseif k:len() == 0 then
flickerstreak@1 563 return '"args" keys must not be 0-length strings.', position
flickerstreak@1 564 end
flickerstreak@1 565 if type(v) ~= "table" then
flickerstreak@1 566 return '"args" values must be tables', position and position .. "." .. k or k
flickerstreak@1 567 end
flickerstreak@1 568 local newposition
flickerstreak@1 569 if position then
flickerstreak@1 570 newposition = position .. ".args." .. k
flickerstreak@1 571 else
flickerstreak@1 572 newposition = "args." .. k
flickerstreak@1 573 end
flickerstreak@1 574 local err, pos = validateOptions(v, newposition, baseOptions, options.pass)
flickerstreak@1 575 if err then
flickerstreak@1 576 return err, pos
flickerstreak@1 577 end
flickerstreak@1 578 end
flickerstreak@1 579 end
flickerstreak@1 580 end
flickerstreak@1 581
flickerstreak@1 582 local colorTable
flickerstreak@1 583 local colorFunc
flickerstreak@1 584 local colorCancelFunc
flickerstreak@1 585
flickerstreak@1 586 local function keybindingValidateFunc(text)
flickerstreak@1 587 if text == nil or text == "NONE" then
flickerstreak@1 588 return nil
flickerstreak@1 589 end
flickerstreak@1 590 text = text:upper()
flickerstreak@1 591 local shift, ctrl, alt
flickerstreak@1 592 local modifier
flickerstreak@1 593 while true do
flickerstreak@1 594 if text == "-" then
flickerstreak@1 595 break
flickerstreak@1 596 end
flickerstreak@1 597 modifier, text = strsplit('-', text, 2)
flickerstreak@1 598 if text then
flickerstreak@1 599 if modifier ~= "SHIFT" and modifier ~= "CTRL" and modifier ~= "ALT" then
flickerstreak@1 600 return false
flickerstreak@1 601 end
flickerstreak@1 602 if modifier == "SHIFT" then
flickerstreak@1 603 if shift then
flickerstreak@1 604 return false
flickerstreak@1 605 end
flickerstreak@1 606 shift = true
flickerstreak@1 607 end
flickerstreak@1 608 if modifier == "CTRL" then
flickerstreak@1 609 if ctrl then
flickerstreak@1 610 return false
flickerstreak@1 611 end
flickerstreak@1 612 ctrl = true
flickerstreak@1 613 end
flickerstreak@1 614 if modifier == "ALT" then
flickerstreak@1 615 if alt then
flickerstreak@1 616 return false
flickerstreak@1 617 end
flickerstreak@1 618 alt = true
flickerstreak@1 619 end
flickerstreak@1 620 else
flickerstreak@1 621 text = modifier
flickerstreak@1 622 break
flickerstreak@1 623 end
flickerstreak@1 624 end
flickerstreak@1 625 if not text:find("^F%d+$") and text:len() ~= 1 and (text:byte() < 128 or text:len() > 4) and not _G["KEY_" .. text] then
flickerstreak@1 626 return false
flickerstreak@1 627 end
flickerstreak@1 628 local s = text
flickerstreak@1 629 if shift then
flickerstreak@1 630 s = "SHIFT-" .. s
flickerstreak@1 631 end
flickerstreak@1 632 if ctrl then
flickerstreak@1 633 s = "CTRL-" .. s
flickerstreak@1 634 end
flickerstreak@1 635 if alt then
flickerstreak@1 636 s = "ALT-" .. s
flickerstreak@1 637 end
flickerstreak@1 638 return s
flickerstreak@1 639 end
flickerstreak@1 640 AceConsole.keybindingValidateFunc = keybindingValidateFunc
flickerstreak@1 641
flickerstreak@1 642 local order
flickerstreak@1 643
flickerstreak@1 644 local mysort_args
flickerstreak@1 645 local mysort
flickerstreak@1 646
flickerstreak@1 647 local function printUsage(self, handler, realOptions, options, path, args, quiet, filter)
flickerstreak@1 648 if filter then
flickerstreak@1 649 filter = "^" .. filter:gsub("([%(%)%.%*%+%-%[%]%?%^%$%%])", "%%%1")
flickerstreak@1 650 end
flickerstreak@1 651 local hidden, disabled = options.cmdHidden or options.hidden, options.disabled
flickerstreak@1 652 if hidden then
flickerstreak@1 653 if type(hidden) == "function" then
flickerstreak@1 654 hidden = hidden()
flickerstreak@1 655 elseif type(hidden) == "string" then
flickerstreak@1 656 local f = hidden
flickerstreak@1 657 local neg = f:match("^~(.-)$")
flickerstreak@1 658 if neg then
flickerstreak@1 659 f = neg
flickerstreak@1 660 end
flickerstreak@1 661 if type(handler[f]) ~= "function" then
flickerstreak@1 662 AceConsole:error("%s: %s", handler, string.format(OPTION_HANDLER_NOT_FOUND, f))
flickerstreak@1 663 end
flickerstreak@1 664 hidden = handler[f](handler)
flickerstreak@1 665 if neg then
flickerstreak@1 666 hidden = not hidden
flickerstreak@1 667 end
flickerstreak@1 668 end
flickerstreak@1 669 end
flickerstreak@1 670 if hidden then
flickerstreak@1 671 disabled = true
flickerstreak@1 672 elseif disabled then
flickerstreak@1 673 if type(disabled) == "function" then
flickerstreak@1 674 disabled = disabled()
flickerstreak@1 675 elseif type(disabled) == "string" then
flickerstreak@1 676 local f = disabled
flickerstreak@1 677 local neg = f:match("^~(.-)$")
flickerstreak@1 678 if neg then
flickerstreak@1 679 f = neg
flickerstreak@1 680 end
flickerstreak@1 681 if type(handler[f]) ~= "function" then
flickerstreak@1 682 AceConsole:error("%s: %s", handler, string.format(OPTION_HANDLER_NOT_FOUND, f))
flickerstreak@1 683 end
flickerstreak@1 684 disabled = handler[f](handler)
flickerstreak@1 685 if neg then
flickerstreak@1 686 disabled = not disabled
flickerstreak@1 687 end
flickerstreak@1 688 end
flickerstreak@1 689 end
flickerstreak@1 690 local kind = (options.type or "group"):lower()
flickerstreak@1 691 if disabled then
flickerstreak@1 692 print(string.format(OPTION_IS_DISABLED, path), realOptions.cmdName or realOptions.name or self)
flickerstreak@1 693 elseif kind == "text" then
flickerstreak@1 694 local var
flickerstreak@1 695 if passTable then
flickerstreak@1 696 if not passTable.get then
flickerstreak@1 697 elseif type(passTable.get) == "function" then
flickerstreak@1 698 var = passTable.get(passValue)
flickerstreak@1 699 else
flickerstreak@1 700 local handler = passTable.handler or handler
flickerstreak@1 701 if type(handler[passTable.get]) ~= "function" then
flickerstreak@1 702 AceConsole:error("%s: %s", handler, string.format(OPTION_HANDLER_NOT_FOUND, passTable.get))
flickerstreak@1 703 end
flickerstreak@1 704 var = handler[passTable.get](handler, passValue)
flickerstreak@1 705 end
flickerstreak@1 706 else
flickerstreak@1 707 if not options.get then
flickerstreak@1 708 elseif type(options.get) == "function" then
flickerstreak@1 709 var = options.get()
flickerstreak@1 710 else
flickerstreak@1 711 local handler = options.handler or handler
flickerstreak@1 712 if type(handler[options.get]) ~= "function" then
flickerstreak@1 713 AceConsole:error("%s: %s", handler, string.format(OPTION_HANDLER_NOT_FOUND, options.get))
flickerstreak@1 714 end
flickerstreak@1 715 var = handler[options.get](handler)
flickerstreak@1 716 end
flickerstreak@1 717 end
flickerstreak@1 718
flickerstreak@1 719 local usage
flickerstreak@1 720 if type(options.validate) == "table" then
flickerstreak@1 721 if filter then
flickerstreak@1 722 if not order then
flickerstreak@1 723 order = {}
flickerstreak@1 724 end
flickerstreak@1 725 for k,v in pairs(options.validate) do
flickerstreak@1 726 if v:find(filter) then
flickerstreak@1 727 table.insert(order, v)
flickerstreak@1 728 end
flickerstreak@1 729 end
flickerstreak@1 730 usage = "{" .. table.concat(order, " || ") .. "}"
flickerstreak@1 731 for k in pairs(order) do
flickerstreak@1 732 order[k] = nil
flickerstreak@1 733 end
flickerstreak@1 734 else
flickerstreak@1 735 if not order then
flickerstreak@1 736 order = {}
flickerstreak@1 737 end
flickerstreak@1 738 for k,v in pairs(options.validate) do
flickerstreak@1 739 table.insert(order, v)
flickerstreak@1 740 end
flickerstreak@1 741 usage = "{" .. table.concat(order, " || ") .. "}"
flickerstreak@1 742 for k in pairs(order) do
flickerstreak@1 743 order[k] = nil
flickerstreak@1 744 end
flickerstreak@1 745 end
flickerstreak@1 746 var = options.validate[var] or var
flickerstreak@1 747 elseif options.validate == "keybinding" then
flickerstreak@1 748 usage = KEYBINDING_USAGE
flickerstreak@1 749 else
flickerstreak@1 750 usage = options.usage or "<value>"
flickerstreak@1 751 end
flickerstreak@1 752 if not quiet then
flickerstreak@1 753 print(string.format("|cffffff7f%s:|r %s %s", USAGE, path, usage), realOptions.cmdName or realOptions.name or self)
flickerstreak@1 754 end
flickerstreak@1 755 if (passTable and passTable.get) or options.get then
flickerstreak@1 756 print(string.format(options.current or IS_CURRENTLY_SET_TO, tostring(options.cmdName or options.name), tostring(var or NONE)))
flickerstreak@1 757 end
flickerstreak@1 758 elseif kind == "range" then
flickerstreak@1 759 local var
flickerstreak@1 760 if passTable then
flickerstreak@1 761 if type(passTable.get) == "function" then
flickerstreak@1 762 var = passTable.get(passValue)
flickerstreak@1 763 else
flickerstreak@1 764 local handler = passTable.handler or handler
flickerstreak@1 765 if type(handler[passTable.get]) ~= "function" then
flickerstreak@1 766 AceConsole:error("%s: %s", handler, string.format(OPTION_HANDLER_NOT_FOUND, passTable.get))
flickerstreak@1 767 end
flickerstreak@1 768 var = handler[passTable.get](handler, passValue)
flickerstreak@1 769 end
flickerstreak@1 770 else
flickerstreak@1 771 if type(options.get) == "function" then
flickerstreak@1 772 var = options.get()
flickerstreak@1 773 else
flickerstreak@1 774 local handler = options.handler or handler
flickerstreak@1 775 if type(handler[options.get]) ~= "function" then
flickerstreak@1 776 AceConsole:error("%s: %s", handler, string.format(OPTION_HANDLER_NOT_FOUND, options.get))
flickerstreak@1 777 end
flickerstreak@1 778 var = handler[options.get](handler)
flickerstreak@1 779 end
flickerstreak@1 780 end
flickerstreak@1 781
flickerstreak@1 782 local usage
flickerstreak@1 783 local min = options.min or 0
flickerstreak@1 784 local max = options.max or 1
flickerstreak@1 785 if options.isPercent then
flickerstreak@1 786 min, max = min * 100, max * 100
flickerstreak@1 787 var = tostring(var * 100) .. "%"
flickerstreak@1 788 end
flickerstreak@1 789 local bit = "-"
flickerstreak@1 790 if min < 0 or max < 0 then
flickerstreak@1 791 bit = " - "
flickerstreak@1 792 end
flickerstreak@1 793 usage = string.format("(%s%s%s)", min, bit, max)
flickerstreak@1 794 if not quiet then
flickerstreak@1 795 print(string.format("|cffffff7f%s:|r %s %s", USAGE, path, usage), realOptions.cmdName or realOptions.name or self)
flickerstreak@1 796 end
flickerstreak@1 797 print(string.format(options.current or IS_CURRENTLY_SET_TO, tostring(options.cmdName or options.name), tostring(var or NONE)))
flickerstreak@1 798 elseif kind == "group" then
flickerstreak@1 799 local usage
flickerstreak@1 800 if next(options.args) then
flickerstreak@1 801 if not order then
flickerstreak@1 802 order = {}
flickerstreak@1 803 end
flickerstreak@1 804 for k,v in pairs(options.args) do
flickerstreak@1 805 if v.type ~= "header" then
flickerstreak@1 806 local hidden = v.cmdHidden or v.hidden
flickerstreak@1 807 if hidden then
flickerstreak@1 808 if type(hidden) == "function" then
flickerstreak@1 809 hidden = hidden()
flickerstreak@1 810 elseif type(hidden) == "string" then
flickerstreak@1 811 local f = hidden
flickerstreak@1 812 local neg = f:match("^~(.-)$")
flickerstreak@1 813 if neg then
flickerstreak@1 814 f = neg
flickerstreak@1 815 end
flickerstreak@1 816 if type(handler[f]) ~= "function" then
flickerstreak@1 817 AceConsole:error("%s: %s", handler, string.format(OPTION_HANDLER_NOT_FOUND, f))
flickerstreak@1 818 end
flickerstreak@1 819 hidden = handler[f](handler)
flickerstreak@1 820 if neg then
flickerstreak@1 821 hidden = not hidden
flickerstreak@1 822 end
flickerstreak@1 823 end
flickerstreak@1 824 end
flickerstreak@1 825 if not hidden then
flickerstreak@1 826 if filter then
flickerstreak@1 827 if k:find(filter) then
flickerstreak@1 828 table.insert(order, k)
flickerstreak@1 829 elseif type(v.aliases) == "table" then
flickerstreak@1 830 for _,bit in ipairs(v.aliases) do
flickerstreak@1 831 if bit:find(filter) then
flickerstreak@1 832 table.insert(order, k)
flickerstreak@1 833 break
flickerstreak@1 834 end
flickerstreak@1 835 end
flickerstreak@1 836 elseif type(v.aliases) == "string" then
flickerstreak@1 837 if v.aliases:find(filter) then
flickerstreak@1 838 table.insert(order, k)
flickerstreak@1 839 end
flickerstreak@1 840 end
flickerstreak@1 841 else
flickerstreak@1 842 table.insert(order, k)
flickerstreak@1 843 end
flickerstreak@1 844 end
flickerstreak@1 845 end
flickerstreak@1 846 end
flickerstreak@1 847 if not mysort then
flickerstreak@1 848 mysort = function(a, b)
flickerstreak@1 849 local alpha, bravo = mysort_args[a], mysort_args[b]
flickerstreak@1 850 local alpha_order = alpha and alpha.order or 100
flickerstreak@1 851 local bravo_order = bravo and bravo.order or 100
flickerstreak@1 852 if alpha_order == bravo_order then
flickerstreak@1 853 return tostring(a) < tostring(b)
flickerstreak@1 854 else
flickerstreak@1 855 if alpha_order < 0 then
flickerstreak@1 856 if bravo_order > 0 then
flickerstreak@1 857 return false
flickerstreak@1 858 end
flickerstreak@1 859 else
flickerstreak@1 860 if bravo_order < 0 then
flickerstreak@1 861 return true
flickerstreak@1 862 end
flickerstreak@1 863 end
flickerstreak@1 864 if alpha_order > 0 and bravo_order > 0 then
flickerstreak@1 865 return tostring(a) < tostring(b)
flickerstreak@1 866 end
flickerstreak@1 867 return alpha_order < bravo_order
flickerstreak@1 868 end
flickerstreak@1 869 end
flickerstreak@1 870 end
flickerstreak@1 871 mysort_args = options.args
flickerstreak@1 872 table.sort(order, mysort)
flickerstreak@1 873 mysort_args = nil
flickerstreak@1 874 if not quiet then
flickerstreak@1 875 if options == realOptions then
flickerstreak@1 876 if options.desc then
flickerstreak@1 877 print(tostring(options.desc), realOptions.cmdName or realOptions.name or self)
flickerstreak@1 878 print(string.format("|cffffff7f%s:|r %s %s", USAGE, path, "{" .. table.concat(order, " || ") .. "}"))
flickerstreak@1 879 elseif self.description or self.notes then
flickerstreak@1 880 print(tostring(self.description or self.notes), realOptions.cmdName or realOptions.name or self)
flickerstreak@1 881 print(string.format("|cffffff7f%s:|r %s %s", USAGE, path, "{" .. table.concat(order, " || ") .. "}"))
flickerstreak@1 882 else
flickerstreak@1 883 print(string.format("|cffffff7f%s:|r %s %s", USAGE, path, "{" .. table.concat(order, " || ") .. "}"), realOptions.cmdName or realOptions.name or self)
flickerstreak@1 884 end
flickerstreak@1 885 else
flickerstreak@1 886 if options.desc then
flickerstreak@1 887 print(string.format("|cffffff7f%s:|r %s %s", USAGE, path, "{" .. table.concat(order, " || ") .. "}"), realOptions.cmdName or realOptions.name or self)
flickerstreak@1 888 print(tostring(options.desc))
flickerstreak@1 889 else
flickerstreak@1 890 print(string.format("|cffffff7f%s:|r %s %s", USAGE, path, "{" .. table.concat(order, " || ") .. "}"), realOptions.cmdName or realOptions.name or self)
flickerstreak@1 891 end
flickerstreak@1 892 end
flickerstreak@1 893 end
flickerstreak@1 894 for _,k in ipairs(order) do
flickerstreak@1 895 local v = options.args[k]
flickerstreak@1 896 if v then
flickerstreak@1 897 local disabled = v.disabled
flickerstreak@1 898 if disabled then
flickerstreak@1 899 if type(disabled) == "function" then
flickerstreak@1 900 disabled = disabled()
flickerstreak@1 901 elseif type(disabled) == "string" then
flickerstreak@1 902 local f = disabled
flickerstreak@1 903 local neg = f:match("^~(.-)$")
flickerstreak@1 904 if neg then
flickerstreak@1 905 f = neg
flickerstreak@1 906 end
flickerstreak@1 907 if type(handler[f]) ~= "function" then
flickerstreak@1 908 AceConsole:error("%s: %s", handler, string.format(OPTION_HANDLER_NOT_FOUND, f))
flickerstreak@1 909 end
flickerstreak@1 910 disabled = handler[f](handler)
flickerstreak@1 911 if neg then
flickerstreak@1 912 disabled = not disabled
flickerstreak@1 913 end
flickerstreak@1 914 end
flickerstreak@1 915 end
flickerstreak@1 916 if type(v.aliases) == "table" then
flickerstreak@1 917 k = k .. " || " .. table.concat(v.aliases, " || ")
flickerstreak@1 918 elseif type(v.aliases) == "string" then
flickerstreak@1 919 k = k .. " || " .. v.aliases
flickerstreak@1 920 end
flickerstreak@1 921 if v.get then
flickerstreak@1 922 local a1,a2,a3,a4
flickerstreak@1 923 if type(v.get) == "function" then
flickerstreak@1 924 if options.pass then
flickerstreak@1 925 a1,a2,a3,a4 = v.get(k)
flickerstreak@1 926 else
flickerstreak@1 927 a1,a2,a3,a4 = v.get()
flickerstreak@1 928 end
flickerstreak@1 929 else
flickerstreak@1 930 local handler = v.handler or handler
flickerstreak@1 931 local f = v.get
flickerstreak@1 932 local neg
flickerstreak@1 933 if v.type == "toggle" then
flickerstreak@1 934 neg = f:match("^~(.-)$")
flickerstreak@1 935 if neg then
flickerstreak@1 936 f = neg
flickerstreak@1 937 end
flickerstreak@1 938 end
flickerstreak@1 939 if type(handler[f]) ~= "function" then
flickerstreak@1 940 AceConsole:error("%s: %s", handler, string.format(OPTION_HANDLER_NOT_FOUND, f))
flickerstreak@1 941 end
flickerstreak@1 942 if options.pass then
flickerstreak@1 943 a1,a2,a3,a4 = handler[f](handler, k)
flickerstreak@1 944 else
flickerstreak@1 945 a1,a2,a3,a4 = handler[f](handler)
flickerstreak@1 946 end
flickerstreak@1 947 if neg then
flickerstreak@1 948 a1 = not a1
flickerstreak@1 949 end
flickerstreak@1 950 end
flickerstreak@1 951 if v.type == "color" then
flickerstreak@1 952 if v.hasAlpha then
flickerstreak@1 953 if not a1 or not a2 or not a3 or not a4 then
flickerstreak@1 954 s = NONE
flickerstreak@1 955 else
flickerstreak@1 956 s = string.format("|c%02x%02x%02x%02x%02x%02x%02x%02x|r", a4*255, a1*255, a2*255, a3*255, a4*255, a1*255, a2*255, a3*255)
flickerstreak@1 957 end
flickerstreak@1 958 else
flickerstreak@1 959 if not a1 or not a2 or not a3 then
flickerstreak@1 960 s = NONE
flickerstreak@1 961 else
flickerstreak@1 962 s = string.format("|cff%02x%02x%02x%02x%02x%02x|r", a1*255, a2*255, a3*255, a1*255, a2*255, a3*255)
flickerstreak@1 963 end
flickerstreak@1 964 end
flickerstreak@1 965 elseif v.type == "toggle" then
flickerstreak@1 966 if v.map then
flickerstreak@1 967 s = tostring(v.map[a1 and true or false] or NONE)
flickerstreak@1 968 else
flickerstreak@1 969 s = tostring(MAP_ONOFF[a1 and true or false] or NONE)
flickerstreak@1 970 end
flickerstreak@1 971 elseif v.type == "range" then
flickerstreak@1 972 if v.isPercent then
flickerstreak@1 973 s = tostring(a1 * 100) .. "%"
flickerstreak@1 974 else
flickerstreak@1 975 s = tostring(a1)
flickerstreak@1 976 end
flickerstreak@1 977 elseif v.type == "text" and type(v.validate) == "table" then
flickerstreak@1 978 s = tostring(v.validate[a1] or a1 or NONE)
flickerstreak@1 979 else
flickerstreak@1 980 s = tostring(a1 or NONE)
flickerstreak@1 981 end
flickerstreak@1 982 if disabled then
flickerstreak@1 983 local s = s:gsub("|cff%x%x%x%x%x%x(.-)|r", "%1")
flickerstreak@1 984 local desc = (v.desc or NONE):gsub("|cff%x%x%x%x%x%x(.-)|r", "%1")
flickerstreak@1 985 print(string.format("|cffcfcfcf - %s: [%s] %s|r", k, s, desc))
flickerstreak@1 986 else
flickerstreak@1 987 print(string.format(" - |cffffff7f%s: [|r%s|cffffff7f]|r %s", k, s, v.desc or NONE))
flickerstreak@1 988 end
flickerstreak@1 989 else
flickerstreak@1 990 if disabled then
flickerstreak@1 991 local desc = (v.desc or NONE):gsub("|cff%x%x%x%x%x%x(.-)|r", "%1")
flickerstreak@1 992 print(string.format("|cffcfcfcf - %s: %s", k, desc))
flickerstreak@1 993 else
flickerstreak@1 994 print(string.format(" - |cffffff7f%s:|r %s", k, v.desc or NONE))
flickerstreak@1 995 end
flickerstreak@1 996 end
flickerstreak@1 997 end
flickerstreak@1 998 end
flickerstreak@1 999 for k in pairs(order) do
flickerstreak@1 1000 order[k] = nil
flickerstreak@1 1001 end
flickerstreak@1 1002 else
flickerstreak@1 1003 if options.desc then
flickerstreak@1 1004 desc = options.desc
flickerstreak@1 1005 print(string.format("|cffffff7f%s:|r %s", USAGE, path), realOptions.cmdName or realOptions.name or self)
flickerstreak@1 1006 print(tostring(options.desc))
flickerstreak@1 1007 elseif options == realOptions and (self.description or self.notes) then
flickerstreak@1 1008 print(tostring(self.description or self.notes), realOptions.cmdName or realOptions.name or self)
flickerstreak@1 1009 print(string.format("|cffffff7f%s:|r %s", USAGE, path))
flickerstreak@1 1010 else
flickerstreak@1 1011 print(string.format("|cffffff7f%s:|r %s", USAGE, path), realOptions.cmdName or realOptions.name or self)
flickerstreak@1 1012 end
flickerstreak@1 1013 print(NO_OPTIONS_AVAILABLE)
flickerstreak@1 1014 end
flickerstreak@1 1015 end
flickerstreak@1 1016 end
flickerstreak@1 1017
flickerstreak@1 1018 local function handlerFunc(self, chat, msg, options)
flickerstreak@1 1019 if not msg then
flickerstreak@1 1020 msg = ""
flickerstreak@1 1021 else
flickerstreak@1 1022 msg = msg:gsub("^%s*(.-)%s*$", "%1")
flickerstreak@1 1023 msg = msg:gsub("%s+", " ")
flickerstreak@1 1024 end
flickerstreak@1 1025
flickerstreak@1 1026 local realOptions = options
flickerstreak@1 1027 local options, path, args, handler, passTable, passValue = findTableLevel(self, options, chat, msg)
flickerstreak@1 1028
flickerstreak@1 1029 local hidden, disabled = options.cmdHidden or options.hidden, options.disabled
flickerstreak@1 1030 if hidden then
flickerstreak@1 1031 if type(hidden) == "function" then
flickerstreak@1 1032 hidden = hidden()
flickerstreak@1 1033 elseif type(hidden) == "string" then
flickerstreak@1 1034 local f = hidden
flickerstreak@1 1035 local neg = f:match("^~(.-)$")
flickerstreak@1 1036 if neg then
flickerstreak@1 1037 f = neg
flickerstreak@1 1038 end
flickerstreak@1 1039 if type(handler[f]) ~= "function" then
flickerstreak@1 1040 AceConsole:error("%s: %s", handler, string.format(OPTION_HANDLER_NOT_FOUND, f))
flickerstreak@1 1041 end
flickerstreak@1 1042 hidden = handler[f](handler)
flickerstreak@1 1043 if neg then
flickerstreak@1 1044 hidden = not hidden
flickerstreak@1 1045 end
flickerstreak@1 1046 end
flickerstreak@1 1047 end
flickerstreak@1 1048 if hidden then
flickerstreak@1 1049 disabled = true
flickerstreak@1 1050 elseif disabled then
flickerstreak@1 1051 if type(disabled) == "function" then
flickerstreak@1 1052 disabled = disabled()
flickerstreak@1 1053 elseif type(disabled) == "string" then
flickerstreak@1 1054 local f = disabled
flickerstreak@1 1055 local neg = f:match("^~(.-)$")
flickerstreak@1 1056 if neg then
flickerstreak@1 1057 f = neg
flickerstreak@1 1058 end
flickerstreak@1 1059 if type(handler[f]) ~= "function" then
flickerstreak@1 1060 AceConsole:error("%s: %s", handler, string.format(OPTION_HANDLER_NOT_FOUND, f))
flickerstreak@1 1061 end
flickerstreak@1 1062 disabled = handler[f](handler)
flickerstreak@1 1063 if neg then
flickerstreak@1 1064 disabled = not disabled
flickerstreak@1 1065 end
flickerstreak@1 1066 end
flickerstreak@1 1067 end
flickerstreak@1 1068 local _G_this = this
flickerstreak@1 1069 local kind = (options.type or "group"):lower()
flickerstreak@1 1070 if disabled then
flickerstreak@1 1071 print(string.format(OPTION_IS_DISABLED, path), realOptions.cmdName or realOptions.name or self)
flickerstreak@1 1072 elseif kind == "text" then
flickerstreak@1 1073 if #args > 0 then
flickerstreak@1 1074 if (type(options.validate) == "table" and #args > 1) or (type(options.validate) ~= "table" and not options.input) then
flickerstreak@1 1075 local arg = table.concat(args, " ")
flickerstreak@1 1076 for k,v in pairs(args) do
flickerstreak@1 1077 args[k] = nil
flickerstreak@1 1078 end
flickerstreak@1 1079 args[1] = arg
flickerstreak@1 1080 end
flickerstreak@1 1081 if options.validate then
flickerstreak@1 1082 local good
flickerstreak@1 1083 if type(options.validate) == "function" then
flickerstreak@1 1084 good = options.validate(unpack(args))
flickerstreak@1 1085 elseif type(options.validate) == "table" then
flickerstreak@1 1086 local arg = args[1]
flickerstreak@1 1087 arg = tostring(arg):lower()
flickerstreak@1 1088 for k,v in pairs(options.validate) do
flickerstreak@1 1089 if v:lower() == arg then
flickerstreak@1 1090 args[1] = type(k) == "string" and k or v
flickerstreak@1 1091 good = true
flickerstreak@1 1092 break
flickerstreak@1 1093 end
flickerstreak@1 1094 end
flickerstreak@1 1095 if not good and type((next(options.validate))) == "string" then
flickerstreak@1 1096 for k,v in pairs(options.validate) do
flickerstreak@1 1097 if type(k) == "string" and k:lower() == arg then
flickerstreak@1 1098 args[1] = k
flickerstreak@1 1099 good = true
flickerstreak@1 1100 break
flickerstreak@1 1101 end
flickerstreak@1 1102 end
flickerstreak@1 1103 end
flickerstreak@1 1104 elseif options.validate == "keybinding" then
flickerstreak@1 1105 good = keybindingValidateFunc(unpack(args))
flickerstreak@1 1106 if good ~= false then
flickerstreak@1 1107 args[1] = good
flickerstreak@1 1108 end
flickerstreak@1 1109 else
flickerstreak@1 1110 if type(handler[options.validate]) ~= "function" then
flickerstreak@1 1111 AceConsole:error("%s: %s", handler, string.format(OPTION_HANDLER_NOT_FOUND, options.validate))
flickerstreak@1 1112 end
flickerstreak@1 1113 good = handler[options.validate](handler, unpack(args))
flickerstreak@1 1114 end
flickerstreak@1 1115 if not good then
flickerstreak@1 1116 local usage
flickerstreak@1 1117 if type(options.validate) == "table" then
flickerstreak@1 1118 if not order then
flickerstreak@1 1119 order = {}
flickerstreak@1 1120 end
flickerstreak@1 1121 for k,v in pairs(options.validate) do
flickerstreak@1 1122 table.insert(order, v)
flickerstreak@1 1123 end
flickerstreak@1 1124 usage = "{" .. table.concat(order, " || ") .. "}"
flickerstreak@1 1125 for k in pairs(order) do
flickerstreak@1 1126 order[k] = nil
flickerstreak@1 1127 end
flickerstreak@1 1128 elseif options.validate == "keybinding" then
flickerstreak@1 1129 usage = KEYBINDING_USAGE
flickerstreak@1 1130 else
flickerstreak@1 1131 usage = options.usage or "<value>"
flickerstreak@1 1132 end
flickerstreak@1 1133 print(string.format(options.error or IS_NOT_A_VALID_OPTION_FOR, tostring(table.concat(args, " ")), path), realOptions.cmdName or realOptions.name or self)
flickerstreak@1 1134 print(string.format("|cffffff7f%s:|r %s %s", USAGE, path, usage))
flickerstreak@1 1135 return
flickerstreak@1 1136 end
flickerstreak@1 1137 end
flickerstreak@1 1138
flickerstreak@1 1139 local var
flickerstreak@1 1140 if passTable then
flickerstreak@1 1141 if not passTable.get then
flickerstreak@1 1142 elseif type(passTable.get) == "function" then
flickerstreak@1 1143 var = passTable.get(passValue)
flickerstreak@1 1144 else
flickerstreak@1 1145 if type(handler[passTable.get]) ~= "function" then
flickerstreak@1 1146 AceConsole:error("%s: %s", handler, string.format(OPTION_HANDLER_NOT_FOUND, passTable.get))
flickerstreak@1 1147 end
flickerstreak@1 1148 var = handler[passTable.get](handler, passValue)
flickerstreak@1 1149 end
flickerstreak@1 1150 else
flickerstreak@1 1151 if not options.get then
flickerstreak@1 1152 elseif type(options.get) == "function" then
flickerstreak@1 1153 var = options.get()
flickerstreak@1 1154 else
flickerstreak@1 1155 if type(handler[options.get]) ~= "function" then
flickerstreak@1 1156 AceConsole:error("%s: %s", handler, string.format(OPTION_HANDLER_NOT_FOUND, options.get))
flickerstreak@1 1157 end
flickerstreak@1 1158 var = handler[options.get](handler)
flickerstreak@1 1159 end
flickerstreak@1 1160 end
flickerstreak@1 1161
flickerstreak@1 1162 if var ~= args[1] then
flickerstreak@1 1163 if passTable then
flickerstreak@1 1164 if type(passTable.set) == "function" then
flickerstreak@1 1165 passTable.set(passValue, unpack(args))
flickerstreak@1 1166 else
flickerstreak@1 1167 if type(handler[passTable.set]) ~= "function" then
flickerstreak@1 1168 AceConsole:error("%s: %s", handler, string.format(OPTION_HANDLER_NOT_FOUND, passTable.set))
flickerstreak@1 1169 end
flickerstreak@1 1170 handler[passTable.set](handler, passTable.set, unpack(args))
flickerstreak@1 1171 end
flickerstreak@1 1172 else
flickerstreak@1 1173 if type(options.set) == "function" then
flickerstreak@1 1174 options.set(unpack(args))
flickerstreak@1 1175 else
flickerstreak@1 1176 if type(handler[options.set]) ~= "function" then
flickerstreak@1 1177 AceConsole:error("%s: %s", handler, string.format(OPTION_HANDLER_NOT_FOUND, options.set))
flickerstreak@1 1178 end
flickerstreak@1 1179 handler[options.set](handler, unpack(args))
flickerstreak@1 1180 end
flickerstreak@1 1181 end
flickerstreak@1 1182 end
flickerstreak@1 1183 end
flickerstreak@1 1184
flickerstreak@1 1185 if #args > 0 then
flickerstreak@1 1186 local var
flickerstreak@1 1187 if passTable then
flickerstreak@1 1188 if not passTable.get then
flickerstreak@1 1189 elseif type(passTable.get) == "function" then
flickerstreak@1 1190 var = passTable.get(passValue)
flickerstreak@1 1191 else
flickerstreak@1 1192 if type(handler[passTable.get]) ~= "function" then
flickerstreak@1 1193 AceConsole:error("%s: %s", handler, string.format(OPTION_HANDLER_NOT_FOUND, passTable.get))
flickerstreak@1 1194 end
flickerstreak@1 1195 var = handler[passTable.get](handler, passValue)
flickerstreak@1 1196 end
flickerstreak@1 1197 else
flickerstreak@1 1198 if not options.get then
flickerstreak@1 1199 elseif type(options.get) == "function" then
flickerstreak@1 1200 var = options.get()
flickerstreak@1 1201 else
flickerstreak@1 1202 if type(handler[options.get]) ~= "function" then
flickerstreak@1 1203 AceConsole:error("%s: %s", handler, string.format(OPTION_HANDLER_NOT_FOUND, options.get))
flickerstreak@1 1204 end
flickerstreak@1 1205 var = handler[options.get](handler)
flickerstreak@1 1206 end
flickerstreak@1 1207 end
flickerstreak@1 1208 if type(options.validate) == "table" then
flickerstreak@1 1209 var = options.validate[var] or var
flickerstreak@1 1210 end
flickerstreak@1 1211 if (passTable and passTable.get) or options.get then
flickerstreak@1 1212 print(string.format(options.message or IS_NOW_SET_TO, tostring(options.cmdName or options.name), tostring(var or NONE)), realOptions.cmdName or realOptions.name or self)
flickerstreak@1 1213 end
flickerstreak@1 1214 if var == args[1] then
flickerstreak@1 1215 return
flickerstreak@1 1216 end
flickerstreak@1 1217 else
flickerstreak@1 1218 printUsage(self, handler, realOptions, options, path, args)
flickerstreak@1 1219 return
flickerstreak@1 1220 end
flickerstreak@1 1221 elseif kind == "execute" then
flickerstreak@1 1222 if passTable then
flickerstreak@1 1223 if type(passFunc) == "function" then
flickerstreak@1 1224 set(passValue)
flickerstreak@1 1225 else
flickerstreak@1 1226 if type(handler[passFunc]) ~= "function" then
flickerstreak@1 1227 AceConsole:error("%s: %s", handler, string.format(OPTION_HANDLER_NOT_FOUND, passFunc))
flickerstreak@1 1228 end
flickerstreak@1 1229 handler[passFunc](handler, passValue)
flickerstreak@1 1230 end
flickerstreak@1 1231 else
flickerstreak@1 1232 local ret, msg
flickerstreak@1 1233 if type(options.func) == "function" then
flickerstreak@1 1234 options.func()
flickerstreak@1 1235 else
flickerstreak@1 1236 local handler = options.handler or self
flickerstreak@1 1237 if type(handler[options.func]) ~= "function" then
flickerstreak@1 1238 AceConsole:error("%s: %s", handler, string.format(OPTION_HANDLER_NOT_FOUND, options.func))
flickerstreak@1 1239 end
flickerstreak@1 1240 handler[options.func](handler)
flickerstreak@1 1241 end
flickerstreak@1 1242 end
flickerstreak@1 1243 elseif kind == "toggle" then
flickerstreak@1 1244 local var
flickerstreak@1 1245 if passTable then
flickerstreak@1 1246 if type(passTable.get) == "function" then
flickerstreak@1 1247 var = passTable.get(passValue)
flickerstreak@1 1248 else
flickerstreak@1 1249 local f = passTable.get
flickerstreak@1 1250 local neg = f:match("^~(.-)$")
flickerstreak@1 1251 if neg then
flickerstreak@1 1252 f = neg
flickerstreak@1 1253 end
flickerstreak@1 1254 if type(handler[f]) ~= "function" then
flickerstreak@1 1255 AceConsole:error("%s: %s", handler, string.format(OPTION_HANDLER_NOT_FOUND, f))
flickerstreak@1 1256 end
flickerstreak@1 1257 var = handler[f](handler, passValue)
flickerstreak@1 1258 if neg then
flickerstreak@1 1259 var = not var
flickerstreak@1 1260 end
flickerstreak@1 1261 end
flickerstreak@1 1262 if type(passTable.set) == "function" then
flickerstreak@1 1263 passTable.set(passValue, not var)
flickerstreak@1 1264 else
flickerstreak@1 1265 if type(handler[passTable.set]) ~= "function" then
flickerstreak@1 1266 AceConsole:error("%s: %s", handler, string.format(OPTION_HANDLER_NOT_FOUND, passTable.set))
flickerstreak@1 1267 end
flickerstreak@1 1268 handler[passTable.set](handler, passValue, not var)
flickerstreak@1 1269 end
flickerstreak@1 1270 if type(passTable.get) == "function" then
flickerstreak@1 1271 var = passTable.get(passValue)
flickerstreak@1 1272 else
flickerstreak@1 1273 local f = passTable.get
flickerstreak@1 1274 local neg = f:match("^~(.-)$")
flickerstreak@1 1275 if neg then
flickerstreak@1 1276 f = neg
flickerstreak@1 1277 end
flickerstreak@1 1278 var = handler[f](handler, passValue)
flickerstreak@1 1279 if neg then
flickerstreak@1 1280 var = not var
flickerstreak@1 1281 end
flickerstreak@1 1282 end
flickerstreak@1 1283 else
flickerstreak@1 1284 local handler = options.handler or self
flickerstreak@1 1285 if type(options.get) == "function" then
flickerstreak@1 1286 var = options.get()
flickerstreak@1 1287 else
flickerstreak@1 1288 local f = options.get
flickerstreak@1 1289 local neg = f:match("^~(.-)$")
flickerstreak@1 1290 if neg then
flickerstreak@1 1291 f = neg
flickerstreak@1 1292 end
flickerstreak@1 1293 if type(handler[f]) ~= "function" then
flickerstreak@1 1294 AceConsole:error("%s: %s", handler, string.format(OPTION_HANDLER_NOT_FOUND, f))
flickerstreak@1 1295 end
flickerstreak@1 1296 var = handler[f](handler)
flickerstreak@1 1297 if neg then
flickerstreak@1 1298 var = not var
flickerstreak@1 1299 end
flickerstreak@1 1300 end
flickerstreak@1 1301 if type(options.set) == "function" then
flickerstreak@1 1302 options.set(not var)
flickerstreak@1 1303 else
flickerstreak@1 1304 if type(handler[options.set]) ~= "function" then
flickerstreak@1 1305 AceConsole:error("%s: %s", handler, string.format(OPTION_HANDLER_NOT_FOUND, options.set))
flickerstreak@1 1306 end
flickerstreak@1 1307 handler[options.set](handler, not var)
flickerstreak@1 1308 end
flickerstreak@1 1309 if type(options.get) == "function" then
flickerstreak@1 1310 var = options.get()
flickerstreak@1 1311 else
flickerstreak@1 1312 local f = options.get
flickerstreak@1 1313 local neg = f:match("^~(.-)$")
flickerstreak@1 1314 if neg then
flickerstreak@1 1315 f = neg
flickerstreak@1 1316 end
flickerstreak@1 1317 var = handler[f](handler)
flickerstreak@1 1318 if neg then
flickerstreak@1 1319 var = not var
flickerstreak@1 1320 end
flickerstreak@1 1321 end
flickerstreak@1 1322 end
flickerstreak@1 1323
flickerstreak@1 1324 print(string.format(options.message or IS_NOW_SET_TO, tostring(options.cmdName or options.name), (options.map or MAP_ONOFF)[var and true or false] or NONE), realOptions.cmdName or realOptions.name or self)
flickerstreak@1 1325 elseif kind == "range" then
flickerstreak@1 1326 local arg
flickerstreak@1 1327 if #args <= 1 then
flickerstreak@1 1328 arg = args[1]
flickerstreak@1 1329 else
flickerstreak@1 1330 arg = table.concat(args, " ")
flickerstreak@1 1331 end
flickerstreak@1 1332
flickerstreak@1 1333 if arg then
flickerstreak@1 1334 local min = options.min or 0
flickerstreak@1 1335 local max = options.max or 1
flickerstreak@1 1336 local good = false
flickerstreak@1 1337 if type(arg) == "number" then
flickerstreak@1 1338 if options.isPercent then
flickerstreak@1 1339 arg = arg / 100
flickerstreak@1 1340 end
flickerstreak@1 1341
flickerstreak@1 1342 if arg >= min and arg <= max then
flickerstreak@1 1343 good = true
flickerstreak@1 1344 end
flickerstreak@1 1345
flickerstreak@1 1346 if good and type(options.step) == "number" and options.step > 0 then
flickerstreak@1 1347 local step = options.step
flickerstreak@1 1348 arg = math.floor((arg - min) / step + 0.5) * step + min
flickerstreak@1 1349 if arg > max then
flickerstreak@1 1350 arg = max
flickerstreak@1 1351 elseif arg < min then
flickerstreak@1 1352 arg = min
flickerstreak@1 1353 end
flickerstreak@1 1354 end
flickerstreak@1 1355 end
flickerstreak@1 1356 if not good then
flickerstreak@1 1357 local usage
flickerstreak@1 1358 local min = options.min or 0
flickerstreak@1 1359 local max = options.max or 1
flickerstreak@1 1360 if options.isPercent then
flickerstreak@1 1361 min, max = min * 100, max * 100
flickerstreak@1 1362 end
flickerstreak@1 1363 local bit = "-"
flickerstreak@1 1364 if min < 0 or max < 0 then
flickerstreak@1 1365 bit = " - "
flickerstreak@1 1366 end
flickerstreak@1 1367 usage = string.format("(%s%s%s)", min, bit, max)
flickerstreak@1 1368 print(string.format(options.error or IS_NOT_A_VALID_VALUE_FOR, tostring(arg), path), realOptions.cmdName or realOptions.name or self)
flickerstreak@1 1369 print(string.format("|cffffff7f%s:|r %s %s", USAGE, path, usage))
flickerstreak@1 1370 return
flickerstreak@1 1371 end
flickerstreak@1 1372
flickerstreak@1 1373 local var
flickerstreak@1 1374 if passTable then
flickerstreak@1 1375 if type(passTable.get) == "function" then
flickerstreak@1 1376 var = passTable.get(passValue)
flickerstreak@1 1377 else
flickerstreak@1 1378 if type(handler[passTable.get]) ~= "function" then
flickerstreak@1 1379 AceConsole:error("%s: %s", handler, string.format(OPTION_HANDLER_NOT_FOUND, passTable.get))
flickerstreak@1 1380 end
flickerstreak@1 1381 var = handler[passTable.get](handler, passValue)
flickerstreak@1 1382 end
flickerstreak@1 1383 else
flickerstreak@1 1384 if type(options.get) == "function" then
flickerstreak@1 1385 var = options.get()
flickerstreak@1 1386 else
flickerstreak@1 1387 local handler = options.handler or self
flickerstreak@1 1388 if type(handler[options.get]) ~= "function" then
flickerstreak@1 1389 AceConsole:error("%s: %s", handler, string.format(OPTION_HANDLER_NOT_FOUND, options.get))
flickerstreak@1 1390 end
flickerstreak@1 1391 var = handler[options.get](handler)
flickerstreak@1 1392 end
flickerstreak@1 1393 end
flickerstreak@1 1394
flickerstreak@1 1395 if var ~= arg then
flickerstreak@1 1396 if passTable then
flickerstreak@1 1397 if type(passTable.set) == "function" then
flickerstreak@1 1398 passTable.set(passValue, arg)
flickerstreak@1 1399 else
flickerstreak@1 1400 if type(handler[passTable.set]) ~= "function" then
flickerstreak@1 1401 AceConsole:error("%s: %s", handler, string.format(OPTION_HANDLER_NOT_FOUND, passTable.set))
flickerstreak@1 1402 end
flickerstreak@1 1403 handler[passTable.set](handler, passValue, arg)
flickerstreak@1 1404 end
flickerstreak@1 1405 else
flickerstreak@1 1406 if type(options.set) == "function" then
flickerstreak@1 1407 options.set(arg)
flickerstreak@1 1408 else
flickerstreak@1 1409 local handler = options.handler or self
flickerstreak@1 1410 if type(handler[options.set]) ~= "function" then
flickerstreak@1 1411 AceConsole:error("%s: %s", handler, string.format(OPTION_HANDLER_NOT_FOUND, options.set))
flickerstreak@1 1412 end
flickerstreak@1 1413 handler[options.set](handler, arg)
flickerstreak@1 1414 end
flickerstreak@1 1415 end
flickerstreak@1 1416 end
flickerstreak@1 1417 end
flickerstreak@1 1418
flickerstreak@1 1419 if arg then
flickerstreak@1 1420 local var
flickerstreak@1 1421 if passTable then
flickerstreak@1 1422 if type(passTable.get) == "function" then
flickerstreak@1 1423 var = passTable.get(passValue)
flickerstreak@1 1424 else
flickerstreak@1 1425 if type(handler[passTable.get]) ~= "function" then
flickerstreak@1 1426 AceConsole:error("%s: %s", handler, string.format(OPTION_HANDLER_NOT_FOUND, passTable.get))
flickerstreak@1 1427 end
flickerstreak@1 1428 var = handler[passTable.get](handler, passValue)
flickerstreak@1 1429 end
flickerstreak@1 1430 else
flickerstreak@1 1431 if type(options.get) == "function" then
flickerstreak@1 1432 var = options.get()
flickerstreak@1 1433 else
flickerstreak@1 1434 local handler = options.handler or self
flickerstreak@1 1435 if type(handler[options.get]) ~= "function" then
flickerstreak@1 1436 AceConsole:error("%s: %s", handler, string.format(OPTION_HANDLER_NOT_FOUND, options.get))
flickerstreak@1 1437 end
flickerstreak@1 1438 var = handler[options.get](handler)
flickerstreak@1 1439 end
flickerstreak@1 1440 end
flickerstreak@1 1441
flickerstreak@1 1442 if var and options.isPercent then
flickerstreak@1 1443 var = tostring(var * 100) .. "%"
flickerstreak@1 1444 end
flickerstreak@1 1445 print(string.format(options.message or IS_NOW_SET_TO, tostring(options.cmdName or options.name), tostring(var or NONE)), realOptions.cmdName or realOptions.name or self)
flickerstreak@1 1446 if var == arg then
flickerstreak@1 1447 return
flickerstreak@1 1448 end
flickerstreak@1 1449 else
flickerstreak@1 1450 printUsage(self, handler, realOptions, options, path, args)
flickerstreak@1 1451 return
flickerstreak@1 1452 end
flickerstreak@1 1453 elseif kind == "color" then
flickerstreak@1 1454 if #args > 0 then
flickerstreak@1 1455 local r,g,b,a
flickerstreak@1 1456 if #args == 1 then
flickerstreak@1 1457 local arg = tostring(args[1])
flickerstreak@1 1458 if options.hasAlpha then
flickerstreak@1 1459 if arg:len() == 8 and arg:find("^%x*$") then
flickerstreak@1 1460 r,g,b,a = tonumber(arg:sub(1, 2), 16) / 255, tonumber(arg:sub(3, 4), 16) / 255, tonumber(arg:sub(5, 6), 16) / 255, tonumber(arg:sub(7, 8), 16) / 255
flickerstreak@1 1461 end
flickerstreak@1 1462 else
flickerstreak@1 1463 if arg:len() == 6 and arg:find("^%x*$") then
flickerstreak@1 1464 r,g,b = tonumber(arg:sub(1, 2), 16) / 255, tonumber(arg:sub(3, 4), 16) / 255, tonumber(arg:sub(5, 6), 16) / 255
flickerstreak@1 1465 end
flickerstreak@1 1466 end
flickerstreak@1 1467 elseif #args == 4 and options.hasAlpha then
flickerstreak@1 1468 local a1,a2,a3,a4 = args[1], args[2], args[3], args[4]
flickerstreak@1 1469 if type(a1) == "number" and type(a2) == "number" and type(a3) == "number" and type(a4) == "number" and a1 <= 1 and a2 <= 1 and a3 <= 1 and a4 <= 1 then
flickerstreak@1 1470 r,g,b,a = a1,a2,a3,a4
flickerstreak@1 1471 elseif (type(a1) == "number" or a1:len() == 2) and a1:find("^%x*$") and (type(a2) == "number" or a2:len() == 2) and a2:find("^%x*$") and (type(a3) == "number" or a3:len() == 2) and a3:find("^%x*$") and (type(a4) == "number" or a4:len() == 2) and a4:find("^%x*$") then
flickerstreak@1 1472 r,g,b,a = tonumber(a1, 16) / 255, tonumber(a2, 16) / 255, tonumber(a3, 16) / 255, tonumber(a4, 16) / 255
flickerstreak@1 1473 end
flickerstreak@1 1474 elseif #args == 3 and not options.hasAlpha then
flickerstreak@1 1475 local a1,a2,a3 = args[1], args[2], args[3]
flickerstreak@1 1476 if type(a1) == "number" and type(a2) == "number" and type(a3) == "number" and a1 <= 1 and a2 <= 1 and a3 <= 1 then
flickerstreak@1 1477 r,g,b = a1,a2,a3
flickerstreak@1 1478 elseif (type(a1) == "number" or a1:len() == 2) and a1:find("^%x*$") and (type(a2) == "number" or a2:len() == 2) and a2:find("^%x*$") and (type(a3) == "number" or a3:len() == 2) and a3:find("^%x*$") then
flickerstreak@1 1479 r,g,b = tonumber(a1, 16) / 255, tonumber(a2, 16) / 255, tonumber(a3, 16) / 255
flickerstreak@1 1480 end
flickerstreak@1 1481 end
flickerstreak@1 1482 if not r then
flickerstreak@1 1483 print(string.format(options.error or IS_NOT_A_VALID_OPTION_FOR, table.concat(args, ' '), path), realOptions.cmdName or realOptions.name or self)
flickerstreak@1 1484 print(string.format("|cffffff7f%s:|r %s {0-1} {0-1} {0-1}%s", USAGE, path, options.hasAlpha and " {0-1}" or ""))
flickerstreak@1 1485 return
flickerstreak@1 1486 end
flickerstreak@1 1487 if passTable then
flickerstreak@1 1488 if type(passTable.set) == "function" then
flickerstreak@1 1489 passTable.set(passValue, r,g,b,a)
flickerstreak@1 1490 else
flickerstreak@1 1491 if type(handler[passTable.set]) ~= "function" then
flickerstreak@1 1492 AceConsole:error("%s: %s", handler, string.format(OPTION_HANDLER_NOT_FOUND, passTable.set))
flickerstreak@1 1493 end
flickerstreak@1 1494 handler[passTable.set](handler, passValue, r,g,b,a)
flickerstreak@1 1495 end
flickerstreak@1 1496 else
flickerstreak@1 1497 if type(options.set) == "function" then
flickerstreak@1 1498 options.set(r,g,b,a)
flickerstreak@1 1499 else
flickerstreak@1 1500 if type(handler[options.set]) ~= "function" then
flickerstreak@1 1501 AceConsole:error("%s: %s", handler, string.format(OPTION_HANDLER_NOT_FOUND, options.set))
flickerstreak@1 1502 end
flickerstreak@1 1503 handler[options.set](handler, r,g,b,a)
flickerstreak@1 1504 end
flickerstreak@1 1505 end
flickerstreak@1 1506
flickerstreak@1 1507 local r,g,b,a
flickerstreak@1 1508 if passTable then
flickerstreak@1 1509 if type(passTable.get) == "function" then
flickerstreak@1 1510 r,g,b,a = passTable.get(passValue)
flickerstreak@1 1511 else
flickerstreak@1 1512 if type(handler[passTable.get]) ~= "function" then
flickerstreak@1 1513 AceConsole:error("%s: %s", handler, string.format(OPTION_HANDLER_NOT_FOUND, passTable.get))
flickerstreak@1 1514 end
flickerstreak@1 1515 r,g,b,a = handler[passTable.get](handler, passValue)
flickerstreak@1 1516 end
flickerstreak@1 1517 else
flickerstreak@1 1518 if type(options.get) == "function" then
flickerstreak@1 1519 r,g,b,a = options.get()
flickerstreak@1 1520 else
flickerstreak@1 1521 if type(handler[options.get]) ~= "function" then
flickerstreak@1 1522 AceConsole:error("%s: %s", handler, string.format(OPTION_HANDLER_NOT_FOUND, options.get))
flickerstreak@1 1523 end
flickerstreak@1 1524 r,g,b,a = handler[options.get](handler)
flickerstreak@1 1525 end
flickerstreak@1 1526 end
flickerstreak@1 1527
flickerstreak@1 1528 local s
flickerstreak@1 1529 if type(r) == "number" and type(g) == "number" and type(b) == "number" then
flickerstreak@1 1530 if options.hasAlpha and type(a) == "number" then
flickerstreak@1 1531 s = string.format("|c%02x%02x%02x%02x%02x%02x%02x%02x|r", a*255, r*255, g*255, b*255, r*255, g*255, b*255, a*255)
flickerstreak@1 1532 else
flickerstreak@1 1533 s = string.format("|cff%02x%02x%02x%02x%02x%02x|r", r*255, g*255, b*255, r*255, g*255, b*255)
flickerstreak@1 1534 end
flickerstreak@1 1535 else
flickerstreak@1 1536 s = NONE
flickerstreak@1 1537 end
flickerstreak@1 1538 print(string.format(options.message or IS_NOW_SET_TO, tostring(options.cmdName or options.name), s), realOptions.cmdName or realOptions.name or self)
flickerstreak@1 1539 else
flickerstreak@1 1540 local r,g,b,a
flickerstreak@1 1541 if passTable then
flickerstreak@1 1542 if type(passTable.get) == "function" then
flickerstreak@1 1543 r,g,b,a = passTable.get(passValue)
flickerstreak@1 1544 else
flickerstreak@1 1545 if type(handler[passTable.get]) ~= "function" then
flickerstreak@1 1546 AceConsole:error("%s: %s", handler, string.format(OPTION_HANDLER_NOT_FOUND, passTable.get))
flickerstreak@1 1547 end
flickerstreak@1 1548 r,g,b,a = handler[passTable.get](handler, passValue)
flickerstreak@1 1549 end
flickerstreak@1 1550 else
flickerstreak@1 1551 if type(options.get) == "function" then
flickerstreak@1 1552 r,g,b,a = options.get()
flickerstreak@1 1553 else
flickerstreak@1 1554 if type(handler[options.get]) ~= "function" then
flickerstreak@1 1555 AceConsole:error("%s: %s", handler, string.format(OPTION_HANDLER_NOT_FOUND, options.get))
flickerstreak@1 1556 end
flickerstreak@1 1557 r,g,b,a = handler[options.get](handler)
flickerstreak@1 1558 end
flickerstreak@1 1559 end
flickerstreak@1 1560
flickerstreak@1 1561 if not colorTable then
flickerstreak@1 1562 colorTable = {}
flickerstreak@1 1563 local t = colorTable
flickerstreak@1 1564
flickerstreak@1 1565 if ColorPickerOkayButton then
flickerstreak@1 1566 local ColorPickerOkayButton_OnClick = ColorPickerOkayButton:GetScript("OnClick")
flickerstreak@1 1567 ColorPickerOkayButton:SetScript("OnClick", function()
flickerstreak@1 1568 if ColorPickerOkayButton_OnClick then
flickerstreak@1 1569 ColorPickerOkayButton_OnClick()
flickerstreak@1 1570 end
flickerstreak@1 1571 if t.active then
flickerstreak@1 1572 ColorPickerFrame.cancelFunc = nil
flickerstreak@1 1573 ColorPickerFrame.func = nil
flickerstreak@1 1574 ColorPickerFrame.opacityFunc = nil
flickerstreak@1 1575 local r,g,b,a
flickerstreak@1 1576 if t.passValue then
flickerstreak@1 1577 if type(t.get) == "function" then
flickerstreak@1 1578 r,g,b,a = t.get(t.passValue)
flickerstreak@1 1579 else
flickerstreak@1 1580 if type(t.handler[t.get]) ~= "function" then
flickerstreak@1 1581 AceConsole:error("%s: %s", handler, string.format(OPTION_HANDLER_NOT_FOUND, t.get))
flickerstreak@1 1582 end
flickerstreak@1 1583 r,g,b,a = t.handler[t.get](t.handler, t.passValue)
flickerstreak@1 1584 end
flickerstreak@1 1585 else
flickerstreak@1 1586 if type(t.get) == "function" then
flickerstreak@1 1587 r,g,b,a = t.get()
flickerstreak@1 1588 else
flickerstreak@1 1589 if type(t.handler[t.get]) ~= "function" then
flickerstreak@1 1590 AceConsole:error("%s: %s", handler, string.format(OPTION_HANDLER_NOT_FOUND, t.get))
flickerstreak@1 1591 end
flickerstreak@1 1592 r,g,b,a = t.handler[t.get](t.handler)
flickerstreak@1 1593 end
flickerstreak@1 1594 end
flickerstreak@1 1595 if r ~= t.r or g ~= t.g or b ~= t.b or (t.hasAlpha and a ~= t.a) then
flickerstreak@1 1596 local s
flickerstreak@1 1597 if type(r) == "number" and type(g) == "number" and type(b) == "number" then
flickerstreak@1 1598 if t.hasAlpha and type(a) == "number" then
flickerstreak@1 1599 s = string.format("|c%02x%02x%02x%02x%02x%02x%02x%02x|r", a*255, r*255, g*255, b*255, r*255, g*255, b*255, a*255)
flickerstreak@1 1600 else
flickerstreak@1 1601 s = string.format("|cff%02x%02x%02x%02x%02x%02x|r", r*255, g*255, b*255, r*255, g*255, b*255)
flickerstreak@1 1602 end
flickerstreak@1 1603 else
flickerstreak@1 1604 s = NONE
flickerstreak@1 1605 end
flickerstreak@1 1606 print(string.format(t.message, tostring(t.name), s), t.realOptions.cmdName or t.realOptions.name or self)
flickerstreak@1 1607 end
flickerstreak@1 1608 for k,v in pairs(t) do
flickerstreak@1 1609 t[k] = nil
flickerstreak@1 1610 end
flickerstreak@1 1611 end
flickerstreak@1 1612 end)
flickerstreak@1 1613 end
flickerstreak@1 1614 else
flickerstreak@1 1615 for k,v in pairs(colorTable) do
flickerstreak@1 1616 colorTable[k] = nil
flickerstreak@1 1617 end
flickerstreak@1 1618 end
flickerstreak@1 1619
flickerstreak@1 1620 if type(r) ~= "number" or type(g) ~= "number" or type(b) ~= "number" then
flickerstreak@1 1621 r,g,b = 1, 1, 1
flickerstreak@1 1622 end
flickerstreak@1 1623 if type(a) ~= "number" then
flickerstreak@1 1624 a = 1
flickerstreak@1 1625 end
flickerstreak@1 1626 local t = colorTable
flickerstreak@1 1627 t.r = r
flickerstreak@1 1628 t.g = g
flickerstreak@1 1629 t.b = b
flickerstreak@1 1630 if hasAlpha then
flickerstreak@1 1631 t.a = a
flickerstreak@1 1632 end
flickerstreak@1 1633 t.realOptions = realOptions
flickerstreak@1 1634 t.hasAlpha = options.hasAlpha
flickerstreak@1 1635 t.handler = handler
flickerstreak@1 1636 t.set = passTable and passTable.set or options.set
flickerstreak@1 1637 t.get = passTable and passTable.get or options.get
flickerstreak@1 1638 t.name = options.cmdName or options.name
flickerstreak@1 1639 t.message = options.message or IS_NOW_SET_TO
flickerstreak@1 1640 t.passValue = passValue
flickerstreak@1 1641 t.active = true
flickerstreak@1 1642
flickerstreak@1 1643 if not colorFunc then
flickerstreak@1 1644 colorFunc = function()
flickerstreak@1 1645 local r,g,b = ColorPickerFrame:GetColorRGB()
flickerstreak@1 1646 if t.hasAlpha then
flickerstreak@1 1647 local a = 1 - OpacitySliderFrame:GetValue()
flickerstreak@1 1648 if type(t.set) == "function" then
flickerstreak@1 1649 if t.passValue then
flickerstreak@1 1650 t.set(t.passValue, r,g,b,a)
flickerstreak@1 1651 else
flickerstreak@1 1652 t.set(r,g,b,a)
flickerstreak@1 1653 end
flickerstreak@1 1654 else
flickerstreak@1 1655 if type(t.handler[t.set]) ~= "function" then
flickerstreak@1 1656 AceConsole:error("%s: %s", handler, string.format(OPTION_HANDLER_NOT_FOUND, t.set))
flickerstreak@1 1657 end
flickerstreak@1 1658 if t.passValue then
flickerstreak@1 1659 t.handler[t.set](t.handler, t.passValue, r,g,b,a)
flickerstreak@1 1660 else
flickerstreak@1 1661 t.handler[t.set](t.handler, r,g,b,a)
flickerstreak@1 1662 end
flickerstreak@1 1663 end
flickerstreak@1 1664 else
flickerstreak@1 1665 if type(t.set) == "function" then
flickerstreak@1 1666 if t.passValue then
flickerstreak@1 1667 t.set(t.passValue, r,g,b)
flickerstreak@1 1668 else
flickerstreak@1 1669 t.set(r,g,b)
flickerstreak@1 1670 end
flickerstreak@1 1671 else
flickerstreak@1 1672 if type(t.handler[t.set]) ~= "function" then
flickerstreak@1 1673 AceConsole:error("%s: %s", handler, string.format(OPTION_HANDLER_NOT_FOUND, t.set))
flickerstreak@1 1674 end
flickerstreak@1 1675 if t.passValue then
flickerstreak@1 1676 t.handler[t.set](t.handler, t.passValue, r,g,b)
flickerstreak@1 1677 else
flickerstreak@1 1678 t.handler[t.set](t.handler, r,g,b)
flickerstreak@1 1679 end
flickerstreak@1 1680 end
flickerstreak@1 1681 end
flickerstreak@1 1682 end
flickerstreak@1 1683 end
flickerstreak@1 1684
flickerstreak@1 1685 ColorPickerFrame.func = colorFunc
flickerstreak@1 1686 ColorPickerFrame.hasOpacity = options.hasAlpha
flickerstreak@1 1687 if options.hasAlpha then
flickerstreak@1 1688 ColorPickerFrame.opacityFunc = ColorPickerFrame.func
flickerstreak@1 1689 ColorPickerFrame.opacity = 1 - a
flickerstreak@1 1690 end
flickerstreak@1 1691 ColorPickerFrame:SetColorRGB(r,g,b)
flickerstreak@1 1692
flickerstreak@1 1693 if not colorCancelFunc then
flickerstreak@1 1694 colorCancelFunc = function()
flickerstreak@1 1695 if t.hasAlpha then
flickerstreak@1 1696 if type(t.set) == "function" then
flickerstreak@1 1697 if t.passValue then
flickerstreak@1 1698 t.set(t.passValue, t.r,t.g,t.b,t.a)
flickerstreak@1 1699 else
flickerstreak@1 1700 t.set(t.r,t.g,t.b,t.a)
flickerstreak@1 1701 end
flickerstreak@1 1702 else
flickerstreak@1 1703 if type(t.handler[t.get]) ~= "function" then
flickerstreak@1 1704 AceConsole:error("%s: %s", handler, string.format(OPTION_HANDLER_NOT_FOUND, t.get))
flickerstreak@1 1705 end
flickerstreak@1 1706 if t.passValue then
flickerstreak@1 1707 t.handler[t.set](t.handler, t.passValue, t.r,t.g,t.b,t.a)
flickerstreak@1 1708 else
flickerstreak@1 1709 t.handler[t.set](t.handler, t.r,t.g,t.b,t.a)
flickerstreak@1 1710 end
flickerstreak@1 1711 end
flickerstreak@1 1712 else
flickerstreak@1 1713 if type(t.set) == "function" then
flickerstreak@1 1714 if t.passValue then
flickerstreak@1 1715 t.set(t.passValue, t.r,t.g,t.b)
flickerstreak@1 1716 else
flickerstreak@1 1717 t.set(t.r,t.g,t.b)
flickerstreak@1 1718 end
flickerstreak@1 1719 else
flickerstreak@1 1720 if type(t.handler[t.set]) ~= "function" then
flickerstreak@1 1721 AceConsole:error("%s: %s", handler, string.format(OPTION_HANDLER_NOT_FOUND, t.set))
flickerstreak@1 1722 end
flickerstreak@1 1723 if t.passValue then
flickerstreak@1 1724 t.handler[t.set](t.handler, t.passValue, t.r,t.g,t.b)
flickerstreak@1 1725 else
flickerstreak@1 1726 t.handler[t.set](t.handler, t.r,t.g,t.b)
flickerstreak@1 1727 end
flickerstreak@1 1728 end
flickerstreak@1 1729 end
flickerstreak@1 1730 for k,v in pairs(t) do
flickerstreak@1 1731 t[k] = nil
flickerstreak@1 1732 end
flickerstreak@1 1733 ColorPickerFrame.cancelFunc = nil
flickerstreak@1 1734 ColorPickerFrame.func = nil
flickerstreak@1 1735 ColorPickerFrame.opacityFunc = nil
flickerstreak@1 1736 end
flickerstreak@1 1737 end
flickerstreak@1 1738
flickerstreak@1 1739 ColorPickerFrame.cancelFunc = colorCancelFunc
flickerstreak@1 1740
flickerstreak@1 1741 ShowUIPanel(ColorPickerFrame)
flickerstreak@1 1742 end
flickerstreak@1 1743 return
flickerstreak@1 1744 elseif kind == "group" then
flickerstreak@1 1745 if #args == 0 then
flickerstreak@1 1746 printUsage(self, handler, realOptions, options, path, args)
flickerstreak@1 1747 else
flickerstreak@1 1748 -- invalid argument
flickerstreak@1 1749 print(string.format(options.error or IS_NOT_A_VALID_OPTION_FOR, args[1], path), realOptions.cmdName or realOptions.name or self)
flickerstreak@1 1750 end
flickerstreak@1 1751 return
flickerstreak@1 1752 end
flickerstreak@1 1753 this = _G_this
flickerstreak@1 1754 if Dewdrop then
flickerstreak@1 1755 Dewdrop:Refresh(1)
flickerstreak@1 1756 Dewdrop:Refresh(2)
flickerstreak@1 1757 Dewdrop:Refresh(3)
flickerstreak@1 1758 Dewdrop:Refresh(4)
flickerstreak@1 1759 Dewdrop:Refresh(5)
flickerstreak@1 1760 end
flickerstreak@1 1761 end
flickerstreak@1 1762
flickerstreak@1 1763 local external
flickerstreak@1 1764 function AceConsole:RegisterChatCommand(slashCommands, options, name)
flickerstreak@1 1765 if type(slashCommands) ~= "table" and slashCommands ~= false then
flickerstreak@1 1766 AceConsole:error("Bad argument #2 to `RegisterChatCommand' (expected table, got %s)", type(slashCommands))
flickerstreak@1 1767 end
flickerstreak@1 1768 if not slashCommands and type(name) ~= "string" then
flickerstreak@1 1769 AceConsole:error("Bad argument #4 to `RegisterChatCommand' (expected string, got %s)", type(name))
flickerstreak@1 1770 end
flickerstreak@1 1771 if type(options) ~= "table" and type(options) ~= "function" and options ~= nil then
flickerstreak@1 1772 AceConsole:error("Bad argument #3 to `RegisterChatCommand' (expected table, function, or nil, got %s)", type(options))
flickerstreak@1 1773 end
flickerstreak@1 1774 if name then
flickerstreak@1 1775 if type(name) ~= "string" then
flickerstreak@1 1776 AceConsole:error("Bad argument #4 to `RegisterChatCommand' (expected string or nil, got %s)", type(name))
flickerstreak@1 1777 elseif not name:find("^%w+$") or name:upper() ~= name or name:len() == 0 then
flickerstreak@1 1778 AceConsole:error("Argument #4 must be an uppercase, letters-only string with at least 1 character")
flickerstreak@1 1779 end
flickerstreak@1 1780 end
flickerstreak@1 1781 if slashCommands then
flickerstreak@1 1782 if #slashCommands == 0 then
flickerstreak@1 1783 AceConsole:error("Argument #2 to `RegisterChatCommand' must include at least one string")
flickerstreak@1 1784 end
flickerstreak@1 1785
flickerstreak@1 1786 for k,v in pairs(slashCommands) do
flickerstreak@1 1787 if type(k) ~= "number" then
flickerstreak@1 1788 AceConsole:error("All keys in argument #2 to `RegisterChatCommand' must be numbers")
flickerstreak@1 1789 end
flickerstreak@1 1790 if type(v) ~= "string" then
flickerstreak@1 1791 AceConsole:error("All values in argument #2 to `RegisterChatCommand' must be strings")
flickerstreak@1 1792 elseif not v:find("^/[A-Za-z][A-Za-z0-9_]*$") then
flickerstreak@1 1793 AceConsole:error("All values in argument #2 to `RegisterChatCommand' must be in the form of \"/word\"")
flickerstreak@1 1794 end
flickerstreak@1 1795 end
flickerstreak@1 1796 end
flickerstreak@1 1797
flickerstreak@1 1798 if not options then
flickerstreak@1 1799 options = {
flickerstreak@1 1800 type = 'group',
flickerstreak@1 1801 args = {},
flickerstreak@1 1802 handler = self
flickerstreak@1 1803 }
flickerstreak@1 1804 end
flickerstreak@1 1805
flickerstreak@1 1806 if type(options) == "table" then
flickerstreak@1 1807 local err, position = validateOptions(options)
flickerstreak@1 1808 if err then
flickerstreak@1 1809 if position then
flickerstreak@1 1810 AceConsole:error(position .. ": " .. err)
flickerstreak@1 1811 else
flickerstreak@1 1812 AceConsole:error(err)
flickerstreak@1 1813 end
flickerstreak@1 1814 end
flickerstreak@1 1815
flickerstreak@1 1816 if not options.handler then
flickerstreak@1 1817 options.handler = self
flickerstreak@1 1818 end
flickerstreak@1 1819
flickerstreak@1 1820 if options.handler == self and options.type:lower() == "group" and self.class then
flickerstreak@1 1821 AceConsole:InjectAceOptionsTable(self, options)
flickerstreak@1 1822 end
flickerstreak@1 1823 end
flickerstreak@1 1824
flickerstreak@1 1825 local chat
flickerstreak@1 1826 if slashCommands then
flickerstreak@1 1827 chat = slashCommands[1]
flickerstreak@1 1828 else
flickerstreak@1 1829 chat = _G["SLASH_"..name..1]
flickerstreak@1 1830 end
flickerstreak@1 1831
flickerstreak@1 1832 local handler
flickerstreak@1 1833 if type(options) == "function" then
flickerstreak@1 1834 handler = options
flickerstreak@1 1835 for k,v in pairs(_G) do
flickerstreak@1 1836 if handler == v then
flickerstreak@1 1837 local k = k
flickerstreak@1 1838 handler = function(msg)
flickerstreak@1 1839 return _G[k](msg)
flickerstreak@1 1840 end
flickerstreak@1 1841 end
flickerstreak@1 1842 end
flickerstreak@1 1843 else
flickerstreak@1 1844 function handler(msg)
flickerstreak@1 1845 handlerFunc(self, chat, msg, options)
flickerstreak@1 1846 end
flickerstreak@1 1847 end
flickerstreak@1 1848
flickerstreak@1 1849 if not _G.SlashCmdList then
flickerstreak@1 1850 _G.SlashCmdList = {}
flickerstreak@1 1851 end
flickerstreak@1 1852
flickerstreak@1 1853 if not name then
flickerstreak@1 1854 local A = ('A'):byte()
flickerstreak@1 1855 repeat
flickerstreak@1 1856 name = string.char(math.random(26) + A - 1) .. string.char(math.random(26) + A - 1) .. string.char(math.random(26) + A - 1) .. string.char(math.random(26) + A - 1) .. string.char(math.random(26) + A - 1) .. string.char(math.random(26) + A - 1) .. string.char(math.random(26) + A - 1) .. string.char(math.random(26) + A - 1)
flickerstreak@1 1857 until not _G.SlashCmdList[name]
flickerstreak@1 1858 end
flickerstreak@1 1859
flickerstreak@1 1860 if slashCommands then
flickerstreak@1 1861 if _G.SlashCmdList[name] then
flickerstreak@1 1862 local i = 0
flickerstreak@1 1863 while true do
flickerstreak@1 1864 i = i + 1
flickerstreak@1 1865 if _G["SLASH_"..name..i] then
flickerstreak@1 1866 _G["SLASH_"..name..i] = nil
flickerstreak@1 1867 else
flickerstreak@1 1868 break
flickerstreak@1 1869 end
flickerstreak@1 1870 end
flickerstreak@1 1871 end
flickerstreak@1 1872
flickerstreak@1 1873 local i = 0
flickerstreak@1 1874 for _,command in ipairs(slashCommands) do
flickerstreak@1 1875 i = i + 1
flickerstreak@1 1876 _G["SLASH_"..name..i] = command
flickerstreak@1 1877 if command:lower() ~= command then
flickerstreak@1 1878 i = i + 1
flickerstreak@1 1879 _G["SLASH_"..name..i] = command:lower()
flickerstreak@1 1880 end
flickerstreak@1 1881 end
flickerstreak@1 1882 end
flickerstreak@1 1883 _G.SlashCmdList[name] = handler
flickerstreak@1 1884 if self ~= AceConsole and self.slashCommand == nil then
flickerstreak@1 1885 self.slashCommand = chat
flickerstreak@1 1886 end
flickerstreak@1 1887
flickerstreak@1 1888 if not AceEvent and AceLibrary:HasInstance("AceEvent-2.0") then
flickerstreak@1 1889 external(AceConsole, "AceEvent-2.0", AceLibrary("AceEvent-2.0"))
flickerstreak@1 1890 end
flickerstreak@1 1891 if AceEvent then
flickerstreak@1 1892 if not AceConsole.nextAddon then
flickerstreak@1 1893 AceConsole.nextAddon = {}
flickerstreak@1 1894 end
flickerstreak@1 1895 if type(options) == "table" then
flickerstreak@1 1896 AceConsole.nextAddon[self] = options
flickerstreak@1 1897 if not self.playerLogin then
flickerstreak@1 1898 AceConsole:RegisterEvent("PLAYER_LOGIN", "PLAYER_LOGIN", true)
flickerstreak@1 1899 end
flickerstreak@1 1900 end
flickerstreak@1 1901 end
flickerstreak@1 1902
flickerstreak@1 1903 AceConsole.registry[name] = options
flickerstreak@1 1904 end
flickerstreak@1 1905
flickerstreak@1 1906 function AceConsole:InjectAceOptionsTable(handler, options)
flickerstreak@1 1907 self:argCheck(handler, 2, "table")
flickerstreak@1 1908 self:argCheck(options, 3, "table")
flickerstreak@1 1909 if options.type:lower() ~= "group" then
flickerstreak@1 1910 self:error('Cannot inject into options table argument #3 if its type is not "group"')
flickerstreak@1 1911 end
flickerstreak@1 1912 if options.handler ~= nil and options.handler ~= handler then
flickerstreak@1 1913 self:error("Cannot inject into options table argument #3 if it has a different handler than argument #2")
flickerstreak@1 1914 end
flickerstreak@1 1915 options.handler = handler
flickerstreak@1 1916 local class = handler.class
flickerstreak@1 1917 if not class then
flickerstreak@1 1918 self:error("Cannot retrieve AceOptions tables from a non-object argument #2")
flickerstreak@1 1919 end
flickerstreak@1 1920 while class and class ~= AceOO.Class do
flickerstreak@1 1921 if type(class.GetAceOptionsDataTable) == "function" then
flickerstreak@1 1922 local t = class:GetAceOptionsDataTable(handler)
flickerstreak@1 1923 for k,v in pairs(t) do
flickerstreak@1 1924 if type(options.args) ~= "table" then
flickerstreak@1 1925 options.args = {}
flickerstreak@1 1926 end
flickerstreak@1 1927 if options.args[k] == nil then
flickerstreak@1 1928 options.args[k] = v
flickerstreak@1 1929 end
flickerstreak@1 1930 end
flickerstreak@1 1931 end
flickerstreak@1 1932 local mixins = class.mixins
flickerstreak@1 1933 if mixins then
flickerstreak@1 1934 for mixin in pairs(mixins) do
flickerstreak@1 1935 if type(mixin.GetAceOptionsDataTable) == "function" then
flickerstreak@1 1936 local t = mixin:GetAceOptionsDataTable(handler)
flickerstreak@1 1937 for k,v in pairs(t) do
flickerstreak@1 1938 if type(options.args) ~= "table" then
flickerstreak@1 1939 options.args = {}
flickerstreak@1 1940 end
flickerstreak@1 1941 if options.args[k] == nil then
flickerstreak@1 1942 options.args[k] = v
flickerstreak@1 1943 end
flickerstreak@1 1944 end
flickerstreak@1 1945 end
flickerstreak@1 1946 end
flickerstreak@1 1947 end
flickerstreak@1 1948 class = class.super
flickerstreak@1 1949 end
flickerstreak@1 1950 return options
flickerstreak@1 1951 end
flickerstreak@1 1952
flickerstreak@1 1953 function AceConsole:PLAYER_LOGIN()
flickerstreak@1 1954 self.playerLogin = true
flickerstreak@1 1955 for addon, options in pairs(self.nextAddon) do
flickerstreak@1 1956 local err, position = validateOptionsMethods(addon, options)
flickerstreak@1 1957 if err then
flickerstreak@1 1958 if position then
flickerstreak@1 1959 geterrorhandler()(tostring(addon) .. ": AceConsole: " .. position .. ": " .. err)
flickerstreak@1 1960 else
flickerstreak@1 1961 geterrorhandler()(tostring(addon) .. ": AceConsole: " .. err)
flickerstreak@1 1962 end
flickerstreak@1 1963 end
flickerstreak@1 1964 self.nextAddon[addon] = nil
flickerstreak@1 1965 end
flickerstreak@1 1966 end
flickerstreak@1 1967
flickerstreak@1 1968 function AceConsole:TabCompleteInfo(cmdpath)
flickerstreak@1 1969 local cmd = cmdpath:match("(/%S+)")
flickerstreak@1 1970 if not cmd then
flickerstreak@1 1971 return
flickerstreak@1 1972 end
flickerstreak@1 1973 local path = cmdpath:sub(cmd:len() + 2)
flickerstreak@1 1974 for name in pairs(SlashCmdList) do --global
flickerstreak@1 1975 if AceConsole.registry[name] then
flickerstreak@1 1976 local i = 0
flickerstreak@1 1977 while true do
flickerstreak@1 1978 i = i + 1
flickerstreak@1 1979 local scmd = _G["SLASH_"..name..i]
flickerstreak@1 1980 if not scmd then break end
flickerstreak@1 1981 if cmd == scmd then
flickerstreak@1 1982 return name, cmd, path
flickerstreak@1 1983 end
flickerstreak@1 1984 end
flickerstreak@1 1985 end
flickerstreak@1 1986 end
flickerstreak@1 1987 end
flickerstreak@1 1988
flickerstreak@1 1989 function external(self, major, instance)
flickerstreak@1 1990 if major == "AceEvent-2.0" then
flickerstreak@1 1991 if not AceEvent then
flickerstreak@1 1992 AceEvent = instance
flickerstreak@1 1993
flickerstreak@1 1994 AceEvent:embed(self)
flickerstreak@1 1995 end
flickerstreak@1 1996 elseif major == "AceTab-2.0" then
flickerstreak@1 1997 instance:RegisterTabCompletion("AceConsole", "%/.*", function(t, cmdpath, pos)
flickerstreak@1 1998 local ac = AceLibrary("AceConsole-2.0")
flickerstreak@1 1999 local name, cmd, path = ac:TabCompleteInfo(cmdpath:sub(1, pos))
flickerstreak@1 2000
flickerstreak@1 2001 if not ac.registry[name] then
flickerstreak@1 2002 return false
flickerstreak@1 2003 else
flickerstreak@1 2004 local validArgs = findTableLevel(ac, ac.registry[name], cmd, path or "")
flickerstreak@1 2005 if validArgs.args then
flickerstreak@1 2006 for arg in pairs(validArgs.args) do
flickerstreak@1 2007 table.insert(t, arg)
flickerstreak@1 2008 end
flickerstreak@1 2009 end
flickerstreak@1 2010 end
flickerstreak@1 2011 end, function(u, matches, gcs, cmdpath)
flickerstreak@1 2012 local ac = AceLibrary("AceConsole-2.0")
flickerstreak@1 2013 local name, cmd, path = ac:TabCompleteInfo(cmdpath)
flickerstreak@1 2014 if ac.registry[name] then
flickerstreak@1 2015 local validArgs, path2, argwork = findTableLevel(ac, ac.registry[name], cmd, path)
flickerstreak@1 2016 printUsage(ac, validArgs.handler, ac.registry[name], validArgs, path2, argwork, not gcs or gcs ~= "", gcs)
flickerstreak@1 2017 end
flickerstreak@1 2018 end)
flickerstreak@1 2019 elseif major == "Dewdrop-2.0" then
flickerstreak@1 2020 Dewdrop = instance
flickerstreak@1 2021 end
flickerstreak@1 2022 end
flickerstreak@1 2023
flickerstreak@1 2024 local function activate(self, oldLib, oldDeactivate)
flickerstreak@1 2025 AceConsole = self
flickerstreak@1 2026
flickerstreak@1 2027 if oldLib then
flickerstreak@1 2028 self.registry = oldLib.registry
flickerstreak@1 2029 self.nextAddon = oldLib.nextAddon
flickerstreak@1 2030 end
flickerstreak@1 2031
flickerstreak@1 2032 if not self.registry then
flickerstreak@1 2033 self.registry = {}
flickerstreak@1 2034 else
flickerstreak@1 2035 for name,options in pairs(self.registry) do
flickerstreak@1 2036 self:RegisterChatCommand(false, options, name)
flickerstreak@1 2037 end
flickerstreak@1 2038 end
flickerstreak@1 2039
flickerstreak@1 2040 self:RegisterChatCommand({ "/reload", "/rl", "/reloadui" }, ReloadUI, "RELOAD")
flickerstreak@1 2041
flickerstreak@1 2042 self:RegisterChatCommand({ "/print" }, function(text)
flickerstreak@1 2043 local f, err = loadstring("AceLibrary('AceConsole-2.0'):PrintComma(" .. text .. ")")
flickerstreak@1 2044 if not f then
flickerstreak@1 2045 self:Print("|cffff0000Error:|r", err)
flickerstreak@1 2046 else
flickerstreak@1 2047 f()
flickerstreak@1 2048 end
flickerstreak@1 2049 end, "PRINT")
flickerstreak@1 2050
flickerstreak@1 2051 self:activate(oldLib, oldDeactivate)
flickerstreak@1 2052
flickerstreak@1 2053 if oldDeactivate then
flickerstreak@1 2054 oldDeactivate(oldLib)
flickerstreak@1 2055 end
flickerstreak@1 2056 end
flickerstreak@1 2057
flickerstreak@1 2058 AceLibrary:Register(AceConsole, MAJOR_VERSION, MINOR_VERSION, activate, nil, external)