public static LibraryX.TilePoolX ToXProxy(TilePool pool) { if (pool == null) { return(null); } List <LibraryX.TileDefX> tiledefs = new List <LibraryX.TileDefX>(); foreach (Tile tile in pool._tiles) { tiledefs.Add(TileResourceCollection.ToXmlProxyX(tile)); } List <CommonX.PropertyX> props = new List <CommonX.PropertyX>(); foreach (Property prop in pool.PropertyManager.CustomProperties) { props.Add(Property.ToXmlProxyX(prop)); } return(new LibraryX.TilePoolX() { Uid = pool.Uid, Name = pool.Name, Texture = pool.Tiles.TextureId, TileWidth = pool.TileWidth, TileHeight = pool.TileHeight, TileDefinitions = tiledefs.Count > 0 ? tiledefs : null, Properties = props.Count > 0 ? props : null, }); }
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); }
internal TilePool(TilePoolManager manager, string name, int tileWidth, int tileHeight) : this() { _name = new ResourceName(this, name); _tiles = new TileResourceCollection(tileWidth, tileHeight, 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)); }
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); }
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)); } } }