diff DependencyLoader/DependencyLoader.lua @ 12:b230b94d4487

fixed Addon.lua to use the unhooked EnableAddOn (still needs to be changed to grab from the interface) improved the error message when creating an Addon object on a Blizzard addon (will add direct support later) implemented the hooks on EnableAddOn and LoadAddOn rearranged functions inside Tree.lua, with some edits copied OptDeps from main module to the bootstrap module, to delegate loading to the client when possible
author mckenziemc
date Fri, 10 Dec 2010 00:21:17 -0800
parents e0a4a8b5b389
children 78b28ebdc169
line wrap: on
line diff
--- a/DependencyLoader/DependencyLoader.lua	Sun Dec 05 03:39:26 2010 -0800
+++ b/DependencyLoader/DependencyLoader.lua	Fri Dec 10 00:21:17 2010 -0800
@@ -1,6 +1,7 @@
 --	DependencyLoader
 --	
 
+
 local addonName, addonTable = ...
 
 
@@ -10,11 +11,11 @@
 addonTable.interface = DependencyLoader
 
 
-local libPrint = LibStub("LibPrint-1.0")
+local LibPrint = LibStub("LibPrint-1.0")
 local LibScriptLink = LibStub("LibScriptLink-1.0")
 
-DependencyLoader.printStream = libPrint:NewStream("DependencyLoader", "DpLdr", print)
-DependencyLoader.debugStream = libPrint:NewStream("DependencyLoader", "DpLdr", "mcm")
+DependencyLoader.printStream = LibPrint:NewStream("DependencyLoader", "DpLdr", print)
+DependencyLoader.debugStream = LibPrint:NewStream("DependencyLoader", "DpLdr", "mcm")
 
 
 function DependencyLoader:Print(...)
@@ -34,11 +35,12 @@
 
 
 function DependencyLoader:OnEnable()
+	self:RawHook("LoadAddOn", true)
+	self:RawHook("EnableAddOn", true)
+	
+	self:PrepareAllAddons()
+	
 	self:Print("Enabled", addonName)
-	
-	self:Hook("EnableAddOn", true)
-	
-	self:FixCurrentAddons()
 end
 
 
@@ -66,7 +68,7 @@
 
 --	Enables any dependencies needed by the addons 
 --	that have already been enabled
-function DependencyLoader:FixCurrentAddons()
+function DependencyLoader:PrepareAllAddons()
 	local requestReload = false
 	
 	for i=1, GetNumAddOns() do
@@ -74,26 +76,105 @@
 		
 		--	TODO: what if an addon was loaded but its deps were then disabled?
 		if addon:IsEnabled() and not addon:IsLoaded() then
-			local tree = addonTable.classes.Tree:Get(addon)
-			
-			if self:CanForceLoad() and tree:CanForceLoad() then
-				tree:ForceLoad()
-			elseif tree:CanLoD() then
-				tree:PrepareForLoD()
-			elseif tree:CanLoad() then
-				tree:PrepareForReload()
-				requestReload = true
-			end
+			self:EnableAddOn(addon:GetName())
 		end
 	end
 	
+	--[[
 	if requestReload then
 		local message = LibScriptLink:NewLink(ReloadUI) .. " to reload your UI."
 		self:Print(message)
 	end
+	]]
 end
 
 
 function DependencyLoader:EnableAddOn(...)
-	print("DependencyLoader:EnableAddOn", ...)
+	local id = ...
+	local addon = addonTable.classes.Addon:Get(id)
+	local tree = addonTable.classes.Tree:Get(addon)
+	
+	local requestReload = false
+	
+	if self:CanForceLoad() then
+		--	NOTE: if we can force-load, then will enabling LoD addons cause them to load too?
+		--	A: no, they will still wait for LoadAddOn
+		
+		--	Can the addon be loaded on demand if force-loading is 
+		--	allowed for its dependencies
+		--	if so, enable all deps and force-load if nec.
+		--		deps will get enabled if all parents are lod, force-loaded
+		--		if any parent can't be loaded on demand
+		--	else
+		--	if the addon is not loadable on demand but the tree can be
+		--	force-loaded, then force-load it all
+		--		deps will all get loaded since req. for root to load
+		--	else
+		--	if it can be loaded with a reloadui then prepare after login
+		--	else
+		--	it can't be loaded, maybe tell the user
+		
+		if tree:CanLoDWithForce() then
+			tree:PrepareForLoD()
+		elseif tree:CanForceLoad() then
+			tree:ForceLoad()
+		elseif tree:CanLoad() then
+			tree:PrepareForReload()
+			requestReload = true
+		else
+			--	TODO: tell user
+		end
+	else
+		--	if it can be loaded on demand (deps are loaded or LoD) then
+		--	prepare it (enable all deps)
+		--	else
+		--	if it can be loaded (and isn't already) then
+		--		if force loading is available, we have to wait, then enable everything
+		--		else
+		--		prepare for reload (TODO: move this check and similar to PLAYER_LOGOUT)
+		--	else
+		--	can't be loaded, maybe tell the user
+		
+		if tree:CanLoD() then
+			tree:PrepareForReload()
+			--	don't actually intend to reload, just enable everything
+		elseif tree:CanLoad() then
+			tree:PrepareForReload()
+			requestReload = true
+		else
+			--	TODO: tell user
+		end
+	end
+	
+	--	TODO: requestReload
+	
+	return self.hooks.EnableAddOn(...)
 end
+
+
+
+---	Prepares the addon tree rooted at the specified addon
+function DependencyLoader:LoadAddOn(...)
+	local id = ...
+	
+	local isBlizzardAddon = false
+	
+	if type(id) == "string" and string.match(id, "Blizzard_") then
+		self:Debug("Asked to load Blizzard addon", id, ", skipping")
+		isBlizzardAddon = true
+	end
+	
+	if not isBlizzardAddon then
+		local addon = addonTable.classes.Addon:Get(id)
+		local tree = addonTable.classes.Tree:Get(addon)
+		
+		if tree:CanLoD() then
+			tree:PrepareForLoD()
+		elseif tree:CanLoad() then
+			tree:PrepareForReload()
+		end
+	end
+		
+	--	call even if it can't be loaded so regular returns appear
+	return self.hooks.LoadAddOn(...)
+end