comparison libs/AceAddon-2.0/AceAddon-2.0.lua @ 1:c11ca1d8ed91

Version 0.1
author Flick <flickerstreak@gmail.com>
date Tue, 20 Mar 2007 21:03:57 +0000
parents
children
comparison
equal deleted inserted replaced
0:4e2ce2894c21 1:c11ca1d8ed91
1 --[[
2 Name: AceAddon-2.0
3 Revision: $Rev: 19844 $
4 Developed by: The Ace Development Team (http://www.wowace.com/index.php/The_Ace_Development_Team)
5 Inspired By: Ace 1.x by Turan (turan@gryphon.com)
6 Website: http://www.wowace.com/
7 Documentation: http://www.wowace.com/index.php/AceAddon-2.0
8 SVN: http://svn.wowace.com/root/trunk/Ace2/AceAddon-2.0
9 Description: Base for all Ace addons to inherit from.
10 Dependencies: AceLibrary, AceOO-2.0, AceEvent-2.0, (optional) AceConsole-2.0
11 ]]
12
13 local MAJOR_VERSION = "AceAddon-2.0"
14 local MINOR_VERSION = "$Revision: 19844 $"
15
16 -- This ensures the code is only executed if the libary doesn't already exist, or is a newer version
17 if not AceLibrary then error(MAJOR_VERSION .. " requires AceLibrary.") end
18 if not AceLibrary:IsNewVersion(MAJOR_VERSION, MINOR_VERSION) then return end
19
20 if not AceLibrary:HasInstance("AceOO-2.0") then error(MAJOR_VERSION .. " requires AceOO-2.0.") end
21
22 local function safecall(func,...)
23 local success, err = pcall(func,...)
24 if not success then geterrorhandler()(err) end
25 end
26 -- Localization
27 local STANDBY, TITLE, NOTES, VERSION, AUTHOR, DATE, CATEGORY, EMAIL, CREDITS, WEBSITE, CATEGORIES, ABOUT, PRINT_ADDON_INFO
28 if GetLocale() == "deDE" then
29 STANDBY = "|cffff5050(Standby)|r" -- capitalized
30
31 TITLE = "Titel"
32 NOTES = "Anmerkung"
33 VERSION = "Version"
34 AUTHOR = "Autor"
35 DATE = "Datum"
36 CATEGORY = "Kategorie"
37 EMAIL = "E-mail"
38 WEBSITE = "Webseite"
39 CREDITS = "Credits" -- fix
40
41 ABOUT = "\195\188ber"
42 PRINT_ADDON_INFO = "Gibt Addondaten aus"
43
44 CATEGORIES = {
45 ["Action Bars"] = "Aktionsleisten",
46 ["Auction"] = "Auktion",
47 ["Audio"] = "Audio",
48 ["Battlegrounds/PvP"] = "Schlachtfeld/PvP",
49 ["Buffs"] = "Buffs",
50 ["Chat/Communication"] = "Chat/Kommunikation",
51 ["Druid"] = "Druide",
52 ["Hunter"] = "J?r",
53 ["Mage"] = "Magier",
54 ["Paladin"] = "Paladin",
55 ["Priest"] = "Priester",
56 ["Rogue"] = "Schurke",
57 ["Shaman"] = "Schamane",
58 ["Warlock"] = "Hexenmeister",
59 ["Warrior"] = "Krieger",
60 ["Healer"] = "Heiler",
61 ["Tank"] = "Tank", -- noone use "Brecher"...
62 ["Caster"] = "Caster",
63 ["Combat"] = "Kampf",
64 ["Compilations"] = "Compilations", -- whats that o_O
65 ["Data Export"] = "Datenexport",
66 ["Development Tools"] = "Entwicklungs Tools",
67 ["Guild"] = "Gilde",
68 ["Frame Modification"] = "Frame Modifikation",
69 ["Interface Enhancements"] = "Interface Verbesserungen",
70 ["Inventory"] = "Inventar",
71 ["Library"] = "Library",
72 ["Map"] = "Map",
73 ["Mail"] = "Mail",
74 ["Miscellaneous"] = "Diverses",
75 ["Quest"] = "Quest",
76 ["Raid"] = "Schlachtzug",
77 ["Tradeskill"] = "Handelsf\195\164higkeit",
78 ["UnitFrame"] = "UnitFrame",
79 }
80 elseif GetLocale() == "frFR" then
81 STANDBY = "|cffff5050(attente)|r"
82
83 TITLE = "Titre"
84 NOTES = "Notes"
85 VERSION = "Version"
86 AUTHOR = "Auteur"
87 DATE = "Date"
88 CATEGORY = "Cat\195\169gorie"
89 EMAIL = "E-mail"
90 WEBSITE = "Site web"
91 CREDITS = "Credits" -- fix
92
93 ABOUT = "A propos"
94 PRINT_ADDON_INFO = "Afficher les informations sur l'addon"
95
96 CATEGORIES = {
97 ["Action Bars"] = "Barres d'action",
98 ["Auction"] = "H\195\180tel des ventes",
99 ["Audio"] = "Audio",
100 ["Battlegrounds/PvP"] = "Champs de bataille/JcJ",
101 ["Buffs"] = "Buffs",
102 ["Chat/Communication"] = "Chat/Communication",
103 ["Druid"] = "Druide",
104 ["Hunter"] = "Chasseur",
105 ["Mage"] = "Mage",
106 ["Paladin"] = "Paladin",
107 ["Priest"] = "Pr\195\170tre",
108 ["Rogue"] = "Voleur",
109 ["Shaman"] = "Chaman",
110 ["Warlock"] = "D\195\169moniste",
111 ["Warrior"] = "Guerrier",
112 ["Healer"] = "Soigneur",
113 ["Tank"] = "Tank",
114 ["Caster"] = "Casteur",
115 ["Combat"] = "Combat",
116 ["Compilations"] = "Compilations",
117 ["Data Export"] = "Exportation de donn\195\169es",
118 ["Development Tools"] = "Outils de d\195\169veloppement",
119 ["Guild"] = "Guilde",
120 ["Frame Modification"] = "Modification des fen\195\170tres",
121 ["Interface Enhancements"] = "Am\195\169liorations de l'interface",
122 ["Inventory"] = "Inventaire",
123 ["Library"] = "Biblioth\195\168ques",
124 ["Map"] = "Carte",
125 ["Mail"] = "Courrier",
126 ["Miscellaneous"] = "Divers",
127 ["Quest"] = "Qu\195\170tes",
128 ["Raid"] = "Raid",
129 ["Tradeskill"] = "M\195\169tiers",
130 ["UnitFrame"] = "Fen\195\170tres d'unit\195\169",
131 }
132 elseif GetLocale() == "koKR" then
133 STANDBY = "|cffff5050(????)|r"
134
135 TITLE = "??"
136 NOTES = "??"
137 VERSION = "??"
138 AUTHOR = "???"
139 DATE = "??"
140 CATEGORY = "??"
141 EMAIL = "E-mail"
142 WEBSITE = "????"
143 CREDITS = "Credits" -- fix
144
145 ABOUT = "??"
146 PRINT_ADDON_INFO = "??? ?? ??"
147
148 CATEGORIES = {
149 ["Action Bars"] = "???",
150 ["Auction"] = "??",
151 ["Audio"] = "??",
152 ["Battlegrounds/PvP"] = "??/PvP",
153 ["Buffs"] = "??",
154 ["Chat/Communication"] = "??/????",
155 ["Druid"] = "????",
156 ["Hunter"] = "???",
157 ["Mage"] = "???",
158 ["Paladin"] = "???",
159 ["Priest"] = "??",
160 ["Rogue"] = "??",
161 ["Shaman"] = "???",
162 ["Warlock"] = "????",
163 ["Warrior"] = "??",
164 ["Healer"] = "??",
165 ["Tank"] = "??",
166 ["Caster"] = "???",
167 ["Combat"] = "??",
168 ["Compilations"] = "??",
169 ["Data Export"] = "?? ??",
170 ["Development Tools"] = "?? ??",
171 ["Guild"] = "??",
172 ["Frame Modification"] = "?? ??",
173 ["Interface Enhancements"] = "????? ??",
174 ["Inventory"] = "????",
175 ["Library"] = "?????",
176 ["Map"] = "??",
177 ["Mail"] = "??",
178 ["Miscellaneous"] = "??",
179 ["Quest"] = "???",
180 ["Raid"] = "???",
181 ["Tradeskill"] = "????",
182 ["UnitFrame"] = "?? ???",
183 }
184 elseif GetLocale() == "zhTW" then
185 STANDBY = "|cffff5050(??)|r"
186
187 TITLE = "??"
188 NOTES = "??"
189 VERSION = "??"
190 AUTHOR = "??"
191 DATE = "??"
192 CATEGORY = "??"
193 EMAIL = "E-mail"
194 WEBSITE = "??"
195 CREDITS = "Credits" -- fix
196
197 ABOUT = "??"
198 PRINT_ADDON_INFO = "??????"
199
200 CATEGORIES = {
201 ["Action Bars"] = "???",
202 ["Auction"] = "??",
203 ["Audio"] = "??",
204 ["Battlegrounds/PvP"] = "??/PvP",
205 ["Buffs"] = "??",
206 ["Chat/Communication"] = "??/??",
207 ["Druid"] = "???",
208 ["Hunter"] = "??",
209 ["Mage"] = "??",
210 ["Paladin"] = "???",
211 ["Priest"] = "??",
212 ["Rogue"] = "??",
213 ["Shaman"] = "??",
214 ["Warlock"] = "??",
215 ["Warrior"] = "??",
216 ["Healer"] = "???",
217 ["Tank"] = "??",
218 ["Caster"] = "???",
219 ["Combat"] = "??",
220 ["Compilations"] = "??",
221 ["Data Export"] = "????",
222 ["Development Tools"] = "????",
223 ["Guild"] = "??",
224 ["Frame Modification"] = "????",
225 ["Interface Enhancements"] = "????",
226 ["Inventory"] = "??",
227 ["Library"] = "???",
228 ["Map"] = "??",
229 ["Mail"] = "??",
230 ["Miscellaneous"] = "??",
231 ["Quest"] = "??",
232 ["Raid"] = "??",
233 ["Tradeskill"] = "????",
234 ["UnitFrame"] = "????",
235 }
236 elseif GetLocale() == "zhCN" then
237 STANDBY = "|cffff5050(\230\154\130\230\140\130)|r"
238
239 TITLE = "\230\160\135\233\162\152"
240 NOTES = "\233\153\132\230\179\168"
241 VERSION = "\231\137\136\230\156\172"
242 AUTHOR = "\228\189\156\232\128\133"
243 DATE = "\230\151\165\230\156\159"
244 CATEGORY = "\229\136\134\231\177\187"
245 EMAIL = "\231\148\181\229\173\144\233\130\174\228\187\182"
246 WEBSITE = "\231\189\145\231\171\153"
247 CREDITS = "Credits" -- fix
248
249 ABOUT = "\229\133\179\228\186\142"
250 PRINT_ADDON_INFO = "\229\141\176\229\136\151\229\135\186\230\143\146\228\187\182\228\191\161\230\129\175"
251
252 CATEGORIES = {
253 ["Action Bars"] = "\229\138\168\228\189\156\230\157\161",
254 ["Auction"] = "\230\139\141\229\141\150",
255 ["Audio"] = "\233\159\179\233\162\145",
256 ["Battlegrounds/PvP"] = "\230\136\152\229\156\186/PvP",
257 ["Buffs"] = "\229\162\158\231\155\138\233\173\148\230\179\149",
258 ["Chat/Communication"] = "\232\129\138\229\164\169/\228\186\164\230\181\129",
259 ["Druid"] = "\229\190\183\233\178\129\228\188\138",
260 ["Hunter"] = "\231\140\142\228\186\186",
261 ["Mage"] = "\230\179\149\229\184\136",
262 ["Paladin"] = "\229\156\163\233\170\145\229\163\171",
263 ["Priest"] = "\231\137\167\229\184\136",
264 ["Rogue"] = "\231\155\151\232\180\188",
265 ["Shaman"] = "\232\144\168\230\187\161\231\165\173\229\143\184",
266 ["Warlock"] = "\230\156\175\229\163\171",
267 ["Warrior"] = "\230\136\152\229\163\171",
268 -- ["Healer"] = "\230\178\187\231\150\151\228\191\157\233\154\156",
269 -- ["Tank"] = "\232\191\145\230\136\152\230\142\167\229\136\182",
270 -- ["Caster"] = "\232\191\156\231\168\139\232\190\147\229\135\186",
271 ["Combat"] = "\230\136\152\230\150\151",
272 ["Compilations"] = "\231\188\150\232\175\145",
273 ["Data Export"] = "\230\149\176\230\141\174\229\175\188\229\135\186",
274 ["Development Tools"] = "\229\188\128\229\143\145\229\183\165\229\133\183",
275 ["Guild"] = "\229\133\172\228\188\154",
276 ["Frame Modification"] = "\230\161\134\230\158\182\228\191\174\230\148\185",
277 ["Interface Enhancements"] = "\231\149\140\233\157\162\229\162\158\229\188\186",
278 ["Inventory"] = "\232\131\140\229\140\133",
279 ["Library"] = "\229\186\147",
280 ["Map"] = "\229\156\176\229\155\190",
281 ["Mail"] = "\233\130\174\228\187\182",
282 ["Miscellaneous"] = "\230\157\130\233\161\185",
283 ["Quest"] = "\228\187\187\229\138\161",
284 ["Raid"] = "\229\155\162\233\152\159",
285 ["Tradeskill"] = "\229\149\134\228\184\154\230\138\128\232\131\189",
286 ["UnitFrame"] = "\229\164\180\229\131\143\230\161\134\230\158\182",
287 }
288 else -- enUS
289 STANDBY = "|cffff5050(standby)|r"
290
291 TITLE = "Title"
292 NOTES = "Notes"
293 VERSION = "Version"
294 AUTHOR = "Author"
295 DATE = "Date"
296 CATEGORY = "Category"
297 EMAIL = "E-mail"
298 WEBSITE = "Website"
299 CREDITS = "Credits"
300
301 ABOUT = "About"
302 PRINT_ADDON_INFO = "Show information about the addon."
303
304 CATEGORIES = {
305 ["Action Bars"] = "Action Bars",
306 ["Auction"] = "Auction",
307 ["Audio"] = "Audio",
308 ["Battlegrounds/PvP"] = "Battlegrounds/PvP",
309 ["Buffs"] = "Buffs",
310 ["Chat/Communication"] = "Chat/Communication",
311 ["Druid"] = "Druid",
312 ["Hunter"] = "Hunter",
313 ["Mage"] = "Mage",
314 ["Paladin"] = "Paladin",
315 ["Priest"] = "Priest",
316 ["Rogue"] = "Rogue",
317 ["Shaman"] = "Shaman",
318 ["Warlock"] = "Warlock",
319 ["Warrior"] = "Warrior",
320 ["Healer"] = "Healer",
321 ["Tank"] = "Tank",
322 ["Caster"] = "Caster",
323 ["Combat"] = "Combat",
324 ["Compilations"] = "Compilations",
325 ["Data Export"] = "Data Export",
326 ["Development Tools"] = "Development Tools",
327 ["Guild"] = "Guild",
328 ["Frame Modification"] = "Frame Modification",
329 ["Interface Enhancements"] = "Interface Enhancements",
330 ["Inventory"] = "Inventory",
331 ["Library"] = "Library",
332 ["Map"] = "Map",
333 ["Mail"] = "Mail",
334 ["Miscellaneous"] = "Miscellaneous",
335 ["Quest"] = "Quest",
336 ["Raid"] = "Raid",
337 ["Tradeskill"] = "Tradeskill",
338 ["UnitFrame"] = "UnitFrame",
339 }
340 end
341
342 setmetatable(CATEGORIES, { __index = function(self, key) -- case-insensitive
343 local lowerKey = key:lower()
344 for k,v in pairs(CATEGORIES) do
345 if k:lower() == lowerKey then
346 return v
347 end
348 end
349 end })
350
351 -- Create the library object
352
353 local AceOO = AceLibrary("AceOO-2.0")
354 local AceAddon = AceOO.Class()
355 local AceEvent
356 local AceConsole
357 local AceModuleCore
358
359 function AceAddon:GetLocalizedCategory(name)
360 self:argCheck(name, 2, "string")
361 return CATEGORIES[name] or UNKNOWN
362 end
363
364 function AceAddon:ToString()
365 return "AceAddon"
366 end
367
368 local function print(text)
369 DEFAULT_CHAT_FRAME:AddMessage(text)
370 end
371
372 function AceAddon:ADDON_LOADED(name)
373 while table.getn(self.nextAddon) > 0 do
374 local addon = table.remove(self.nextAddon, 1)
375 table.insert(self.addons, addon)
376 if not self.addons[name] then
377 self.addons[name] = addon
378 end
379 self:InitializeAddon(addon, name)
380 end
381 end
382
383 local function RegisterOnEnable(self)
384 if DEFAULT_CHAT_FRAME and DEFAULT_CHAT_FRAME.defaultLanguage then -- HACK
385 AceAddon.playerLoginFired = true
386 end
387 if AceAddon.playerLoginFired then
388 AceAddon.addonsStarted[self] = true
389 if (type(self.IsActive) ~= "function" or self:IsActive()) and (not AceModuleCore or not AceModuleCore:IsModule(self) or AceModuleCore:IsModuleActive(self)) then
390 local current = self.class
391 while true do
392 if current == AceOO.Class then
393 break
394 end
395 if current.mixins then
396 for mixin in pairs(current.mixins) do
397 if type(mixin.OnEmbedEnable) == "function" then
398 safecall(mixin.OnEmbedEnable,mixin,self)
399 end
400 end
401 end
402 current = current.super
403 end
404 if type(self.OnEnable) == "function" then
405 safecall(self.OnEnable,self)
406 end
407 if AceEvent then
408 AceEvent:TriggerEvent("Ace2_AddonEnabled", self)
409 end
410 end
411 else
412 if not AceAddon.addonsToOnEnable then
413 AceAddon.addonsToOnEnable = {}
414 end
415 table.insert(AceAddon.addonsToOnEnable, self)
416 end
417 end
418
419 local function stripSpaces(text)
420 if type(text) == "string" then
421 return strtrim(text)
422 end
423 return text
424 end
425
426 function AceAddon:InitializeAddon(addon, name)
427 if addon.name == nil then
428 addon.name = name
429 end
430 if GetAddOnMetadata then
431 -- TOC checks
432 if addon.title == nil then
433 addon.title = GetAddOnMetadata(name, "Title")
434 end
435 if type(addon.title) == "string" then
436 local num = addon.title:find(" |cff7fff7f %-Ace2%-|r$")
437 if num then
438 addon.title = addon.title:sub(1, num - 1)
439 end
440 addon.title = addon.title:trim()
441 end
442 if addon.notes == nil then
443 addon.notes = GetAddOnMetadata(name, "Notes")
444 end
445 if type(addon.notes) == "string" then
446 addon.notes = addon.notes:trim()
447 end
448 if addon.version == nil then
449 addon.version = GetAddOnMetadata(name, "Version")
450 end
451 if type(addon.version) == "string" then
452 if addon.version:find("%$Revision: (%d+) %$") then
453 addon.version = addon.version:gsub("%$Revision: (%d+) %$", "%1")
454 elseif addon.version:find("%$Rev: (%d+) %$") then
455 addon.version = addon.version:gsub("%$Rev: (%d+) %$", "%1")
456 elseif addon.version:find("%$LastChangedRevision: (%d+) %$") then
457 addon.version = addon.version:gsub("%$LastChangedRevision: (%d+) %$", "%1")
458 end
459 addon.version = addon.version:trim()
460 end
461 if addon.author == nil then
462 addon.author = GetAddOnMetadata(name, "Author")
463 end
464 if type(addon.author) == "string" then
465 addon.author = addon.author:trim()
466 end
467 if addon.credits == nil then
468 addon.credits = GetAddOnMetadata(name, "X-Credits")
469 end
470 if type(addon.credits) == "string" then
471 addon.credits = addon.credits:trim()
472 end
473 if addon.date == nil then
474 addon.date = GetAddOnMetadata(name, "X-Date") or GetAddOnMetadata(name, "X-ReleaseDate")
475 end
476 if type(addon.date) == "string" then
477 if addon.date:find("%$Date: (.-) %$") then
478 addon.date = addon.date:gsub("%$Date: (.-) %$", "%1")
479 elseif addon.date:find("%$LastChangedDate: (.-) %$") then
480 addon.date = addon.date:gsub("%$LastChangedDate: (.-) %$", "%1")
481 end
482 addon.date = addon.date:trim()
483 end
484
485 if addon.category == nil then
486 addon.category = GetAddOnMetadata(name, "X-Category")
487 end
488 if type(addon.category) == "string" then
489 addon.category = addon.category:trim()
490 end
491 if addon.email == nil then
492 addon.email = GetAddOnMetadata(name, "X-eMail") or GetAddOnMetadata(name, "X-Email")
493 end
494 if type(addon.email) == "string" then
495 addon.email = addon.email:trim()
496 end
497 if addon.website == nil then
498 addon.website = GetAddOnMetadata(name, "X-Website")
499 end
500 if type(addon.website) == "string" then
501 addon.website = addon.website:trim()
502 end
503 end
504 local current = addon.class
505 while true do
506 if current == AceOO.Class then
507 break
508 end
509 if current.mixins then
510 for mixin in pairs(current.mixins) do
511 if type(mixin.OnEmbedInitialize) == "function" then
512 mixin:OnEmbedInitialize(addon, name)
513 end
514 end
515 end
516 current = current.super
517 end
518 if type(addon.OnInitialize) == "function" then
519 safecall(addon.OnInitialize, addon, name)
520 end
521 if AceEvent then
522 AceEvent:TriggerEvent("Ace2_AddonInitialized", addon)
523 end
524 RegisterOnEnable(addon)
525 end
526
527 function AceAddon.prototype:PrintAddonInfo()
528 local x
529 if self.title then
530 x = "|cffffff7f" .. tostring(self.title) .. "|r"
531 elseif self.name then
532 x = "|cffffff7f" .. tostring(self.name) .. "|r"
533 else
534 x = "|cffffff7f<" .. tostring(self.class) .. " instance>|r"
535 end
536 if type(self.IsActive) == "function" then
537 if not self:IsActive() then
538 x = x .. " " .. STANDBY
539 end
540 end
541 if self.version then
542 x = x .. " - |cffffff7f" .. tostring(self.version) .. "|r"
543 end
544 if self.notes then
545 x = x .. " - " .. tostring(self.notes)
546 end
547 print(x)
548 if self.author then
549 print(" - |cffffff7f" .. AUTHOR .. ":|r " .. tostring(self.author))
550 end
551 if self.credits then
552 print(" - |cffffff7f" .. CREDITS .. ":|r " .. tostring(self.credits))
553 end
554 if self.date then
555 print(" - |cffffff7f" .. DATE .. ":|r " .. tostring(self.date))
556 end
557 if self.category then
558 local category = CATEGORIES[self.category]
559 if category then
560 print(" - |cffffff7f" .. CATEGORY .. ":|r " .. category)
561 end
562 end
563 if self.email then
564 print(" - |cffffff7f" .. EMAIL .. ":|r " .. tostring(self.email))
565 end
566 if self.website then
567 print(" - |cffffff7f" .. WEBSITE .. ":|r " .. tostring(self.website))
568 end
569 end
570
571 local options
572 function AceAddon:GetAceOptionsDataTable(target)
573 if not options then
574 options = {
575 about = {
576 name = ABOUT,
577 desc = PRINT_ADDON_INFO,
578 type = "execute",
579 func = "PrintAddonInfo",
580 order = -1,
581 }
582 }
583 end
584 return options
585 end
586
587 function AceAddon:PLAYER_LOGIN()
588 self.playerLoginFired = true
589 if self.addonsToOnEnable then
590 while table.getn(self.addonsToOnEnable) > 0 do
591 local addon = table.remove(self.addonsToOnEnable, 1)
592 self.addonsStarted[addon] = true
593 if (type(addon.IsActive) ~= "function" or addon:IsActive()) and (not AceModuleCore or not AceModuleCore:IsModule(addon) or AceModuleCore:IsModuleActive(addon)) then
594 local current = addon.class
595 while true do
596 if current == AceOO.Class then
597 break
598 end
599 if current.mixins then
600 for mixin in pairs(current.mixins) do
601 if type(mixin.OnEmbedEnable) == "function" then
602 safecall(mixin.OnEmbedEnable,mixin,addon)
603 end
604 end
605 end
606 current = current.super
607 end
608 if type(addon.OnEnable) == "function" then
609 safecall(addon.OnEnable,addon)
610 end
611 if AceEvent then
612 AceEvent:TriggerEvent("Ace2_AddonEnabled", addon)
613 end
614 end
615 end
616 self.addonsToOnEnable = nil
617 end
618 end
619
620 function AceAddon.prototype:Inject(t)
621 AceAddon:argCheck(t, 2, "table")
622 for k,v in pairs(t) do
623 self[k] = v
624 end
625 end
626
627 function AceAddon.prototype:init()
628 if not AceEvent then
629 error(MAJOR_VERSION .. " requires AceEvent-2.0", 4)
630 end
631 AceAddon.super.prototype.init(self)
632
633 self.super = self.class.prototype
634
635 AceAddon:RegisterEvent("ADDON_LOADED", "ADDON_LOADED", true)
636 table.insert(AceAddon.nextAddon, self)
637 end
638
639 function AceAddon.prototype:ToString()
640 local x
641 if type(self.title) == "string" then
642 x = self.title
643 elseif type(self.name) == "string" then
644 x = self.name
645 else
646 x = "<" .. tostring(self.class) .. " instance>"
647 end
648 if (type(self.IsActive) == "function" and not self:IsActive()) or (AceModuleCore and AceModuleCore:IsModule(addon) and AceModuleCore:IsModuleActive(addon)) then
649 x = x .. " " .. STANDBY
650 end
651 return x
652 end
653
654 AceAddon.new = function(self, ...)
655 local class = AceAddon:pcall(AceOO.Classpool, self, ...)
656 return class:new()
657 end
658
659 local function external(self, major, instance)
660 if major == "AceEvent-2.0" then
661 AceEvent = instance
662
663 AceEvent:embed(self)
664
665 self:RegisterEvent("PLAYER_LOGIN", "PLAYER_LOGIN", true)
666 elseif major == "AceConsole-2.0" then
667 AceConsole = instance
668
669 local slashCommands = { "/ace2" }
670 local _,_,_,enabled,loadable = GetAddOnInfo("Ace")
671 if not enabled or not loadable then
672 table.insert(slashCommands, "/ace")
673 end
674 local function listAddon(addon, depth)
675 if not depth then
676 depth = 0
677 end
678
679 local s = (" "):rep(depth) .. " - " .. tostring(addon)
680 if rawget(addon, 'version') then
681 s = s .. " - |cffffff7f" .. tostring(addon.version) .. "|r"
682 end
683 if rawget(addon, 'slashCommand') then
684 s = s .. " |cffffff7f(" .. tostring(addon.slashCommand) .. ")|r"
685 end
686 print(s)
687 if type(rawget(addon, 'modules')) == "table" then
688 local i = 0
689 for k,v in pairs(addon.modules) do
690 i = i + 1
691 if i == 6 then
692 print((" "):rep(depth + 1) .. " - more...")
693 break
694 else
695 listAddon(v, depth + 1)
696 end
697 end
698 end
699 end
700 local function listNormalAddon(i)
701 local name,_,_,enabled,loadable = GetAddOnInfo(i)
702 if not loadable then
703 enabled = false
704 end
705 if self.addons[name] then
706 local addon = self.addons[name]
707 if not AceCoreAddon or not AceCoreAddon:IsModule(addon) then
708 listAddon(addon)
709 end
710 else
711 local s = " - " .. tostring(GetAddOnMetadata(i, "Title") or name)
712 local version = GetAddOnMetadata(i, "Version")
713 if version then
714 if version:find("%$Revision: (%d+) %$") then
715 version = version:gsub("%$Revision: (%d+) %$", "%1")
716 elseif version:find("%$Rev: (%d+) %$") then
717 version = version:gsub("%$Rev: (%d+) %$", "%1")
718 elseif version:find("%$LastChangedRevision: (%d+) %$") then
719 version = version:gsub("%$LastChangedRevision: (%d+) %$", "%1")
720 end
721 s = s .. " - |cffffff7f" .. version .. "|r"
722 end
723 if not enabled then
724 s = s .. " |cffff0000(disabled)|r"
725 end
726 if IsAddOnLoadOnDemand(i) then
727 s = s .. " |cff00ff00[LoD]|r"
728 end
729 print(s)
730 end
731 end
732 local function mySort(alpha, bravo)
733 return tostring(alpha) < tostring(bravo)
734 end
735 AceConsole.RegisterChatCommand(self, slashCommands, {
736 desc = "AddOn development framework",
737 name = "Ace2",
738 type = "group",
739 args = {
740 about = {
741 desc = "Get information about Ace2",
742 name = "About",
743 type = "execute",
744 func = function()
745 print("|cffffff7fAce2|r - |cffffff7f2.0." .. MINOR_VERSION:gsub("%$Revision: (%d+) %$", "%1") .. "|r - AddOn development framework")
746 print(" - |cffffff7f" .. AUTHOR .. ":|r Ace Development Team")
747 print(" - |cffffff7f" .. WEBSITE .. ":|r http://www.wowace.com/")
748 end
749 },
750 list = {
751 desc = "List addons",
752 name = "List",
753 type = "group",
754 args = {
755 ace2 = {
756 desc = "List addons using Ace2",
757 name = "Ace2",
758 type = "execute",
759 func = function()
760 print("|cffffff7fAddon list:|r")
761 local AceCoreAddon = AceLibrary:HasInstance("AceCoreAddon-2.0") and AceLibrary("AceCoreAddon-2.0")
762 table.sort(self.addons, mySort)
763 for _,v in ipairs(self.addons) do
764 if not AceCoreAddon or not AceCoreAddon:IsModule(v) then
765 listAddon(v)
766 end
767 end
768 end
769 },
770 all = {
771 desc = "List all addons",
772 name = "All",
773 type = "execute",
774 func = function()
775 print("|cffffff7fAddon list:|r")
776 local AceCoreAddon = AceLibrary:HasInstance("AceCoreAddon-2.0") and AceLibrary("AceCoreAddon-2.0")
777 local count = GetNumAddOns()
778 for i = 1, count do
779 listNormalAddon(i)
780 end
781 end
782 },
783 enabled = {
784 desc = "List all enabled addons",
785 name = "Enabled",
786 type = "execute",
787 func = function()
788 print("|cffffff7fAddon list:|r")
789 local AceCoreAddon = AceLibrary:HasInstance("AceCoreAddon-2.0") and AceLibrary("AceCoreAddon-2.0")
790 local count = GetNumAddOns()
791 for i = 1, count do
792 local _,_,_,enabled,loadable = GetAddOnInfo(i)
793 if enabled and loadable then
794 listNormalAddon(i)
795 end
796 end
797 end
798 },
799 disabled = {
800 desc = "List all disabled addons",
801 name = "Disabled",
802 type = "execute",
803 func = function()
804 print("|cffffff7fAddon list:|r")
805 local AceCoreAddon = AceLibrary:HasInstance("AceCoreAddon-2.0") and AceLibrary("AceCoreAddon-2.0")
806 local count = GetNumAddOns()
807 for i = 1, count do
808 local _,_,_,enabled,loadable = GetAddOnInfo(i)
809 if not enabled or not loadable then
810 listNormalAddon(i)
811 end
812 end
813 end
814 },
815 lod = {
816 desc = "List all LoadOnDemand addons",
817 name = "LoadOnDemand",
818 type = "execute",
819 func = function()
820 print("|cffffff7fAddon list:|r")
821 local AceCoreAddon = AceLibrary:HasInstance("AceCoreAddon-2.0") and AceLibrary("AceCoreAddon-2.0")
822 local count = GetNumAddOns()
823 for i = 1, count do
824 if IsAddOnLoadOnDemand(i) then
825 listNormalAddon(i)
826 end
827 end
828 end
829 },
830 ace1 = {
831 desc = "List all addons using Ace1",
832 name = "Ace 1.x",
833 type = "execute",
834 func = function()
835 print("|cffffff7fAddon list:|r")
836 local count = GetNumAddOns()
837 for i = 1, count do
838 local dep1, dep2, dep3, dep4 = GetAddOnDependencies(i)
839 if dep1 == "Ace" or dep2 == "Ace" or dep3 == "Ace" or dep4 == "Ace" then
840 listNormalAddon(i)
841 end
842 end
843 end
844 },
845 libs = {
846 desc = "List all libraries using AceLibrary",
847 name = "Libraries",
848 type = "execute",
849 func = function()
850 if type(AceLibrary) == "table" and type(AceLibrary.libs) == "table" then
851 print("|cffffff7fLibrary list:|r")
852 for name, data in pairs(AceLibrary.libs) do
853 local s
854 if data.minor then
855 s = " - " .. tostring(name) .. "." .. tostring(data.minor)
856 else
857 s = " - " .. tostring(name)
858 end
859 if rawget(AceLibrary(name), 'slashCommand') then
860 s = s .. " |cffffff7f(" .. tostring(AceLibrary(name).slashCommand) .. "|cffffff7f)"
861 end
862 print(s)
863 end
864 end
865 end
866 },
867 search = {
868 desc = "Search by name",
869 name = "Search",
870 type = "text",
871 usage = "<keyword>",
872 input = true,
873 get = false,
874 set = function(...)
875 local arg = { ... }
876 for i,v in ipairs(arg) do
877 arg[i] = v:gsub('%*', '.*'):gsub('%%', '%%%%'):lower()
878 end
879 local count = GetNumAddOns()
880 for i = 1, count do
881 local name = GetAddOnInfo(i)
882 local good = true
883 for _,v in ipairs(arg) do
884 if not name:lower():find(v) then
885 good = false
886 break
887 end
888 end
889 if good then
890 listNormalAddon(i)
891 end
892 end
893 end
894 }
895 },
896 },
897 enable = {
898 desc = "Enable addon",
899 name = "Enable",
900 type = "text",
901 usage = "<addon>",
902 get = false,
903 set = function(text)
904 local name,title,_,enabled,_,reason = GetAddOnInfo(text)
905 if reason == "MISSING" then
906 print(string.format("|cffffff7fAce2:|r AddOn %q does not exist", text))
907 elseif not enabled then
908 EnableAddOn(text)
909 print(string.format("|cffffff7fAce2:|r %s is now enabled", title or name))
910 else
911 print(string.format("|cffffff7fAce2:|r %s is already enabled", title or name))
912 end
913 end,
914 },
915 disable = {
916 desc = "Disable addon",
917 name = "Disable",
918 type = "text",
919 usage = "<addon>",
920 get = false,
921 set = function(text)
922 local name,title,_,enabled,_,reason = GetAddOnInfo(text)
923 if reason == "MISSING" then
924 print(string.format("|cffffff7fAce2:|r AddOn %q does not exist", text))
925 elseif enabled then
926 DisableAddOn(text)
927 print(string.format("|cffffff7fAce2:|r %s is now disabled", title or name))
928 else
929 print(string.format("|cffffff7fAce2:|r %s is already disabled", title or name))
930 end
931 end,
932 },
933 load = {
934 desc = "Load addon",
935 name = "Load",
936 type = "text",
937 usage = "<addon>",
938 get = false,
939 set = function(text)
940 local name,title,_,_,loadable,reason = GetAddOnInfo(text)
941 if reason == "MISSING" then
942 print(string.format("|cffffff7fAce2:|r AddOn %q does not exist.", text))
943 elseif not loadable then
944 print(string.format("|cffffff7fAce2:|r AddOn %q is not loadable. Reason: %s", text, reason))
945 else
946 LoadAddOn(text)
947 print(string.format("|cffffff7fAce2:|r %s is now loaded", title or name))
948 end
949 end
950 },
951 info = {
952 desc = "Display information",
953 name = "Information",
954 type = "execute",
955 func = function()
956 local mem, threshold = gcinfo()
957 print(string.format(" - |cffffff7fMemory usage [|r%.3f MiB|cffffff7f]|r", mem / 1024))
958 if threshold then
959 print(string.format(" - |cffffff7fThreshold [|r%.3f MiB|cffffff7f]|r", threshold / 1024))
960 end
961 print(string.format(" - |cffffff7fFramerate [|r%.0f fps|cffffff7f]|r", GetFramerate()))
962 local bandwidthIn, bandwidthOut, latency = GetNetStats()
963 bandwidthIn, bandwidthOut = floor(bandwidthIn * 1024), floor(bandwidthOut * 1024)
964 print(string.format(" - |cffffff7fLatency [|r%.0f ms|cffffff7f]|r", latency))
965 print(string.format(" - |cffffff7fBandwidth in [|r%.0f B/s|cffffff7f]|r", bandwidthIn))
966 print(string.format(" - |cffffff7fBandwidth out [|r%.0f B/s|cffffff7f]|r", bandwidthOut))
967 print(string.format(" - |cffffff7fTotal addons [|r%d|cffffff7f]|r", GetNumAddOns()))
968 print(string.format(" - |cffffff7fAce2 addons [|r%d|cffffff7f]|r", table.getn(self.addons)))
969 local ace = 0
970 local enabled = 0
971 local disabled = 0
972 local lod = 0
973 for i = 1, GetNumAddOns() do
974 local dep1, dep2, dep3, dep4 = GetAddOnDependencies(i)
975 if dep1 == "Ace" or dep2 == "Ace" or dep3 == "Ace" or dep4 == "Ace" then
976 ace = ace + 1
977 end
978 if IsAddOnLoadOnDemand(i) then
979 lod = lod + 1
980 end
981 local _,_,_,IsActive,loadable = GetAddOnInfo(i)
982 if not IsActive or not loadable then
983 disabled = disabled + 1
984 else
985 enabled = enabled + 1
986 end
987 end
988 print(string.format(" - |cffffff7fAce 1.x addons [|r%d|cffffff7f]|r", ace))
989 print(string.format(" - |cffffff7fLoadOnDemand addons [|r%d|cffffff7f]|r", lod))
990 print(string.format(" - |cffffff7fenabled addons [|r%d|cffffff7f]|r", enabled))
991 print(string.format(" - |cffffff7fdisabled addons [|r%d|cffffff7f]|r", disabled))
992 local libs = 0
993 if type(AceLibrary) == "table" and type(AceLibrary.libs) == "table" then
994 for _ in pairs(AceLibrary.libs) do
995 libs = libs + 1
996 end
997 end
998 print(string.format(" - |cffffff7fAceLibrary instances [|r%d|cffffff7f]|r", libs))
999 end
1000 }
1001 }
1002 })
1003 elseif major == "AceModuleCore-2.0" then
1004 AceModuleCore = instance
1005 end
1006 end
1007
1008 local function activate(self, oldLib, oldDeactivate)
1009 AceAddon = self
1010
1011 if oldLib then
1012 self.playerLoginFired = oldLib.playerLoginFired or DEFAULT_CHAT_FRAME and DEFAULT_CHAT_FRAME.defaultLanguage
1013 self.addonsToOnEnable = oldLib.addonsToOnEnable
1014 self.addons = oldLib.addons
1015 self.nextAddon = oldLib.nextAddon
1016 self.addonsStarted = oldLib.addonsStarted
1017 end
1018 if not self.addons then
1019 self.addons = {}
1020 end
1021 if not self.nextAddon then
1022 self.nextAddon = {}
1023 end
1024 if not self.addonsStarted then
1025 self.addonsStarted = {}
1026 end
1027 if oldDeactivate then
1028 oldDeactivate(oldLib)
1029 end
1030 end
1031
1032 AceLibrary:Register(AceAddon, MAJOR_VERSION, MINOR_VERSION, activate, nil, external)