comparison 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
comparison
equal deleted inserted replaced
11:47d15fc9208e 12:b230b94d4487
1 -- DependencyLoader 1 -- DependencyLoader
2 -- 2 --
3
3 4
4 local addonName, addonTable = ... 5 local addonName, addonTable = ...
5 6
6 7
7 local DependencyLoader = LibStub("AceAddon-3.0"):NewAddon(addonName, "AceHook-3.0") 8 local DependencyLoader = LibStub("AceAddon-3.0"):NewAddon(addonName, "AceHook-3.0")
8 _G[addonName] = DependencyLoader 9 _G[addonName] = DependencyLoader
9 10
10 addonTable.interface = DependencyLoader 11 addonTable.interface = DependencyLoader
11 12
12 13
13 local libPrint = LibStub("LibPrint-1.0") 14 local LibPrint = LibStub("LibPrint-1.0")
14 local LibScriptLink = LibStub("LibScriptLink-1.0") 15 local LibScriptLink = LibStub("LibScriptLink-1.0")
15 16
16 DependencyLoader.printStream = libPrint:NewStream("DependencyLoader", "DpLdr", print) 17 DependencyLoader.printStream = LibPrint:NewStream("DependencyLoader", "DpLdr", print)
17 DependencyLoader.debugStream = libPrint:NewStream("DependencyLoader", "DpLdr", "mcm") 18 DependencyLoader.debugStream = LibPrint:NewStream("DependencyLoader", "DpLdr", "mcm")
18 19
19 20
20 function DependencyLoader:Print(...) 21 function DependencyLoader:Print(...)
21 self.printStream:Print(...) 22 self.printStream:Print(...)
22 end 23 end
32 self:Enable() 33 self:Enable()
33 end 34 end
34 35
35 36
36 function DependencyLoader:OnEnable() 37 function DependencyLoader:OnEnable()
38 self:RawHook("LoadAddOn", true)
39 self:RawHook("EnableAddOn", true)
40
41 self:PrepareAllAddons()
42
37 self:Print("Enabled", addonName) 43 self:Print("Enabled", addonName)
38
39 self:Hook("EnableAddOn", true)
40
41 self:FixCurrentAddons()
42 end 44 end
43 45
44 46
45 function DependencyLoader:OnDisable() 47 function DependencyLoader:OnDisable()
46 self:Print("Disabled", addonName) 48 self:Print("Disabled", addonName)
64 end 66 end
65 67
66 68
67 -- Enables any dependencies needed by the addons 69 -- Enables any dependencies needed by the addons
68 -- that have already been enabled 70 -- that have already been enabled
69 function DependencyLoader:FixCurrentAddons() 71 function DependencyLoader:PrepareAllAddons()
70 local requestReload = false 72 local requestReload = false
71 73
72 for i=1, GetNumAddOns() do 74 for i=1, GetNumAddOns() do
73 local addon = addonTable.classes.Addon:Get(i) 75 local addon = addonTable.classes.Addon:Get(i)
74 76
75 -- TODO: what if an addon was loaded but its deps were then disabled? 77 -- TODO: what if an addon was loaded but its deps were then disabled?
76 if addon:IsEnabled() and not addon:IsLoaded() then 78 if addon:IsEnabled() and not addon:IsLoaded() then
77 local tree = addonTable.classes.Tree:Get(addon) 79 self:EnableAddOn(addon:GetName())
78
79 if self:CanForceLoad() and tree:CanForceLoad() then
80 tree:ForceLoad()
81 elseif tree:CanLoD() then
82 tree:PrepareForLoD()
83 elseif tree:CanLoad() then
84 tree:PrepareForReload()
85 requestReload = true
86 end
87 end 80 end
88 end 81 end
89 82
83 --[[
90 if requestReload then 84 if requestReload then
91 local message = LibScriptLink:NewLink(ReloadUI) .. " to reload your UI." 85 local message = LibScriptLink:NewLink(ReloadUI) .. " to reload your UI."
92 self:Print(message) 86 self:Print(message)
93 end 87 end
88 ]]
94 end 89 end
95 90
96 91
97 function DependencyLoader:EnableAddOn(...) 92 function DependencyLoader:EnableAddOn(...)
98 print("DependencyLoader:EnableAddOn", ...) 93 local id = ...
94 local addon = addonTable.classes.Addon:Get(id)
95 local tree = addonTable.classes.Tree:Get(addon)
96
97 local requestReload = false
98
99 if self:CanForceLoad() then
100 -- NOTE: if we can force-load, then will enabling LoD addons cause them to load too?
101 -- A: no, they will still wait for LoadAddOn
102
103 -- Can the addon be loaded on demand if force-loading is
104 -- allowed for its dependencies
105 -- if so, enable all deps and force-load if nec.
106 -- deps will get enabled if all parents are lod, force-loaded
107 -- if any parent can't be loaded on demand
108 -- else
109 -- if the addon is not loadable on demand but the tree can be
110 -- force-loaded, then force-load it all
111 -- deps will all get loaded since req. for root to load
112 -- else
113 -- if it can be loaded with a reloadui then prepare after login
114 -- else
115 -- it can't be loaded, maybe tell the user
116
117 if tree:CanLoDWithForce() then
118 tree:PrepareForLoD()
119 elseif tree:CanForceLoad() then
120 tree:ForceLoad()
121 elseif tree:CanLoad() then
122 tree:PrepareForReload()
123 requestReload = true
124 else
125 -- TODO: tell user
126 end
127 else
128 -- if it can be loaded on demand (deps are loaded or LoD) then
129 -- prepare it (enable all deps)
130 -- else
131 -- if it can be loaded (and isn't already) then
132 -- if force loading is available, we have to wait, then enable everything
133 -- else
134 -- prepare for reload (TODO: move this check and similar to PLAYER_LOGOUT)
135 -- else
136 -- can't be loaded, maybe tell the user
137
138 if tree:CanLoD() then
139 tree:PrepareForReload()
140 -- don't actually intend to reload, just enable everything
141 elseif tree:CanLoad() then
142 tree:PrepareForReload()
143 requestReload = true
144 else
145 -- TODO: tell user
146 end
147 end
148
149 -- TODO: requestReload
150
151 return self.hooks.EnableAddOn(...)
99 end 152 end
153
154
155
156 --- Prepares the addon tree rooted at the specified addon
157 function DependencyLoader:LoadAddOn(...)
158 local id = ...
159
160 local isBlizzardAddon = false
161
162 if type(id) == "string" and string.match(id, "Blizzard_") then
163 self:Debug("Asked to load Blizzard addon", id, ", skipping")
164 isBlizzardAddon = true
165 end
166
167 if not isBlizzardAddon then
168 local addon = addonTable.classes.Addon:Get(id)
169 local tree = addonTable.classes.Tree:Get(addon)
170
171 if tree:CanLoD() then
172 tree:PrepareForLoD()
173 elseif tree:CanLoad() then
174 tree:PrepareForReload()
175 end
176 end
177
178 -- call even if it can't be loaded so regular returns appear
179 return self.hooks.LoadAddOn(...)
180 end