Esempio n. 1
0
        public Tile Add(TextureResource texture)
        {
            if (texture.Width != TileWidth || texture.Height != TileHeight)
            {
                throw new ArgumentException("Supplied texture does not have tile dimensions", "texture");
            }

            Tile tile = new PhysicalTile()
            {
                Pool = _pool
            };

            if (ShouldExpandTexture())
            {
                ExpandTexture();
            }

            TileCoord coord = _openLocations[_openLocations.Count - 1];

            _openLocations.RemoveAt(_openLocations.Count - 1);

            _tileSource.Set(texture, new Point(coord.X * TileWidth, coord.Y * TileHeight));
            _texturePool.Invalidate(_tileSource.Uid);

            _locations[tile.Uid] = coord;

            Add(tile);

            return(tile);
        }
Esempio n. 2
0
        public void CreatePhysicalTile()
        {
            Tile tile = new PhysicalTile(1, _pool);

            Assert.AreEqual(1, tile.Uid);
            Assert.AreEqual(_pool, tile.Pool);
            Assert.AreEqual(_pool.TileWidth, tile.Width);
            Assert.AreEqual(_pool.TileHeight, tile.Height);
        }
Esempio n. 3
0
        public static Tile FromXmlProxy(LibraryX.TileDefX proxy, TileResourceCollection tileCollection)
        {
            if (proxy == null)
            {
                return(null);
            }

            string[] loc = proxy.Location.Split(new char[] { ',' });
            if (loc.Length != 2)
            {
                throw new Exception("Malformed location: " + proxy.Location);
            }

            int x = Convert.ToInt32(loc[0]);
            int y = Convert.ToInt32(loc[1]);

            if (x < 0 || y < 0)
            {
                throw new Exception("Invalid location: " + proxy.Location);
            }

            TileCoord coord = new TileCoord(x, y);
            Tile      tile  = new PhysicalTile(proxy.Uid)
            {
                Pool = tileCollection._pool,
            };

            if (proxy.Properties != null)
            {
                foreach (var propertyProxy in proxy.Properties)
                {
                    tile.PropertyManager.CustomProperties.Add(Property.FromXmlProxy(propertyProxy));
                }
            }

            tileCollection._locations[tile.Uid] = coord;
            tileCollection.Add(tile);

            return(tile);
        }
Esempio n. 4
0
        public void UpdatePhysicalTileData()
        {
            Tile tile = new PhysicalTile(1, _pool);
            AttachEvents(tile);

            byte[] data = new byte[16 * 16 * 4];
            for (int i = 0; i < data.Length; i++)
                data[i] = (byte)(i % 255);

            tile.TextureModified += (s, e) =>
            {
                byte[] comp = _pool.GetTileTextureData(1);
                Assert.AreEqual(data.Length, comp.Length);
                for (int i = 0; i < comp.Length; i++) {
                    Assert.AreEqual(data[i], comp[i]);
                }
            };

            tile.Update(data);

            Assert.AreEqual(EventFlags.Modified | EventFlags.TextureModified, _eventsFired);
        }