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(); }
public Library(Stream stream) : this(Guid.NewGuid(), "Default") { Extra = new List <XmlElement>(); XmlReaderSettings settings = new XmlReaderSettings() { CloseInput = true, IgnoreComments = true, IgnoreWhitespace = true, }; using (XmlReader reader = XmlTextReader.Create(stream, settings)) { XmlSerializer serializer = new XmlSerializer(typeof(LibraryX)); LibraryX proxy = serializer.Deserialize(reader) as LibraryX; if (proxy.PropertyGroup != null) { _uid = proxy.PropertyGroup.LibraryGuid; _name = new ResourceName(this, proxy.PropertyGroup.LibraryName); } Initialize(proxy); } }
public static DynamicTileBrush FromXProxy(LibraryX.DynamicTileBrushX proxy, TilePoolManager manager, DynamicTileBrushClassRegistry registry) { if (proxy == null) return null; DynamicTileBrush brush = new DynamicTileBrush(proxy, manager, registry); if (brush._brushClass == null) return null; return brush; }
private ObjectClass(LibraryX.ObjectClassX proxy, ITexturePool texturePool) : this(proxy.Name) { _uid = proxy.Uid; _image = texturePool.GetResource(proxy.Texture); _imageBounds = proxy.ImageBounds; _maskBounds = proxy.MaskBounds; _origin = proxy.Origin; if (proxy.Properties != null) { foreach (var propertyProxy in proxy.Properties) PropertyManager.CustomProperties.Add(Property.FromXmlProxy(propertyProxy)); } }
public static TexturePool FromXmlProxy(LibraryX.TextureGroupX proxy) { if (proxy == null) return null; TexturePool pool = new TexturePool(); foreach (var defProxy in proxy.Textures) { TextureResource resource = TextureResource.FromXmlProxy(defProxy.TextureData); if (resource != null) { pool._resources[defProxy.Uid.ValueOrNew()] = resource; } } return pool; }
public static Library FromXProxy(LibraryX proxy) { if (proxy == null) { return(null); } Guid uid = proxy.PropertyGroup != null ? proxy.PropertyGroup.LibraryGuid : Guid.NewGuid(); string name = proxy.PropertyGroup != null ? proxy.PropertyGroup.LibraryName : "Default"; Library library = new Library(uid, name); library.Initialize(proxy); return(library); }
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 void Save(Stream stream) { XmlWriterSettings settings = new XmlWriterSettings() { CloseOutput = true, Indent = true, }; using (XmlWriter writer = XmlTextWriter.Create(stream, settings)) { LibraryX proxy = ToXProxy(this); XmlSerializer serializer = new XmlSerializer(typeof(LibraryX)); serializer.Serialize(writer, proxy); } ResetModified(); }
private void Initialize(LibraryX proxy) { if (proxy.PropertyGroup != null) { Extra = new List <XmlElement>(proxy.PropertyGroup.Extra ?? new XmlElement[0]); } TexturePool = TexturePool.FromXmlProxy(proxy.TextureGroup) ?? new TexturePool(); ObjectPoolManager = ObjectPoolManager.FromXmlProxy(proxy.ObjectGroup, TexturePool) ?? new ObjectPoolManager(TexturePool); ObjectPoolManager.PoolModified += (s, e) => OnModified(EventArgs.Empty); TilePoolManager = TilePoolManager.FromXmlProxy(proxy.TileGroup, TexturePool) ?? new TilePoolManager(TexturePool); TilePoolManager.PoolModified += (s, e) => OnModified(EventArgs.Empty); TileBrushManager = TileBrushManager.FromXProxy(proxy.TileBrushGroup, TilePoolManager, Project.DynamicBrushClassRegistry) ?? new TileBrushManager(); TileBrushManager.PoolModified += (s, e) => OnModified(EventArgs.Empty); }
public static StaticTileBrush FromXProxy(LibraryX.StaticTileBrushX proxy, TilePoolManager manager) { if (proxy == null) return null; return new StaticTileBrush(proxy, manager); }
public static ObjectClass FromXProxy(LibraryX.ObjectClassX proxy, ITexturePool texturePool) { if (proxy == null) return null; return new ObjectClass(proxy, texturePool); }