public static Models.GameProgress Deserialize(string serializedGameProgress) { Csv csv = new Csv (serializedGameProgress); int[] savedGameData = csv.ToIntArray (); int dataIndex = 0; Models.GameProgress gameProgress = new Models.GameProgress (savedGameData [dataIndex++]); while (dataIndex < savedGameData.Length) { int worldNumber = savedGameData [dataIndex++]; int levelNumber = savedGameData [dataIndex++]; int moves = savedGameData [dataIndex++]; int stars = savedGameData [dataIndex++]; Models.SolvedLevel solvedLevel = new Models.SolvedLevel (worldNumber, levelNumber, moves, stars); gameProgress.AddSolvedLevel (solvedLevel); } return gameProgress; }
/// <summary> /// Deserialize the specified serializedLockGrid: see Serialize. /// </summary> /// <param name="serializedLockGrid">Serialized lock grid.</param> public static Models.LockGrid Deserialize(string serializedLockGrid) { Csv csv = new Csv (serializedLockGrid); int[] values = csv.ToIntArray (); int valueIndex = 0; // Deserialize the lock grid properties int rowCount = values [valueIndex++]; int colCount = values [valueIndex++]; int buttonCount = values [valueIndex++]; int maxMovesFor2Stars = values [valueIndex++]; int maxMovesFor3Stars = values [valueIndex++]; Models.LockGrid lockGrid = new Models.LockGrid (rowCount, colCount, buttonCount, maxMovesFor2Stars, maxMovesFor3Stars); // Deserialize the locks and buttons for (int row=0; row<rowCount; row++) { for (int col=0; col<colCount; col++) { Models.Lock currentLock = lockGrid.Locks [row, col]; // Deserialize the lock properties //currentLock.UnlockedPosition = values [valueIndex++]; currentLock.CurrentPosition = values [valueIndex++]; // Deserialize the buttons for (int buttonIndex=0; buttonIndex<buttonCount; buttonIndex++) { Models.LockButton button = currentLock.Buttons [buttonIndex]; button.IsOn = (values [valueIndex++] == 1); int linkedButtonRow = values[valueIndex++]; int linkedButtonCol = values [valueIndex++]; int linkedButtonIndex = values [valueIndex++]; if (button.IsUnlinked ()) { button.LinkWithButton (lockGrid.GetButtonAt (linkedButtonRow, linkedButtonCol, linkedButtonIndex)); } } } } return lockGrid; }