private async static Task <LevelProgress[]> FetchDataFromFireBase() { LevelProgress[] result = null; await FireBaseDatabase.Database.Child(FireBaseSavePaths.PlayerProgressLocation()) .GetValueAsync().ContinueWith(task => { if (task.IsFaulted) { } else if (task.IsCompleted) { try { DataSnapshot snapshot = task.Result; string info = snapshot?.GetRawJsonValue()?.ToString(); if (info != null) { result = JsonHelper.FromJson <LevelProgress>(info); } } catch (Exception ex) { Debug.LogError(ex); } } }); return(result); }
public void WriteException(Exception ex) { string output = $"{DateTime.Now} - ERROR - {ex.Message}{Environment.NewLine}{ex.StackTrace}"; Debug.LogError(output); FireBaseDatabase.AddUniqueString(FireBaseSavePaths.ExceptionLocation(), output); }
private void UpdateValue(string chapter, int level, Vector2Int pos, int used) { string key = $"{pos.x}:{pos.y}"; FireBaseDatabase.Database.Child(FireBaseSavePaths.HeatMapLocation(chapter, level)).RunTransaction(mutableData => { List <object> storedData = mutableData.Value as List <object>; if (storedData == null) { storedData = new List <object>(); } int newUses = used; foreach (var child in storedData) { var parsedChild = child as Dictionary <string, object>; if (parsedChild == null) { continue; } if (!parsedChild.ContainsKey("Key")) { continue; } if (parsedChild["Key"].ToString() != key) { continue; } if (!parsedChild.ContainsKey("Uses")) { continue; } string data = parsedChild["Uses"].ToString(); int childValue = int.Parse(data); newUses += childValue; storedData.Remove(child); break; } Dictionary <string, object> newMap = new Dictionary <string, object>(); newMap["Key"] = key; newMap["Uses"] = newUses; storedData.Add(newMap); mutableData.Value = storedData; return(TransactionResult.Success(mutableData)); } ); }
public void SaveDailyChallenge(int score) { var entry = new ScoreEntry() { User = UserManager.UserID, Score = score, Date = DateTime.Now.ToString() }; var jsonValue = JsonUtility.ToJson(entry); FireBaseDatabase.AddUniqueJSON(FireBaseSavePaths.DailyChallengeLocation(DateTime.Now), jsonValue); }
public void GetScoresAsync(string chapter, int level) { try { var t = new Task(() => { var result = FireBaseReader.ReadAsync <LevelScoreEntry>(FireBaseSavePaths.ScoreLocation(chapter, level + 1)); ScoresLoaded?.Invoke(result.Result); }); t.Start(); } catch (Exception ex) { DebugLogger.Instance.WriteException(ex); } }
public void GetDailyScoresAsync() { try { var t = new Task(() => { var result = FireBaseReader.ReadSingleAsync <ScoreEntry>(FireBaseSavePaths.DailyChallengeLocation(DateTime.Now)); DailyScoresLoaded?.Invoke(result.Result); }); t.Start(); } catch (Exception ex) { DebugLogger.Instance.WriteException(ex); } }
public void SaveScore(string chapter, int level, int star, int score, GameResult result) { var entry = new LevelScoreEntry() { Chapter = chapter, Level = level, Star = star, Date = DateTime.Now.ToString(), Result = result, Score = score, User = UserManager.UserID }; var jsonValue = JsonUtility.ToJson(entry); FireBaseDatabase.AddUniqueJSON(FireBaseSavePaths.ScoreLocation(chapter, level, star), jsonValue); }
public void GetHeatmapAsync(string chapter, int level) { try { FireBaseDatabase.Database.Child(FireBaseSavePaths.HeatMapLocation(chapter, level)) .GetValueAsync().ContinueWith(task => { if (task.IsFaulted) { } else if (task.IsCompleted) { try { DataSnapshot snapshot = task.Result; var result = new Dictionary <string, int>(); var list = snapshot.Value as List <object>; foreach (var item in list) { var parsedChild = item as Dictionary <string, object>; var key = parsedChild["Key"].ToString(); var uses = parsedChild["Uses"].ToString(); int childValue = int.Parse(uses); result.Add(key, childValue); } HeatmapLoaded?.Invoke(result); } catch (Exception ex) { Debug.LogError(ex); } } }); } catch { } }
public async Task LoadPieceCollectionAsync() { try { await FireBaseDatabase.Database.Child(FireBaseSavePaths.PlayerCollectionLocation()) .GetValueAsync().ContinueWith(task => { if (task.IsFaulted) { } else if (task.IsCompleted) { try { DataSnapshot snapshot = task.Result; string info = snapshot?.GetRawJsonValue()?.ToString(); var array = new PiecesCollected.PieceCollectionInfo[0]; if (info != null) { array = JsonHelper.FromJson <PiecesCollected.PieceCollectionInfo>(info); } var result = new PiecesCollected(); if (array != null) { result.Pieces.AddRange(array); } PieceCollectionManager.Instance.PiecesCollected = result; } catch (Exception ex) { Debug.LogError(ex); } } }); } catch { } }
public async Task ReadEquippedPowerupsAsync() { try { await FireBaseDatabase.Database.Child(FireBaseSavePaths.PlayerEquippedPowerupLocation()) .GetValueAsync().ContinueWith(task => { if (task.IsFaulted) { } else if (task.IsCompleted) { try { DataSnapshot snapshot = task.Result; string info = snapshot?.GetRawJsonValue()?.ToString(); var result = new string[0]; if (info != null) { result = JsonHelper.FromJson <string>(info); } for (int i = 0; i < result.Length; i++) { UserPowerupManager.Instance.EquippedPowerups[i] = PowerupFactory.GetPowerup(result[i]); } } catch (Exception ex) { Debug.LogError(ex); } } }); } catch (Exception ex) { DebugLogger.Instance.WriteException(ex); } }
public async Task ReadPowerupsAsync() { try { await Task.Run(() => { var result = FireBaseReader.ReadAsync <PowerupEntity>(FireBaseSavePaths.PlayerPowerupLocation()); foreach (var entity in result.Result) { UserPowerupManager.Instance.Powerups.Add(new PowerupCollection() { Powerup = PowerupFactory.GetPowerup(entity.Name), Count = entity.Count }); } }); } catch (Exception ex) { DebugLogger.Instance.WriteException(ex); } }
public async Task ReadLivesAsync() { try { await FireBaseDatabase.Database.Child(FireBaseSavePaths.PlayerLivesLocation()) .GetValueAsync().ContinueWith(task => { if (task.IsFaulted) { } else if (task.IsCompleted) { try { DataSnapshot snapshot = task.Result; string info = snapshot?.GetRawJsonValue()?.ToString(); LivesEntity result = null; if (info != null) { result = JsonUtility.FromJson <LivesEntity>(info); } LivesManager.Instance.Setup(result); } catch (Exception ex) { Debug.LogError(ex); } } }); } catch (Exception ex) { Debug.LogError(ex); } }
public void WriteLives(int livesRemaining, DateTime lastEarnedLife) { var entity = new LivesEntity() { LastEarnedLife = lastEarnedLife.ToString(), LivesRemaining = livesRemaining }; var toJson = JsonUtility.ToJson(entity); var result = System.Threading.Tasks.Task.Run(() => FireBaseDatabase.Database.Child(FireBaseSavePaths.PlayerLivesLocation()).SetRawJsonValueAsync(toJson)); if (result.IsCanceled || result.IsFaulted) { Debug.LogWarning(result.Exception); } }
public void WritePiecesCollected(PiecesCollected pieces) { var toJson = JsonHelper.ToJson(pieces.Pieces.ToArray()); var result = System.Threading.Tasks.Task.Run(() => FireBaseDatabase.Database.Child(FireBaseSavePaths.PlayerCollectionLocation()).SetRawJsonValueAsync(toJson)); if (result.IsCanceled || result.IsFaulted) { Debug.LogWarning(result.Exception); } }
public void WriteEquippedPowerups(IPowerup[] powerups) { var data = powerups.Select(x => x.GetType().Name).ToArray(); var toJson = JsonHelper.ToJson(data); var result = System.Threading.Tasks.Task.Run(() => FireBaseDatabase.Database.Child(FireBaseSavePaths.PlayerEquippedPowerupLocation()).SetRawJsonValueAsync(toJson)); if (result.IsCanceled || result.IsFaulted) { Debug.LogWarning(result.Exception); } }
public void WritePowerups(List <PowerupCollection> powerups) { var data = new List <PowerupEntity>(); foreach (PowerupCollection powerupCollected in powerups) { data.Add(new PowerupEntity() { Name = powerupCollected.Powerup.GetType().Name, Count = powerupCollected.Count }); } var toJson = JsonHelper.ToJson(data.ToArray()); var result = System.Threading.Tasks.Task.Run(() => FireBaseDatabase.Database.Child(FireBaseSavePaths.PlayerPowerupLocation()).SetRawJsonValueAsync(toJson)); if (result.IsCanceled || result.IsFaulted) { Debug.LogWarning(result.Exception); } }
public void SaveLevelProgress(LevelProgress[] levelProgress) { var toJson = JsonHelper.ToJson(levelProgress); var result = System.Threading.Tasks.Task.Run(() => FireBaseDatabase.Database.Child(FireBaseSavePaths.PlayerProgressLocation()).SetRawJsonValueAsync(toJson)); if (result.IsCanceled || result.IsFaulted) { Debug.LogWarning(result.Exception); } }