public static World FromJson(string jsonData)
    {
        var tmp = TinyJsonDeserializer.Deserialize(jsonData, typeof(TempMap)) as TempMap;
        var map = new World();

        map.goalPositions      = (tmp.goal_positions ?? new float[0][]).Select(p => new Vector2(p[0], p[1])).ToArray();
        map.startPositions     = (tmp.start_positions ?? new float[0][]).Select(p => new Vector2(p[0], p[1])).ToArray();
        map.enemyPositions     = (tmp.enemy_positions ?? new float[0][]).Select(p => new Vector2(p[0], p[1])).ToArray();
        map.formationPositions = (tmp.formation_positions ?? new float[0][]).Select(p => new Vector2(p[0], p[1])).ToArray();
        map.pointsOfInterest   = (tmp.points_of_interest ?? new float[0][]).Select(p => new Vector2(p[0], p[1])).ToArray();
        map.boundingPolygon    = tmp.bounding_polygon.Select(p => new Vector2(p[0], p[1])).ToArray();
        map.obstacles          = new [] {
            tmp.obstacle_1, tmp.obstacle_2, tmp.obstacle_3, tmp.obstacle_4, tmp.obstacle_5,
            tmp.obstacle_6, tmp.obstacle_7, tmp.obstacle_8, tmp.obstacle_9, tmp.obstacle_10,
        }.Where(x => x != null).Select(o => o.Select(p => new Vector2(p[0], p[1])).ToArray()).ToList();
        map.sensorRange = tmp.sensor_range;
        map.vehicle     = new VehicleInfo {
            length          = tmp.vehicle_L,
            maxAcceleration = tmp.vehicle_a_max,
            dt          = tmp.vehicle_dt,
            maxOmega    = tmp.vehicle_omega_max,
            maxPhi      = tmp.vehicle_phi_max,
            t           = tmp.vehicle_t,
            maxVelocity = tmp.vehicle_v_max
        };

        return(map);
    }
Esempio n. 2
0
        NavGraph DeserializeGraph(int zipIndex, int graphIndex, System.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 (System.Type.Equals(graphType, null))
            {
                return(null);
            }

            // Create a new graph of the right type
            NavGraph 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);
        }
Esempio n. 3
0
 private GraphMeta DeserializeMeta(ZipEntry entry)
 {
     return(TinyJsonDeserializer.Deserialize(GetString(entry), typeof(GraphMeta)) as GraphMeta);
 }