vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | |
2 | -- Class Setup |
||
3 | AceData = AceDatabase:new("AceDB") |
||
4 | |||
5 | -- Need a constructor to override the AceDB one. |
||
6 | function AceData:new() |
||
7 | return ace:new(self) |
||
8 | end |
||
9 | |||
10 | function AceData:Initialize() |
||
11 | if( self.initialized ) then return end |
||
12 | |||
13 | self.optionsPath = {"options"} |
||
14 | self.profileBasePath = {"profiles"} |
||
15 | self.profileMapPath = {"profileMap"} |
||
16 | self.profilePath = {} |
||
17 | self.profileLoadPath = {self.profilePath, "_loadOnStart"} |
||
18 | |||
19 | return AceDbClass.Initialize(self) |
||
20 | end |
||
21 | |||
22 | |||
23 | --[[--------------------------------------------------------------------------------- |
||
24 | Ace Settings |
||
25 | ------------------------------------------------------------------------------------]] |
||
26 | |||
27 | function AceData:GetOpt(var) |
||
28 | return self:get(self.optionsPath, var) |
||
29 | end |
||
30 | |||
31 | function AceData:SetOpt(var, val) |
||
32 | return self:set(self.optionsPath, var, val) |
||
33 | end |
||
34 | |||
35 | |||
36 | --[[--------------------------------------------------------------------------------- |
||
37 | Profile Management |
||
38 | ------------------------------------------------------------------------------------]] |
||
39 | |||
40 | function AceData:GetProfile(name) |
||
41 | return self:get(self.profileBasePath, name) |
||
42 | end |
||
43 | |||
44 | function AceData:GetAddonProfile(profile, addon, profName) |
||
45 | return self:get({self.profileBasePath, profile}, addon.name, profName) |
||
46 | end |
||
47 | |||
48 | function AceData:SetAddonProfile(profile, addon, profName) |
||
49 | if( (not addon) or (not addon.db) ) then return end |
||
50 | |||
51 | self:set({self.profileBasePath, profile}, addon.name, profName) |
||
52 | if( profName and (not addon.db:get(self.profileBasePath, profile)) ) then |
||
53 | local defaults = self:GetAddonDefaults(addon) |
||
54 | if( defaults ) then |
||
55 | addon.db:set(self.profileBasePath, profile, defaults) |
||
56 | end |
||
57 | end |
||
58 | end |
||
59 | |||
60 | function AceData:GetLoadOnStart(addon) |
||
61 | if( not addon ) then |
||
62 | -- Return the entire list. |
||
63 | return self:get(self.profilePath, "_loadOnStart") |
||
64 | else |
||
65 | return self:get(self.profileLoadPath, strlower(addon)) |
||
66 | end |
||
67 | end |
||
68 | |||
69 | function AceData:SetLoadOnStart(addon, val) |
||
70 | self:set(self.profileLoadPath, strlower(addon), val) |
||
71 | end |
||
72 | |||
73 | function AceData:SetCurrentProfile() |
||
74 | local profile = self:get(self.profileMapPath, ace.char.id) |
||
75 | if( (not profile) or (not self:GetProfile(profile)) ) then |
||
76 | profile = ACE_PROFILE_DEFAULT |
||
77 | end |
||
78 | |||
79 | self:SetProfile(profile) |
||
80 | end |
||
81 | |||
82 | function AceData:SetProfile(name) |
||
83 | self.profileName = name |
||
84 | self.profilePath[1] = self.profileBasePath |
||
85 | self.profilePath[2] = name |
||
86 | end |
||
87 | |||
88 | function AceData:LoadProfile(name) |
||
89 | self:SetProfile(name) |
||
90 | self:set(self.profileMapPath, ace.char.id, name) |
||
91 | for _, addon in ace.registry:get() do |
||
92 | if( addon.db and addon.db.initialized ) then |
||
93 | self:LoadAddonProfile(addon) |
||
94 | end |
||
95 | end |
||
96 | |||
97 | -- Load any on demand addons in this profile. |
||
98 | local addons = self:GetLoadOnStart(addon) |
||
99 | if( addons ) then |
||
100 | for addon in addons do |
||
101 | LoadAddOn(addon) |
||
102 | end |
||
103 | end |
||
104 | |||
105 | ace.event:TriggerEvent("ACE_PROFILE_LOADED") |
||
106 | end |
||
107 | |||
108 | function AceData:LoadAddonProfile(addon) |
||
109 | if( not addon.profilePath ) then addon.profilePath = {} end |
||
110 | addon.profilePath[1] = self.profileBasePath |
||
111 | addon.profilePath[2] = self:SelectAddonProfile(self.profileName, addon) |
||
112 | if( addon.initialized and addon.db ) then |
||
113 | if( addon.db:get(addon.profilePath, "disabled") ) then |
||
114 | addon:DisableAddon() |
||
115 | else |
||
116 | addon:EnableAddon() |
||
117 | end |
||
118 | end |
||
119 | end |
||
120 | |||
121 | function AceData:SelectAddonProfile(name, addon) |
||
122 | if( not addon.db ) then return end |
||
123 | |||
124 | local profile = self:get({self.profileBasePath, name}, addon.name) or ACE_PROFILE_DEFAULT |
||
125 | |||
126 | if( not addon.db:get(self.profileBasePath, profile) ) then |
||
127 | local defaults = self:GetAddonDefaults(addon) |
||
128 | if( defaults ) then |
||
129 | addon.db:set(self.profileBasePath, profile, defaults) |
||
130 | end |
||
131 | end |
||
132 | |||
133 | return profile |
||
134 | end |
||
135 | |||
136 | function AceData:GetAddonDefaults(addon) |
||
137 | if( addon.db and addon.db:get(self.profileBasePath, ACE_PROFILE_DEFAULT) ) then |
||
138 | return ace.CopyTable({}, addon.db:get(self.profileBasePath, ACE_PROFILE_DEFAULT)) |
||
139 | elseif( addon.defaults ) then |
||
140 | return ace.CopyTable({}, addon.defaults) |
||
141 | end |
||
142 | end |
||
143 | |||
144 | function AceData:SaveProfile(name, profile) |
||
145 | self:set(self.profileBasePath, name, {desc=profile.desc}) |
||
146 | if( not profile.addons ) then return end |
||
147 | for _, addon in ace.registry:get() do |
||
148 | if( addon.db and profile.addons[addon.name] ) then |
||
149 | addon.db:set(self.profileBasePath, name, profile.addons[addon.name]) |
||
150 | end |
||
151 | end |
||
152 | end |
||
153 | |||
154 | function AceData:DeleteProfile(name) |
||
155 | self:set(self.profileBasePath, name) |
||
156 | for _, addon in ace.registry:get() do |
||
157 | if( addon.db ) then |
||
158 | addon.db:set(self.profileBasePath, name) |
||
159 | end |
||
160 | end |
||
161 | end |
||
162 | |||
163 | function AceData:NewProfile(incDefaults) |
||
164 | local profile = {} |
||
165 | if( not incDefault ) then return profile end |
||
166 | |||
167 | profile.addons = {} |
||
168 | for _, addon in ace.registry:get() do |
||
169 | if( addon.db and incDefaults ) then |
||
170 | profile.addons[addon.name] = self:GetAddonDefaults(addon) |
||
171 | end |
||
172 | end |
||
173 | return profile |
||
174 | end |
||
175 | |||
176 | ace.db = AceData |