vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 --[[
2 Bongos\core\profiles.lua
3 Code for saving and loading Bongos Settings
4 --]]
5  
6 local savedList = {};
7  
8 BProfile = {
9 Load = function(name)
10 if not BongosProfiles then
11 BMsg("No profiles saved yet.");
12 elseif not name then
13 BMsg("No profile name specified.");
14 elseif not BongosProfiles[name] then
15 BMsg("'" .. (name or "null") .. "' is an invalid profile.");
16 else
17 BBar.ForAllIDs(BBar.Delete);
18 for field, value in pairs(BongosProfiles[name]) do
19 setfield(field, tcopy(value));
20 local action = savedList[name];
21 if action and not tonumber(action) then
22 action();
23 end
24 end
25 BScript.CallStartup();
26  
27 BMsg("Loaded profile '" .. name .. "'.");
28 end
29 end,
30  
31 Save = function(name)
32 if not BongosProfiles then
33 BongosProfiles = {};
34 end
35 BongosProfiles[name] = {};
36  
37 --save all bar and position information
38 for _, bar in pairs(BBar.GetAll()) do
39 BongosProfiles[name][bar.setsGlobal] = tcopy(bar.sets) or {};
40 BongosProfiles[name][bar.setsGlobal].x = bar:GetLeft();
41 BongosProfiles[name][bar.setsGlobal].y = bar:GetTop();
42 local scale = bar:GetScale();
43 if scale == 1 then
44 scale = nil;
45 end
46 BongosProfiles[name][bar.setsGlobal].scale = scale;
47 end
48 for var in savedList do
49 BongosProfiles[name][var] = tcopy(getfield(var));
50 end
51  
52 BMsg("Saved your current configuration as the profile '" .. name .. "'.");
53 end,
54  
55 Delete = function(name)
56 if not BongosProfiles then
57 BMsg("No profiles saved yet.");
58 elseif(not name) then
59 BMsg("No profile specified.");
60 elseif not BongosProfiles[name] then
61 BMsg("'" .. (name or "null") .. "' is an invalid profile.");
62 else
63 BongosProfiles[name] = nil;
64 BMsg("Deleted profile '" .. name .. "'.");
65 end
66 end,
67  
68 SetDefault = function(name)
69 if not name then
70 if BongosProfiles then
71 BongosProfiles.default = nil;
72 BMsg("Default profile disabled.");
73 end
74 elseif BongosProfiles and BongosProfiles[name] then
75 BongosProfiles.default = name;
76 BMsg("'" .. name .. "' has been set as the default Bongos profile.");
77 else
78 BMsg("Invalid profile name.");
79 end
80 end,
81  
82 GetDefault = function()
83 if BongosProfiles then
84 return BongosProfiles.default;
85 end
86 end,
87  
88 RegisterForSave = function(varName, loadAction)
89 if not savedList[varName] then
90 savedList[varName] = (loadAction or 1);
91 end
92 end,
93  
94 GetDefaultValue = function(varName)
95 if not (varName and BongosProfiles and BongosProfiles.default and BongosProfiles[BongosProfiles.default]) then
96 return nil;
97 end
98 local defaults = BongosProfiles[BongosProfiles.default][varName];
99 if defaults then
100 return tcopy(defaults);
101 end
102 end,
103 }