Example #1
0
        /// <summary>
        /// Adds a state.
        /// </summary>
        /// <param name="state">State to add.</param>
        public bool AddState(GameState state)
        {
            if (state == null)
            {
                throw new ArgumentNullException("State must not be null.");
            }

            if (this.stateByString.ContainsKey(state.Identifier) == false)
            {
                this.stateByString.Add(state.Identifier, state);
                return true;
            }

            Logger.Global.Log("Could not add state. Existing state exists with the identifier: " + state.Identifier, LogLevel.Error);
            return false;
        }
Example #2
0
        /// <summary>
        /// Updates the component with the specified seconds since last update.
        /// </summary>
        /// <param name="seconds">The amount of seconds since last update.</param>
        public void Update(double seconds)
        {
            // Switch state
            if (this.switchData != null && this.stateByString.ContainsKey(this.switchData.NextState))
            {
                if (this.currentState != null)
                {
                    this.currentState.Deactivate(this.switchData);
                    if (this.currentState.IsTemporary)
                    {
                        this.RemoveState(this.currentState.Identifier);
                    }
                }

                this.currentState = this.stateByString[this.switchData.NextState];
                this.currentState.Activate(this.switchData);
                this.switchData = null;
            }

            // Update current state
            if (this.currentState != null)
            {
                this.currentState.Update(seconds);
            }
        }