public static void AddTakenCoins(LevelID lid, IEnumerable <int> indices) { lock (staticMutationLock) { LevelCompletionDetails oldDetails = GetDetails(lid); foreach (var index in indices) { if (oldDetails.CoinIndicesCollected.Contains(index)) { throw new ApplicationException("Error: Can not add coin index '" + index + "' twice."); } } int[] newIndicesArr = new int[oldDetails.CoinIndicesCollected.Count() + indices.Count()]; for (int i = 0; i < newIndicesArr.Length; ++i) { if (i < oldDetails.CoinIndicesCollected.Count()) { newIndicesArr[i] = oldDetails.CoinIndicesCollected.ElementAt(i); } else { newIndicesArr[i] = indices.ElementAt(i - oldDetails.CoinIndicesCollected.Count()); } } LevelCompletionDetails newDetails = new LevelCompletionDetails( oldDetails.GoldenEggClaimed, oldDetails.BestTimeRemainingMs, newIndicesArr ); SetDetails(lid, newDetails); RecalculateSecondHandState(); } }
private static void SetDetails(int worldIndex, int levelIndex, LevelCompletionDetails details) { rawState[worldIndex * 10 + levelIndex] = details; }
private static void SetDetails(LevelID lid, LevelCompletionDetails details) { SetDetails(lid.WorldIndex, lid.LevelIndex, details); }
public static void LoadFromDisk() { lock (staticMutationLock) { try { CreateBlankSaveData(); var userID = LeaderboardManager.LocalPlayerDetails.SteamID; var userKey = userID >> 1; Logger.Log("Loading data for userID " + userID + "..."); string filepath = Path.Combine(LosgapSystem.MutableDataDirectory.FullName, userID + FILE_NAME_SUFFIX); if (!File.Exists(filepath)) { Logger.Log("No save data found for userID '" + userID + "' (at " + filepath + "): Using blank save data."); return; } try { string unencryptedFile = UnencryptData(File.ReadAllText(filepath), userKey); string[] lines = unencryptedFile.Split("\r\n", StringSplitOptions.RemoveEmptyEntries); foreach (var line in lines) { string[] lineSplit = line.Split(' '); if (lineSplit.Length != 2) { Logger.Warn("Invalid save file line: " + line); continue; } var header = lineSplit[0]; string[] headerSplit = header.Split(':'); if (headerSplit.Length != 2) { Logger.Warn("Invalid save file line: " + line); continue; } int worldIndex, levelIndex; bool validWorldIndex = Int32.TryParse(headerSplit[0], out worldIndex); bool validLevelIndex = Int32.TryParse(headerSplit[1], out levelIndex); if (!validWorldIndex || !validLevelIndex || worldIndex < 0 || worldIndex > 10 || levelIndex < 0 || levelIndex > 9) { Logger.Warn("Invalid save file line: " + line); continue; } var contentSplit = lineSplit[1].Split('/'); if (contentSplit.Length != 3) { Logger.Warn("Invalid save file line: " + line); continue; } bool eggClaimed; bool validEggClaimed = Boolean.TryParse(contentSplit[0], out eggClaimed); if (!validEggClaimed) { Logger.Warn("Invalid save file line: " + line); continue; } int?bestTimeMs = null; if (contentSplit[1] != String.Empty) { int outBestTime; bool validTime = Int32.TryParse(contentSplit[1], out outBestTime); if (!validTime) { Logger.Warn("Invalid save file line: " + line); continue; } else { bestTimeMs = outBestTime; } } string[] unlockedCoinStrings = contentSplit[2].Split('-', StringSplitOptions.RemoveEmptyEntries); int[] unlockedCoinIndices = new int[unlockedCoinStrings.Length]; for (int i = 0; i < unlockedCoinStrings.Length; ++i) { int index; bool validIndex = Int32.TryParse(unlockedCoinStrings[i], out index); if (!validIndex) { Logger.Warn("Invalid save file line: " + line); goto innerLoopBreak; } unlockedCoinIndices[i] = index; } LevelCompletionDetails lcd = new LevelCompletionDetails(eggClaimed, bestTimeMs, unlockedCoinIndices); SetDetails(worldIndex, levelIndex, lcd); innerLoopBreak: Logger.Debug(""); } } catch (Exception e) { Logger.Warn("Could not open save data for Steam ID '" + userKey + "'. See associated error information. Creating blank save data.", e); CreateBlankSaveData(); } } finally { RecalculateSecondHandState(); } } }