예제 #1
0
        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;
                }
                }
            }
        }
예제 #2
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),
     }));
 }
 void CheckForUpdates()
 {
     checkForUpdates++;
     while (responseListener.HasPendingMessage)
     {
         greedleResponsesCollected++;
         var response = GreedleResponse.FromJSON(JSON.SyncParse(responseListener.AcceptMessage().As <string>()));
         greedles.Add(new Greedle()
         {
             name = response.name, position = response.position
         });
     }
     DrawOutput();
 }