INI parser used by MapMyne.
Exemplo n.º 1
0
        private static Map LoadMeta([NotNull] Stream stream)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }
            INIFile metaFile = new INIFile(stream);

            if (metaFile.IsEmpty)
            {
                throw new Exception("Metadata file is empty or incorrectly formatted.");
            }
            if (!metaFile.Contains("size", "x", "y", "z"))
            {
                throw new Exception("Metadata file is missing map dimensions.");
            }

            int width  = Int32.Parse(metaFile["size", "x"]);
            int length = Int32.Parse(metaFile["size", "z"]);
            int height = Int32.Parse(metaFile["size", "y"]);

            Map map = new Map(null, width, length, height, false);

            if (!map.ValidateHeader())
            {
                throw new MapFormatException("One or more of the map dimensions are invalid.");
            }

            if (metaFile.Contains("spawn", "x", "y", "z", "h"))
            {
                map.Spawn = new Position
                {
                    X = (short)(Int16.Parse(metaFile["spawn", "x"]) * 32 + 16),
                    Y = (short)(Int16.Parse(metaFile["spawn", "z"]) * 32 + 16),
                    Z = (short)(Int16.Parse(metaFile["spawn", "y"]) * 32 + 16),
                    R = Byte.Parse(metaFile["spawn", "h"]),
                    L = 0
                };
            }
            return(map);
        }
Exemplo n.º 2
0
        static Map LoadMeta(Stream stream)
        {
            INIFile metaFile = new INIFile(stream);

            if (metaFile.IsEmpty())
            {
                throw new Exception("Metadata file is empty or incorrectly formatted.");
            }
            if (!metaFile.Contains("size", "x", "y", "z"))
            {
                throw new Exception("Metadata file is missing map dimensions.");
            }

            int widthX = Int32.Parse(metaFile["size", "x"]);
            int widthY = Int32.Parse(metaFile["size", "z"]);
            int height = Int32.Parse(metaFile["size", "y"]);

            Map map = new Map(null, widthX, widthY, height, false);

            if (!map.ValidateHeader())
            {
                throw new MapFormatException("One or more of the map dimensions are invalid.");
            }

            if (metaFile.Contains("spawn", "x", "y", "z", "h"))
            {
                Position spawn = new Position {
                    X = (short)(Int16.Parse(metaFile["spawn", "x"]) * 32 + 16),
                    Y = (short)(Int16.Parse(metaFile["spawn", "z"]) * 32 + 16),
                    H = (short)(Int16.Parse(metaFile["spawn", "y"]) * 32 + 16),
                    R = Byte.Parse(metaFile["spawn", "h"]),
                    L = 0
                };
                map.SetSpawn(spawn);
            }
            else
            {
                map.ResetSpawn();
            }
            return(map);
        }
Exemplo n.º 3
0
        static Map LoadMeta( Stream stream ) {
            INIFile metaFile = new INIFile( stream );
            if( metaFile.IsEmpty() ) {
                throw new Exception( "Metadata file is empty or incorrectly formatted." );
            }
            if( !metaFile.Contains( "size", "x", "y", "z" ) ) {
                throw new Exception( "Metadata file is missing map dimensions." );
            }

            int widthX = Int32.Parse( metaFile["size", "x"] );
            int widthY = Int32.Parse( metaFile["size", "z"] );
            int height = Int32.Parse( metaFile["size", "y"] );

            Map map = new Map( null, widthX, widthY, height, false );

            if( !map.ValidateHeader() ) {
                throw new MapFormatException( "One or more of the map dimensions are invalid." );
            }

            if( metaFile.Contains( "spawn", "x", "y", "z", "h" ) ) {
                Position spawn = new Position {
                    X = (short)(Int16.Parse( metaFile["spawn", "x"] ) * 32 + 16),
                    Y = (short)(Int16.Parse( metaFile["spawn", "z"] ) * 32 + 16),
                    H = (short)(Int16.Parse( metaFile["spawn", "y"] ) * 32 + 16),
                    R = Byte.Parse( metaFile["spawn", "h"] ),
                    L = 0
                };
                map.SetSpawn( spawn );
            } else {
                map.ResetSpawn();
            }
            return map;
        }
Exemplo n.º 4
0
        static Map LoadMeta( [NotNull] Stream stream )
        {
            if( stream == null ) throw new ArgumentNullException( "stream" );
            INIFile metaFile = new INIFile( stream );
            if( metaFile.IsEmpty ) {
                throw new Exception( "Metadata file is empty or incorrectly formatted." );
            }
            if( !metaFile.Contains( "size", "x", "y", "z" ) ) {
                throw new Exception( "Metadata file is missing map dimensions." );
            }

            int width = Int32.Parse( metaFile["size", "x"] );
            int length = Int32.Parse( metaFile["size", "z"] );
            int height = Int32.Parse( metaFile["size", "y"] );

            Map map = new Map( null, width, length, height, false );

            if( !map.ValidateHeader() ) {
                throw new MapFormatException( "One or more of the map dimensions are invalid." );
            }

            if( metaFile.Contains( "spawn", "x", "y", "z", "h" ) ) {
                map.Spawn = new Position {
                    X = (short)(Int16.Parse( metaFile["spawn", "x"] ) * 32 + 16),
                    Y = (short)(Int16.Parse( metaFile["spawn", "z"] ) * 32 + 16),
                    Z = (short)(Int16.Parse( metaFile["spawn", "y"] ) * 32 + 16),
                    R = Byte.Parse( metaFile["spawn", "h"] ),
                    L = 0
                };
            }
            return map;
        }