Quake-style console for MonoGame
Quake-style console is an in-game command-line interface with swappable command interpreters. It can be used during development to easily manipulate game objects at runtime or allow players to enter cheat codes, for example.
Note that this project is no longer in development. I do try to fix bugs though!
The following is required to successfully compile the QuakeConsole MonoGame solution:
Install the console assembly through NuGet:
PM> Install-Package MonoGame.QuakeConsole.WindowsDX
The console itself is a typical DrawableGameComponent
. The following steps will go through setting it up in a game.
Game
constructor, create the console and add it to the components collection (console itself should be stored in a variable since it must be initialized and manually opened/closed later):ConsoleComponent console;
public Game1()
{
// ...
console = new ConsoleComponent(this);
Components.Add(console);
}
protected override void Update(GameTime gameTime)
{
// ...
// manage previous and current keyboard states
if (previousKeyboardState.IsKeyUp(Keys.OemTilde) && currentKeyboardState.IsKeyDown(Keys.OemTilde))
console.ToggleOpenClose();
}
This has setup the console shell. For the console to actually do anything useful on user input, an interpreter must be configured (see below).
Sometimes it is desirable to prevent other game systems from accepting input while the console window is open. For this, it is required to know if the console is currently open (accepting input) or closed. This can be checked by the console.IsAcceptingInput
property.
Python interpreter can be used to interpret user input as Python code. It is extremely useful to, for example, manipulate game objects at runtime.
Install the interpreter assembly through NuGet (this will also bring in the console if it hasn't been installed already):
PM> Install-Package MonoGame.QuakeConsole.PythonInterpreter.WindowsDX
var interpreter = new PythonInterpreter();
console.Interpreter = interpreter;
interpreter.AddVariable("name", myVariable);
The object's public members can now be accessed from the console using the passed variable's name (press ctrl + space [by default] to autocomplete input to known variables/types/members).
Manual interpreter can be used to define commands and their corresponding actions for the console manually. Useful to execute some behavior on command or provide players means to input cheat codes, for example.
Install the interpreter assembly through NuGet (this will also bring in the console if it hasn't been installed already):
PM> Install-Package MonoGame.QuakeConsole.ManualInterpreter.WindowsDX
var interpreter = new ManualInterpreter();
console.Interpreter = interpreter;
A command is essentially a delegate that is invoked when user inputs the name of the command. The delegate provides an array of arguments separated by spaces (similar to arguments in a Windows console application) and optionally can return a string value that is output to the console.
interpreter.RegisterCommand("name", action);
where action is of type Action<string[]>
or Func<string[], string>
.
Provides autocompletion for registered command names (ctrl + space by default).
Roslyn interpreter can be used to interpret user input as C# code using the Roslyn scripting API. It is useful to, for example, manipulate game objects at runtime.
Install the interpreter assembly through NuGet (this will also bring in the console if it hasn't been installed already):
PM> Install-Package MonoGame.QuakeConsole.RoslynInterpreter.WindowsDX
var interpreter = new RoslynInterpreter();
console.Interpreter = interpreter;
interpreter.AddVariable("name", myVariable);
The object's public members can now be accessed from the console using the passed variable's name.
Due to an issue at Roslyn side, global variables must be accessed through a 'globals' wrapper object:
globals.myVariable
RoslynInterpreter does not provide any autocompletion features.
dotnet pack -c Release MonoGame.QuakeConsole.DesktopGL.sln
dotnet pack -c Release MonoGame.QuakeConsole.WindowsDX.sln
<version>
with version to be released):VERSION=<version>
dotnet nuget push Source/bin/Release/MonoGame.QuakeConsole.DesktopGL.$VERSION.nupkg --api-key $NUGET_API_KEY --source https://api.nuget.org/v3/index.json
dotnet nuget push Source/bin/Release/MonoGame.QuakeConsole.WindowsDX.$VERSION.nupkg --api-key $NUGET_API_KEY --source https://api.nuget.org/v3/index.json
dotnet nuget push Interpreters/ManualInterpreter/bin/Release/MonoGame.QuakeConsole.ManualInterpreter.DesktopGL.$VERSION.nupkg --api-key $NUGET_API_KEY --source https://api.nuget.org/v3/index.json
dotnet nuget push Interpreters/ManualInterpreter/bin/Release/MonoGame.QuakeConsole.ManualInterpreter.WindowsDX.$VERSION.nupkg --api-key $NUGET_API_KEY --source https://api.nuget.org/v3/index.json
dotnet nuget push Interpreters/PythonInterpreter/bin/Release/MonoGame.QuakeConsole.PythonInterpreter.DesktopGL.$VERSION.nupkg --api-key $NUGET_API_KEY --source https://api.nuget.org/v3/index.json
dotnet nuget push Interpreters/PythonInterpreter/bin/Release/MonoGame.QuakeConsole.PythonInterpreter.WindowsDX.$VERSION.nupkg --api-key $NUGET_API_KEY --source https://api.nuget.org/v3/index.json
dotnet nuget push Interpreters/RoslynInterpreter/bin/Release/MonoGame.QuakeConsole.RoslynInterpreter.WindowsDX.$VERSION.nupkg --api-key $NUGET_API_KEY --source https://api.nuget.org/v3/index.json