Skip to content

Commit de4a77c

Browse files
authored
Merge pull request #78 from TaloDev/develop
Release 0.23.0
2 parents 8b74eac + 8d67a35 commit de4a77c

24 files changed

+153
-3762
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
/[Bb]uilds/
1010
/[Ll]ogs/
1111
/[Mm]emoryCaptures/
12+
/[Uu]serSettings/
1213

1314
# Asset meta data should only be ignored when the corresponding asset is also ignored
1415
!/[Aa]ssets/**/*.meta

Assets/Samples/AuthenticationDemo/Scripts/GameUIController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ private void OnDisable()
2222

2323
private void OnIdentified(Player player)
2424
{
25-
root.Q<Label>("title").text = root.Q<Label>("title").text.Replace("{username}", Talo.CurrentAlias.identifier);
25+
root.Q<Label>("title").text = $"Hi, {Talo.CurrentAlias.identifier}";
2626
}
2727

2828
private async void OnLogoutClick()

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 Talo Platform Ltd
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

LICENSE.md

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

Packages/com.trytalo.talo/Runtime/APIs/SavesAPI.cs

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ public class SavesAPI : BaseAPI
1717
public event Action<GameSave> OnSaveChosen;
1818
public event Action OnSaveLoadingCompleted;
1919

20-
private readonly string _offlineSavesPath = Application.persistentDataPath + "/talo-saves.bin";
2120
private IFileHandler<OfflineSavesContent> _fileHandler;
2221

2322
public GameSave[] All
@@ -148,18 +147,35 @@ public void Register(Loadable loadable)
148147
_registeredLoadables.Add(new LoadableData(loadable));
149148
}
150149

150+
internal string GetOfflineSavesPath()
151+
{
152+
return Application.persistentDataPath + $"/ts.{Talo.CurrentPlayer.id}.bin";
153+
}
154+
151155
internal OfflineSavesContent GetOfflineSavesContent()
152156
{
153-
return _fileHandler.ReadContent(_offlineSavesPath);
157+
return _fileHandler.ReadContent(GetOfflineSavesPath());
154158
}
155159

156160
internal void WriteOfflineSavesContent(OfflineSavesContent newContent)
157161
{
158-
_fileHandler.WriteContent(_offlineSavesPath, newContent);
162+
_fileHandler.WriteContent(GetOfflineSavesPath(), newContent);
163+
}
164+
165+
private GameSave CreateOfflineCopy(GameSave originalSave)
166+
{
167+
return new GameSave
168+
{
169+
id = originalSave.id,
170+
name = originalSave.name,
171+
content = originalSave.content,
172+
updatedAt = originalSave.updatedAt
173+
};
159174
}
160175

161-
private void UpdateOfflineSaves(GameSave incomingSave)
176+
private GameSave UpdateOfflineSaves(GameSave incomingSave)
162177
{
178+
var offlineIncomingSave = CreateOfflineCopy(incomingSave);
163179
var offlineContent = GetOfflineSavesContent();
164180
var updated = false;
165181

@@ -168,33 +184,34 @@ private void UpdateOfflineSaves(GameSave incomingSave)
168184
// updating
169185
offlineContent.saves = offlineContent.saves.Select((existingSave) =>
170186
{
171-
if (existingSave.id == incomingSave.id)
187+
if (existingSave.id == offlineIncomingSave.id)
172188
{
173189
updated = true;
174-
return incomingSave;
190+
return offlineIncomingSave;
175191
}
176192
return existingSave;
177193
}).ToArray();
178194

179195
// appending
180196
if (!updated)
181197
{
182-
if (incomingSave.id == 0)
198+
if (offlineIncomingSave.id == 0)
183199
{
184-
incomingSave.id = -offlineContent.saves.Length - 1;
200+
offlineIncomingSave.id = -offlineContent.saves.Length - 1;
185201
}
186202

187-
offlineContent.saves = offlineContent.saves.Concat(new GameSave[] { incomingSave }).ToArray();
203+
offlineContent.saves = offlineContent.saves.Concat(new GameSave[] { offlineIncomingSave }).ToArray();
188204
}
189205
}
190206
else
191207
{
192208
// first entry into the saves file
193-
incomingSave.id = -1;
194-
offlineContent = new OfflineSavesContent(new GameSave[] { incomingSave });
209+
offlineIncomingSave.id = -1;
210+
offlineContent = new OfflineSavesContent(new GameSave[] { offlineIncomingSave });
195211
}
196212

197213
WriteOfflineSavesContent(offlineContent);
214+
return offlineIncomingSave;
198215
}
199216

