ChangeEffect() public method

Disables the current effect and changes it to the provided effect.
public ChangeEffect ( EffectModel effectModel, LoopManager loopManager = null ) : void
effectModel Artemis.Models.EffectModel The effect to activate
loopManager LoopManager Optionally pass the LoopManager to automatically start it, if it's not running.
return void
Ejemplo n.º 1
0
        private void Start()
        {
            if (Running)
            {
                return;
            }

            _logger.Debug("Starting LoopManager");

            if (_deviceManager.ActiveKeyboard == null)
            {
                _deviceManager.EnableLastKeyboard();
            }
            // If still null, no last keyboard, so stop.
            if (_deviceManager.ActiveKeyboard == null)
            {
                _logger.Debug("Cancel LoopManager start, no keyboard");
                return;
            }

            if (_effectManager.ActiveEffect == null)
            {
                var lastEffect = _effectManager.GetLastEffect();
                if (lastEffect == null)
                {
                    _logger.Debug("Cancel LoopManager start, no effect");
                    return;
                }
                _effectManager.ChangeEffect(lastEffect);
            }

            Running = true;
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Keeps track of profiles being previewed and sets up the active efffect accordingly
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SetupProfilePreview(object sender, ElapsedEventArgs e)
        {
            if (string.IsNullOrEmpty(_generalSettings.LastKeyboard) || _deviceManager.ChangingKeyboard ||
                ProfilePreviewModel == null)
            {
                return;
            }

            var activePreview = GameViewModels.FirstOrDefault(vm => vm.IsActive);

            if (activePreview == null)
            {
                // Should not be active if no selected profile is set
                if (_effectManager.ActiveEffect != ProfilePreviewModel)
                {
                    return;
                }

                _logger.Debug("Loading last effect after profile preview");
                var lastEffect = _effectManager.GetLastEffect();
                if (lastEffect != null)
                {
                    _effectManager.ChangeEffect(lastEffect);
                }
                else
                {
                    _effectManager.ClearEffect();
                }
            }
            else
            {
                if (_effectManager.ActiveEffect != ProfilePreviewModel && !(_effectManager.ActiveEffect is GameModel))
                {
                    _logger.Debug("Activate profile preview");
                    _effectManager.ChangeEffect(ProfilePreviewModel);
                }

                // LoopManager might be running, this method won't do any harm in that case.
                _loopManager.StartAsync();

                ProfilePreviewModel.ProfileViewModel = activePreview.ProfileEditor.ProfileViewModel;
                if (!ReferenceEquals(ProfilePreviewModel.Profile, activePreview.ProfileEditor.SelectedProfile))
                {
                    ProfilePreviewModel.Profile = activePreview.ProfileEditor.SelectedProfile;
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        ///     Manages active games by keeping an eye on their processes
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ScanProcesses(object sender, ElapsedEventArgs e)
        {
            if (!ProgramEnabled)
            {
                return;
            }

            var runningProcesses = Process.GetProcesses();

            // If the currently active effect is a disabled game, get rid of it.
            if (EffectManager.ActiveEffect != null)
            {
                EffectManager.DisableInactiveGame();
            }

            if (EffectManager.ActiveEffect is ProfilePreviewModel)
            {
                return;
            }

            // If the currently active effect is a no longer running game, get rid of it.
            var activeGame = EffectManager.ActiveEffect as GameModel;

            if (activeGame != null)
            {
                if (!runningProcesses.Any(p => p.ProcessName == activeGame.ProcessName && p.HasExited == false))
                {
                    Logger.Info("Disabling game: {0}", activeGame.Name);
                    EffectManager.DisableGame(activeGame);
                }
            }

            // Look for running games, stopping on the first one that's found.
            var newGame = EffectManager.EnabledGames
                          .FirstOrDefault(g => runningProcesses
                                          .Any(p => p.ProcessName == g.ProcessName && p.HasExited == false));

            if (newGame == null || EffectManager.ActiveEffect == newGame)
            {
                return;
            }
            // If it's not already enabled, do so.
            Logger.Info("Detected and enabling game: {0}", newGame.Name);
            EffectManager.ChangeEffect(newGame, LoopManager);
        }