private Map LoadMap(string fileName)
{
Map map = new Map();
using (FileStream fileStream = new FileStream(fileName, FileMode.Open))
{
using (BinaryReader binaryReader = new BinaryReader(fileStream))
{
map.Name = binaryReader.ReadString();
map.Version = binaryReader.ReadInt32();
int mapWidth = binaryReader.ReadInt32();
int mapHeight = binaryReader.ReadInt32();
map.ResizeMap(mapWidth, mapHeight);
for (int x = 0; x < mapWidth; x++)
{
for (int y = 0; y < mapHeight; y++)
{
map.SetTile(x, y, new Map.Tile());
map.GetTile(x, y).Blocked = binaryReader.ReadBoolean();
foreach (Layers layer in Enum.GetValues(typeof(Layers)))
{
if (binaryReader.ReadBoolean() == false) continue;
int tileSetTextureIndex = binaryReader.ReadInt32();
int tileLeft = binaryReader.ReadInt32();
int tileTop = binaryReader.ReadInt32();
int tileWidth = binaryReader.ReadInt32();
int tileHeight = binaryReader.ReadInt32();
var tileLayer = new Map.Tile.Layer
{
SpriteRect = new Rect(tileLeft, tileTop, tileHeight, tileWidth),
TextureNumber = tileSetTextureIndex
};
map.GetTile(new Vector(x, y)).SetLayer(tileLayer, layer);
}
}
}
}
}
return map;
}