Mercurial > wow > dependencyloader
diff 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 |
line wrap: on
line diff
--- a/DependencyLoader/Tree.lua Sat Dec 11 03:32:04 2010 -0800 +++ b/DependencyLoader/Tree.lua Tue Dec 21 00:23:57 2010 -0800 @@ -12,6 +12,7 @@ local Tree, tree = addonTable:NewClass("Tree") +local debug = addonTable.debug local classes = addonTable.classes @@ -68,6 +69,8 @@ function tree:CanLoad() local root = self.root + --debug("Checking if the tree rooted at", root:GetName(), "can be loaded.") + if root:IsLoaded() then return true end @@ -92,6 +95,7 @@ end end + --debug("The tree rooted at", root:GetName(), "can be loaded") return true end @@ -130,6 +134,33 @@ end +-- Checks if this tree can load late (LoadAddOn with non-LoD) +function tree:CanLoadLate() + local root = self.root + + if not root:CanLoadLate() then + return false + end + + local dependencies = {root:GetDependencies()} + + for i, depName in pairs(dependencies) do + if not classes.Addon:Exists(depName) then + return false + end + + local dep = classes.Addon:Get(depName) + local depTree = Tree:Get(dep) + + if not depTree:CanLoadLate() then + return false + end + end + + return true +end + + --- Checks if this tree can be force-loaded. -- Does not check user settings nor if force-loading is actually available. -- @return canForceLoad True if this tree can be force loaded, false otherwise @@ -172,6 +203,8 @@ function tree:PrepareForLoad() local root = self.root + --debug("Preparing the tree rooted at", root:GetName(), "for loading") + -- The Addon class will take care of delaying enables -- till after PLAYER_LOGIN if necessary. @@ -249,6 +282,30 @@ end +function tree:LoadLate() + local root = self.root + + -- load dependencies + local dependencies = {root:GetDependencies()} + + for i, depName in pairs(dependencies) do + Tree:Get(depName):LoadLate() + end + + -- load embeds, if they are available separately + local embeds = {root:GetEmbeds()} + + for i, embedName in pairs(embeds) do + if classes.Addon:Exists(embedName) then + Tree:Get(embedName):LoadLate() + end + end + + root:LoadLate() +end + + + --- Force-loads this tree. -- This will also load any LoD addons in the tree function tree:ForceLoad() @@ -272,5 +329,9 @@ end end - root:ForceLoad() + if root:CanLoD() then + root:Load() + else + root:ForceLoad() + end end