diff --git a/Cogwheel/.idea/.idea.Cogwheel/.idea/vcs.xml b/Cogwheel/.idea/.idea.Cogwheel/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/Cogwheel/.idea/.idea.Cogwheel/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Cogwheel/Assembly-CSharp.csproj b/Cogwheel/Assembly-CSharp.csproj index f645a39..d579197 100644 --- a/Cogwheel/Assembly-CSharp.csproj +++ b/Cogwheel/Assembly-CSharp.csproj @@ -45,13 +45,17 @@ - + + + + + /home/spudnut/Unity/Hub/Editor/2022.3.36f1/Editor/Data/Managed/UnityEngine/UnityEngine.dll diff --git a/Cogwheel/Assets/Cogwheel/Scripts/COGWHEEL.cs b/Cogwheel/Assets/Cogwheel/Scripts/COGWHEEL.cs index 458f74c..51c0540 100644 --- a/Cogwheel/Assets/Cogwheel/Scripts/COGWHEEL.cs +++ b/Cogwheel/Assets/Cogwheel/Scripts/COGWHEEL.cs @@ -1,12 +1,85 @@ +using OpenCover.Framework.Model; +using UnityEngine; + namespace Cogwheel { public static class COGWHEEL { public static ICommandsManager CommandsManager { get; } + public static CogwheelSettings Settings { get; } + public static CogwheelConsole Console { get; private set; } static COGWHEEL() { CommandsManager = new CommandsManager(); + CommandsManager.GetCommands(); + Settings = Resources.Load("CogwheelSettings"); + if (Settings is null) + { + Debug.LogError("CogwheelSettings not found. Make sure you have a CogwheelSettings asset in a Resources folder."); + return; + } + Console = GameObject.Instantiate(Settings.CogwheelConsolePrefab).GetComponent(); } + + #region BUILT-IN COMMANDS + + [Command(Description = "Logs a message to the console.")] + public static void Log(string message) + { + Console.Log(message); + } + + [Command(Description = "Logs an error message to the console.")] + public static void LogError(string message) + { + Console.LogError(message); + } + + [Command(Description = "Clears the console.")] + public static void Clear() + { + Console.Clear(); + } + + [Command(Description = "Lists all available commands.")] + public static void Help() + { + foreach (var command in CommandsManager.Commands.Values) + { + if (command.Method.IsStatic) + { + Console.Log($"{command.Name} - {command.Description}"); + } + else + { + if (CommandsManager.SceneContext is not null) + { + foreach (var behaviour in CommandsManager.SceneContext.GetComponents()) + { + if (behaviour.GetType() == command.Method.DeclaringType) + { + Console.Log($"({command.Method.DeclaringType.Name}) : {command.Name} - {command.Description}"); + } + else + { + Console.Log($"({command.Method.DeclaringType.Name}) : {command.Name} - {command.Description}"); + } + } + } + else + { + Console.Log($"({command.Method.DeclaringType.Name}) : {command.Name} - {command.Description}"); + } + } + + //Console.Log($"({command.Method.DeclaringType.Name}) : {command.Name} - {command.Description}"); + } + } + + + #endregion + + } } \ No newline at end of file diff --git a/Cogwheel/Assets/Cogwheel/Scripts/CogwheelSettings.cs b/Cogwheel/Assets/Cogwheel/Scripts/CogwheelSettings.cs new file mode 100644 index 0000000..bc2bf96 --- /dev/null +++ b/Cogwheel/Assets/Cogwheel/Scripts/CogwheelSettings.cs @@ -0,0 +1,10 @@ +using UnityEngine; + +namespace Cogwheel +{ + [CreateAssetMenu(fileName = "CogwheelSettings", menuName = "Cogwheel/CogwheelSettings", order = 0)] + public class CogwheelSettings : ScriptableObject + { + public CogwheelConsole CogwheelConsolePrefab; + } +} \ No newline at end of file diff --git a/Cogwheel/Assets/Cogwheel/Scripts/CogwheelSettings.cs.meta b/Cogwheel/Assets/Cogwheel/Scripts/CogwheelSettings.cs.meta new file mode 100644 index 0000000..cf8177e --- /dev/null +++ b/Cogwheel/Assets/Cogwheel/Scripts/CogwheelSettings.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 53d39a5b2f874ce2b49327a3ec509eba +timeCreated: 1727924347 \ No newline at end of file diff --git a/Cogwheel/Assets/Cogwheel/Scripts/Test.cs b/Cogwheel/Assets/Cogwheel/Scripts/Test.cs deleted file mode 100644 index 9963b15..0000000 --- a/Cogwheel/Assets/Cogwheel/Scripts/Test.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using Cogwheel; -using UnityEngine; - -public class Test : MonoBehaviour -{ - private void Start() - { - COGWHEEL.CommandsManager.GetCommands(); - string commands = ""; - foreach (var command in COGWHEEL.CommandsManager.Commands) - { - commands += command.Key + " | "; - } - Debug.Log(commands); - - COGWHEEL.CommandsManager.SceneContext = gameObject; - COGWHEEL.CommandsManager.RunCommand("private 10 WHAT 100.5"); - } - - [Command(Description = "This is a test command")] - public static void TestMethod() - { - Debug.Log("TestMethod called"); - } - - [Command(CommandName = "private", Description = "This is a private command")] - private void PrivateCommand(int value, string text, float f) - { - Debug.Log($"PrivateCommand called: int is {value} and string is {text} and float is {f}"); - } -} diff --git a/Cogwheel/Assets/Cogwheel/Test.cs b/Cogwheel/Assets/Cogwheel/Test.cs new file mode 100644 index 0000000..4a7b347 --- /dev/null +++ b/Cogwheel/Assets/Cogwheel/Test.cs @@ -0,0 +1,21 @@ +using System.Collections; +using System.Collections.Generic; +using Cogwheel; +using UnityEngine; + +public class Test : MonoBehaviour +{ + // Start is called before the first frame update + void Start() + { + Debug.Log(COGWHEEL.Settings.CogwheelConsolePrefab.name); + //COGWHEEL.CommandsManager.SceneContext = gameObject; + } + + [Command(Description = "Test command.")] + private void TestCommand() + { + + } + +} diff --git a/Cogwheel/Assets/Cogwheel/Scripts/Test.cs.meta b/Cogwheel/Assets/Cogwheel/Test.cs.meta similarity index 83% rename from Cogwheel/Assets/Cogwheel/Scripts/Test.cs.meta rename to Cogwheel/Assets/Cogwheel/Test.cs.meta index 655e9d9..7e53609 100644 --- a/Cogwheel/Assets/Cogwheel/Scripts/Test.cs.meta +++ b/Cogwheel/Assets/Cogwheel/Test.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 5f2dd85165475cf7a81bf4b02e9502f4 +guid: 4a61e49036c312c83a47481446b0c01a MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Cogwheel/Assets/Cogwheel/UI.meta b/Cogwheel/Assets/Cogwheel/UI.meta new file mode 100644 index 0000000..c72b537 --- /dev/null +++ b/Cogwheel/Assets/Cogwheel/UI.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: c518ec6d6afdadbbf994a9fd6f78626c +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Cogwheel/Assets/Cogwheel/UI/CogwheelConsole.cs b/Cogwheel/Assets/Cogwheel/UI/CogwheelConsole.cs new file mode 100644 index 0000000..6be68c3 --- /dev/null +++ b/Cogwheel/Assets/Cogwheel/UI/CogwheelConsole.cs @@ -0,0 +1,52 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using Cogwheel; +using UnityEngine; +using UnityEngine.UIElements; + +public class CogwheelConsole : MonoBehaviour +{ + [SerializeField] private UIDocument uiDocument; + + private VisualElement _consoleRoot; + private TextField _inputField; + private Label _outputLabel; + + private void Start() + { + _consoleRoot = uiDocument.rootVisualElement; + _inputField = _consoleRoot.Q("InputTextField"); + _outputLabel = _consoleRoot.Q