Skip to content

Commit b632042

Browse files
committed
feature: Add some convenience methods for player state management
1 parent 249dd50 commit b632042

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed

Runtime/Client/LootLockerStateData.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,29 @@ public static List<string> ClearAllSavedStates()
310310
return removedULIDs;
311311
}
312312

313+
public static List<string> ClearAllSavedStatesExceptForPlayer(string playerULID)
314+
{
315+
List<string> removedULIDs = new List<string>();
316+
LoadMetaDataFromPlayerPrefsIfNeeded();
317+
if (ActiveMetaData == null)
318+
{
319+
return removedULIDs;
320+
}
321+
322+
List<string> ulidsToRemove = new List<string>(ActiveMetaData.SavedPlayerStateULIDs);
323+
foreach (string ULID in ulidsToRemove)
324+
{
325+
if (!ULID.Equals(playerULID, StringComparison.OrdinalIgnoreCase))
326+
{
327+
if (ClearSavedStateForPlayerWithULID(ULID))
328+
{
329+
removedULIDs.Add(ULID);
330+
}
331+
}
332+
}
333+
return removedULIDs;
334+
}
335+
313336
public static void SetPlayerULIDToInactive(string playerULID)
314337
{
315338
if (string.IsNullOrEmpty(playerULID) || !ActivePlayerData.ContainsKey(playerULID))
@@ -320,6 +343,25 @@ public static void SetPlayerULIDToInactive(string playerULID)
320343
ActivePlayerData.Remove(playerULID);
321344
}
322345

346+
public static void SetAllPlayersToInactive()
347+
{
348+
ActivePlayerData.Clear();
349+
}
350+
351+
public static void SetAllPlayersToInactiveExceptForPlayer(string playerULID)
352+
{
353+
if (string.IsNullOrEmpty(playerULID))
354+
{
355+
return;
356+
}
357+
358+
var keysToRemove = ActivePlayerData.Keys.Where(key => !key.Equals(playerULID, StringComparison.OrdinalIgnoreCase)).ToList();
359+
foreach (string key in keysToRemove)
360+
{
361+
ActivePlayerData.Remove(key);
362+
}
363+
}
364+
323365
public static List<string> GetActivePlayerULIDs()
324366
{
325367
return ActivePlayerData.Keys.ToList();

Runtime/Game/LootLockerSDKManager.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,27 @@ public static void SetPlayerUlidToInactive(string playerUlid)
151151
LootLockerStateData.SetPlayerULIDToInactive(playerUlid);
152152
}
153153

154+
/// <summary>
155+
/// Make the state for all currently active players to be "inactive".
156+
///
157+
/// This will not delete the state, but it will remove all players from the list of active players.
158+
/// </summary>
159+
public static void SetAllPlayersToInactive()
160+
{
161+
LootLockerStateData.SetAllPlayersToInactive();
162+
}
163+
164+
/// <summary>
165+
/// Make the state for all currently active players except the specified player to be "inactive".
166+
///
167+
/// This will not delete the state, but it will remove all players except the specified one from the list of active players.
168+
/// </summary>
169+
/// <param name="playerUlid">The ULID of the player to keep active.</param>
170+
public static void SetAllPlayersToInactiveExceptForPlayer(string playerUlid)
171+
{
172+
LootLockerStateData.SetAllPlayersToInactiveExceptForPlayer(playerUlid);
173+
}
174+
154175
/// <summary>
155176
/// Get a list of player ULIDs that there is a stored state for.
156177
/// This includes both active and inactive players.
@@ -213,6 +234,17 @@ public static void ClearAllPlayerCaches()
213234
LootLockerStateData.ClearAllSavedStates();
214235
}
215236

237+
/// <summary>
238+
/// Remove all stored state information except for the specified player (players will need to re-authenticate).
239+
/// This will clear all player states except for the specified player.
240+
/// If the specified player is the default player, it will remain as the default player.
241+
/// </summary>
242+
/// <param name="playerUlid">The ULID of the player to save the cache for.</param>
243+
public static void ClearAllPlayerCachesExceptForPlayer(string playerUlid)
244+
{
245+
LootLockerStateData.ClearAllSavedStatesExceptForPlayer(playerUlid);
246+
}
247+
216248
#endregion
217249

218250
#region Authentication

0 commit comments

Comments
 (0)