Various QOL changes
This commit is contained in:
parent
c48543138d
commit
22b25cd8a8
@ -16,7 +16,7 @@ public class DeafultCogwheelConsole : ICogwheelConsole
|
|||||||
CommandsManager = commandsManager;
|
CommandsManager = commandsManager;
|
||||||
CommandsManager.RegisterObject(this);
|
CommandsManager.RegisterObject(this);
|
||||||
|
|
||||||
Log(OpeningMessage);
|
Write(OpeningMessage);
|
||||||
|
|
||||||
IsRunning = true;
|
IsRunning = true;
|
||||||
while (IsRunning)
|
while (IsRunning)
|
||||||
@ -41,6 +41,11 @@ public class DeafultCogwheelConsole : ICogwheelConsole
|
|||||||
{
|
{
|
||||||
Console.WriteLine($"[COGWHEEL WARNING] {message}");
|
Console.WriteLine($"[COGWHEEL WARNING] {message}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Write(string message)
|
||||||
|
{
|
||||||
|
Console.WriteLine(message);
|
||||||
|
}
|
||||||
|
|
||||||
public void ClearConsole()
|
public void ClearConsole()
|
||||||
{
|
{
|
||||||
|
@ -43,6 +43,11 @@ public static class COGWHEEL
|
|||||||
_console.LogWarning(message);
|
_console.LogWarning(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void Write(string message)
|
||||||
|
{
|
||||||
|
_console.Write(message);
|
||||||
|
}
|
||||||
|
|
||||||
// == Built-in commands == //
|
// == Built-in commands == //
|
||||||
[Command(Name = "quit", Description = "Quits the Cogwheel console.")]
|
[Command(Name = "quit", Description = "Quits the Cogwheel console.")]
|
||||||
public static void QuitCogwheelConsole()
|
public static void QuitCogwheelConsole()
|
||||||
@ -76,7 +81,7 @@ public static class COGWHEEL
|
|||||||
{
|
{
|
||||||
foreach (var command in _commandsManager.Commands)
|
foreach (var command in _commandsManager.Commands)
|
||||||
{
|
{
|
||||||
_console.Log($"{command.Key} - {command.Value.Description}");
|
Write($"{_commandsManager.GetCommandUsage(command.Value)}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,7 +91,7 @@ public static class COGWHEEL
|
|||||||
_console.Log($"Current context: {_commandsManager.CurrentContext.GetType()} : {_commandsManager.CurrentContextGuid}");
|
_console.Log($"Current context: {_commandsManager.CurrentContext.GetType()} : {_commandsManager.CurrentContextGuid}");
|
||||||
}
|
}
|
||||||
|
|
||||||
[Command(Name = "test")]
|
[Command(Name = "test", Description = "Creates a new TestClass object.")]
|
||||||
public static void CreateTestObject(string name)
|
public static void CreateTestObject(string name)
|
||||||
{
|
{
|
||||||
_console.Log($"Creating new TestClass object with name: {name}");
|
_console.Log($"Creating new TestClass object with name: {name}");
|
||||||
@ -110,7 +115,7 @@ public static class COGWHEEL
|
|||||||
Log("Available registered objects:");
|
Log("Available registered objects:");
|
||||||
foreach (var (guid, obj) in filteredObjects)
|
foreach (var (guid, obj) in filteredObjects)
|
||||||
{
|
{
|
||||||
Log($"- {obj.GetType().FullName} : {guid}");
|
Write($"- {obj.GetType().FullName} : {guid}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,11 +90,33 @@ public class CommandsManager
|
|||||||
|
|
||||||
public virtual string GetCommandUsage(ICommand command)
|
public virtual string GetCommandUsage(ICommand command)
|
||||||
{
|
{
|
||||||
|
string output = "";
|
||||||
|
if (!command.Method.IsStatic)
|
||||||
|
{
|
||||||
|
output += $"|{command.Method.DeclaringType?.FullName}| ";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
output += "|Global| ";
|
||||||
|
}
|
||||||
|
|
||||||
|
output += $"{command.Name}: ";
|
||||||
|
|
||||||
|
if (!string.IsNullOrWhiteSpace(command.Description))
|
||||||
|
{
|
||||||
|
output += $"{command.Description} ";
|
||||||
|
}
|
||||||
|
|
||||||
string paramUsage = string.Join(" ",
|
string paramUsage = string.Join(" ",
|
||||||
command.Method.GetParameters().Select(param =>
|
command.Method.GetParameters().Select(param =>
|
||||||
$"<{(param.IsDefined(typeof(ParamArrayAttribute)) ? "params " : "")}{param}>"));
|
$"<{(param.IsDefined(typeof(ParamArrayAttribute)) ? "params " : "")}{param}>"));
|
||||||
|
|
||||||
|
if (!string.IsNullOrWhiteSpace(paramUsage))
|
||||||
|
{
|
||||||
|
output += $"- {paramUsage}";
|
||||||
|
}
|
||||||
|
|
||||||
return $"{command.Name}: {paramUsage}";
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual bool ExecuteCommand(object obj, (ICommand command, List<object> args) command)
|
public virtual bool ExecuteCommand(object obj, (ICommand command, List<object> args) command)
|
||||||
|
@ -10,6 +10,7 @@ public interface ICogwheelConsole
|
|||||||
public void Log(string message);
|
public void Log(string message);
|
||||||
public void LogError(string message);
|
public void LogError(string message);
|
||||||
public void LogWarning(string message);
|
public void LogWarning(string message);
|
||||||
|
public void Write(string message);
|
||||||
public void ClearConsole();
|
public void ClearConsole();
|
||||||
public void Exit();
|
public void Exit();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user