Cogwheel integration, more code structure

This commit is contained in:
Chris Bell 2025-02-15 01:31:26 -06:00
parent 5ff3525a5e
commit 2ecf7ec93f
22 changed files with 206 additions and 47 deletions

View File

@ -6,4 +6,7 @@
<ItemGroup>
<PackageReference Include="CogwheelLib" Version="1.3.0" />
</ItemGroup>
<ItemGroup>
<Folder Include="Client\Scripts\UI\" />
</ItemGroup>
</Project>

View File

@ -1,5 +1,6 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ACOGWHEEL_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fb946d2ce7ffb4216bc1b230d32963b475600_003F51_003Fe7e8cc77_003FCOGWHEEL_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ACommandsManager_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fb946d2ce7ffb4216bc1b230d32963b475600_003F53_003Fe083e0a5_003FCommandsManager_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/Environment/AssemblyExplorer/XmlDocument/@EntryValue">&lt;AssemblyExplorer&gt;
&lt;Assembly Path="/home/chris/.nuget/packages/cogwheellib/1.3.0/lib/net9.0/CogwheelLib.dll" /&gt;
&lt;/AssemblyExplorer&gt;</s:String></wpf:ResourceDictionary>

View File

@ -1,28 +1,21 @@
[gd_scene load_steps=3 format=3 uid="uid://c35ohffpqfqnr"]
[ext_resource type="Script" uid="uid://geelevcnulxy" path="res://Client/Scripts/UI/Main.cs" id="1_np6pa"]
[ext_resource type="Texture2D" uid="uid://chm704rgdebfb" path="res://icon.png" id="2_swjw6"]
[ext_resource type="PackedScene" uid="uid://caivf0icbv7gk" path="res://Core/Scenes/CogwheelConsole.tscn" id="3_ama40"]
[node name="MainCanvas" type="CanvasLayer"]
[node name="Main" type="Control" parent="."]
layout_mode = 3
[node name="Panel" type="Panel" parent="."]
visible = false
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_np6pa")
size_flags_horizontal = 3
size_flags_vertical = 3
[node name="Panel" type="Panel" parent="Main"]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
[node name="TextureRect" type="TextureRect" parent="Main/Panel"]
[node name="TextureRect" type="TextureRect" parent="Panel"]
layout_mode = 1
anchors_preset = 8
anchor_left = 0.5
@ -36,3 +29,5 @@ offset_bottom = 20.0
grow_horizontal = 2
grow_vertical = 2
texture = ExtResource("2_swjw6")
[node name="CogwheelConsole" parent="." instance=ExtResource("3_ama40")]

View File

@ -1,8 +0,0 @@
using Godot;
namespace ADEPT.Client;
public partial class Main : Control
{
}

View File

@ -0,0 +1,54 @@
[gd_scene load_steps=2 format=3 uid="uid://caivf0icbv7gk"]
[ext_resource type="Script" uid="uid://cgn58uiwyog25" path="res://Core/Scripts/Cogwheel/GodotCogwheelConsole.cs" id="1_23urx"]
[node name="CogwheelConsole" type="Control" node_paths=PackedStringArray("_input", "_output")]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_23urx")
_input = NodePath("VBoxContainer/Input")
_output = NodePath("VBoxContainer/Panel/MarginContainer/Output")
[node name="VBoxContainer" type="VBoxContainer" parent="."]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
[node name="Panel" type="Panel" parent="VBoxContainer"]
layout_mode = 2
size_flags_vertical = 3
[node name="MarginContainer" type="MarginContainer" parent="VBoxContainer/Panel"]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
theme_override_constants/margin_left = 10
theme_override_constants/margin_top = 10
theme_override_constants/margin_right = 10
theme_override_constants/margin_bottom = 10
[node name="Output" type="RichTextLabel" parent="VBoxContainer/Panel/MarginContainer"]
layout_mode = 2
focus_mode = 2
bbcode_enabled = true
scroll_following = true
selection_enabled = true
[node name="Input" type="TextEdit" parent="VBoxContainer"]
custom_minimum_size = Vector2(0, 30)
layout_mode = 2
placeholder_text = "> Enter Command"
wrap_mode = 1
autowrap_mode = 1
scroll_fit_content_height = true
scroll_fit_content_width = true

View File

@ -1,6 +1,9 @@
[gd_scene load_steps=2 format=3 uid="uid://udmowtmx1o3l"]
[gd_scene load_steps=3 format=3 uid="uid://udmowtmx1o3l"]
[ext_resource type="Script" uid="uid://bl2h8ot302x3g" path="res://Core/Scripts/MainNode.cs" id="1_wh72m"]
[ext_resource type="Script" uid="uid://dnmj6a1ptvwry" path="res://Core/Scripts/Main.cs" id="1_0ovck"]
[ext_resource type="PackedScene" uid="uid://c35ohffpqfqnr" path="res://Client/Scenes/MainCanvas.tscn" id="2_0ovck"]
[node name="Main" type="Node"]
script = ExtResource("1_wh72m")
script = ExtResource("1_0ovck")
[node name="MainCanvas" parent="." instance=ExtResource("2_0ovck")]

View File

@ -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;
}

View File

@ -0,0 +1 @@
uid://b8cf4qnyf2hyu

View File

@ -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;
}
}

View File

@ -0,0 +1 @@
uid://cgn58uiwyog25

View File

@ -0,0 +1 @@
uid://casaduku5g3p0

View File

@ -0,0 +1 @@
uid://bcf583puvlvt1

View File

@ -0,0 +1 @@
uid://n46c56nkxhni

View File

@ -0,0 +1 @@
uid://clgpj02pia5d2

View File

@ -0,0 +1 @@
uid://cwhhuavq5ximh

View File

@ -0,0 +1 @@
uid://dy3wuh6e6yjda

View File

@ -0,0 +1 @@
uid://b8aqy8n1dyd7c

View File

@ -0,0 +1 @@
uid://dfasrsmo4r2oi

View 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!");
}
}

View File

@ -0,0 +1 @@
uid://dnmj6a1ptvwry

View File

@ -4,8 +4,5 @@ namespace ADEPT.Core;
public partial class MainNode : Node
{
public override void _Ready()
{
ADEPT.Initialize(this);
}
}

View File

@ -12,7 +12,7 @@ config_version=5
config/name="ADEPT"
config/version="0.0.0"
run/main_scene="uid://c35ohffpqfqnr"
run/main_scene="uid://udmowtmx1o3l"
config/features=PackedStringArray("4.4", "C#", "Forward Plus")
boot_splash/show_image=false
config/icon="uid://chm704rgdebfb"
@ -20,3 +20,12 @@ config/icon="uid://chm704rgdebfb"
[dotnet]
project/assembly_name="ADEPT"
[input]
Enter={
"deadzone": 0.2,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194309,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194310,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
]
}