Artemis.Managers.EffectManager.ChangeEffect C# (CSharp) Method

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
        public void ChangeEffect(EffectModel effectModel, LoopManager loopManager = null)
        {
            if (_waitEffect != null)
            {
                _logger.Debug("Stopping effect because a change is already queued");
                return;
            }

            if (effectModel == null)
                throw new ArgumentNullException(nameof(effectModel));
            if (effectModel is OverlayModel)
                throw new ArgumentException("Can't set an Overlay effect as the active effect");

            if (_deviceManager.ActiveKeyboard == null)
            {
                _logger.Debug("Stopping effect change until keyboard is enabled");
                _waitEffect = effectModel;
                _waitLoopManager = loopManager;
                _deviceManager.OnKeyboardChangedEvent += DeviceManagerOnOnKeyboardChangedEvent;
                _deviceManager.EnableLastKeyboard();
                return;
            }

            // Game models are only used if they are enabled
            var gameModel = effectModel as GameModel;
            if (gameModel != null)
                if (!gameModel.Enabled)
                {
                    _logger.Debug("Cancelling effect change, provided game not enabled");
                    return;
                }


            var wasNull = false;
            if (ActiveEffect == null)
            {
                wasNull = true;
                ActiveEffect = effectModel;
            }

            lock (ActiveEffect)
            {
                if (!wasNull)
                    ActiveEffect.Dispose();

                ActiveEffect = effectModel;
                ActiveEffect.Enable();
                if (!ActiveEffect.Initialized)
                {
                    _logger.Debug("Cancelling effect change, couldn't initialize the effect ({0})", effectModel.Name);
                    ActiveEffect = null;
                    return;
                }
            }

            if (loopManager != null && !loopManager.Running)
            {
                _logger.Debug("Starting LoopManager for effect change");
                loopManager.StartAsync();
            }

            _logger.Debug("Changed active effect to: {0}", effectModel.Name);

            if (ActiveEffect is GameModel || ActiveEffect is ProfilePreviewModel)
                return;

            // Non-game effects are stored as the new LastEffect.
            _generalSettings.LastEffect = ActiveEffect?.Name;
            _generalSettings.Save();
        }

Usage Example

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;
        }
All Usage Examples Of Artemis.Managers.EffectManager::ChangeEffect