Skip to content

Commit 5eb85a1

Browse files
JohannesLootkirre-bylund
authored andcommitted
Added possibility to get persistent storage as dictionary
1 parent ec6e057 commit 5eb85a1

File tree

2 files changed

+66
-1
lines changed

2 files changed

+66
-1
lines changed

Runtime/Game/LootLockerSDKManager.cs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2303,6 +2303,19 @@ public static void GetEntirePersistentStorage(Action<LootLockerGetPersistentStor
23032303
}
23042304
LootLockerAPIManager.GetEntirePersistentStorage(onComplete);
23052305
}
2306+
/// <summary>
2307+
/// Get the player storage as a Dictionary<string, string> for the currently active player (key/values).
2308+
/// </summary>
2309+
/// <param name="onComplete">onComplete Action for handling the response of type LootLockerGetPersistentStoragResponseDictionary</param>
2310+
public static void GetEntirePersistentStorage(Action<LootLockerGetPersistentStoragResponseDictionary> onComplete)
2311+
{
2312+
if (!CheckInitialized())
2313+
{
2314+
onComplete?.Invoke(LootLockerResponseFactory.SDKNotInitializedError<LootLockerGetPersistentStoragResponseDictionary>());
2315+
return;
2316+
}
2317+
LootLockerAPIManager.GetEntirePersistentStorage(onComplete);
2318+
}
23062319

23072320
/// <summary>
23082321
/// Get a specific key from the player storage for the currently active player.
@@ -2339,6 +2352,47 @@ public static void UpdateOrCreateKeyValue(string key, string value, Action<LootL
23392352
LootLockerAPIManager.UpdateOrCreateKeyValue(data, onComplete);
23402353
}
23412354

2355+
/// <summary>
2356+
/// Update or create a key/value pair in the player storage for the currently active player.
2357+
/// </summary>
2358+
/// <param name="key">Name of the key</param>
2359+
/// <param name="value">Value of the key</param>
2360+
/// <param name="onComplete">onComplete Action for handling the response of type LootLockerGetPersistentStoragResponse</param>
2361+
public static void UpdateOrCreateKeyValue(Dictionary<string,string> keyValuePairs, bool isPublic, Action<LootLockerGetPersistentStoragResponse> onComplete)
2362+
{
2363+
if (!CheckInitialized())
2364+
{
2365+
onComplete?.Invoke(LootLockerResponseFactory.SDKNotInitializedError<LootLockerGetPersistentStoragResponse>());
2366+
return;
2367+
}
2368+
LootLockerGetPersistentStorageRequest data = new LootLockerGetPersistentStorageRequest();
2369+
// Add all the key value pairs to the payload
2370+
foreach (var keyValuePair in keyValuePairs)
2371+
{
2372+
data.AddToPayload(new LootLockerPayload { key = keyValuePair.Key, value = keyValuePair.Value });
2373+
}
2374+
LootLockerAPIManager.UpdateOrCreateKeyValue(data, onComplete);
2375+
}
2376+
2377+
/// <summary>
2378+
/// Update or create a key/value pair in the player storage for the currently active player.
2379+
/// </summary>
2380+
/// <param name="key">Name of the key</param>
2381+
/// <param name="value">Value of the key</param>
2382+
/// <param name="isPublic">Is the key public?</param>
2383+
/// <param name="onComplete">onComplete Action for handling the response of type LootLockerGetPersistentStoragResponse</param>
2384+
public static void UpdateOrCreateKeyValue(string key, string value, bool isPublic, Action<LootLockerGetPersistentStoragResponse> onComplete)
2385+
{
2386+
if (!CheckInitialized())
2387+
{
2388+
onComplete?.Invoke(LootLockerResponseFactory.SDKNotInitializedError<LootLockerGetPersistentStoragResponse>());
2389+
return;
2390+
}
2391+
LootLockerGetPersistentStorageRequest data = new LootLockerGetPersistentStorageRequest();
2392+
data.AddToPayload(new LootLockerPayload { key = key, value = value, is_public = isPublic });
2393+
LootLockerAPIManager.UpdateOrCreateKeyValue(data, onComplete);
2394+
}
2395+
23422396
/// <summary>
23432397
/// Update or create multiple key/value pairs in the player storage for the currently active player.
23442398
/// </summary>

Runtime/Game/Requests/PersitentPlayerStorageRequest.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ public class LootLockerGetPersistentStoragResponse : LootLockerResponse
88
{
99
public virtual LootLockerPayload[] payload { get; set; }
1010
}
11+
public class LootLockerGetPersistentStoragResponseDictionary : LootLockerResponse
12+
{
13+
public virtual Dictionary<string, string> payload { get; set; }
14+
}
1115

1216
public class LootLockerGetPersistentStorageRequest
1317
{
@@ -47,6 +51,13 @@ public static void GetEntirePersistentStorage(Action<LootLockerGetPersistentStor
4751
LootLockerServerRequest.CallAPI(endPoint.endPoint, endPoint.httpMethod, null, onComplete: (serverResponse) => { LootLockerResponse.Deserialize(onComplete, serverResponse); });
4852
}
4953

54+
public static void GetEntirePersistentStorage(Action<LootLockerGetPersistentStoragResponseDictionary> onComplete)
55+
{
56+
EndPointClass endPoint = LootLockerEndPoints.getEntirePersistentStorage;
57+
58+
LootLockerServerRequest.CallAPI(endPoint.endPoint, endPoint.httpMethod, null, onComplete: (serverResponse) => { LootLockerResponse.Deserialize(onComplete, serverResponse); });
59+
}
60+
5061
public static void GetSingleKeyPersistentStorage(LootLockerGetRequest data, Action<LootLockerGetPersistentSingle> onComplete)
5162
{
5263
EndPointClass endPoint = LootLockerEndPoints.getSingleKeyFromPersitenctStorage;
@@ -56,7 +67,7 @@ public static void GetSingleKeyPersistentStorage(LootLockerGetRequest data, Acti
5667
LootLockerServerRequest.CallAPI(getVariable, endPoint.httpMethod, null, onComplete: (serverResponse) => { LootLockerResponse.Deserialize(onComplete, serverResponse); });
5768
}
5869

59-
public static void UpdateOrCreateKeyValue(LootLockerGetPersistentStorageRequest data, Action<LootLockerGetPersistentStoragResponse> onComplete)
70+
public static void UpdateOrCreateKeyValue(LootLockerGetPersistentStorageRequest data, Action<LootLockerGetPersistentStoragResponse> onComplete, bool isPublic = false)
6071
{
6172
if(data == null)
6273
{

0 commit comments

Comments
 (0)