vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1  
2 ------------------------------
3 -- Are you local? --
4 ------------------------------
5  
6 local LC = AceLibrary("AceLocale-2.2"):new("BigWigs")
7 local BZ = AceLibrary("Babble-Zone-2.2")
8  
9 local withcore = {}
10 local inzone = {}
11 local zonelist = {}
12  
13 local function Split(str, sep)
14 local x, y = string.find(str, sep) or 0, string.len(sep) or 1
15 return tonumber(string.sub(str, 1, x - 1)) or string.sub(str, 1, x - 1), tonumber(string.sub(str, x + y)) or string.sub(str, x + y)
16 end
17  
18 local function Trim(str)
19 str = string.gsub(str, "^%s*", "")
20 str = string.gsub(str, "%s*$", "")
21 return str
22 end
23  
24 local function Explode(str, sep)
25 local a, b = Split(str, sep)
26 if not b or b == "" then return Trim(a) end
27 if not string.find(b, sep) then return Trim(a), Trim(b) end
28 return Trim(a), Explode(b, sep)
29 end
30  
31 ------------------------------
32 -- Addon Declaration --
33 ------------------------------
34  
35 BigWigsLoD = AceLibrary("AceAddon-2.0"):new("AceEvent-2.0")
36  
37 ------------------------------
38 -- Initialization --
39 ------------------------------
40  
41 function BigWigsLoD:OnInitialize()
42 self:InitializeLoD()
43 end
44  
45 function BigWigsLoD:OnEnable()
46  
47 self:RegisterEvent("BigWigs_CoreEnabled")
48  
49 self:RegisterEvent("ZONE_CHANGED_NEW_AREA")
50 self:RegisterEvent("CHAT_MSG_SYSTEM")
51 self:RegisterEvent("BigWigs_JoinedGroup")
52 self:RegisterEvent("BigWigs_LeftGroup")
53  
54 if AceLibrary("AceEvent-2.0"):IsFullyInitialized() then
55 self:ZONE_CHANGED_NEW_AREA()
56 else
57 self:RegisterEvent("AceEvent_FullyInitialized", "ZONE_CHANGED_NEW_AREA")
58 end
59 end
60  
61 ------------------------------
62 -- Event Handlers --
63 ------------------------------
64  
65 function BigWigsLoD:BigWigs_CoreEnabled()
66  
67 local loaded = false
68 for k,v in pairs( withcore ) do
69 if not IsAddOnLoaded( v ) then
70 loaded = true
71 LoadAddOn( v )
72 end
73 end
74  
75 withcore = {}
76  
77 -- Fire an event to have the target monitor check it's stuff
78 if loaded then
79 self:TriggerEvent("BigWigs_ModulePackLoaded")
80 end
81 end
82  
83 function BigWigsLoD:ZONE_CHANGED_NEW_AREA()
84 self:LoadZone( GetRealZoneText() )
85 end
86  
87 function BigWigsLoD:CHAT_MSG_SYSTEM( msg )
88 if string.find(msg, "^"..ERR_RAID_YOU_LEFT) then
89 self:TriggerEvent("BigWigs_LeftGroup")
90 elseif string.find(msg, ERR_RAID_YOU_JOINED) then
91 self:TriggerEvent("BigWigs_JoinedGroup")
92 end
93 end
94  
95 function BigWigsLoD:BigWigs_JoinedGroup()
96 BigWigs:ToggleActive(true)
97 end
98  
99 function BigWigsLoD:BigWigs_LeftGroup()
100 BigWigs:ToggleActive(false)
101 end
102  
103 ------------------------------
104 -- Utility Functions --
105 ------------------------------
106  
107 function BigWigsLoD:InitializeLoD()
108 local numAddons = GetNumAddOns()
109 for i = 1, numAddons do
110 if not IsAddOnLoaded(i) and IsAddOnLoadOnDemand(i) then
111 local meta = GetAddOnMetadata(i, "X-BigWigs-LoadInZone")
112 if meta then
113 local ignorezone = string.find( meta, LC["Outdoor Raid Bosses Zone"] )
114 for k, v in pairs({Explode(meta, ",")}) do
115 local zone
116 if BZ:HasTranslation(v) then zone = BZ[v] end
117 -- elseif LC:HasTranslation(v) then zone = LC[v] end
118 if zone then
119 if not inzone[zone] then inzone[zone] = {} end
120 table.insert( inzone[zone], i)
121 if not ignorezone then
122 zonelist[zone] = true
123 else
124 if not zonelist[LC["Other"]] then zonelist[LC["Other"]] = {} end
125 zonelist[LC["Other"]][zone] = true
126 end
127 end
128 end
129 end
130 meta = GetAddOnMetadata(i, "X-BigWigs-LoadWithCore")
131 if meta then
132 -- register this addon for loading with core
133 table.insert( withcore, i )
134 end
135 end
136 end
137 end
138  
139 function BigWigsLoD:LoadZone( zone )
140 if inzone[zone] then
141 local loaded = false
142 for k,v in pairs( inzone[zone] ) do
143 if not IsAddOnLoaded( v ) then
144 loaded = true
145 LoadAddOn( v )
146 end
147 end
148 inzone[zone] = nil
149 zonelist[zone] = nil
150 if loaded then
151 self:TriggerEvent("BigWigs_ModulePackLoaded", zone)
152 end
153 end
154 end
155  
156 function BigWigsLoD:GetZones()
157 return zonelist
158 end
159