Cogwheel integration, more code structure
This commit is contained in:
@@ -7,16 +7,10 @@ namespace ADEPT.Core;
|
||||
|
||||
public static class ADEPT
|
||||
{
|
||||
private static CommandsManager _commandsManager = new CommandsManager();
|
||||
private static ICogwheelConsole _cogwheelConsole = new GodotCogwheelConsole();
|
||||
public static Main MainNode { get; private set; }
|
||||
|
||||
public static MainNode MainNode { get; private set; }
|
||||
|
||||
public static void Initialize(MainNode mainNode)
|
||||
public static void Initialize(Main mainNode)
|
||||
{
|
||||
COGWHEEL.Initialize(_commandsManager, _cogwheelConsole);
|
||||
COGWHEEL.AddAssembly(Assembly.GetCallingAssembly());
|
||||
|
||||
MainNode = mainNode;
|
||||
}
|
||||
|
||||
|
||||
1
ADEPT-Godot/Core/Scripts/ADEPT.cs.uid
Normal file
1
ADEPT-Godot/Core/Scripts/ADEPT.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://b8cf4qnyf2hyu
|
||||
@@ -1,45 +1,103 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using Cogwheel;
|
||||
using Godot;
|
||||
|
||||
namespace ADEPT.Core.Cogwheel;
|
||||
|
||||
public class GodotCogwheelConsole : ICogwheelConsole
|
||||
public partial class GodotCogwheelConsole : Control, ICogwheelConsole
|
||||
{
|
||||
public string OpeningMessage { get; set; }
|
||||
public bool IsRunning { get; set; }
|
||||
public CommandsManager CommandsManager { get; set; }
|
||||
|
||||
[Export] private string _openingMessage = "ADEPT Console";
|
||||
[Export] private TextEdit _input;
|
||||
[Export] private RichTextLabel _output;
|
||||
[Export] private Godot.Collections.Dictionary<string, Color> _colors = new()
|
||||
{
|
||||
{"error", new Color(1, 0, 0)},
|
||||
{"warning", new Color(1, 1, 0)},
|
||||
{"log", new Color(1, 1, 1)},
|
||||
{"info", new Color(0, 0, 1)},
|
||||
{"commandHighlight", new Color(0, 0.8f, 0.4f)},
|
||||
};
|
||||
|
||||
private CommandsManager _commandsManager;
|
||||
private CodeHighlighter _codeHighlighter;
|
||||
|
||||
public void Initialize(CommandsManager commandsManager)
|
||||
{
|
||||
_commandsManager = commandsManager;
|
||||
_codeHighlighter = new CodeHighlighter();
|
||||
_input.SyntaxHighlighter = _codeHighlighter;
|
||||
|
||||
_codeHighlighter.KeywordColors = BuildKeywords();
|
||||
}
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_output.Text += _openingMessage + "\n";
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void Log(string message)
|
||||
{
|
||||
|
||||
Write(message + "\n");
|
||||
}
|
||||
|
||||
public void LogError(string message)
|
||||
{
|
||||
|
||||
Log($"[color=#{_colors["error"].ToHtml()}]{message}[/color]");
|
||||
}
|
||||
|
||||
public void LogWarning(string message)
|
||||
{
|
||||
|
||||
Log($"[color=#{_colors["warning"].ToHtml()}]{message}[/color]");
|
||||
}
|
||||
|
||||
public void LogInfo(string message)
|
||||
{
|
||||
Log($"[color=#{_colors["info"].ToHtml()}]{message}[/color]");
|
||||
}
|
||||
|
||||
public void Write(string message)
|
||||
{
|
||||
|
||||
_output.Text += message;
|
||||
}
|
||||
|
||||
public void ClearConsole()
|
||||
{
|
||||
|
||||
_output.Text = "";
|
||||
}
|
||||
|
||||
public void Exit()
|
||||
{
|
||||
|
||||
Visible = false;
|
||||
}
|
||||
|
||||
public string OpeningMessage { get; set; }
|
||||
public bool IsRunning { get; set; }
|
||||
public CommandsManager CommandsManager { get; set; }
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
if (Input.IsActionJustPressed("Enter") && _input.HasFocus() && _input.Text.Length > 0)
|
||||
{
|
||||
var command = _input.Text;
|
||||
_input.Clear();
|
||||
_output.Text += $"> {command}\n";
|
||||
_commandsManager.RunCommand(command);
|
||||
}
|
||||
}
|
||||
|
||||
private Godot.Collections.Dictionary BuildKeywords()
|
||||
{
|
||||
var keywords = new Godot.Collections.Dictionary();
|
||||
foreach (var commandName in _commandsManager.Commands.Keys)
|
||||
{
|
||||
keywords.Add(commandName, _colors["commandHighlight"].ToHtml());
|
||||
}
|
||||
|
||||
return keywords;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://cgn58uiwyog25
|
||||
@@ -0,0 +1 @@
|
||||
uid://casaduku5g3p0
|
||||
@@ -0,0 +1 @@
|
||||
uid://bcf583puvlvt1
|
||||
1
ADEPT-Godot/Core/Scripts/Interfaces/Lesson/IPage.cs.uid
Normal file
1
ADEPT-Godot/Core/Scripts/Interfaces/Lesson/IPage.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://n46c56nkxhni
|
||||
@@ -0,0 +1 @@
|
||||
uid://clgpj02pia5d2
|
||||
1
ADEPT-Godot/Core/Scripts/Lesson/BasePageComponent.cs.uid
Normal file
1
ADEPT-Godot/Core/Scripts/Lesson/BasePageComponent.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://cwhhuavq5ximh
|
||||
1
ADEPT-Godot/Core/Scripts/Lesson/Lesson.cs.uid
Normal file
1
ADEPT-Godot/Core/Scripts/Lesson/Lesson.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://dy3wuh6e6yjda
|
||||
1
ADEPT-Godot/Core/Scripts/Lesson/LessonHandler.cs.uid
Normal file
1
ADEPT-Godot/Core/Scripts/Lesson/LessonHandler.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://b8aqy8n1dyd7c
|
||||
1
ADEPT-Godot/Core/Scripts/Lesson/Page.cs.uid
Normal file
1
ADEPT-Godot/Core/Scripts/Lesson/Page.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://dfasrsmo4r2oi
|
||||
42
ADEPT-Godot/Core/Scripts/Main.cs
Normal file
42
ADEPT-Godot/Core/Scripts/Main.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using System.Reflection;
|
||||
using Godot;
|
||||
using ADEPT.Core;
|
||||
using ADEPT.Core.Cogwheel;
|
||||
using Cogwheel;
|
||||
|
||||
|
||||
namespace ADEPT.Core;
|
||||
|
||||
public partial class Main : Node
|
||||
{
|
||||
private static CommandsManager _commandsManager;
|
||||
private static ICogwheelConsole _cogwheelConsole;
|
||||
|
||||
public CanvasLayer MainCanvas { get; private set; }
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
MainCanvas = GetNode<CanvasLayer>("MainCanvas");
|
||||
|
||||
ADEPT.Initialize(this);
|
||||
|
||||
_commandsManager = new CommandsManager();
|
||||
_cogwheelConsole = MainCanvas.GetNode<GodotCogwheelConsole>("CogwheelConsole");
|
||||
if (_cogwheelConsole is null) throw new System.Exception("CogwheelConsole not found in MainNode.");
|
||||
|
||||
_commandsManager.AddAssembly(Assembly.GetExecutingAssembly());
|
||||
_commandsManager.AddAssembly(Assembly.GetAssembly(typeof(CommandsManager)));
|
||||
|
||||
COGWHEEL.Initialize(_commandsManager, _cogwheelConsole);
|
||||
|
||||
GD.Print("ADEPT initialized.");
|
||||
|
||||
COGWHEEL.RegisterObject(this);
|
||||
}
|
||||
|
||||
[Command(Name = "test", Description = "Test command.")]
|
||||
private void Test()
|
||||
{
|
||||
COGWHEEL.LogWarning("Testing!\nTesting!\nTesting!");
|
||||
}
|
||||
}
|
||||
1
ADEPT-Godot/Core/Scripts/Main.cs.uid
Normal file
1
ADEPT-Godot/Core/Scripts/Main.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://dnmj6a1ptvwry
|
||||
@@ -4,8 +4,5 @@ namespace ADEPT.Core;
|
||||
|
||||
public partial class MainNode : Node
|
||||
{
|
||||
public override void _Ready()
|
||||
{
|
||||
ADEPT.Initialize(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user