commit 78e9943067dfe70544575365b720a6397a83a73f Author: Chris Bell Date: Thu Jan 2 16:25:49 2025 -0600 Init diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c6e49ef --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +obj/ +bin/ diff --git a/Game.cs b/Game.cs new file mode 100644 index 0000000..1fb32b7 --- /dev/null +++ b/Game.cs @@ -0,0 +1,58 @@ +using System.Reflection; +using RaylibCogwheel; +using Raylib_cs; +using rlImGui_cs; +using Cogwheel; + +public class Game +{ + + private RaylibCogwheelConsole _console = new(); + private CommandsManager _commandsManager = new(); + + public void Init() + { + _commandsManager.AddAssembly(Assembly.GetAssembly(typeof(CommandsManager))); + _commandsManager.AddAssembly(Assembly.GetCallingAssembly()); + + COGWHEEL.Initialize(_commandsManager, _console); + + Raylib.InitWindow(1280, 720, "RaylibCogwheel"); + Raylib.SetTargetFPS(60); + + rlImGui.Setup(); + + while (!Raylib.WindowShouldClose()) + { + Update(); + + Raylib.BeginDrawing(); + Raylib.ClearBackground(new Color(0, 50, 80)); + rlImGui.Begin(); + + Draw(); + DrawImGui(); + + rlImGui.End(); + Raylib.EndDrawing(); + } + + rlImGui.Shutdown(); + Raylib.CloseWindow(); + } + + private void Update() + { + _console.Update(); + } + + private void Draw() + { + // All drawing code goes here + } + + private void DrawImGui() + { + _console.Draw(); + } +} \ No newline at end of file diff --git a/Program.cs b/Program.cs new file mode 100644 index 0000000..8eefa7e --- /dev/null +++ b/Program.cs @@ -0,0 +1,6 @@ +// See https://aka.ms/new-console-template for more information + +using Cogwheel; + +Game game = new(); +game.Init(); \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/RaylibCogwheel.csproj b/RaylibCogwheel.csproj new file mode 100644 index 0000000..7f806f8 --- /dev/null +++ b/RaylibCogwheel.csproj @@ -0,0 +1,17 @@ + + + + Exe + net9.0 + enable + enable + + + + + + + + + + diff --git a/RaylibCogwheelConsole.cs b/RaylibCogwheelConsole.cs new file mode 100644 index 0000000..2dde15e --- /dev/null +++ b/RaylibCogwheelConsole.cs @@ -0,0 +1,198 @@ +using System.Text.RegularExpressions; +using Cogwheel; +using ImGuiNET; +using Raylib_cs; + +namespace RaylibCogwheel; + +public class RaylibCogwheelConsole : ICogwheelConsole +{ + public string OpeningMessage { get; set; } = + "===========================\n" + + "| COGWHEEL RAYLIB CONSOLE |\n" + + "==========================="; + public bool IsRunning { get; set; } + public CommandsManager CommandsManager { get; set; } + public bool IsOpen { get; set; } = false; + + private string _input = string.Empty; + private string _output = string.Empty; + private int _output_buffer_size = 1000; + //private List _history = new(); + + private bool _scrollToBottom = false; + private string hint = ""; + + + public void Initialize(CommandsManager commandsManager) + { + COGWHEEL.RegisterObject(this); + CommandsManager = commandsManager; + + Write(OpeningMessage); + } + + [Command(Name = "log", Description = "Logs a message to the console.")] + public void Log(string message) + { + Write(message); + } + + public void LogError(string message) + { + WriteColor("[COGWHEEL ERROR] " + message, new Color(255, 0, 0, 255)); // Red color + } + + public void LogWarning(string message) + { + WriteColor("[COGWHEEL WARNING] " + message, new Color(255, 255, 0, 255)); // Yellow color + } + + public void WriteColor(string message, Color color) + { + string colorCode = $"{color.R},{color.G},{color.B},{color.A}"; + _output += $"[Color={colorCode}]{message}[/Color]\n"; + TrimOutputBuffer(); + } + + public void Write(string message) + { + _output += message; + // log [Color=255,0,0,255]G[/Color][Color=0,255,0,255]A[/Color][Color=0,0,255,255]Y[/Color] + TrimOutputBuffer(); + } + + public void ClearConsole() + { + _output = string.Empty; + } + + public void Exit() + { + Raylib.CloseWindow(); + } + + public void ToggleConsole() + { + IsOpen = !IsOpen; + } + + public void Update() + { + if (Raylib.IsKeyPressed(KeyboardKey.Grave)) + { + ToggleConsole(); + } + + if (CommandsManager.CurrentContext != null && hint != CommandsManager.CurrentContext.GetType().FullName) + { + hint = CommandsManager.CurrentContext.GetType().FullName; + } + } + + public void Draw() + { + if (!IsOpen) return; + + ImGui.SetNextWindowSize(new System.Numerics.Vector2(Raylib.GetScreenWidth(), (float)(Raylib.GetScreenHeight() * 0.75)), ImGuiCond.Always); + ImGui.SetNextWindowPos(new System.Numerics.Vector2(0, 0), ImGuiCond.Always); + + if (ImGui.Begin("Cogwheel Console", ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoMove | ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.NoTitleBar)) + { + // Display the output text in a scrollable region + ImGui.BeginChild("ScrollingRegion", new System.Numerics.Vector2(0, -ImGui.GetTextLineHeightWithSpacing() - 10), ImGuiChildFlags.None); + + // Split the output into lines + var lines = _output.Split('\n'); + var regex = new Regex(@"\[Color=(\d+),(\d+),(\d+),(\d+)\](.*?)\[/Color\]", RegexOptions.Compiled); + + foreach (var line in lines) + { + var matches = regex.Matches(line); + int lastIndex = 0; + + foreach (Match match in matches) + { + // Add text before the color tag + if (match.Index > lastIndex) + { + ImGui.PushStyleColor(ImGuiCol.Text, new System.Numerics.Vector4(1.0f, 1.0f, 1.0f, 1.0f)); // White for normal text + ImGui.Text(line.Substring(lastIndex, match.Index - lastIndex)); + ImGui.PopStyleColor(); + ImGui.SameLine(0, 0); + } + + // Set the color for the text inside the color tags + var color = new System.Numerics.Vector4( + float.Parse(match.Groups[1].Value) / 255.0f, + float.Parse(match.Groups[2].Value) / 255.0f, + float.Parse(match.Groups[3].Value) / 255.0f, + float.Parse(match.Groups[4].Value) / 255.0f + ); + + ImGui.PushStyleColor(ImGuiCol.Text, color); + ImGui.Text(match.Groups[5].Value); + ImGui.PopStyleColor(); + ImGui.SameLine(0, 0); + + lastIndex = match.Index + match.Length; + } + + // Add remaining text after the last color tag + if (lastIndex < line.Length) + { + ImGui.PushStyleColor(ImGuiCol.Text, new System.Numerics.Vector4(1.0f, 1.0f, 1.0f, 1.0f)); // White for normal text + ImGui.Text(line.Substring(lastIndex)); + ImGui.PopStyleColor(); + } + ImGui.NewLine(); // Move to the next line after processing the current line + } + + if (_scrollToBottom) + { + ImGui.SetScrollHereY(1.0f); + _scrollToBottom = false; + } + ImGui.EndChild(); + + ImGui.Separator(); + + ImGui.SetKeyboardFocusHere(); + ImGui.PushStyleColor(ImGuiCol.FrameBg, new System.Numerics.Vector4(0, 0, 0, 1)); + ImGui.PushItemWidth(-1); + ImGui.InputText("", ref _input, 256, ImGuiInputTextFlags.EnterReturnsTrue); + ImGui.PopItemWidth(); + ImGui.PopStyleColor(); + + if (_input != "" && ImGui.IsKeyPressed(ImGuiKey.Enter)) + { + ProcessInput(_input); + _input = string.Empty; + _scrollToBottom = true; + } + } + } + + private void ProcessInput(string input) + { + _output += "\n" + "> " + input + "\n"; + TrimOutputBuffer(); + + COGWHEEL.RunCommand(input); + } + + private void TrimOutputBuffer() + { + var lines = _output.Split('\n'); + if (lines.Length > _output_buffer_size) + { + _output = string.Join("\n", lines.Skip(lines.Length - _output_buffer_size)); + } + } + + [Command(Name = "test")] + private void Test() + { + Write("[COLOR=255,0,255,255] Test command executed!"); + } +} \ No newline at end of file diff --git a/bin/Debug/net9.0/CogwheelLib.dll b/bin/Debug/net9.0/CogwheelLib.dll new file mode 100755 index 0000000..fcf39c6 Binary files /dev/null and b/bin/Debug/net9.0/CogwheelLib.dll differ diff --git a/bin/Debug/net9.0/ImGui.NET.dll b/bin/Debug/net9.0/ImGui.NET.dll new file mode 100755 index 0000000..82d9a96 Binary files /dev/null and b/bin/Debug/net9.0/ImGui.NET.dll differ diff --git a/bin/Debug/net9.0/Raylib-cs.dll b/bin/Debug/net9.0/Raylib-cs.dll new file mode 100755 index 0000000..b980503 Binary files /dev/null and b/bin/Debug/net9.0/Raylib-cs.dll differ diff --git a/bin/Debug/net9.0/RaylibCogwheel b/bin/Debug/net9.0/RaylibCogwheel new file mode 100755 index 0000000..030190e Binary files /dev/null and b/bin/Debug/net9.0/RaylibCogwheel differ diff --git a/bin/Debug/net9.0/RaylibCogwheel.deps.json b/bin/Debug/net9.0/RaylibCogwheel.deps.json new file mode 100644 index 0000000..7dcacd3 --- /dev/null +++ b/bin/Debug/net9.0/RaylibCogwheel.deps.json @@ -0,0 +1,176 @@ +{ + "runtimeTarget": { + "name": ".NETCoreApp,Version=v9.0", + "signature": "" + }, + "compilationOptions": {}, + "targets": { + ".NETCoreApp,Version=v9.0": { + "RaylibCogwheel/1.0.0": { + "dependencies": { + "CogwheelLib": "1.2.0", + "ImGui.NET": "1.91.0.1", + "Raylib-cs": "7.0.0", + "rlImgui-cs": "3.0.0" + }, + "runtime": { + "RaylibCogwheel.dll": {} + } + }, + "CogwheelLib/1.2.0": { + "runtime": { + "lib/net9.0/CogwheelLib.dll": { + "assemblyVersion": "0.0.0.0", + "fileVersion": "0.0.0.0" + } + } + }, + "ImGui.NET/1.91.0.1": { + "dependencies": { + "System.Buffers": "4.5.1", + "System.Numerics.Vectors": "4.5.0", + "System.Runtime.CompilerServices.Unsafe": "6.0.0" + }, + "runtime": { + "lib/net8.0/ImGui.NET.dll": { + "assemblyVersion": "1.91.0.1", + "fileVersion": "1.91.0.1" + } + }, + "runtimeTargets": { + "runtimes/linux-x64/native/libcimgui.so": { + "rid": "linux-x64", + "assetType": "native", + "fileVersion": "0.0.0.0" + }, + "runtimes/osx/native/libcimgui.dylib": { + "rid": "osx", + "assetType": "native", + "fileVersion": "0.0.0.0" + }, + "runtimes/win-arm64/native/cimgui.dll": { + "rid": "win-arm64", + "assetType": "native", + "fileVersion": "0.0.0.0" + }, + "runtimes/win-x64/native/cimgui.dll": { + "rid": "win-x64", + "assetType": "native", + "fileVersion": "0.0.0.0" + }, + "runtimes/win-x86/native/cimgui.dll": { + "rid": "win-x86", + "assetType": "native", + "fileVersion": "0.0.0.0" + } + } + }, + "Raylib-cs/7.0.0": { + "runtime": { + "lib/net6.0/Raylib-cs.dll": { + "assemblyVersion": "0.0.0.0", + "fileVersion": "0.0.0.0" + } + }, + "runtimeTargets": { + "runtimes/linux-x64/native/libraylib.so": { + "rid": "linux-x64", + "assetType": "native", + "fileVersion": "0.0.0.0" + }, + "runtimes/osx-arm64/native/libraylib.dylib": { + "rid": "osx-arm64", + "assetType": "native", + "fileVersion": "0.0.0.0" + }, + "runtimes/osx-x64/native/libraylib.dylib": { + "rid": "osx-x64", + "assetType": "native", + "fileVersion": "0.0.0.0" + }, + "runtimes/win-x64/native/raylib.dll": { + "rid": "win-x64", + "assetType": "native", + "fileVersion": "0.0.0.0" + }, + "runtimes/win-x86/native/raylib.dll": { + "rid": "win-x86", + "assetType": "native", + "fileVersion": "0.0.0.0" + } + } + }, + "rlImgui-cs/3.0.0": { + "dependencies": { + "ImGui.NET": "1.91.0.1", + "Raylib-cs": "7.0.0" + }, + "runtime": { + "lib/net6.0/rlImGui.dll": { + "assemblyVersion": "3.0.0.0", + "fileVersion": "3.0.0.0" + } + } + }, + "System.Buffers/4.5.1": {}, + "System.Numerics.Vectors/4.5.0": {}, + "System.Runtime.CompilerServices.Unsafe/6.0.0": {} + } + }, + "libraries": { + "RaylibCogwheel/1.0.0": { + "type": "project", + "serviceable": false, + "sha512": "" + }, + "CogwheelLib/1.2.0": { + "type": "package", + "serviceable": true, + "sha512": "sha512-dd4Lfzyvi6Ds4O654BjdzBJEKyGeWDzotZroBxB9t3c2+5LXL99O3aR5KwWjM9GgmCDoO/yR7xfcBiG26LEItA==", + "path": "cogwheellib/1.2.0", + "hashPath": "cogwheellib.1.2.0.nupkg.sha512" + }, + "ImGui.NET/1.91.0.1": { + "type": "package", + "serviceable": true, + "sha512": "sha512-Q7IoWTeAJ3jywfvgbFdhKCtcSeRt90ghrZiZlnHPOlcojrPcx9UbqaM3rXWsDg6vv1JKqz1BhNIK2RIwRV4Pxw==", + "path": "imgui.net/1.91.0.1", + "hashPath": "imgui.net.1.91.0.1.nupkg.sha512" + }, + "Raylib-cs/7.0.0": { + "type": "package", + "serviceable": true, + "sha512": "sha512-8SvFkeKujjBToZTzVGKiYQErvQaekDxWIdNIVUDiayKamMR7vT9ZzUv0W4BfQ6iA02KOui5I9HSzI6Cq9u4jCA==", + "path": "raylib-cs/7.0.0", + "hashPath": "raylib-cs.7.0.0.nupkg.sha512" + }, + "rlImgui-cs/3.0.0": { + "type": "package", + "serviceable": true, + "sha512": "sha512-WGf3wzCQDcNuWSNFtFRGWPxlNY1a+ME/NF6bhOofN/npCFWQ88Yej2VrU2ZvDT8X6VX260MqjiD5ZR4fF20cTQ==", + "path": "rlimgui-cs/3.0.0", + "hashPath": "rlimgui-cs.3.0.0.nupkg.sha512" + }, + "System.Buffers/4.5.1": { + "type": "package", + "serviceable": true, + "sha512": "sha512-Rw7ijyl1qqRS0YQD/WycNst8hUUMgrMH4FCn1nNm27M4VxchZ1js3fVjQaANHO5f3sN4isvP4a+Met9Y4YomAg==", + "path": "system.buffers/4.5.1", + "hashPath": "system.buffers.4.5.1.nupkg.sha512" + }, + "System.Numerics.Vectors/4.5.0": { + "type": "package", + "serviceable": true, + "sha512": "sha512-QQTlPTl06J/iiDbJCiepZ4H//BVraReU4O4EoRw1U02H5TLUIT7xn3GnDp9AXPSlJUDyFs4uWjWafNX6WrAojQ==", + "path": "system.numerics.vectors/4.5.0", + "hashPath": "system.numerics.vectors.4.5.0.nupkg.sha512" + }, + "System.Runtime.CompilerServices.Unsafe/6.0.0": { + "type": "package", + "serviceable": true, + "sha512": "sha512-/iUeP3tq1S0XdNNoMz5C9twLSrM/TH+qElHkXWaPvuNOt+99G75NrV0OS2EqHx5wMN7popYjpc8oTjC1y16DLg==", + "path": "system.runtime.compilerservices.unsafe/6.0.0", + "hashPath": "system.runtime.compilerservices.unsafe.6.0.0.nupkg.sha512" + } + } +} \ No newline at end of file diff --git a/bin/Debug/net9.0/RaylibCogwheel.dll b/bin/Debug/net9.0/RaylibCogwheel.dll new file mode 100644 index 0000000..9ad46cb Binary files /dev/null and b/bin/Debug/net9.0/RaylibCogwheel.dll differ diff --git a/bin/Debug/net9.0/RaylibCogwheel.pdb b/bin/Debug/net9.0/RaylibCogwheel.pdb new file mode 100644 index 0000000..b8b4699 Binary files /dev/null and b/bin/Debug/net9.0/RaylibCogwheel.pdb differ diff --git a/bin/Debug/net9.0/RaylibCogwheel.runtimeconfig.json b/bin/Debug/net9.0/RaylibCogwheel.runtimeconfig.json new file mode 100644 index 0000000..b19c3c8 --- /dev/null +++ b/bin/Debug/net9.0/RaylibCogwheel.runtimeconfig.json @@ -0,0 +1,12 @@ +{ + "runtimeOptions": { + "tfm": "net9.0", + "framework": { + "name": "Microsoft.NETCore.App", + "version": "9.0.0" + }, + "configProperties": { + "System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false + } + } +} \ No newline at end of file diff --git a/bin/Debug/net9.0/imgui.ini b/bin/Debug/net9.0/imgui.ini new file mode 100644 index 0000000..0450628 --- /dev/null +++ b/bin/Debug/net9.0/imgui.ini @@ -0,0 +1,9 @@ +[Window][Debug##Default] +Pos=60,60 +Size=400,400 +Collapsed=0 + +[Window][Cogwheel Console] +Size=2560,1080 +Collapsed=0 + diff --git a/bin/Debug/net9.0/rlImGui.dll b/bin/Debug/net9.0/rlImGui.dll new file mode 100755 index 0000000..0030ad2 Binary files /dev/null and b/bin/Debug/net9.0/rlImGui.dll differ diff --git a/bin/Debug/net9.0/runtimes/linux-x64/native/libcimgui.so b/bin/Debug/net9.0/runtimes/linux-x64/native/libcimgui.so new file mode 100755 index 0000000..754029e Binary files /dev/null and b/bin/Debug/net9.0/runtimes/linux-x64/native/libcimgui.so differ diff --git a/bin/Debug/net9.0/runtimes/linux-x64/native/libraylib.so b/bin/Debug/net9.0/runtimes/linux-x64/native/libraylib.so new file mode 100755 index 0000000..018784a Binary files /dev/null and b/bin/Debug/net9.0/runtimes/linux-x64/native/libraylib.so differ diff --git a/bin/Debug/net9.0/runtimes/osx-arm64/native/libraylib.dylib b/bin/Debug/net9.0/runtimes/osx-arm64/native/libraylib.dylib new file mode 100755 index 0000000..2d87369 Binary files /dev/null and b/bin/Debug/net9.0/runtimes/osx-arm64/native/libraylib.dylib differ diff --git a/bin/Debug/net9.0/runtimes/osx-x64/native/libraylib.dylib b/bin/Debug/net9.0/runtimes/osx-x64/native/libraylib.dylib new file mode 100755 index 0000000..cfdc792 Binary files /dev/null and b/bin/Debug/net9.0/runtimes/osx-x64/native/libraylib.dylib differ diff --git a/bin/Debug/net9.0/runtimes/osx/native/libcimgui.dylib b/bin/Debug/net9.0/runtimes/osx/native/libcimgui.dylib new file mode 100755 index 0000000..3713e33 Binary files /dev/null and b/bin/Debug/net9.0/runtimes/osx/native/libcimgui.dylib differ diff --git a/bin/Debug/net9.0/runtimes/win-arm64/native/cimgui.dll b/bin/Debug/net9.0/runtimes/win-arm64/native/cimgui.dll new file mode 100755 index 0000000..362387d Binary files /dev/null and b/bin/Debug/net9.0/runtimes/win-arm64/native/cimgui.dll differ diff --git a/bin/Debug/net9.0/runtimes/win-x64/native/cimgui.dll b/bin/Debug/net9.0/runtimes/win-x64/native/cimgui.dll new file mode 100755 index 0000000..393c23c Binary files /dev/null and b/bin/Debug/net9.0/runtimes/win-x64/native/cimgui.dll differ diff --git a/bin/Debug/net9.0/runtimes/win-x64/native/raylib.dll b/bin/Debug/net9.0/runtimes/win-x64/native/raylib.dll new file mode 100755 index 0000000..8a9477f Binary files /dev/null and b/bin/Debug/net9.0/runtimes/win-x64/native/raylib.dll differ diff --git a/bin/Debug/net9.0/runtimes/win-x86/native/cimgui.dll b/bin/Debug/net9.0/runtimes/win-x86/native/cimgui.dll new file mode 100755 index 0000000..1064dc4 Binary files /dev/null and b/bin/Debug/net9.0/runtimes/win-x86/native/cimgui.dll differ diff --git a/bin/Debug/net9.0/runtimes/win-x86/native/raylib.dll b/bin/Debug/net9.0/runtimes/win-x86/native/raylib.dll new file mode 100755 index 0000000..bd1b14c Binary files /dev/null and b/bin/Debug/net9.0/runtimes/win-x86/native/raylib.dll differ