コード例 #1
0
ファイル: TileMap.cs プロジェクト: santosh90n/defold-stuff
        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);
        }
コード例 #2
0
ファイル: TileMapLayer.cs プロジェクト: johnnyjr/defold-stuff
 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;
 }
コード例 #3
0
        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);
        }