Mercurial > wow > dependencyloader
changeset 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 | f825ccf94a89 |
children | |
files | .pkgmeta DependencyLoader/Addon.lua DependencyLoader/Core.lua DependencyLoader/DependencyLoader.toc DependencyLoader/Tree.lua DependencyLoader/class.lua DependencyLoader_Bootstrap/bootstrap.lua DependencyLoader_Errata/main.lua |
diffstat | 8 files changed, 127 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/.pkgmeta Sat Dec 11 03:32:04 2010 -0800 +++ b/.pkgmeta Tue Dec 21 00:23:57 2010 -0800 @@ -1,16 +1,21 @@ package-as: DependencyLoader externals: - DependencyLoader/libs/LibStub: + libs/LibStub: url: svn://svn.wowace.com/wow/libstub/mainline/trunk - DependencyLoader/libs/Ace3: + tag: latest + libs/Ace3: url: svn://svn.wowace.com/wow/ace3/mainline/trunk - DependencyLoader/libs/LibBuilder-1.0: - url: http://hg.wowace.com/wow/libbuilder/mainline - DependencyLoader/libs/LibPrint-1.0: - url: http://hg.wowace.com/wow/libprint/mainline/LibPrint - DependencyLoader/libs/LibScriptLink-1.0: - url: http://hg.wowace.com/wow/libscriptlink/mainline + tag: latest + libs/LibBuilder-1.0: + url: http://hg.curseforge.net/wow/libbuilder-1-0/mainline/main + tag: latest + libs/LibPrint-1.0: + url: http://hg.curseforge.net/wow/libprint-1-0/mainline/main + tag: latest + libs/LibScriptLink-1.0: + url: http://hg.curseforge.net/wow/libscriptlink-1-0/mainline/main + tag: latest move-folders: DependencyLoader/DependencyLoader: DependencyLoader
--- a/DependencyLoader/Addon.lua Sat Dec 11 03:32:04 2010 -0800 +++ b/DependencyLoader/Addon.lua Tue Dec 21 00:23:57 2010 -0800 @@ -5,6 +5,8 @@ local addonName, addonTable = ... +local debug = addonTable.debug + -- TODO: test if the API functions are quicker with indexes than names. -- TODO: modify the dependency stuff to check the Errata module. @@ -161,6 +163,12 @@ end +function addon:CanLoadLate() + -- TODO: check Errata module + return false +end + + -- can this addon be force-loaded after the point where the client would enable it? function addon:CanForceLoadAfter() -- TODO: check Errata module @@ -184,9 +192,9 @@ function addon:Enable() if IsLoggedIn() then + addonTable.classes.Core:RawEnableAddOn(self.name) + else addonTable.classes.Core:QueueEnable(self.name) - else - addonTable.classes.Core:RawEnableAddOn(self.name) end end @@ -200,7 +208,15 @@ end +function addon:LoadLate() + classes.Core:RawEnableAddOn(self.name) + classes.Core:RawLoadAddOn(self.name) +end + + function addon:ForceLoad() + debug("addon:ForceLoad called on", self.name) + assert(self:CanForceLoad()) -- TODO: make sure force-loading is available at this time
--- a/DependencyLoader/Core.lua Sat Dec 11 03:32:04 2010 -0800 +++ b/DependencyLoader/Core.lua Tue Dec 21 00:23:57 2010 -0800 @@ -48,6 +48,13 @@ end +function Core:CanLoadLate() + -- assume we've already logged in + return true + -- TODO: check user settings +end + + -- Enables any dependencies needed by the addons -- that have already been enabled function Core:PrepareAllAddons() @@ -104,6 +111,8 @@ -- else -- it can't be loaded, maybe tell the user + debug("EnableAddOn hook, checking", addon:GetName()) + if tree:CanForceLoad() then if addon:CanLoD() then tree:PrepareForLoD() @@ -144,6 +153,8 @@ if tree:CanLoD() then tree:PrepareForLoad() -- don't actually intend to reload, just enable everything + elseif self:CanLoadLate() and tree:CanLoadLate() then + tree:LoadLate() elseif tree:CanLoad() then tree:PrepareForLoad() requestReload = true @@ -201,6 +212,7 @@ function Core:RawEnableAddOn(...) + debug("RawEnableAddOn: enabling", ...) return self.hooks.EnableAddOn(...) end
--- a/DependencyLoader/DependencyLoader.toc Sat Dec 11 03:32:04 2010 -0800 +++ b/DependencyLoader/DependencyLoader.toc Tue Dec 21 00:23:57 2010 -0800 @@ -10,4 +10,8 @@ ## LoadOnDemand: 1 +#@no-lib-strip@ +embeds.xml +#@end-no-lib-strip@ + load.xml
--- 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
--- a/DependencyLoader/class.lua Sat Dec 11 03:32:04 2010 -0800 +++ b/DependencyLoader/class.lua Tue Dec 21 00:23:57 2010 -0800 @@ -6,8 +6,6 @@ -- FIXME: prevent duplicate class definitions -print( string.format([[running %s\class.lua]], addonName) ) - addonTable.classes = {} function addonTable:NewClass(name)
--- a/DependencyLoader_Bootstrap/bootstrap.lua Sat Dec 11 03:32:04 2010 -0800 +++ b/DependencyLoader_Bootstrap/bootstrap.lua Tue Dec 21 00:23:57 2010 -0800 @@ -9,9 +9,6 @@ -- FIXME: don't force-load if we're already logged in - -print("loading DependencyLoader_Bootstrap") - -- TODO: move and use dependency parsing function here? local dependencies = {"LibStub", "Ace3", "LibBuilder-1.0", "LibPrint-1.0", "LibScriptLink-1.0"} @@ -32,13 +29,14 @@ end -print("bootstrap: Loading DependencyLoader") +--print("bootstrap: Loading DependencyLoader") for _, addon in pairs(dependencies) do EnableAddOn(addon) LoadAddOn(addon) end + EnableAddOn("DependencyLoader") LoadAddOn("DependencyLoader")
--- a/DependencyLoader_Errata/main.lua Sat Dec 11 03:32:04 2010 -0800 +++ b/DependencyLoader_Errata/main.lua Tue Dec 21 00:23:57 2010 -0800 @@ -1,1 +1,16 @@ -print("running DependencyLoader_Errata\main.lua") + + +local addonName, addonTable = ... + + + + + +-- data needed +-- addon name +-- TOC suggestion: some way to differentiate the main addon from "fake" versions, +-- eg. real fubar vs fubar stub for Fubar2Broker +-- TOC suggestion: way to determine if an addon is full or no-lib +-- external libraries used +-- optional deps +