/// <summary>
 /// Listen to model update signal to track difficulty changes.
 /// </summary>
 /// <returns>The model update.</returns>
 /// <param name="vo">.</param>
 protected void OnModelUpdate(ITutorialTrigger vo)
 {
     _currentRoundTriggers.Add((ITutorialTrigger)vo);
 }
Beispiel #2
0
 public virtual void TriggerTutorial(ITutorialTrigger trigger)
 {
     OnTutorialTrigger?.Invoke(trigger);
 }
        public ITutorialStateHandler GetTutorialTypeAndUpdate()
        {
            // if currently tutorial is running update its loop
            if (_currentTutorialConfig != null)
            {
                var tutFinished = IncreaseTutorialLoop(_currentTutorialHandler.TutorialLoopIncrease);
                if (tutFinished)
                {
                    var tutorialType = _currentTutorialConfig.HandlerType;
                    //finish tutorial
                    _currentTutorialConfig = null;
                    _currentTutorialHandler.Dispose();
                    _currentTutorialHandler = null;
                    // mark how may times this type of tutorial finished for running it again
                    if (_tutorialRuns.ContainsKey(tutorialType))
                    {
                        _tutorialRuns[tutorialType]++;
                    }
                    else
                    {
                        _tutorialRuns.Add(tutorialType, 1);
                    }
                    // dispatch tutorial finish signal
                    OnUpdate?.Invoke(new GuidedTourUpdateVO(false, tutorialType.Name));
                }
                else
                {
                    //tutorial still running
                    _currentRoundTriggers = new List <ITutorialTrigger>();
                    return(_currentTutorialHandler);
                }
            }
            //if there is no tutorial or it was finished check if new one should be started
            // and there is no current running tutorial -> start a new one
            if (_currentRoundTriggers.Count > 0 && _currentTutorialConfig == null)
            {
                ITutorialConfiguration newTutorialConfig  = null;
                ITutorialTrigger       newTutorialTrigger = null;
                foreach (var trigger in _currentRoundTriggers)
                {
                    foreach (var config in _exerciseConfiguration.TutorialConfigurations)
                    {
                        if (config.TriggerType != null && trigger.GetType() == config.TriggerType)
                        {
                            // if there is a new tutorial config with still defined repeats
                            // and this tutorial wasn't been shown already enough times
                            if (config != null && config.Repeats > 0 && GetTutorialRuns(config.HandlerType) == 0)
                            {
                                if (newTutorialConfig == null)
                                {
                                    newTutorialConfig  = config;
                                    newTutorialTrigger = trigger;
                                }
                                else if (config.Priority > newTutorialConfig.Priority)
                                {
                                    newTutorialConfig  = config;
                                    newTutorialTrigger = trigger;
                                }
                            }
                        }
                    }
                }

                if (newTutorialConfig != null)
                {
                    // assign new tutorial as currently running
                    _currentTutorialConfig = newTutorialConfig;
                    // set tutorial first loop
                    _tutorialLoops = 1;
                    // dispatch tutorial started signal
                    OnUpdate?.Invoke(new GuidedTourUpdateVO(true, _currentTutorialConfig.HandlerType.Name));

                    // indicate new tutorial
                    _currentTutorialHandler         = (ITutorialStateHandler)Activator.CreateInstance(_currentTutorialConfig.HandlerType);
                    _currentTutorialHandler.Trigger = newTutorialTrigger;
                    _currentRoundTriggers           = new List <ITutorialTrigger>();
                    return(_currentTutorialHandler);
                }
            }
            _currentRoundTriggers = new List <ITutorialTrigger>();

            //there is no tutorial right now
            return(TYPE_NO_TUTORIAL);
        }