comparison DependencyLoader/Addon.lua @ 15:a46bf694050c

cleaned up Tree's methods a bit and improved documentation Addon:Exists will now return false for Blizzard addons (needs to be handled better) Addon.lua will now use the raw hooks from the interface module fixed the inverted returns from IsForceLoadAvailable EnableAddOn and LoadAddOn hooks will now skip the extra processing if the addon does not exist or is a Blizzard addon moved the EnableAddOn queing to the interface
author mckenziemc
date Sat, 11 Dec 2010 01:48:39 -0800
parents b230b94d4487
children f825ccf94a89
comparison
equal deleted inserted replaced
14:78b28ebdc169 15:a46bf694050c
8 -- TODO: test if the API functions are quicker with indexes than names. 8 -- TODO: test if the API functions are quicker with indexes than names.
9 -- TODO: modify the dependency stuff to check the Errata module. 9 -- TODO: modify the dependency stuff to check the Errata module.
10 10
11 local Addon, addon = addonTable:NewClass("Addon") 11 local Addon, addon = addonTable:NewClass("Addon")
12 12
13 Addon.enableAddon = EnableAddOn -- TODO: use raw hook from main module?
14
15 Addon.addons = {} 13 Addon.addons = {}
16 Addon.nameToIndex = {} 14 Addon.nameToIndex = {}
17 15
18 16
19 -- Internal function 17 --- (private) Creates a new Addon object
20 -- Creates a new Addon object
21 -- @param id Name or index of the addon. 18 -- @param id Name or index of the addon.
22 function Addon:New(id) 19 function Addon:New(id)
23 local instance = {} 20 local instance = {}
24 setmetatable(instance, self.instanceMetatable) 21 setmetatable(instance, self.instanceMetatable)
25 22
53 50
54 --- Retrieves an Addon object. 51 --- Retrieves an Addon object.
55 -- @param id Name or index of the addon to retrieve. 52 -- @param id Name or index of the addon to retrieve.
56 -- @return The Addon object, or nil if not found. 53 -- @return The Addon object, or nil if not found.
57 function Addon:Get(id) 54 function Addon:Get(id)
55 assert(id)
56
58 if not self:Exists(id) then 57 if not self:Exists(id) then
59 return nil 58 return nil
60 end 59 end
61 60
62 if type(id) == "number" then 61 if type(id) == "number" then
92 return true 91 return true
93 else 92 else
94 return false 93 return false
95 end 94 end
96 elseif type(addon) == "string" then 95 elseif type(addon) == "string" then
96 if addon:match("Blizzard_") then
97 return false
98 end
99
97 local status = select(6, GetAddOnInfo(addon)) 100 local status = select(6, GetAddOnInfo(addon))
98 101
99 if status == "MISSING" then 102 if status == "MISSING" then
100 return false 103 return false
101 else 104 else
102 return true 105 return true
103 end 106 end
104 else 107 else
105 error() 108 local message = string.format("Unexpected argument type: \"%s\", value: %s", type(addon), addon or "nil")
109 error(message)
106 end 110 end
107 end 111 end
108 112
109 113
110 function addon:GetName() 114 function addon:GetName()
123 127
124 if status == "DISABLED" then 128 if status == "DISABLED" then
125 return false 129 return false
126 else 130 else
127 return true 131 return true
132 end
133 end
134
135
136 function addon:IsLoaded()
137 if IsAddOnLoaded(self.index) then
138 return true
139 else
140 return false
128 end 141 end
129 end 142 end
130 143
131 144
132 --- Checks if the addon is loadable. 145 --- Checks if the addon is loadable.
146 return false 159 return false
147 end 160 end
148 end 161 end
149 162
150 163
164 -- can this addon be force-loaded after the point where the client would enable it?
151 function addon:CanForceLoadAfter() 165 function addon:CanForceLoadAfter()
152 -- TODO: check Errata module 166 -- TODO: check Errata module
153 return false 167 return false
154 end 168 end
155 169
156 170
171 -- can this addon be force-loaded before the point where the client would enable it?
157 function addon:CanForceLoadBefore() 172 function addon:CanForceLoadBefore()
158 -- TODO: check Errata module 173 -- TODO: check Errata module
159 return false -- TODO: check if there's any reason addons can't be forceloaded 174 return false -- TODO: check if there's any reason addons can't be forceloaded
160 end 175 end
161 176
162 177
163 function addon:CanForceLoad() 178 function addon:CanForceLoad()
164 -- FIXME: check if this would've already been loaded 179 -- FIXME: check if this would've already been loaded
165 return self:CanForceLoadAfter() 180 return self:CanForceLoadAfter() or self:CanLoD()
181 -- FIXME: should CanLoD() be in here?
166 end 182 end
167 183
168 184
169 function addon:Enable() 185 function addon:Enable()
170 -- FIXME: delay this till after PLAYER_LOGIN or it'll get force-loaded 186 if IsLoggedIn() then
171 Addon.enableAddon(self.name) 187 addonTable.interface:QueueEnable(self.name)
188 else
189 addonTable.interface:RawEnableAddOn(self.name)
190 end
172 end 191 end
173 192
174 193
175 -- NOTE: only call for LoD, not force-loading 194 -- NOTE: only call for LoD, not force-loading
176 function addon:Load() 195 function addon:Load()
177 assert(self:CanLoD()) 196 assert(self:CanLoD())
178 197
179 EnableAddOn(self.name) 198 addonTable.interface:RawEnableAddOn(self.name)
180 LoadAddOn(self.name) 199 addonTable.interface:RawLoadAddOn(self.name)
181 end 200 end
182 201
183 202
184 function addon:ForceLoad() 203 function addon:ForceLoad()
185 assert(self:CanForceLoad()) 204 assert(self:CanForceLoad())
186 -- TODO: make sure force-loading is available at this time 205 -- TODO: make sure force-loading is available at this time
187 206
188 EnableAddOn(self.name) -- This should cause the game to also load this addon 207 addonTable.interface:RawEnableAddOn(self.name) -- This should cause the game to also load this addon
189 end 208 end
190 209
191 210
192 function addon:GetDependencies() 211 function addon:GetDependencies()
193 -- TODO: consider no-lib embeds as deps? 212 -- TODO: consider no-lib embeds as deps?
206 end 225 end
207 end 226 end
208 227
209 return unpack(embeds) 228 return unpack(embeds)
210 end 229 end
211
212 function addon:IsLoaded()
213 if IsAddOnLoaded(self.index) then
214 return true
215 else
216 return false
217 end
218 end