private void UpdatePlayerHistory() { string accountId = ChosenPlayer.accountId; bool fileExists = File.Exists(FilePaths.PLAYER_HISTORY(accountId, Server)); if (fileExists) { History savedHistory = DataManager.LoadPlayerHistory(accountId, Server); if (savedHistory.LastGameId == -1) { Console.WriteLine($"Player {ChosenPlayer.name} has no history saved. A new one will be created."); } else { Instant lastMatch = Instant.FromEpochSeconds(savedHistory.matches[0].timestamp / 1000); Console.WriteLine($"Player {ChosenPlayer.name} has a history saved," + $" with the last game played on {lastMatch.ToString("dddd, MMMM d, yyyy - HH:mm")}." + $" Their history will now be updated."); } savedHistory = UpdateHistoryFromApi(savedHistory, ChosenPlayer, Server); DataManager.SavePlayerHistory(savedHistory, accountId, Server); } else { Console.WriteLine($"Player {ChosenPlayer.name} has no history saved. A new one will be created."); History history = GetFullHistoryFromApi(ChosenPlayer, Server); DataManager.SavePlayerHistory(history, accountId, Server); } }
public static History LoadPlayerHistory(string accountId, string server) { string sJson = File.ReadAllText(FilePaths.PLAYER_HISTORY(accountId, server)); if (string.IsNullOrEmpty(sJson)) { return(null); } else { return(JsonConvert.DeserializeObject <History>(sJson)); } }
//private JsonSerializer json = new JsonSerializer() { Formatting = Formatting.Indented }; public static List <Player> LoadPlayerList(string server) { string sJson = File.ReadAllText(FilePaths.PLAYER_KEYS(server)); if (string.IsNullOrEmpty(sJson)) { return(null); } else { return(JsonConvert.DeserializeObject <List <Player> >(sJson)); } }
public static void SavePlayerHistory(History history, string accountId, string server) { string sJson = JsonConvert.SerializeObject(history, Formatting.Indented); File.WriteAllText(FilePaths.PLAYER_HISTORY(accountId, server), sJson); }