comparison DependencyLoader/DependencyLoader.lua @ 10:e0a4a8b5b389

lots more modifications...
author mckenziemc
date Sun, 05 Dec 2010 03:10:07 -0800
parents DependencyLoader/frontend.lua@5362e308c3eb
children b230b94d4487
comparison
equal deleted inserted replaced
9:5362e308c3eb 10:e0a4a8b5b389
1 -- DependencyLoader
2 --
3
4 local addonName, addonTable = ...
5
6
7 local DependencyLoader = LibStub("AceAddon-3.0"):NewAddon(addonName, "AceHook-3.0")
8 _G[addonName] = DependencyLoader
9
10 addonTable.interface = DependencyLoader
11
12
13 local libPrint = LibStub("LibPrint-1.0")
14 local LibScriptLink = LibStub("LibScriptLink-1.0")
15
16 DependencyLoader.printStream = libPrint:NewStream("DependencyLoader", "DpLdr", print)
17 DependencyLoader.debugStream = libPrint:NewStream("DependencyLoader", "DpLdr", "mcm")
18
19
20 function DependencyLoader:Print(...)
21 self.printStream:Print(...)
22 end
23
24
25 function DependencyLoader:Debug(...)
26 self.debugStream:Print(...)
27 end
28
29
30 function DependencyLoader:OnInitialize()
31 self:Debug("Initializing", addonName)
32 self:Enable()
33 end
34
35
36 function DependencyLoader:OnEnable()
37 self:Print("Enabled", addonName)
38
39 self:Hook("EnableAddOn", true)
40
41 self:FixCurrentAddons()
42 end
43
44
45 function DependencyLoader:OnDisable()
46 self:Print("Disabled", addonName)
47 end
48
49
50 -- Does not consider user settings or addon errata.
51 function DependencyLoader:IsForceLoadAvailable()
52 return IsLoggedIn() and true or false
53 end
54
55
56 function DependencyLoader:IsForceLoadAllowed()
57 -- TODO: check user settings
58 return true
59 end
60
61
62 function DependencyLoader:CanForceLoad()
63 return self:IsForceLoadAvailable() and self:IsForceLoadAllowed()
64 end
65
66
67 -- Enables any dependencies needed by the addons
68 -- that have already been enabled
69 function DependencyLoader:FixCurrentAddons()
70 local requestReload = false
71
72 for i=1, GetNumAddOns() do
73 local addon = addonTable.classes.Addon:Get(i)
74
75 -- TODO: what if an addon was loaded but its deps were then disabled?
76 if addon:IsEnabled() and not addon:IsLoaded() then
77 local tree = addonTable.classes.Tree:Get(addon)
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
88 end
89
90 if requestReload then
91 local message = LibScriptLink:NewLink(ReloadUI) .. " to reload your UI."
92 self:Print(message)
93 end
94 end
95
96
97 function DependencyLoader:EnableAddOn(...)
98 print("DependencyLoader:EnableAddOn", ...)
99 end