public static PathMap ImportFromCSV(string file)
        {
            CsvFrame frame = CsvFrame.ParseOne(File.ReadAllText(file).Trim());

            if (frame.VariableSetOwner != "Global")
            {
                Log.Write(LogLevel.Normal, new ColorMod("Error: need the global variable set, got " + frame.VariableSetOwner + " instead.", ConsoleColor.Red));
                return(null);
            }

            List <Vertex> vectors   = new List <Vertex>();
            CsvArray      nodeArray = frame.VariableValues[nodesOut] as CsvArray;

            for (int i = 0; i < nodeArray.Values.Length; i++)
            {
                CsvVector nodeVector = (CsvVector)nodeArray.Values[i];
                vectors.Add(nodeVector.Value);
            }

            List <Segment> segments     = new List <Segment>();
            CsvArray       segmentArray = frame.VariableValues[segmentsOut] as CsvArray;

            for (int i = 0; i < segmentArray.Values.Length; i++)
            {
                CsvVector segmentVector = (CsvVector)segmentArray.Values[i];

                segments.Add(new Segment(
                                 (int)segmentVector.Value.X,
                                 (int)segmentVector.Value.Y,
                                 (int)segmentVector.Value.Z
                                 ));
            }

            return(new PathMap(vectors.ToArray(), segments.ToArray()));
        }
Esempio n. 2
0
        public static PathMap ImportFromCSV(string text, IPathmapErrorHandler errorHandler)
        {
            CsvFrame frame;

            try {
                frame = CsvFrame.ParseOne(text);
            }
            catch (Exception) {
                errorHandler.Error("Incorrect CSV format.");
                return(null);
            }

            if (frame.VariableSetOwner != "Global")
            {
                errorHandler.Error("Need the global variable set, got the '" + frame.VariableSetOwner + "' variable set instead.");
                return(null);
            }

            List <Vertex> vectors   = new List <Vertex>();
            CsvArray      nodeArray = frame.VariableValues[nodesOut] as CsvArray;

            if (nodeArray == null)
            {
                errorHandler.Error("Incorrect format, 'nodesOut' is not an array. Did you compile your pathmap?");
                return(null);
            }

            for (int i = 0; i < nodeArray.Values.Length; i++)
            {
                CsvVector nodeVector = (CsvVector)nodeArray.Values[i];
                vectors.Add(nodeVector.Value);
            }

            List <Segment> segments     = new List <Segment>();
            CsvArray       segmentArray = frame.VariableValues[segmentsOut] as CsvArray;

            if (segmentArray == null)
            {
                errorHandler.Error("Incorrect format, 'segmentsOut' is not an array.");
                return(null);
            }

            for (int i = 0; i < segmentArray.Values.Length; i++)
            {
                CsvVector segmentVector = (CsvVector)segmentArray.Values[i];

                segments.Add(new Segment(
                                 (int)segmentVector.Value.X,
                                 (int)segmentVector.Value.Y,
                                 (int)Math.Round((segmentVector.Value.X % 1) * 100),
                                 (int)Math.Round((segmentVector.Value.Y % 1) * 100)
                                 ));
            }

            return(new PathMap(vectors.ToArray(), segments.ToArray()));
        }
Esempio n. 3
0
        public static Pathmap ImportFromCSV(string text, IPathmapErrorHandler errorHandler)
        {
            CsvFrame frame;

            try
            {
                frame = CsvFrame.ParseOne(text);
            }
            catch (Exception)
            {
                errorHandler.Error("Incorrect CSV format.");
                return(null);
            }

            if (frame.VariableSetOwner != "Global")
            {
                errorHandler.Error("Need the global variable set, got the '" + frame.VariableSetOwner + "' variable set instead.");
                return(null);
            }

            // Get nodes
            CsvArray nodeArray = frame.VariableValues[nodesOut] as CsvArray;

            if (nodeArray == null)
            {
                errorHandler.Error("Incorrect format, 'nodesOut' is not an array. Did you compile your pathmap?");
                return(null);
            }

            Vertex[] vectors = new Vertex[nodeArray.Values.Length];
            for (int i = 0; i < nodeArray.Values.Length; i++)
            {
                CsvVector nodeVector = (CsvVector)nodeArray.Values[i];
                vectors[i] = nodeVector.Value;
            }

            // Get segments
            CsvArray segmentArray = frame.VariableValues[segmentsOut] as CsvArray;

            if (segmentArray == null)
            {
                errorHandler.Error("Incorrect format, 'segmentsOut' is not an array.");
                return(null);
            }

            Segment[] segments = new Segment[segmentArray.Values.Length];
            for (int i = 0; i < segmentArray.Values.Length; i++)
            {
                CsvVector segmentVector = (CsvVector)segmentArray.Values[i];
                segments[i] = new Segment(
                    (int)segmentVector.Value.X,
                    (int)segmentVector.Value.Y
                    );
            }

            // Get attributes
            CsvArray attributeArray = frame.VariableValues[attributesOut] as CsvArray;

            if (attributeArray == null)
            {
                errorHandler.Error("Incorrect format, 'attributesOut' is not an array.");
                return(null);
            }

            MapAttribute[] attributes = new MapAttribute[attributeArray.Values.Length];
            for (int i = 0; i < attributeArray.Values.Length; i++)
            {
                CsvVector attributeVector = (CsvVector)attributeArray.Values[i];
                attributes[i] = new MapAttribute(
                    (int)attributeVector.Value.X,
                    (int)attributeVector.Value.Y,
                    (int)attributeVector.Value.Z
                    );
            }

            return(new Pathmap(vectors.ToArray(), segments.ToArray(), attributes));
        }