comparison DependencyLoader/Core.lua @ 17:f825ccf94a89

fixed an indexing issue in Addon.lua moved most of the code in DependencyLoader.lua to Core.lua, and renamed the former to frontend.lua updated load.xml rearranged stuff in start.lua
author mckenziemc
date Sat, 11 Dec 2010 03:32:04 -0800
parents 1d8898cd1c82
children e7995d599184
comparison
equal deleted inserted replaced
16:1d8898cd1c82 17:f825ccf94a89
1 -- Core 1 -- Core
2 -- Provides core functionality of DependencyLoader 2 -- Provides core functionality of Core
3
4
5 -- TODO: disable bootstrap if we load successfully?
6 -- TODO: implement a feature to disable unneeded libraries when a parent
7 -- is disabled?
3 8
4 9
5 local addonName, addonTable = ... 10 local addonName, addonTable = ...
6 11
7 12
8 local Core, core = addonTable:NewClass("Core") 13 -- locals
14 local print = addonTable.print
15 local debug = addonTable.debug
16 local classes = addonTable.classes
17
18 local AceHook = LibStub("AceHook-3.0")
19 local LibScriptLink = LibStub("LibScriptLink-1.0")
20
21
22 local Core = addonTable:NewClass("Core")
23
24
25 AceHook:Embed(Core)
26
27 Core.queuedEnables = {} -- addons queued to be enabled after PLAYER_LOGIN
28
29
30 -- Does not consider user settings or addon errata.
31 function Core:IsForceLoadAvailable()
32 if IsLoggedIn() then
33 return false
34 else
35 return true
36 end
37 end
38
39
40 function Core:IsForceLoadAllowed()
41 -- TODO: check user settings
42 return true
43 end
44
45
46 function Core:CanForceLoad()
47 return self:IsForceLoadAvailable() and self:IsForceLoadAllowed()
48 end
49
50
51 -- Enables any dependencies needed by the addons
52 -- that have already been enabled
53 function Core:PrepareAllAddons()
54 for i=1, GetNumAddOns() do
55 local addon = classes.Addon:Get(i)
56
57 -- TODO: what if an addon was loaded but its deps were then disabled?
58 if addon:IsEnabled() and not addon:IsLoaded() then
59 self:EnableAddOn(i)
60 end
61 end
62 end
63
64
65 function Core:SetHooks()
66 self:RawHook("EnableAddOn", true)
67 self:RawHook("LoadAddOn", true)
68 end
69
70
71 -- FIXME: use pcall in EnableAddOn and LoadAddOn, so that if my part errors,
72 -- it can still use the unhooked version
73
74 function Core:EnableAddOn(...)
75 local id = ...
76
77 debug("EnableAddOn", ...)
78
79 -- even though we know EnableAddOn can cause force-loading before PLAYER_LOGIN,
80 -- DO NOT attempt to "fix" it: another addon that -does- know about
81 -- the different behavior might call our hook.
82
83 if classes.Addon:Exists(id) then
84 local addon = classes.Addon:Get(id)
85 local tree = classes.Tree:Get(addon)
86
87 local requestReload = false
88
89 if self:CanForceLoad() then
90 -- NOTE: if we can force-load, then will enabling LoD addons cause them to load too?
91 -- A: no, they will still wait for LoadAddOn
92
93 -- Can the addon be loaded on demand if force-loading is
94 -- allowed for its dependencies
95 -- if so, enable all deps and force-load if nec.
96 -- deps will get enabled if all parents are lod, force-loaded
97 -- if any parent can't be loaded on demand
98 -- else
99 -- if the addon is not loadable on demand but the tree can be
100 -- force-loaded, then force-load it all
101 -- deps will all get loaded since req. for root to load
102 -- else
103 -- if it can be loaded with a reloadui then prepare after login
104 -- else
105 -- it can't be loaded, maybe tell the user
106
107 if tree:CanForceLoad() then
108 if addon:CanLoD() then
109 tree:PrepareForLoD()
110 else
111 tree:ForceLoad()
112 end
113 elseif tree:CanLoad() then
114 tree:PrepareForLoad()
115 requestReload = true
116 else
117 -- TODO: tell user
118 end
119
120
121 --[[
122 if tree:CanLoDWithForce() then
123 tree:PrepareForLoD()
124 elseif tree:CanForceLoad() then
125 tree:ForceLoad()
126 elseif tree:CanLoad() then
127 tree:PrepareForLoad()
128 requestReload = true
129 else
130 -- TODO: tell user
131 end
132 ]]
133 else
134 -- if it can be loaded on demand (deps are loaded or LoD) then
135 -- prepare it (enable all deps)
136 -- else
137 -- if it can be loaded (and isn't already) then
138 -- if force loading is available, we have to wait, then enable everything
139 -- else
140 -- prepare for reload (TODO: move this check and similar to PLAYER_LOGOUT)
141 -- else
142 -- can't be loaded, maybe tell the user
143
144 if tree:CanLoD() then
145 tree:PrepareForLoad()
146 -- don't actually intend to reload, just enable everything
147 elseif tree:CanLoad() then
148 tree:PrepareForLoad()
149 requestReload = true
150 else
151 -- TODO: tell user
152 end
153 end
154
155 if requestReload then
156 self:RequestReload()
157 end
158 end
159
160 -- propogate the call even if it doesn't exist or deps are unavailable
161 return self:RawEnableAddOn(...)
162 end
163
164
165
166 --- Prepares the addon tree rooted at the specified addon
167 function Core:LoadAddOn(...)
168 local id = ...
169
170 debug("LoadAddOn", ...)
171
172 if classes.Addon:Exists(id) then
173 local addon = classes.Addon:Get(id)
174 local tree = classes.Tree:Get(addon)
175
176 if tree:CanLoD() then
177 tree:PrepareForLoD()
178 elseif tree:CanLoad() then
179 tree:PrepareForLoad()
180 -- TODO: request reload
181 end
182 end
183
184 -- call even if it can't be loaded so regular returns appear
185 return self:RawLoadAddOn(...)
186 end
187
188
189 function Core:RequestReload()
190 -- TODO: this should be throtled so that it can
191 -- occur more than once but not within a short time
192
193 debug("reload requested (NYI)")
194 end
195
196
197 -- name or index
198 function Core:QueueEnable(addon)
199 self.queuedEnables[addon] = true
200 end
201
202
203 function Core:RawEnableAddOn(...)
204 return self.hooks.EnableAddOn(...)
205 end
206
207
208 function Core:RawLoadAddOn(...)
209 return self.hooks.LoadAddOn(...)
210 end
211
212
213 function Core:ProcessEnableQueue()
214 for addon in pairs(self.queuedEnables) do
215 self:RawEnableAddOn(addon)
216 self.queuedEnables[addon] = nil
217 end
218 end