-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathDatabaseCore.lua
More file actions
213 lines (176 loc) · 6.64 KB
/
DatabaseCore.lua
File metadata and controls
213 lines (176 loc) · 6.64 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
--[[ ArenaLive Database Core
Created by: Vadrak
Creation Date: 31.05.2013
Last Update: 02.06.2013
This function set handles the database for ArenaLive. All ArenaLive based addons need to register their defaults to this core on their first launch.
The defaults will then be used to set up a database entry for the addon's saved variables.
]]--
-- Local version is said to be faster.
local addonName = "ArenaLiveCore";
local ArenaLiveCore = ArenaLiveCore;
-- Create a local to store the player's name and realm for the current logged char.
local characterModifier;
-- Create the database table.
ArenaLiveCore.db = {};
local defaultSettings =
{
["CCPriority/defCD"] = 100,
["CCPriority/offCD"] = 30,
["CCPriority/stun"] = 90,
["CCPriority/silence"] = 80,
["CCPriority/crowdControl"] = 70,
["CCPriority/defCD"] = 60,
["CCPriority/disarm"] = 50,
["CCPriority/root"] = 40,
["Auras/OnlyShowCastableBuffs"] = false,
["Auras/OnlyShowDispellableDebuffs"] = false,
["Auras/ShowOwnDebuffsOnly"] = false,
["Auras/TournamentFilter"] = false,
}
--[[ Function: AddDatabase
This function adds a addon's default settings to the database on the initial start up.
Arguments:
databaseName: The databases' name.
defaultSettings: A table containing the addon's default variables.
]]--
function ArenaLiveCore:AddDatabase(databaseName, defaultSettings, saveByCharacter)
if ( not databaseName ) then
ArenaLiveCore:Message(string.format(ArenaLiveCore:GetLocalisation(addonName, "ERR_ADD_DATABASE_NAME_NOT_GIVEN"), databaseName), "error");
return;
end
local name, realm;
if ( not ArenaLiveCore.db[databaseName] ) then
if ( saveByCharacter ) then
ArenaLiveCore.db[databaseName] = {};
ArenaLiveCore.db[databaseName]["saveByCharacter"] = true;
ArenaLiveCore.db[databaseName][characterModifier] = defaultSettings;
else
ArenaLiveCore.db[databaseName] = defaultSettings;
end
elseif ( ArenaLiveCore.db[databaseName] and ArenaLiveCore.db[databaseName]["saveByCharacter"] and not ArenaLiveCore.db[databaseName][characterModifier] ) then
ArenaLiveCore.db[databaseName][characterModifier] = defaultSettings;
else
--[[ If an entry with this name already exists, we don't overwrite it, because this could cause problems.
We will print an error messsage instead, if we handle two different addon's that use the same name.
If you want to update your database during the game use the "UpdateAddOn" function instead! ]]--
ArenaLiveCore:Message(string.format(ArenaLiveCore:GetLocalisation(addonName, "ERR_ADD_DATABASE_ALREADY_EXISTS"), databaseName), "error");
end
end
--[[ Function: RemoveDatabase
Removes a addon's saved variables from the database.
databaseName: The databases' name.
]]--
function ArenaLiveCore:RemoveDatabase(databaseName)
if ( not databaseName ) then
ArenaLiveCore:Message(ArenaLiveCore:GetLocalisation(addonName, "ERR_REMOVE_DATABASE_NAME_NOT_GIVEN"), "error");
return;
end
if ( ArenaLiveCore.db[databaseName] ) then
ArenaLiveCore.db[databaseName] = nil;
else
ArenaLiveCore:Message(string.format(ArenaLiveCore:GetLocalisation(addonName, "ERR_REMOVE_DATABASE_DOESNT_EXISTS"), databaseName), "error");
end
end
--[[ Function: UpdateDatabase
This function updates a addon's saved variables in the database.
In contrast to the AddAddon function, this one overwrites the already existing database entry
and returns an error message, if the database entry doesn't exist.
Arguments:
databaseName: The databases' name.
updatedSettings: A table containing the addon's updated saved variables.
]]--
function ArenaLiveCore:UpdateDatabase(databaseName, updatedSettings)
if ( not databaseName ) then
ArenaLiveCore:Message(ArenaLiveCore:GetLocalisation(addonName, "ERR_UPDATE_DATABASE_NAME_NOT_GIVEN"), "error");
return;
end
if ( ArenaLiveCore.db[databaseName] ) then
if ( ArenaLiveCore.db[databaseName]["saveByCharacter"] ) then
ArenaLiveCore.db[databaseName][characterModifier] = updatedSettings;
else
ArenaLiveCore.db[databaseName] = updatedSettings;
end
else
ArenaLiveCore:Message(string.format(ArenaLiveCore:GetLocalisation(addonName, "ERR_UPDATE_DATABASE_DOESNT_EXISTS"), databaseName), "error");
end
end
--[[ Function: GetDBEntry
Returns the value of the requested saved variable.
Arguments:
databaseName: The databases' name. If no addon name is given, then the function will start at the base of the database.
key: String containing the key of the variable.
Returns:
returnValue: The value of specified database entry.
]]--
function ArenaLiveCore:GetDBEntry (databaseName, key)
if ( databaseName and not ArenaLiveCore.db[databaseName] ) then
ArenaLiveCore:Message(string.format(ArenaLiveCore:GetLocalisation(addonName, "ERR_GET_DATABASE_DOESNT_EXISTS"), key, databaseName), "error");
return;
end
local returnValue;
if ( databaseName ) then
if ( ArenaLiveCore.db[databaseName]["saveByCharacter"] ) then
returnValue = ArenaLiveCore.db[databaseName][characterModifier][key];
else
returnValue = ArenaLiveCore.db[databaseName][key];
end
else
ArenaLiveCore:Message(ArenaLiveCore:GetLocalisation(addonName, "ERR_GET_DATABASE_NAME_NOT_GIVEN"), "error");
return;
end
return returnValue;
end
--[[ Function: SetDBEntry
Sets the value of the specified saved variable.
Arguments:
databaseName: The addon's name.
key: String containing the key of the variable.
value: the new value of the entry.
]]--
function ArenaLiveCore:SetDBEntry(databaseName, key, value)
if ( databaseName and not ArenaLiveCore.db[databaseName] ) then
ArenaLiveCore:Message(string.format(ArenaLiveCore:GetLocalisation(addonName, "ERR_SET_DATABASE_DOESNT_EXISTS"), name), "error");
return;
end
if ( databaseName ) then
if ( ArenaLiveCore.db[databaseName]["saveByCharacter"] ) then
ArenaLiveCore.db[databaseName][characterModifier][key] = value;
else
ArenaLiveCore.db[databaseName][key] = value;
end
else
ArenaLiveCore.db[key] = value;
end
end
--[[ Function: SetDBEntry
Returns wether a database with the specified name exists or not.
Arguments:
databaseName: The addon's name.
Returns:
true, if the database exists, otherwise nil.
]]--
function ArenaLiveCore:DatabaseExists(databaseName)
if ( not databaseName ) then
return;
end
if ( ArenaLiveCore.db[databaseName] ) then
if ( not ArenaLiveCore.db[databaseName]["saveByCharacter"] ) then
return true;
else
if ( ArenaLiveCore.db[databaseName][characterModifier] ) then
return true;
else
return nil;
end
end
else
return nil;
end
end
local function SetCharacterModifier()
local name, realm;
name = UnitName("player");
realm = GetRealmName();
characterModifier = name.."-"..realm;
end
SetCharacterModifier();