Skip to content

Commit

Permalink
refs to DebugConsole everywhere...
Browse files Browse the repository at this point in the history
  • Loading branch information
ANU-CHEEKI-BREEKI committed Jun 30, 2023
1 parent 72bd8e6 commit 97ea94d
Show file tree
Hide file tree
Showing 11 changed files with 382 additions and 219 deletions.
47 changes: 35 additions & 12 deletions Runtime/Scripts/IngameDebug/Console/AttributeCommandsInitializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,43 @@
using NDesk.Options;
using UnityEngine;
using System.Diagnostics;
using ANU.IngameDebug.Console.Converters;

namespace ANU.IngameDebug.Console
{
public class AttributeCommandsInitializer : MonoBehaviour
{
private void Start()
{
DebugConsole.Logger.LogInfo($"Start searching {name} commands declared by attributes...");
var init = new AttributeCommandsInitializerProcessor(
DebugConsole.Logger,
DebugConsole.Commands
);
init.Initialize();
}
}

public class AttributeCommandsInitializerProcessor
{
public ILogger Logger { get; }
public ICommandsRegistry Commands { get; set; }

public AttributeCommandsInitializerProcessor(ILogger logger, ICommandsRegistry commands)
{
Commands = commands;
Logger = logger;
}

public void Initialize()
{
Logger.LogInfo($"Start searching commands declared by attributes...");
var timer = StartLog(null);

var assemblies = AppDomain.CurrentDomain.GetAssemblies();

var timerMethods = StartLog("method");

DebugConsole.Commands.RegisterCommands(
Commands.RegisterCommands(
assemblies
.SelectMany(asm => asm.GetTypes())
.Where(t => typeof(UnityEngine.MonoBehaviour).IsAssignableFrom(t))
Expand Down Expand Up @@ -63,7 +85,7 @@ private void Start()

var timerProperty = StartLog("property");

DebugConsole.Commands.RegisterCommands(
Commands.RegisterCommands(
assemblies
.SelectMany(asm => asm.GetTypes())
.Where(t => typeof(UnityEngine.MonoBehaviour).IsAssignableFrom(t))
Expand Down Expand Up @@ -104,7 +126,7 @@ private void Start()

var timerfield = StartLog("field");

DebugConsole.Commands.RegisterCommands(
Commands.RegisterCommands(
assemblies
.SelectMany(asm => asm.GetTypes())
.Where(t => typeof(UnityEngine.MonoBehaviour).IsAssignableFrom(t))
Expand Down Expand Up @@ -144,24 +166,25 @@ private void Start()
Log(timerfield, "field");

Log(timer, null);
var log = $"Searching {name} commands declared by attributes ended.\nOperation elapsed duration: {timer.Elapsed:ss's.'fff'ms'}, ticks: {timer.ElapsedTicks}";
var log = $"Searching commands declared by attributes ended.\nOperation elapsed duration: {timer.Elapsed:ss's.'fff'ms'}, ticks: {timer.ElapsedTicks}";
if (timer.Elapsed.Seconds < 1)
DebugConsole.Logger.LogInfo(log);
Logger.LogInfo(log);
else if (timer.Elapsed.Seconds < 2)
DebugConsole.Logger.LogWarning(log);
Logger.LogWarning(log);
else
DebugConsole.Logger.LogError(log);
Logger.LogError(log);
}

private Stopwatch StartLog(string name)
{
if (name != null)
DebugConsole.Logger.LogInfo($"Start searching {name}...");
Logger.LogInfo($"Start searching {name}...");

var timer = new System.Diagnostics.Stopwatch();
timer.Start();
return timer;
}

private void Log(Stopwatch timer, string name)
{
timer.Stop();
Expand All @@ -171,11 +194,11 @@ private void Log(Stopwatch timer, string name)

var log = $"Searching {name} ended. Operation elapsed duration: {timer.Elapsed:ss's.'fff'ms'}, ticks: {timer.ElapsedTicks}";
if (timer.Elapsed.Seconds < 3)
DebugConsole.Logger.LogInfo(log);
Logger.LogInfo(log);
else if (timer.Elapsed.Seconds < 5)
DebugConsole.Logger.LogWarning(log);
Logger.LogWarning(log);
else
DebugConsole.Logger.LogError(log);
Logger.LogError(log);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,7 @@ public string Preprocess(string input)
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterAssembliesLoaded)]
private static void RegisterSelf() => DebugConsole.Preprocessors.Add(new ExpressionEvaluatorPreprocessor());

[DebugCommand(Name = "$", Description = @"Alias for Evaluate command
You can call this command as nested command to pass expression as parameter.
Use: ""${expression}""
For example: ""echo ${1+4}""")]
[DebugCommand(Name = "$", Description = @"Alias for evaluate command")]
private static string EvaluateAlias(string expression) => Evaluate(expression);

[DebugCommand(
Expand Down
Loading

0 comments on commit 97ea94d

Please sign in to comment.