예제 #1
0
        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");
        }
예제 #2
0
 public static GreedleResponse FromJSON(JSON.Element rootElement)
 {
     return(new GreedleResponse()
     {
         name = rootElement.jsonObject["name"].jsonString,
         position = Vector3Utils.Vector3FromJSON(rootElement.jsonObject["position"])
     });
 }
예제 #3
0
 public static JSON.Element ToJSON(GreedleResponse response)
 {
     return(JSON.Element.NewObject(new Dictionary <string, JSON.Element>()
     {
         ["name"] = JSON.Element.NewString(response.name),
         ["position"] = Vector3Utils.Vector3ToJSON(response.position),
     }));
 }
예제 #4
0
 public static JSON.Element ToJSON(Waypoint point)
 {
     return(JSON.Element.NewObject(new Dictionary <string, JSON.Element>()
     {
         ["name"] = JSON.Element.NewString(point.name),
         ["radius"] = JSON.Element.NewNumber(point.radius),
         ["position"] = Vector3Utils.Vector3ToJSON(point.position),
         ["direction"] = Vector3Utils.Vector3ToJSON(point.direction),
     }));
 }
예제 #5
0
 public static JSON.Element ToJSON(Location location)
 {
     return(JSON.Element.NewObject(new Dictionary <string, JSON.Element>()
     {
         ["name"] = JSON.Element.NewString(location.name),
         ["position"] = Vector3Utils.Vector3ToJSON(location.position),
         ["pathsToLocations"] = JSON.Element.NewObject(location.pathsToLocations
                                                       .Select(pathToLocation => new KeyValuePair <string, JSON.Element>(pathToLocation.Key, Waypath.ToJSON(pathToLocation.Value)))
                                                       .ToDictionary(entry => entry.Key, entry => entry.Value)),
     }));
 }
예제 #6
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)
     });
 }
예제 #7
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));
        }
예제 #8
0
        public static JSON.Element ToJSON(GreedleDirective directive)
        {
            switch (directive.type)
            {
            case DirectiveType.Target:
                return(JSON.Element.NewObject(new Dictionary <string, JSON.Element>()
                {
                    ["type"] = JSON.Element.NewString("target"),
                    ["addressedTo"] = JSON.Element.NewString(directive.targetDirective.addressedTo),
                    ["target"] = Vector3Utils.Vector3ToJSON(directive.targetDirective.target),
                }));

            case DirectiveType.Respond:
                return(JSON.Element.NewObject(new Dictionary <string, JSON.Element>()
                {
                    ["type"] = JSON.Element.NewString("respond"),
                }));
            }
            throw new Exception("Unknown Directive Type");
        }
        void DrawOutput()
        {
            if (outputSurface == null)
            {
                return;
            }
            outputSurface.ContentType = ContentType.TEXT_AND_IMAGE;

            string greedleListText = string.Join("\n", greedles
                                                 .Select(greedle => $"{greedle.name} {Vector3Utils.ToShorthand(greedle.position)}"));

            outputSurface.WriteText(string.Join("\n",
                                                "Greedles",
                                                "Called List " + calledList + " times",
                                                "Called CheckForUpdates " + checkForUpdates + " times",
                                                "Recieved a Greedle Response " + greedleResponsesCollected + " times",
                                                greedles.Count,
                                                greedleListText
                                                )
                                    );
        }