Skip to content
Snippets Groups Projects
Commit 61d8bf31 authored by Miklós Mayer's avatar Miklós Mayer
Browse files

Import ObjectType for each tile in a TileSet

parent 52a33eff
No related branches found
No related tags found
1 merge request!2Export new properties
......@@ -39,6 +39,7 @@ namespace TiledToOrx.Core
Map map = SerialiseToMap(reader);
ISet<string> objectTypes = new HashSet<string>();
List<TileSet> externalTileSets = new List<TileSet>();
foreach (TileSet tileset in map.tileSets)
......@@ -47,6 +48,13 @@ namespace TiledToOrx.Core
{
TileSet tileSetPortion = ConvertExternalTileSetFile(filePath, tileset.source);
externalTileSets.Add(tileSetPortion);
foreach (TileSet.TileSetTile tile in tileSetPortion.tiles)
{
if (tile.objectType != null)
{
objectTypes.Add(tile.objectType);
}
}
}
}
......@@ -60,7 +68,7 @@ namespace TiledToOrx.Core
if (Errors.Length == 0)
{
CreateGraphicEntries(sb, map, mapOnly, oneBasedIndex ? 0 : -1);
CreateGraphicEntries(sb, map, objectTypes, mapOnly, oneBasedIndex ? 0 : -1);
}
}
......@@ -114,7 +122,7 @@ namespace TiledToOrx.Core
return "NONE"; //return blank if no tile defined. ERROR RETURNS ?
}
public void CreateGraphicEntries(StringBuilder sb, Map map, bool mapOnly, int plusIndex)
public void CreateGraphicEntries(StringBuilder sb, Map map, ISet<string> objectTypes, bool mapOnly, int plusIndex)
{
HashSet<Tile> tilesInUse = new HashSet<Tile>();
......@@ -137,6 +145,10 @@ namespace TiledToOrx.Core
if (layer.data.mapData.Contains(tile.index))
{
// This is probably not efficient, but I don't know how to parse the XML list into a HashMap, where the id attribute becomes the key
TileSet.TileSetTile setTile = tileSet.tiles.Find(t => t.id + tileSet.firstgid + 1 == tile.index);
tile.objectType = setTile != null ? setTile.objectType : "DefaultTile";
tilesInUse.Add(tile);
}
}
......@@ -182,6 +194,13 @@ namespace TiledToOrx.Core
sb.AppendLine(FormatConfigHeading("DefaultTile"));
sb.AppendLine("");
//all the objects from the tilesets
foreach (string type in objectTypes)
{
sb.AppendLine(FormatConfigHeading(type));
sb.AppendLine("");
}
//Output object sections
foreach (Tile tile in tilesInUse)
{
......@@ -191,7 +210,7 @@ namespace TiledToOrx.Core
return;
}
sb.AppendLine(FormatConfigHeading(tile.TileSetName + (tile.index + plusIndex).ToString() + AT + "DefaultTile"));
sb.AppendLine(FormatConfigHeading(tile.TileSetName + (tile.index + plusIndex).ToString() + AT + (tile.objectType != null ? tile.objectType : "DefaulTile")));
string graphic = tile.TileSetName + (tile.index + plusIndex).ToString() + "Graphic";
sb.AppendLine(FormatConfigProperty("Graphic", graphic));
......
......@@ -57,6 +57,17 @@ namespace TiledToOrx.Core
public Image image;
[XmlAttribute(AttributeName = "source")]
public string source;
[XmlElement(ElementName = "tile")]
public List<TileSetTile> tiles;
[XmlRoot("tile")]
public class TileSetTile
{
[XmlAttribute(AttributeName = "id")]
public int id;
[XmlAttribute(AttributeName = "type")]
public string objectType;
}
}
[XmlRoot("layer")]
......@@ -70,20 +81,20 @@ namespace TiledToOrx.Core
public int height;
[XmlElement(ElementName = "data")]
public Data data;
}
[XmlRoot("tile")]
public class XmlTile
{
[XmlAttribute(AttributeName = "gid")]
public int gid;
[XmlRoot("tile")]
public class LayerTile
{
[XmlAttribute(AttributeName = "gid")]
public int gid;
}
}
[XmlRoot("data")]
public class Data
{
private List<Int64> _mapData = new List<Int64>();
private List<XmlTile> _tileData = new List<XmlTile>(); //when map is xml format
private List<Layer.LayerTile> _tileData = new List<Layer.LayerTile>(); //when map is xml format
private string _textData = "";
[XmlAttribute(AttributeName = "encoding")]
......@@ -102,7 +113,7 @@ namespace TiledToOrx.Core
/// This is for when the tile map is supplied in XML format
/// </summary>
[XmlElement(ElementName = "tile")]
public List<XmlTile> tiles;
public List<Layer.LayerTile> tiles;
/// <summary>
/// This is for when the tile map is supplied in csv, base64, gzip or zlib formats
......
......@@ -6,5 +6,6 @@
public int X { get; set; }
public int Y { get; set; }
public string TileSetName { get; set; }
public string objectType { get; set; }
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment