comparison DependencyLoader_Core/Addon.lua @ 8:930871e163bc

created a new Tree class and started rearranging code
author mckenziemc
date Sat, 04 Dec 2010 23:05:34 -0800
parents 9852fcd5e59e
children
comparison
equal deleted inserted replaced
7:f4ab9d7b97b0 8:930871e163bc
2 -- Represents individual addon modules 2 -- Represents individual addon modules
3 3
4 4
5 local addonName, addonTable = ... 5 local addonName, addonTable = ...
6 6
7 print("running Addon.lua")
8 7
9 -- NOTE: I assume that the API addon functions are 8 -- NOTE: I assume that the API addon functions are
10 -- slightly quicker with an index than with a number. 9 -- slightly quicker with an index than with a number.
11 10
12 -- TODO: modify the dependency stuff to use the Errata module if available 11 -- TODO: modify the dependency stuff to use the Errata module if available
13 12
14 local Addon, addon = addonTable:NewClass("Addon") 13 local Addon, addon = addonTable:NewClass("Addon")
15 14
15
16 -- load ability masks
17 Addon.loadMasks = {
18 reload = bit.lshift(1, 0), -- can load after reloadui
19 ondemand = bit.lshift(1, 1), -- can load on demand
20 forceafter = bit.lshift(1, 2), -- force load after it would normally be loaded
21 forcebefore = bit.lshift(1, 3), -- force load before it would normally be loaded
22 }
23
24
25 Addon.addons = {}
26 Addon.nameToIndex = {}
27
28
29 -- Internal function
30 -- Creates a new Addon object
31 -- @param id Name or index of the addon.
16 function Addon:New(id) 32 function Addon:New(id)
17 assert(type(id) == "number" or type(id) == "string")
18
19 local instance = {} 33 local instance = {}
20
21 setmetatable(instance, self.instanceMetatable) 34 setmetatable(instance, self.instanceMetatable)
22 35
23 if type(id) == "number" then 36 if type(id) == "number" then
24 -- TODO: make sure it's in range 37 -- TODO: make sure it's in range
25 instance.index = id 38 instance.index = id
44 end 57 end
45 58
46 return instance 59 return instance
47 end 60 end
48 61
62
63 --- Retrieves an Addon object.
64 -- @param id Name or index of the addon to retrieve.
65 -- @return The Addon object, or nil if not found.
66 function Addon:Get(id)
67 if not self:Exists(id) then
68 return nil
69 end
70
71 if type(id) == "number" then
72 if self.addons[id] ~= nil then
73 return self.addons[id]
74 end
75
76 local new = self:New(id)
77 self.addons[new:GetIndex()] = new
78 self.nameToIndex[new:GetName()] = id
79
80 return new
81 elseif type(id) == "string" then
82 if self.nameToIndex[id] then
83 return self.addons[self.nameToIndex[id] ]
84 end
85
86 local new = self:New(id)
87 self.addons[new:GetIndex()] = new
88 self.nameToIndex[id] = new:GetIndex()
89
90 return new
91 end
92 end
49 93
50 -- Checks if an addon exists with the specified name. 94 -- Checks if an addon exists with the specified name.
51 -- @param addon Name of the addon. 95 -- @param addon Name of the addon.
52 -- @return True if the addon is present, false otherwise. 96 -- @return True if the addon is present, false otherwise.
53 function Addon:Exists(addon) 97 function Addon:Exists(addon)
69 error() 113 error()
70 end 114 end
71 end 115 end
72 116
73 117
118 function Addon:GetLoadMasks()
119 return self.masks
120 end
121
122
74 function addon:GetName() 123 function addon:GetName()
75 return self.name 124 return self.name
76 end 125 end
77 126
78 127
90 else 139 else
91 return true 140 return true
92 end 141 end
93 end 142 end
94 143
95 -- FIXME: an addon may be present but unloadable if loading out of date addons is disabled. 144
96 -- NOTE: CanForceLoad and CanLoD don't check the status of dependencies 145 function addon:GetLoadBitfield()
97 146 local bitfield = 0
98 function addon:CanForceLoad() 147
99 return true -- TODO: check if there's any reason addons can't be forceloaded 148 if self:CanLoad() then
100 end 149 bitfield = bitfield + self.masks.reload
150 end
151
152 if self:CanLoD() then
153 bitfield = bitfield + self.masks.ondemand
154 end
155
156 if self:CanForceLoadAfter() then
157 bitfield = bitfield + self.masks.forceafter
158 end
159
160 if self:CanForceLoadBefore() then
161 bitfield = bitfield + self.masks.forcebefore
162 end
163
164 return bitfield
165 end
166
167
168 --- Checks if the addon is loadable.
169 -- Considers interface issues, missing, etc. (NYI)
170 -- Does not check dependencies.
171 function addon:CanLoad()
172 -- FIXME: an addon may be present but unloadable if loading out of date addons is disabled.
173 return true
174 end
175
101 176
102 function addon:CanLoD() 177 function addon:CanLoD()
103 -- FIXME: what will the client say about addons using LoadManagers if the LM was force-loaded? 178 -- FIXME: what will the client say about addons using LoadManagers if the LM was force-loaded?
104 if IsAddOnLoadOnDemand(self.name) then 179 if IsAddOnLoadOnDemand(self.name) then
105 return true 180 return true
106 else 181 else
107 return false 182 return false
108 end 183 end
109 end 184 end
110 185
186
187 function addon:CanForceLoadAfter()
188 -- TODO: check Errata module
189 return false
190 end
191
192
193 function addon:CanForceLoadBefore()
194 -- TODO: check Errata module
195 return false -- TODO: check if there's any reason addons can't be forceloaded
196 end
197
198
199 function addon:Enable()
200 -- FIXME: delay this till after PLAYER_LOGIN or it'll get force-loaded
201 EnableAddOn(self.name)
202 end
203
204
111 -- NOTE: only call for LoD, not force-loading 205 -- NOTE: only call for LoD, not force-loading
112 function addon:Load() 206 function addon:Load()
113 assert(self:CanLoD()) 207 assert(self:CanLoD())
114 208
115 EnableAddOn(self.name) 209 EnableAddOn(self.name)
116 LoadAddOn(self.name) 210 LoadAddOn(self.name)
117 end 211 end
118 212
213
119 function addon:ForceLoad() 214 function addon:ForceLoad()
120 assert(self:CanForceLoad()) 215 assert(self:CanForceLoad())
121 -- TODO: make sure force-loading is available at this time 216 -- TODO: make sure force-loading is available at this time
122 217
123 EnableAddOn(self.name) -- This should cause the game to also load this addon 218 EnableAddOn(self.name) -- This should cause the game to also load this addon
124 end 219 end
125 220
126 221
127 function addon:GetDependencies() 222 function addon:GetDependencies()
223 -- TODO: consider no-lib embeds as deps?
128 return GetAddOnDependencies(self.index) 224 return GetAddOnDependencies(self.index)
129 end 225 end
130 226
131 227
132 function addon:GetEmbeds() 228 function addon:GetEmbeds()