Skip to content

Commit b67d118

Browse files
committed
fix: Fixes to metadata operations after testing
1 parent 1453631 commit b67d118

File tree

1 file changed

+42
-14
lines changed

1 file changed

+42
-14
lines changed

Runtime/Game/Requests/MetadataRequests.cs

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public class LootLockerMetadataEntry
9191
///</summary>
9292
public string[] tags { get; set; }
9393
/// <summary>
94-
/// The access level set for this metadata entry. Valid values are game_api.read and game_api.write, though no values are required.
94+
/// The access level set for this metadata entry. Valid values are game_api.read, game_api.write and player.read (only applicable for player metadata and means that the metadata entry is readable for players except the owner), though no values are required.
9595
/// Note that different sources can allow or disallow a subset of these values.
9696
/// </summary>
9797
public string[] access { get; set; }
@@ -282,7 +282,27 @@ public class LootLockerMetadataOperation : LootLockerMetadataEntry
282282
/// <summary>
283283
/// The type of action to perform for this metadata operation
284284
/// </summary>
285-
LootLockerMetadataActions action { get; set; }
285+
public LootLockerMetadataActions action { get; set; }
286+
}
287+
288+
/// <summary>
289+
/// </summary>
290+
public class LootLockerInternalMetadataOperationWithStringEnums : LootLockerMetadataOperation
291+
{
292+
public LootLockerInternalMetadataOperationWithStringEnums(LootLockerMetadataOperation other)
293+
{
294+
this.key = other.key;
295+
this.type = other.type.ToString().ToLower();
296+
this.value = other.value;
297+
this.tags = other.tags;
298+
this.access = other.access;
299+
this.action = other.action.ToString().ToLower();
300+
}
301+
302+
public new string type { get; set; }
303+
public new string action { get; set; }
304+
305+
286306
}
287307

288308
//==================================================
@@ -299,7 +319,9 @@ public class LootLockerGetMultisourceMetadataRequest
299319
public LootLockerMetadataSourceAndKeys[] sources { get; set; }
300320
}
301321

302-
public class LootLockerMetadataOperationRequest
322+
/// <summary>
323+
/// </summary>
324+
public class LootLockerInternalMetadataOperationRequest
303325
{
304326
/// <summary>
305327
/// Whether or not this operation is for metadata on the current player
@@ -316,8 +338,7 @@ public class LootLockerMetadataOperationRequest
316338
/// <summary>
317339
/// List of operations to perform for the given source
318340
/// </summary>
319-
public LootLockerMetadataOperation[] entries { get; set; }
320-
341+
public LootLockerInternalMetadataOperationWithStringEnums[] entries { get; set; }
321342
}
322343

323344
//==================================================
@@ -413,7 +434,12 @@ public static void ListMetadata(LootLockerMetadataSources Source, string SourceI
413434
LootLockerServerRequest.CallAPI(formattedEndpoint, LootLockerEndPoints.listMetadata.httpMethod, onComplete:
414435
(serverResponse) =>
415436
{
416-
LootLockerResponse.Deserialize<LootLockerListMetadataResponse>(onComplete, serverResponse);
437+
var parsedResponse = LootLockerResponse.Deserialize<LootLockerListMetadataResponse>(serverResponse);
438+
if(parsedResponse.entries == null)
439+
{
440+
parsedResponse.entries = new LootLockerMetadataEntry[] {};
441+
}
442+
onComplete?.Invoke(parsedResponse);
417443
});
418444
}
419445

@@ -455,22 +481,24 @@ public static void GetMultisourceMetadata(LootLockerMetadataSourceAndKeys[] Sour
455481

456482
public static void PerformMetadataOperations(LootLockerMetadataSources Source, string SourceID, List<LootLockerMetadataOperation> OperationsToPerform, Action<LootLockerMetadataOperationsResponse> onComplete)
457483
{
458-
if (Source == LootLockerMetadataSources.self)
459-
{
460-
SourceID = "self";
461-
}
462484
if (string.IsNullOrEmpty(SourceID) || OperationsToPerform.Count == 0)
463485
{
464486
onComplete?.Invoke(LootLockerResponseFactory.InputUnserializableError<LootLockerMetadataOperationsResponse>());
465487
return;
466488
}
467489

468-
LootLockerMetadataOperationRequest request = new LootLockerMetadataOperationRequest
490+
List<LootLockerInternalMetadataOperationWithStringEnums> entries = new List<LootLockerInternalMetadataOperationWithStringEnums>();
491+
foreach(var op in OperationsToPerform)
492+
{
493+
entries.Add(new LootLockerInternalMetadataOperationWithStringEnums(op));
494+
}
495+
496+
LootLockerInternalMetadataOperationRequest request = new LootLockerInternalMetadataOperationRequest
469497
{
470498
self = Source == LootLockerMetadataSources.self,
471-
source = Source.ToString().ToLower(),
472-
source_id = SourceID,
473-
entries = OperationsToPerform.ToArray()
499+
source = Source == LootLockerMetadataSources.self ? LootLockerMetadataSources.player.ToString().ToLower() : Source.ToString().ToLower(),
500+
source_id = Source == LootLockerMetadataSources.self ? string.IsNullOrEmpty(LootLockerConfig.current.playerULID) ? "00000000000000000000000000" : LootLockerConfig.current.playerULID : SourceID,
501+
entries = entries.ToArray()
474502
};
475503

476504
string json = LootLockerJson.SerializeObject(request);

0 commit comments

Comments
 (0)