flickerstreak@22
|
1 --[[
|
flickerstreak@1
|
2 Name: AceConsole-2.0
|
flickerstreak@22
|
3 Revision: $Rev: 48940 $
|
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@22
|
8 SVN: http://svn.wowace.com/wowace/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@22
|
11 http://www.wowace.com/index.php/AceOptions_data_table
|
flickerstreak@1
|
12 Dependencies: AceLibrary, AceOO-2.0
|
flickerstreak@22
|
13 License: LGPL v2.1
|
flickerstreak@1
|
14 ]]
|
flickerstreak@1
|
15
|
flickerstreak@1
|
16 local MAJOR_VERSION = "AceConsole-2.0"
|
flickerstreak@22
|
17 local MINOR_VERSION = "$Revision: 48940 $"
|
flickerstreak@1
|
18
|
flickerstreak@1
|
19 if not AceLibrary then error(MAJOR_VERSION .. " requires AceLibrary.") end
|
flickerstreak@1
|
20 if not AceLibrary:IsNewVersion(MAJOR_VERSION, MINOR_VERSION) then return end
|
flickerstreak@1
|
21
|
flickerstreak@1
|
22 if not AceLibrary:HasInstance("AceOO-2.0") then error(MAJOR_VERSION .. " requires AceOO-2.0.") end
|
flickerstreak@1
|
23
|
flickerstreak@22
|
24 -- #AUTODOC_NAMESPACE AceConsole
|
flickerstreak@22
|
25
|
flickerstreak@22
|
26 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, DEFAULT_CONFIRM_MESSAGE
|
flickerstreak@1
|
27 if GetLocale() == "deDE" then
|
flickerstreak@1
|
28 MAP_ONOFF = { [false] = "|cffff0000Aus|r", [true] = "|cff00ff00An|r" }
|
flickerstreak@1
|
29 USAGE = "Benutzung"
|
flickerstreak@1
|
30 IS_CURRENTLY_SET_TO = "|cffffff7f%s|r steht momentan auf |cffffff7f[|r%s|cffffff7f]|r"
|
flickerstreak@1
|
31 IS_NOW_SET_TO = "|cffffff7f%s|r ist nun auf |cffffff7f[|r%s|cffffff7f]|r gesetzt"
|
flickerstreak@1
|
32 IS_NOT_A_VALID_OPTION_FOR = "[|cffffff7f%s|r] ist keine g\195\188ltige Option f\195\188r |cffffff7f%s|r"
|
flickerstreak@1
|
33 IS_NOT_A_VALID_VALUE_FOR = "[|cffffff7f%s|r] ist kein g\195\188ltiger Wert f\195\188r |cffffff7f%s|r"
|
flickerstreak@1
|
34 NO_OPTIONS_AVAILABLE = "Keine Optionen verfügbar"
|
flickerstreak@1
|
35 OPTION_HANDLER_NOT_FOUND = "Optionen handler |cffffff7f%q|r nicht gefunden."
|
flickerstreak@1
|
36 OPTION_HANDLER_NOT_VALID = "Optionen handler nicht g\195\188ltig."
|
flickerstreak@1
|
37 OPTION_IS_DISABLED = "Option |cffffff7f%s|r deaktiviert."
|
flickerstreak@1
|
38 KEYBINDING_USAGE = "<ALT-CTRL-SHIFT-KEY>" -- fix
|
flickerstreak@22
|
39 DEFAULT_CONFIRM_MESSAGE = "Are you sure you want to perform `%s'?" -- fix
|
flickerstreak@1
|
40 elseif GetLocale() == "frFR" then
|
flickerstreak@1
|
41 MAP_ONOFF = { [false] = "|cffff0000Inactif|r", [true] = "|cff00ff00Actif|r" }
|
flickerstreak@1
|
42 USAGE = "Utilisation"
|
flickerstreak@1
|
43 IS_CURRENTLY_SET_TO = "|cffffff7f%s|r est actuellement positionn\195\169 sur |cffffff7f[|r%s|cffffff7f]|r"
|
flickerstreak@1
|
44 IS_NOW_SET_TO = "|cffffff7f%s|r est maintenant positionn\195\169 sur |cffffff7f[|r%s|cffffff7f]|r"
|
flickerstreak@1
|
45 IS_NOT_A_VALID_OPTION_FOR = "[|cffffff7f%s|r] n'est pas une option valide pour |cffffff7f%s|r"
|
flickerstreak@1
|
46 IS_NOT_A_VALID_VALUE_FOR = "[|cffffff7f%s|r] n'est pas une valeur valide pour |cffffff7f%s|r"
|
flickerstreak@1
|
47 NO_OPTIONS_AVAILABLE = "Pas d'options disponibles"
|
flickerstreak@1
|
48 OPTION_HANDLER_NOT_FOUND = "Le gestionnaire d'option |cffffff7f%q|r n'a pas \195\169t\195\169 trouv\195\169."
|
flickerstreak@1
|
49 OPTION_HANDLER_NOT_VALID = "Le gestionnaire d'option n'est pas valide."
|
flickerstreak@1
|
50 OPTION_IS_DISABLED = "L'option |cffffff7f%s|r est d\195\169sactiv\195\169e."
|
flickerstreak@1
|
51 KEYBINDING_USAGE = "<ALT-CTRL-SHIFT-KEY>" -- fix
|
flickerstreak@22
|
52 DEFAULT_CONFIRM_MESSAGE = "Are you sure you want to perform `%s'?" -- fix
|
flickerstreak@1
|
53 elseif GetLocale() == "koKR" then
|
flickerstreak@1
|
54 MAP_ONOFF = { [false] = "|cffff0000끔|r", [true] = "|cff00ff00켬|r" }
|
flickerstreak@1
|
55 USAGE = "사용법"
|
flickerstreak@22
|
56 IS_CURRENTLY_SET_TO = "|cffffff7f%s|r|1은;는; 현재 상태는 |cffffff7f[|r%s|cffffff7f]|r|1으로;로; 설정되어 있습니다."
|
flickerstreak@22
|
57 IS_NOW_SET_TO = "|cffffff7f%s|r|1을;를; |cffffff7f[|r%s|cffffff7f]|r 상태로 변경합니다."
|
flickerstreak@22
|
58 IS_NOT_A_VALID_OPTION_FOR = "[|cffffff7f%s|r]|1은;는; |cffffff7f%s|r에서 사용 불가능한 설정입니다."
|
flickerstreak@22
|
59 IS_NOT_A_VALID_VALUE_FOR = "[|cffffff7f%s|r]|1은;는; |cffffff7f%s|r에서 사용 불가능한 설정 값입니다."
|
flickerstreak@22
|
60 NO_OPTIONS_AVAILABLE = "가능한 설정이 없습니다."
|
flickerstreak@22
|
61 OPTION_HANDLER_NOT_FOUND = "설정 조정 값인 |cffffff7f%q|r|1을;를; 찾지 못했습니다."
|
flickerstreak@22
|
62 OPTION_HANDLER_NOT_VALID = "설정 조정 값이 올바르지 않습니다."
|
flickerstreak@1
|
63 OPTION_IS_DISABLED = "|cffffff7f%s|r 설정은 사용할 수 없습니다."
|
flickerstreak@22
|
64 KEYBINDING_USAGE = "<ALT-CTRL-SHIFT-KEY>"
|
flickerstreak@22
|
65 DEFAULT_CONFIRM_MESSAGE = "정말 당신은 `%s'|1을;를; 하시겠습니까?"
|
flickerstreak@1
|
66 elseif GetLocale() == "zhCN" then
|
flickerstreak@1
|
67 MAP_ONOFF = { [false] = "|cffff0000\229\133\179\233\151\173|r", [true] = "|cff00ff00\229\188\128\229\144\175|r" }
|
flickerstreak@1
|
68 USAGE = "\231\148\168\230\179\149"
|
flickerstreak@1
|
69 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
|
70 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
|
71 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
|
72 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
|
73 NO_OPTIONS_AVAILABLE = "\230\178\161\230\156\137\233\128\137\233\161\185\229\143\175\231\148\168"
|
flickerstreak@1
|
74 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
|
75 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
|
76 OPTION_IS_DISABLED = "\233\128\137\233\161\185 |cffffff7f%s|r \228\184\141\229\174\140\230\149\180."
|
flickerstreak@1
|
77 KEYBINDING_USAGE = "<ALT-CTRL-SHIFT-KEY>" -- fix
|
flickerstreak@22
|
78 DEFAULT_CONFIRM_MESSAGE = "Are you sure you want to perform `%s'?" -- fix
|
flickerstreak@1
|
79 elseif GetLocale() == "zhTW" then
|
flickerstreak@1
|
80 MAP_ONOFF = { [false] = "|cffff0000關閉|r", [true] = "|cff00ff00開啟|r" }
|
flickerstreak@1
|
81 USAGE = "用法"
|
flickerstreak@22
|
82 IS_CURRENTLY_SET_TO = "|cffffff7f%s|r目前的設定為|cffffff7f[|r%s|cffffff7f]|r"
|
flickerstreak@22
|
83 IS_NOW_SET_TO = "|cffffff7f%s|r現在被設定為|cffffff7f[|r%s|cffffff7f]|r"
|
flickerstreak@22
|
84 IS_NOT_A_VALID_OPTION_FOR = "對於|cffffff7f%2$s|r,[|cffffff7f%1$s|r]是一個不符合規定的選項"
|
flickerstreak@22
|
85 IS_NOT_A_VALID_VALUE_FOR = "對於|cffffff7f%2$s|r,[|cffffff7f%1$s|r]是一個不符合規定的數值"
|
flickerstreak@22
|
86 NO_OPTIONS_AVAILABLE = "沒有可用的選項"
|
flickerstreak@22
|
87 OPTION_HANDLER_NOT_FOUND = "找不到|cffffff7f%q|r選項處理器。"
|
flickerstreak@1
|
88 OPTION_HANDLER_NOT_VALID = "選項處理器不符合規定。"
|
flickerstreak@22
|
89 OPTION_IS_DISABLED = "|cffffff7f%s|r已被停用。"
|
flickerstreak@22
|
90 KEYBINDING_USAGE = "<Alt-Ctrl-Shift-鍵>"
|
flickerstreak@22
|
91 DEFAULT_CONFIRM_MESSAGE = "是否執行「%s」?"
|
flickerstreak@22
|
92 elseif GetLocale() == "esES" then
|
flickerstreak@22
|
93 MAP_ONOFF = { [false] = "|cffff0000Desactivado|r", [true] = "|cff00ff00Activado|r" }
|
flickerstreak@22
|
94 USAGE = "Uso"
|
flickerstreak@22
|
95 IS_CURRENTLY_SET_TO = "|cffffff7f%s|r est\195\161 establecido actualmente a |cffffff7f[|r%s|cffffff7f]|r"
|
flickerstreak@22
|
96 IS_NOW_SET_TO = "|cffffff7f%s|r se ha establecido a |cffffff7f[|r%s|cffffff7f]|r"
|
flickerstreak@22
|
97 IS_NOT_A_VALID_OPTION_FOR = "[|cffffff7f%s|r] no es una opci\195\179n valida para |cffffff7f%s|r"
|
flickerstreak@22
|
98 IS_NOT_A_VALID_VALUE_FOR = "[|cffffff7f%s|r] no es un valor v\195\161lido para |cffffff7f%s|r"
|
flickerstreak@22
|
99 NO_OPTIONS_AVAILABLE = "No hay opciones disponibles"
|
flickerstreak@22
|
100 OPTION_HANDLER_NOT_FOUND = "Gestor de opciones |cffffff7f%q|r no encontrado."
|
flickerstreak@22
|
101 OPTION_HANDLER_NOT_VALID = "Gestor de opciones no v\195\161lido."
|
flickerstreak@22
|
102 OPTION_IS_DISABLED = "La opci\195\179n |cffffff7f%s|r est\195\161 desactivada."
|
flickerstreak@22
|
103 KEYBINDING_USAGE = "<ALT-CTRL-SHIFT-KEY>"
|
flickerstreak@22
|
104 DEFAULT_CONFIRM_MESSAGE = "Are you sure you want to perform `%s'?" -- fix
|
flickerstreak@1
|
105 else -- enUS
|
flickerstreak@1
|
106 MAP_ONOFF = { [false] = "|cffff0000Off|r", [true] = "|cff00ff00On|r" }
|
flickerstreak@1
|
107 USAGE = "Usage"
|
flickerstreak@1
|
108 IS_CURRENTLY_SET_TO = "|cffffff7f%s|r is currently set to |cffffff7f[|r%s|cffffff7f]|r"
|
flickerstreak@1
|
109 IS_NOW_SET_TO = "|cffffff7f%s|r is now set to |cffffff7f[|r%s|cffffff7f]|r"
|
flickerstreak@1
|
110 IS_NOT_A_VALID_OPTION_FOR = "[|cffffff7f%s|r] is not a valid option for |cffffff7f%s|r"
|
flickerstreak@1
|
111 IS_NOT_A_VALID_VALUE_FOR = "[|cffffff7f%s|r] is not a valid value for |cffffff7f%s|r"
|
flickerstreak@1
|
112 NO_OPTIONS_AVAILABLE = "No options available"
|
flickerstreak@1
|
113 OPTION_HANDLER_NOT_FOUND = "Option handler |cffffff7f%q|r not found."
|
flickerstreak@1
|
114 OPTION_HANDLER_NOT_VALID = "Option handler not valid."
|
flickerstreak@1
|
115 OPTION_IS_DISABLED = "Option |cffffff7f%s|r is disabled."
|
flickerstreak@1
|
116 KEYBINDING_USAGE = "<ALT-CTRL-SHIFT-KEY>"
|
flickerstreak@22
|
117 DEFAULT_CONFIRM_MESSAGE = "Are you sure you want to perform `%s'?"
|
flickerstreak@1
|
118 end
|
flickerstreak@1
|
119
|
flickerstreak@1
|
120 local NONE = NONE or "None"
|
flickerstreak@1
|
121
|
flickerstreak@1
|
122 local AceOO = AceLibrary("AceOO-2.0")
|
flickerstreak@1
|
123 local AceEvent
|
flickerstreak@1
|
124
|
flickerstreak@22
|
125 local AceConsole = AceOO.Mixin { "Print", "PrintComma", "PrintLiteral", "CustomPrint", "RegisterChatCommand" }
|
flickerstreak@1
|
126 local Dewdrop
|
flickerstreak@1
|
127
|
flickerstreak@1
|
128 local _G = getfenv(0)
|
flickerstreak@1
|
129
|
flickerstreak@1
|
130 local function print(text, name, r, g, b, frame, delay)
|
flickerstreak@1
|
131 if not text or text:len() == 0 then
|
flickerstreak@1
|
132 text = " "
|
flickerstreak@1
|
133 end
|
flickerstreak@1
|
134 if not name or name == AceConsole then
|
flickerstreak@1
|
135 else
|
flickerstreak@22
|
136 text = "|cffffff78" .. tostring(name) .. ":|r " .. text
|
flickerstreak@1
|
137 end
|
flickerstreak@22
|
138 local last_color
|
flickerstreak@22
|
139 for t in text:gmatch("[^\n]+") do
|
flickerstreak@22
|
140 (frame or DEFAULT_CHAT_FRAME):AddMessage(last_color and "|cff" .. last_color .. t or t, r, g, b, nil, delay or 5)
|
flickerstreak@22
|
141 if not last_color or t:find("|r") or t:find("|c") then
|
flickerstreak@22
|
142 last_color = t:match(".*|c[fF][fF](%x%x%x%x%x%x)[^|]-$")
|
flickerstreak@22
|
143 end
|
flickerstreak@22
|
144 end
|
flickerstreak@22
|
145 return text
|
flickerstreak@1
|
146 end
|
flickerstreak@1
|
147
|
flickerstreak@1
|
148 local real_tostring = tostring
|
flickerstreak@1
|
149
|
flickerstreak@1
|
150 local function tostring(t)
|
flickerstreak@1
|
151 if type(t) == "table" then
|
flickerstreak@1
|
152 if type(rawget(t, 0)) == "userdata" and type(t.GetObjectType) == "function" then
|
flickerstreak@22
|
153 return ("<%s:%s>"):format(t:GetObjectType(), t:GetName() or "(anon)")
|
flickerstreak@1
|
154 end
|
flickerstreak@1
|
155 end
|
flickerstreak@1
|
156 return real_tostring(t)
|
flickerstreak@1
|
157 end
|
flickerstreak@1
|
158
|
flickerstreak@22
|
159 local getkeystring
|
flickerstreak@22
|
160
|
flickerstreak@22
|
161 local function isList(t)
|
flickerstreak@22
|
162 local n = #t
|
flickerstreak@22
|
163 for k,v in pairs(t) do
|
flickerstreak@22
|
164 if type(k) ~= "number" then
|
flickerstreak@22
|
165 return false
|
flickerstreak@22
|
166 elseif k < 1 or k > n then
|
flickerstreak@22
|
167 return false
|
flickerstreak@22
|
168 end
|
flickerstreak@1
|
169 end
|
flickerstreak@22
|
170 return true
|
flickerstreak@1
|
171 end
|
flickerstreak@22
|
172
|
flickerstreak@22
|
173 local findGlobal = setmetatable({}, {__index=function(self, t)
|
flickerstreak@22
|
174 for k,v in pairs(_G) do
|
flickerstreak@22
|
175 if v == t then
|
flickerstreak@22
|
176 k = tostring(k)
|
flickerstreak@22
|
177 self[v] = k
|
flickerstreak@22
|
178 return k
|
flickerstreak@22
|
179 end
|
flickerstreak@22
|
180 end
|
flickerstreak@22
|
181 self[t] = false
|
flickerstreak@22
|
182 return false
|
flickerstreak@22
|
183 end})
|
flickerstreak@22
|
184
|
flickerstreak@22
|
185 local recurse = {}
|
flickerstreak@22
|
186 local timeToEnd
|
flickerstreak@22
|
187 local GetTime = GetTime
|
flickerstreak@22
|
188 local type = type
|
flickerstreak@22
|
189
|
flickerstreak@22
|
190 local new, del
|
flickerstreak@22
|
191 do
|
flickerstreak@22
|
192 local cache = setmetatable({},{__mode='k'})
|
flickerstreak@22
|
193 function new()
|
flickerstreak@22
|
194 local t = next(cache)
|
flickerstreak@22
|
195 if t then
|
flickerstreak@22
|
196 cache[t] = nil
|
flickerstreak@22
|
197 return t
|
flickerstreak@22
|
198 else
|
flickerstreak@22
|
199 return {}
|
flickerstreak@22
|
200 end
|
flickerstreak@22
|
201 end
|
flickerstreak@22
|
202
|
flickerstreak@22
|
203 function del(t)
|
flickerstreak@22
|
204 for k in pairs(t) do
|
flickerstreak@22
|
205 t[k] = nil
|
flickerstreak@22
|
206 end
|
flickerstreak@22
|
207 cache[t] = true
|
flickerstreak@22
|
208 return nil
|
flickerstreak@22
|
209 end
|
flickerstreak@22
|
210 end
|
flickerstreak@22
|
211
|
flickerstreak@22
|
212 local function ignoreCaseSort(alpha, bravo)
|
flickerstreak@22
|
213 if not alpha or not bravo then
|
flickerstreak@22
|
214 return false
|
flickerstreak@22
|
215 end
|
flickerstreak@22
|
216 return tostring(alpha):lower() < tostring(bravo):lower()
|
flickerstreak@22
|
217 end
|
flickerstreak@22
|
218
|
flickerstreak@22
|
219 local function specialSort(alpha, bravo)
|
flickerstreak@22
|
220 if alpha == nil or bravo == nil then
|
flickerstreak@22
|
221 return false
|
flickerstreak@22
|
222 end
|
flickerstreak@22
|
223 local type_alpha, type_bravo = type(alpha), type(bravo)
|
flickerstreak@22
|
224 if type_alpha ~= type_bravo then
|
flickerstreak@22
|
225 return type_alpha < type_bravo
|
flickerstreak@22
|
226 end
|
flickerstreak@22
|
227 if type_alpha == "string" then
|
flickerstreak@22
|
228 return alpha:lower() < bravo:lower()
|
flickerstreak@22
|
229 elseif type_alpha == "number" then
|
flickerstreak@22
|
230 return alpha < bravo
|
flickerstreak@22
|
231 elseif type_alpha == "table" then
|
flickerstreak@22
|
232 return #alpha < #bravo
|
flickerstreak@22
|
233 elseif type_alpha == "boolean" then
|
flickerstreak@22
|
234 return not alpha
|
flickerstreak@22
|
235 else
|
flickerstreak@22
|
236 return false
|
flickerstreak@22
|
237 end
|
flickerstreak@22
|
238 end
|
flickerstreak@22
|
239
|
flickerstreak@22
|
240 local function escapeChar(c)
|
flickerstreak@22
|
241 return ("\\%03d"):format(c:byte())
|
flickerstreak@22
|
242 end
|
flickerstreak@22
|
243
|
flickerstreak@22
|
244 local function literal_tostring_prime(t, depth)
|
flickerstreak@22
|
245 if type(t) == "string" then
|
flickerstreak@22
|
246 return ("|cff00ff00%q|r"):format((t:gsub("|", "||"))):gsub("[\001-\012\014-\031\128-\255]", escapeChar)
|
flickerstreak@22
|
247 elseif type(t) == "table" then
|
flickerstreak@22
|
248 if t == _G then
|
flickerstreak@22
|
249 return "|cffffea00_G|r"
|
flickerstreak@22
|
250 end
|
flickerstreak@22
|
251 if type(rawget(t, 0)) == "userdata" and type(t.GetObjectType) == "function" then
|
flickerstreak@22
|
252 return ("|cffffea00<%s:%s>|r"):format(t:GetObjectType(), t:GetName() or "(anon)")
|
flickerstreak@22
|
253 end
|
flickerstreak@22
|
254 if next(t) == nil then
|
flickerstreak@22
|
255 local mt = getmetatable(t)
|
flickerstreak@22
|
256 if type(mt) == "table" and type(mt.__raw) == "table" then
|
flickerstreak@22
|
257 t = mt.__raw
|
flickerstreak@22
|
258 end
|
flickerstreak@22
|
259 end
|
flickerstreak@22
|
260 if recurse[t] then
|
flickerstreak@22
|
261 local g = findGlobal[t]
|
flickerstreak@22
|
262 if g then
|
flickerstreak@22
|
263 return ("|cff9f9f9f<Recursion _G[%q]>|r"):format(g)
|
flickerstreak@22
|
264 else
|
flickerstreak@22
|
265 return ("|cff9f9f9f<Recursion %s>|r"):format(real_tostring(t):gsub("|", "||"))
|
flickerstreak@22
|
266 end
|
flickerstreak@22
|
267 elseif GetTime() > timeToEnd then
|
flickerstreak@22
|
268 local g = findGlobal[t]
|
flickerstreak@22
|
269 if g then
|
flickerstreak@22
|
270 return ("|cff9f9f9f<Timeout _G[%q]>|r"):format(g)
|
flickerstreak@22
|
271 else
|
flickerstreak@22
|
272 return ("|cff9f9f9f<Timeout %s>|r"):format(real_tostring(t):gsub("|", "||"))
|
flickerstreak@22
|
273 end
|
flickerstreak@22
|
274 elseif depth >= 2 then
|
flickerstreak@22
|
275 local g = findGlobal[t]
|
flickerstreak@22
|
276 if g then
|
flickerstreak@22
|
277 return ("|cff9f9f9f<_G[%q]>|r"):format(g)
|
flickerstreak@22
|
278 else
|
flickerstreak@22
|
279 return ("|cff9f9f9f<%s>|r"):format(real_tostring(t):gsub("|", "||"))
|
flickerstreak@22
|
280 end
|
flickerstreak@22
|
281 end
|
flickerstreak@22
|
282 recurse[t] = true
|
flickerstreak@22
|
283 if next(t) == nil then
|
flickerstreak@22
|
284 return "{}"
|
flickerstreak@22
|
285 elseif next(t, (next(t))) == nil then
|
flickerstreak@22
|
286 local k, v = next(t)
|
flickerstreak@22
|
287 if k == 1 then
|
flickerstreak@22
|
288 return "{ " .. literal_tostring_prime(v, depth+1) .. " }"
|
flickerstreak@22
|
289 else
|
flickerstreak@22
|
290 return "{ " .. getkeystring(k, depth+1) .. " = " .. literal_tostring_prime(v, depth+1) .. " }"
|
flickerstreak@22
|
291 end
|
flickerstreak@22
|
292 end
|
flickerstreak@22
|
293 local s
|
flickerstreak@22
|
294 local g = findGlobal[t]
|
flickerstreak@22
|
295 if g then
|
flickerstreak@22
|
296 s = ("{ |cff9f9f9f-- _G[%q]|r\n"):format(g)
|
flickerstreak@22
|
297 else
|
flickerstreak@22
|
298 s = "{ |cff9f9f9f-- " .. real_tostring(t):gsub("|", "||") .. "|r\n"
|
flickerstreak@22
|
299 end
|
flickerstreak@22
|
300 if isList(t) then
|
flickerstreak@22
|
301 for i = 1, #t do
|
flickerstreak@22
|
302 s = s .. (" "):rep(depth+1) .. literal_tostring_prime(t[i], depth+1) .. (i == #t and "\n" or ",\n")
|
flickerstreak@22
|
303 end
|
flickerstreak@22
|
304 else
|
flickerstreak@22
|
305 local tmp = new()
|
flickerstreak@22
|
306 for k in pairs(t) do
|
flickerstreak@22
|
307 tmp[#tmp+1] = k
|
flickerstreak@22
|
308 end
|
flickerstreak@22
|
309 table.sort(tmp, specialSort)
|
flickerstreak@22
|
310 for i,k in ipairs(tmp) do
|
flickerstreak@22
|
311 tmp[i] = nil
|
flickerstreak@22
|
312 local v = t[k]
|
flickerstreak@22
|
313 s = s .. (" "):rep(depth+1) .. getkeystring(k, depth+1) .. " = " .. literal_tostring_prime(v, depth+1) .. (tmp[i+1] == nil and "\n" or ",\n")
|
flickerstreak@22
|
314 end
|
flickerstreak@22
|
315 tmp = del(tmp)
|
flickerstreak@22
|
316 end
|
flickerstreak@22
|
317 if g then
|
flickerstreak@22
|
318 s = s .. (" "):rep(depth) .. string.format("} |cff9f9f9f-- _G[%q]|r", g)
|
flickerstreak@22
|
319 else
|
flickerstreak@22
|
320 s = s .. (" "):rep(depth) .. "} |cff9f9f9f-- " .. real_tostring(t):gsub("|", "||")
|
flickerstreak@22
|
321 end
|
flickerstreak@22
|
322 return s
|
flickerstreak@22
|
323 end
|
flickerstreak@22
|
324 if type(t) == "number" then
|
flickerstreak@22
|
325 return "|cffff7fff" .. real_tostring(t) .. "|r"
|
flickerstreak@22
|
326 elseif type(t) == "boolean" then
|
flickerstreak@22
|
327 return "|cffff9100" .. real_tostring(t) .. "|r"
|
flickerstreak@22
|
328 elseif t == nil then
|
flickerstreak@22
|
329 return "|cffff7f7f" .. real_tostring(t) .. "|r"
|
flickerstreak@22
|
330 else
|
flickerstreak@22
|
331 return "|cffffea00" .. real_tostring(t) .. "|r"
|
flickerstreak@22
|
332 end
|
flickerstreak@22
|
333 end
|
flickerstreak@22
|
334
|
flickerstreak@22
|
335 function getkeystring(t, depth)
|
flickerstreak@22
|
336 if type(t) == "string" then
|
flickerstreak@22
|
337 if t:find("^[%a_][%a%d_]*$") then
|
flickerstreak@22
|
338 return "|cff7fd5ff" .. t .. "|r"
|
flickerstreak@22
|
339 end
|
flickerstreak@22
|
340 end
|
flickerstreak@22
|
341 return "[" .. literal_tostring_prime(t, depth) .. "]"
|
flickerstreak@22
|
342 end
|
flickerstreak@22
|
343
|
flickerstreak@22
|
344 local get_stringed_args
|
flickerstreak@22
|
345 do
|
flickerstreak@22
|
346 local function g(value, ...)
|
flickerstreak@22
|
347 if select('#', ...) == 0 then
|
flickerstreak@22
|
348 return literal_tostring_prime(value, 1)
|
flickerstreak@22
|
349 end
|
flickerstreak@22
|
350 return literal_tostring_prime(value, 1) .. ", " .. g(...)
|
flickerstreak@22
|
351 end
|
flickerstreak@22
|
352
|
flickerstreak@22
|
353 local function f(success, ...)
|
flickerstreak@22
|
354 if not success then
|
flickerstreak@1
|
355 return
|
flickerstreak@1
|
356 end
|
flickerstreak@22
|
357 return g(...)
|
flickerstreak@1
|
358 end
|
flickerstreak@22
|
359
|
flickerstreak@22
|
360 function get_stringed_args(func, ...)
|
flickerstreak@22
|
361 return f(pcall(func, ...))
|
flickerstreak@22
|
362 end
|
flickerstreak@22
|
363 end
|
flickerstreak@22
|
364
|
flickerstreak@22
|
365 local function literal_tostring_frame(t)
|
flickerstreak@22
|
366 local s = ("|cffffea00<%s:%s|r\n"):format(t:GetObjectType(), t:GetName() or "(anon)")
|
flickerstreak@22
|
367 local __index = getmetatable(t).__index
|
flickerstreak@22
|
368 local tmp, tmp2, tmp3 = new(), new(), new()
|
flickerstreak@22
|
369 for k in pairs(t) do
|
flickerstreak@22
|
370 if k ~= 0 then
|
flickerstreak@22
|
371 tmp3[k] = true
|
flickerstreak@22
|
372 tmp2[k] = true
|
flickerstreak@22
|
373 end
|
flickerstreak@22
|
374 end
|
flickerstreak@22
|
375 for k in pairs(__index) do
|
flickerstreak@22
|
376 tmp2[k] = true
|
flickerstreak@22
|
377 end
|
flickerstreak@22
|
378 for k in pairs(tmp2) do
|
flickerstreak@22
|
379 tmp[#tmp+1] = k
|
flickerstreak@22
|
380 tmp2[k] = nil
|
flickerstreak@22
|
381 end
|
flickerstreak@22
|
382 table.sort(tmp, ignoreCaseSort)
|
flickerstreak@22
|
383 local first = true
|
flickerstreak@22
|
384 for i,k in ipairs(tmp) do
|
flickerstreak@22
|
385 local v = t[k]
|
flickerstreak@22
|
386 local good = true
|
flickerstreak@22
|
387 if k == "GetPoint" then
|
flickerstreak@22
|
388 for i = 1, t:GetNumPoints() do
|
flickerstreak@22
|
389 if not first then
|
flickerstreak@22
|
390 s = s .. ",\n"
|
flickerstreak@22
|
391 else
|
flickerstreak@22
|
392 first = false
|
flickerstreak@22
|
393 end
|
flickerstreak@22
|
394 s = s .. " " .. getkeystring(k, 1) .. "(" .. literal_tostring_prime(i, 1) .. ") => " .. get_stringed_args(v, t, i)
|
flickerstreak@22
|
395 end
|
flickerstreak@22
|
396 elseif type(v) == "function" and type(k) == "string" and (k:find("^Is") or k:find("^Get") or k:find("^Can")) then
|
flickerstreak@22
|
397 local q = get_stringed_args(v, t)
|
flickerstreak@22
|
398 if q then
|
flickerstreak@22
|
399 if not first then
|
flickerstreak@22
|
400 s = s .. ",\n"
|
flickerstreak@22
|
401 else
|
flickerstreak@22
|
402 first = false
|
flickerstreak@22
|
403 end
|
flickerstreak@22
|
404 s = s .. " " .. getkeystring(k, 1) .. "() => " .. q
|
flickerstreak@22
|
405 end
|
flickerstreak@22
|
406 elseif type(v) ~= "function" or (type(v) == "function" and type(k) == "string" and tmp3[k]) then
|
flickerstreak@22
|
407 if not first then
|
flickerstreak@22
|
408 s = s .. ",\n"
|
flickerstreak@22
|
409 else
|
flickerstreak@22
|
410 first = false
|
flickerstreak@22
|
411 end
|
flickerstreak@22
|
412 s = s .. " " .. getkeystring(k, 1) .. " = " .. literal_tostring_prime(v, 1)
|
flickerstreak@22
|
413 else
|
flickerstreak@22
|
414 good = false
|
flickerstreak@22
|
415 end
|
flickerstreak@22
|
416 end
|
flickerstreak@22
|
417 tmp, tmp2, tmp3 = del(tmp), del(tmp2), del(tmp3)
|
flickerstreak@22
|
418 s = s .. "\n|cffffea00>|r"
|
flickerstreak@22
|
419 return s
|
flickerstreak@22
|
420 end
|
flickerstreak@22
|
421
|
flickerstreak@22
|
422 local function literal_tostring(t, only)
|
flickerstreak@22
|
423 timeToEnd = GetTime() + 0.2
|
flickerstreak@22
|
424 local s
|
flickerstreak@22
|
425 if only and type(t) == "table" and type(rawget(t, 0)) == "userdata" and type(t.GetObjectType) == "function" then
|
flickerstreak@22
|
426 s = literal_tostring_frame(t)
|
flickerstreak@22
|
427 else
|
flickerstreak@22
|
428 s = literal_tostring_prime(t, 0)
|
flickerstreak@22
|
429 end
|
flickerstreak@22
|
430 for k,v in pairs(recurse) do
|
flickerstreak@22
|
431 recurse[k] = nil
|
flickerstreak@22
|
432 end
|
flickerstreak@22
|
433 for k,v in pairs(findGlobal) do
|
flickerstreak@22
|
434 findGlobal[k] = nil
|
flickerstreak@22
|
435 end
|
flickerstreak@22
|
436 return s
|
flickerstreak@22
|
437 end
|
flickerstreak@22
|
438
|
flickerstreak@22
|
439 local function tostring_args(a1, ...)
|
flickerstreak@22
|
440 if select('#', ...) < 1 then
|
flickerstreak@22
|
441 return tostring(a1)
|
flickerstreak@22
|
442 end
|
flickerstreak@22
|
443 return tostring(a1), tostring_args(...)
|
flickerstreak@22
|
444 end
|
flickerstreak@22
|
445
|
flickerstreak@22
|
446 local function literal_tostring_args(a1, ...)
|
flickerstreak@22
|
447 if select('#', ...) < 1 then
|
flickerstreak@22
|
448 return literal_tostring(a1)
|
flickerstreak@22
|
449 end
|
flickerstreak@22
|
450 return literal_tostring(a1), literal_tostring_args(...)
|
flickerstreak@22
|
451 end
|
flickerstreak@22
|
452
|
flickerstreak@22
|
453 function AceConsole:CustomPrint(r, g, b, frame, delay, connector, a1, ...)
|
flickerstreak@22
|
454 if connector == true then
|
flickerstreak@22
|
455 local s
|
flickerstreak@22
|
456 if select('#', ...) == 0 then
|
flickerstreak@22
|
457 s = literal_tostring(a1, true)
|
flickerstreak@22
|
458 else
|
flickerstreak@22
|
459 s = (", "):join(literal_tostring_args(a1, ...))
|
flickerstreak@22
|
460 end
|
flickerstreak@22
|
461 return print(s, self, r, g, b, frame or self.printFrame, delay)
|
flickerstreak@22
|
462 elseif tostring(a1):find("%%") and select('#', ...) >= 1 then
|
flickerstreak@22
|
463 local success, text = pcall(string.format, tostring_args(a1, ...))
|
flickerstreak@22
|
464 if success then
|
flickerstreak@22
|
465 return print(text, self, r, g, b, frame or self.printFrame, delay)
|
flickerstreak@22
|
466 end
|
flickerstreak@22
|
467 end
|
flickerstreak@22
|
468 return print((connector or " "):join(tostring_args(a1, ...)), self, r, g, b, frame or self.printFrame, delay)
|
flickerstreak@1
|
469 end
|
flickerstreak@1
|
470
|
flickerstreak@1
|
471 function AceConsole:Print(...)
|
flickerstreak@1
|
472 return AceConsole.CustomPrint(self, nil, nil, nil, nil, nil, " ", ...)
|
flickerstreak@1
|
473 end
|
flickerstreak@1
|
474
|
flickerstreak@1
|
475 function AceConsole:PrintComma(...)
|
flickerstreak@1
|
476 return AceConsole.CustomPrint(self, nil, nil, nil, nil, nil, ", ", ...)
|
flickerstreak@1
|
477 end
|
flickerstreak@1
|
478
|
flickerstreak@22
|
479 function AceConsole:PrintLiteral(...)
|
flickerstreak@22
|
480 return AceConsole.CustomPrint(self, nil, nil, nil, nil, nil, true, ...)
|
flickerstreak@22
|
481 end
|
flickerstreak@22
|
482
|
flickerstreak@1
|
483 local work
|
flickerstreak@1
|
484 local argwork
|
flickerstreak@1
|
485
|
flickerstreak@1
|
486 local function findTableLevel(self, options, chat, text, index, passTable)
|
flickerstreak@1
|
487 if not index then
|
flickerstreak@1
|
488 index = 1
|
flickerstreak@1
|
489 if work then
|
flickerstreak@1
|
490 for k,v in pairs(work) do
|
flickerstreak@1
|
491 work[k] = nil
|
flickerstreak@1
|
492 end
|
flickerstreak@1
|
493 for k,v in pairs(argwork) do
|
flickerstreak@1
|
494 argwork[k] = nil
|
flickerstreak@1
|
495 end
|
flickerstreak@1
|
496 else
|
flickerstreak@1
|
497 work = {}
|
flickerstreak@1
|
498 argwork = {}
|
flickerstreak@1
|
499 end
|
flickerstreak@1
|
500 local len = text:len()
|
flickerstreak@1
|
501 local count
|
flickerstreak@1
|
502 repeat
|
flickerstreak@1
|
503 text, count = text:gsub("(|cff%x%x%x%x%x%x|Hitem:%d-:%d-:%d-:%d-|h%[[^%]]-) (.-%]|h|r)", "%1\001%2")
|
flickerstreak@1
|
504 until count == 0
|
flickerstreak@1
|
505 text = text:gsub("(%]|h|r)(|cff%x%x%x%x%x%x|Hitem:%d-:%d-:%d-:%d-|h%[)", "%1 %2")
|
flickerstreak@1
|
506 for token in text:gmatch("([^%s]+)") do
|
flickerstreak@1
|
507 local token = token
|
flickerstreak@1
|
508 local num = tonumber(token)
|
flickerstreak@1
|
509 if num then
|
flickerstreak@1
|
510 token = num
|
flickerstreak@1
|
511 else
|
flickerstreak@1
|
512 token = token:gsub("\001", " ")
|
flickerstreak@1
|
513 end
|
flickerstreak@1
|
514 table.insert(work, token)
|
flickerstreak@1
|
515 end
|
flickerstreak@1
|
516 end
|
flickerstreak@22
|
517
|
flickerstreak@1
|
518 local path = chat
|
flickerstreak@1
|
519 for i = 1, index - 1 do
|
flickerstreak@1
|
520 path = path .. " " .. tostring(work[i])
|
flickerstreak@1
|
521 end
|
flickerstreak@22
|
522
|
flickerstreak@22
|
523 local passValue = options.passValue or (passTable and work[index-1])
|
flickerstreak@22
|
524 passTable = passTable or options
|
flickerstreak@22
|
525
|
flickerstreak@1
|
526 if type(options.args) == "table" then
|
flickerstreak@1
|
527 local disabled, hidden = options.disabled, options.cmdHidden or options.hidden
|
flickerstreak@1
|
528 if hidden then
|
flickerstreak@1
|
529 if type(hidden) == "function" then
|
flickerstreak@22
|
530 hidden = hidden(passValue)
|
flickerstreak@1
|
531 elseif type(hidden) == "string" then
|
flickerstreak@1
|
532 local handler = options.handler or self
|
flickerstreak@1
|
533 local f = hidden
|
flickerstreak@1
|
534 local neg = f:match("^~(.-)$")
|
flickerstreak@1
|
535 if neg then
|
flickerstreak@1
|
536 f = neg
|
flickerstreak@1
|
537 end
|
flickerstreak@1
|
538 if type(handler[f]) ~= "function" then
|
flickerstreak@22
|
539 AceConsole:error("%s: %s", handler, OPTION_HANDLER_NOT_FOUND:format(tostring(f)))
|
flickerstreak@1
|
540 end
|
flickerstreak@22
|
541 hidden = handler[f](handler, passValue)
|
flickerstreak@1
|
542 if neg then
|
flickerstreak@1
|
543 hidden = not hidden
|
flickerstreak@1
|
544 end
|
flickerstreak@1
|
545 end
|
flickerstreak@1
|
546 end
|
flickerstreak@1
|
547 if hidden then
|
flickerstreak@1
|
548 disabled = true
|
flickerstreak@1
|
549 elseif disabled then
|
flickerstreak@1
|
550 if type(disabled) == "function" then
|
flickerstreak@22
|
551 disabled = disabled(passValue)
|
flickerstreak@1
|
552 elseif type(disabled) == "string" then
|
flickerstreak@1
|
553 local handler = options.handler or self
|
flickerstreak@1
|
554 local f = disabled
|
flickerstreak@1
|
555 local neg = f:match("^~(.-)$")
|
flickerstreak@1
|
556 if neg then
|
flickerstreak@1
|
557 f = neg
|
flickerstreak@1
|
558 end
|
flickerstreak@1
|
559 if type(handler[f]) ~= "function" then
|
flickerstreak@22
|
560 AceConsole:error("%s: %s", handler, OPTION_HANDLER_NOT_FOUND:format(tostring(f)))
|
flickerstreak@1
|
561 end
|
flickerstreak@22
|
562 disabled = handler[f](handler, passValue)
|
flickerstreak@1
|
563 if neg then
|
flickerstreak@1
|
564 disabled = not disabled
|
flickerstreak@1
|
565 end
|
flickerstreak@1
|
566 end
|
flickerstreak@1
|
567 end
|
flickerstreak@1
|
568 if not disabled then
|
flickerstreak@22
|
569 local next = work[index] and tostring(work[index]):lower()
|
flickerstreak@22
|
570 local next_num = tonumber(next)
|
flickerstreak@1
|
571 if next then
|
flickerstreak@1
|
572 for k,v in pairs(options.args) do
|
flickerstreak@1
|
573 local good = false
|
flickerstreak@22
|
574 if tostring(k):gsub("%s", "-"):lower() == next then
|
flickerstreak@22
|
575 good = true
|
flickerstreak@22
|
576 elseif k == next_num then
|
flickerstreak@1
|
577 good = true
|
flickerstreak@1
|
578 elseif type(v.aliases) == "table" then
|
flickerstreak@1
|
579 for _,alias in ipairs(v.aliases) do
|
flickerstreak@22
|
580 if alias:gsub("%s", "-"):lower() == next then
|
flickerstreak@1
|
581 good = true
|
flickerstreak@1
|
582 break
|
flickerstreak@1
|
583 end
|
flickerstreak@1
|
584 end
|
flickerstreak@22
|
585 elseif type(v.aliases) == "string" and v.aliases:gsub("%s", "-"):lower() == next then
|
flickerstreak@1
|
586 good = true
|
flickerstreak@1
|
587 end
|
flickerstreak@1
|
588 if good then
|
flickerstreak@22
|
589 work[index] = k -- revert it back to its original form as supplied in args
|
flickerstreak@22
|
590 if options.pass then
|
flickerstreak@22
|
591 passTable = passTable or options
|
flickerstreak@22
|
592 if options.get and options.set then
|
flickerstreak@22
|
593 passTable = options
|
flickerstreak@22
|
594 end
|
flickerstreak@22
|
595 else
|
flickerstreak@22
|
596 passTable = nil
|
flickerstreak@22
|
597 end
|
flickerstreak@22
|
598 return findTableLevel(options.handler or self, v, chat, text, index + 1, passTable)
|
flickerstreak@1
|
599 end
|
flickerstreak@1
|
600 end
|
flickerstreak@1
|
601 end
|
flickerstreak@1
|
602 end
|
flickerstreak@1
|
603 end
|
flickerstreak@1
|
604 for i = index, #work do
|
flickerstreak@1
|
605 table.insert(argwork, work[i])
|
flickerstreak@1
|
606 end
|
flickerstreak@22
|
607 return options, path, argwork, options.handler or self, passTable, passValue
|
flickerstreak@1
|
608 end
|
flickerstreak@1
|
609
|
flickerstreak@1
|
610 local function validateOptionsMethods(self, options, position)
|
flickerstreak@1
|
611 if type(options) ~= "table" then
|
flickerstreak@1
|
612 return "Options must be a table.", position
|
flickerstreak@1
|
613 end
|
flickerstreak@1
|
614 self = options.handler or self
|
flickerstreak@1
|
615 if options.type == "execute" then
|
flickerstreak@1
|
616 if options.func and type(options.func) ~= "string" and type(options.func) ~= "function" then
|
flickerstreak@1
|
617 return "func must be a string or function", position
|
flickerstreak@1
|
618 end
|
flickerstreak@1
|
619 if options.func and type(options.func) == "string" and type(self[options.func]) ~= "function" then
|
flickerstreak@22
|
620 return ("%q is not a proper function"):format(tostring(options.func)), position
|
flickerstreak@1
|
621 end
|
flickerstreak@1
|
622 else
|
flickerstreak@1
|
623 if options.get then
|
flickerstreak@1
|
624 if type(options.get) ~= "string" and type(options.get) ~= "function" then
|
flickerstreak@1
|
625 return "get must be a string or function", position
|
flickerstreak@1
|
626 end
|
flickerstreak@1
|
627 if type(options.get) == "string" then
|
flickerstreak@1
|
628 local f = options.get
|
flickerstreak@1
|
629 if options.type == "toggle" then
|
flickerstreak@1
|
630 f = f:match("^~(.-)$") or f
|
flickerstreak@1
|
631 end
|
flickerstreak@1
|
632 if type(self[f]) ~= "function" then
|
flickerstreak@22
|
633 return ("%q is not a proper function"):format(tostring(f)), position
|
flickerstreak@1
|
634 end
|
flickerstreak@1
|
635 end
|
flickerstreak@1
|
636 end
|
flickerstreak@1
|
637 if options.set then
|
flickerstreak@1
|
638 if type(options.set) ~= "string" and type(options.set) ~= "function" then
|
flickerstreak@1
|
639 return "set must be a string or function", position
|
flickerstreak@1
|
640 end
|
flickerstreak@1
|
641 if type(options.set) == "string" and type(self[options.set]) ~= "function" then
|
flickerstreak@22
|
642 return ("%q is not a proper function"):format(tostring(options.set)), position
|
flickerstreak@1
|
643 end
|
flickerstreak@1
|
644 end
|
flickerstreak@1
|
645 if options.validate and type(options.validate) ~= "table" and options.validate ~= "keybinding" then
|
flickerstreak@1
|
646 if type(options.validate) ~= "string" and type(options.validate) ~= "function" then
|
flickerstreak@1
|
647 return "validate must be a string or function", position
|
flickerstreak@1
|
648 end
|
flickerstreak@1
|
649 if type(options.validate) == "string" and type(self[options.validate]) ~= "function" then
|
flickerstreak@22
|
650 return ("%q is not a proper function"):format(tostring(options.validate)), position
|
flickerstreak@1
|
651 end
|
flickerstreak@1
|
652 end
|
flickerstreak@1
|
653 end
|
flickerstreak@1
|
654 if options.disabled and type(options.disabled) == "string" then
|
flickerstreak@1
|
655 local f = options.disabled
|
flickerstreak@1
|
656 f = f:match("^~(.-)$") or f
|
flickerstreak@1
|
657 if type(self[f]) ~= "function" then
|
flickerstreak@22
|
658 return ("%q is not a proper function"):format(tostring(f)), position
|
flickerstreak@1
|
659 end
|
flickerstreak@1
|
660 end
|
flickerstreak@1
|
661 if options.cmdHidden and type(options.cmdHidden) == "string" then
|
flickerstreak@1
|
662 local f = options.cmdHidden
|
flickerstreak@1
|
663 f = f:match("^~(.-)$") or f
|
flickerstreak@1
|
664 if type(self[f]) ~= "function" then
|
flickerstreak@22
|
665 return ("%q is not a proper function"):format(tostring(f)), position
|
flickerstreak@1
|
666 end
|
flickerstreak@1
|
667 end
|
flickerstreak@1
|
668 if options.guiHidden and type(options.guiHidden) == "string" then
|
flickerstreak@1
|
669 local f = options.guiHidden
|
flickerstreak@1
|
670 f = f:match("^~(.-)$") or f
|
flickerstreak@1
|
671 if type(self[f]) ~= "function" then
|
flickerstreak@22
|
672 return ("%q is not a proper function"):format(tostring(f)), position
|
flickerstreak@1
|
673 end
|
flickerstreak@1
|
674 end
|
flickerstreak@1
|
675 if options.hidden and type(options.hidden) == "string" then
|
flickerstreak@1
|
676 local f = options.hidden
|
flickerstreak@1
|
677 f = f:match("^~(.-)$") or f
|
flickerstreak@1
|
678 if type(self[f]) ~= "function" then
|
flickerstreak@22
|
679 return ("%q is not a proper function"):format(tostring(f)), position
|
flickerstreak@1
|
680 end
|
flickerstreak@1
|
681 end
|
flickerstreak@1
|
682 if options.type == "group" and type(options.args) == "table" then
|
flickerstreak@1
|
683 for k,v in pairs(options.args) do
|
flickerstreak@1
|
684 if type(v) == "table" then
|
flickerstreak@1
|
685 local newposition
|
flickerstreak@1
|
686 if position then
|
flickerstreak@1
|
687 newposition = position .. ".args." .. k
|
flickerstreak@1
|
688 else
|
flickerstreak@1
|
689 newposition = "args." .. k
|
flickerstreak@1
|
690 end
|
flickerstreak@1
|
691 local err, pos = validateOptionsMethods(self, v, newposition)
|
flickerstreak@1
|
692 if err then
|
flickerstreak@1
|
693 return err, pos
|
flickerstreak@1
|
694 end
|
flickerstreak@1
|
695 end
|
flickerstreak@1
|
696 end
|
flickerstreak@1
|
697 end
|
flickerstreak@1
|
698 end
|
flickerstreak@1
|
699
|
flickerstreak@1
|
700 local function validateOptions(options, position, baseOptions, fromPass)
|
flickerstreak@1
|
701 if not baseOptions then
|
flickerstreak@1
|
702 baseOptions = options
|
flickerstreak@1
|
703 end
|
flickerstreak@1
|
704 if type(options) ~= "table" then
|
flickerstreak@1
|
705 return "Options must be a table.", position
|
flickerstreak@1
|
706 end
|
flickerstreak@1
|
707 local kind = options.type
|
flickerstreak@1
|
708 if type(kind) ~= "string" then
|
flickerstreak@1
|
709 return '"type" must be a string.', position
|
flickerstreak@1
|
710 elseif kind ~= "group" and kind ~= "range" and kind ~= "text" and kind ~= "execute" and kind ~= "toggle" and kind ~= "color" and kind ~= "header" then
|
flickerstreak@1
|
711 return '"type" must either be "range", "text", "group", "toggle", "execute", "color", or "header".', position
|
flickerstreak@1
|
712 end
|
flickerstreak@1
|
713 if options.aliases then
|
flickerstreak@1
|
714 if type(options.aliases) ~= "table" and type(options.aliases) ~= "string" then
|
flickerstreak@1
|
715 return '"alias" must be a table or string', position
|
flickerstreak@1
|
716 end
|
flickerstreak@1
|
717 end
|
flickerstreak@1
|
718 if not fromPass then
|
flickerstreak@1
|
719 if kind == "execute" then
|
flickerstreak@1
|
720 if type(options.func) ~= "string" and type(options.func) ~= "function" then
|
flickerstreak@1
|
721 return '"func" must be a string or function', position
|
flickerstreak@1
|
722 end
|
flickerstreak@1
|
723 elseif kind == "range" or kind == "text" or kind == "toggle" then
|
flickerstreak@1
|
724 if type(options.set) ~= "string" and type(options.set) ~= "function" then
|
flickerstreak@1
|
725 return '"set" must be a string or function', position
|
flickerstreak@1
|
726 end
|
flickerstreak@1
|
727 if kind == "text" and options.get == false then
|
flickerstreak@1
|
728 elseif type(options.get) ~= "string" and type(options.get) ~= "function" then
|
flickerstreak@1
|
729 return '"get" must be a string or function', position
|
flickerstreak@1
|
730 end
|
flickerstreak@1
|
731 elseif kind == "group" and options.pass then
|
flickerstreak@1
|
732 if options.pass ~= true then
|
flickerstreak@1
|
733 return '"pass" must be either nil, true, or false', position
|
flickerstreak@1
|
734 end
|
flickerstreak@1
|
735 if not options.func then
|
flickerstreak@1
|
736 if type(options.set) ~= "string" and type(options.set) ~= "function" then
|
flickerstreak@1
|
737 return '"set" must be a string or function', position
|
flickerstreak@1
|
738 end
|
flickerstreak@1
|
739 if type(options.get) ~= "string" and type(options.get) ~= "function" then
|
flickerstreak@1
|
740 return '"get" must be a string or function', position
|
flickerstreak@1
|
741 end
|
flickerstreak@1
|
742 elseif type(options.func) ~= "string" and type(options.func) ~= "function" then
|
flickerstreak@1
|
743 return '"func" must be a string or function', position
|
flickerstreak@1
|
744 end
|
flickerstreak@1
|
745 end
|
flickerstreak@1
|
746 end
|
flickerstreak@1
|
747 if options ~= baseOptions then
|
flickerstreak@1
|
748 if kind == "header" then
|
flickerstreak@1
|
749 elseif type(options.desc) ~= "string" then
|
flickerstreak@1
|
750 return '"desc" must be a string', position
|
flickerstreak@1
|
751 elseif options.desc:len() == 0 then
|
flickerstreak@1
|
752 return '"desc" cannot be a 0-length string', position
|
flickerstreak@1
|
753 end
|
flickerstreak@1
|
754 end
|
flickerstreak@1
|
755
|
flickerstreak@1
|
756 if options ~= baseOptions or kind == "range" or kind == "text" or kind == "toggle" or kind == "color" then
|
flickerstreak@1
|
757 if options.type == "header" and not options.cmdName and not options.name then
|
flickerstreak@1
|
758 elseif options.cmdName then
|
flickerstreak@1
|
759 if type(options.cmdName) ~= "string" then
|
flickerstreak@1
|
760 return '"cmdName" must be a string or nil', position
|
flickerstreak@1
|
761 elseif options.cmdName:len() == 0 then
|
flickerstreak@1
|
762 return '"cmdName" cannot be a 0-length string', position
|
flickerstreak@1
|
763 end
|
flickerstreak@1
|
764 if type(options.guiName) ~= "string" then
|
flickerstreak@1
|
765 if not options.guiNameIsMap then
|
flickerstreak@1
|
766 return '"guiName" must be a string or nil', position
|
flickerstreak@1
|
767 end
|
flickerstreak@1
|
768 elseif options.guiName:len() == 0 then
|
flickerstreak@1
|
769 return '"guiName" cannot be a 0-length string', position
|
flickerstreak@1
|
770 end
|
flickerstreak@1
|
771 else
|
flickerstreak@1
|
772 if type(options.name) ~= "string" then
|
flickerstreak@1
|
773 return '"name" must be a string', position
|
flickerstreak@1
|
774 elseif options.name:len() == 0 then
|
flickerstreak@1
|
775 return '"name" cannot be a 0-length string', position
|
flickerstreak@1
|
776 end
|
flickerstreak@1
|
777 end
|
flickerstreak@1
|
778 end
|
flickerstreak@1
|
779 if options.guiNameIsMap then
|
flickerstreak@1
|
780 if type(options.guiNameIsMap) ~= "boolean" then
|
flickerstreak@1
|
781 return '"guiNameIsMap" must be a boolean or nil', position
|
flickerstreak@1
|
782 elseif options.type ~= "toggle" then
|
flickerstreak@1
|
783 return 'if "guiNameIsMap" is true, then "type" must be set to \'toggle\'', position
|
flickerstreak@1
|
784 elseif type(options.map) ~= "table" then
|
flickerstreak@1
|
785 return '"map" must be a table', position
|
flickerstreak@1
|
786 end
|
flickerstreak@1
|
787 end
|
flickerstreak@1
|
788 if options.message and type(options.message) ~= "string" then
|
flickerstreak@1
|
789 return '"message" must be a string or nil', position
|
flickerstreak@1
|
790 end
|
flickerstreak@1
|
791 if options.error and type(options.error) ~= "string" then
|
flickerstreak@1
|
792 return '"error" must be a string or nil', position
|
flickerstreak@1
|
793 end
|
flickerstreak@1
|
794 if options.current and type(options.current) ~= "string" then
|
flickerstreak@1
|
795 return '"current" must be a string or nil', position
|
flickerstreak@1
|
796 end
|
flickerstreak@1
|
797 if options.order then
|
flickerstreak@1
|
798 if type(options.order) ~= "number" or (-1 < options.order and options.order < 0.999) then
|
flickerstreak@1
|
799 return '"order" must be a non-zero number or nil', position
|
flickerstreak@1
|
800 end
|
flickerstreak@1
|
801 end
|
flickerstreak@1
|
802 if options.disabled then
|
flickerstreak@1
|
803 if type(options.disabled) ~= "function" and type(options.disabled) ~= "string" and options.disabled ~= true then
|
flickerstreak@1
|
804 return '"disabled" must be a function, string, or boolean', position
|
flickerstreak@1
|
805 end
|
flickerstreak@1
|
806 end
|
flickerstreak@1
|
807 if options.cmdHidden then
|
flickerstreak@1
|
808 if type(options.cmdHidden) ~= "function" and type(options.cmdHidden) ~= "string" and options.cmdHidden ~= true then
|
flickerstreak@1
|
809 return '"cmdHidden" must be a function, string, or boolean', position
|
flickerstreak@1
|
810 end
|
flickerstreak@1
|
811 end
|
flickerstreak@1
|
812 if options.guiHidden then
|
flickerstreak@1
|
813 if type(options.guiHidden) ~= "function" and type(options.guiHidden) ~= "string" and options.guiHidden ~= true then
|
flickerstreak@1
|
814 return '"guiHidden" must be a function, string, or boolean', position
|
flickerstreak@1
|
815 end
|
flickerstreak@1
|
816 end
|
flickerstreak@1
|
817 if options.hidden then
|
flickerstreak@1
|
818 if type(options.hidden) ~= "function" and type(options.hidden) ~= "string" and options.hidden ~= true then
|
flickerstreak@1
|
819 return '"hidden" must be a function, string, or boolean', position
|
flickerstreak@1
|
820 end
|
flickerstreak@1
|
821 end
|
flickerstreak@1
|
822 if kind == "text" then
|
flickerstreak@1
|
823 if type(options.validate) == "table" then
|
flickerstreak@1
|
824 local t = options.validate
|
flickerstreak@1
|
825 local iTable = nil
|
flickerstreak@1
|
826 for k,v in pairs(t) do
|
flickerstreak@1
|
827 if type(k) == "number" then
|
flickerstreak@1
|
828 if iTable == nil then
|
flickerstreak@1
|
829 iTable = true
|
flickerstreak@1
|
830 elseif not iTable then
|
flickerstreak@1
|
831 return '"validate" must either have all keys be indexed numbers or strings', position
|
flickerstreak@1
|
832 elseif k < 1 or k > #t then
|
flickerstreak@1
|
833 return '"validate" numeric keys must be indexed properly. >= 1 and <= #validate', position
|
flickerstreak@1
|
834 end
|
flickerstreak@1
|
835 else
|
flickerstreak@1
|
836 if iTable == nil then
|
flickerstreak@1
|
837 iTable = false
|
flickerstreak@1
|
838 elseif iTable then
|
flickerstreak@1
|
839 return '"validate" must either have all keys be indexed numbers or strings', position
|
flickerstreak@1
|
840 end
|
flickerstreak@1
|
841 end
|
flickerstreak@1
|
842 if type(v) ~= "string" then
|
flickerstreak@1
|
843 return '"validate" values must all be strings', position
|
flickerstreak@1
|
844 end
|
flickerstreak@1
|
845 end
|
flickerstreak@22
|
846 if options.multiToggle and options.multiToggle ~= true then
|
flickerstreak@22
|
847 return '"multiToggle" must be a boolean or nil if "validate" is a table', position
|
flickerstreak@22
|
848 end
|
flickerstreak@1
|
849 elseif options.validate == "keybinding" then
|
flickerstreak@22
|
850
|
flickerstreak@1
|
851 else
|
flickerstreak@1
|
852 if type(options.usage) ~= "string" then
|
flickerstreak@1
|
853 return '"usage" must be a string', position
|
flickerstreak@1
|
854 elseif options.validate and type(options.validate) ~= "string" and type(options.validate) ~= "function" then
|
flickerstreak@1
|
855 return '"validate" must be a string, function, or table', position
|
flickerstreak@1
|
856 end
|
flickerstreak@1
|
857 end
|
flickerstreak@22
|
858 if options.multiToggle and type(options.validate) ~= "table" then
|
flickerstreak@22
|
859 return '"validate" must be a table if "multiToggle" is true', position
|
flickerstreak@22
|
860 end
|
flickerstreak@1
|
861 elseif kind == "range" then
|
flickerstreak@1
|
862 if options.min or options.max then
|
flickerstreak@1
|
863 if type(options.min) ~= "number" then
|
flickerstreak@1
|
864 return '"min" must be a number', position
|
flickerstreak@1
|
865 elseif type(options.max) ~= "number" then
|
flickerstreak@1
|
866 return '"max" must be a number', position
|
flickerstreak@1
|
867 elseif options.min >= options.max then
|
flickerstreak@1
|
868 return '"min" must be less than "max"', position
|
flickerstreak@1
|
869 end
|
flickerstreak@1
|
870 end
|
flickerstreak@1
|
871 if options.step then
|
flickerstreak@1
|
872 if type(options.step) ~= "number" then
|
flickerstreak@1
|
873 return '"step" must be a number', position
|
flickerstreak@1
|
874 elseif options.step < 0 then
|
flickerstreak@1
|
875 return '"step" must be nonnegative', position
|
flickerstreak@1
|
876 end
|
flickerstreak@1
|
877 end
|
flickerstreak@1
|
878 if options.isPercent and options.isPercent ~= true then
|
flickerstreak@1
|
879 return '"isPercent" must either be nil, true, or false', position
|
flickerstreak@1
|
880 end
|
flickerstreak@1
|
881 elseif kind == "toggle" then
|
flickerstreak@1
|
882 if options.map then
|
flickerstreak@1
|
883 if type(options.map) ~= "table" then
|
flickerstreak@1
|
884 return '"map" must be a table', position
|
flickerstreak@1
|
885 elseif type(options.map[true]) ~= "string" then
|
flickerstreak@1
|
886 return '"map[true]" must be a string', position
|
flickerstreak@1
|
887 elseif type(options.map[false]) ~= "string" then
|
flickerstreak@1
|
888 return '"map[false]" must be a string', position
|
flickerstreak@1
|
889 end
|
flickerstreak@1
|
890 end
|
flickerstreak@1
|
891 elseif kind == "color" then
|
flickerstreak@1
|
892 if options.hasAlpha and options.hasAlpha ~= true then
|
flickerstreak@1
|
893 return '"hasAlpha" must be nil, true, or false', position
|
flickerstreak@1
|
894 end
|
flickerstreak@1
|
895 elseif kind == "group" then
|
flickerstreak@1
|
896 if options.pass and options.pass ~= true then
|
flickerstreak@1
|
897 return '"pass" must be nil, true, or false', position
|
flickerstreak@1
|
898 end
|
flickerstreak@1
|
899 if type(options.args) ~= "table" then
|
flickerstreak@1
|
900 return '"args" must be a table', position
|
flickerstreak@1
|
901 end
|
flickerstreak@1
|
902 for k,v in pairs(options.args) do
|
flickerstreak@22
|
903 if type(k) ~= "number" then
|
flickerstreak@22
|
904 if type(k) ~= "string" then
|
flickerstreak@22
|
905 return '"args" keys must be strings or numbers', position
|
flickerstreak@22
|
906 elseif k:len() == 0 then
|
flickerstreak@22
|
907 return '"args" keys must not be 0-length strings.', position
|
flickerstreak@22
|
908 end
|
flickerstreak@1
|
909 end
|
flickerstreak@1
|
910 if type(v) ~= "table" then
|
flickerstreak@22
|
911 if type(k) == "number" then
|
flickerstreak@22
|
912 return '"args" values must be tables', position and position .. "[" .. k .. "]" or "[" .. k .. "]"
|
flickerstreak@22
|
913 else
|
flickerstreak@22
|
914 return '"args" values must be tables', position and position .. "." .. k or k
|
flickerstreak@22
|
915 end
|
flickerstreak@1
|
916 end
|
flickerstreak@1
|
917 local newposition
|
flickerstreak@22
|
918 if type(k) == "number" then
|
flickerstreak@22
|
919 newposition = position and position .. ".args[" .. k .. "]" or "args[" .. k .. "]"
|
flickerstreak@1
|
920 else
|
flickerstreak@22
|
921 newposition = position and position .. ".args." .. k or "args." .. k
|
flickerstreak@1
|
922 end
|
flickerstreak@1
|
923 local err, pos = validateOptions(v, newposition, baseOptions, options.pass)
|
flickerstreak@1
|
924 if err then
|
flickerstreak@1
|
925 return err, pos
|
flickerstreak@1
|
926 end
|
flickerstreak@1
|
927 end
|
flickerstreak@22
|
928 elseif kind == "execute" then
|
flickerstreak@22
|
929 if type(options.confirm) ~= "string" and type(options.confirm) ~= "boolean" and type(options.confirm) ~= "nil" then
|
flickerstreak@22
|
930 return '"confirm" must be a string, boolean, or nil', position
|
flickerstreak@22
|
931 end
|
flickerstreak@1
|
932 end
|
flickerstreak@1
|
933 end
|
flickerstreak@1
|
934
|
flickerstreak@1
|
935 local colorTable
|
flickerstreak@1
|
936 local colorFunc
|
flickerstreak@1
|
937 local colorCancelFunc
|
flickerstreak@1
|
938
|
flickerstreak@1
|
939 local function keybindingValidateFunc(text)
|
flickerstreak@1
|
940 if text == nil or text == "NONE" then
|
flickerstreak@1
|
941 return nil
|
flickerstreak@1
|
942 end
|
flickerstreak@1
|
943 text = text:upper()
|
flickerstreak@1
|
944 local shift, ctrl, alt
|
flickerstreak@1
|
945 local modifier
|
flickerstreak@1
|
946 while true do
|
flickerstreak@1
|
947 if text == "-" then
|
flickerstreak@1
|
948 break
|
flickerstreak@1
|
949 end
|
flickerstreak@1
|
950 modifier, text = strsplit('-', text, 2)
|
flickerstreak@1
|
951 if text then
|
flickerstreak@1
|
952 if modifier ~= "SHIFT" and modifier ~= "CTRL" and modifier ~= "ALT" then
|
flickerstreak@1
|
953 return false
|
flickerstreak@1
|
954 end
|
flickerstreak@1
|
955 if modifier == "SHIFT" then
|
flickerstreak@1
|
956 if shift then
|
flickerstreak@1
|
957 return false
|
flickerstreak@1
|
958 end
|
flickerstreak@1
|
959 shift = true
|
flickerstreak@1
|
960 end
|
flickerstreak@1
|
961 if modifier == "CTRL" then
|
flickerstreak@1
|
962 if ctrl then
|
flickerstreak@1
|
963 return false
|
flickerstreak@1
|
964 end
|
flickerstreak@1
|
965 ctrl = true
|
flickerstreak@1
|
966 end
|
flickerstreak@1
|
967 if modifier == "ALT" then
|
flickerstreak@1
|
968 if alt then
|
flickerstreak@1
|
969 return false
|
flickerstreak@1
|
970 end
|
flickerstreak@1
|
971 alt = true
|
flickerstreak@1
|
972 end
|
flickerstreak@1
|
973 else
|
flickerstreak@1
|
974 text = modifier
|
flickerstreak@1
|
975 break
|
flickerstreak@1
|
976 end
|
flickerstreak@1
|
977 end
|
flickerstreak@22
|
978 if not text:find("^F%d+$") and text ~= "CAPSLOCK" and text:len() ~= 1 and (text:byte() < 128 or text:len() > 4) and not _G["KEY_" .. text] then
|
flickerstreak@1
|
979 return false
|
flickerstreak@1
|
980 end
|
flickerstreak@1
|
981 local s = text
|
flickerstreak@1
|
982 if shift then
|
flickerstreak@1
|
983 s = "SHIFT-" .. s
|
flickerstreak@1
|
984 end
|
flickerstreak@1
|
985 if ctrl then
|
flickerstreak@1
|
986 s = "CTRL-" .. s
|
flickerstreak@1
|
987 end
|
flickerstreak@1
|
988 if alt then
|
flickerstreak@1
|
989 s = "ALT-" .. s
|
flickerstreak@1
|
990 end
|
flickerstreak@1
|
991 return s
|
flickerstreak@1
|
992 end
|
flickerstreak@1
|
993 AceConsole.keybindingValidateFunc = keybindingValidateFunc
|
flickerstreak@1
|
994
|
flickerstreak@1
|
995 local order
|
flickerstreak@1
|
996
|
flickerstreak@1
|
997 local mysort_args
|
flickerstreak@1
|
998 local mysort
|
flickerstreak@1
|
999
|
flickerstreak@22
|
1000 local function icaseSort(alpha, bravo)
|
flickerstreak@22
|
1001 if type(alpha) == "number" and type(bravo) == "number" then
|
flickerstreak@22
|
1002 return alpha < bravo
|
flickerstreak@22
|
1003 end
|
flickerstreak@22
|
1004 return tostring(alpha):lower() < tostring(bravo):lower()
|
flickerstreak@22
|
1005 end
|
flickerstreak@22
|
1006
|
flickerstreak@22
|
1007 local tmp = {}
|
flickerstreak@22
|
1008 local function printUsage(self, handler, realOptions, options, path, args, passValue, quiet, filter)
|
flickerstreak@1
|
1009 if filter then
|
flickerstreak@1
|
1010 filter = "^" .. filter:gsub("([%(%)%.%*%+%-%[%]%?%^%$%%])", "%%%1")
|
flickerstreak@1
|
1011 end
|
flickerstreak@1
|
1012 local hidden, disabled = options.cmdHidden or options.hidden, options.disabled
|
flickerstreak@1
|
1013 if hidden then
|
flickerstreak@1
|
1014 if type(hidden) == "function" then
|
flickerstreak@22
|
1015 hidden = hidden(options.passValue)
|
flickerstreak@1
|
1016 elseif type(hidden) == "string" then
|
flickerstreak@1
|
1017 local f = hidden
|
flickerstreak@1
|
1018 local neg = f:match("^~(.-)$")
|
flickerstreak@1
|
1019 if neg then
|
flickerstreak@1
|
1020 f = neg
|
flickerstreak@1
|
1021 end
|
flickerstreak@1
|
1022 if type(handler[f]) ~= "function" then
|
flickerstreak@22
|
1023 AceConsole:error("%s: %s", handler, OPTION_HANDLER_NOT_FOUND:format(tostring(f)))
|
flickerstreak@1
|
1024 end
|
flickerstreak@22
|
1025 hidden = handler[f](handler, options.passValue)
|
flickerstreak@1
|
1026 if neg then
|
flickerstreak@1
|
1027 hidden = not hidden
|
flickerstreak@1
|
1028 end
|
flickerstreak@1
|
1029 end
|
flickerstreak@1
|
1030 end
|
flickerstreak@1
|
1031 if hidden then
|
flickerstreak@1
|
1032 disabled = true
|
flickerstreak@1
|
1033 elseif disabled then
|
flickerstreak@1
|
1034 if type(disabled) == "function" then
|
flickerstreak@22
|
1035 disabled = disabled(options.passValue)
|
flickerstreak@1
|
1036 elseif type(disabled) == "string" then
|
flickerstreak@1
|
1037 local f = disabled
|
flickerstreak@1
|
1038 local neg = f:match("^~(.-)$")
|
flickerstreak@1
|
1039 if neg then
|
flickerstreak@1
|
1040 f = neg
|
flickerstreak@1
|
1041 end
|
flickerstreak@1
|
1042 if type(handler[f]) ~= "function" then
|
flickerstreak@22
|
1043 AceConsole:error("%s: %s", handler, OPTION_HANDLER_NOT_FOUND:format(tostring(f)))
|
flickerstreak@1
|
1044 end
|
flickerstreak@22
|
1045 disabled = handler[f](handler, options.passValue)
|
flickerstreak@1
|
1046 if neg then
|
flickerstreak@1
|
1047 disabled = not disabled
|
flickerstreak@1
|
1048 end
|
flickerstreak@1
|
1049 end
|
flickerstreak@1
|
1050 end
|
flickerstreak@1
|
1051 local kind = (options.type or "group"):lower()
|
flickerstreak@1
|
1052 if disabled then
|
flickerstreak@22
|
1053 print(OPTION_IS_DISABLED:format(path), realOptions.cmdName or realOptions.name or self)
|
flickerstreak@1
|
1054 elseif kind == "text" then
|
flickerstreak@1
|
1055 local var
|
flickerstreak@22
|
1056 local multiToggle
|
flickerstreak@22
|
1057 for k in pairs(tmp) do
|
flickerstreak@22
|
1058 tmp[k] = nil
|
flickerstreak@22
|
1059 end
|
flickerstreak@1
|
1060 if passTable then
|
flickerstreak@22
|
1061 multiToggle = passTable.multiToggle
|
flickerstreak@1
|
1062 if not passTable.get then
|
flickerstreak@1
|
1063 elseif type(passTable.get) == "function" then
|
flickerstreak@22
|
1064 if not multiToggle then
|
flickerstreak@22
|
1065 var = passTable.get(passValue)
|
flickerstreak@22
|
1066 else
|
flickerstreak@22
|
1067 var = tmp
|
flickerstreak@22
|
1068 for k,v in pairs(options.validate) do
|
flickerstreak@22
|
1069 local val = type(k) ~= "number" and k or v
|
flickerstreak@22
|
1070 if passValue == nil then
|
flickerstreak@22
|
1071 var[val] = passTable.get(val) or nil
|
flickerstreak@22
|
1072 else
|
flickerstreak@22
|
1073 var[val] = passTable.get(passValue, val) or nil
|
flickerstreak@22
|
1074 end
|
flickerstreak@22
|
1075 end
|
flickerstreak@22
|
1076 end
|
flickerstreak@1
|
1077 else
|
flickerstreak@1
|
1078 local handler = passTable.handler or handler
|
flickerstreak@1
|
1079 if type(handler[passTable.get]) ~= "function" then
|
flickerstreak@22
|
1080 AceConsole:error("%s: %s", handler, OPTION_HANDLER_NOT_FOUND:format(tostring(passTable.get)))
|
flickerstreak@1
|
1081 end
|
flickerstreak@1
|
1082 var = handler[passTable.get](handler, passValue)
|
flickerstreak@22
|
1083 if not multiToggle then
|
flickerstreak@22
|
1084 var = handler[passTable.get](handler, passValue)
|
flickerstreak@22
|
1085 else
|
flickerstreak@22
|
1086 var = tmp
|
flickerstreak@22
|
1087 for k,v in pairs(options.validate) do
|
flickerstreak@22
|
1088 local val = type(k) ~= "number" and k or v
|
flickerstreak@22
|
1089 if passValue == nil then
|
flickerstreak@22
|
1090 var[val] = handler[passTable.get](handler, val) or nil
|
flickerstreak@22
|
1091 else
|
flickerstreak@22
|
1092 var[val] = handler[passTable.get](handler, passValue, val) or nil
|
flickerstreak@22
|
1093 end
|
flickerstreak@22
|
1094 end
|
flickerstreak@22
|
1095 end
|
flickerstreak@1
|
1096 end
|
flickerstreak@1
|
1097 else
|
flickerstreak@22
|
1098 multiToggle = options.multiToggle
|
flickerstreak@1
|
1099 if not options.get then
|
flickerstreak@1
|
1100 elseif type(options.get) == "function" then
|
flickerstreak@22
|
1101 if not multiToggle then
|
flickerstreak@22
|
1102 var = options.get(passValue)
|
flickerstreak@22
|
1103 else
|
flickerstreak@22
|
1104 var = tmp
|
flickerstreak@22
|
1105 for k,v in pairs(options.validate) do
|
flickerstreak@22
|
1106 local val = type(k) ~= "number" and k or v
|
flickerstreak@22
|
1107 if passValue == nil then
|
flickerstreak@22
|
1108 var[val] = options.get(val) or nil
|
flickerstreak@22
|
1109 else
|
flickerstreak@22
|
1110 var[val] = options.get(passValue, val) or nil
|
flickerstreak@22
|
1111 end
|
flickerstreak@22
|
1112 end
|
flickerstreak@22
|
1113 end
|
flickerstreak@1
|
1114 else
|
flickerstreak@1
|
1115 local handler = options.handler or handler
|
flickerstreak@1
|
1116 if type(handler[options.get]) ~= "function" then
|
flickerstreak@22
|
1117 AceConsole:error("%s: %s", handler, OPTION_HANDLER_NOT_FOUND:format(tostring(options.get)))
|
flickerstreak@1
|
1118 end
|
flickerstreak@22
|
1119 if not multiToggle then
|
flickerstreak@22
|
1120 var = handler[options.get](handler, passValue)
|
flickerstreak@22
|
1121 else
|
flickerstreak@22
|
1122 var = tmp
|
flickerstreak@22
|
1123 for k,v in pairs(options.validate) do
|
flickerstreak@22
|
1124 local val = type(k) ~= "number" and k or v
|
flickerstreak@22
|
1125 if passValue == nil then
|
flickerstreak@22
|
1126 var[val] = handler[options.get](handler, val) or nil
|
flickerstreak@22
|
1127 else
|
flickerstreak@22
|
1128 var[val] = handler[options.get](handler, passValue, val) or nil
|
flickerstreak@22
|
1129 end
|
flickerstreak@22
|
1130 end
|
flickerstreak@22
|
1131 end
|
flickerstreak@1
|
1132 end
|
flickerstreak@1
|
1133 end
|
flickerstreak@22
|
1134
|
flickerstreak@1
|
1135 local usage
|
flickerstreak@1
|
1136 if type(options.validate) == "table" then
|
flickerstreak@1
|
1137 if filter then
|
flickerstreak@1
|
1138 if not order then
|
flickerstreak@1
|
1139 order = {}
|
flickerstreak@1
|
1140 end
|
flickerstreak@1
|
1141 for k,v in pairs(options.validate) do
|
flickerstreak@1
|
1142 if v:find(filter) then
|
flickerstreak@1
|
1143 table.insert(order, v)
|
flickerstreak@1
|
1144 end
|
flickerstreak@1
|
1145 end
|
flickerstreak@22
|
1146 table.sort(order, icaseSort)
|
flickerstreak@1
|
1147 usage = "{" .. table.concat(order, " || ") .. "}"
|
flickerstreak@1
|
1148 for k in pairs(order) do
|
flickerstreak@1
|
1149 order[k] = nil
|
flickerstreak@1
|
1150 end
|
flickerstreak@1
|
1151 else
|
flickerstreak@1
|
1152 if not order then
|
flickerstreak@1
|
1153 order = {}
|
flickerstreak@1
|
1154 end
|
flickerstreak@1
|
1155 for k,v in pairs(options.validate) do
|
flickerstreak@1
|
1156 table.insert(order, v)
|
flickerstreak@1
|
1157 end
|
flickerstreak@22
|
1158 table.sort(order, icaseSort)
|
flickerstreak@1
|
1159 usage = "{" .. table.concat(order, " || ") .. "}"
|
flickerstreak@1
|
1160 for k in pairs(order) do
|
flickerstreak@1
|
1161 order[k] = nil
|
flickerstreak@1
|
1162 end
|
flickerstreak@1
|
1163 end
|
flickerstreak@22
|
1164 if multiToggle then
|
flickerstreak@22
|
1165 if not next(var) then
|
flickerstreak@22
|
1166 var = NONE
|
flickerstreak@22
|
1167 else
|
flickerstreak@22
|
1168 if not order then
|
flickerstreak@22
|
1169 order = {}
|
flickerstreak@22
|
1170 end
|
flickerstreak@22
|
1171 for k in pairs(var) do
|
flickerstreak@22
|
1172 if options.validate[k] then
|
flickerstreak@22
|
1173 order[#order+1] = options.validate[k]
|
flickerstreak@22
|
1174 else
|
flickerstreak@22
|
1175 for _,v in pairs(options.validate) do
|
flickerstreak@22
|
1176 if v == k or (type(v) == "string" and type(k) == "string" and v:lower() == k:lower()) then
|
flickerstreak@22
|
1177 order[#order+1] = v
|
flickerstreak@22
|
1178 break
|
flickerstreak@22
|
1179 end
|
flickerstreak@22
|
1180 end
|
flickerstreak@22
|
1181 end
|
flickerstreak@22
|
1182 end
|
flickerstreak@22
|
1183 table.sort(order, icaseSort)
|
flickerstreak@22
|
1184 var = table.concat(order, ", ")
|
flickerstreak@22
|
1185 for k in pairs(order) do
|
flickerstreak@22
|
1186 order[k] = nil
|
flickerstreak@22
|
1187 end
|
flickerstreak@22
|
1188 end
|
flickerstreak@22
|
1189 else
|
flickerstreak@22
|
1190 var = options.validate[var] or var
|
flickerstreak@22
|
1191 end
|
flickerstreak@1
|
1192 elseif options.validate == "keybinding" then
|
flickerstreak@1
|
1193 usage = KEYBINDING_USAGE
|
flickerstreak@1
|
1194 else
|
flickerstreak@1
|
1195 usage = options.usage or "<value>"
|
flickerstreak@1
|
1196 end
|
flickerstreak@1
|
1197 if not quiet then
|
flickerstreak@22
|
1198 print(("|cffffff7f%s:|r %s %s"):format(USAGE, path, usage), realOptions.cmdName or realOptions.name or self)
|
flickerstreak@1
|
1199 end
|
flickerstreak@1
|
1200 if (passTable and passTable.get) or options.get then
|
flickerstreak@22
|
1201 print((options.current or IS_CURRENTLY_SET_TO):format(tostring(options.cmdName or options.name), tostring(var or NONE)))
|
flickerstreak@1
|
1202 end
|
flickerstreak@1
|
1203 elseif kind == "range" then
|
flickerstreak@1
|
1204 local var
|
flickerstreak@1
|
1205 if passTable then
|
flickerstreak@1
|
1206 if type(passTable.get) == "function" then
|
flickerstreak@1
|
1207 var = passTable.get(passValue)
|
flickerstreak@1
|
1208 else
|
flickerstreak@1
|
1209 local handler = passTable.handler or handler
|
flickerstreak@1
|
1210 if type(handler[passTable.get]) ~= "function" then
|
flickerstreak@22
|
1211 AceConsole:error("%s: %s", handler, OPTION_HANDLER_NOT_FOUND:format(tostring(passTable.get)))
|
flickerstreak@1
|
1212 end
|
flickerstreak@1
|
1213 var = handler[passTable.get](handler, passValue)
|
flickerstreak@1
|
1214 end
|
flickerstreak@1
|
1215 else
|
flickerstreak@1
|
1216 if type(options.get) == "function" then
|
flickerstreak@22
|
1217 var = options.get(passValue)
|
flickerstreak@1
|
1218 else
|
flickerstreak@1
|
1219 local handler = options.handler or handler
|
flickerstreak@1
|
1220 if type(handler[options.get]) ~= "function" then
|
flickerstreak@22
|
1221 AceConsole:error("%s: %s", handler, OPTION_HANDLER_NOT_FOUND:format(tostring(options.get)))
|
flickerstreak@1
|
1222 end
|
flickerstreak@22
|
1223 var = handler[options.get](handler, passValue)
|
flickerstreak@1
|
1224 end
|
flickerstreak@1
|
1225 end
|
flickerstreak@22
|
1226
|
flickerstreak@1
|
1227 local usage
|
flickerstreak@1
|
1228 local min = options.min or 0
|
flickerstreak@1
|
1229 local max = options.max or 1
|
flickerstreak@1
|
1230 if options.isPercent then
|
flickerstreak@1
|
1231 min, max = min * 100, max * 100
|
flickerstreak@1
|
1232 var = tostring(var * 100) .. "%"
|
flickerstreak@1
|
1233 end
|
flickerstreak@1
|
1234 local bit = "-"
|
flickerstreak@1
|
1235 if min < 0 or max < 0 then
|
flickerstreak@1
|
1236 bit = " - "
|
flickerstreak@1
|
1237 end
|
flickerstreak@22
|
1238 usage = ("(%s%s%s)"):format(min, bit, max)
|
flickerstreak@1
|
1239 if not quiet then
|
flickerstreak@22
|
1240 print(("|cffffff7f%s:|r %s %s"):format(USAGE, path, usage), realOptions.cmdName or realOptions.name or self)
|
flickerstreak@1
|
1241 end
|
flickerstreak@22
|
1242 print((options.current or IS_CURRENTLY_SET_TO):format(tostring(options.cmdName or options.name), tostring(var or NONE)))
|
flickerstreak@1
|
1243 elseif kind == "group" then
|
flickerstreak@1
|
1244 local usage
|
flickerstreak@1
|
1245 if next(options.args) then
|
flickerstreak@1
|
1246 if not order then
|
flickerstreak@1
|
1247 order = {}
|
flickerstreak@1
|
1248 end
|
flickerstreak@1
|
1249 for k,v in pairs(options.args) do
|
flickerstreak@1
|
1250 if v.type ~= "header" then
|
flickerstreak@1
|
1251 local hidden = v.cmdHidden or v.hidden
|
flickerstreak@1
|
1252 if hidden then
|
flickerstreak@1
|
1253 if type(hidden) == "function" then
|
flickerstreak@1
|
1254 hidden = hidden()
|
flickerstreak@1
|
1255 elseif type(hidden) == "string" then
|
flickerstreak@1
|
1256 local f = hidden
|
flickerstreak@1
|
1257 local neg = f:match("^~(.-)$")
|
flickerstreak@1
|
1258 if neg then
|
flickerstreak@1
|
1259 f = neg
|
flickerstreak@1
|
1260 end
|
flickerstreak@1
|
1261 if type(handler[f]) ~= "function" then
|
flickerstreak@22
|
1262 AceConsole:error("%s: %s", handler, OPTION_HANDLER_NOT_FOUND:format(tostring(f)))
|
flickerstreak@1
|
1263 end
|
flickerstreak@1
|
1264 hidden = handler[f](handler)
|
flickerstreak@1
|
1265 if neg then
|
flickerstreak@1
|
1266 hidden = not hidden
|
flickerstreak@1
|
1267 end
|
flickerstreak@1
|
1268 end
|
flickerstreak@1
|
1269 end
|
flickerstreak@1
|
1270 if not hidden then
|
flickerstreak@1
|
1271 if filter then
|
flickerstreak@1
|
1272 if k:find(filter) then
|
flickerstreak@1
|
1273 table.insert(order, k)
|
flickerstreak@1
|
1274 elseif type(v.aliases) == "table" then
|
flickerstreak@1
|
1275 for _,bit in ipairs(v.aliases) do
|
flickerstreak@1
|
1276 if bit:find(filter) then
|
flickerstreak@1
|
1277 table.insert(order, k)
|
flickerstreak@1
|
1278 break
|
flickerstreak@1
|
1279 end
|
flickerstreak@1
|
1280 end
|
flickerstreak@1
|
1281 elseif type(v.aliases) == "string" then
|
flickerstreak@1
|
1282 if v.aliases:find(filter) then
|
flickerstreak@1
|
1283 table.insert(order, k)
|
flickerstreak@1
|
1284 end
|
flickerstreak@1
|
1285 end
|
flickerstreak@1
|
1286 else
|
flickerstreak@1
|
1287 table.insert(order, k)
|
flickerstreak@1
|
1288 end
|
flickerstreak@1
|
1289 end
|
flickerstreak@1
|
1290 end
|
flickerstreak@1
|
1291 end
|
flickerstreak@1
|
1292 if not mysort then
|
flickerstreak@1
|
1293 mysort = function(a, b)
|
flickerstreak@1
|
1294 local alpha, bravo = mysort_args[a], mysort_args[b]
|
flickerstreak@1
|
1295 local alpha_order = alpha and alpha.order or 100
|
flickerstreak@1
|
1296 local bravo_order = bravo and bravo.order or 100
|
flickerstreak@1
|
1297 if alpha_order == bravo_order then
|
flickerstreak@22
|
1298 return tostring(a):lower() < tostring(b):lower()
|
flickerstreak@1
|
1299 else
|
flickerstreak@1
|
1300 if alpha_order < 0 then
|
flickerstreak@1
|
1301 if bravo_order > 0 then
|
flickerstreak@1
|
1302 return false
|
flickerstreak@1
|
1303 end
|
flickerstreak@1
|
1304 else
|
flickerstreak@1
|
1305 if bravo_order < 0 then
|
flickerstreak@1
|
1306 return true
|
flickerstreak@1
|
1307 end
|
flickerstreak@1
|
1308 end
|
flickerstreak@1
|
1309 if alpha_order > 0 and bravo_order > 0 then
|
flickerstreak@22
|
1310 return tostring(a):lower() < tostring(b):lower()
|
flickerstreak@1
|
1311 end
|
flickerstreak@1
|
1312 return alpha_order < bravo_order
|
flickerstreak@1
|
1313 end
|
flickerstreak@1
|
1314 end
|
flickerstreak@1
|
1315 end
|
flickerstreak@1
|
1316 mysort_args = options.args
|
flickerstreak@1
|
1317 table.sort(order, mysort)
|
flickerstreak@1
|
1318 mysort_args = nil
|
flickerstreak@1
|
1319 if not quiet then
|
flickerstreak@1
|
1320 if options == realOptions then
|
flickerstreak@1
|
1321 if options.desc then
|
flickerstreak@1
|
1322 print(tostring(options.desc), realOptions.cmdName or realOptions.name or self)
|
flickerstreak@22
|
1323 print(("|cffffff7f%s:|r %s %s"):format(USAGE, path, "{" .. table.concat(order, " || ") .. "}"))
|
flickerstreak@1
|
1324 elseif self.description or self.notes then
|
flickerstreak@1
|
1325 print(tostring(self.description or self.notes), realOptions.cmdName or realOptions.name or self)
|
flickerstreak@22
|
1326 print(("|cffffff7f%s:|r %s %s"):format(USAGE, path, "{" .. table.concat(order, " || ") .. "}"))
|
flickerstreak@1
|
1327 else
|
flickerstreak@22
|
1328 print(("|cffffff7f%s:|r %s %s"):format(USAGE, path, "{" .. table.concat(order, " || ") .. "}"), realOptions.cmdName or realOptions.name or self)
|
flickerstreak@1
|
1329 end
|
flickerstreak@1
|
1330 else
|
flickerstreak@1
|
1331 if options.desc then
|
flickerstreak@22
|
1332 print(("|cffffff7f%s:|r %s %s"):format(USAGE, path, "{" .. table.concat(order, " || ") .. "}"), realOptions.cmdName or realOptions.name or self)
|
flickerstreak@1
|
1333 print(tostring(options.desc))
|
flickerstreak@1
|
1334 else
|
flickerstreak@22
|
1335 print(("|cffffff7f%s:|r %s %s"):format(USAGE, path, "{" .. table.concat(order, " || ") .. "}"), realOptions.cmdName or realOptions.name or self)
|
flickerstreak@1
|
1336 end
|
flickerstreak@1
|
1337 end
|
flickerstreak@1
|
1338 end
|
flickerstreak@22
|
1339 local passTable = options.pass and options or nil
|
flickerstreak@1
|
1340 for _,k in ipairs(order) do
|
flickerstreak@22
|
1341 local passValue = passTable and k or nil
|
flickerstreak@22
|
1342 local real_k = k
|
flickerstreak@1
|
1343 local v = options.args[k]
|
flickerstreak@1
|
1344 if v then
|
flickerstreak@22
|
1345 local v_p = passTable or v
|
flickerstreak@22
|
1346 if v.get and v.set then
|
flickerstreak@22
|
1347 v_p = v
|
flickerstreak@22
|
1348 passValue = nil
|
flickerstreak@22
|
1349 end
|
flickerstreak@22
|
1350 if v.passValue then
|
flickerstreak@22
|
1351 passValue = v.passValue
|
flickerstreak@22
|
1352 end
|
flickerstreak@22
|
1353 local k = tostring(k):gsub("%s", "-")
|
flickerstreak@1
|
1354 local disabled = v.disabled
|
flickerstreak@1
|
1355 if disabled then
|
flickerstreak@1
|
1356 if type(disabled) == "function" then
|
flickerstreak@22
|
1357 disabled = disabled(passValue)
|
flickerstreak@1
|
1358 elseif type(disabled) == "string" then
|
flickerstreak@1
|
1359 local f = disabled
|
flickerstreak@1
|
1360 local neg = f:match("^~(.-)$")
|
flickerstreak@1
|
1361 if neg then
|
flickerstreak@1
|
1362 f = neg
|
flickerstreak@1
|
1363 end
|
flickerstreak@1
|
1364 if type(handler[f]) ~= "function" then
|
flickerstreak@22
|
1365 AceConsole:error("%s: %s", handler, OPTION_HANDLER_NOT_FOUND:format(tostring(f)))
|
flickerstreak@1
|
1366 end
|
flickerstreak@22
|
1367 disabled = handler[f](handler, passValue)
|
flickerstreak@1
|
1368 if neg then
|
flickerstreak@1
|
1369 disabled = not disabled
|
flickerstreak@1
|
1370 end
|
flickerstreak@1
|
1371 end
|
flickerstreak@1
|
1372 end
|
flickerstreak@1
|
1373 if type(v.aliases) == "table" then
|
flickerstreak@22
|
1374 for _,s in ipairs(v.aliases) do
|
flickerstreak@22
|
1375 k = k .. " || " .. s:gsub("%s", "-")
|
flickerstreak@22
|
1376 end
|
flickerstreak@1
|
1377 elseif type(v.aliases) == "string" then
|
flickerstreak@22
|
1378 k = k .. " || " .. v.aliases:gsub("%s", "-")
|
flickerstreak@1
|
1379 end
|
flickerstreak@22
|
1380 if v_p.get then
|
flickerstreak@1
|
1381 local a1,a2,a3,a4
|
flickerstreak@22
|
1382 local multiToggle = v_p.type == "text" and v_p.multiToggle
|
flickerstreak@22
|
1383 for k in pairs(tmp) do
|
flickerstreak@22
|
1384 tmp[k] = nil
|
flickerstreak@22
|
1385 end
|
flickerstreak@22
|
1386 if type(v_p.get) == "function" then
|
flickerstreak@22
|
1387 if multiToggle then
|
flickerstreak@22
|
1388 a1 = tmp
|
flickerstreak@22
|
1389 for k,v in pairs(v.validate) do
|
flickerstreak@22
|
1390 local val = type(k) ~= "number" and k or v
|
flickerstreak@22
|
1391 if passValue == nil then
|
flickerstreak@22
|
1392 a1[val] = v_p.get(val) or nil
|
flickerstreak@22
|
1393 else
|
flickerstreak@22
|
1394 a1[val] = v_p.get(passValue, val) or nil
|
flickerstreak@22
|
1395 end
|
flickerstreak@22
|
1396 end
|
flickerstreak@1
|
1397 else
|
flickerstreak@22
|
1398 a1,a2,a3,a4 = v_p.get(passValue)
|
flickerstreak@1
|
1399 end
|
flickerstreak@1
|
1400 else
|
flickerstreak@22
|
1401 local handler = v_p.handler or handler
|
flickerstreak@22
|
1402 local f = v_p.get
|
flickerstreak@1
|
1403 local neg
|
flickerstreak@1
|
1404 if v.type == "toggle" then
|
flickerstreak@1
|
1405 neg = f:match("^~(.-)$")
|
flickerstreak@1
|
1406 if neg then
|
flickerstreak@1
|
1407 f = neg
|
flickerstreak@1
|
1408 end
|
flickerstreak@1
|
1409 end
|
flickerstreak@1
|
1410 if type(handler[f]) ~= "function" then
|
flickerstreak@22
|
1411 AceConsole:error("%s: %s", handler, OPTION_HANDLER_NOT_FOUND:format(tostring(f)))
|
flickerstreak@1
|
1412 end
|
flickerstreak@22
|
1413 if multiToggle then
|
flickerstreak@22
|
1414 a1 = tmp
|
flickerstreak@22
|
1415 for k,v in pairs(v.validate) do
|
flickerstreak@22
|
1416 local val = type(k) ~= "number" and k or v
|
flickerstreak@22
|
1417 if passValue == nil then
|
flickerstreak@22
|
1418 a1[val] = handler[f](handler, val) or nil
|
flickerstreak@22
|
1419 else
|
flickerstreak@22
|
1420 a1[val] = handler[f](handler, passValue, val) or nil
|
flickerstreak@22
|
1421 end
|
flickerstreak@22
|
1422 end
|
flickerstreak@1
|
1423 else
|
flickerstreak@22
|
1424 a1,a2,a3,a4 = handler[f](handler, passValue)
|
flickerstreak@1
|
1425 end
|
flickerstreak@1
|
1426 if neg then
|
flickerstreak@1
|
1427 a1 = not a1
|
flickerstreak@1
|
1428 end
|
flickerstreak@1
|
1429 end
|
flickerstreak@22
|
1430 local s
|
flickerstreak@1
|
1431 if v.type == "color" then
|
flickerstreak@1
|
1432 if v.hasAlpha then
|
flickerstreak@1
|
1433 if not a1 or not a2 or not a3 or not a4 then
|
flickerstreak@1
|
1434 s = NONE
|
flickerstreak@1
|
1435 else
|
flickerstreak@22
|
1436 s = ("|c%02x%02x%02x%02x%02x%02x%02x%02x|r"):format(a4*255, a1*255, a2*255, a3*255, a4*255, a1*255, a2*255, a3*255)
|
flickerstreak@1
|
1437 end
|
flickerstreak@1
|
1438 else
|
flickerstreak@1
|
1439 if not a1 or not a2 or not a3 then
|
flickerstreak@1
|
1440 s = NONE
|
flickerstreak@1
|
1441 else
|
flickerstreak@22
|
1442 s = ("|cff%02x%02x%02x%02x%02x%02x|r"):format(a1*255, a2*255, a3*255, a1*255, a2*255, a3*255)
|
flickerstreak@1
|
1443 end
|
flickerstreak@1
|
1444 end
|
flickerstreak@1
|
1445 elseif v.type == "toggle" then
|
flickerstreak@1
|
1446 if v.map then
|
flickerstreak@1
|
1447 s = tostring(v.map[a1 and true or false] or NONE)
|
flickerstreak@1
|
1448 else
|
flickerstreak@1
|
1449 s = tostring(MAP_ONOFF[a1 and true or false] or NONE)
|
flickerstreak@1
|
1450 end
|
flickerstreak@1
|
1451 elseif v.type == "range" then
|
flickerstreak@1
|
1452 if v.isPercent then
|
flickerstreak@1
|
1453 s = tostring(a1 * 100) .. "%"
|
flickerstreak@1
|
1454 else
|
flickerstreak@1
|
1455 s = tostring(a1)
|
flickerstreak@1
|
1456 end
|
flickerstreak@1
|
1457 elseif v.type == "text" and type(v.validate) == "table" then
|
flickerstreak@22
|
1458 if multiToggle then
|
flickerstreak@22
|
1459 if not next(a1) then
|
flickerstreak@22
|
1460 s = NONE
|
flickerstreak@22
|
1461 else
|
flickerstreak@22
|
1462 s = ''
|
flickerstreak@22
|
1463 for k in pairs(a1) do
|
flickerstreak@22
|
1464 if v.validate[k] then
|
flickerstreak@22
|
1465 if s == '' then
|
flickerstreak@22
|
1466 s = v.validate[k]
|
flickerstreak@22
|
1467 else
|
flickerstreak@22
|
1468 s = s .. ', ' .. v.validate[k]
|
flickerstreak@22
|
1469 end
|
flickerstreak@22
|
1470 else
|
flickerstreak@22
|
1471 for _,u in pairs(v.validate) do
|
flickerstreak@22
|
1472 if u == k or (type(v) == "string" and type(k) == "string" and v:lower() == k:lower()) then
|
flickerstreak@22
|
1473 if s == '' then
|
flickerstreak@22
|
1474 s = u
|
flickerstreak@22
|
1475 else
|
flickerstreak@22
|
1476 s = s .. ', ' .. u
|
flickerstreak@22
|
1477 end
|
flickerstreak@22
|
1478 break
|
flickerstreak@22
|
1479 end
|
flickerstreak@22
|
1480 end
|
flickerstreak@22
|
1481 end
|
flickerstreak@22
|
1482 end
|
flickerstreak@22
|
1483 end
|
flickerstreak@22
|
1484 else
|
flickerstreak@22
|
1485 s = tostring(v.validate[a1] or a1 or NONE)
|
flickerstreak@22
|
1486 end
|
flickerstreak@1
|
1487 else
|
flickerstreak@1
|
1488 s = tostring(a1 or NONE)
|
flickerstreak@1
|
1489 end
|
flickerstreak@1
|
1490 if disabled then
|
flickerstreak@1
|
1491 local s = s:gsub("|cff%x%x%x%x%x%x(.-)|r", "%1")
|
flickerstreak@1
|
1492 local desc = (v.desc or NONE):gsub("|cff%x%x%x%x%x%x(.-)|r", "%1")
|
flickerstreak@22
|
1493 print(("|cffcfcfcf - %s: [%s] %s|r"):format(k, s, desc))
|
flickerstreak@1
|
1494 else
|
flickerstreak@22
|
1495 print((" - |cffffff7f%s: [|r%s|cffffff7f]|r %s"):format(k, s, v.desc or NONE))
|
flickerstreak@1
|
1496 end
|
flickerstreak@1
|
1497 else
|
flickerstreak@1
|
1498 if disabled then
|
flickerstreak@1
|
1499 local desc = (v.desc or NONE):gsub("|cff%x%x%x%x%x%x(.-)|r", "%1")
|
flickerstreak@22
|
1500 print(("|cffcfcfcf - %s: %s"):format(k, desc))
|
flickerstreak@1
|
1501 else
|
flickerstreak@22
|
1502 print((" - |cffffff7f%s:|r %s"):format(k, v.desc or NONE))
|
flickerstreak@1
|
1503 end
|
flickerstreak@1
|
1504 end
|
flickerstreak@1
|
1505 end
|
flickerstreak@1
|
1506 end
|
flickerstreak@1
|
1507 for k in pairs(order) do
|
flickerstreak@1
|
1508 order[k] = nil
|
flickerstreak@1
|
1509 end
|
flickerstreak@1
|
1510 else
|
flickerstreak@1
|
1511 if options.desc then
|
flickerstreak@22
|
1512 print(("|cffffff7f%s:|r %s"):format(USAGE, path), realOptions.cmdName or realOptions.name or self)
|
flickerstreak@1
|
1513 print(tostring(options.desc))
|
flickerstreak@1
|
1514 elseif options == realOptions and (self.description or self.notes) then
|
flickerstreak@1
|
1515 print(tostring(self.description or self.notes), realOptions.cmdName or realOptions.name or self)
|
flickerstreak@22
|
1516 print(("|cffffff7f%s:|r %s"):format(USAGE, path))
|
flickerstreak@1
|
1517 else
|
flickerstreak@22
|
1518 print(("|cffffff7f%s:|r %s"):format(USAGE, path), realOptions.cmdName or realOptions.name or self)
|
flickerstreak@1
|
1519 end
|
flickerstreak@1
|
1520 print(NO_OPTIONS_AVAILABLE)
|
flickerstreak@1
|
1521 end
|
flickerstreak@1
|
1522 end
|
flickerstreak@1
|
1523 end
|
flickerstreak@1
|
1524
|
flickerstreak@22
|
1525 local function confirmPopup(message, func, ...)
|
flickerstreak@22
|
1526 if not StaticPopupDialogs["ACECONSOLE20_CONFIRM_DIALOG"] then
|
flickerstreak@22
|
1527 StaticPopupDialogs["ACECONSOLE20_CONFIRM_DIALOG"] = {}
|
flickerstreak@22
|
1528 end
|
flickerstreak@22
|
1529 local t = StaticPopupDialogs["ACECONSOLE20_CONFIRM_DIALOG"]
|
flickerstreak@22
|
1530 for k in pairs(t) do
|
flickerstreak@22
|
1531 t[k] = nil
|
flickerstreak@22
|
1532 end
|
flickerstreak@22
|
1533 t.text = message
|
flickerstreak@22
|
1534 t.button1 = ACCEPT or "Accept"
|
flickerstreak@22
|
1535 t.button2 = CANCEL or "Cancel"
|
flickerstreak@22
|
1536 t.OnAccept = function()
|
flickerstreak@22
|
1537 func(unpack(t))
|
flickerstreak@22
|
1538 end
|
flickerstreak@22
|
1539 for i = 1, select('#', ...) do
|
flickerstreak@22
|
1540 t[i] = select(i, ...)
|
flickerstreak@22
|
1541 end
|
flickerstreak@22
|
1542 t.timeout = 0
|
flickerstreak@22
|
1543 t.whileDead = 1
|
flickerstreak@22
|
1544 t.hideOnEscape = 1
|
flickerstreak@22
|
1545
|
flickerstreak@22
|
1546 StaticPopup_Show("ACECONSOLE20_CONFIRM_DIALOG")
|
flickerstreak@22
|
1547 end
|
flickerstreak@22
|
1548
|
flickerstreak@1
|
1549 local function handlerFunc(self, chat, msg, options)
|
flickerstreak@1
|
1550 if not msg then
|
flickerstreak@1
|
1551 msg = ""
|
flickerstreak@1
|
1552 else
|
flickerstreak@1
|
1553 msg = msg:gsub("^%s*(.-)%s*$", "%1")
|
flickerstreak@1
|
1554 msg = msg:gsub("%s+", " ")
|
flickerstreak@1
|
1555 end
|
flickerstreak@22
|
1556
|
flickerstreak@1
|
1557 local realOptions = options
|
flickerstreak@1
|
1558 local options, path, args, handler, passTable, passValue = findTableLevel(self, options, chat, msg)
|
flickerstreak@22
|
1559 if options.type == "execute" then
|
flickerstreak@22
|
1560 if options.func then
|
flickerstreak@22
|
1561 passTable = nil
|
flickerstreak@22
|
1562 end
|
flickerstreak@22
|
1563 else
|
flickerstreak@22
|
1564 if options.get and options.set then
|
flickerstreak@22
|
1565 passTable = nil
|
flickerstreak@22
|
1566 end
|
flickerstreak@22
|
1567 end
|
flickerstreak@22
|
1568 passValue = options.passValue or passTable and passValue
|
flickerstreak@22
|
1569
|
flickerstreak@1
|
1570 local hidden, disabled = options.cmdHidden or options.hidden, options.disabled
|
flickerstreak@1
|
1571 if hidden then
|
flickerstreak@1
|
1572 if type(hidden) == "function" then
|
flickerstreak@22
|
1573 hidden = hidden(passValue)
|
flickerstreak@1
|
1574 elseif type(hidden) == "string" then
|
flickerstreak@1
|
1575 local f = hidden
|
flickerstreak@1
|
1576 local neg = f:match("^~(.-)$")
|
flickerstreak@1
|
1577 if neg then
|
flickerstreak@1
|
1578 f = neg
|
flickerstreak@1
|
1579 end
|
flickerstreak@1
|
1580 if type(handler[f]) ~= "function" then
|
flickerstreak@22
|
1581 AceConsole:error("%s: %s", handler, OPTION_HANDLER_NOT_FOUND:format(tostring(f)))
|
flickerstreak@1
|
1582 end
|
flickerstreak@22
|
1583 hidden = handler[f](handler, passValue)
|
flickerstreak@1
|
1584 if neg then
|
flickerstreak@1
|
1585 hidden = not hidden
|
flickerstreak@1
|
1586 end
|
flickerstreak@1
|
1587 end
|
flickerstreak@1
|
1588 end
|
flickerstreak@1
|
1589 if hidden then
|
flickerstreak@1
|
1590 disabled = true
|
flickerstreak@1
|
1591 elseif disabled then
|
flickerstreak@1
|
1592 if type(disabled) == "function" then
|
flickerstreak@22
|
1593 disabled = disabled(passValue)
|
flickerstreak@1
|
1594 elseif type(disabled) == "string" then
|
flickerstreak@1
|
1595 local f = disabled
|
flickerstreak@1
|
1596 local neg = f:match("^~(.-)$")
|
flickerstreak@1
|
1597 if neg then
|
flickerstreak@1
|
1598 f = neg
|
flickerstreak@1
|
1599 end
|
flickerstreak@1
|
1600 if type(handler[f]) ~= "function" then
|
flickerstreak@22
|
1601 AceConsole:error("%s: %s", handler, OPTION_HANDLER_NOT_FOUND:format(tostring(f)))
|
flickerstreak@1
|
1602 end
|
flickerstreak@22
|
1603 disabled = handler[f](handler, passValue)
|
flickerstreak@1
|
1604 if neg then
|
flickerstreak@1
|
1605 disabled = not disabled
|
flickerstreak@1
|
1606 end
|
flickerstreak@1
|
1607 end
|
flickerstreak@1
|
1608 end
|
flickerstreak@1
|
1609 local _G_this = this
|
flickerstreak@1
|
1610 local kind = (options.type or "group"):lower()
|
flickerstreak@22
|
1611 local options_p = passTable or options
|
flickerstreak@1
|
1612 if disabled then
|
flickerstreak@22
|
1613 print(OPTION_IS_DISABLED:format(path), realOptions.cmdName or realOptions.name or self)
|
flickerstreak@1
|
1614 elseif kind == "text" then
|
flickerstreak@1
|
1615 if #args > 0 then
|
flickerstreak@1
|
1616 if (type(options.validate) == "table" and #args > 1) or (type(options.validate) ~= "table" and not options.input) then
|
flickerstreak@1
|
1617 local arg = table.concat(args, " ")
|
flickerstreak@1
|
1618 for k,v in pairs(args) do
|
flickerstreak@1
|
1619 args[k] = nil
|
flickerstreak@1
|
1620 end
|
flickerstreak@1
|
1621 args[1] = arg
|
flickerstreak@1
|
1622 end
|
flickerstreak@1
|
1623 if options.validate then
|
flickerstreak@1
|
1624 local good
|
flickerstreak@1
|
1625 if type(options.validate) == "function" then
|
flickerstreak@1
|
1626 good = options.validate(unpack(args))
|
flickerstreak@1
|
1627 elseif type(options.validate) == "table" then
|
flickerstreak@1
|
1628 local arg = args[1]
|
flickerstreak@1
|
1629 arg = tostring(arg):lower()
|
flickerstreak@1
|
1630 for k,v in pairs(options.validate) do
|
flickerstreak@1
|
1631 if v:lower() == arg then
|
flickerstreak@1
|
1632 args[1] = type(k) == "string" and k or v
|
flickerstreak@1
|
1633 good = true
|
flickerstreak@1
|
1634 break
|
flickerstreak@1
|
1635 end
|
flickerstreak@1
|
1636 end
|
flickerstreak@1
|
1637 if not good and type((next(options.validate))) == "string" then
|
flickerstreak@1
|
1638 for k,v in pairs(options.validate) do
|
flickerstreak@1
|
1639 if type(k) == "string" and k:lower() == arg then
|
flickerstreak@1
|
1640 args[1] = k
|
flickerstreak@1
|
1641 good = true
|
flickerstreak@1
|
1642 break
|
flickerstreak@1
|
1643 end
|
flickerstreak@1
|
1644 end
|
flickerstreak@1
|
1645 end
|
flickerstreak@1
|
1646 elseif options.validate == "keybinding" then
|
flickerstreak@1
|
1647 good = keybindingValidateFunc(unpack(args))
|
flickerstreak@1
|
1648 if good ~= false then
|
flickerstreak@1
|
1649 args[1] = good
|
flickerstreak@1
|
1650 end
|
flickerstreak@1
|
1651 else
|
flickerstreak@1
|
1652 if type(handler[options.validate]) ~= "function" then
|
flickerstreak@22
|
1653 AceConsole:error("%s: %s", handler, OPTION_HANDLER_NOT_FOUND:format(tostring(options.validate)))
|
flickerstreak@1
|
1654 end
|
flickerstreak@1
|
1655 good = handler[options.validate](handler, unpack(args))
|
flickerstreak@1
|
1656 end
|
flickerstreak@1
|
1657 if not good then
|
flickerstreak@1
|
1658 local usage
|
flickerstreak@1
|
1659 if type(options.validate) == "table" then
|
flickerstreak@1
|
1660 if not order then
|
flickerstreak@1
|
1661 order = {}
|
flickerstreak@1
|
1662 end
|
flickerstreak@1
|
1663 for k,v in pairs(options.validate) do
|
flickerstreak@1
|
1664 table.insert(order, v)
|
flickerstreak@1
|
1665 end
|
flickerstreak@1
|
1666 usage = "{" .. table.concat(order, " || ") .. "}"
|
flickerstreak@1
|
1667 for k in pairs(order) do
|
flickerstreak@1
|
1668 order[k] = nil
|
flickerstreak@1
|
1669 end
|
flickerstreak@1
|
1670 elseif options.validate == "keybinding" then
|
flickerstreak@1
|
1671 usage = KEYBINDING_USAGE
|
flickerstreak@1
|
1672 else
|
flickerstreak@1
|
1673 usage = options.usage or "<value>"
|
flickerstreak@1
|
1674 end
|
flickerstreak@22
|
1675 print((options.error or IS_NOT_A_VALID_OPTION_FOR):format(tostring(table.concat(args, " ")), path), realOptions.cmdName or realOptions.name or self)
|
flickerstreak@22
|
1676 print(("|cffffff7f%s:|r %s %s"):format(USAGE, path, usage))
|
flickerstreak@1
|
1677 return
|
flickerstreak@1
|
1678 end
|
flickerstreak@1
|
1679 end
|
flickerstreak@22
|
1680
|
flickerstreak@1
|
1681 local var
|
flickerstreak@22
|
1682 local multiToggle
|
flickerstreak@22
|
1683 for k in pairs(tmp) do
|
flickerstreak@22
|
1684 tmp[k] = nil
|
flickerstreak@22
|
1685 end
|
flickerstreak@22
|
1686 multiToggle = options_p.multiToggle
|
flickerstreak@22
|
1687 if not options_p.get then
|
flickerstreak@22
|
1688 elseif type(options_p.get) == "function" then
|
flickerstreak@22
|
1689 if multiToggle then
|
flickerstreak@22
|
1690 var = tmp
|
flickerstreak@22
|
1691 for k,v in pairs(options.validate) do
|
flickerstreak@22
|
1692 local val = type(k) ~= "number" and k or v
|
flickerstreak@22
|
1693 if passValue then
|
flickerstreak@22
|
1694 var[val] = options_p.get(passValue, val) or nil
|
flickerstreak@22
|
1695 else
|
flickerstreak@22
|
1696 var[val] = options_p.get(val) or nil
|
flickerstreak@22
|
1697 end
|
flickerstreak@22
|
1698 end
|
flickerstreak@1
|
1699 else
|
flickerstreak@22
|
1700 var = options_p.get(passValue)
|
flickerstreak@1
|
1701 end
|
flickerstreak@1
|
1702 else
|
flickerstreak@22
|
1703 if type(handler[options_p.get]) ~= "function" then
|
flickerstreak@22
|
1704 AceConsole:error("%s: %s", handler, OPTION_HANDLER_NOT_FOUND:format(tostring(options_p.get)))
|
flickerstreak@22
|
1705 end
|
flickerstreak@22
|
1706 if multiToggle then
|
flickerstreak@22
|
1707 var = tmp
|
flickerstreak@22
|
1708 for k,v in pairs(options.validate) do
|
flickerstreak@22
|
1709 local val = type(k) ~= "number" and k or v
|
flickerstreak@22
|
1710 if passValue then
|
flickerstreak@22
|
1711 var[val] = handler[options_p.get](handler, passValue, val) or nil
|
flickerstreak@22
|
1712 else
|
flickerstreak@22
|
1713 var[val] = handler[options_p.get](handler, val) or nil
|
flickerstreak@22
|
1714 end
|
flickerstreak@22
|
1715 end
|
flickerstreak@1
|
1716 else
|
flickerstreak@22
|
1717 var = handler[options_p.get](handler, passValue)
|
flickerstreak@1
|
1718 end
|
flickerstreak@1
|
1719 end
|
flickerstreak@22
|
1720
|
flickerstreak@22
|
1721 if multiToggle or var ~= args[1] then
|
flickerstreak@22
|
1722 if multiToggle then
|
flickerstreak@22
|
1723 local current = var[args[1]]
|
flickerstreak@22
|
1724 if current == nil and type(args[1]) == "string" then
|
flickerstreak@22
|
1725 for k in pairs(var) do
|
flickerstreak@22
|
1726 if type(k) == "string" and k:lower() == args[1]:lower() then
|
flickerstreak@22
|
1727 current = true
|
flickerstreak@22
|
1728 break
|
flickerstreak@22
|
1729 end
|
flickerstreak@22
|
1730 end
|
flickerstreak@22
|
1731 end
|
flickerstreak@22
|
1732 args[2] = not current
|
flickerstreak@22
|
1733 end
|
flickerstreak@22
|
1734 if type(options_p.set) == "function" then
|
flickerstreak@22
|
1735 if passValue then
|
flickerstreak@22
|
1736 options_p.set(passValue, unpack(args))
|
flickerstreak@1
|
1737 else
|
flickerstreak@22
|
1738 options_p.set(unpack(args))
|
flickerstreak@1
|
1739 end
|
flickerstreak@1
|
1740 else
|
flickerstreak@22
|
1741 if type(handler[options_p.set]) ~= "function" then
|
flickerstreak@22
|
1742 AceConsole:error("%s: %s", handler, OPTION_HANDLER_NOT_FOUND:format(tostring(options_p.set)))
|
flickerstreak@22
|
1743 end
|
flickerstreak@22
|
1744 if passValue then
|
flickerstreak@22
|
1745 handler[options_p.set](handler, passValue, unpack(args))
|
flickerstreak@1
|
1746 else
|
flickerstreak@22
|
1747 handler[options_p.set](handler, unpack(args))
|
flickerstreak@1
|
1748 end
|
flickerstreak@1
|
1749 end
|
flickerstreak@1
|
1750 end
|
flickerstreak@1
|
1751 end
|
flickerstreak@22
|
1752
|
flickerstreak@1
|
1753 if #args > 0 then
|
flickerstreak@1
|
1754 local var
|
flickerstreak@22
|
1755 local multiToggle
|
flickerstreak@22
|
1756 for k in pairs(tmp) do
|
flickerstreak@22
|
1757 tmp[k] = nil
|
flickerstreak@22
|
1758 end
|
flickerstreak@22
|
1759 multiToggle = options_p.multiToggle
|
flickerstreak@22
|
1760 if not options_p.get then
|
flickerstreak@22
|
1761 elseif type(options_p.get) == "function" then
|
flickerstreak@22
|
1762 if multiToggle then
|
flickerstreak@22
|
1763 var = tmp
|
flickerstreak@22
|
1764 for k,v in pairs(options_p.validate) do
|
flickerstreak@22
|
1765 local val = type(k) ~= "number" and k or v
|
flickerstreak@22
|
1766 if passValue then
|
flickerstreak@22
|
1767 var[val] = options_p.get(passValue, val) or nil
|
flickerstreak@22
|
1768 else
|
flickerstreak@22
|
1769 var[val] = options_p.get(val) or nil
|
flickerstreak@22
|
1770 end
|
flickerstreak@22
|
1771 end
|
flickerstreak@1
|
1772 else
|
flickerstreak@22
|
1773 var = options_p.get(passValue)
|
flickerstreak@1
|
1774 end
|
flickerstreak@1
|
1775 else
|
flickerstreak@22
|
1776 if type(handler[options_p.get]) ~= "function" then
|
flickerstreak@22
|
1777 AceConsole:error("%s: %s", handler, OPTION_HANDLER_NOT_FOUND:format(tostring(options_p.get)))
|
flickerstreak@22
|
1778 end
|
flickerstreak@22
|
1779 if multiToggle then
|
flickerstreak@22
|
1780 var = tmp
|
flickerstreak@22
|
1781 for k,v in pairs(options.validate) do
|
flickerstreak@22
|
1782 local val = type(k) ~= "number" and k or v
|
flickerstreak@22
|
1783 if passValue then
|
flickerstreak@22
|
1784 var[val] = handler[options_p.get](handler, passValue, val) or nil
|
flickerstreak@22
|
1785 else
|
flickerstreak@22
|
1786 var[val] = handler[options_p.get](handler, val) or nil
|
flickerstreak@22
|
1787 end
|
flickerstreak@22
|
1788 end
|
flickerstreak@1
|
1789 else
|
flickerstreak@22
|
1790 var = handler[options_p.get](handler, passValue)
|
flickerstreak@1
|
1791 end
|
flickerstreak@1
|
1792 end
|
flickerstreak@22
|
1793 if multiToggle then
|
flickerstreak@22
|
1794 if not next(var) then
|
flickerstreak@22
|
1795 var = NONE
|
flickerstreak@22
|
1796 else
|
flickerstreak@22
|
1797 if not order then
|
flickerstreak@22
|
1798 order = {}
|
flickerstreak@22
|
1799 end
|
flickerstreak@22
|
1800 for k in pairs(var) do
|
flickerstreak@22
|
1801 if options.validate[k] then
|
flickerstreak@22
|
1802 order[#order+1] = options.validate[k]
|
flickerstreak@22
|
1803 else
|
flickerstreak@22
|
1804 for _,v in pairs(options.validate) do
|
flickerstreak@22
|
1805 if v == k or (type(v) == "string" and type(k) == "string" and v:lower() == k:lower()) then
|
flickerstreak@22
|
1806 order[#order+1] = v
|
flickerstreak@22
|
1807 break
|
flickerstreak@22
|
1808 end
|
flickerstreak@22
|
1809 end
|
flickerstreak@22
|
1810 end
|
flickerstreak@22
|
1811 end
|
flickerstreak@22
|
1812 table.sort(order, icaseSort)
|
flickerstreak@22
|
1813 var = table.concat(order, ", ")
|
flickerstreak@22
|
1814 for k in pairs(order) do
|
flickerstreak@22
|
1815 order[k] = nil
|
flickerstreak@22
|
1816 end
|
flickerstreak@22
|
1817 end
|
flickerstreak@22
|
1818 elseif type(options.validate) == "table" then
|
flickerstreak@1
|
1819 var = options.validate[var] or var
|
flickerstreak@1
|
1820 end
|
flickerstreak@22
|
1821 if options_p.get then
|
flickerstreak@22
|
1822 print((options.message or IS_NOW_SET_TO):format(tostring(options.cmdName or options.name), tostring(var or NONE)), realOptions.cmdName or realOptions.name or self)
|
flickerstreak@1
|
1823 end
|
flickerstreak@1
|
1824 if var == args[1] then
|
flickerstreak@1
|
1825 return
|
flickerstreak@1
|
1826 end
|
flickerstreak@1
|
1827 else
|
flickerstreak@22
|
1828 printUsage(self, handler, realOptions, options, path, args, passValue)
|
flickerstreak@1
|
1829 return
|
flickerstreak@1
|
1830 end
|
flickerstreak@1
|
1831 elseif kind == "execute" then
|
flickerstreak@22
|
1832 local confirm = options.confirm
|
flickerstreak@22
|
1833 if confirm == true then
|
flickerstreak@22
|
1834 confirm = DEFAULT_CONFIRM_MESSAGE:format(options.desc or options.name or UNKNOWN or "Unknown")
|
flickerstreak@22
|
1835 end
|
flickerstreak@22
|
1836 if type(options_p.func) == "function" then
|
flickerstreak@22
|
1837 if confirm then
|
flickerstreak@22
|
1838 confirmPopup(confirm, options_p.func, passValue)
|
flickerstreak@1
|
1839 else
|
flickerstreak@22
|
1840 options_p.func(passValue)
|
flickerstreak@1
|
1841 end
|
flickerstreak@1
|
1842 else
|
flickerstreak@22
|
1843 if type(handler[options_p.func]) ~= "function" then
|
flickerstreak@22
|
1844 AceConsole:error("%s: %s", handler, OPTION_HANDLER_NOT_FOUND:format(tostring(options_p.func)))
|
flickerstreak@22
|
1845 end
|
flickerstreak@22
|
1846 if confirm then
|
flickerstreak@22
|
1847 confirmPopup(confirm, handler[options_p.func], handler, passValue)
|
flickerstreak@1
|
1848 else
|
flickerstreak@22
|
1849 handler[options_p.func](handler, passValue)
|
flickerstreak@1
|
1850 end
|
flickerstreak@1
|
1851 end
|
flickerstreak@1
|
1852 elseif kind == "toggle" then
|
flickerstreak@1
|
1853 local var
|
flickerstreak@22
|
1854 if type(options_p.get) == "function" then
|
flickerstreak@22
|
1855 var = options_p.get(passValue)
|
flickerstreak@22
|
1856 else
|
flickerstreak@22
|
1857 local f = options_p.get
|
flickerstreak@22
|
1858 local neg = f:match("^~(.-)$")
|
flickerstreak@22
|
1859 if neg then
|
flickerstreak@22
|
1860 f = neg
|
flickerstreak@22
|
1861 end
|
flickerstreak@22
|
1862 if type(handler[f]) ~= "function" then
|
flickerstreak@22
|
1863 AceConsole:error("%s: %s", handler, OPTION_HANDLER_NOT_FOUND:format(tostring(f)))
|
flickerstreak@22
|
1864 end
|
flickerstreak@22
|
1865 var = handler[f](handler, passValue)
|
flickerstreak@22
|
1866 if neg then
|
flickerstreak@22
|
1867 var = not var
|
flickerstreak@22
|
1868 end
|
flickerstreak@22
|
1869 end
|
flickerstreak@22
|
1870 if type(options_p.set) == "function" then
|
flickerstreak@22
|
1871 if passValue then
|
flickerstreak@22
|
1872 options_p.set(passValue, not var)
|
flickerstreak@1
|
1873 else
|
flickerstreak@22
|
1874 options_p.set(not var)
|
flickerstreak@1
|
1875 end
|
flickerstreak@1
|
1876 else
|
flickerstreak@22
|
1877 if type(handler[options_p.set]) ~= "function" then
|
flickerstreak@22
|
1878 AceConsole:error("%s: %s", handler, OPTION_HANDLER_NOT_FOUND:format(tostring(options_p.set)))
|
flickerstreak@22
|
1879 end
|
flickerstreak@22
|
1880 if passValue then
|
flickerstreak@22
|
1881 handler[options_p.set](handler, passValue, not var)
|
flickerstreak@1
|
1882 else
|
flickerstreak@22
|
1883 handler[options_p.set](handler, not var)
|
flickerstreak@1
|
1884 end
|
flickerstreak@1
|
1885 end
|
flickerstreak@22
|
1886 if type(options_p.get) == "function" then
|
flickerstreak@22
|
1887 var = options_p.get(passValue)
|
flickerstreak@22
|
1888 else
|
flickerstreak@22
|
1889 local f = options_p.get
|
flickerstreak@22
|
1890 local neg = f:match("^~(.-)$")
|
flickerstreak@22
|
1891 if neg then
|
flickerstreak@22
|
1892 f = neg
|
flickerstreak@22
|
1893 end
|
flickerstreak@22
|
1894 var = handler[f](handler, passValue)
|
flickerstreak@22
|
1895 if neg then
|
flickerstreak@22
|
1896 var = not var
|
flickerstreak@22
|
1897 end
|
flickerstreak@22
|
1898 end
|
flickerstreak@22
|
1899
|
flickerstreak@22
|
1900 print((options.message or IS_NOW_SET_TO):format(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
|
1901 elseif kind == "range" then
|
flickerstreak@1
|
1902 local arg
|
flickerstreak@1
|
1903 if #args <= 1 then
|
flickerstreak@1
|
1904 arg = args[1]
|
flickerstreak@1
|
1905 else
|
flickerstreak@1
|
1906 arg = table.concat(args, " ")
|
flickerstreak@1
|
1907 end
|
flickerstreak@1
|
1908
|
flickerstreak@1
|
1909 if arg then
|
flickerstreak@1
|
1910 local min = options.min or 0
|
flickerstreak@1
|
1911 local max = options.max or 1
|
flickerstreak@1
|
1912 local good = false
|
flickerstreak@1
|
1913 if type(arg) == "number" then
|
flickerstreak@1
|
1914 if options.isPercent then
|
flickerstreak@1
|
1915 arg = arg / 100
|
flickerstreak@1
|
1916 end
|
flickerstreak@1
|
1917
|
flickerstreak@1
|
1918 if arg >= min and arg <= max then
|
flickerstreak@1
|
1919 good = true
|
flickerstreak@1
|
1920 end
|
flickerstreak@22
|
1921
|
flickerstreak@1
|
1922 if good and type(options.step) == "number" and options.step > 0 then
|
flickerstreak@1
|
1923 local step = options.step
|
flickerstreak@1
|
1924 arg = math.floor((arg - min) / step + 0.5) * step + min
|
flickerstreak@1
|
1925 if arg > max then
|
flickerstreak@1
|
1926 arg = max
|
flickerstreak@1
|
1927 elseif arg < min then
|
flickerstreak@1
|
1928 arg = min
|
flickerstreak@1
|
1929 end
|
flickerstreak@1
|
1930 end
|
flickerstreak@1
|
1931 end
|
flickerstreak@1
|
1932 if not good then
|
flickerstreak@1
|
1933 local usage
|
flickerstreak@1
|
1934 local min = options.min or 0
|
flickerstreak@1
|
1935 local max = options.max or 1
|
flickerstreak@1
|
1936 if options.isPercent then
|
flickerstreak@1
|
1937 min, max = min * 100, max * 100
|
flickerstreak@1
|
1938 end
|
flickerstreak@1
|
1939 local bit = "-"
|
flickerstreak@1
|
1940 if min < 0 or max < 0 then
|
flickerstreak@1
|
1941 bit = " - "
|
flickerstreak@1
|
1942 end
|
flickerstreak@22
|
1943 usage = ("(%s%s%s)"):format(min, bit, max)
|
flickerstreak@22
|
1944 print((options.error or IS_NOT_A_VALID_VALUE_FOR):format(tostring(arg), path), realOptions.cmdName or realOptions.name or self)
|
flickerstreak@22
|
1945 print(("|cffffff7f%s:|r %s %s"):format(USAGE, path, usage))
|
flickerstreak@1
|
1946 return
|
flickerstreak@1
|
1947 end
|
flickerstreak@22
|
1948
|
flickerstreak@1
|
1949 local var
|
flickerstreak@22
|
1950 if type(options_p.get) == "function" then
|
flickerstreak@22
|
1951 var = options_p.get(passValue)
|
flickerstreak@22
|
1952 else
|
flickerstreak@22
|
1953 if type(handler[options_p.get]) ~= "function" then
|
flickerstreak@22
|
1954 AceConsole:error("%s: %s", handler, OPTION_HANDLER_NOT_FOUND:format(tostring(options_p.get)))
|
flickerstreak@1
|
1955 end
|
flickerstreak@22
|
1956 var = handler[options_p.get](handler, passValue)
|
flickerstreak@1
|
1957 end
|
flickerstreak@22
|
1958
|
flickerstreak@1
|
1959 if var ~= arg then
|
flickerstreak@22
|
1960 if type(options_p.set) == "function" then
|
flickerstreak@22
|
1961 if passValue then
|
flickerstreak@22
|
1962 options_p.set(passValue, arg)
|
flickerstreak@1
|
1963 else
|
flickerstreak@22
|
1964 options_p.set(arg)
|
flickerstreak@1
|
1965 end
|
flickerstreak@1
|
1966 else
|
flickerstreak@22
|
1967 if type(handler[options_p.set]) ~= "function" then
|
flickerstreak@22
|
1968 AceConsole:error("%s: %s", handler, OPTION_HANDLER_NOT_FOUND:format(tostring(options_p.set)))
|
flickerstreak@22
|
1969 end
|
flickerstreak@22
|
1970 if passValue then
|
flickerstreak@22
|
1971 handler[options_p.set](handler, passValue, arg)
|
flickerstreak@1
|
1972 else
|
flickerstreak@22
|
1973 handler[options_p.set](handler, arg)
|
flickerstreak@1
|
1974 end
|
flickerstreak@1
|
1975 end
|
flickerstreak@1
|
1976 end
|
flickerstreak@1
|
1977 end
|
flickerstreak@22
|
1978
|
flickerstreak@1
|
1979 if arg then
|
flickerstreak@1
|
1980 local var
|
flickerstreak@22
|
1981 if type(options_p.get) == "function" then
|
flickerstreak@22
|
1982 var = options_p.get(passValue)
|
flickerstreak@22
|
1983 else
|
flickerstreak@22
|
1984 if type(handler[options_p.get]) ~= "function" then
|
flickerstreak@22
|
1985 AceConsole:error("%s: %s", handler, OPTION_HANDLER_NOT_FOUND:format(tostring(options_p.get)))
|
flickerstreak@1
|
1986 end
|
flickerstreak@22
|
1987 var = handler[options_p.get](handler, passValue)
|
flickerstreak@1
|
1988 end
|
flickerstreak@22
|
1989
|
flickerstreak@1
|
1990 if var and options.isPercent then
|
flickerstreak@1
|
1991 var = tostring(var * 100) .. "%"
|
flickerstreak@1
|
1992 end
|
flickerstreak@22
|
1993 print((options.message or IS_NOW_SET_TO):format(tostring(options.cmdName or options.name), tostring(var or NONE)), realOptions.cmdName or realOptions.name or self)
|
flickerstreak@1
|
1994 if var == arg then
|
flickerstreak@1
|
1995 return
|
flickerstreak@1
|
1996 end
|
flickerstreak@1
|
1997 else
|
flickerstreak@22
|
1998 printUsage(self, handler, realOptions, options, path, args, passValue)
|
flickerstreak@1
|
1999 return
|
flickerstreak@1
|
2000 end
|
flickerstreak@1
|
2001 elseif kind == "color" then
|
flickerstreak@1
|
2002 if #args > 0 then
|
flickerstreak@1
|
2003 local r,g,b,a
|
flickerstreak@1
|
2004 if #args == 1 then
|
flickerstreak@1
|
2005 local arg = tostring(args[1])
|
flickerstreak@1
|
2006 if options.hasAlpha then
|
flickerstreak@1
|
2007 if arg:len() == 8 and arg:find("^%x*$") then
|
flickerstreak@1
|
2008 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
|
2009 end
|
flickerstreak@1
|
2010 else
|
flickerstreak@1
|
2011 if arg:len() == 6 and arg:find("^%x*$") then
|
flickerstreak@1
|
2012 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
|
2013 end
|
flickerstreak@1
|
2014 end
|
flickerstreak@1
|
2015 elseif #args == 4 and options.hasAlpha then
|
flickerstreak@1
|
2016 local a1,a2,a3,a4 = args[1], args[2], args[3], args[4]
|
flickerstreak@1
|
2017 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
|
2018 r,g,b,a = a1,a2,a3,a4
|
flickerstreak@1
|
2019 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
|
2020 r,g,b,a = tonumber(a1, 16) / 255, tonumber(a2, 16) / 255, tonumber(a3, 16) / 255, tonumber(a4, 16) / 255
|
flickerstreak@1
|
2021 end
|
flickerstreak@1
|
2022 elseif #args == 3 and not options.hasAlpha then
|
flickerstreak@1
|
2023 local a1,a2,a3 = args[1], args[2], args[3]
|
flickerstreak@1
|
2024 if type(a1) == "number" and type(a2) == "number" and type(a3) == "number" and a1 <= 1 and a2 <= 1 and a3 <= 1 then
|
flickerstreak@1
|
2025 r,g,b = a1,a2,a3
|
flickerstreak@1
|
2026 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
|
2027 r,g,b = tonumber(a1, 16) / 255, tonumber(a2, 16) / 255, tonumber(a3, 16) / 255
|
flickerstreak@1
|
2028 end
|
flickerstreak@1
|
2029 end
|
flickerstreak@1
|
2030 if not r then
|
flickerstreak@22
|
2031 print((options.error or IS_NOT_A_VALID_OPTION_FOR):format(table.concat(args, ' '), path), realOptions.cmdName or realOptions.name or self)
|
flickerstreak@22
|
2032 print(("|cffffff7f%s:|r %s {0-1} {0-1} {0-1}%s"):format(USAGE, path, options.hasAlpha and " {0-1}" or ""))
|
flickerstreak@1
|
2033 return
|
flickerstreak@1
|
2034 end
|
flickerstreak@22
|
2035
|
flickerstreak@22
|
2036 if type(options_p.set) == "function" then
|
flickerstreak@22
|
2037 if passValue then
|
flickerstreak@22
|
2038 options_p.set(passValue, r,g,b,a)
|
flickerstreak@1
|
2039 else
|
flickerstreak@22
|
2040 options_p.set(r,g,b,a)
|
flickerstreak@1
|
2041 end
|
flickerstreak@1
|
2042 else
|
flickerstreak@22
|
2043 if type(handler[options_p.set]) ~= "function" then
|
flickerstreak@22
|
2044 AceConsole:error("%s: %s", handler, OPTION_HANDLER_NOT_FOUND:format(tostring(options_p.set)))
|
flickerstreak@22
|
2045 end
|
flickerstreak@22
|
2046 if passValue then
|
flickerstreak@22
|
2047 handler[options_p.set](handler, passValue, r,g,b,a)
|
flickerstreak@1
|
2048 else
|
flickerstreak@22
|
2049 handler[options_p.set](handler, r,g,b,a)
|
flickerstreak@1
|
2050 end
|
flickerstreak@1
|
2051 end
|
flickerstreak@22
|
2052
|
flickerstreak@1
|
2053 local r,g,b,a
|
flickerstreak@22
|
2054 if type(options_p.get) == "function" then
|
flickerstreak@22
|
2055 r,g,b,a = options_p.get(passValue)
|
flickerstreak@22
|
2056 else
|
flickerstreak@22
|
2057 if type(handler[options_p.get]) ~= "function" then
|
flickerstreak@22
|
2058 AceConsole:error("%s: %s", handler, OPTION_HANDLER_NOT_FOUND:format(tostring(options_p.get)))
|
flickerstreak@1
|
2059 end
|
flickerstreak@22
|
2060 r,g,b,a = handler[options_p.get](handler, passValue)
|
flickerstreak@1
|
2061 end
|
flickerstreak@22
|
2062
|
flickerstreak@1
|
2063 local s
|
flickerstreak@1
|
2064 if type(r) == "number" and type(g) == "number" and type(b) == "number" then
|
flickerstreak@1
|
2065 if options.hasAlpha and type(a) == "number" then
|
flickerstreak@22
|
2066 s = ("|c%02x%02x%02x%02x%02x%02x%02x%02x|r"):format(a*255, r*255, g*255, b*255, r*255, g*255, b*255, a*255)
|
flickerstreak@1
|
2067 else
|
flickerstreak@22
|
2068 s = ("|cff%02x%02x%02x%02x%02x%02x|r"):format(r*255, g*255, b*255, r*255, g*255, b*255)
|
flickerstreak@1
|
2069 end
|
flickerstreak@1
|
2070 else
|
flickerstreak@1
|
2071 s = NONE
|
flickerstreak@1
|
2072 end
|
flickerstreak@22
|
2073 print((options.message or IS_NOW_SET_TO):format(tostring(options.cmdName or options.name), s), realOptions.cmdName or realOptions.name or self)
|
flickerstreak@1
|
2074 else
|
flickerstreak@1
|
2075 local r,g,b,a
|
flickerstreak@22
|
2076 if type(options_p.get) == "function" then
|
flickerstreak@22
|
2077 r,g,b,a = options_p.get(passValue)
|
flickerstreak@22
|
2078 else
|
flickerstreak@22
|
2079 if type(handler[options_p.get]) ~= "function" then
|
flickerstreak@22
|
2080 AceConsole:error("%s: %s", handler, OPTION_HANDLER_NOT_FOUND:format(tostring(options_p.get)))
|
flickerstreak@1
|
2081 end
|
flickerstreak@22
|
2082 r,g,b,a = handler[options_p.get](handler, passValue)
|
flickerstreak@1
|
2083 end
|
flickerstreak@22
|
2084
|
flickerstreak@1
|
2085 if not colorTable then
|
flickerstreak@1
|
2086 colorTable = {}
|
flickerstreak@1
|
2087 local t = colorTable
|
flickerstreak@22
|
2088
|
flickerstreak@1
|
2089 if ColorPickerOkayButton then
|
flickerstreak@1
|
2090 local ColorPickerOkayButton_OnClick = ColorPickerOkayButton:GetScript("OnClick")
|
flickerstreak@1
|
2091 ColorPickerOkayButton:SetScript("OnClick", function()
|
flickerstreak@1
|
2092 if ColorPickerOkayButton_OnClick then
|
flickerstreak@1
|
2093 ColorPickerOkayButton_OnClick()
|
flickerstreak@1
|
2094 end
|
flickerstreak@1
|
2095 if t.active then
|
flickerstreak@1
|
2096 ColorPickerFrame.cancelFunc = nil
|
flickerstreak@1
|
2097 ColorPickerFrame.func = nil
|
flickerstreak@1
|
2098 ColorPickerFrame.opacityFunc = nil
|
flickerstreak@1
|
2099 local r,g,b,a
|
flickerstreak@1
|
2100 if t.passValue then
|
flickerstreak@1
|
2101 if type(t.get) == "function" then
|
flickerstreak@1
|
2102 r,g,b,a = t.get(t.passValue)
|
flickerstreak@1
|
2103 else
|
flickerstreak@1
|
2104 if type(t.handler[t.get]) ~= "function" then
|
flickerstreak@22
|
2105 AceConsole:error("%s: %s", handler, OPTION_HANDLER_NOT_FOUND:format(tostring(t.get)))
|
flickerstreak@1
|
2106 end
|
flickerstreak@1
|
2107 r,g,b,a = t.handler[t.get](t.handler, t.passValue)
|
flickerstreak@1
|
2108 end
|
flickerstreak@1
|
2109 else
|
flickerstreak@1
|
2110 if type(t.get) == "function" then
|
flickerstreak@1
|
2111 r,g,b,a = t.get()
|
flickerstreak@1
|
2112 else
|
flickerstreak@1
|
2113 if type(t.handler[t.get]) ~= "function" then
|
flickerstreak@22
|
2114 AceConsole:error("%s: %s", handler, OPTION_HANDLER_NOT_FOUND:format(tostring(t.get)))
|
flickerstreak@1
|
2115 end
|
flickerstreak@1
|
2116 r,g,b,a = t.handler[t.get](t.handler)
|
flickerstreak@1
|
2117 end
|
flickerstreak@1
|
2118 end
|
flickerstreak@1
|
2119 if r ~= t.r or g ~= t.g or b ~= t.b or (t.hasAlpha and a ~= t.a) then
|
flickerstreak@1
|
2120 local s
|
flickerstreak@1
|
2121 if type(r) == "number" and type(g) == "number" and type(b) == "number" then
|
flickerstreak@1
|
2122 if t.hasAlpha and type(a) == "number" then
|
flickerstreak@22
|
2123 s = ("|c%02x%02x%02x%02x%02x%02x%02x%02x|r"):format(a*255, r*255, g*255, b*255, r*255, g*255, b*255, a*255)
|
flickerstreak@1
|
2124 else
|
flickerstreak@22
|
2125 s = ("|cff%02x%02x%02x%02x%02x%02x|r"):format(r*255, g*255, b*255, r*255, g*255, b*255)
|
flickerstreak@1
|
2126 end
|
flickerstreak@1
|
2127 else
|
flickerstreak@1
|
2128 s = NONE
|
flickerstreak@1
|
2129 end
|
flickerstreak@22
|
2130 print(t.message:format(tostring(t.name), s), t.realOptions.cmdName or t.realOptions.name or self)
|
flickerstreak@1
|
2131 end
|
flickerstreak@1
|
2132 for k,v in pairs(t) do
|
flickerstreak@1
|
2133 t[k] = nil
|
flickerstreak@1
|
2134 end
|
flickerstreak@1
|
2135 end
|
flickerstreak@1
|
2136 end)
|
flickerstreak@1
|
2137 end
|
flickerstreak@1
|
2138 else
|
flickerstreak@1
|
2139 for k,v in pairs(colorTable) do
|
flickerstreak@1
|
2140 colorTable[k] = nil
|
flickerstreak@1
|
2141 end
|
flickerstreak@1
|
2142 end
|
flickerstreak@22
|
2143
|
flickerstreak@1
|
2144 if type(r) ~= "number" or type(g) ~= "number" or type(b) ~= "number" then
|
flickerstreak@1
|
2145 r,g,b = 1, 1, 1
|
flickerstreak@1
|
2146 end
|
flickerstreak@1
|
2147 if type(a) ~= "number" then
|
flickerstreak@1
|
2148 a = 1
|
flickerstreak@1
|
2149 end
|
flickerstreak@1
|
2150 local t = colorTable
|
flickerstreak@1
|
2151 t.r = r
|
flickerstreak@1
|
2152 t.g = g
|
flickerstreak@1
|
2153 t.b = b
|
flickerstreak@1
|
2154 if hasAlpha then
|
flickerstreak@1
|
2155 t.a = a
|
flickerstreak@1
|
2156 end
|
flickerstreak@1
|
2157 t.realOptions = realOptions
|
flickerstreak@1
|
2158 t.hasAlpha = options.hasAlpha
|
flickerstreak@1
|
2159 t.handler = handler
|
flickerstreak@22
|
2160 t.set = options_p.set
|
flickerstreak@22
|
2161 t.get = options_p.get
|
flickerstreak@1
|
2162 t.name = options.cmdName or options.name
|
flickerstreak@1
|
2163 t.message = options.message or IS_NOW_SET_TO
|
flickerstreak@1
|
2164 t.passValue = passValue
|
flickerstreak@1
|
2165 t.active = true
|
flickerstreak@22
|
2166
|
flickerstreak@1
|
2167 if not colorFunc then
|
flickerstreak@1
|
2168 colorFunc = function()
|
flickerstreak@1
|
2169 local r,g,b = ColorPickerFrame:GetColorRGB()
|
flickerstreak@1
|
2170 if t.hasAlpha then
|
flickerstreak@1
|
2171 local a = 1 - OpacitySliderFrame:GetValue()
|
flickerstreak@1
|
2172 if type(t.set) == "function" then
|
flickerstreak@1
|
2173 if t.passValue then
|
flickerstreak@1
|
2174 t.set(t.passValue, r,g,b,a)
|
flickerstreak@1
|
2175 else
|
flickerstreak@1
|
2176 t.set(r,g,b,a)
|
flickerstreak@1
|
2177 end
|
flickerstreak@1
|
2178 else
|
flickerstreak@1
|
2179 if type(t.handler[t.set]) ~= "function" then
|
flickerstreak@22
|
2180 AceConsole:error("%s: %s", handler, OPTION_HANDLER_NOT_FOUND:format(tostring(t.set)))
|
flickerstreak@1
|
2181 end
|
flickerstreak@1
|
2182 if t.passValue then
|
flickerstreak@1
|
2183 t.handler[t.set](t.handler, t.passValue, r,g,b,a)
|
flickerstreak@1
|
2184 else
|
flickerstreak@1
|
2185 t.handler[t.set](t.handler, r,g,b,a)
|
flickerstreak@1
|
2186 end
|
flickerstreak@1
|
2187 end
|
flickerstreak@1
|
2188 else
|
flickerstreak@1
|
2189 if type(t.set) == "function" then
|
flickerstreak@1
|
2190 if t.passValue then
|
flickerstreak@1
|
2191 t.set(t.passValue, r,g,b)
|
flickerstreak@1
|
2192 else
|
flickerstreak@1
|
2193 t.set(r,g,b)
|
flickerstreak@1
|
2194 end
|
flickerstreak@1
|
2195 else
|
flickerstreak@1
|
2196 if type(t.handler[t.set]) ~= "function" then
|
flickerstreak@22
|
2197 AceConsole:error("%s: %s", handler, OPTION_HANDLER_NOT_FOUND:format(tostring(t.set)))
|
flickerstreak@1
|
2198 end
|
flickerstreak@1
|
2199 if t.passValue then
|
flickerstreak@1
|
2200 t.handler[t.set](t.handler, t.passValue, r,g,b)
|
flickerstreak@1
|
2201 else
|
flickerstreak@1
|
2202 t.handler[t.set](t.handler, r,g,b)
|
flickerstreak@1
|
2203 end
|
flickerstreak@1
|
2204 end
|
flickerstreak@1
|
2205 end
|
flickerstreak@1
|
2206 end
|
flickerstreak@1
|
2207 end
|
flickerstreak@22
|
2208
|
flickerstreak@1
|
2209 ColorPickerFrame.func = colorFunc
|
flickerstreak@1
|
2210 ColorPickerFrame.hasOpacity = options.hasAlpha
|
flickerstreak@1
|
2211 if options.hasAlpha then
|
flickerstreak@1
|
2212 ColorPickerFrame.opacityFunc = ColorPickerFrame.func
|
flickerstreak@1
|
2213 ColorPickerFrame.opacity = 1 - a
|
flickerstreak@1
|
2214 end
|
flickerstreak@1
|
2215 ColorPickerFrame:SetColorRGB(r,g,b)
|
flickerstreak@22
|
2216
|
flickerstreak@1
|
2217 if not colorCancelFunc then
|
flickerstreak@1
|
2218 colorCancelFunc = function()
|
flickerstreak@1
|
2219 if t.hasAlpha then
|
flickerstreak@1
|
2220 if type(t.set) == "function" then
|
flickerstreak@1
|
2221 if t.passValue then
|
flickerstreak@1
|
2222 t.set(t.passValue, t.r,t.g,t.b,t.a)
|
flickerstreak@1
|
2223 else
|
flickerstreak@1
|
2224 t.set(t.r,t.g,t.b,t.a)
|
flickerstreak@1
|
2225 end
|
flickerstreak@1
|
2226 else
|
flickerstreak@1
|
2227 if type(t.handler[t.get]) ~= "function" then
|
flickerstreak@22
|
2228 AceConsole:error("%s: %s", handler, OPTION_HANDLER_NOT_FOUND:format(tostring(t.get)))
|
flickerstreak@1
|
2229 end
|
flickerstreak@1
|
2230 if t.passValue then
|
flickerstreak@1
|
2231 t.handler[t.set](t.handler, t.passValue, t.r,t.g,t.b,t.a)
|
flickerstreak@1
|
2232 else
|
flickerstreak@1
|
2233 t.handler[t.set](t.handler, t.r,t.g,t.b,t.a)
|
flickerstreak@1
|
2234 end
|
flickerstreak@1
|
2235 end
|
flickerstreak@1
|
2236 else
|
flickerstreak@1
|
2237 if type(t.set) == "function" then
|
flickerstreak@1
|
2238 if t.passValue then
|
flickerstreak@1
|
2239 t.set(t.passValue, t.r,t.g,t.b)
|
flickerstreak@1
|
2240 else
|
flickerstreak@1
|
2241 t.set(t.r,t.g,t.b)
|
flickerstreak@1
|
2242 end
|
flickerstreak@1
|
2243 else
|
flickerstreak@1
|
2244 if type(t.handler[t.set]) ~= "function" then
|
flickerstreak@22
|
2245 AceConsole:error("%s: %s", handler, OPTION_HANDLER_NOT_FOUND:format(tostring(t.set)))
|
flickerstreak@1
|
2246 end
|
flickerstreak@1
|
2247 if t.passValue then
|
flickerstreak@1
|
2248 t.handler[t.set](t.handler, t.passValue, t.r,t.g,t.b)
|
flickerstreak@1
|
2249 else
|
flickerstreak@1
|
2250 t.handler[t.set](t.handler, t.r,t.g,t.b)
|
flickerstreak@1
|
2251 end
|
flickerstreak@1
|
2252 end
|
flickerstreak@1
|
2253 end
|
flickerstreak@1
|
2254 for k,v in pairs(t) do
|
flickerstreak@1
|
2255 t[k] = nil
|
flickerstreak@1
|
2256 end
|
flickerstreak@1
|
2257 ColorPickerFrame.cancelFunc = nil
|
flickerstreak@1
|
2258 ColorPickerFrame.func = nil
|
flickerstreak@1
|
2259 ColorPickerFrame.opacityFunc = nil
|
flickerstreak@1
|
2260 end
|
flickerstreak@1
|
2261 end
|
flickerstreak@22
|
2262
|
flickerstreak@1
|
2263 ColorPickerFrame.cancelFunc = colorCancelFunc
|
flickerstreak@22
|
2264
|
flickerstreak@1
|
2265 ShowUIPanel(ColorPickerFrame)
|
flickerstreak@1
|
2266 end
|
flickerstreak@1
|
2267 return
|
flickerstreak@1
|
2268 elseif kind == "group" then
|
flickerstreak@1
|
2269 if #args == 0 then
|
flickerstreak@22
|
2270 printUsage(self, handler, realOptions, options, path, args, passValue)
|
flickerstreak@1
|
2271 else
|
flickerstreak@1
|
2272 -- invalid argument
|
flickerstreak@22
|
2273 print((options.error or IS_NOT_A_VALID_OPTION_FOR):format(args[1], path), realOptions.cmdName or realOptions.name or self)
|
flickerstreak@1
|
2274 end
|
flickerstreak@1
|
2275 return
|
flickerstreak@1
|
2276 end
|
flickerstreak@1
|
2277 this = _G_this
|
flickerstreak@1
|
2278 if Dewdrop then
|
flickerstreak@22
|
2279 Dewdrop:Refresh()
|
flickerstreak@1
|
2280 end
|
flickerstreak@1
|
2281 end
|
flickerstreak@1
|
2282
|
flickerstreak@1
|
2283 local external
|
flickerstreak@22
|
2284 local tmp
|
flickerstreak@22
|
2285 function AceConsole:RegisterChatCommand(...) -- slashCommands, options, name
|
flickerstreak@22
|
2286 local slashCommands, options, name
|
flickerstreak@22
|
2287 if type((...)) == "string" then
|
flickerstreak@22
|
2288 if not tmp then
|
flickerstreak@22
|
2289 tmp = {}
|
flickerstreak@22
|
2290 else
|
flickerstreak@22
|
2291 for i in ipairs(tmp) do
|
flickerstreak@22
|
2292 tmp[i] = nil
|
flickerstreak@22
|
2293 end
|
flickerstreak@22
|
2294 end
|
flickerstreak@22
|
2295 for i = 1, select('#', ...)+1 do
|
flickerstreak@22
|
2296 local v = select(i, ...)
|
flickerstreak@22
|
2297 if type(v) == "string" then
|
flickerstreak@22
|
2298 tmp[#tmp+1] = v
|
flickerstreak@22
|
2299 else
|
flickerstreak@22
|
2300 slashCommands = tmp
|
flickerstreak@22
|
2301 options = v
|
flickerstreak@22
|
2302 name = select(i+1, ...)
|
flickerstreak@22
|
2303 break
|
flickerstreak@22
|
2304 end
|
flickerstreak@22
|
2305 end
|
flickerstreak@22
|
2306 else
|
flickerstreak@22
|
2307 slashCommands, options, name = ...
|
flickerstreak@22
|
2308 end
|
flickerstreak@1
|
2309 if type(slashCommands) ~= "table" and slashCommands ~= false then
|
flickerstreak@1
|
2310 AceConsole:error("Bad argument #2 to `RegisterChatCommand' (expected table, got %s)", type(slashCommands))
|
flickerstreak@1
|
2311 end
|
flickerstreak@1
|
2312 if not slashCommands and type(name) ~= "string" then
|
flickerstreak@1
|
2313 AceConsole:error("Bad argument #4 to `RegisterChatCommand' (expected string, got %s)", type(name))
|
flickerstreak@1
|
2314 end
|
flickerstreak@1
|
2315 if type(options) ~= "table" and type(options) ~= "function" and options ~= nil then
|
flickerstreak@1
|
2316 AceConsole:error("Bad argument #3 to `RegisterChatCommand' (expected table, function, or nil, got %s)", type(options))
|
flickerstreak@1
|
2317 end
|
flickerstreak@1
|
2318 if name then
|
flickerstreak@1
|
2319 if type(name) ~= "string" then
|
flickerstreak@1
|
2320 AceConsole:error("Bad argument #4 to `RegisterChatCommand' (expected string or nil, got %s)", type(name))
|
flickerstreak@1
|
2321 elseif not name:find("^%w+$") or name:upper() ~= name or name:len() == 0 then
|
flickerstreak@1
|
2322 AceConsole:error("Argument #4 must be an uppercase, letters-only string with at least 1 character")
|
flickerstreak@1
|
2323 end
|
flickerstreak@1
|
2324 end
|
flickerstreak@1
|
2325 if slashCommands then
|
flickerstreak@1
|
2326 if #slashCommands == 0 then
|
flickerstreak@1
|
2327 AceConsole:error("Argument #2 to `RegisterChatCommand' must include at least one string")
|
flickerstreak@1
|
2328 end
|
flickerstreak@22
|
2329
|
flickerstreak@1
|
2330 for k,v in pairs(slashCommands) do
|
flickerstreak@1
|
2331 if type(k) ~= "number" then
|
flickerstreak@1
|
2332 AceConsole:error("All keys in argument #2 to `RegisterChatCommand' must be numbers")
|
flickerstreak@1
|
2333 end
|
flickerstreak@1
|
2334 if type(v) ~= "string" then
|
flickerstreak@1
|
2335 AceConsole:error("All values in argument #2 to `RegisterChatCommand' must be strings")
|
flickerstreak@1
|
2336 elseif not v:find("^/[A-Za-z][A-Za-z0-9_]*$") then
|
flickerstreak@1
|
2337 AceConsole:error("All values in argument #2 to `RegisterChatCommand' must be in the form of \"/word\"")
|
flickerstreak@1
|
2338 end
|
flickerstreak@1
|
2339 end
|
flickerstreak@1
|
2340 end
|
flickerstreak@22
|
2341
|
flickerstreak@1
|
2342 if not options then
|
flickerstreak@1
|
2343 options = {
|
flickerstreak@1
|
2344 type = 'group',
|
flickerstreak@1
|
2345 args = {},
|
flickerstreak@1
|
2346 handler = self
|
flickerstreak@1
|
2347 }
|
flickerstreak@1
|
2348 end
|
flickerstreak@22
|
2349
|
flickerstreak@1
|
2350 if type(options) == "table" then
|
flickerstreak@1
|
2351 local err, position = validateOptions(options)
|
flickerstreak@1
|
2352 if err then
|
flickerstreak@1
|
2353 if position then
|
flickerstreak@1
|
2354 AceConsole:error(position .. ": " .. err)
|
flickerstreak@1
|
2355 else
|
flickerstreak@1
|
2356 AceConsole:error(err)
|
flickerstreak@1
|
2357 end
|
flickerstreak@1
|
2358 end
|
flickerstreak@22
|
2359
|
flickerstreak@1
|
2360 if not options.handler then
|
flickerstreak@1
|
2361 options.handler = self
|
flickerstreak@1
|
2362 end
|
flickerstreak@22
|
2363
|
flickerstreak@1
|
2364 if options.handler == self and options.type:lower() == "group" and self.class then
|
flickerstreak@1
|
2365 AceConsole:InjectAceOptionsTable(self, options)
|
flickerstreak@1
|
2366 end
|
flickerstreak@1
|
2367 end
|
flickerstreak@22
|
2368
|
flickerstreak@1
|
2369 local chat
|
flickerstreak@1
|
2370 if slashCommands then
|
flickerstreak@1
|
2371 chat = slashCommands[1]
|
flickerstreak@1
|
2372 else
|
flickerstreak@1
|
2373 chat = _G["SLASH_"..name..1]
|
flickerstreak@1
|
2374 end
|
flickerstreak@22
|
2375
|
flickerstreak@1
|
2376 local handler
|
flickerstreak@1
|
2377 if type(options) == "function" then
|
flickerstreak@1
|
2378 handler = options
|
flickerstreak@1
|
2379 for k,v in pairs(_G) do
|
flickerstreak@1
|
2380 if handler == v then
|
flickerstreak@1
|
2381 local k = k
|
flickerstreak@1
|
2382 handler = function(msg)
|
flickerstreak@1
|
2383 return _G[k](msg)
|
flickerstreak@1
|
2384 end
|
flickerstreak@1
|
2385 end
|
flickerstreak@1
|
2386 end
|
flickerstreak@1
|
2387 else
|
flickerstreak@1
|
2388 function handler(msg)
|
flickerstreak@1
|
2389 handlerFunc(self, chat, msg, options)
|
flickerstreak@1
|
2390 end
|
flickerstreak@1
|
2391 end
|
flickerstreak@22
|
2392
|
flickerstreak@1
|
2393 if not _G.SlashCmdList then
|
flickerstreak@1
|
2394 _G.SlashCmdList = {}
|
flickerstreak@1
|
2395 end
|
flickerstreak@22
|
2396
|
flickerstreak@22
|
2397 if not name and type(slashCommands) == "table" and type(slashCommands[1]) == "string" then
|
flickerstreak@22
|
2398 name = slashCommands[1]:gsub("%A", ""):upper()
|
flickerstreak@22
|
2399 end
|
flickerstreak@22
|
2400
|
flickerstreak@1
|
2401 if not name then
|
flickerstreak@1
|
2402 local A = ('A'):byte()
|
flickerstreak@1
|
2403 repeat
|
flickerstreak@1
|
2404 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
|
2405 until not _G.SlashCmdList[name]
|
flickerstreak@1
|
2406 end
|
flickerstreak@22
|
2407
|
flickerstreak@1
|
2408 if slashCommands then
|
flickerstreak@1
|
2409 if _G.SlashCmdList[name] then
|
flickerstreak@1
|
2410 local i = 0
|
flickerstreak@1
|
2411 while true do
|
flickerstreak@1
|
2412 i = i + 1
|
flickerstreak@1
|
2413 if _G["SLASH_"..name..i] then
|
flickerstreak@1
|
2414 _G["SLASH_"..name..i] = nil
|
flickerstreak@1
|
2415 else
|
flickerstreak@1
|
2416 break
|
flickerstreak@1
|
2417 end
|
flickerstreak@1
|
2418 end
|
flickerstreak@1
|
2419 end
|
flickerstreak@22
|
2420
|
flickerstreak@1
|
2421 local i = 0
|
flickerstreak@1
|
2422 for _,command in ipairs(slashCommands) do
|
flickerstreak@1
|
2423 i = i + 1
|
flickerstreak@1
|
2424 _G["SLASH_"..name..i] = command
|
flickerstreak@1
|
2425 if command:lower() ~= command then
|
flickerstreak@1
|
2426 i = i + 1
|
flickerstreak@1
|
2427 _G["SLASH_"..name..i] = command:lower()
|
flickerstreak@1
|
2428 end
|
flickerstreak@1
|
2429 end
|
flickerstreak@1
|
2430 end
|
flickerstreak@1
|
2431 _G.SlashCmdList[name] = handler
|
flickerstreak@1
|
2432 if self ~= AceConsole and self.slashCommand == nil then
|
flickerstreak@1
|
2433 self.slashCommand = chat
|
flickerstreak@1
|
2434 end
|
flickerstreak@22
|
2435
|
flickerstreak@1
|
2436 if not AceEvent and AceLibrary:HasInstance("AceEvent-2.0") then
|
flickerstreak@1
|
2437 external(AceConsole, "AceEvent-2.0", AceLibrary("AceEvent-2.0"))
|
flickerstreak@1
|
2438 end
|
flickerstreak@1
|
2439 if AceEvent then
|
flickerstreak@1
|
2440 if not AceConsole.nextAddon then
|
flickerstreak@1
|
2441 AceConsole.nextAddon = {}
|
flickerstreak@1
|
2442 end
|
flickerstreak@1
|
2443 if type(options) == "table" then
|
flickerstreak@1
|
2444 AceConsole.nextAddon[self] = options
|
flickerstreak@1
|
2445 if not self.playerLogin then
|
flickerstreak@1
|
2446 AceConsole:RegisterEvent("PLAYER_LOGIN", "PLAYER_LOGIN", true)
|
flickerstreak@1
|
2447 end
|
flickerstreak@1
|
2448 end
|
flickerstreak@1
|
2449 end
|
flickerstreak@22
|
2450
|
flickerstreak@1
|
2451 AceConsole.registry[name] = options
|
flickerstreak@22
|
2452
|
flickerstreak@22
|
2453 if slashCommands == tmp then
|
flickerstreak@22
|
2454 for i in ipairs(tmp) do
|
flickerstreak@22
|
2455 tmp[i] = nil
|
flickerstreak@22
|
2456 end
|
flickerstreak@22
|
2457 end
|
flickerstreak@1
|
2458 end
|
flickerstreak@1
|
2459
|
flickerstreak@1
|
2460 function AceConsole:InjectAceOptionsTable(handler, options)
|
flickerstreak@1
|
2461 self:argCheck(handler, 2, "table")
|
flickerstreak@1
|
2462 self:argCheck(options, 3, "table")
|
flickerstreak@1
|
2463 if options.type:lower() ~= "group" then
|
flickerstreak@1
|
2464 self:error('Cannot inject into options table argument #3 if its type is not "group"')
|
flickerstreak@1
|
2465 end
|
flickerstreak@1
|
2466 if options.handler ~= nil and options.handler ~= handler then
|
flickerstreak@1
|
2467 self:error("Cannot inject into options table argument #3 if it has a different handler than argument #2")
|
flickerstreak@1
|
2468 end
|
flickerstreak@1
|
2469 options.handler = handler
|
flickerstreak@1
|
2470 local class = handler.class
|
flickerstreak@22
|
2471 if not AceLibrary:HasInstance("AceOO-2.0") or not class then
|
flickerstreak@22
|
2472 if Rock then
|
flickerstreak@22
|
2473 -- possible Rock object
|
flickerstreak@22
|
2474 for mixin in Rock:IterateObjectMixins(handler) do
|
flickerstreak@1
|
2475 if type(mixin.GetAceOptionsDataTable) == "function" then
|
flickerstreak@1
|
2476 local t = mixin:GetAceOptionsDataTable(handler)
|
flickerstreak@1
|
2477 for k,v in pairs(t) do
|
flickerstreak@1
|
2478 if type(options.args) ~= "table" then
|
flickerstreak@1
|
2479 options.args = {}
|
flickerstreak@1
|
2480 end
|
flickerstreak@1
|
2481 if options.args[k] == nil then
|
flickerstreak@1
|
2482 options.args[k] = v
|
flickerstreak@1
|
2483 end
|
flickerstreak@1
|
2484 end
|
flickerstreak@1
|
2485 end
|
flickerstreak@1
|
2486 end
|
flickerstreak@1
|
2487 end
|
flickerstreak@22
|
2488 else
|
flickerstreak@22
|
2489 -- Ace2 object
|
flickerstreak@22
|
2490 while class and class ~= AceLibrary("AceOO-2.0").Class do
|
flickerstreak@22
|
2491 if type(class.GetAceOptionsDataTable) == "function" then
|
flickerstreak@22
|
2492 local t = class:GetAceOptionsDataTable(handler)
|
flickerstreak@22
|
2493 for k,v in pairs(t) do
|
flickerstreak@22
|
2494 if type(options.args) ~= "table" then
|
flickerstreak@22
|
2495 options.args = {}
|
flickerstreak@22
|
2496 end
|
flickerstreak@22
|
2497 if options.args[k] == nil then
|
flickerstreak@22
|
2498 options.args[k] = v
|
flickerstreak@22
|
2499 end
|
flickerstreak@22
|
2500 end
|
flickerstreak@22
|
2501 end
|
flickerstreak@22
|
2502 local mixins = class.mixins
|
flickerstreak@22
|
2503 if mixins then
|
flickerstreak@22
|
2504 for mixin in pairs(mixins) do
|
flickerstreak@22
|
2505 if type(mixin.GetAceOptionsDataTable) == "function" then
|
flickerstreak@22
|
2506 local t = mixin:GetAceOptionsDataTable(handler)
|
flickerstreak@22
|
2507 for k,v in pairs(t) do
|
flickerstreak@22
|
2508 if type(options.args) ~= "table" then
|
flickerstreak@22
|
2509 options.args = {}
|
flickerstreak@22
|
2510 end
|
flickerstreak@22
|
2511 if options.args[k] == nil then
|
flickerstreak@22
|
2512 options.args[k] = v
|
flickerstreak@22
|
2513 end
|
flickerstreak@22
|
2514 end
|
flickerstreak@22
|
2515 end
|
flickerstreak@22
|
2516 end
|
flickerstreak@22
|
2517 end
|
flickerstreak@22
|
2518 class = class.super
|
flickerstreak@22
|
2519 end
|
flickerstreak@1
|
2520 end
|
flickerstreak@22
|
2521
|
flickerstreak@1
|
2522 return options
|
flickerstreak@1
|
2523 end
|
flickerstreak@1
|
2524
|
flickerstreak@1
|
2525 function AceConsole:PLAYER_LOGIN()
|
flickerstreak@1
|
2526 self.playerLogin = true
|
flickerstreak@1
|
2527 for addon, options in pairs(self.nextAddon) do
|
flickerstreak@1
|
2528 local err, position = validateOptionsMethods(addon, options)
|
flickerstreak@1
|
2529 if err then
|
flickerstreak@1
|
2530 if position then
|
flickerstreak@1
|
2531 geterrorhandler()(tostring(addon) .. ": AceConsole: " .. position .. ": " .. err)
|
flickerstreak@1
|
2532 else
|
flickerstreak@1
|
2533 geterrorhandler()(tostring(addon) .. ": AceConsole: " .. err)
|
flickerstreak@1
|
2534 end
|
flickerstreak@1
|
2535 end
|
flickerstreak@1
|
2536 self.nextAddon[addon] = nil
|
flickerstreak@1
|
2537 end
|
flickerstreak@1
|
2538 end
|
flickerstreak@1
|
2539
|
flickerstreak@1
|
2540 function AceConsole:TabCompleteInfo(cmdpath)
|
flickerstreak@1
|
2541 local cmd = cmdpath:match("(/%S+)")
|
flickerstreak@1
|
2542 if not cmd then
|
flickerstreak@1
|
2543 return
|
flickerstreak@1
|
2544 end
|
flickerstreak@1
|
2545 local path = cmdpath:sub(cmd:len() + 2)
|
flickerstreak@1
|
2546 for name in pairs(SlashCmdList) do --global
|
flickerstreak@1
|
2547 if AceConsole.registry[name] then
|
flickerstreak@1
|
2548 local i = 0
|
flickerstreak@1
|
2549 while true do
|
flickerstreak@1
|
2550 i = i + 1
|
flickerstreak@1
|
2551 local scmd = _G["SLASH_"..name..i]
|
flickerstreak@1
|
2552 if not scmd then break end
|
flickerstreak@1
|
2553 if cmd == scmd then
|
flickerstreak@1
|
2554 return name, cmd, path
|
flickerstreak@1
|
2555 end
|
flickerstreak@1
|
2556 end
|
flickerstreak@1
|
2557 end
|
flickerstreak@1
|
2558 end
|
flickerstreak@1
|
2559 end
|
flickerstreak@1
|
2560
|
flickerstreak@1
|
2561 function external(self, major, instance)
|
flickerstreak@1
|
2562 if major == "AceEvent-2.0" then
|
flickerstreak@1
|
2563 if not AceEvent then
|
flickerstreak@1
|
2564 AceEvent = instance
|
flickerstreak@22
|
2565
|
flickerstreak@1
|
2566 AceEvent:embed(self)
|
flickerstreak@1
|
2567 end
|
flickerstreak@1
|
2568 elseif major == "AceTab-2.0" then
|
flickerstreak@1
|
2569 instance:RegisterTabCompletion("AceConsole", "%/.*", function(t, cmdpath, pos)
|
flickerstreak@22
|
2570 local name, cmd, path = self:TabCompleteInfo(cmdpath:sub(1, pos))
|
flickerstreak@1
|
2571
|
flickerstreak@22
|
2572 if not self.registry[name] then
|
flickerstreak@1
|
2573 return false
|
flickerstreak@1
|
2574 else
|
flickerstreak@22
|
2575 local validArgs, _, _, handler = findTableLevel(self, self.registry[name], cmd, path or "")
|
flickerstreak@1
|
2576 if validArgs.args then
|
flickerstreak@22
|
2577 for arg, v in pairs(validArgs.args) do
|
flickerstreak@22
|
2578 local hidden = v.hidden
|
flickerstreak@22
|
2579 local handler = v.handler or handler
|
flickerstreak@22
|
2580 if hidden then
|
flickerstreak@22
|
2581 if type(hidden) == "function" then
|
flickerstreak@22
|
2582 hidden = hidden(v.passValue)
|
flickerstreak@22
|
2583 elseif type(hidden) == "string" then
|
flickerstreak@22
|
2584 local f = hidden
|
flickerstreak@22
|
2585 local neg = f:match("^~(.-)$")
|
flickerstreak@22
|
2586 if neg then
|
flickerstreak@22
|
2587 f = neg
|
flickerstreak@22
|
2588 end
|
flickerstreak@22
|
2589 if type(handler[f]) ~= "function" then
|
flickerstreak@22
|
2590 self:error("%s: %s", handler, OPTION_HANDLER_NOT_FOUND:format(tostring(f)))
|
flickerstreak@22
|
2591 end
|
flickerstreak@22
|
2592 hidden = handler[f](handler, v.passValue)
|
flickerstreak@22
|
2593 if neg then
|
flickerstreak@22
|
2594 hidden = not hidden
|
flickerstreak@22
|
2595 end
|
flickerstreak@22
|
2596 end
|
flickerstreak@22
|
2597 end
|
flickerstreak@22
|
2598 local disabled = hidden or v.disabled
|
flickerstreak@22
|
2599 if disabled then
|
flickerstreak@22
|
2600 if type(disabled) == "function" then
|
flickerstreak@22
|
2601 disabled = disabled(v.passValue)
|
flickerstreak@22
|
2602 elseif type(disabled) == "string" then
|
flickerstreak@22
|
2603 local f = disabled
|
flickerstreak@22
|
2604 local neg = f:match("^~(.-)$")
|
flickerstreak@22
|
2605 if neg then
|
flickerstreak@22
|
2606 f = neg
|
flickerstreak@22
|
2607 end
|
flickerstreak@22
|
2608 if type(handler[f]) ~= "function" then
|
flickerstreak@22
|
2609 self:error("%s: %s", handler, OPTION_HANDLER_NOT_FOUND:format(tostring(f)))
|
flickerstreak@22
|
2610 end
|
flickerstreak@22
|
2611 disabled = handler[f](handler, v.passValue)
|
flickerstreak@22
|
2612 if neg then
|
flickerstreak@22
|
2613 disabled = not disabled
|
flickerstreak@22
|
2614 end
|
flickerstreak@22
|
2615 end
|
flickerstreak@22
|
2616 end
|
flickerstreak@22
|
2617 if not hidden and not disabled and v.type ~= "header" then
|
flickerstreak@22
|
2618 table.insert(t, (tostring(arg):gsub("%s", "-")))
|
flickerstreak@22
|
2619 end
|
flickerstreak@1
|
2620 end
|
flickerstreak@1
|
2621 end
|
flickerstreak@1
|
2622 end
|
flickerstreak@1
|
2623 end, function(u, matches, gcs, cmdpath)
|
flickerstreak@22
|
2624 local name, cmd, path = self:TabCompleteInfo(cmdpath)
|
flickerstreak@22
|
2625 if self.registry[name] then
|
flickerstreak@22
|
2626 local validArgs, path2, argwork, handler = findTableLevel(self, self.registry[name], cmd, path)
|
flickerstreak@22
|
2627 printUsage(self, validArgs.handler or handler, self.registry[name], validArgs, path2, argwork, argwork[#argwork], not gcs or gcs ~= "", gcs)
|
flickerstreak@1
|
2628 end
|
flickerstreak@1
|
2629 end)
|
flickerstreak@1
|
2630 elseif major == "Dewdrop-2.0" then
|
flickerstreak@1
|
2631 Dewdrop = instance
|
flickerstreak@1
|
2632 end
|
flickerstreak@1
|
2633 end
|
flickerstreak@1
|
2634
|
flickerstreak@1
|
2635 local function activate(self, oldLib, oldDeactivate)
|
flickerstreak@1
|
2636 AceConsole = self
|
flickerstreak@22
|
2637
|
flickerstreak@1
|
2638 if oldLib then
|
flickerstreak@1
|
2639 self.registry = oldLib.registry
|
flickerstreak@1
|
2640 self.nextAddon = oldLib.nextAddon
|
flickerstreak@1
|
2641 end
|
flickerstreak@22
|
2642
|
flickerstreak@1
|
2643 if not self.registry then
|
flickerstreak@1
|
2644 self.registry = {}
|
flickerstreak@1
|
2645 else
|
flickerstreak@1
|
2646 for name,options in pairs(self.registry) do
|
flickerstreak@1
|
2647 self:RegisterChatCommand(false, options, name)
|
flickerstreak@1
|
2648 end
|
flickerstreak@1
|
2649 end
|
flickerstreak@22
|
2650
|
flickerstreak@22
|
2651 self:RegisterChatCommand("/reload", "/rl", "/reloadui", ReloadUI, "RELOAD")
|
flickerstreak@22
|
2652 self:RegisterChatCommand("/gm", ToggleHelpFrame, "GM")
|
flickerstreak@22
|
2653 local t = { "/print", "/echo" }
|
flickerstreak@22
|
2654 local _,_,_,enabled,loadable = GetAddOnInfo("DevTools")
|
flickerstreak@22
|
2655 if not enabled and not loadable then
|
flickerstreak@22
|
2656 table.insert(t, "/dump")
|
flickerstreak@22
|
2657 end
|
flickerstreak@22
|
2658 self:RegisterChatCommand(t, function(text)
|
flickerstreak@22
|
2659 text = text:trim():match("^(.-);*$")
|
flickerstreak@22
|
2660 local f, err = loadstring("AceLibrary('AceConsole-2.0'):PrintLiteral(" .. text .. ")")
|
flickerstreak@1
|
2661 if not f then
|
flickerstreak@1
|
2662 self:Print("|cffff0000Error:|r", err)
|
flickerstreak@1
|
2663 else
|
flickerstreak@1
|
2664 f()
|
flickerstreak@1
|
2665 end
|
flickerstreak@1
|
2666 end, "PRINT")
|
flickerstreak@22
|
2667
|
flickerstreak@1
|
2668 self:activate(oldLib, oldDeactivate)
|
flickerstreak@22
|
2669
|
flickerstreak@1
|
2670 if oldDeactivate then
|
flickerstreak@1
|
2671 oldDeactivate(oldLib)
|
flickerstreak@1
|
2672 end
|
flickerstreak@1
|
2673 end
|
flickerstreak@1
|
2674
|
flickerstreak@1
|
2675 AceLibrary:Register(AceConsole, MAJOR_VERSION, MINOR_VERSION, activate, nil, external)
|