Beispiel #1
0
 public ActionContainer(TinBotAction action)
 {
     MovementAcion  = action as MovementAcion;
     FaceAction     = action as FaceAction;
     SpeakAction    = action as SpeakAction;
     SavedAction    = action as SavedAction;
     SequenceAction = action as SequenceAction;
     ToggleAction   = action as ToggleAction;
 }
Beispiel #2
0
 public ActionContainer(TinBotAction action)
 {
     MovementAcion = action as MovementAcion;
     FaceAction = action as FaceAction;
     SpeakAction = action as SpeakAction;
     SavedAction = action as SavedAction;
     SequenceAction = action as SequenceAction;
     ToggleAction = action as ToggleAction;
 }
Beispiel #3
0
        public async Task ExecuteAction(TinBotAction action)
        {
            if (action == null || !_body.IsReady)
                return;

            try
            {
                for (int i = 0; i < Math.Max(1, action.Repeat); i++)
                {
                    switch (action.Type)
                    {
                        case EActionType.Speak:
                            await Speak(((SpeakAction)action).Text);
                            break;
                        case EActionType.Face:
                            var sb = Faces[((FaceAction)action).TinBotFaces];
                            await ExecuteOnMainThread(() => PlayAndPause(sb));
                            break;
                        case EActionType.Toggle:
                            if (_body.IsReady)
                            {
                                await ExecuteToggle((ToggleAction)action);
                            }
                            break;
                        case EActionType.Move:
                            if (_body.IsReady)
                            {
                                var moveAction = (MovementAcion)action;
                                if (_body.Servos.ContainsKey(moveAction.Servo))
                                    await Move(moveAction);
                            }
                            break;
                        case EActionType.Saved:
                            var found = ActionsLib.AllActions().FirstOrDefault(
                                x => x.Name.Equals(((SavedAction) action).ActionName, StringComparison.OrdinalIgnoreCase));
                            if (found != null)
                                await ExecuteAction(found);
                            break;
                        case EActionType.Sequence:
                            var sequenceAction = (SequenceAction)action;
                            foreach (var paralellAction in sequenceAction.Sequence)
                            {
                                List<Task> waiters = new List<Task>();
                                foreach (var actionContainer in paralellAction)
                                {
                                    var a = actionContainer.GetAction();
                                    var t = ExecuteAction(a);
                                    if (!a.IgnoreBlockingInSeries)
                                        waiters.Add(t);
                                }
                                await Task.WhenAll(waiters);
                            }
                            break;
                    }
                    await Task.Delay(action.ExtraWaitTime);
                }
            }
            catch (Exception ex)
            {
                return;
            }
        }