comparison DependencyLoader/Tree.lua @ 18:e7995d599184 tip

updated pkgmeta fix the inversion in addon:Enable added support for late-loading
author mckenziemc
date Tue, 21 Dec 2010 00:23:57 -0800
parents a46bf694050c
children
comparison
equal deleted inserted replaced
17:f825ccf94a89 18:e7995d599184
10 10
11 11
12 local Tree, tree = addonTable:NewClass("Tree") 12 local Tree, tree = addonTable:NewClass("Tree")
13 13
14 14
15 local debug = addonTable.debug
15 local classes = addonTable.classes 16 local classes = addonTable.classes
16 17
17 18
18 Tree.trees = {} 19 Tree.trees = {}
19 20
66 -- and the UI is reloaded. 67 -- and the UI is reloaded.
67 -- Basically makes sure all dependencies are installed. 68 -- Basically makes sure all dependencies are installed.
68 function tree:CanLoad() 69 function tree:CanLoad()
69 local root = self.root 70 local root = self.root
70 71
72 --debug("Checking if the tree rooted at", root:GetName(), "can be loaded.")
73
71 if root:IsLoaded() then 74 if root:IsLoaded() then
72 return true 75 return true
73 end 76 end
74 77
75 if not root:CanLoad() then 78 if not root:CanLoad() then
90 if not depTree:CanLoad() then 93 if not depTree:CanLoad() then
91 return false 94 return false
92 end 95 end
93 end 96 end
94 97
98 --debug("The tree rooted at", root:GetName(), "can be loaded")
95 return true 99 return true
96 end 100 end
97 101
98 102
99 --- Checks if the tree can be loaded on demand. 103 --- Checks if the tree can be loaded on demand.
128 132
129 return true 133 return true
130 end 134 end
131 135
132 136
137 -- Checks if this tree can load late (LoadAddOn with non-LoD)
138 function tree:CanLoadLate()
139 local root = self.root
140
141 if not root:CanLoadLate() then
142 return false
143 end
144
145 local dependencies = {root:GetDependencies()}
146
147 for i, depName in pairs(dependencies) do
148 if not classes.Addon:Exists(depName) then
149 return false
150 end
151
152 local dep = classes.Addon:Get(depName)
153 local depTree = Tree:Get(dep)
154
155 if not depTree:CanLoadLate() then
156 return false
157 end
158 end
159
160 return true
161 end
162
163
133 --- Checks if this tree can be force-loaded. 164 --- Checks if this tree can be force-loaded.
134 -- Does not check user settings nor if force-loading is actually available. 165 -- Does not check user settings nor if force-loading is actually available.
135 -- @return canForceLoad True if this tree can be force loaded, false otherwise 166 -- @return canForceLoad True if this tree can be force loaded, false otherwise
136 function tree:CanForceLoad() 167 function tree:CanForceLoad()
137 local root = self.root 168 local root = self.root
169 --- Prepares this tree to be loaded, whether through 200 --- Prepares this tree to be loaded, whether through
170 -- a ui reload or by loading on demand. 201 -- a ui reload or by loading on demand.
171 -- Assumptions: CanLoad is true for this tree 202 -- Assumptions: CanLoad is true for this tree
172 function tree:PrepareForLoad() 203 function tree:PrepareForLoad()
173 local root = self.root 204 local root = self.root
205
206 --debug("Preparing the tree rooted at", root:GetName(), "for loading")
174 207
175 -- The Addon class will take care of delaying enables 208 -- The Addon class will take care of delaying enables
176 -- till after PLAYER_LOGIN if necessary. 209 -- till after PLAYER_LOGIN if necessary.
177 210
178 root:Enable() 211 root:Enable()
247 280
248 root:Enable() 281 root:Enable()
249 end 282 end
250 283
251 284
285 function tree:LoadLate()
286 local root = self.root
287
288 -- load dependencies
289 local dependencies = {root:GetDependencies()}
290
291 for i, depName in pairs(dependencies) do
292 Tree:Get(depName):LoadLate()
293 end
294
295 -- load embeds, if they are available separately
296 local embeds = {root:GetEmbeds()}
297
298 for i, embedName in pairs(embeds) do
299 if classes.Addon:Exists(embedName) then
300 Tree:Get(embedName):LoadLate()
301 end
302 end
303
304 root:LoadLate()
305 end
306
307
308
252 --- Force-loads this tree. 309 --- Force-loads this tree.
253 -- This will also load any LoD addons in the tree 310 -- This will also load any LoD addons in the tree
254 function tree:ForceLoad() 311 function tree:ForceLoad()
255 local root = self.root 312 local root = self.root
256 313
270 if classes.Addon:Exists(embedName) then 327 if classes.Addon:Exists(embedName) then
271 Tree:Get(embedName):ForceLoad() 328 Tree:Get(embedName):ForceLoad()
272 end 329 end
273 end 330 end
274 331
275 root:ForceLoad() 332 if root:CanLoD() then
276 end 333 root:Load()
334 else
335 root:ForceLoad()
336 end
337 end