Esempio n. 1
0
        private void WriteColumnValues(StringBuilder sb, IList <string> columnNames, CSVPropertyType type, string layerName)
        {
            columnNames = columnNames.Select(item => property.GetStrippedName(item)).ToList();


            // TODO: There is probably a good way to refactor this code
            switch (type)
            {
            case CSVPropertyType.Tile:
                WriteColumnValuesForTile(sb, columnNames);
                break;

            case CSVPropertyType.Layer:

                WriteColumnValuesForLayer(sb, columnNames, layerName);
                break;

            case CSVPropertyType.Map:
                WriteValuesFromDictionary(sb, null, PropertyDictionary, columnNames, null);
                break;

            case CSVPropertyType.Object:
                this.objectgroup.Where(
                    og =>
                    layerName == null ||
                    (og.name != null && og.name.Equals(layerName, StringComparison.OrdinalIgnoreCase)))
                .SelectMany(o => o.@object, (o, c) => new { group = o, obj = c, X = c.x, Y = c.y })
                .Where(o => String.IsNullOrEmpty(o.obj.gid))
                .ToList()
                .ForEach(o => WriteValuesFromDictionary(sb, o.group.PropertyDictionary, o.obj.PropertyDictionary, columnNames, null));
                break;
            }
        }
Esempio n. 2
0
        private IEnumerable <string> GetColumnNames(CSVPropertyType type, string layerName)
        {
            var comparer = new CaseInsensitivePropertyEqualityComparer();

            var columnNames = new HashSet <string>();

            switch (type)
            {
            case CSVPropertyType.Tile:
                return(GetColumnNamesForTile(comparer));

            case CSVPropertyType.Layer:
                return
                    (this.Layers.Where(
                         l =>
                         layerName == null ||
                         (l.Name != null && l.Name.Equals(layerName, StringComparison.OrdinalIgnoreCase)))
                     .SelectMany(l => l.PropertyDictionary)
                     .Select(d => d.Key)
                     .Distinct(comparer));

            case CSVPropertyType.Map:
                return(this.PropertyDictionary.Select(d => d.Key).Distinct(comparer));

            case CSVPropertyType.Object:

                List <string> toReturn = new List <string>();

                toReturn.Add("X (int)");
                toReturn.Add("Y (int)");

                if (objectgroup != null)
                {
                    var query1 =
                        objectgroup.Where(l =>
                                          layerName == null ||
                                          (l.name != null &&
                                           l.name.Equals(layerName, StringComparison.OrdinalIgnoreCase)));
                    var query2 =
                        objectgroup.Where(l =>
                                          layerName == null ||
                                          (l.name != null &&
                                           l.name.Equals(layerName, StringComparison.OrdinalIgnoreCase)));
                    return(toReturn
                           .Union(query1
                                  .SelectMany(o => o.@object)
                                  .Where(o => String.IsNullOrEmpty(o.gid))      //November 2015 by Jesse Crafts-Finch: will ignore objects which are to be treated as sprites (they have a gid).
                                  .SelectMany(o => o.PropertyDictionary)
                                  .Select(d => d.Key), comparer)
                           .Union(query2
                                  .SelectMany(o => o.PropertyDictionary)
                                  .Select(d => d.Key), comparer));
                }
                else
                {
                    return(toReturn);
                }
            }
            return(columnNames);
        }
Esempio n. 3
0
        public string ToCSVString(CSVPropertyType type = CSVPropertyType.Tile, string layerName = null)
        {
            var sb = new StringBuilder();
            IEnumerable <string> columnsAsEnumerable = GetColumnNames(type, layerName);
            var columnList = columnsAsEnumerable as IList <string> ?? columnsAsEnumerable.ToList();

            WriteColumnHeader(sb, columnList);
            WriteColumnValues(sb, columnList, type, layerName);

            return(sb.ToString());
        }