Exemplo n.º 1
0
 public void DeserializeEditorSettings(GraphEditorBase[] graphEditors)
 {
     if (graphEditors == null)
     {
         return;
     }
     for (int i = 0; i < graphEditors.Length; i++)
     {
         if (graphEditors[i] != null)
         {
             for (int j = 0; j < this.graphs.Length; j++)
             {
                 if (graphEditors[i].target == this.graphs[j])
                 {
                     int      num   = this.graphIndexInZip[this.graphs[j]];
                     ZipEntry entry = this.GetEntry("graph" + num + "_editor.json");
                     if (entry != null)
                     {
                         TinyJsonDeserializer.Deserialize(AstarSerializer.GetString(entry), graphEditors[i].GetType(), graphEditors[i]);
                         break;
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 2
0
        /** Deserializes graph editor settings.
         * For future compatibility this method does not assume that the \a graphEditors array matches the #graphs array in order and/or count.
         * It searches for a matching graph (matching if graphEditor.target == graph) for every graph editor.
         * Multiple graph editors should not refer to the same graph.\n
         * \note Stored in files named "graph#_editor.json" where # is the graph number.
         */
        public void DeserializeEditorSettings(GraphEditorBase[] graphEditors)
        {
            if (graphEditors == null)
            {
                return;
            }

            for (int i = 0; i < graphEditors.Length; i++)
            {
                if (graphEditors[i] == null)
                {
                    continue;
                }
                for (int j = 0; j < graphs.Length; j++)
                {
                    if (graphEditors[i].target != graphs[j])
                    {
                        continue;
                    }

                    var      zipIndex = graphIndexInZip[graphs[j]];
                    ZipEntry entry    = zip["graph" + zipIndex + "_editor" + jsonExt];
                    if (entry == null)
                    {
                        continue;
                    }

                    TinyJsonDeserializer.Deserialize(GetString(entry), graphEditors[i].GetType(), graphEditors[i]);
                    break;
                }
            }
        }
Exemplo n.º 3
0
        private NavGraph DeserializeGraph(int zipIndex, int graphIndex)
        {
            Type graphType = this.meta.GetGraphType(zipIndex);

            if (object.Equals(graphType, null))
            {
                return(null);
            }
            NavGraph navGraph = this.data.CreateGraph(graphType);

            navGraph.graphIndex = (uint)graphIndex;
            string name  = "graph" + zipIndex + ".json";
            string name2 = "graph" + zipIndex + ".binary";

            if (this.ContainsEntry(name))
            {
                TinyJsonDeserializer.Deserialize(AstarSerializer.GetString(this.GetEntry(name)), graphType, navGraph);
            }
            else
            {
                if (!this.ContainsEntry(name2))
                {
                    throw new FileNotFoundException(string.Concat(new object[]
                    {
                        "Could not find data for graph ",
                        zipIndex,
                        " in zip. Entry 'graph",
                        zipIndex,
                        ".json' does not exist"
                    }));
                }
                BinaryReader binaryReader     = AstarSerializer.GetBinaryReader(this.GetEntry(name2));
                GraphSerializationContext ctx = new GraphSerializationContext(binaryReader, null, navGraph.graphIndex, this.meta);
                navGraph.DeserializeSettingsCompatibility(ctx);
            }
            if (navGraph.guid.ToString() != this.meta.guids[zipIndex])
            {
                throw new Exception(string.Concat(new object[]
                {
                    "Guid in graph file not equal to guid defined in meta file. Have you edited the data manually?\n",
                    navGraph.guid,
                    " != ",
                    this.meta.guids[zipIndex]
                }));
            }
            return(navGraph);
        }
Exemplo n.º 4
0
        private NavGraph DeserializeGraph(int zipIndex, int graphIndex, Type[] availableGraphTypes)
        {
            // Get the graph type from the metadata we deserialized earlier
            var graphType = meta.GetGraphType(zipIndex, availableGraphTypes);

            // Graph was null when saving, ignore
            if (Equals(graphType, null))
            {
                return(null);
            }

            // Create a new graph of the right type
            var graph = data.CreateGraph(graphType);

            graph.graphIndex = (uint)graphIndex;

            var jsonName = "graph" + zipIndex + jsonExt;
            var binName  = "graph" + zipIndex + binaryExt;

            if (ContainsEntry(jsonName))
            {
                // Read the graph settings
                TinyJsonDeserializer.Deserialize(GetString(GetEntry(jsonName)), graphType, graph);
            }
            else if (ContainsEntry(binName))
            {
                var reader = GetBinaryReader(GetEntry(binName));
                var ctx    = new GraphSerializationContext(reader, null, graph.graphIndex, meta);
                ((IGraphInternals)graph).DeserializeSettingsCompatibility(ctx);
            }
            else
            {
                throw new FileNotFoundException("Could not find data for graph " + zipIndex + " in zip. Entry 'graph" +
                                                zipIndex + jsonExt + "' does not exist");
            }

            if (graph.guid.ToString() != meta.guids[zipIndex])
            {
                throw new Exception(
                          "Guid in graph file not equal to guid defined in meta file. Have you edited the data manually?\n" +
                          graph.guid + " != " + meta.guids[zipIndex]);
            }

            return(graph);
        }
Exemplo n.º 5
0
 private GraphMeta DeserializeMeta(ZipEntry entry)
 {
     return(TinyJsonDeserializer.Deserialize(GetString(entry), typeof(GraphMeta)) as GraphMeta);
 }