// Create New public PlayerProgress(string username) { // cache string[] directory = new string[] { username, directoryName }; int maxSeasonLength = 4; seasons = new SeasonData[maxSeasonLength]; for (int i = 0; i < maxSeasonLength; i++) { var type = (Season)i; seasons[i] = new SeasonData(type); seasons[i].Save(username); } // For Wrapper Data lastLevelLoaded = new LevelIdentification((Season)0, (Difficulty)0); maxLevelAchieved = new LevelIdentification((Season)0, (Difficulty)0); var newDataWrapper = new PlayerProgressWrapper(this); SaveManager.Save(directory, dataFileName, newDataWrapper); // QUESTION: // What is PlayerProgressWrapper use for? // It is a PlayerProgress data without "SeasonData" in it, the purpose is to shorten the save and organize it in different files. }
// Save public PlayerProgressWrapper(PlayerProgress progressData) { lastLevelLoaded = progressData.lastLevelLoaded; maxLevelAchieved = progressData.maxLevelAchieved; // seasons = progressData.seasons; // seasons are saved separately (Different folder and files). }
public bool IsEqualTo(LevelIdentification compare) // called from LevelLoader { bool isSeasonsSame = season == compare.season; bool isDifficultySame = difficulty == compare.difficulty; bool isLevelSame = level == compare.level; return(isSeasonsSame && isDifficultySame && isLevelSame); }
// Override for "Get Level Data" public LevelData GetData(LevelIdentification identification) // Called from "LevelSelect_LevelButton" { return(GetData( identification.season, identification.difficulty, identification.level )); }
// Level public bool IsLocked(LevelIdentification identification) // use from: Level manager "OnLevelFinished", LevelSelect_LevelButton "Setup" // check it on DifficultyData, because it holds the levels array { var season = seasons[(int)identification.season]; var difficulty = season.difficulties[(int)identification.difficulty]; bool isLevelLocked = difficulty.IsLevelLocked(identification.level); return(isLevelLocked); }
// default constructor, no arguments (no specific use, but can be handy in some situation when instantiating an empty "PlayerProgress") public PlayerProgress() { lastLevelLoaded = new LevelIdentification((Season)0, (Difficulty)0); maxLevelAchieved = new LevelIdentification((Season)0, (Difficulty)0); seasons = new SeasonData[] { new SeasonData(Season.Spring), new SeasonData(Season.Summer), new SeasonData(Season.Autumn), new SeasonData(Season.Winter) }; }
public void SaveProgress(LevelIdentification levelId, LevelData newData) { var currentSeasonData = GetData(levelId.season); var currentDiffculty = currentSeasonData.difficulties[(int)levelId.difficulty]; var currentLevel = currentDiffculty.levels[levelId.level]; currentLevel = newData; var directory = new string[] { GetUser().name, PlayerProgress.directoryName }; var fileName = levelId.season.ToString(); SaveManager.Save(directory, fileName, currentSeasonData); }
public LevelIdentification ResumeLevel() { var resumeLevel = new LevelIdentification(); for (int i = 0; i < seasons.Length; i++) { var season = seasons[i]; if (!season.IsCompleted()) { resumeLevel = season.ResumeLevel(); break; } } return(resumeLevel); }
public LevelIdentification ResumeLevel() { // get the first level searched that has no key, no star acquired. var resumeLevel = new LevelIdentification(type); for (int i = 0; i < difficulties.Length; i++) { var difficulty = difficulties[i]; if (!difficulty.IsCompleted()) { resumeLevel.difficulty = (Difficulty)i; resumeLevel.level = difficulty.ResumeLevel(); break; } } return(resumeLevel); }
// Enums // Dynamic, Clamped to Season, Clamped to Difficulty public LevelIdentification Next() { // Cache int nextSeasonIndex = (int)season; int nextDifficultyIndex = (int)difficulty; int nextLevelIndex = level; // Increment Level index nextLevelIndex++; if (nextLevelIndex > maxLevelIndex) { nextLevelIndex = minimumIndex; // 0 // Increment Difficulty index nextDifficultyIndex++; if (nextDifficultyIndex > maxDifficultyIndex) { nextDifficultyIndex = minimumIndex; // 0 // Increment Season nextSeasonIndex++; nextSeasonIndex = nextSeasonIndex % maxSeasonIndex; } } // Convert to orginal types var next = new LevelIdentification( (Season)nextSeasonIndex, (Difficulty)nextDifficultyIndex, nextLevelIndex ); // Debug.Log("CURRENT: " + ToString()); // Debug.Log("NEXT: " + next.ToString()); return(next); }
public LevelIdentification IsMaxLevelAchieved(LevelIdentification newEntry) { // check for highest season // check for highest difficulty // check for highest level id LevelIdentification output = maxLevelAchieved; // predetermine the output // check for highest season int newSeason = (int)newEntry.season; int currentSeason = (int)maxLevelAchieved.season; if (newSeason > currentSeason) { output = newEntry; } else { int newDifficulty = (int)newEntry.difficulty; int currentDifficulty = (int)maxLevelAchieved.difficulty; if (newDifficulty > currentDifficulty) { output = newEntry; } else { int newLevel = newEntry.level; int currentLevel = maxLevelAchieved.level; if (newLevel > currentLevel) { output = newEntry; } } } return(output); }
public LevelIdentification Previous() // NO USE YET // Cache { int prevSeasonIndex = (int)season; int prevDifficultyIndex = (int)difficulty; int prevLevelIndex = level; // Decrement Level Index prevLevelIndex--; if (prevLevelIndex < minimumIndex) { prevLevelIndex = maxLevelIndex; // Decrement Difficulty Index prevDifficultyIndex--; if (prevDifficultyIndex < minimumIndex) { prevDifficultyIndex = maxDifficultyIndex; // Decrement Season Index prevSeasonIndex--; prevSeasonIndex = prevSeasonIndex % maxSeasonIndex; } } // Convert to orginal types var previous = new LevelIdentification( (Season)prevSeasonIndex, (Difficulty)prevDifficultyIndex, prevLevelIndex ); // Debug.Log("CURRENT: " + ToString()); // Debug.Log("PREVIOUS: " + previous.ToString()); return(previous); }
// Load public PlayerProgress(PlayerProgressWrapper dataWrapper) { lastLevelLoaded = dataWrapper.lastLevelLoaded; maxLevelAchieved = dataWrapper.maxLevelAchieved; seasons = dataWrapper.seasons; }
public LevelData GetData(LevelIdentification levelId) { var progressData = GetPlayerProgress(); return(progressData.GetData(levelId)); }