200217
public async Task<GameSave> CreateSave(string saveName, string content = null)
@@ -228,10 +245,12 @@ public async Task<GameSave> CreateSave(string saveName, string content = null)
228245
}
229246

230247
_allSaves.Add(save);
231-
UpdateOfflineSaves(save);
232248

233-
SetChosenSave(save, false);
234-
return save;
249+
var offlineSave = UpdateOfflineSaves(save);
250+
var chosenSave = Talo.IsOffline() ? offlineSave : save;
251+
252+
SetChosenSave(chosenSave, false);
253+
return chosenSave;
235254
}
236255

237256
public async Task<GameSave> UpdateCurrentSave(string newName = "")

Packages/com.trytalo.talo/Runtime/Utils/ContinuityManager.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class ContinuityContent
2424

2525
public class ContinuityManager
2626
{
27-
private readonly string _continuityPath = Application.persistentDataPath + "/talo-continuity.bin";
27+
private readonly string _continuityPath = Application.persistentDataPath + "/tc.bin";
2828

2929
private List<Request> _requests;
3030

@@ -81,6 +81,7 @@ public async void ProcessRequests()
8181
if (!HasRequests() || !await Talo.HealthCheck.Ping()) return;
8282

8383
var queue = new List<Request>(_requests.Take(10));
84+
var exceptions = new List<Exception>();
8485

8586
for (var i = 0; i < queue.Count; i++)
8687
{
@@ -98,7 +99,18 @@ public async void ProcessRequests()
9899
headers.Add(new HttpHeader("X-Talo-Continuity-Timestamp", request.timestamp.ToString()));
99100
}
100101

101-
await _api.Replay(uri, request.method, request.content, headers);
102+
try
103+
{
104+
await _api.Replay(uri, request.method, request.content, headers);
105+
} catch (Exception e)
106+
{
107+
exceptions.Add(e);
108+
}
109+
}
110+
111+
if (exceptions.Count > 0)
112+
{
113+
throw new ContinuityReplayException(exceptions);
102114
}
103115
}
104116
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System;
2+
using System.Collections.Generic;
3+
4+
namespace TaloGameServices
5+
{
6+
public class ContinuityReplayException : Exception
7+
{
8+
private List<Exception> _exceptions;
9+
public List<Exception> Exceptions => _exceptions;
10+
11+
public ContinuityReplayException(List<Exception> exceptions)
12+
: base($"{exceptions.Count} requests failed after being replayed")
13+
{
14+
_exceptions = exceptions;
15+
}
16+
17+
public ContinuityReplayException(List<Exception> exceptions, Exception inner)
18+
: base($"{exceptions.Count} requests failed after being replayed", inner)
19+
{
20+
_exceptions = exceptions;
21+
}
22+
}
23+
}

Packages/com.trytalo.talo/Runtime/Utils/ContinuityReplayException.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Packages/com.trytalo.talo/Runtime/Utils/CryptoManager.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace TaloGameServices
88
{
99
public class CryptoManager
1010
{
11-
private readonly string _keyPath = Application.persistentDataPath + "/talo-init.bin";
11+
private readonly string _keyPath = Application.persistentDataPath + "/ti.bin";
1212

1313
private IFileHandler<string> _fileHandler;
1414

@@ -52,7 +52,7 @@ private byte[] GetAESKey()
5252
{
5353
using (var sha256 = SHA256.Create())
5454
{
55-
return sha256.ComputeHash(Encoding.UTF8.GetBytes(Talo.Settings.accessKey));
55+
return sha256.ComputeHash(Encoding.UTF8.GetBytes(SystemInfo.deviceUniqueIdentifier));
5656
}
5757
}
5858

Packages/com.trytalo.talo/Runtime/Utils/FileHandlers/SavesFileHandler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ public class SavesFileHandler : IFileHandler<OfflineSavesContent>
77
public OfflineSavesContent ReadContent(string path)
88
{
99
if (!File.Exists(path)) return null;
10-
return JsonUtility.FromJson<OfflineSavesContent>(File.ReadAllText(path));
10+
return JsonUtility.FromJson<OfflineSavesContent>(Talo.Crypto.ReadFileContent(path));
1111
}
1212

1313
public void WriteContent(string path, OfflineSavesContent content)
1414
{
15-
File.WriteAllText(path, JsonUtility.ToJson(content));
15+
Talo.Crypto.WriteFileContent(path, JsonUtility.ToJson(content));
1616
}
1717
}

0 commit comments

Comments
 (0)