public void Merge(TilePool pool, TileImportPolicy policy) { Dictionary <string, Tile> existingHashes = new Dictionary <string, Tile>(); Dictionary <string, Tile> newHashes = new Dictionary <string, Tile>(); using (SHA1CryptoServiceProvider sha1 = new SHA1CryptoServiceProvider()) { foreach (Tile tile in _tiles) { TextureResource tileTex = Tiles.GetTileTexture(tile.Uid); string hash = Convert.ToBase64String(sha1.ComputeHash(tileTex.RawData)); existingHashes[hash] = tile; } foreach (Tile tile in pool.Tiles) { TextureResource tileTex = pool.Tiles.GetTileTexture(tile.Uid); string hash = Convert.ToBase64String(sha1.ComputeHash(tileTex.RawData)); if (policy == TileImportPolicy.SourceUnique && newHashes.ContainsKey(hash)) { continue; } else if (policy == TileImportPolicy.SetUnique && existingHashes.ContainsKey(hash)) { continue; } Tile newTile = _tiles.Add(tileTex); existingHashes[hash] = newTile; newHashes[hash] = newTile; } } }
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); }
private StaticTileBrush(LibraryX.StaticTileBrushX proxy, TilePoolManager manager) : base(proxy.Uid, proxy.Name, proxy.TileWidth, proxy.TileHeight) { _tiles = new Dictionary <TileCoord, TileStack>(); if (proxy.Tiles != null) { foreach (var stack in proxy.Tiles) { string[] coord = stack.At.Split(','); string[] tileIds = stack.Items.Split(','); int x = (coord.Length > 0) ? Convert.ToInt32(coord[0].Trim()) : 0; int y = (coord.Length > 1) ? Convert.ToInt32(coord[1].Trim()) : 0; foreach (string tileId in tileIds) { Guid id = new Guid(tileId.Trim()); TilePool pool = manager.PoolFromItemKey(id); if (pool == null) { continue; } AddTile(new TileCoord(x, y), pool.GetTile(id)); } } } Normalize(); }
//private Guid _textureId; public TileResourceCollection(int tileWidth, int tileHeight, TilePool pool, ITexturePool texturePool) { _pool = pool; _texturePool = texturePool; TileWidth = tileWidth; TileHeight = tileHeight; _locations = new Dictionary <Guid, TileCoord>(); _openLocations = new List <TileCoord>(); _tileSource = new TextureResource(TileWidth * _initFactor, TileHeight * _initFactor); _texturePool.AddResource(_tileSource); for (int x = 0; x < _initFactor; x++) { for (int y = 0; y < _initFactor; y++) { _openLocations.Add(new TileCoord(x, y)); } } }
private void ParseTileBlockString(string blockString) { string[] tokens = blockString.Split(new char[] { ' ' }); ITilePoolManager manager = Level.Project.TilePoolManager; for (int i = 0; i < tokens.Length; i += 3) { if (tokens.Length - i < 3) { break; } int x = int.Parse(tokens[i + 0]); int y = int.Parse(tokens[i + 1]); int count = int.Parse(tokens[i + 2]); if (tokens.Length - i < 3 + count) { break; } for (int j = 0; j < count; j++) { int tileId = int.Parse(tokens[i + 3 + j]); if (Level.TileIndex.ContainsKey(tileId)) { Guid tileUid = Level.TileIndex[tileId]; TilePool pool = manager.PoolFromItemKey(tileUid); Tile tile = pool.GetTile(tileUid); AddTile(x, y, tile); } } i += count; } }
private DynamicTileBrush(LibraryX.DynamicTileBrushX proxy, TilePoolManager manager, DynamicTileBrushClassRegistry registry) : base(proxy.Uid, proxy.Name, proxy.TileWidth, proxy.TileHeight) { _brushClass = registry.Lookup(proxy.Type); if (_brushClass == null) { return; } _tiles = _brushClass.CreateTileProxyList(); foreach (var entry in proxy.Entries) { TilePool pool = manager.PoolFromItemKey(entry.TileId); if (pool == null) { continue; } SetTile(entry.Slot, pool.GetTile(entry.TileId)); } }
public TilePoolEventArgs(TilePool pool) { TilePool = pool; }