Skip to content

Commit 137eae1

Browse files
Erik Bylundkirre-bylund
authored andcommitted
Refactored our entire API layer
The purpose was really only to remove the "FindAnyObjectByType" call. However, as I did, I refactored the entire class structure. - LootLockerServerManager was only used in LootLockerBaseServerAPI and LootLockerGameServerAPI to get access to StartCoroutine. That was it's only use. So I removed it and baked that functionality straight into those classes. - LootLockerGameServerAPI was a sub class of LootLockerBaseServerAPI in theory. But in reality they were so tightly coupled that it was a complete fake inheritance. Additionally, the only reason for the sub-class was a premature optimization to support f.ex. Server API and Admin API through different subclasses. But that functionality was instead built in Base through the SwitchURL method. - Additionally, I changed the interfaces to decouple the stack. Instead of the user calling SwitchURL, getting the instance, and more, I baked all that into the serverapi class and just provide a static "Send(...)" method.
1 parent 179e978 commit 137eae1

8 files changed

+192
-328
lines changed

Runtime/Client/LootLockerBaseServerAPI.cs renamed to Runtime/Client/LootLockerServerApi.cs

Lines changed: 182 additions & 86 deletions
Large diffs are not rendered by default.

Runtime/Client/LootLockerServerRequest.cs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ public struct LootLockerServerRequest
400400
public byte[] upload { get; set; }
401401
public string uploadName { get; set; }
402402
public string uploadType { get; set; }
403-
public LootLocker.LootLockerEnums.LootLockerCallerRole adminCall { get; set; }
403+
public LootLockerCallerRole callerRole { get; set; }
404404
public WWWForm form { get; set; }
405405

406406
/// <summary>
@@ -461,8 +461,6 @@ public static void CallAPI(string endPoint, LootLockerHTTPMethod httpMethod, str
461461
}
462462
}
463463

464-
LootLockerBaseServerAPI.I.SwitchURL(callerRole);
465-
466464
new LootLockerServerRequest(endPoint, httpMethod, body, headers, callerRole: callerRole).Send((response) => { onComplete?.Invoke(response); });
467465
}
468466

@@ -491,9 +489,7 @@ public static void CallDomainAuthAPI(string endPoint, LootLockerHTTPMethod httpM
491489
{
492490
headers.Add("is-development", "true");
493491
}
494-
495-
LootLockerBaseServerAPI.I.SwitchURL(LootLockerCallerRole.Base);
496-
492+
497493
new LootLockerServerRequest(endPoint, httpMethod, body, headers, callerRole: LootLockerCallerRole.Base).Send((response) => { onComplete?.Invoke(response); });
498494
}
499495

@@ -519,9 +515,7 @@ public static void UploadFile(string endPoint, LootLockerHTTPMethod httpMethod,
519515

520516
headers.Add(callerRole == LootLockerCallerRole.Admin ? "x-auth-token" : "x-session-token", LootLockerConfig.current.token);
521517
}
522-
523-
LootLockerBaseServerAPI.I.SwitchURL(callerRole);
524-
518+
525519
new LootLockerServerRequest(endPoint, httpMethod, file, fileName, fileContentType, body, headers, callerRole: callerRole).Send((response) => { onComplete?.Invoke(response); });
526520
}
527521

