Exemplo n.º 1
0
        /// <summary>
        /// Loads content at the beginning of the game
        /// </summary>
        protected override void LoadContent()
        {
            _spriteBatch   = new SpriteBatch(GraphicsDevice);
            _uiSpriteBatch = new SpriteBatch(GraphicsDevice);

            _debugConsole = new MBConsole(Color.Black, Color.Yellow, Content.Load <SpriteFont>("Fonts/SourceCode"));
            _debugConsole.InitWindow(Graphics);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Prints the variable to the console. If it's not a previously
        /// assigned variable, it will print the variable name itself as
        /// if it's an immediate value.
        /// </summary>
        /// <param name="console">Console to print to.</param>
        public override void Handle(MBConsole console)
        {
            // Check for valid identifier
            if (_ident == string.Empty)
            {
                console.Write("Parse error: Identifier expected.");
                return;
            }

            // Check if the variable exists already
            if (console.Vars.ContainsKey(_ident))
            {
                var printFmt = console.Vars[_ident].ToString();
                // Format string between quotes for printing
                if (console.Vars[_ident] is string)
                {
                    printFmt = "\'" + printFmt + "\'";
                }
                console.Write(printFmt);
                return;
            }

            double testDouble;
            bool   testBool;

            // Checks immediate values. If not a valid string, double, or
            // bool returns parse error, otherwise prints the variable name
            // as if it was an immediate value.
            if (_tokenType == Token.String)
            {
                console.Write("'{0}'", _ident);
            }
            else if (double.TryParse(_ident, out testDouble) ||
                     bool.TryParse(_ident, out testBool))
            {
                console.Write(_ident);
            }
            else
            {
                console.Write(
                    "Parse error: Unknown variable: '{0}'", _ident
                    );
            }
        }
Exemplo n.º 3
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;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Checks for valid identifier and executes the given function
        /// from the console if correctly defined.
        /// </summary>
        /// <param name="console">Console to handle.</param>
        public override void Handle(MBConsole console)
        {
            // Check for valid identifier
            if (_ident.Length <= 0)
            {
                console.Write("Parse error: Identifier expected.");
                return;
            }

            // Check if function exists
            if (console.Funcs.ContainsKey(_ident))
            {
                console.Funcs[_ident].Invoke(_args);
            }
            else
            {
                console.Write(
                    "Parse error: Unknown function: '{0}'",
                    _ident
                    );
            }
        }
Exemplo n.º 5
0
 /// <summary>
 /// Calls the child commands handle method
 /// </summary>
 /// <param name="console">Console to handle.</param>
 public override void Handle(MBConsole console)
 {
     _child.Handle(console);
 }
Exemplo n.º 6
0
 /// <summary>
 /// Quits the game
 /// </summary>
 /// <param name="console">Console to handle.</param>
 public override void Handle(MBConsole console)
 {
     MBGame.ForceQuit = true;
 }
Exemplo n.º 7
0
 /// <summary>
 /// Executes specific logic on the console
 /// </summary>
 /// <param name="console">Game console.</param>
 public abstract void Handle(MBConsole console);