Пример #1
0
        private void LoadMap(TextReader rdr)
        {
            Console.WriteLine("Reading z-level #{0}", world.Levels.Count);

            // (1,1,1) = {"
            ReaderUtils.ReadUntil(rdr, '"');

            // This is awful.
            // In order to load up our array of tiles, we need to know how big the z-level is.
            // Unfortunately, the map does not f*****g tell us what it is immediately, so we
            //  have to figure it out on our own.
            // Which is where this f*****g monstrosity comes in.
            List <List <string> > idmap = new List <List <string> >();
            uint   size_x = 0;
            uint   size_y = 0;
            int    x      = 0;
            int    y      = 0;
            string idbuf;

            while (true)
            {
                idmap.Add(new List <string>());
                string line = rdr.ReadLine();
                if (string.IsNullOrEmpty(line))
                {
                    continue;
                }
                //Console.WriteLine(line);
                if (line.StartsWith("\"}"))
                {
                    break;
                }
                line   = line.Trim();
                size_x = (uint)(line.Length / idlen);
                for (x = 0; x < line.Length; x += idlen)
                {
                    idbuf = line.Substring(x, idlen);
                    idmap[y].Add(idbuf);
                }
                if (idmap[y].Count == 0)
                {
                    throw new InvalidDataException(string.Format("idmap[{0}] is empty.", y));
                }
                y++;
            }
            size_y = (uint)y;

            // And now we build the god damned z-level.
            ZLevel zlevel = world.CreateZLevel(size_y, size_x);

            for (y = 0; y < size_y; y++)
            {
                for (x = 0; x < size_x; x++)
                {
                    zlevel.Tiles[x, y] = Tiles[idmap[y][x]].CopyNew((uint)x, (uint)y, zlevel.Z);
                }
            }
            Console.WriteLine(" -> Loaded {0}x{1} tilemap.", size_x, size_y);
        }
Пример #2
0
        public void LoadMapTest()
        {
            DMMLoader target   = new DMMLoader();
            string    filename = Path.Combine("TestFiles", "TestMap.dmm");

            OpenBYOND.World.World world = new OpenBYOND.World.World();
            target.Load(world, filename);

            Assert.AreEqual(6, world.Levels.Count);

            ZLevel zlev = world.Levels[0];

            Assert.AreEqual(255, zlev.Height);
            Assert.AreEqual(255, zlev.Width);
        }