@@ -548,7 +542,7 @@ public LootLockerServerRequest(string endpoint, LootLockerHTTPMethod httpMethod
548542
this.jsonPayload = null;
549543
this.extraHeaders = extraHeaders != null && extraHeaders.Count == 0 ? null : extraHeaders; // Force extra headers to null if empty dictionary was supplied
550544
this.queryParams = null;
551-
this.adminCall = callerRole;
545+
this.callerRole = callerRole;
552546
this.form = new WWWForm();
553547

554548
foreach (var kvp in body)
@@ -579,7 +573,7 @@ public LootLockerServerRequest(string endpoint, LootLockerHTTPMethod httpMethod
579573
this.jsonPayload = null;
580574
this.extraHeaders = extraHeaders != null && extraHeaders.Count == 0 ? null : extraHeaders; // Force extra headers to null if empty dictionary was supplied
581575
this.queryParams = queryParams != null && queryParams.Count == 0 ? null : queryParams;
582-
this.adminCall = callerRole;
576+
this.callerRole = callerRole;
583577
bool isNonPayloadMethod = (this.httpMethod == LootLockerHTTPMethod.GET || this.httpMethod == LootLockerHTTPMethod.HEAD || this.httpMethod == LootLockerHTTPMethod.OPTIONS);
584578
this.form = null;
585579
if (this.payload != null && isNonPayloadMethod)
@@ -601,7 +595,7 @@ public LootLockerServerRequest(string endpoint, LootLockerHTTPMethod httpMethod
601595
this.payload = null;
602596
this.extraHeaders = extraHeaders != null && extraHeaders.Count == 0 ? null : extraHeaders; // Force extra headers to null if empty dictionary was supplied
603597
this.queryParams = queryParams != null && queryParams.Count == 0 ? null : queryParams;
604-
this.adminCall = callerRole;
598+
this.callerRole = callerRole;
605599
bool isNonPayloadMethod = (this.httpMethod == LootLockerHTTPMethod.GET || this.httpMethod == LootLockerHTTPMethod.HEAD || this.httpMethod == LootLockerHTTPMethod.OPTIONS);
606600
this.form = null;
607601
if (!string.IsNullOrEmpty(jsonPayload) && isNonPayloadMethod)
@@ -617,7 +611,7 @@ public LootLockerServerRequest(string endpoint, LootLockerHTTPMethod httpMethod
617611
/// </summary>
618612
public void Send(System.Action<LootLockerResponse> OnServerResponse)
619613
{
620-
LootLockerBaseServerAPI.I.SendRequest(this, (response) => { OnServerResponse?.Invoke(response); });
614+
LootLockerServerApi.SendRequest(this, (response) => { OnServerResponse?.Invoke(response); });
621615
}
622616
}
623617
}

Runtime/Game/LootLockerGameServerAPI.cs

Lines changed: 0 additions & 137 deletions
This file was deleted.

Runtime/Game/LootLockerGameServerAPI.cs.meta

Lines changed: 0 additions & 11 deletions
This file was deleted.

Runtime/Game/LootLockerSDKManager.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ public partial class LootLockerSDKManager
1818
[InitializeOnEnterPlayMode]
1919
static void OnEnterPlaymodeInEditor(EnterPlayModeOptions options)
2020
{
21-
LootLockerLogger.GetForLogLevel(LootLockerLogger.LogLevel.Verbose)("SDK is resetting for entering Playmode");
2221
initialized = false;
2322
}
2423
#endif
@@ -36,8 +35,7 @@ public static string GetCurrentPlatform()
3635
static bool initialized;
3736
static bool Init()
3837
{
39-
LootLockerLogger.GetForLogLevel(LootLockerLogger.LogLevel.Verbose)("SDK is Initializing");
40-
LootLockerServerManager.CheckInit();
38+
LootLockerServerApi.GetInstance();
4139
return LoadConfig();
4240
}
4341

@@ -50,8 +48,7 @@ static bool Init()
5048
/// <returns>True if initialized successfully, false otherwise</returns>
5149
public static bool Init(string apiKey, string gameVersion, string domainKey)
5250
{
53-
LootLockerLogger.GetForLogLevel()("SDK is Initializing");
54-
LootLockerServerManager.CheckInit();
51+
LootLockerServerApi.GetInstance();
5552
return LootLockerConfig.CreateNewSettings(apiKey, gameVersion, domainKey);
5653
}
5754

@@ -68,8 +65,7 @@ static bool LoadConfig()
6865
LootLockerLogger.GetForLogLevel(LootLockerLogger.LogLevel.Error)("API Key has not been set, set it in project settings or manually calling Init(string apiKey, string gameVersion, bool onDevelopmentMode, string domainKey)");
6966
return false;
7067
}
71-
72-
LootLockerLogger.GetForLogLevel(LootLockerLogger.LogLevel.Verbose)("SDK is Initialized");
68+
7369
initialized = true;
7470
return initialized;
7571
}

Runtime/Game/LootLockerServerManager.cs

Lines changed: 0 additions & 63 deletions
This file was deleted.

Runtime/Game/LootLockerServerManager.cs.meta

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)