Various QOL changes
This commit is contained in:
		
							parent
							
								
									c48543138d
								
							
						
					
					
						commit
						22b25cd8a8
					
				@ -16,7 +16,7 @@ public class DeafultCogwheelConsole : ICogwheelConsole
 | 
			
		||||
        CommandsManager = commandsManager;
 | 
			
		||||
        CommandsManager.RegisterObject(this);
 | 
			
		||||
        
 | 
			
		||||
        Log(OpeningMessage);
 | 
			
		||||
        Write(OpeningMessage);
 | 
			
		||||
        
 | 
			
		||||
        IsRunning = true;
 | 
			
		||||
        while (IsRunning)
 | 
			
		||||
@ -42,6 +42,11 @@ public class DeafultCogwheelConsole : ICogwheelConsole
 | 
			
		||||
        Console.WriteLine($"[COGWHEEL WARNING] {message}");
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    public void Write(string message)
 | 
			
		||||
    {
 | 
			
		||||
        Console.WriteLine(message);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void ClearConsole()
 | 
			
		||||
    {
 | 
			
		||||
        Console.Clear();
 | 
			
		||||
 | 
			
		||||
@ -43,6 +43,11 @@ public static class COGWHEEL
 | 
			
		||||
        _console.LogWarning(message);
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    public static void Write(string message)
 | 
			
		||||
    {
 | 
			
		||||
        _console.Write(message);
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    // == Built-in commands == //
 | 
			
		||||
    [Command(Name = "quit", Description = "Quits the Cogwheel console.")]
 | 
			
		||||
    public static void QuitCogwheelConsole()
 | 
			
		||||
@ -76,7 +81,7 @@ public static class COGWHEEL
 | 
			
		||||
    {
 | 
			
		||||
        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}");
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    [Command(Name = "test")]
 | 
			
		||||
    [Command(Name = "test", Description = "Creates a new TestClass object.")]
 | 
			
		||||
    public static void CreateTestObject(string name)
 | 
			
		||||
    {
 | 
			
		||||
        _console.Log($"Creating new TestClass object with name: {name}");
 | 
			
		||||
@ -110,7 +115,7 @@ public static class COGWHEEL
 | 
			
		||||
        Log("Available registered objects:");
 | 
			
		||||
        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)
 | 
			
		||||
    {
 | 
			
		||||
        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(" ",
 | 
			
		||||
            command.Method.GetParameters().Select(param =>
 | 
			
		||||
                $"<{(param.IsDefined(typeof(ParamArrayAttribute)) ? "params " : "")}{param}>"));
 | 
			
		||||
        
 | 
			
		||||
        return $"{command.Name}: {paramUsage}";
 | 
			
		||||
        if (!string.IsNullOrWhiteSpace(paramUsage))
 | 
			
		||||
        {
 | 
			
		||||
            output += $"- {paramUsage}";
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return output;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    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 LogError(string message);
 | 
			
		||||
    public void LogWarning(string message);
 | 
			
		||||
    public void Write(string message);
 | 
			
		||||
    public void ClearConsole();
 | 
			
		||||
    public void Exit();
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user