Add documentation for the console and a doxygen config.

This commit is contained in:
excitedneon 2017-05-08 22:14:52 +03:00
parent 4926530a49
commit b57fd162c8
5 changed files with 2566 additions and 30 deletions

3
.gitignore vendored
View File

@ -52,3 +52,6 @@ sysinfo.txt
# Project Version #
/ProjectSettings/ProjectVersion.txt
# Doxygen #
/Doxygen/

View File

@ -4,50 +4,44 @@ using System.Text.RegularExpressions;
using UnityEngine;
using UnityEngine.UI;
/// <summary>
/// Controls an input and an output to implement a console interface to call
/// arbitrary commands which can be set from anywhere in the program.
/// <seealso cref="Term"/>
/// </summary>
public class DebugConsole : MonoBehaviour {
private static readonly Regex CommandPartRegex = new Regex("([^ \"]+ )|(\"[^\"]+\")");
/// <summary>
/// The parent of the <see cref="InputField"/> and <see cref="TextField"/>.
/// </summary>
public GameObject Panel;
/// <summary>
/// The input for the console.
/// </summary>
public InputField InputField;
/// <summary>
/// The output for the console.
/// </summary>
public Text TextField;
/// <summary>
/// Controls the visibility of the console. For how this is controlled in-game, see <see cref="Update"/>.
/// </summary>
public bool Visible = false;
private Dictionary<string, DebugConsoleAction> Actions = new Dictionary<string, DebugConsoleAction>();
/// <summary>
/// Creates a new <see cref="DebugConsole"/>, and sets the <see cref="Term"/>'s singleton.
/// <seealso cref="Term.SetDebugConsole"/>
/// </summary>
public DebugConsole() {
AddCommand("help", "Lists all commands.", (args) => {
Println("Commands:");
foreach (string Action in Actions.Keys) {
Println("- " + Action);
}
});
AddCommand("help (command)", "Describes the given command.", (args) => {
// Check complete versions of the names (so you can do eg. help "help (command)")
foreach (string Action in Actions.Keys) {
if (Action.Equals(args[0])) {
Println(Actions[Action].Description);
return;
}
}
// Check just names
foreach (string Action in Actions.Keys) {
string[] Parts = Action.Split(' ');
if (Parts[0].Equals(args[0])) {
Println(Actions[Action].Description);
return;
}
}
Println("That command doesn't exist.");
});
AddCommand("print (text)", "Prints the given text.", (args) => {
Println(args[0]);
});
Term.SetDebugConsole(this);
}
/// <summary>
/// Tries to call the command in the <see cref="InputField"/>.
/// </summary>
public void CallCommand() {
if (InputField.text.Length == 0) {
return;
@ -85,15 +79,55 @@ public class DebugConsole : MonoBehaviour {
Actions[command] = new DebugConsoleAction(PrettyDescription, action);
}
/// <summary>
/// Prints text into the DebugConsole and adds a newline.
/// </summary>
/// <param name="text">Text.</param>
public void Println(string text) {
Print(text + "\n");
}
// TODO: Handle removing history when it gets very long. Very long console logs might cause problems when displaying new prints.
/// <summary>
/// Prints text into the Console.
/// </summary>
/// <param name="text">Text.</param>
public void Print(string text) {
TextField.text += text;
}
private void Start() {
AddCommand("help", "Lists all commands.", (args) => {
Println("Commands:");
foreach (string Action in Actions.Keys) {
Println("- " + Action);
}
});
AddCommand("help (command)", "Describes the given command.", (args) => {
// Check complete versions of the names (so you can do eg. help "help (command)")
foreach (string Action in Actions.Keys) {
if (Action.Equals(args[0])) {
Println(Actions[Action].Description);
return;
}
}
// Check just names
foreach (string Action in Actions.Keys) {
string[] Parts = Action.Split(' ');
if (Parts[0].Equals(args[0])) {
Println(Actions[Action].Description);
return;
}
}
Println("That command doesn't exist.");
});
AddCommand("print (text)", "Prints the given text.", (args) => {
Println(args[0]);
});
}
private void Update() {
if (Input.GetButtonDown("Console Toggle")) {
Visible = !Visible;

View File

@ -11,6 +11,10 @@ public class DebugConsoleAction {
this.ActionFunc = actionFunc;
}
/// <summary>
/// Executes the <see cref="ActionFunc"/>.
/// </summary>
/// <param name="command">Command.</param>
public void Call(List<string> command) {
ActionFunc(command);
}

View File

@ -8,10 +8,18 @@ using UnityEngine;
public class Term {
private static DebugConsole Console;
/// <summary>
/// Sets the <see cref="DebugConsole"/> singleton that will be used in other static <see cref="Term"/> functions.
/// </summary>
/// <param name="console">Console.</param>
public static void SetDebugConsole(DebugConsole console) {
Console = console;
}
/// <summary>
/// Returns whether or not the DebugConsole is currently on the screen, ready to be used.
/// </summary>
/// <returns><c>true</c> if is visible; otherwise, <c>false</c>.</returns>
public static bool IsVisible() {
if (Console == null) {
return false;
@ -20,6 +28,10 @@ public class Term {
}
}
/// <summary>
/// See <see cref="DebugConsole.Println"/>.
/// </summary>
/// <param name="text">Text.</param>
public static void Println(string text) {
if (Console == null) {
Debug.Log(text);
@ -28,6 +40,10 @@ public class Term {
}
}
/// <summary>
/// See <see cref="DebugConsole.Print"/>.
/// </summary>
/// <param name="text">Text.</param>
public static void Print(string text) {
if (Console == null) {
Debug.Log(text);
@ -36,6 +52,12 @@ public class Term {
}
}
/// <summary>
/// See <see cref="DebugConsole.AddCommand"/>
/// </summary>
/// <param name="command">Command.</param>
/// <param name="description">Description.</param>
/// <param name="action">Action.</param>
public static void AddCommand(string command, string description, DebugConsoleAction.Action action) {
if (Console != null) {
Console.AddCommand(command, description, action);

2473
Doxygen.conf Normal file

File diff suppressed because it is too large Load Diff