Beispiel #1
0
        /// <summary>
        /// Sets up all the initial debug console variables and functions used in the game.
        /// </summary>
        private void SetUpDebugVals()
        {
            // Add all variables
            _debugConsole.AddVar("showFramerate", false);
            _debugConsole.AddVar("drawBorders", false);
            _debugConsole.AddVar("drawGrids", false);
            _debugConsole.AddVar("drawCollision", false);
            _debugConsole.AddVar("collisionChecks", false);
            _debugConsole.AddVar("systemRuntime", false);
            _debugConsole.AddVar("showCameraPos", false);
            _debugConsole.AddVar("showKeys", false);

            // Add all functions
            _debugConsole.AddFunc("ToggleFullscreen", (string[] args) => _graphics.ToggleFullScreen());
            _debugConsole.AddFunc("PopScene", (string[] args) => _scenes.Pop());

            _debugConsole.AddFunc("TestUI", (string[] args) => _scenes.Push(new UITest(_gameObjects, Content)));
        }
Beispiel #2
0
        /// <summary>
        /// Handles setting the variable using the consoles Vars property.
        /// Checks if the identifier only starts with an alpha or underscore
        /// and handles any type checking or parse errors.
        /// </summary>
        /// <param name="console">Console to handle.</param>
        public override void Handle(MBConsole console)
        {
            // Get the type-specific value from object
            var typedVal = Convert.ChangeType(_value.Value, _value.Type);

            // Check if identifier exists
            if (_ident.Length <= 0)
            {
                console.Write("Parse error: Identifier expected.");
                return;
            }

            // Check if value is valid
            if (typedVal.GetType() == typeof(object))
            {
                console.Write("Parse error: Value expected.");
                return;
            }

            // Check if identifier is valid
            if (!Regex.Match(_ident, "[a-zA-Z_][a-zA-Z0-9_]*").Success)
            {
                console.Write(
                    "Parse error: Identifier must start with an" +
                    " alpha or underscore character."
                    );
                return;
            }

            // Check if the console already has the variable and assign
            // the new value if so
            if (!console.Vars.ContainsKey(_ident))
            {
                console.AddVar(_ident, typedVal);
                return;
            }

            // Otherwise create a new variable
            console.Vars[_ident] = typedVal;
        }