Hello,
I’m writing a c# reader for my Tiled output, and I’m just wondering how others work with the tileset property.
So there is the “Tileset” element in the actual .tmx, but then also the “Tileset” in the .tsx. This how thrown me off a little as I’ve resorted to having 2 separate properties, which doesn’t seem right
.tmx class
...
[XmlElement("tileset")]
public Tileset_Short[] Tileset_Short;
public List<Tileset_Full> Tileset_Full;
public static TiledMap Load(string path, string fileName)
{
// Deserialize it, and return the TmxMap instance.
var xml = new XmlSerializer(typeof(TiledMap));
using (var stream = new StreamReader($"{path}/{fileName}"))
{
var instance = (TiledMap)xml.Deserialize(stream);
instance.Tileset_Full = new List<Tileset_Full>();
var tilesetXML = new XmlSerializer(typeof(Tileset_Full));
foreach (var tileset in instance.Tileset_Short)
{
using (var tilesetStream = new StreamReader($"{path}/{tileset.Source}"))
{
var tilesetInstance = (Tileset_Full)tilesetXML.Deserialize(tilesetStream);
instance.Tileset_Full.Add(tilesetInstance);
}
}
return instance;
}
}
[XmlRoot(ElementName = "tileset")]
public class Tileset_Full
{
[XmlAttribute("name")]
public string Name;
[XmlAttribute("tilewidth")]
public int TileWidth;
[XmlAttribute("tileheight")]
public int TileHeight;
[XmlAttribute("tilecount")]
public int TileCount;
[XmlAttribute("columns")]
public int Columns;
[XmlElement("image")]
public Image Image;
}
[XmlRoot(ElementName = "tileset")]
public class Tileset_Short
{
[XmlAttribute("firstgid")]
public string FirstGId;
[XmlAttribute("source")]
public string Source;
}
So as you’ll be able to see in my “Load” method, I have to deserialize the “Tileset_Full”, and that leaves me with information split between my 2 “Tileset” properties.
Am I going about this the wrong way?
Cheers