public static LevelFormat GetLevelData(string levelId) { if (levelId.Length == 0) { return(null); } levelId = levelId.ToUpper(); // Make sure the level exists: string fullLevelPath = LevelContent.GetFullLevelPath(levelId); if (!File.Exists(fullLevelPath)) { return(null); } string json = File.ReadAllText(fullLevelPath); // If there is no JSON content, end the attempt to load level: if (json == "") { return(null); } // Load the Data return(JsonConvert.DeserializeObject <LevelFormat>(json)); }
public bool LoadLevelData(string levelId = "") { levelId = levelId.ToUpper(); // Update the Level ID, or use existing Level ID if applicable. if (levelId.Length > 0) { this.levelId = levelId; } else { return(false); } string fullLevelPath = LevelContent.GetFullLevelPath(this.levelId); // Make sure the level exists: if (!File.Exists(fullLevelPath)) { return(false); } string json = File.ReadAllText(fullLevelPath); // If there is no JSON content, end the attempt to load level: if (json == "") { return(false); } // Load the Data this.data = JsonConvert.DeserializeObject <LevelFormat>(json); return(true); }
// Verify that the level exists in the level directory. public static bool LevelExists(string levelId) { levelId = levelId.ToUpper(); string fullLevelPath = LevelContent.GetFullLevelPath(levelId); return(File.Exists(fullLevelPath)); }