Refactoring, added more logging, minor command structure change.

This commit is contained in:
2020-07-05 23:32:03 -05:00
parent 63a31c491d
commit b2a47ebefc
5 changed files with 43 additions and 37 deletions

View File

@@ -10,7 +10,7 @@ namespace SlatedGameToolkit.Tools.Commands
public class GraphicalPlaygroundCommand : IInvocable
{
private readonly string[] invokers = new string[] {"playground"};
private ConsoleLogListener logListener;
private ConsolePlaygroundListener logListener;
private bool debugging;
public bool Execute(IInteractable interactable, string[] args)
@@ -22,8 +22,6 @@ namespace SlatedGameToolkit.Tools.Commands
interactable.Tell("Engine is already running!");
return true;
}
Logger.AddLogListener((logListener = new ConsoleLogListener(interactable as ConsoleInteraction)));
logListener.Debug = debugging;
GameEngine.Ignite(new MainState());
return true;
} else if (args[0].Equals("stop")) {
@@ -31,7 +29,6 @@ namespace SlatedGameToolkit.Tools.Commands
interactable.Tell("Engine was never running!");
return true;
}
Logger.RemoveLogListener(logListener);
GameEngine.Stop();
return true;
} else if (args[0].Equals("status")) {
@@ -49,6 +46,17 @@ namespace SlatedGameToolkit.Tools.Commands
interactable.Tell(string.Format("Debug will be turned {0} when playground is started.", debugging ? "on" : "off"));
}
return true;
} else if (args[0].Equals("log")) {
if (logListener == null) {
Logger.AddLogListener((logListener = new ConsolePlaygroundListener(interactable as ConsoleInteraction)));
logListener.Debug = debugging;
interactable.Tell("Listening to game engine's logging.");
} else {
Logger.RemoveLogListener(logListener);
logListener = null;
interactable.Tell("Stopped listening to game engine's logging.");
}
return true;
}
return false;
}

View File

@@ -4,21 +4,21 @@ using SlatedGameToolkit.Tools.CommandSystem.Interaction;
namespace SlatedGameToolkit.Tools.Utilities.Playground
{
public class ConsoleLogListener : ILogListener
public class ConsolePlaygroundListener : ILogListener
{
public bool Debug { get; set; }
public LogLevel Level => Debug ? LogLevel.DEBUG : LogLevel.INFO;
private ConsoleInteraction interaction;
public ConsoleLogListener(ConsoleInteraction interaction = null) {
public ConsolePlaygroundListener(ConsoleInteraction interaction = null) {
this.interaction = interaction;
}
public void LogMesesage(string message, DateTime time, LogLevel level)
{
Console.SetCursorPosition(0, Console.CursorTop);
Console.WriteLine(string.Format("Playground [{0}] [{1}]: {2}", level, time.ToString("H:mm:ss"), message));
Console.WriteLine(string.Format("Engine [{0}] [{1}]: {2}", level, time.ToString("H:mm:ss"), message));
if (interaction != null && interaction.Listening) {
Console.SetCursorPosition(0, Console.CursorTop);
Console.Write(interaction.Prefix + "> ");