diff --git a/.vscode/settings.json b/.vscode/settings.json index 5118349..071ec02 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -3,5 +3,7 @@ "files.exclude": { "**/*.meta": true }, - "dotnet.defaultSolution": "unity.sln" + "dotnet.defaultSolution": "unity.sln", + "editor.tabSize": 4, + "editor.indentSize": "tabSize" } \ No newline at end of file diff --git a/Assets/Samples/Playground/Scenes/Playground.unity b/Assets/Samples/Playground/Scenes/Playground.unity index 8e53d55..b7d7a37 100644 --- a/Assets/Samples/Playground/Scenes/Playground.unity +++ b/Assets/Samples/Playground/Scenes/Playground.unity @@ -157,6 +157,7 @@ RectTransform: - {fileID: 41042924} - {fileID: 1810825303} - {fileID: 1484174634} + - {fileID: 414252746} m_Father: {fileID: 2079681527} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 0} @@ -647,6 +648,85 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: eeab45c0be5c343c68f0df33c440919c, type: 3} m_Name: m_EditorClassIdentifier: +--- !u!1 &131549789 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 131549790} + - component: {fileID: 131549792} + - component: {fileID: 131549791} + m_Layer: 5 + m_Name: Text + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &131549790 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 131549789} + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 414252746} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0, y: 0} + m_AnchorMax: {x: 1, y: 1} + m_AnchoredPosition: {x: 0, y: 0} + m_SizeDelta: {x: 0, y: 0} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!114 &131549791 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 131549789} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 5f7201a12d95ffc409449d95f23cf332, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Material: {fileID: 0} + m_Color: {r: 0.19607843, g: 0.19607843, b: 0.19607843, a: 1} + m_RaycastTarget: 1 + m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} + m_Maskable: 1 + m_OnCullStateChanged: + m_PersistentCalls: + m_Calls: [] + m_FontData: + m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0} + m_FontSize: 14 + m_FontStyle: 0 + m_BestFit: 0 + m_MinSize: 10 + m_MaxSize: 40 + m_Alignment: 4 + m_AlignByGeometry: 0 + m_RichText: 1 + m_HorizontalOverflow: 0 + m_VerticalOverflow: 0 + m_LineSpacing: 1 + m_Text: Get group +--- !u!222 &131549792 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 131549789} + m_CullTransparentMesh: 1 --- !u!1 &324014309 GameObject: m_ObjectHideFlags: 0 @@ -1019,6 +1099,153 @@ CanvasRenderer: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 376592790} m_CullTransparentMesh: 1 +--- !u!1 &414252745 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 414252746} + - component: {fileID: 414252750} + - component: {fileID: 414252749} + - component: {fileID: 414252748} + - component: {fileID: 414252751} + m_Layer: 5 + m_Name: Get group + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &414252746 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 414252745} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: + - {fileID: 131549790} + m_Father: {fileID: 13014977} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0, y: 0} + m_AnchorMax: {x: 0, y: 0} + m_AnchoredPosition: {x: 0, y: 0} + m_SizeDelta: {x: 0, y: 30} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!114 &414252748 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 414252745} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 4e29b1a8efbd4b44bb3f3716e73f07ff, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Navigation: + m_Mode: 3 + m_WrapAround: 0 + m_SelectOnUp: {fileID: 0} + m_SelectOnDown: {fileID: 0} + m_SelectOnLeft: {fileID: 0} + m_SelectOnRight: {fileID: 0} + m_Transition: 1 + m_Colors: + m_NormalColor: {r: 1, g: 1, b: 1, a: 1} + m_HighlightedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1} + m_PressedColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 1} + m_SelectedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1} + m_DisabledColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 0.5019608} + m_ColorMultiplier: 1 + m_FadeDuration: 0.1 + m_SpriteState: + m_HighlightedSprite: {fileID: 0} + m_PressedSprite: {fileID: 0} + m_SelectedSprite: {fileID: 0} + m_DisabledSprite: {fileID: 0} + m_AnimationTriggers: + m_NormalTrigger: Normal + m_HighlightedTrigger: Highlighted + m_PressedTrigger: Pressed + m_SelectedTrigger: Selected + m_DisabledTrigger: Disabled + m_Interactable: 1 + m_TargetGraphic: {fileID: 414252749} + m_OnClick: + m_PersistentCalls: + m_Calls: + - m_Target: {fileID: 414252751} + m_TargetAssemblyTypeName: GetGroup, Assembly-CSharp + m_MethodName: OnButtonClick + m_Mode: 1 + m_Arguments: + m_ObjectArgument: {fileID: 0} + m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine + m_IntArgument: 0 + m_FloatArgument: 0 + m_StringArgument: + m_BoolArgument: 0 + m_CallState: 2 +--- !u!114 &414252749 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 414252745} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Material: {fileID: 0} + m_Color: {r: 1, g: 1, b: 1, a: 1} + m_RaycastTarget: 1 + m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} + m_Maskable: 1 + m_OnCullStateChanged: + m_PersistentCalls: + m_Calls: [] + m_Sprite: {fileID: 10905, guid: 0000000000000000f000000000000000, type: 0} + m_Type: 1 + m_PreserveAspect: 0 + m_FillCenter: 1 + m_FillMethod: 4 + m_FillAmount: 1 + m_FillClockwise: 1 + m_FillOrigin: 0 + m_UseSpriteMesh: 0 + m_PixelsPerUnitMultiplier: 1 +--- !u!222 &414252750 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 414252745} + m_CullTransparentMesh: 1 +--- !u!114 &414252751 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 414252745} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 3ac5ee86ce1ba48ca84820db7452e975, type: 3} + m_Name: + m_EditorClassIdentifier: + groupId: --- !u!1 &496913033 GameObject: m_ObjectHideFlags: 0 @@ -1476,7 +1703,7 @@ MonoBehaviour: m_HorizontalOverflow: 0 m_VerticalOverflow: 0 m_LineSpacing: 1 - m_Text: Set Health + m_Text: Set health --- !u!222 &520760485 CanvasRenderer: m_ObjectHideFlags: 0 @@ -3101,7 +3328,7 @@ GameObject: - component: {fileID: 1484174636} - component: {fileID: 1484174635} m_Layer: 5 - m_Name: Delete Prop + m_Name: Delete prop m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 @@ -3841,7 +4068,7 @@ MonoBehaviour: m_HorizontalOverflow: 0 m_VerticalOverflow: 0 m_LineSpacing: 1 - m_Text: Delete Health + m_Text: Delete health --- !u!222 &1720564335 CanvasRenderer: m_ObjectHideFlags: 0 @@ -3967,7 +4194,7 @@ GameObject: - component: {fileID: 1810825305} - component: {fileID: 1810825304} m_Layer: 5 - m_Name: Set Prop + m_Name: Set prop m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 diff --git a/Assets/Samples/Playground/Scripts/Players/GetGroup.cs b/Assets/Samples/Playground/Scripts/Players/GetGroup.cs new file mode 100644 index 0000000..c0acacf --- /dev/null +++ b/Assets/Samples/Playground/Scripts/Players/GetGroup.cs @@ -0,0 +1,28 @@ +using System; +using TaloGameServices; +using UnityEngine; + +public class GetGroup : MonoBehaviour +{ + public string groupId; + + public async void OnButtonClick() + { + if (string.IsNullOrEmpty(groupId)) + { + ResponseMessage.SetText("groupId not set on 'Get group' button"); + } + else + { + try + { + var group = await Talo.PlayerGroups.Get(groupId); + ResponseMessage.SetText($"{group.name} has {group.count} player(s)"); + } + catch (Exception e) + { + ResponseMessage.SetText(e.Message); + } + } + } +} diff --git a/Assets/Samples/Playground/Scripts/Players/GetGroup.cs.meta b/Assets/Samples/Playground/Scripts/Players/GetGroup.cs.meta new file mode 100644 index 0000000..b046355 --- /dev/null +++ b/Assets/Samples/Playground/Scripts/Players/GetGroup.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 3ac5ee86ce1ba48ca84820db7452e975 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/com.trytalo.talo/Runtime/APIs/PlayerGroupsAPI.cs b/Packages/com.trytalo.talo/Runtime/APIs/PlayerGroupsAPI.cs new file mode 100644 index 0000000..a7ae099 --- /dev/null +++ b/Packages/com.trytalo.talo/Runtime/APIs/PlayerGroupsAPI.cs @@ -0,0 +1,20 @@ +using System; +using System.Threading.Tasks; +using UnityEngine; + +namespace TaloGameServices +{ + public class PlayerGroupsAPI : BaseAPI + { + public PlayerGroupsAPI() : base("v1/player-groups") { } + + public async Task Get(string groupId) + { + var uri = new Uri($"{baseUrl}/{groupId}"); + var json = await Call(uri, "GET"); + + var res = JsonUtility.FromJson(json); + return res.group; + } + } +} diff --git a/Packages/com.trytalo.talo/Runtime/APIs/PlayerGroupsAPI.cs.meta b/Packages/com.trytalo.talo/Runtime/APIs/PlayerGroupsAPI.cs.meta new file mode 100644 index 0000000..822672e --- /dev/null +++ b/Packages/com.trytalo.talo/Runtime/APIs/PlayerGroupsAPI.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c064731cebf0245119a22aecb48bd8d5 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/com.trytalo.talo/Runtime/Entities/Group.cs b/Packages/com.trytalo.talo/Runtime/Entities/Group.cs index d469ca6..c69212c 100644 --- a/Packages/com.trytalo.talo/Runtime/Entities/Group.cs +++ b/Packages/com.trytalo.talo/Runtime/Entities/Group.cs @@ -1,5 +1,16 @@ -[System.Serializable] -public class Group +namespace TaloGameServices { - public string id, name; + [System.Serializable] + public class Group + { + public string id; + public string name; + public string description; + public object[] rules; + public string ruleMode; + public bool membersVisible; + public int count; + public Player[] members; + public string updatedAt; + } } diff --git a/Packages/com.trytalo.talo/Runtime/Entities/Group.cs.meta b/Packages/com.trytalo.talo/Runtime/Entities/Group.cs.meta index 37d59a4..e27ca1c 100644 --- a/Packages/com.trytalo.talo/Runtime/Entities/Group.cs.meta +++ b/Packages/com.trytalo.talo/Runtime/Entities/Group.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 7953e59f777b44f7c8da7ce0fc9e52dd +guid: 61551ce2d477449e8abede7651239921 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Packages/com.trytalo.talo/Runtime/Entities/GroupStub.cs b/Packages/com.trytalo.talo/Runtime/Entities/GroupStub.cs new file mode 100644 index 0000000..dab375a --- /dev/null +++ b/Packages/com.trytalo.talo/Runtime/Entities/GroupStub.cs @@ -0,0 +1,8 @@ +namespace TaloGameServices +{ + [System.Serializable] + public class GroupStub + { + public string id, name; + } +} diff --git a/Packages/com.trytalo.talo/Runtime/Entities/GroupStub.cs.meta b/Packages/com.trytalo.talo/Runtime/Entities/GroupStub.cs.meta new file mode 100644 index 0000000..37d59a4 --- /dev/null +++ b/Packages/com.trytalo.talo/Runtime/Entities/GroupStub.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 7953e59f777b44f7c8da7ce0fc9e52dd +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/com.trytalo.talo/Runtime/Entities/LiveConfig.cs b/Packages/com.trytalo.talo/Runtime/Entities/LiveConfig.cs index 1664b8b..66dd5f6 100644 --- a/Packages/com.trytalo.talo/Runtime/Entities/LiveConfig.cs +++ b/Packages/com.trytalo.talo/Runtime/Entities/LiveConfig.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Linq; namespace TaloGameServices @@ -17,7 +17,7 @@ public LiveConfig(Prop[] props) try { Prop prop = props.First((prop) => prop.key == key); - return ((T)Convert.ChangeType(prop.value, typeof(T))); + return (T)Convert.ChangeType(prop.value, typeof(T)); } catch (Exception) { diff --git a/Packages/com.trytalo.talo/Runtime/Entities/Player.cs b/Packages/com.trytalo.talo/Runtime/Entities/Player.cs index 21d16ca..4bb66c8 100644 --- a/Packages/com.trytalo.talo/Runtime/Entities/Player.cs +++ b/Packages/com.trytalo.talo/Runtime/Entities/Player.cs @@ -9,7 +9,7 @@ namespace TaloGameServices public class Player: EntityWithProps { public string id; - public Group[] groups; + public GroupStub[] groups; public override string ToString() { diff --git a/Packages/com.trytalo.talo/Runtime/Responses/PlayerGroupsGetResponse.cs b/Packages/com.trytalo.talo/Runtime/Responses/PlayerGroupsGetResponse.cs new file mode 100644 index 0000000..22ec3ef --- /dev/null +++ b/Packages/com.trytalo.talo/Runtime/Responses/PlayerGroupsGetResponse.cs @@ -0,0 +1,8 @@ +namespace TaloGameServices +{ + [System.Serializable] + public class PlayerGroupsGetResponse + { + public Group group; + } +} diff --git a/Packages/com.trytalo.talo/Runtime/Responses/PlayerGroupsGetResponse.cs.meta b/Packages/com.trytalo.talo/Runtime/Responses/PlayerGroupsGetResponse.cs.meta new file mode 100644 index 0000000..84bc743 --- /dev/null +++ b/Packages/com.trytalo.talo/Runtime/Responses/PlayerGroupsGetResponse.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: d6e400d1848ed426c8507badd1e773ba +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/com.trytalo.talo/Runtime/Talo.cs b/Packages/com.trytalo.talo/Runtime/Talo.cs index 67f022b..2da7c15 100644 --- a/Packages/com.trytalo.talo/Runtime/Talo.cs +++ b/Packages/com.trytalo.talo/Runtime/Talo.cs @@ -20,6 +20,7 @@ public class Talo internal static FeedbackAPI _feedback; internal static PlayerAuthAPI _playerAuth; internal static HealthCheckAPI _healthCheck; + internal static PlayerGroupsAPI _playerGroups; private static PlayerAlias _currentAlias; @@ -106,6 +107,11 @@ public static HealthCheckAPI HealthCheck get => _healthCheck; } + public static PlayerGroupsAPI PlayerGroups + { + get => _playerGroups; + } + static Talo() { TaloManager tm; @@ -139,6 +145,7 @@ static Talo() _feedback = new FeedbackAPI(); _playerAuth = new PlayerAuthAPI(); _healthCheck = new HealthCheckAPI(); + _playerGroups = new PlayerGroupsAPI(); tm.OnReady(); } diff --git a/Packages/com.trytalo.talo/Runtime/Utils/FileHandlers/CryptoFileHandler.cs b/Packages/com.trytalo.talo/Runtime/Utils/FileHandlers/CryptoFileHandler.cs index f031018..d9930dd 100644 --- a/Packages/com.trytalo.talo/Runtime/Utils/FileHandlers/CryptoFileHandler.cs +++ b/Packages/com.trytalo.talo/Runtime/Utils/FileHandlers/CryptoFileHandler.cs @@ -1,14 +1,17 @@ using System.IO; -public class CryptoFileHandler : IFileHandler +namespace TaloGameServices { - public string ReadContent(string path) + public class CryptoFileHandler : IFileHandler { - return File.ReadAllText(path); - } + public string ReadContent(string path) + { + return File.ReadAllText(path); + } - public void WriteContent(string path, string content) - { - File.WriteAllText(path, content); + public void WriteContent(string path, string content) + { + File.WriteAllText(path, content); + } } } diff --git a/Packages/com.trytalo.talo/Runtime/Utils/FileHandlers/CryptoTestFileHandler.cs b/Packages/com.trytalo.talo/Runtime/Utils/FileHandlers/CryptoTestFileHandler.cs index 695286e..6f87523 100644 --- a/Packages/com.trytalo.talo/Runtime/Utils/FileHandlers/CryptoTestFileHandler.cs +++ b/Packages/com.trytalo.talo/Runtime/Utils/FileHandlers/CryptoTestFileHandler.cs @@ -1,18 +1,21 @@ using System.Collections.Generic; -using UnityEngine; -internal class CryptoTestFileHandler : IFileHandler +namespace TaloGameServices { - private Dictionary files = new (); - - public string ReadContent(string path) + internal class CryptoTestFileHandler : IFileHandler { - if (!files.ContainsKey(path)) return ""; - return files[path]; - } + private Dictionary files = new (); - public void WriteContent(string path, string content) - { - files[path] = content; + public string ReadContent(string path) + { + if (!files.ContainsKey(path)) return ""; + return files[path]; + } + + public void WriteContent(string path, string content) + { + files[path] = content; + } } + } diff --git a/Packages/com.trytalo.talo/Runtime/Utils/FileHandlers/IFileHandler.cs b/Packages/com.trytalo.talo/Runtime/Utils/FileHandlers/IFileHandler.cs index 67dd53d..1a314f9 100644 --- a/Packages/com.trytalo.talo/Runtime/Utils/FileHandlers/IFileHandler.cs +++ b/Packages/com.trytalo.talo/Runtime/Utils/FileHandlers/IFileHandler.cs @@ -1,14 +1,17 @@ using System; -internal interface IFileHandler +namespace TaloGameServices { - public T ReadContent(string path) + internal interface IFileHandler { - throw new NotImplementedException(); - } + public T ReadContent(string path) + { + throw new NotImplementedException(); + } - public void WriteContent(string path, T content) - { - throw new NotImplementedException(); + public void WriteContent(string path, T content) + { + throw new NotImplementedException(); + } } } diff --git a/Packages/com.trytalo.talo/Runtime/Utils/FileHandlers/SavesFileHandler.cs b/Packages/com.trytalo.talo/Runtime/Utils/FileHandlers/SavesFileHandler.cs index d757073..094ea5e 100644 --- a/Packages/com.trytalo.talo/Runtime/Utils/FileHandlers/SavesFileHandler.cs +++ b/Packages/com.trytalo.talo/Runtime/Utils/FileHandlers/SavesFileHandler.cs @@ -1,17 +1,19 @@ using System.IO; -using TaloGameServices; using UnityEngine; -public class SavesFileHandler : IFileHandler +namespace TaloGameServices { - public OfflineSavesContent ReadContent(string path) + public class SavesFileHandler : IFileHandler { - if (!File.Exists(path)) return null; - return JsonUtility.FromJson(Talo.Crypto.ReadFileContent(path)); - } + public OfflineSavesContent ReadContent(string path) + { + if (!File.Exists(path)) return null; + return JsonUtility.FromJson(Talo.Crypto.ReadFileContent(path)); + } - public void WriteContent(string path, OfflineSavesContent content) - { - Talo.Crypto.WriteFileContent(path, JsonUtility.ToJson(content)); + public void WriteContent(string path, OfflineSavesContent content) + { + Talo.Crypto.WriteFileContent(path, JsonUtility.ToJson(content)); + } } } diff --git a/Packages/com.trytalo.talo/Runtime/Utils/FileHandlers/SavesTestFileHandler.cs b/Packages/com.trytalo.talo/Runtime/Utils/FileHandlers/SavesTestFileHandler.cs index 8821f94..30f55f1 100644 --- a/Packages/com.trytalo.talo/Runtime/Utils/FileHandlers/SavesTestFileHandler.cs +++ b/Packages/com.trytalo.talo/Runtime/Utils/FileHandlers/SavesTestFileHandler.cs @@ -1,18 +1,20 @@ -using TaloGameServices; -using UnityEngine; +using UnityEngine; -internal class SavesTestFileHandler : IFileHandler +namespace TaloGameServices { - private string content; - - public OfflineSavesContent ReadContent(string path) + internal class SavesTestFileHandler : IFileHandler { - if (content == default) return null; - return JsonUtility.FromJson(content); - } + private string content; - public void WriteContent(string path, OfflineSavesContent content) - { - this.content = JsonUtility.ToJson(content); + public OfflineSavesContent ReadContent(string path) + { + if (content == default) return null; + return JsonUtility.FromJson(content); + } + + public void WriteContent(string path, OfflineSavesContent content) + { + this.content = JsonUtility.ToJson(content); + } } } diff --git a/Packages/com.trytalo.talo/Runtime/Utils/RequestMock.cs b/Packages/com.trytalo.talo/Runtime/Utils/RequestMock.cs index 066bcfe..7244f91 100644 --- a/Packages/com.trytalo.talo/Runtime/Utils/RequestMock.cs +++ b/Packages/com.trytalo.talo/Runtime/Utils/RequestMock.cs @@ -2,80 +2,83 @@ using System.Collections.Generic; using System.Linq; -internal class RequestMock +namespace TaloGameServices { - private struct RequestHandler + internal class RequestMock { - public Uri uri; - public string method, response; - public long status; - } + private struct RequestHandler + { + public Uri uri; + public string method, response; + public long status; + } - private static List _permanentHandlers = new List(); - private static List _oneTimeHandlers = new List(); - private static bool _offline; + private static List _permanentHandlers = new List(); + private static List _oneTimeHandlers = new List(); + private static bool _offline; - public static bool Offline - { - get => _offline; - set => _offline = value; - } - - public static void Reset() - { - _permanentHandlers.Clear(); - _oneTimeHandlers.Clear(); - } + public static bool Offline + { + get => _offline; + set => _offline = value; + } - private static void AddToHandlerList(List list, Uri uri, string method, string response, long status) - { - list.Add(new RequestHandler + public static void Reset() { - uri = uri, - method = method, - response = response, - status = status - }); - } + _permanentHandlers.Clear(); + _oneTimeHandlers.Clear(); + } - public static void Reply(Uri uri, string method, string response = "", long status = 200) - { - AddToHandlerList(_permanentHandlers, uri, method, response, status); - } + private static void AddToHandlerList(List list, Uri uri, string method, string response, long status) + { + list.Add(new RequestHandler + { + uri = uri, + method = method, + response = response, + status = status + }); + } - public static void ReplyOnce(Uri uri, string method, string response = "", long status = 200) - { - AddToHandlerList(_oneTimeHandlers, uri, method, response, status); - } + public static void Reply(Uri uri, string method, string response = "", long status = 200) + { + AddToHandlerList(_permanentHandlers, uri, method, response, status); + } - private static RequestHandler? FindInHandlerList(List list, Uri uri, string method) - { - return list - .Where((m) => m.uri == uri && m.method == method) - .Cast() - .FirstOrDefault(); - } + public static void ReplyOnce(Uri uri, string method, string response = "", long status = 200) + { + AddToHandlerList(_oneTimeHandlers, uri, method, response, status); + } - public static string HandleCall(Uri uri, string method) - { - var handler = FindInHandlerList(_permanentHandlers, uri, method); - if (handler != null) + private static RequestHandler? FindInHandlerList(List list, Uri uri, string method) { - var value = handler.GetValueOrDefault(); - return value.response; + return list + .Where((m) => m.uri == uri && m.method == method) + .Cast() + .FirstOrDefault(); } - else + + public static string HandleCall(Uri uri, string method) { - handler = FindInHandlerList(_oneTimeHandlers, uri, method); + var handler = FindInHandlerList(_permanentHandlers, uri, method); if (handler != null) { var value = handler.GetValueOrDefault(); - _oneTimeHandlers.Remove(value); return value.response; } else { - throw new Exception($"Request handler not set for {method} {uri}"); + handler = FindInHandlerList(_oneTimeHandlers, uri, method); + if (handler != null) + { + var value = handler.GetValueOrDefault(); + _oneTimeHandlers.Remove(value); + return value.response; + } + else + { + throw new Exception($"Request handler not set for {method} {uri}"); + } } } } diff --git a/Packages/com.trytalo.talo/Tests/Runtime/LiveConfig/GetPropTest.cs b/Packages/com.trytalo.talo/Tests/Runtime/LiveConfig/GetPropTest.cs index c6e753a..19ab055 100644 --- a/Packages/com.trytalo.talo/Tests/Runtime/LiveConfig/GetPropTest.cs +++ b/Packages/com.trytalo.talo/Tests/Runtime/LiveConfig/GetPropTest.cs @@ -1,59 +1,59 @@ using System.Collections; using NUnit.Framework; using UnityEngine.TestTools; -using TaloGameServices; -using UnityEngine; using System; -public class GetPropTest -{ - [UnityTest] - public IEnumerator GetProp_WithALiveConfigThatHasValues_ReturnsCorrectValue() +namespace TaloGameServices.Test { + internal class GetPropTest { - var config = new LiveConfig(new[] { new Prop(("gameName", "Crawle")), new Prop(("halloweenEventEnabled", "True")) }); + [UnityTest] + public IEnumerator GetProp_WithALiveConfigThatHasValues_ReturnsCorrectValue() + { + var config = new LiveConfig(new[] { new Prop(("gameName", "Crawle")), new Prop(("halloweenEventEnabled", "True")) }); - Assert.AreEqual("Crawle", config.GetProp("gameName", "No name")); + Assert.AreEqual("Crawle", config.GetProp("gameName", "No name")); - yield return null; - } + yield return null; + } - [UnityTest] - public IEnumerator GetProp_WithAnEmptyList_ReturnsFallback() - { - var config = new LiveConfig(Array.Empty()); + [UnityTest] + public IEnumerator GetProp_WithAnEmptyList_ReturnsFallback() + { + var config = new LiveConfig(Array.Empty()); - Assert.AreEqual("No name", config.GetProp("gameName", "No name")); + Assert.AreEqual("No name", config.GetProp("gameName", "No name")); - yield return null; - } + yield return null; + } - [UnityTest] - public IEnumerator GetProp_WithNoMatchingValuesInList_ReturnsFallback() - { - var config = new LiveConfig(new[] { new Prop(("gameName", "Crawle")), new Prop(("halloweenEventEnabled", "True")) }); + [UnityTest] + public IEnumerator GetProp_WithNoMatchingValuesInList_ReturnsFallback() + { + var config = new LiveConfig(new[] { new Prop(("gameName", "Crawle")), new Prop(("halloweenEventEnabled", "True")) }); - Assert.AreEqual("1.0", config.GetProp("latestGameVersion", "1.0")); + Assert.AreEqual("1.0", config.GetProp("latestGameVersion", "1.0")); - yield return null; - } + yield return null; + } - [UnityTest] - public IEnumerator GetProp_WhenConvertingTypeToBoolean_ReturnsCorrectValue() - { - var config = new LiveConfig(new[] { new Prop(("halloweenEventEnabled", "True")) }); + [UnityTest] + public IEnumerator GetProp_WhenConvertingTypeToBoolean_ReturnsCorrectValue() + { + var config = new LiveConfig(new[] { new Prop(("halloweenEventEnabled", "True")) }); - Assert.AreEqual(true, config.GetProp("halloweenEventEnabled", false)); + Assert.AreEqual(true, config.GetProp("halloweenEventEnabled", false)); - yield return null; - } + yield return null; + } - [UnityTest] - public IEnumerator GetProp_WhenConvertingTypeToNumber_ReturnsCorrectValue() - { - var config = new LiveConfig(new[] { new Prop(("maxLevel", "60")) }); + [UnityTest] + public IEnumerator GetProp_WhenConvertingTypeToNumber_ReturnsCorrectValue() + { + var config = new LiveConfig(new[] { new Prop(("maxLevel", "60")) }); - Assert.AreEqual(60, config.GetProp("maxLevel", 0)); + Assert.AreEqual(60, config.GetProp("maxLevel", 0)); - yield return null; + yield return null; + } } } diff --git a/Packages/com.trytalo.talo/Tests/Runtime/SavesAPI/ChooseSaveTest.cs b/Packages/com.trytalo.talo/Tests/Runtime/SavesAPI/ChooseSaveTest.cs index 83c0c88..477bf3c 100644 --- a/Packages/com.trytalo.talo/Tests/Runtime/SavesAPI/ChooseSaveTest.cs +++ b/Packages/com.trytalo.talo/Tests/Runtime/SavesAPI/ChooseSaveTest.cs @@ -1,71 +1,73 @@ using System.Collections; using NUnit.Framework; using UnityEngine.TestTools; -using TaloGameServices; using UnityEngine; using System.Collections.Generic; -internal class LoadingCompletedEvent +namespace TaloGameServices.Test { - public bool wasInvoked; - - public void Invoke() + internal class LoadingCompletedEvent { - wasInvoked = true; + public bool wasInvoked; + + public void Invoke() + { + wasInvoked = true; + } } -} -public class ChooseSaveTest -{ - [OneTimeSetUp] - public void SetUp() + internal class ChooseSaveTest { - var tm = new GameObject().AddComponent(); - tm.settings = ScriptableObject.CreateInstance(); + [OneTimeSetUp] + public void SetUp() + { + var tm = new GameObject().AddComponent(); + tm.settings = ScriptableObject.CreateInstance(); - Talo.CurrentAlias = new PlayerAlias() { - player = new Player() { - id = "uuid" - } - }; - } + Talo.CurrentAlias = new PlayerAlias() { + player = new Player() { + id = "uuid" + } + }; + } - [UnityTest] - public IEnumerator ChooseSave_LoadsLoadableData() - { - var api = new SavesAPI(); - Talo._saves = api; + [UnityTest] + public IEnumerator ChooseSave_LoadsLoadableData() + { + var api = new SavesAPI(); + Talo._saves = api; - Vector3 loadable1Pos, loadable2Pos; + Vector3 loadable1Pos, loadable2Pos; - var loadable1 = new GameObject("First Loadable").AddComponent(); - loadable1.transform.position = loadable1Pos = new Vector3(88, -20, 6); - var loadable2 = new GameObject("Second Loadable").AddComponent(); - loadable2.transform.position = loadable2Pos = new Vector3(-4, 105, 71); + var loadable1 = new GameObject("First Loadable").AddComponent(); + loadable1.transform.position = loadable1Pos = new Vector3(88, -20, 6); + var loadable2 = new GameObject("Second Loadable").AddComponent(); + loadable2.transform.position = loadable2Pos = new Vector3(-4, 105, 71); - var loadables = new List(); - loadables.Add(new LoadableData(loadable1)); - loadables.Add(new LoadableData(loadable2)); + var loadables = new List(); + loadables.Add(new LoadableData(loadable1)); + loadables.Add(new LoadableData(loadable2)); - api._allSaves.Add(new GameSave() { - id = 1, - name = "Save", - content = JsonUtility.ToJson(new SaveContent(loadables)) - }); + api._allSaves.Add(new GameSave() { + id = 1, + name = "Save", + content = JsonUtility.ToJson(new SaveContent(loadables)) + }); - loadable1.transform.position = Vector3.zero; - loadable2.transform.position = Vector3.zero; + loadable1.transform.position = Vector3.zero; + loadable2.transform.position = Vector3.zero; - var eventMock = new LoadingCompletedEvent(); - api.OnSaveLoadingCompleted += eventMock.Invoke; + var eventMock = new LoadingCompletedEvent(); + api.OnSaveLoadingCompleted += eventMock.Invoke; - api.ChooseSave(api.All[0].id); + api.ChooseSave(api.All[0].id); - Assert.AreEqual(loadable1.transform.position, loadable1Pos); - Assert.AreEqual(loadable2.transform.position, loadable2Pos); + Assert.AreEqual(loadable1.transform.position, loadable1Pos); + Assert.AreEqual(loadable2.transform.position, loadable2Pos); - api.OnSaveLoadingCompleted -= eventMock.Invoke; + api.OnSaveLoadingCompleted -= eventMock.Invoke; - yield return null; + yield return null; + } } } diff --git a/Packages/com.trytalo.talo/Tests/Runtime/SavesAPI/CreateSaveTest.cs b/Packages/com.trytalo.talo/Tests/Runtime/SavesAPI/CreateSaveTest.cs index fda2208..31151c2 100644 --- a/Packages/com.trytalo.talo/Tests/Runtime/SavesAPI/CreateSaveTest.cs +++ b/Packages/com.trytalo.talo/Tests/Runtime/SavesAPI/CreateSaveTest.cs @@ -1,101 +1,103 @@ using System.Collections; using NUnit.Framework; using UnityEngine.TestTools; -using TaloGameServices; using UnityEngine; -internal class ChosenEventMock +namespace TaloGameServices.Test { - public GameSave chosenSave; - - public void Invoke(GameSave chosenSave) + internal class ChosenEventMock { - this.chosenSave = chosenSave; - } -} + public GameSave chosenSave; -public class CreateSaveTest -{ - [OneTimeSetUp] - public void SetUp() - { - var tm = new GameObject().AddComponent(); - tm.settings = ScriptableObject.CreateInstance(); - - Talo.CurrentAlias = new PlayerAlias() { - player = new Player() { - id = "uuid" - } - }; + public void Invoke(GameSave chosenSave) + { + this.chosenSave = chosenSave; + } } - [TearDown] - public void TearDown() + internal class CreateSaveTest { - RequestMock.Offline = false; - } + [OneTimeSetUp] + public void SetUp() + { + var tm = new GameObject().AddComponent(); + tm.settings = ScriptableObject.CreateInstance(); + + Talo.CurrentAlias = new PlayerAlias() { + player = new Player() { + id = "uuid" + } + }; + } + + [TearDown] + public void TearDown() + { + RequestMock.Offline = false; + } - [UnityTest] - public IEnumerator CreateSave_InOnlineMode_AddsToArrayOfSaves() - { - var api = new SavesAPI(); - Talo._saves = api; + [UnityTest] + public IEnumerator CreateSave_InOnlineMode_AddsToArrayOfSaves() + { + var api = new SavesAPI(); + Talo._saves = api; - api._allSaves.Add(new GameSave() { name = "Existing Online Save" }); - api.WriteOfflineSavesContent(new OfflineSavesContent(api._allSaves.ToArray())); + api._allSaves.Add(new GameSave() { name = "Existing Online Save" }); + api.WriteOfflineSavesContent(new OfflineSavesContent(api._allSaves.ToArray())); - var eventMock = new ChosenEventMock(); - api.OnSaveChosen += eventMock.Invoke; + var eventMock = new ChosenEventMock(); + api.OnSaveChosen += eventMock.Invoke; - RequestMock.ReplyOnce(api.GetUri(), "POST", JsonUtility.ToJson(new SavesPostResponse - { - save = new GameSave { id = 1, name = "New Online Save", content = "", updatedAt = "2022-10-30T21:23:30.977Z" } - })); - _ = api.CreateSave("New Online Save"); + RequestMock.ReplyOnce(api.GetUri(), "POST", JsonUtility.ToJson(new SavesPostResponse + { + save = new GameSave { id = 1, name = "New Online Save", content = "", updatedAt = "2022-10-30T21:23:30.977Z" } + })); + _ = api.CreateSave("New Online Save"); - Assert.AreEqual(2, api.All.Length); - Assert.AreEqual("Existing Online Save", api.All[0].name); - Assert.AreEqual("New Online Save", api.All[1].name); + Assert.AreEqual(2, api.All.Length); + Assert.AreEqual("Existing Online Save", api.All[0].name); + Assert.AreEqual("New Online Save", api.All[1].name); - Assert.AreEqual(2, api.GetOfflineSavesContent().saves.Length); - Assert.AreEqual("Existing Online Save", api.GetOfflineSavesContent().saves[0].name); - Assert.AreEqual("New Online Save", api.GetOfflineSavesContent().saves[1].name); + Assert.AreEqual(2, api.GetOfflineSavesContent().saves.Length); + Assert.AreEqual("Existing Online Save", api.GetOfflineSavesContent().saves[0].name); + Assert.AreEqual("New Online Save", api.GetOfflineSavesContent().saves[1].name); - Assert.AreEqual(1, api.Current.id); - Assert.Null(eventMock.chosenSave); // should not invoke the OnSaveChosen event - api.OnSaveChosen -= eventMock.Invoke; + Assert.AreEqual(1, api.Current.id); + Assert.Null(eventMock.chosenSave); // should not invoke the OnSaveChosen event + api.OnSaveChosen -= eventMock.Invoke; - yield return null; - } + yield return null; + } - [UnityTest] - public IEnumerator CreateSave_InOfflineMode_AddsToArrayOfSaves() - { - RequestMock.Offline = true; + [UnityTest] + public IEnumerator CreateSave_InOfflineMode_AddsToArrayOfSaves() + { + RequestMock.Offline = true; - var api = new SavesAPI(); - Talo._saves = api; + var api = new SavesAPI(); + Talo._saves = api; - api._allSaves.Add(new GameSave() { id = -1, name = "Existing Offline Save" }); - api.WriteOfflineSavesContent(new OfflineSavesContent(api._allSaves.ToArray())); + api._allSaves.Add(new GameSave() { id = -1, name = "Existing Offline Save" }); + api.WriteOfflineSavesContent(new OfflineSavesContent(api._allSaves.ToArray())); - var eventMock = new ChosenEventMock(); - api.OnSaveChosen += eventMock.Invoke; + var eventMock = new ChosenEventMock(); + api.OnSaveChosen += eventMock.Invoke; - _ = api.CreateSave("New Offline Save"); + _ = api.CreateSave("New Offline Save"); - Assert.AreEqual(2, api.All.Length); - Assert.AreEqual("Existing Offline Save", api.All[0].name); - Assert.AreEqual("New Offline Save", api.All[1].name); + Assert.AreEqual(2, api.All.Length); + Assert.AreEqual("Existing Offline Save", api.All[0].name); + Assert.AreEqual("New Offline Save", api.All[1].name); - Assert.AreEqual(2, api.GetOfflineSavesContent().saves.Length); - Assert.AreEqual("Existing Offline Save", api.GetOfflineSavesContent().saves[0].name); - Assert.AreEqual("New Offline Save", api.GetOfflineSavesContent().saves[1].name); + Assert.AreEqual(2, api.GetOfflineSavesContent().saves.Length); + Assert.AreEqual("Existing Offline Save", api.GetOfflineSavesContent().saves[0].name); + Assert.AreEqual("New Offline Save", api.GetOfflineSavesContent().saves[1].name); - Assert.AreEqual(-2, api.Current.id); - Assert.Null(eventMock.chosenSave); // should not invoke the OnSaveChosen event - api.OnSaveChosen -= eventMock.Invoke; + Assert.AreEqual(-2, api.Current.id); + Assert.Null(eventMock.chosenSave); // should not invoke the OnSaveChosen event + api.OnSaveChosen -= eventMock.Invoke; - yield return null; + yield return null; + } } } diff --git a/Packages/com.trytalo.talo/Tests/Runtime/SavesAPI/DeleteSaveTest.cs b/Packages/com.trytalo.talo/Tests/Runtime/SavesAPI/DeleteSaveTest.cs index e7c023c..4146d77 100644 --- a/Packages/com.trytalo.talo/Tests/Runtime/SavesAPI/DeleteSaveTest.cs +++ b/Packages/com.trytalo.talo/Tests/Runtime/SavesAPI/DeleteSaveTest.cs @@ -1,85 +1,87 @@ using System.Collections; using NUnit.Framework; using UnityEngine.TestTools; -using TaloGameServices; using UnityEngine; using System; -public class DeleteSaveTest +namespace TaloGameServices.Test { - [OneTimeSetUp] - public void SetUp() + internal class DeleteSaveTest { - var tm = new GameObject().AddComponent(); - tm.settings = ScriptableObject.CreateInstance(); - - Talo.CurrentAlias = new PlayerAlias() { - player = new Player() { - id = "uuid" - } - }; - } + [OneTimeSetUp] + public void SetUp() + { + var tm = new GameObject().AddComponent(); + tm.settings = ScriptableObject.CreateInstance(); - [TearDown] - public void TearDown() - { - RequestMock.Offline = false; - } + Talo.CurrentAlias = new PlayerAlias() { + player = new Player() { + id = "uuid" + } + }; + } - [UnityTest] - public IEnumerator DeleteSave_InOnlineMode_RemovesFromArrayOfSaves() - { - var api = new SavesAPI(); - Talo._saves = api; + [TearDown] + public void TearDown() + { + RequestMock.Offline = false; + } - api._allSaves.Add(new GameSave() { id = 1, name = "Save 1" }); - api._allSaves.Add(new GameSave() { id = 2, name = "Save 2" }); - api.WriteOfflineSavesContent(new OfflineSavesContent(api._allSaves.ToArray())); + [UnityTest] + public IEnumerator DeleteSave_InOnlineMode_RemovesFromArrayOfSaves() + { + var api = new SavesAPI(); + Talo._saves = api; - var eventMock = new ChosenEventMock(); - api.OnSaveChosen += eventMock.Invoke; + api._allSaves.Add(new GameSave() { id = 1, name = "Save 1" }); + api._allSaves.Add(new GameSave() { id = 2, name = "Save 2" }); + api.WriteOfflineSavesContent(new OfflineSavesContent(api._allSaves.ToArray())); - RequestMock.ReplyOnce(new Uri(api.GetUri() + "/1"), "DELETE"); - _ = api.DeleteSave(1); + var eventMock = new ChosenEventMock(); + api.OnSaveChosen += eventMock.Invoke; - Assert.AreEqual(1, api.All.Length); - Assert.AreEqual("Save 2", api.All[0].name); + RequestMock.ReplyOnce(new Uri(api.GetUri() + "/1"), "DELETE"); + _ = api.DeleteSave(1); - Assert.AreEqual(1, api.GetOfflineSavesContent().saves.Length); - Assert.AreEqual("Save 2", api.GetOfflineSavesContent().saves[0].name); + Assert.AreEqual(1, api.All.Length); + Assert.AreEqual("Save 2", api.All[0].name); - Assert.AreEqual(null, eventMock.chosenSave); - api.OnSaveChosen -= eventMock.Invoke; + Assert.AreEqual(1, api.GetOfflineSavesContent().saves.Length); + Assert.AreEqual("Save 2", api.GetOfflineSavesContent().saves[0].name); - yield return null; - } + Assert.AreEqual(null, eventMock.chosenSave); + api.OnSaveChosen -= eventMock.Invoke; - [UnityTest] - public IEnumerator DeleteSave_InOfflineMode_RemovesFromArrayOfSaves() - { - RequestMock.Offline = true; + yield return null; + } + + [UnityTest] + public IEnumerator DeleteSave_InOfflineMode_RemovesFromArrayOfSaves() + { + RequestMock.Offline = true; - var api = new SavesAPI(); - Talo._saves = api; + var api = new SavesAPI(); + Talo._saves = api; - api._allSaves.Add(new GameSave() { id = -1, name = "Save 1" }); - api._allSaves.Add(new GameSave() { id = -2, name = "Save 2" }); - api.WriteOfflineSavesContent(new OfflineSavesContent(api._allSaves.ToArray())); + api._allSaves.Add(new GameSave() { id = -1, name = "Save 1" }); + api._allSaves.Add(new GameSave() { id = -2, name = "Save 2" }); + api.WriteOfflineSavesContent(new OfflineSavesContent(api._allSaves.ToArray())); - var eventMock = new ChosenEventMock(); - api.OnSaveChosen += eventMock.Invoke; + var eventMock = new ChosenEventMock(); + api.OnSaveChosen += eventMock.Invoke; - _ = api.DeleteSave(-2); + _ = api.DeleteSave(-2); - Assert.AreEqual(1, api.All.Length); - Assert.AreEqual("Save 1", api.All[0].name); + Assert.AreEqual(1, api.All.Length); + Assert.AreEqual("Save 1", api.All[0].name); - Assert.AreEqual(1, api.GetOfflineSavesContent().saves.Length); - Assert.AreEqual("Save 1", api.GetOfflineSavesContent().saves[0].name); + Assert.AreEqual(1, api.GetOfflineSavesContent().saves.Length); + Assert.AreEqual("Save 1", api.GetOfflineSavesContent().saves[0].name); - Assert.AreEqual(null, eventMock.chosenSave); - api.OnSaveChosen -= eventMock.Invoke; + Assert.AreEqual(null, eventMock.chosenSave); + api.OnSaveChosen -= eventMock.Invoke; - yield return null; + yield return null; + } } } diff --git a/Packages/com.trytalo.talo/Tests/Runtime/SavesAPI/GetSavesTest.cs b/Packages/com.trytalo.talo/Tests/Runtime/SavesAPI/GetSavesTest.cs index 06fd35d..4a72f05 100644 --- a/Packages/com.trytalo.talo/Tests/Runtime/SavesAPI/GetSavesTest.cs +++ b/Packages/com.trytalo.talo/Tests/Runtime/SavesAPI/GetSavesTest.cs @@ -1,220 +1,222 @@ using System.Collections; using NUnit.Framework; using UnityEngine.TestTools; -using TaloGameServices; using UnityEngine; using System; -internal class LoadedEventMock +namespace TaloGameServices.Test { - public bool wasInvoked; - - public void Invoke() + internal class LoadedEventMock { - wasInvoked = true; - } -} + public bool wasInvoked; -public class GetSavesTest -{ - [OneTimeSetUp] - public void SetUp() - { - var tm = new GameObject().AddComponent(); - tm.settings = ScriptableObject.CreateInstance(); - - Talo.CurrentAlias = new PlayerAlias() { - player = new Player() { - id = "uuid" - } - }; + public void Invoke() + { + wasInvoked = true; + } } - [TearDown] - public void TearDown() + internal class GetSavesTest { - RequestMock.Offline = false; - } + [OneTimeSetUp] + public void SetUp() + { + var tm = new GameObject().AddComponent(); + tm.settings = ScriptableObject.CreateInstance(); - [UnityTest] - public IEnumerator GetSaves_InOnlineMode_ReturnsAnArrayOfSaves() - { - var api = new SavesAPI(); + Talo.CurrentAlias = new PlayerAlias() { + player = new Player() { + id = "uuid" + } + }; + } - var eventMock = new LoadedEventMock(); - api.OnSavesLoaded += eventMock.Invoke; + [TearDown] + public void TearDown() + { + RequestMock.Offline = false; + } - RequestMock.ReplyOnce(api.GetUri(), "GET", JsonUtility.ToJson(new SavesIndexResponse + [UnityTest] + public IEnumerator GetSaves_InOnlineMode_ReturnsAnArrayOfSaves() { - saves = new GameSave[] { - new GameSave { - id = 1, - name = "Online Save", - content = "", - updatedAt = "2022-10-30T21:23:30.977Z" + var api = new SavesAPI(); + + var eventMock = new LoadedEventMock(); + api.OnSavesLoaded += eventMock.Invoke; + + RequestMock.ReplyOnce(api.GetUri(), "GET", JsonUtility.ToJson(new SavesIndexResponse + { + saves = new GameSave[] { + new GameSave { + id = 1, + name = "Online Save", + content = "", + updatedAt = "2022-10-30T21:23:30.977Z" + } } - } - })); - _ = api.GetSaves(); - - Assert.AreEqual(1, api.All.Length); - Assert.AreEqual("Online Save", api.All[0].name); - - Assert.AreEqual(1, api.GetOfflineSavesContent().saves.Length); - Assert.AreEqual("Online Save", api.GetOfflineSavesContent().saves[0].name); - - Assert.IsTrue(eventMock.wasInvoked); - api.OnSavesLoaded -= eventMock.Invoke; + })); + _ = api.GetSaves(); - yield return null; - } + Assert.AreEqual(1, api.All.Length); + Assert.AreEqual("Online Save", api.All[0].name); - [UnityTest] - public IEnumerator GetSaves_InOfflineModeWithNoSaves_ReturnsAnEmptyArray() - { - RequestMock.Offline = true; + Assert.AreEqual(1, api.GetOfflineSavesContent().saves.Length); + Assert.AreEqual("Online Save", api.GetOfflineSavesContent().saves[0].name); - var api = new SavesAPI(); + Assert.IsTrue(eventMock.wasInvoked); + api.OnSavesLoaded -= eventMock.Invoke; - var eventMock = new LoadedEventMock(); - api.OnSavesLoaded += eventMock.Invoke; + yield return null; + } - _ = api.GetSaves(); + [UnityTest] + public IEnumerator GetSaves_InOfflineModeWithNoSaves_ReturnsAnEmptyArray() + { + RequestMock.Offline = true; - Assert.AreEqual(0, api.All.Length); - Assert.IsNull(api.GetOfflineSavesContent()); + var api = new SavesAPI(); - Assert.IsTrue(eventMock.wasInvoked); - api.OnSavesLoaded -= eventMock.Invoke; + var eventMock = new LoadedEventMock(); + api.OnSavesLoaded += eventMock.Invoke; - yield return null; - } + _ = api.GetSaves(); - [UnityTest] - public IEnumerator GetSaves_InOfflineModeWithSaves_ReturnsAnArrayOfSaves() - { - RequestMock.Offline = true; + Assert.AreEqual(0, api.All.Length); + Assert.IsNull(api.GetOfflineSavesContent()); - var api = new SavesAPI(); - _ = api.CreateSave("Offline Save"); + Assert.IsTrue(eventMock.wasInvoked); + api.OnSavesLoaded -= eventMock.Invoke; - var eventMock = new LoadedEventMock(); - api.OnSavesLoaded += eventMock.Invoke; + yield return null; + } - _ = api.GetSaves(); + [UnityTest] + public IEnumerator GetSaves_InOfflineModeWithSaves_ReturnsAnArrayOfSaves() + { + RequestMock.Offline = true; - Assert.AreEqual(1, api.All.Length); - Assert.AreEqual("Offline Save", api.All[0].name); + var api = new SavesAPI(); + _ = api.CreateSave("Offline Save"); - Assert.AreEqual(1, api.GetOfflineSavesContent().saves.Length); - Assert.AreEqual("Offline Save", api.GetOfflineSavesContent().saves[0].name); + var eventMock = new LoadedEventMock(); + api.OnSavesLoaded += eventMock.Invoke; - Assert.IsTrue(eventMock.wasInvoked); - api.OnSavesLoaded -= eventMock.Invoke; + _ = api.GetSaves(); - yield return null; - } + Assert.AreEqual(1, api.All.Length); + Assert.AreEqual("Offline Save", api.All[0].name); - [UnityTest] - public IEnumerator GetSaves_InOnlineMode_PrefersTheLastUpdatedSaveIfTwoWithTheSameIDExist() - { - var api = new SavesAPI(); + Assert.AreEqual(1, api.GetOfflineSavesContent().saves.Length); + Assert.AreEqual("Offline Save", api.GetOfflineSavesContent().saves[0].name); - var eventMock = new LoadedEventMock(); - api.OnSavesLoaded += eventMock.Invoke; + Assert.IsTrue(eventMock.wasInvoked); + api.OnSavesLoaded -= eventMock.Invoke; - api.WriteOfflineSavesContent(new OfflineSavesContent( - new GameSave[] { - new GameSave - { - id = 2, - name = "Both Save (old)", - content = "", - updatedAt = "2022-10-29T21:23:30.977Z" - } - } - )); + yield return null; + } - RequestMock.ReplyOnce(api.GetUri(), "GET", JsonUtility.ToJson(new SavesIndexResponse + [UnityTest] + public IEnumerator GetSaves_InOnlineMode_PrefersTheLastUpdatedSaveIfTwoWithTheSameIDExist() { - saves = new GameSave[] { - new GameSave { - id = 2, - name = "Both Save (new)", - content = "", - updatedAt = "2022-10-30T21:23:30.977Z" + var api = new SavesAPI(); + + var eventMock = new LoadedEventMock(); + api.OnSavesLoaded += eventMock.Invoke; + + api.WriteOfflineSavesContent(new OfflineSavesContent( + new GameSave[] { + new GameSave + { + id = 2, + name = "Both Save (old)", + content = "", + updatedAt = "2022-10-29T21:23:30.977Z" + } } - } - })); - _ = api.GetSaves(); - - Assert.AreEqual(1, api.All.Length); - Assert.AreEqual("Both Save (new)", api.All[0].name); - - Assert.AreEqual(1, api.GetOfflineSavesContent().saves.Length); - Assert.AreEqual("Both Save (new)", api.GetOfflineSavesContent().saves[0].name); - Assert.AreEqual("2022-10-30T21:23:30.977Z", api.GetOfflineSavesContent().saves[0].updatedAt); + )); + + RequestMock.ReplyOnce(api.GetUri(), "GET", JsonUtility.ToJson(new SavesIndexResponse + { + saves = new GameSave[] { + new GameSave { + id = 2, + name = "Both Save (new)", + content = "", + updatedAt = "2022-10-30T21:23:30.977Z" + } + } + })); + _ = api.GetSaves(); - Assert.IsTrue(eventMock.wasInvoked); - api.OnSavesLoaded -= eventMock.Invoke; + Assert.AreEqual(1, api.All.Length); + Assert.AreEqual("Both Save (new)", api.All[0].name); - yield return null; - } + Assert.AreEqual(1, api.GetOfflineSavesContent().saves.Length); + Assert.AreEqual("Both Save (new)", api.GetOfflineSavesContent().saves[0].name); + Assert.AreEqual("2022-10-30T21:23:30.977Z", api.GetOfflineSavesContent().saves[0].updatedAt); - [UnityTest] - public IEnumerator GetSaves_InOnlineMode_ReplacesTheOnlineSaveIfTheOfflineVersionIsNewer() - { - var api = new SavesAPI(); + Assert.IsTrue(eventMock.wasInvoked); + api.OnSavesLoaded -= eventMock.Invoke; - var eventMock = new LoadedEventMock(); - api.OnSavesLoaded += eventMock.Invoke; + yield return null; + } - api.WriteOfflineSavesContent(new OfflineSavesContent( - new GameSave[] { - new GameSave - { - id = 3, - name = "Both Save (offline)", - content = "", - updatedAt = "2022-10-30T21:23:30.977Z" + [UnityTest] + public IEnumerator GetSaves_InOnlineMode_ReplacesTheOnlineSaveIfTheOfflineVersionIsNewer() + { + var api = new SavesAPI(); + + var eventMock = new LoadedEventMock(); + api.OnSavesLoaded += eventMock.Invoke; + + api.WriteOfflineSavesContent(new OfflineSavesContent( + new GameSave[] { + new GameSave + { + id = 3, + name = "Both Save (offline)", + content = "", + updatedAt = "2022-10-30T21:23:30.977Z" + } } - } - )); + )); + + RequestMock.ReplyOnce(api.GetUri(), "GET", JsonUtility.ToJson(new SavesIndexResponse + { + saves = new GameSave[] { + new GameSave { + id = 3, + name = "Both Save (online)", + content = "", + updatedAt = "2022-10-29T21:23:30.977Z" + } + } + })); - RequestMock.ReplyOnce(api.GetUri(), "GET", JsonUtility.ToJson(new SavesIndexResponse - { - saves = new GameSave[] { - new GameSave { + RequestMock.ReplyOnce(new Uri(api.GetUri() + "/3"), "PATCH", JsonUtility.ToJson(new SavesPostResponse + { + save = new GameSave { id = 3, - name = "Both Save (online)", + name = "Both Save (offline)", content = "", - updatedAt = "2022-10-29T21:23:30.977Z" + updatedAt = "2022-10-30T21:30:30.977Z" } - } - })); - - RequestMock.ReplyOnce(new Uri(api.GetUri() + "/3"), "PATCH", JsonUtility.ToJson(new SavesPostResponse - { - save = new GameSave { - id = 3, - name = "Both Save (offline)", - content = "", - updatedAt = "2022-10-30T21:30:30.977Z" - } - })); + })); - _ = api.GetSaves(); + _ = api.GetSaves(); - Assert.AreEqual(1, api.All.Length); - Assert.AreEqual("Both Save (offline)", api.All[0].name); + Assert.AreEqual(1, api.All.Length); + Assert.AreEqual("Both Save (offline)", api.All[0].name); - Assert.AreEqual(1, api.GetOfflineSavesContent().saves.Length); - Assert.AreEqual("Both Save (offline)", api.GetOfflineSavesContent().saves[0].name); - Assert.AreEqual("2022-10-30T21:30:30.977Z", api.GetOfflineSavesContent().saves[0].updatedAt); + Assert.AreEqual(1, api.GetOfflineSavesContent().saves.Length); + Assert.AreEqual("Both Save (offline)", api.GetOfflineSavesContent().saves[0].name); + Assert.AreEqual("2022-10-30T21:30:30.977Z", api.GetOfflineSavesContent().saves[0].updatedAt); - Assert.IsTrue(eventMock.wasInvoked); - api.OnSavesLoaded -= eventMock.Invoke; + Assert.IsTrue(eventMock.wasInvoked); + api.OnSavesLoaded -= eventMock.Invoke; - yield return null; + yield return null; + } } } diff --git a/Packages/com.trytalo.talo/Tests/Runtime/SavesAPI/SaveContentTest.cs b/Packages/com.trytalo.talo/Tests/Runtime/SavesAPI/SaveContentTest.cs index 9126442..562f4dd 100644 --- a/Packages/com.trytalo.talo/Tests/Runtime/SavesAPI/SaveContentTest.cs +++ b/Packages/com.trytalo.talo/Tests/Runtime/SavesAPI/SaveContentTest.cs @@ -2,130 +2,132 @@ using NUnit.Framework; using UnityEngine; using UnityEngine.TestTools; -using TaloGameServices; using System.Collections.Generic; -internal class PositionedLoadable : Loadable +namespace TaloGameServices.Test { - public override void RegisterFields() + internal class PositionedLoadable : Loadable { - RegisterField("pos.x", transform.position.x); - RegisterField("pos.y", transform.position.y); - RegisterField("pos.z", transform.position.z); + public override void RegisterFields() + { + RegisterField("pos.x", transform.position.x); + RegisterField("pos.y", transform.position.y); + RegisterField("pos.z", transform.position.z); + } + + public override void OnLoaded(Dictionary data) + { + if (HandleDestroyed(data)) return; + + gameObject.transform.position = new Vector3( + (float)data["pos.x"], + (float)data["pos.y"], + (float)data["pos.z"] + ); + } } - public override void OnLoaded(Dictionary data) + public class SaveContentTest { - if (HandleDestroyed(data)) return; + [OneTimeSetUp] + public void Setup() + { + var tm = new GameObject().AddComponent(); + tm.settings = ScriptableObject.CreateInstance(); - gameObject.transform.position = new Vector3( - (float)data["pos.x"], - (float)data["pos.y"], - (float)data["pos.z"] - ); - } -} + Talo.CurrentAlias = new PlayerAlias() { + player = new Player() { + id = "uuid" + } + }; + } -public class SaveContentTest -{ - [OneTimeSetUp] - public void Setup() - { - var tm = new GameObject().AddComponent(); - tm.settings = ScriptableObject.CreateInstance(); - - Talo.CurrentAlias = new PlayerAlias() { - player = new Player() { - id = "uuid" - } - }; - } + [UnityTest] + public IEnumerator SaveContent_ActiveObjects_AreSavedCorrectly() + { + var api = new SavesAPI(); + Talo._saves = api; - [UnityTest] - public IEnumerator SaveContent_ActiveObjects_AreSavedCorrectly() - { - var api = new SavesAPI(); - Talo._saves = api; + var loadable = new GameObject("First Loadable").AddComponent(); + loadable.transform.position = new Vector3(88, -20, 6); - var loadable = new GameObject("First Loadable").AddComponent(); - loadable.transform.position = new Vector3(88, -20, 6); + var content = new SaveContent(api._registeredLoadables); + Assert.AreEqual(1, content.objects.Length); - var content = new SaveContent(api._registeredLoadables); - Assert.AreEqual(1, content.objects.Length); + Assert.AreEqual(loadable.Id, content.objects[0].id); + Assert.AreEqual("First Loadable", content.objects[0].name); - Assert.AreEqual(loadable.Id, content.objects[0].id); - Assert.AreEqual("First Loadable", content.objects[0].name); + Assert.AreEqual("pos.x", content.objects[0].data[0].key); + Assert.AreEqual("88", content.objects[0].data[0].value); + Assert.AreEqual("System.Single", content.objects[0].data[0].type); - Assert.AreEqual("pos.x", content.objects[0].data[0].key); - Assert.AreEqual("88", content.objects[0].data[0].value); - Assert.AreEqual("System.Single", content.objects[0].data[0].type); + Assert.AreEqual("pos.y", content.objects[0].data[1].key); + Assert.AreEqual("-20", content.objects[0].data[1].value); + Assert.AreEqual("System.Single", content.objects[0].data[1].type); - Assert.AreEqual("pos.y", content.objects[0].data[1].key); - Assert.AreEqual("-20", content.objects[0].data[1].value); - Assert.AreEqual("System.Single", content.objects[0].data[1].type); + Assert.AreEqual("pos.z", content.objects[0].data[2].key); + Assert.AreEqual("6", content.objects[0].data[2].value); + Assert.AreEqual("System.Single", content.objects[0].data[2].type); - Assert.AreEqual("pos.z", content.objects[0].data[2].key); - Assert.AreEqual("6", content.objects[0].data[2].value); - Assert.AreEqual("System.Single", content.objects[0].data[2].type); + Object.DestroyImmediate(loadable.gameObject); - Object.DestroyImmediate(loadable.gameObject); + yield return null; + } - yield return null; - } + [UnityTest] + public IEnumerator SaveContent_DestroyedObjects_AreSavedCorrectly() + { + var api = new SavesAPI(); + Talo._saves = api; - [UnityTest] - public IEnumerator SaveContent_DestroyedObjects_AreSavedCorrectly() - { - var api = new SavesAPI(); - Talo._saves = api; + var activeLoadable = new GameObject("Active Loadable").AddComponent(); + var destroyedLoadable = new GameObject("Destroyed Loadable").AddComponent(); - var activeLoadable = new GameObject("Active Loadable").AddComponent(); - var destroyedLoadable = new GameObject("Destroyed Loadable").AddComponent(); + Object.DestroyImmediate(destroyedLoadable.gameObject); - Object.DestroyImmediate(destroyedLoadable.gameObject); + var content = new SaveContent(api._registeredLoadables); + Assert.AreEqual(2, content.objects.Length); - var content = new SaveContent(api._registeredLoadables); - Assert.AreEqual(2, content.objects.Length); + Assert.AreEqual(activeLoadable.Id, content.objects[0].id); + Assert.AreEqual("Active Loadable", content.objects[0].name); + Assert.AreEqual("pos.x", content.objects[0].data[0].key); + Assert.AreEqual("pos.y", content.objects[0].data[1].key); + Assert.AreEqual("pos.z", content.objects[0].data[2].key); - Assert.AreEqual(activeLoadable.Id, content.objects[0].id); - Assert.AreEqual("Active Loadable", content.objects[0].name); - Assert.AreEqual("pos.x", content.objects[0].data[0].key); - Assert.AreEqual("pos.y", content.objects[0].data[1].key); - Assert.AreEqual("pos.z", content.objects[0].data[2].key); + Assert.AreEqual(destroyedLoadable.Id, content.objects[1].id); + Assert.AreEqual("Destroyed Loadable", content.objects[1].name); + Assert.AreEqual("meta.destroyed", content.objects[1].data[0].key); + Assert.AreEqual("True", content.objects[1].data[0].value); + Assert.AreEqual("System.Boolean", content.objects[1].data[0].type); - Assert.AreEqual(destroyedLoadable.Id, content.objects[1].id); - Assert.AreEqual("Destroyed Loadable", content.objects[1].name); - Assert.AreEqual("meta.destroyed", content.objects[1].data[0].key); - Assert.AreEqual("True", content.objects[1].data[0].value); - Assert.AreEqual("System.Boolean", content.objects[1].data[0].type); + Object.DestroyImmediate(activeLoadable.gameObject); - Object.DestroyImmediate(activeLoadable.gameObject); + yield return null; + } - yield return null; - } - - [UnityTest] - public IEnumerator SaveContent_NestedObjects_AreNamedCorrectly() - { - var api = new SavesAPI(); - Talo._saves = api; + [UnityTest] + public IEnumerator SaveContent_NestedObjects_AreNamedCorrectly() + { + var api = new SavesAPI(); + Talo._saves = api; - var grandParent = new GameObject("Grandparent"); - var parent = new GameObject("Parent"); - parent.transform.parent = grandParent.transform; + var grandParent = new GameObject("Grandparent"); + var parent = new GameObject("Parent"); + parent.transform.parent = grandParent.transform; - var loadable = new GameObject("First Loadable"); - loadable.transform.parent = parent.transform; - var id = loadable.AddComponent().Id; + var loadable = new GameObject("First Loadable"); + loadable.transform.parent = parent.transform; + var id = loadable.AddComponent().Id; - var content = new SaveContent(api._registeredLoadables); - Assert.AreEqual(1, content.objects.Length); + var content = new SaveContent(api._registeredLoadables); + Assert.AreEqual(1, content.objects.Length); - Assert.AreEqual(id, content.objects[0].id); - Assert.AreEqual("Grandparent.Parent.First Loadable", content.objects[0].name); + Assert.AreEqual(id, content.objects[0].id); + Assert.AreEqual("Grandparent.Parent.First Loadable", content.objects[0].name); - Object.DestroyImmediate(loadable.gameObject); + Object.DestroyImmediate(loadable.gameObject); - yield return null; + yield return null; + } } } diff --git a/Packages/com.trytalo.talo/Tests/Runtime/SavesAPI/UpdateSaveTest.cs b/Packages/com.trytalo.talo/Tests/Runtime/SavesAPI/UpdateSaveTest.cs index 7f23352..8ed7f97 100644 --- a/Packages/com.trytalo.talo/Tests/Runtime/SavesAPI/UpdateSaveTest.cs +++ b/Packages/com.trytalo.talo/Tests/Runtime/SavesAPI/UpdateSaveTest.cs @@ -1,122 +1,124 @@ using System.Collections; using NUnit.Framework; using UnityEngine.TestTools; -using TaloGameServices; using UnityEngine; using System; -public class UpdateSaveTest +namespace TaloGameServices.Test { - [OneTimeSetUp] - public void SetUp() + internal class UpdateSaveTest { - var tm = new GameObject().AddComponent(); - tm.settings = ScriptableObject.CreateInstance(); - - Talo.CurrentAlias = new PlayerAlias() { - player = new Player() { - id = "uuid" - } - }; - } - - [TearDown] - public void TearDown() - { - RequestMock.Offline = false; - } - - [UnityTest] - public IEnumerator UpdateSave_InOnlineMode_UpdatesTheSaveContent() - { - var api = new SavesAPI(); - Talo._saves = api; - - api._allSaves.Add(new GameSave() { id = 1, name = "Online Save" }); - api.WriteOfflineSavesContent(new OfflineSavesContent(api._allSaves.ToArray())); + [OneTimeSetUp] + public void SetUp() + { + var tm = new GameObject().AddComponent(); + tm.settings = ScriptableObject.CreateInstance(); + + Talo.CurrentAlias = new PlayerAlias() { + player = new Player() { + id = "uuid" + } + }; + } + + [TearDown] + public void TearDown() + { + RequestMock.Offline = false; + } - RequestMock.ReplyOnce(new Uri(api.GetUri() + "/1"), "PATCH", JsonUtility.ToJson(new SavesPostResponse + [UnityTest] + public IEnumerator UpdateSave_InOnlineMode_UpdatesTheSaveContent() { - save = new GameSave { id = 1, name = "Online Save", content = "updated", updatedAt = "2022-10-30T21:23:30.977Z" } - })); - _ = api.UpdateSave(1); + var api = new SavesAPI(); + Talo._saves = api; - Assert.AreEqual(1, api.All.Length); - Assert.AreEqual("Online Save", api.All[0].name); - Assert.AreEqual("updated", api.All[0].content); + api._allSaves.Add(new GameSave() { id = 1, name = "Online Save" }); + api.WriteOfflineSavesContent(new OfflineSavesContent(api._allSaves.ToArray())); - Assert.AreEqual(1, api.GetOfflineSavesContent().saves.Length); - Assert.AreEqual("Online Save", api.GetOfflineSavesContent().saves[0].name); - Assert.AreEqual("updated", api.GetOfflineSavesContent().saves[0].content); + RequestMock.ReplyOnce(new Uri(api.GetUri() + "/1"), "PATCH", JsonUtility.ToJson(new SavesPostResponse + { + save = new GameSave { id = 1, name = "Online Save", content = "updated", updatedAt = "2022-10-30T21:23:30.977Z" } + })); + _ = api.UpdateSave(1); - yield return null; - } + Assert.AreEqual(1, api.All.Length); + Assert.AreEqual("Online Save", api.All[0].name); + Assert.AreEqual("updated", api.All[0].content); - [UnityTest] - public IEnumerator UpdateSave_InOnlineMode_UpdatesTheSaveName() - { - var api = new SavesAPI(); - Talo._saves = api; + Assert.AreEqual(1, api.GetOfflineSavesContent().saves.Length); + Assert.AreEqual("Online Save", api.GetOfflineSavesContent().saves[0].name); + Assert.AreEqual("updated", api.GetOfflineSavesContent().saves[0].content); - api._allSaves.Add(new GameSave() { id = 1, name = "Online Save" }); - api.WriteOfflineSavesContent(new OfflineSavesContent(api._allSaves.ToArray())); + yield return null; + } - RequestMock.ReplyOnce(new Uri(api.GetUri() + "/1"), "PATCH", JsonUtility.ToJson(new SavesPostResponse + [UnityTest] + public IEnumerator UpdateSave_InOnlineMode_UpdatesTheSaveName() { - save = new GameSave { id = 1, name = "New Name", content = "", updatedAt = "2022-10-30T21:23:30.977Z" } - })); - _ = api.UpdateSave(1); + var api = new SavesAPI(); + Talo._saves = api; - Assert.AreEqual(1, api.All.Length); - Assert.AreEqual("New Name", api.All[0].name); + api._allSaves.Add(new GameSave() { id = 1, name = "Online Save" }); + api.WriteOfflineSavesContent(new OfflineSavesContent(api._allSaves.ToArray())); - Assert.AreEqual(1, api.GetOfflineSavesContent().saves.Length); - Assert.AreEqual("New Name", api.GetOfflineSavesContent().saves[0].name); + RequestMock.ReplyOnce(new Uri(api.GetUri() + "/1"), "PATCH", JsonUtility.ToJson(new SavesPostResponse + { + save = new GameSave { id = 1, name = "New Name", content = "", updatedAt = "2022-10-30T21:23:30.977Z" } + })); + _ = api.UpdateSave(1); - yield return null; - } + Assert.AreEqual(1, api.All.Length); + Assert.AreEqual("New Name", api.All[0].name); - [UnityTest] - public IEnumerator UpdateSave_InOfflineMode_UpdatesTheSaveContent() - { - RequestMock.Offline = true; + Assert.AreEqual(1, api.GetOfflineSavesContent().saves.Length); + Assert.AreEqual("New Name", api.GetOfflineSavesContent().saves[0].name); - var api = new SavesAPI(); - Talo._saves = api; + yield return null; + } - api._allSaves.Add(new GameSave() { id = -1, name = "Offline Save" }); - api.WriteOfflineSavesContent(new OfflineSavesContent(api._allSaves.ToArray())); + [UnityTest] + public IEnumerator UpdateSave_InOfflineMode_UpdatesTheSaveContent() + { + RequestMock.Offline = true; - _ = api.UpdateSave(-1); + var api = new SavesAPI(); + Talo._saves = api; - Assert.AreEqual(1, api.All.Length); - Assert.AreEqual("Offline Save", api.All[0].name); + api._allSaves.Add(new GameSave() { id = -1, name = "Offline Save" }); + api.WriteOfflineSavesContent(new OfflineSavesContent(api._allSaves.ToArray())); - Assert.AreEqual(1, api.GetOfflineSavesContent().saves.Length); - Assert.AreEqual("Offline Save", api.GetOfflineSavesContent().saves[0].name); + _ = api.UpdateSave(-1); - yield return null; - } + Assert.AreEqual(1, api.All.Length); + Assert.AreEqual("Offline Save", api.All[0].name); - [UnityTest] - public IEnumerator UpdateSave_InOfflineMode_UpdatesTheSaveName() - { - RequestMock.Offline = true; + Assert.AreEqual(1, api.GetOfflineSavesContent().saves.Length); + Assert.AreEqual("Offline Save", api.GetOfflineSavesContent().saves[0].name); + + yield return null; + } + + [UnityTest] + public IEnumerator UpdateSave_InOfflineMode_UpdatesTheSaveName() + { + RequestMock.Offline = true; - var api = new SavesAPI(); - Talo._saves = api; + var api = new SavesAPI(); + Talo._saves = api; - api._allSaves.Add(new GameSave() { id = -1, name = "Offline Save" }); - api.WriteOfflineSavesContent(new OfflineSavesContent(api._allSaves.ToArray())); + api._allSaves.Add(new GameSave() { id = -1, name = "Offline Save" }); + api.WriteOfflineSavesContent(new OfflineSavesContent(api._allSaves.ToArray())); - _ = api.UpdateSave(-1, "New Name"); + _ = api.UpdateSave(-1, "New Name"); - Assert.AreEqual(1, api.All.Length); - Assert.AreEqual("New Name", api.All[0].name); + Assert.AreEqual(1, api.All.Length); + Assert.AreEqual("New Name", api.All[0].name); - Assert.AreEqual(1, api.GetOfflineSavesContent().saves.Length); - Assert.AreEqual("New Name", api.GetOfflineSavesContent().saves[0].name); + Assert.AreEqual(1, api.GetOfflineSavesContent().saves.Length); + Assert.AreEqual("New Name", api.GetOfflineSavesContent().saves[0].name); - yield return null; + yield return null; + } } } diff --git a/Packages/com.trytalo.talo/package.json b/Packages/com.trytalo.talo/package.json index e3270e1..ccd5cb5 100644 --- a/Packages/com.trytalo.talo/package.json +++ b/Packages/com.trytalo.talo/package.json @@ -1,6 +1,6 @@ { "name": "com.trytalo.talo", - "version": "0.25.0", + "version": "0.26.0", "displayName": "Talo Game Services", "description": "Talo (https://trytalo.com) is an open-source game backend with services designed to help you build games faster. You can currently:\n\n- Identify and authenticate players\n- Store persistent data across players\n- Track events (levelling up, finding loot, etc)\n- Display high scores with leaderboards\n- Store and load player saves\n- Load game config options and flags from the cloud\n- Get feedback directly from your players", "unity": "2022.3", diff --git a/ProjectSettings/PackageManagerSettings.asset b/ProjectSettings/PackageManagerSettings.asset index be4a797..94a75fb 100644 --- a/ProjectSettings/PackageManagerSettings.asset +++ b/ProjectSettings/PackageManagerSettings.asset @@ -12,10 +12,11 @@ MonoBehaviour: m_Script: {fileID: 13964, guid: 0000000000000000e000000000000000, type: 0} m_Name: m_EditorClassIdentifier: - m_EnablePreviewPackages: 0 - m_EnablePackageDependencies: 0 + m_EnablePreReleasePackages: 0 m_AdvancedSettingsExpanded: 1 m_ScopedRegistriesSettingsExpanded: 1 + m_SeeAllPackageVersions: 0 + m_DismissPreviewPackagesInUse: 0 oneTimeWarningShown: 0 m_Registries: - m_Id: main @@ -24,20 +25,12 @@ MonoBehaviour: m_Scopes: [] m_IsDefault: 1 m_Capabilities: 7 + m_ConfigSource: 0 m_UserSelectedRegistryName: m_UserAddingNewScopedRegistry: 0 m_RegistryInfoDraft: - m_ErrorMessage: - m_Original: - m_Id: - m_Name: - m_Url: - m_Scopes: [] - m_IsDefault: 0 - m_Capabilities: 0 m_Modified: 0 - m_Name: - m_Url: - m_Scopes: - - - m_SelectedScopeIndex: 0 + m_ErrorMessage: + m_UserModificationsInstanceId: -834 + m_OriginalInstanceId: -836 + m_LoadAssets: 0