private void layerListbox_SelectedIndexChanged(object sender, EventArgs e) { if (layerListbox.SelectedItem != null) { currentLayer = layerDict[layerListbox.SelectedItem as string]; } }
private static MapLayer ProcessFile(string filename, List<string> textureNames) { MapLayer MapLayer; List<List<int>> tempLayout = new List<List<int>>(); Dictionary<string, string> properties = new Dictionary<string, string>(); using (StreamReader reader = new StreamReader(filename)) { bool readingTextures = false; bool readingLayout = false; bool readingProperties = false; while (!reader.EndOfStream) { string line = reader.ReadLine().Trim(); if (string.IsNullOrEmpty(line)) continue; if (line.Contains("[Textures]")) { readingTextures = true; readingLayout = false; readingProperties = false; } else if (line.Contains("[Layout]")) { readingTextures = false; readingLayout = true; readingProperties = false; } else if (line.Contains("[Properties]")) { readingTextures = false; readingLayout = false; readingProperties = true; } else if (readingTextures) { textureNames.Add(line); } else if (readingLayout) { List<int> row = new List<int>(); string[] cells = line.Split(' '); foreach (string c in cells) { if (!string.IsNullOrEmpty(c)) row.Add(int.Parse(c)); } tempLayout.Add(row); } else if (readingProperties) { string[] pair = line.Split('='); string key = pair[0].Trim(); string value = pair[1].Trim(); properties.Add(key, value); } } } int width = tempLayout[0].Count; int height = tempLayout.Count; MapLayer = new MapLayer(width, height); foreach (KeyValuePair<string, string> property in properties) { switch (property.Key) { case "Alpha": throw new Exception("You stopped being able to use alpha in layers you fool!"); //MapLayer.Alpha = float.Parse(property.Value); //break; } } for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { MapLayer.SetCellIndex(x, y, tempLayout[y][x]); } } return MapLayer; }