Esempio n. 1
0
        public static AGameGraph loadGraph(string[] serialization)
        {
            string[]   filteredSerialization = ParsingUtils.clearComments(serialization);
            string     graphType             = filteredSerialization[0];
            AGameGraph graph = (AGameGraph)Activator.CreateInstance(null, graphType).Unwrap();

            graph.deserialize(filteredSerialization);
            return(graph);
        }
Esempio n. 2
0
        /// <summary>
        /// allows loading the graph, from lines as returned from GameGraph.serialize()
        ///
        /// if an inheriting graph needs to extend serialize()/desiralize(), it needs to implement serializeEx()/deserializeEx()
        /// (these methods are called at the end of serialize()/deserialize() automatically)
        /// </summary>
        /// <returns></returns>
        ///
        public override void deserialize(string[] serialization)
        {
            string[] lines = ParsingUtils.clearComments(serialization);
            // line 1 specifies graph concrete type, so we skip it (assuming this object was already constructed)
            int  nodeCount = Int32.Parse(lines[1]);
            uint nextLine  = 2;

            while (nodeCount > 0)
            {
                NodeID id = deserializeID(lines[nextLine++]);
                Nodes[id] = new Node <NodeID>(id, (NodeType)Int32.Parse(lines[nextLine++]));
                Edges[id] = new Dictionary <NodeID, double>();
                --nodeCount;
            }
            while (nextLine < lines.Count())
            {
                NodeID id1    = deserializeID(lines[nextLine++]);
                NodeID id2    = deserializeID(lines[nextLine++]);
                double weight = Double.Parse(lines[nextLine++]);

                if (Edges[id1] == null)
                {
                    Edges[id1] = new Dictionary <NodeID, Double>();
                }
                if (Edges[id2] == null)
                {
                    Edges[id2] = new Dictionary <NodeID, Double>();
                }

                Edges[id1][id2] = weight;
                Edges[id2][id1] = weight;
            }

            // call desiralization extension with remaining lines:
            deserializeEx(lines.Skip((int)nextLine).ToArray());
        }