diff --git a/GamecraftModdingAPI/Commands/CommandEngineFactory.cs b/GamecraftModdingAPI/Commands/CommandEngineFactory.cs
new file mode 100644
index 0000000..ddcdcb8
--- /dev/null
+++ b/GamecraftModdingAPI/Commands/CommandEngineFactory.cs
@@ -0,0 +1,17 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace GamecraftModdingAPI.Commands
+{
+ ///
+ /// UNIMPLEMENTED!
+ /// Convenient factories for command engines
+ ///
+ public static class CommandEngineFactory
+ {
+ //TODO
+ }
+}
diff --git a/GamecraftModdingAPI/Commands/CommandManager.cs b/GamecraftModdingAPI/Commands/CommandManager.cs
new file mode 100644
index 0000000..6ff3046
--- /dev/null
+++ b/GamecraftModdingAPI/Commands/CommandManager.cs
@@ -0,0 +1,56 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Svelto.ECS;
+
+namespace GamecraftModdingAPI.Commands
+{
+ ///
+ /// Keeps track of custom commands
+ /// This is used to add, remove and get command engines
+ ///
+ public static class CommandManager
+ {
+ private static Dictionary _customCommands = new Dictionary();
+
+ public static void AddCommand(ICustomCommandEngine engine)
+ {
+ _customCommands[engine.Name] = engine;
+ }
+
+ public static bool ExistsCommand(string name)
+ {
+ return _customCommands.ContainsKey(name);
+ }
+
+ public static bool ExistsCommand(ICustomCommandEngine engine)
+ {
+ return ExistsCommand(engine.Name);
+ }
+
+ public static ICustomCommandEngine GetCommand(string name)
+ {
+ return _customCommands[name];
+ }
+
+ public static Dictionary GetCommands()
+ {
+ return _customCommands;
+ }
+
+ public static void RemoveCommand(string name)
+ {
+ _customCommands.Remove(name);
+ }
+
+ public static void RegisterEngines(EnginesRoot enginesRoot)
+ {
+ foreach (var key in _customCommands.Keys)
+ {
+ enginesRoot.AddEngine(_customCommands[key]);
+ }
+ }
+ }
+}
diff --git a/GamecraftModdingAPI/Commands/CommandPatch.cs b/GamecraftModdingAPI/Commands/CommandPatch.cs
index fb4f320..bc75df5 100644
--- a/GamecraftModdingAPI/Commands/CommandPatch.cs
+++ b/GamecraftModdingAPI/Commands/CommandPatch.cs
@@ -15,14 +15,17 @@ using GamecraftModdingAPI.Utility;
namespace GamecraftModdingAPI.Commands
{
+ ///
+ /// Patch of RobocraftX.GUI.CommandLine.CommandLineCompositionRoot.Compose()
+ ///
[HarmonyPatch]
public static class CommandPatch
{
- public static void Prefix(UnityContext contextHolder, EnginesRoot enginesRoot, World physicsWorld, Action reloadGame, MultiplayerInitParameters multiplayerParameters)
+ public static void Postfix(UnityContext contextHolder, EnginesRoot enginesRoot, World physicsWorld, Action reloadGame, MultiplayerInitParameters multiplayerParameters)
{
- Logging.Log("Command Line was loaded");
+ Logging.MetaDebugLog("Command Line was loaded");
// When a game is loaded, register the command engines
- // TODO
+ CommandManager.RegisterEngines(enginesRoot);
}
public static MethodBase TargetMethod(HarmonyInstance instance)
diff --git a/GamecraftModdingAPI/Commands/CommandRegistrationHelper.cs b/GamecraftModdingAPI/Commands/CommandRegistrationHelper.cs
new file mode 100644
index 0000000..7e48dfc
--- /dev/null
+++ b/GamecraftModdingAPI/Commands/CommandRegistrationHelper.cs
@@ -0,0 +1,67 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using uREPL;
+using RobocraftX.CommandLine.Custom;
+
+namespace GamecraftModdingAPI.Commands
+{
+ ///
+ /// Convenient methods for registering commands to Gamecraft.
+ /// All methods register to the command line and console block by default.
+ ///
+ public static class CommandRegistrationHelper
+ {
+ public static void Register(string name, Action action, string desc, bool noConsole = false)
+ {
+ RuntimeCommands.Register(name, action, desc);
+ if (noConsole) { return; }
+ ConsoleCommands.Register(name, action, desc);
+ }
+
+ public static void Register(string name, Action