public override void init() { base.init(); String filename = "Assets/" + mapName + ".oel"; Stack<String> parseStack = new Stack<String>(); int w = 0, h = 0; string tileset; string exportMode; string[] tiles = {""}, solids = {""}; using (var stream = System.IO.File.OpenText(filename)) using (var reader = XmlReader.Create(stream)) { while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element) { if (parseStack.Count > 0 && parseStack.Peek() == "Entities") { bEntity e = parseEntity(reader); if (e != null) entities.Add(e); } else { parseStack.Push(reader.Name); switch (reader.Name) { case "level": w = int.Parse(reader.GetAttribute("width")); h = int.Parse(reader.GetAttribute("height")); break; case "Tiles": tileset = reader.GetAttribute("tileset"); break; case "Solids": exportMode = reader.GetAttribute("exportMode"); break; case "Entities": break; } } } else if (reader.NodeType == XmlNodeType.Text) { String current = parseStack.Pop(); switch (current) { case "level": break; case "Tiles": string v = reader.Value; tiles = v.Split('\n'); break; case "Solids": v = reader.Value; solids = v.Split('\n'); break; } parseStack.Push(current); } else if (reader.NodeType == XmlNodeType.EndElement) { parseStack.Pop(); } } } tilemap = new bTilemap(w, h, 16, 16, game.Content.Load<Texture2D>("tilemap0")); tilemap.parseTiles(tiles); mask = new bSolidGrid(w / 16, h / 16, 16, 16); mask.game = game; (mask as bSolidGrid).parseSolids(solids); }
public override void init() { base.init(); String fname = "Assets/" + mapName + ".oel"; Stack<String> parseStack = new Stack<String>(); int w = 0, h = 0; string tileset = ""; string[] tiles = { "" }; using (var stream = System.IO.File.OpenText(fname)) using (var reader = XmlReader.Create(stream)) { while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element) { if (parseStack.Count > 0 && parseStack.Peek() == "Nodes") { LevelNode e = parseNode(reader); if (e != null) nodes.Add(e); } else { parseStack.Push(reader.Name); switch (reader.Name) { case "level": w = int.Parse(reader.GetAttribute("width")); h = int.Parse(reader.GetAttribute("height")); break; case "Tiles": tileset = reader.GetAttribute("tileset"); break; case "Nodes": break; } } } else if (reader.NodeType == XmlNodeType.Text) { String current = parseStack.Pop(); switch (current) { case "level": break; case "Tiles": string v = reader.Value; tiles = v.Split('\n'); break; } parseStack.Push(current); } else if (reader.NodeType == XmlNodeType.EndElement) { parseStack.Pop(); } } } tilemap = new bTilemap(w, h, 8, 8, game.Content.Load<Texture2D>(tileset)); tilemap.parseTiles(tiles); }