private void ReadTMX(ref Area area, DataSet data)
{
TileSetBox tileSets = new TileSetBox();
foreach(DataRow setData in data.Tables["tileset"].Rows)
{
tileSets.Add(setData);
}
area.TileSets = tileSets;
#region Read TileLayers
foreach(DataRow layerData in data.Tables["layer"].Rows)
{
try
{
if (layerData["visible"].ToString().Equals("0"))
continue;
}
catch { }
Point layerDims = new Point(int.Parse(layerData["width"].ToString()), int.Parse(layerData["height"].ToString()));
int[,] tileGrid = new int[layerDims.X, layerDims.Y];
int x = 0;
int y = 0;
foreach (DataRow mapData in layerData.GetChildRows("layer_data"))
{
foreach (DataRow tileData in mapData.GetChildRows("data_tile"))
{
tileGrid[x, y] = int.Parse(tileData["gid"].ToString());
if (x < layerDims.X - 1)
++x;
else
{
x = 0;
++y;
}
}
}
TileLayer tileLayer = new TileLayer(tileGrid, area);
foreach (DataRow properties in layerData.GetChildRows("layer_properties"))
{
foreach (DataRow propertyData in properties.GetChildRows("properties_property"))
{
if (propertyData["name"].Equals("Type") || propertyData["name"].Equals("type"))
{
if (propertyData["value"].Equals("Low") || propertyData["value"].Equals("low"))
{
area.AddLowLayer(tileLayer);
continue;
}
if (propertyData["value"].Equals("High") || propertyData["value"].Equals("high"))
{
area.AddHighLayer(tileLayer);
continue;
}
throw new Exception("No or faulty 'Type' property set for tileLayer. Accepted values are 'Low' and 'High'.");
}
}
}
}
#endregion
#region Read Objectgroups
EntityBuilder.BeginArea(area);
foreach (DataRow groupData in data.Tables["objectgroup"].Rows)
{
try
{
if (groupData["visible"].ToString().Equals("0"))
continue;
}
catch { }
switch (XMLParser.ValueOfProperty(
groupData.GetChildRows("objectgroup_properties")[0],
"Type"))
{
case "Entities":
ReadEntityLayer(ref area, groupData);
break;
case "RoamZones":
ReadRoamZones(groupData);
break;
}
}
EntityBuilder.EndArea();
#endregion
}