public static void Load(Editor editor, string fileLoc) { editor.Clear(); // clean up anything the user might have been working on before var doc = new XmlDocument(); doc.Load(fileLoc); var level = doc.SelectSingleNode("Level"); // Floor Tiles var rows = level.SelectNodes("Row"); var yOffset = rows.Count - 1; var x = 0; var y = 0; foreach (XmlNode row in rows) { foreach (XmlNode column in row.SelectNodes("Column")) { var tile = column.SelectSingleNode("Tile"); editor.SelectTileChoice(tile.InnerText); editor.PlaceTile(new Point(x * Gc.TILE_SIZE, (yOffset - y) * Gc.TILE_SIZE)); x++; } y++; x = 0; } // Walls var walls = level.SelectSingleNode("Walls"); foreach (XmlNode wall in walls.SelectNodes("Wall")) { // wall pattern is: x,y x1,y2 string[] parts = wall.InnerText.Split(new[] {" "}, StringSplitOptions.RemoveEmptyEntries); var p1 = parts[0].Split(','); var p2 = parts[1].Split(','); var isHor = p1[1] == p2[1]; editor.PlaceWall( new Point(int.Parse(p1[0]) * Gc.TILE_SIZE, (yOffset - int.Parse(p1[1]) + (isHor ? 1 : 0)) * Gc.TILE_SIZE), new Point((int.Parse(p2[0]) - (isHor ? 1 : 0)) * Gc.TILE_SIZE, (yOffset - int.Parse(p2[1]) + (isHor ? 1 : -1)) * Gc.TILE_SIZE)); } // Doors var doors = level.SelectSingleNode("Doors"); foreach (XmlNode door in doors.SelectNodes("Door")) { // door is stored as x,y,rotation var parts = door.InnerText.Split(','); var dx = int.Parse(parts[0]); var dy = int.Parse(parts[1]); var drot = int.Parse(parts[2]); // when placing doors, you need to put it closer to left or top side of tile it's on or else it will mess up if(drot == 0) editor.PlaceDoor(new Point(dx * Gc.TILE_SIZE + 1, (yOffset - dy + 1) * Gc.TILE_SIZE)); if (drot == 90) editor.PlaceDoor(new Point(dx * Gc.TILE_SIZE, (yOffset - dy) * Gc.TILE_SIZE + 1)); } // Items var items = level.SelectSingleNode("Items"); foreach (XmlNode item in items.SelectNodes("Item")) { var ix = float.Parse(item.Attributes["X"].InnerText); var iy = float.Parse(item.Attributes["Y"].InnerText); var irot = float.Parse(item.Attributes["Rot"].InnerText); editor.SelectItemChoice(item.InnerText); editor.PlaceItem(new Point( ix.FromEditorCoordX(editor) - editor.SelectedItemChoice.Image.Source.Width, yOffset * Gc.TILE_SIZE - iy.FromEditorCoordY(editor) - editor.SelectedItemChoice.Image.Source.Height + Gc.TILE_SIZE), irot); editor.EditingItem.Rotation = irot; } }
public void OnMouseDown(Editor editor, UIView view) { editor.PlaceItem(editor.startPoint); }