This commit is contained in:
Chris Bell 2025-01-02 16:25:49 -06:00
commit 78e9943067
26 changed files with 478 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
obj/
bin/

58
Game.cs Normal file
View File

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

6
Program.cs Normal file
View File

@ -0,0 +1,6 @@
// See https://aka.ms/new-console-template for more information
using Cogwheel;
Game game = new();
game.Init();

0
README.md Normal file
View File

17
RaylibCogwheel.csproj Normal file
View File

@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CogwheelLib" Version="1.2.0" />
<PackageReference Include="ImGui.NET" Version="1.91.0.1" />
<PackageReference Include="Raylib-cs" Version="7.0.0" />
<PackageReference Include="rlImgui-cs" Version="3.0.0" />
</ItemGroup>
</Project>

198
RaylibCogwheelConsole.cs Normal file
View File

@ -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<string> _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!");
}
}

BIN
bin/Debug/net9.0/CogwheelLib.dll Executable file

Binary file not shown.

BIN
bin/Debug/net9.0/ImGui.NET.dll Executable file

Binary file not shown.

BIN
bin/Debug/net9.0/Raylib-cs.dll Executable file

Binary file not shown.

BIN
bin/Debug/net9.0/RaylibCogwheel Executable file

Binary file not shown.

View File

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

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,12 @@
{
"runtimeOptions": {
"tfm": "net9.0",
"framework": {
"name": "Microsoft.NETCore.App",
"version": "9.0.0"
},
"configProperties": {
"System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false
}
}
}

View File

@ -0,0 +1,9 @@
[Window][Debug##Default]
Pos=60,60
Size=400,400
Collapsed=0
[Window][Cogwheel Console]
Size=2560,1080
Collapsed=0

BIN
bin/Debug/net9.0/rlImGui.dll Executable file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.