-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path_Settings.lua
93 lines (74 loc) · 2.75 KB
/
_Settings.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
local THIS_ADDON_NAME=...;
local g_Addon = getfenv(0)[THIS_ADDON_NAME];
local g_Consts = g_Addon.Constants;
-- Global reference to g_Addon.Settings for SavedVariables in .toc
-- Debugging: /dump CatRotationHelperSettings
CatRotationHelperSettings = {};
function g_Addon.Settings_Frame_ComposeDefault(a_FrmPoint, a_ScrPoint, a_LocationX, a_LocationY, a_Angle)
local result = {};
result.LocationFrmPoint = a_FrmPoint;
result.LocationScrPoint = a_ScrPoint;
result.LocationX = a_LocationX;
result.LocationY = a_LocationY;
result.Angle = a_Angle;
result.Scale = 1;
return result;
end
function g_Addon.Settings_ComposeDefaults()
local defaultSettings = {};
defaultSettings.Version = 3;
defaultSettings.Frames =
{
g_Addon.Settings_Frame_ComposeDefault("TOP", "CENTER", 0, -70, 0),
g_Addon.Settings_Frame_ComposeDefault("RIGHT", "CENTER", -100, 0, 270),
g_Addon.Settings_Frame_ComposeDefault("LEFT", "CENTER", 100, 0, 270),
};
defaultSettings.DisabledIcons = {};
defaultSettings.ShowWhen = g_Consts.UI_SHOWWHEN_COMBAT_OR_TARGET;
return defaultSettings;
end
function g_Addon.Settings_Repair(a_Settings)
if (nil == a_Settings.Version) then
return false;
end
if (1 == a_Settings.Version) then
a_Settings.DisabledIcons = {};
a_Settings.Version = 2;
end
if (2 == a_Settings.Version) then
-- If user already had addon, keep the old behavior
a_Settings.ShowWhen = g_Consts.UI_SHOWWHEN_TARGET;
a_Settings.Version = 3;
end
if (("number" ~= type(a_Settings.ShowWhen)) or (a_Settings.ShowWhen < g_Consts.UI_SHOWWHEN_FIRST) or (a_Settings.ShowWhen > g_Consts.UI_SHOWWHEN_LAST)) then
a_Settings.ShowWhen = g_Consts.UI_SHOWWHEN_COMBAT_OR_TARGET;
end
return true;
end
function g_Addon.Settings_Load(a_Settings)
a_Settings = a_Settings or CatRotationHelperSettings;
-- Create defaults if user has bad settings (or doesn't have any at all)
if (not g_Addon.Settings_Repair(a_Settings)) then
g_Addon.PrintToChat("Creating default settings");
a_Settings = g_Addon.Settings_ComposeDefaults();
end
-- Store references to loaded settings
CatRotationHelperSettings = a_Settings;
g_Addon.Settings = a_Settings;
end
function g_Addon.Settings_Reset()
g_Addon.SettingsBackup = g_Addon.Settings;
g_Addon.Settings_Load(g_Addon.Settings_ComposeDefaults());
g_Addon.PrintToChat("Settings have been reset");
end
function g_Addon.Settings_UndoReset()
if (g_Addon.SettingsBackup) then
-- swap active and backup settings
local backup = g_Addon.SettingsBackup;
g_Addon.SettingsBackup = g_Addon.Settings;
g_Addon.Settings_Load(backup);
g_Addon.PrintToChat("Restored settings from backup");
else
g_Addon.PrintToChat("No settings backup to restore");
end
end