Ejemplo n.º 1
0
        public static TileResourceCollection FromXmlProxy(LibraryX.TilePoolX proxy, TilePool pool, ITexturePool texturePool)
        {
            if (proxy == null)
            {
                return(null);
            }

            TileResourceCollection collection = new TileResourceCollection(proxy.TileWidth, proxy.TileHeight, pool, texturePool);

            texturePool.RemoveResource(collection.TextureId);

            collection._tileSource = texturePool.GetResource(proxy.Texture);

            if (collection._tileSource != null)
            {
                collection._tileSource.Apply(c => {
                    return((c.A == 0) ? Colors.Transparent : c);
                });
            }

            if (proxy.TileDefinitions != null)
            {
                foreach (var tiledef in proxy.TileDefinitions)
                {
                    TileResourceCollection.FromXmlProxy(tiledef, collection);
                }
            }

            if (collection.TextureResource != null)
            {
                collection.RecalculateOpenLocations();
            }

            return(collection);
        }
Ejemplo n.º 2
0
        private TilePool(LibraryX.TilePoolX proxy, TilePoolManager manager)
            : this()
        {
            _uid  = proxy.Uid;
            _name = new ResourceName(this, proxy.Name);

            Tiles                   = TileResourceCollection.FromXmlProxy(proxy, this, manager.TexturePool);
            Tiles.Modified         += (s, e) => OnModified(EventArgs.Empty);
            Tiles.ResourceAdded    += (s, e) => OnTileAdded(new TileEventArgs(e.Resource));
            Tiles.ResourceRemoved  += (s, e) => OnTileRemoved(new TileEventArgs(e.Resource));
            Tiles.ResourceModified += (s, e) => OnTileModified(new TileEventArgs(e.Resource));

            manager.Pools.Add(this);

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