示例#1
0
文件: Level.cs 项目: Jorch72/obsidian
        public static Level Load(string name)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (name == "")
            {
                throw new ArgumentException("Name musn't be an empty string.", "name");
            }
            if (!RegexHelper.IsAlphaNumeric(name))
            {
                throw new ArgumentException("Only alphanumerical characters allowed.", "name");
            }
            string filename = "levels/" + name + ".lvl";

            try {
                Node node = host.Load(filename, out name);
                if (name != "obsidian-level")
                {
                    return(null);
                }
                short    width     = (short)node["width"].Value;
                short    depth     = (short)node["depth"].Value;
                short    height    = (short)node["height"].Value;
                Node     spawnNode = node["spawn"];
                Position spawn     = new Position(
                    (short)spawnNode["x"].Value, (short)spawnNode["y"].Value, (short)spawnNode["z"].Value,
                    (byte)spawnNode["rotx"].Value, (byte)spawnNode["roty"].Value);
                byte[] mapdata   = (byte[])node["mapdata"].Value;
                byte[] blockdata = (byte[])node["blockdata"].Value;
                Level  level     = new Level(width, depth, height);
                level.spawn.Set(spawn);
                level.mapdata   = mapdata;
                level.blockdata = blockdata;
                level.custom    = node["custom"] ?? level.custom;
                return(level);
            } catch { return(null); }
        }