public static GreedleDirective FromJSON(JSON.Element rootElement)
        {
            var type = rootElement.jsonObject["type"].jsonString;

            switch (type)
            {
            case "target":
                return(new GreedleDirective()
                {
                    type = DirectiveType.Target,
                    targetDirective = new TargetDirective()
                    {
                        addressedTo = rootElement.jsonObject["addressedTo"].jsonString,
                        target = Vector3Utils.Vector3FromJSON(rootElement.jsonObject["target"]),
                    },
                });

            case "respond":
                return(new GreedleDirective()
                {
                    type = DirectiveType.Respond,
                });
            }
            throw new Exception("Unknown Directive Type");
        }
 public static GreedleResponse FromJSON(JSON.Element rootElement)
 {
     return(new GreedleResponse()
     {
         name = rootElement.jsonObject["name"].jsonString,
         position = Vector3Utils.Vector3FromJSON(rootElement.jsonObject["position"])
     });
 }
Example #3
0
 public static Vector3 Vector3FromJSON(JSON.Element rootElement)
 {
     return(new Vector3(
                rootElement.jsonObject["x"].jsonNumber,
                rootElement.jsonObject["y"].jsonNumber,
                rootElement.jsonObject["z"].jsonNumber
                ));
 }
Example #4
0
        public static Waypath FromJSON(JSON.Element rootElement)
        {
            var name   = rootElement.jsonObject["name"].jsonString;
            var points = rootElement.jsonObject["points"].jsonArray
                         .Select(element => Waypoint.FromJSON(element))
                         .ToList();

            return(new Waypath(name, points));
        }
Example #5
0
 public static Location FromJSON(JSON.Element rootElement)
 {
     return(new Location()
     {
         name = rootElement.jsonObject["name"].jsonString,
         position = Vector3Utils.Vector3FromJSON(rootElement.jsonObject["position"]),
         pathsToLocations = rootElement.jsonObject["paths"].jsonObject
                            .Select(element => new KeyValuePair <string, Waypath>(element.Key, Waypath.FromJSON(element.Value)))
                            .ToDictionary(entry => entry.Key, entry => entry.Value)
     });
 }
Example #6
0
        public static Waypoint FromJSON(JSON.Element rootElement)
        {
            string name   = rootElement.jsonObject["name"].jsonString;
            float  radius = (float)rootElement.jsonObject["radius"].jsonNumber;

            Vector3 position = Vector3Utils.Vector3FromJSON(rootElement.jsonObject["position"]);

            Vector3 direction = Vector3.Zero;

            JSON.Element directionElement;
            if (rootElement.jsonObject.TryGetValue("direction", out directionElement))
            {
                direction = Vector3Utils.Vector3FromJSON(directionElement);
            }

            return(new Waypoint(name, radius, position, direction));
        }
 void DeserializeState(JSON.Element state)
 {
     paths.Clear();
     paths.AddRange(
         state
         .jsonObject["paths"].jsonArray
         .Select(element => Waypath.FromJSON(element))
         );
     currentPathIndex = (int)state.jsonObject["paths"].jsonNumber;
     if (paths.Count < 1)
     {
         paths.Add(new Waypath(name: "Default Waypath", points: new List <Waypoint>()));
         currentPathIndex = 0;
     }
     recorder.SetPath(paths[currentPathIndex]);
     traveller.SetPath(paths[currentPathIndex]);
     traveller.LoadState(state.jsonObject["traveler"]);
     DrawPaths();
 }
 public void LoadState(JSON.Element element)
 {
     travelState       = (TravelState)Enum.Parse(typeof(TravelState), element.jsonObject["travelState"].jsonString);
     currentPointIndex = (int)element.jsonObject["currentPointIndex"].jsonNumber;
 }
 public void LoadState(JSON.Element rootElement)
 {
     paths = rootElement.jsonObject["paths"].jsonArray.Select(element => Waypath.FromJSON(element)).ToList();
     DrawOutput();
 }