public static LevelPack ParseLevelPack(string packID, string serializedLevelPack)
            {
                if (string.IsNullOrWhiteSpace(packID))
                {
                    throw new Exception($"Pack ID was not valid [{packID}]");
                }

                try
                {
                    // Parse the string as JSON
                    JObject levelJSON = JObject.Parse(serializedLevelPack);
                    if (levelJSON == null)
                    {
                        throw new InvalidSerializedLevelPackException("Level was not valid JSON");
                    }

                    var packName = levelJSON.Value <string>("PackName");
                    if (string.IsNullOrWhiteSpace(packName))
                    {
                        throw new InvalidSerializedLevelPackException($"Pack name was not valid [{packName}]");
                    }

                    var levelInfosJSON = (JArray)levelJSON["Levels"];
                    if (levelInfosJSON == null || levelInfosJSON.Count < 1)
                    {
                        throw new InvalidSerializedLevelPackException("Level pack did not contain any levels");
                    }

                    var levelInfos = new LevelList();
                    foreach (var levelInfoJSON in levelInfosJSON)
                    {
                        var levelInfo = ParseLevelInfo(levelInfoJSON, levelInfos.Count);
                        levelInfos.Add(levelInfo);
                    }

                    var levelPack = new LevelPack(packID, packName, levelInfos);
                    return(levelPack);
                }
                catch (Exception ex)
                {
                    throw new InvalidSerializedLevelPackException("Unable to parse level", ex);
                }
            }
Ejemplo n.º 2
0
        public void AddLevel(string name, int needExp, int allowPoints)
        {
            TLevel level = new TLevel(name, needExp, allowPoints);

            LevelList.Add(level);
        }