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 TileMapCell Parse(List<string> rows) { var cell = new TileMapCell(); 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).Trim ("\"".ToCharArray ()); var property = cell.GetType ().GetProperty (prop); property.SetValue(cell, Convert.ChangeType(value, property.PropertyType)); } rows.RemoveAt (0); } return cell; }
public static TileMapCell Parse(List <string> rows) { var cell = new TileMapCell(); 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).Trim("\"".ToCharArray()); var property = cell.GetType().GetProperty(prop); property.SetValue(cell, Convert.ChangeType(value, property.PropertyType)); } rows.RemoveAt(0); } return(cell); }