public TileContent(XmlNode node, TileLayerContent layer, TileLayerSettingsContent settings) { if (!settings.MultipleTilesets && !settings.ExportTileSize) { this.Height = layer.TileHeight; this.Width = layer.TileWidth; } else if(settings.MultipleTilesets || settings.ExportTileSize) { if (node.Attributes["th"] != null) this.Height = int.Parse(node.Attributes["th"].Value, CultureInfo.InvariantCulture); if (node.Attributes["tw"] != null) this.Width = int.Parse(node.Attributes["tw"].Value, CultureInfo.InvariantCulture); } if (node.Attributes["x"] != null) this.Position.X = int.Parse(node.Attributes["x"].Value, CultureInfo.InvariantCulture); if (node.Attributes["y"] != null) this.Position.Y = int.Parse(node.Attributes["y"].Value, CultureInfo.InvariantCulture); if (node.Attributes["tx"] != null) this.TextureOffset.X = int.Parse(node.Attributes["tx"].Value, CultureInfo.InvariantCulture); if (node.Attributes["ty"] != null) this.TextureOffset.Y = int.Parse(node.Attributes["ty"].Value, CultureInfo.InvariantCulture); if (node.Attributes["id"] != null) this.SourceIndex = int.Parse(node.Attributes["id"].Value, CultureInfo.InvariantCulture); if (settings.MultipleTilesets) { if (node.Attributes["set"] != null) this.TilesetName = node.Attributes["set"].Value; } else this.TilesetName = layer.Tilesets[0]; }
internal static void Write(ContentWriter writer, LayerSettingsContent content) { if (content is GridLayerSettingsContent) { GridLayerSettingsContent gContent = content as GridLayerSettingsContent; writer.Write("g"); writer.Write(gContent.GridColor); writer.Write(gContent.GridDrawSize); writer.Write(gContent.GridSize); writer.Write(gContent.Name); writer.Write(gContent.ExportAsObjects); writer.Write(gContent.NewLine); } else if (content is ObjectLayerSettingsContent) { ObjectLayerSettingsContent oContent = content as ObjectLayerSettingsContent; writer.Write("o"); writer.Write(oContent.GridColor); writer.Write(oContent.GridDrawSize); writer.Write(oContent.GridSize); writer.Write(oContent.Name); } else if (content is TileLayerSettingsContent) { TileLayerSettingsContent tContent = content as TileLayerSettingsContent; writer.Write("t"); writer.Write(tContent.GridColor); writer.Write(tContent.GridDrawSize); writer.Write(tContent.GridSize); writer.Write(tContent.Name); writer.Write(tContent.ExportTileIDs); writer.Write(tContent.ExportTileSize); writer.Write(tContent.MultipleTilesets); } }
public TileLayerContent(XmlNode node, LevelContent level, TileLayerSettingsContent settings) : base(node) { XmlNodeList tileNodes = node.SelectNodes("tile"); if (!settings.MultipleTilesets) { // Just one tileset for this layer, so get it and save it. if (node.Attributes["set"] != null) this.Tilesets.Add(node.Attributes["set"].Value); if (settings.ExportTileSize) { if (node.Attributes["tileWidth"] != null) this.TileWidth = int.Parse(node.Attributes["tileWidth"].Value, CultureInfo.InvariantCulture); if (node.Attributes["tileHeight"] != null) this.TileHeight = int.Parse(node.Attributes["tileHeight"].Value, CultureInfo.InvariantCulture); } else { if(this.Tilesets.Count > 0) { // Extract the tileset so we can get the default tile width/height for the layer. TilesetContent tileset = (from x in level.Project.Tilesets where (x.Name == this.Tilesets[0]) select x).First<TilesetContent>(); if (tileset != null) { this.TileWidth = tileset.TileWidth; this.TileHeight = tileset.TileHeight; } } } } else { // Multiple tilesets for this layer, all saved to each tile. We want to save these up front, so we // need to extract them all. List<XmlNode> nodes = new List<XmlNode>(tileNodes.Count); foreach(XmlNode tileNode in tileNodes) nodes.Add(tileNode); string[] tilesetNames = (from x in nodes where (x.Attributes["set"] != null) select x.Attributes["set"].Value).Distinct<string>().ToArray<string>(); this.Tilesets.AddRange(tilesetNames); } foreach (XmlNode tileNode in tileNodes) this.Tiles.Add(new TileContent(tileNode, this, settings)); }
internal static LayerSettingsContent Parse(XmlNode node) { LayerSettingsContent content = null; switch (node.Name) { case "grid": content = new GridLayerSettingsContent(node); break; case "tiles": content = new TileLayerSettingsContent(node); break; case "objects": content = new ObjectLayerSettingsContent(node); break; } return content; }
internal static LayerSettingsContent Read(XmlNode node) { LayerSettingsContent content = null; switch (node.Name) { case "grid": content = new GridLayerSettingsContent(node); break; case "tiles": content = new TileLayerSettingsContent(node); break; case "objects": content = new ObjectLayerSettingsContent(node); break; } return(content); }