public static TileMap Parse(string text) { var tileMap = new TileMap(); var rows = text.Split("\n".ToCharArray()).ToList(); while (rows.Count > 0 && !String.IsNullOrWhiteSpace(rows[0])) { if (rows [0].IndexOf("{") == -1) { var propName = rows [0].Substring(0, rows [0].IndexOf(":")).Trim(); var prop = ""; foreach (var part in propName.Split("_".ToCharArray())) { prop += part.Substring(0, 1).ToUpper() + part.Substring(1); } var value = rows [0].Substring(rows [0].IndexOf(":") + 1).Replace("\"", ""); tileMap.GetType().GetProperty(prop).SetValue(tileMap, value); rows.RemoveAt(0); } else { var propName = rows[0].Substring(0, rows[0].IndexOf("{")).Trim(); switch (propName) { case "layers": var layer = TileMapLayer.Parse(rows); tileMap.Layers.Add(layer); break; } } } return(tileMap); }
public static TileMapLayer Parse(List<string> rows) { var layer = new TileMapLayer (); while (rows.Count > 0 && rows [0].IndexOf ("}") == -1) { if (rows [0].IndexOf ("{") == -1) { var propName = rows [0].Substring (0, rows [0].IndexOf (":")).Trim (); var prop = ""; foreach (var part in propName.Split("_".ToCharArray())) { prop += part.Substring (0, 1).ToUpper () + part.Substring (1); } var value = rows [0].Substring (rows [0].IndexOf (":") + 1).Replace("\"",""); var property = layer.GetType ().GetProperty (prop); property.SetValue(layer, Convert.ChangeType(value, property.PropertyType)); } else { var propName = rows [0].Substring (0, rows [0].IndexOf ("{")).Trim (); switch (propName) { case "cell": var cell = TileMapCell.Parse (rows); layer.Cells.Add (cell); break; } } rows.RemoveAt (0); } rows.RemoveAt (0); return layer; }
public static TileMapLayer Parse(List <string> rows) { var layer = new TileMapLayer(); while (rows.Count > 0 && rows [0].IndexOf("}") == -1) { if (rows [0].IndexOf("{") == -1) { var propName = rows [0].Substring(0, rows [0].IndexOf(":")).Trim(); var prop = ""; foreach (var part in propName.Split("_".ToCharArray())) { prop += part.Substring(0, 1).ToUpper() + part.Substring(1); } var value = rows [0].Substring(rows [0].IndexOf(":") + 1).Replace("\"", ""); var property = layer.GetType().GetProperty(prop); property.SetValue(layer, Convert.ChangeType(value, property.PropertyType)); } else { var propName = rows [0].Substring(0, rows [0].IndexOf("{")).Trim(); switch (propName) { case "cell": var cell = TileMapCell.Parse(rows); layer.Cells.Add(cell); break; } } rows.RemoveAt(0); } rows.RemoveAt(0); return(layer); }