void HandleMessage()
        {
            while (directiveListener.HasPendingMessage)
            {
                var directive = GreedleDirective.FromJSON(JSON.Parse(directiveListener.AcceptMessage().As <string>()));
                switch (directive.type)
                {
                case GreedleDirective.DirectiveType.Respond:
                    IGC.SendBroadcastMessage(
                        "greedle_response",
                        JSON.Stringify(GreedleResponse.ToJSON(new GreedleResponse()
                    {
                        name     = name,
                        position = mainControl.GetPosition()
                    }))
                        ); break;

                case GreedleDirective.DirectiveType.Target:
                {
                    if (directive.targetDirective.addressedTo == name)
                    {
                        Target(directive.targetDirective.target);
                    }
                    break;
                }
                }
            }
        }
 void ListGreedles()
 {
     calledList++;
     greedles.Clear();
     IGC.SendBroadcastMessage("greedle_directive", JSON.Stringify(GreedleDirective.ToJSON(new GreedleDirective()
     {
         type = GreedleDirective.DirectiveType.Respond
     })));
     DrawOutput();
 }
 void SendGreedle(string name, Vector3 target)
 {
     IGC.SendBroadcastMessage("greedle_directive", JSON.Stringify(GreedleDirective.ToJSON(new GreedleDirective()
     {
         type            = GreedleDirective.DirectiveType.Target,
         targetDirective = new GreedleDirective.TargetDirective()
         {
             addressedTo = name,
             target      = target,
         },
     })));
 }
        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");
        }