-
Notifications
You must be signed in to change notification settings - Fork 8
/
GRM_SaveVar_API.lua
269 lines (223 loc) · 11 KB
/
GRM_SaveVar_API.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
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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
-- Save Variables for GRM
-- API to access and modify
GRM_AddonSettings_Save = GRM_AddonSettings_Save or {}; -- Configuration saved here for all alts. Each toon gets their own configuration table as they might be in different guilds, thus player may want to configure different.
GRM_LogReport_Save = GRM_LogReport_Save or {}; -- This will be the stored Log of events and changes.
GRM_GuildMemberHistory_Save = GRM_GuildMemberHistory_Save or {} -- Detailed information on each guild member
GRM_PlayersThatLeftHistory_Save = GRM_PlayersThatLeftHistory_Save or {}; -- Data storage of all players that left the guild, so metadata is stored if they return. Useful for "rejoin" tracking, and to see if players were banned.
GRM_CalendarAddQue_Save = GRM_CalendarAddQue_Save or {}; -- Since the add to calendar is protected, and requires a player input, this will be qued here between sessions. { name , eventTitle , eventMonth , eventDay , eventYear , eventDescription }
GRM_PlayerListOfAlts_Save = GRM_PlayerListOfAlts_Save or {}; -- This is used so the player has a working alt list to reference, so they can add themselves to an alt list.
GRM_Alts = GRM_Alts or {}; -- Alt groupings
GRM_DebugLog_Save = GRM_DebugLog_Save or {}; -- Character specific debug log for addon dev use submission.
GRM_Misc = GRM_Misc or {}; -- This serves as a backup placeholder to hold important values if a player logs off in the middle of something, it can carry on where it left off by storing a marker.
GRM_DailyAnnounce = GRM_DailyAnnounce or {};
-- Backups...
GRM_GuildDataBackup_Save = GRM_GuildDataBackup_Save or {}; -- For guild transferring to a new server
-- Minimap position for databroker
GRM_MinimapPosition = GRM_MinimapPosition or {}; -- Saving this due to changes in frame positions need to now be saved
-- Functions table
GRM = {};
-- local ghostSettings; -- In case a player leaves the guild abruptly.
--------------------------
--- DATA Queries ---------
--------------------------
-- OF NOTE, original tables will be returned, not new copies. These are absolutely mutatable tables and this is done intentionally.
-- The GRM API for public use being built in the GRM_API.lua file will follow the rules of functional programming and share copies of the tables.
-- As style preference, this is so a call can be made to the data, and it can be updated without needing a "SET" API for use. This will NOT be true in
-- the general use API class.
-- Method: GRM.S( string )
-- What it Does: Returns the player's settings. "S" is for settings.
-- Purpose: The entire purpose of this is to streamline the code a bit and clean it up.
GRM.S = function ( name )
if name and GRM_AddonSettings_Save[name] then
return GRM_AddonSettings_Save[name];
else
if GRM_G.playerOnlySettings then
-- if GRM_AddonSettings_Save[GRM_G.addonUser] then
return GRM_AddonSettings_Save[GRM_G.addonUser];
-- else
-- ghostSettings = ghostSettings or BuildGhostSettings();
-- return ghostSettings;
-- end
else
-- if GRM_AddonSettings_Save[GRM_G.guildName] then
return GRM_AddonSettings_Save[GRM_G.guildName];
-- else
-- ghostSettings = ghostSettings or BuildGhostSettings();
-- return ghostSettings;
-- end
end
end
end
-- -- Method: BuildGhostSettings()
-- -- What it Does: Creates a parallel settings profile
-- -- Purpose: Since settings are tied to the guild, or to the player, if someone quits a guild, all of a sudden the settings unload
-- -- Well, this is a problem if there are frames in the middle of loading, or various GRM features still being processed and calling settings variables.
-- -- Now, if the settings are called, and instead of returning a nil, it will just return the placeholder default setting, which doesn't relaly matter
-- -- as you are now in the guild, but it will allow those edge cases to finish running and not cause lua errors when leaving a guild abruptly.
-- local BuildGhostSettings = function()
-- local player = {};
-- for i = 0, GRM_G.SettingsPages do
-- GRM.SetDefaultAddonSettings (player, i);
-- end
-- return player;
-- end
-- Method: GRM.GetPlayer ( string [, bool] [, string] )
-- What it Does: Returns the playerTable
-- Purpose: Easier to pull player data.
GRM.GetPlayer = function ( name , appendServer , gName )
local guildName = gName or GRM_G.guildName;
if guildName ~= "" and GRM_GuildMemberHistory_Save[ guildName ] then
if not appendServer then
return GRM_GuildMemberHistory_Save[ guildName ][ name ];
else
return GRM_GuildMemberHistory_Save[ guildName ][ GRM.AppendServerName ( name , true ) ];
end
else
return nil;
end
end
-- Method: GRM.GetFormerPlayer ( string [, bool] [, string])
-- What it Does: Returns the playerTable
-- Purpose: Easier to pull player data.j
GRM.GetFormerPlayer = function ( name , appendServer , gName )
local guildName = gName or GRM_G.guildName;
if guildName ~= "" and GRM_GuildMemberHistory_Save[ guildName ] then
if not appendServer then
return GRM_PlayersThatLeftHistory_Save[ guildName ][ name ];
else
return GRM_PlayersThatLeftHistory_Save[ guildName ][ GRM.AppendServerName ( name , false ) ];
end
else
return nil;
end
end
-- Method: GRM.GetGuild ( [,string] )
-- What it Does: Returns the guild database of all players with the selected, or default current guild.
-- Purpose: Compartmentalize the data queries.
GRM.GetGuild = function ( name )
if name then
return GRM_GuildMemberHistory_Save[ name ];
else
return GRM_GuildMemberHistory_Save[ GRM_G.guildName ];
end
end
-- Method: GRM.GetFormerMembers ( [,string] )
-- What it Does: Returns the guild database of all players with the selected, or default current guild.
-- Purpose: Compartmentalize the data queries.
GRM.GetFormerMembers = function ( name )
if name then
return GRM_PlayersThatLeftHistory_Save[ name ];
else
return GRM_PlayersThatLeftHistory_Save[ GRM_G.guildName ];
end
end
-- Method: GRM.GetLog ( [,string] )
-- What it Does: Returns the log report of the given guild, or the default guild you are in
-- Purpose: Call the data easily.
GRM.GetLog = function( name )
if name then
return GRM_LogReport_Save[name];
else
return GRM_LogReport_Save[GRM_G.guildName];
end
end
-- Method: GRM.GetEvents ( [,string] )
-- What it Does: Returns items in queue to be added to the calendar.
-- Purpose: Call the data easily.
GRM.GetEvents = function( name )
if name then
return GRM_CalendarAddQue_Save[name];
else
return GRM_CalendarAddQue_Save[GRM_G.guildName];
end
end
-- Method: GRM.GetAddOnUserGuildAlts ( [,string] )
-- What it Does: Returns list of addon users' alts that have been auto-found and registered for given guild.
-- Purpose: Call the data easily.
GRM.GetAddOnUserGuildAlts = function ( name )
if name then
return GRM_PlayerListOfAlts_Save[name];
else
return GRM_PlayerListOfAlts_Save[GRM_G.guildName];
end
end
-- Method: GRM.GetGuildAlts ( string )
-- What it Does: Returns the database of alts for the given guild or current guild
-- Purpose: Call the data easily.
GRM.GetGuildAlts = function ( name )
if name then
return GRM_Alts[name];
else
return GRM_Alts[GRM_G.guildName];
end
end
-- Method: GRM.GetClubMemberInfo ( string , int )
-- What it Does: Returns the info provided by the Club API on a member
-- Purpose: The GetGuildRosterInfo provides some info that Club API does not, and the club API provides some info the guild API does not. This is an easy lookup by name.
GRM.GetClubMemberInfo = function ( playerName , clubID )
local result;
clubID = clubID or C_Club.GetGuildClubId();
if clubID and clubID ~= "" then
local members = C_Club.GetClubMembers ( clubID );
local name = "";
local player = {};
for i = 1 , #members do
player = C_Club.GetMemberInfo ( clubID , members[i] )
name = GRM.GetFullNameClubMember ( player.guid );
if name ~= "" and name == playerName then
result = player;
break;
end
end
end
return result;
end
-- Method: GRM.GetMemberInfoWithFullName ( int , int )
-- What it Does: Returns the Club member info, as well as their full name-serverName
-- Purpose: It is necessary to have the full player-serverName, but the Club API only returns the slim non-server name. This ensures you have their full name as well by utilizing the guid.
GRM.GetMemberInfoWithFullName = function ( memberID , clubID )
clubID = clubID or C_Club.GetGuildClubId();
local memberInfo = C_Club.GetMemberInfo ( clubID , memberID );
local fullName = "";
if memberInfo then
fullName = GRM.GetFullNameClubMember ( memberInfo.guid );
end
return memberInfo , fullName;
end
-- Method: GRM.GetListOfGuildies( bool )
-- What it Does: Returns a list of all current members of the guild in alphabetical order
-- Purpose: Occasionally you want a list of guild members.
GRM.GetListOfGuildies = function( slimName )
local list = {};
local members = C_Club.GetClubMembers ( GRM_G.gClubID );
local fullName = "";
for i = 1 , #members do
if slimName then
table.insert ( list , C_Club.GetMemberInfo ( GRM_G.gClubID , members[i] ).name );
else
fullName = select ( 2 , GRM.GetMemberInfoWithFullName ( members[i] ) );
table.insert ( list , fullName );
end
end
sort ( list );
return list;
end
-- Method: GRM.GetIndexOfPlayerOnList ( table , string )
-- What it Does: Returns index of player in a list, or nil if not found.
-- Purpose: Faster searching using binary search algorithm.
GRM.GetIndexOfPlayerOnList = function ( sortedTable , name )
local bottomNum = 1;
local topNum = #sortedTable;
local mid = 0;
while topNum >= bottomNum do
mid = math.floor ( ( bottomNum + topNum ) / 2 ); -- Cut it in half, and ensure it rounds down like dividing an integer
if name < sortedTable[mid].name then -- It is below!
topNum = mid - 1;
elseif name == sortedTable[mid].name then -- It is a match!
return mid;
else -- It is above!
bottomNum = mid + 1;
end
end
return nil;
end