public override MapModel <LayerModel <TileModel <SpriteInfo> > > Load(IDataManagerArguments arguments) { MapModel <LayerModel <TileModel <SpriteInfo> > > map = null; var mapArguments = (arguments as ContentFileDataLoaderArguments); using (var fileStream = new FileStream(this.RootPath + mapArguments.FileName + EngineConstants.MAP_FILE_EXT, FileMode.Open)) { using (var bR = new BinaryReader(fileStream)) { // Load the tileset information int tilesetCount = bR.ReadInt32(); List <string> tilesetPaths = new List <string>(); for (int i = 0; i < tilesetCount; i++) { // We can throw this information away as it is used only in the editor suite. string tilesetPath = bR.ReadString(); tilesetPaths.Add(tilesetPath); } string name = bR.ReadString(); var dimensions = new Vector(bR.ReadInt32(), bR.ReadInt32()); map = new MapModel <LayerModel <TileModel <SpriteInfo> > >(dimensions, name) { Dark = bR.ReadBoolean() }; map.TilesetPaths.AddRange(tilesetPaths); map.Bounds = new Rect(0, 0, (int)map.Dimensions.X, (int)map.Dimensions.Y); int layerCount = bR.ReadInt32(); for (int i = 0; i < layerCount; i++) { string layerName = bR.ReadString(); int lIndex = bR.ReadInt32(); var layer = new LayerModel <TileModel <SpriteInfo> >(map.Dimensions, layerName, lIndex); for (int x = 0; x < layer.Tiles.GetLength(0); x++) { for (int y = 0; y < layer.Tiles.GetLength(1); y++) { if (bR.ReadBoolean()) { layer.Tiles[x, y] = new TileModel <SpriteInfo>(new Vector(x * EngineConstants.TILE_SIZE, y * EngineConstants.TILE_SIZE)); if (bR.ReadBoolean()) // Is there a valid attribute saved for this tile? { int attributeDataLength = bR.ReadInt32(); byte[] attributeData = bR.ReadBytes(attributeDataLength); layer.Tiles[x, y].Attribute = TileAttribute.Deserialize(attributeData); } if (bR.ReadBoolean()) { layer.Tiles[x, y].Animated = bR.ReadBoolean(); layer.Tiles[x, y].LightSource = bR.ReadBoolean(); string spriteName = bR.ReadString(); float zIndex = bR.ReadSingle(); // We can throw this away layer.Tiles[x, y].Sprite = new SpriteInfo(spriteName) { Transform = { Position = new Vector(x * EngineConstants.TILE_SIZE, y * EngineConstants.TILE_SIZE), Color = new Color(bR.ReadByte(), bR.ReadByte(), bR.ReadByte(), bR.ReadByte()), Rect = new Rect(bR.ReadInt32(), bR.ReadInt32(), bR.ReadInt32(), bR.ReadInt32()), LayerDepth = zIndex } }; layer.Tiles[x, y].FrameCount = bR.ReadInt32(); } } } } //int mapObjectCount = bR.ReadInt32(); //for (int mI = 0; mI < mapObjectCount; mI++) //{ // var mapObject = new MapObjectDescriptor() // { // Position = new Vector(bR.ReadSingle(), bR.ReadSingle()) // }; // if (bR.ReadBoolean()) // { // string texturePath = bR.ReadString(); // mapObject.Sprite = new SpriteInfo(texturePath) // { // Transform = // { // Rect = new Rect(bR.ReadInt32(), bR.ReadInt32(), bR.ReadInt32(), bR.ReadInt32()) // } // }; // } // mapObject.Animated = bR.ReadBoolean(); // mapObject.FrameTime = bR.ReadInt32(); // string scriptPath = bR.ReadString(); // var lightSource = bR.ReadBoolean(); // var lightRadius = bR.ReadSingle(); // var lightColor = new Color(bR.ReadByte(), bR.ReadByte(), bR.ReadByte(), bR.ReadByte()); // if (lightSource) // { // mapObject.LightInformation = new LightInformation() // { // Radius = lightRadius, // Color = lightColor // }; // } //} map.AddLayer(layerName, layer); } } } return(map); }