public TileLayer(XmlNode node)
: base(node)
{
XmlNode dataNode = node["data"];
Data = new int[Width * Height];
// figure out what encoding is being used, if any, and process
// the data appropriately
if (dataNode.Attributes["encoding"] != null)
{
string encoding = dataNode.Attributes["encoding"].Value;
if (encoding == "base64")
{
ReadAsBase64(node, dataNode);
}
else if (encoding == "csv")
{
ReadAsCsv(node, dataNode);
}
else
{
throw new Exception("Unknown encoding: " + encoding);
}
}
else
{
// XML format simply lays out a lot of <tile gid="X" /> nodes inside of data.
int i = 0;
foreach (XmlNode tileNode in dataNode.SelectNodes("tile"))
{
Data[i] = int.Parse(tileNode.Attributes["gid"].Value, CultureInfo.InvariantCulture);
i++;
}
if (i != Data.Length)
throw new Exception("Not enough tile nodes to fill data");
}
}