diff --git a/GamecraftModdingAPI/Commands/CommandBuilder.cs b/GamecraftModdingAPI/Commands/CommandBuilder.cs
index f0f9258..d5f1b51 100644
--- a/GamecraftModdingAPI/Commands/CommandBuilder.cs
+++ b/GamecraftModdingAPI/Commands/CommandBuilder.cs
@@ -19,6 +19,8 @@ namespace GamecraftModdingAPI.Commands
private ICustomCommandEngine commandEngine;
+ private bool fromExisting = false;
+
///
/// Create a new command builder.
///
@@ -138,6 +140,96 @@ namespace GamecraftModdingAPI.Commands
return this;
}
+ ///
+ /// Build the command from an existing command.
+ ///
+ /// The command. Use Invoke() to execute it.
+ public SimpleCustomCommandEngine FromExisting()
+ {
+ if (string.IsNullOrWhiteSpace(name))
+ {
+ throw new InvalidOperationException("Command name must be defined before FromExisting() is called");
+ }
+ if (!ExistingCommands.Exists(name))
+ {
+ throw new InvalidOperationException("Command cannot be built from existing because it does not exist.");
+ }
+ fromExisting = true;
+ return new SimpleCustomCommandEngine(
+ () => { ExistingCommands.Call(name); },
+ name,
+ description);
+ }
+
+ ///
+ /// Build the command from an existing command.
+ ///
+ /// The command. Use Invoke() to execute it.
+ /// The 1st parameter's type.
+ public SimpleCustomCommandEngine FromExisting()
+ {
+ if (string.IsNullOrWhiteSpace(name))
+ {
+ throw new InvalidOperationException("Command name must be defined before FromExisting() is called");
+ }
+ if (!ExistingCommands.Exists(name))
+ {
+ throw new InvalidOperationException("Command cannot be built from existing because it does not exist.");
+ }
+ fromExisting = true;
+ return new SimpleCustomCommandEngine(
+ (A a) => { ExistingCommands.Call(name, a); },
+ name,
+ description);
+ }
+
+ ///
+ /// Build the command from an existing command.
+ ///
+ /// The command. Use Invoke() to execute it.
+ /// The 1st parameter's type.
+ /// The 2nd parameter's type.
+ public SimpleCustomCommandEngine FromExisting()
+ {
+ if (string.IsNullOrWhiteSpace(name))
+ {
+ throw new InvalidOperationException("Command name must be defined before FromExisting() is called");
+ }
+ if (!ExistingCommands.Exists(name))
+ {
+ throw new InvalidOperationException("Command cannot be built from existing because it does not exist.");
+ }
+ fromExisting = true;
+ return new SimpleCustomCommandEngine(
+ (A a, B b) => { ExistingCommands.Call(name, a, b); },
+ name,
+ description);
+ }
+
+ ///
+ /// Build the command from an existing command.
+ ///
+ /// The command. Use Invoke() to execute it.
+ /// The 1st parameter's type.
+ /// The 2nd parameter's type.
+ /// The 3rd parameter's type.
+ public SimpleCustomCommandEngine FromExisting()
+ {
+ if (string.IsNullOrWhiteSpace(name))
+ {
+ throw new InvalidOperationException("Command name must be defined before FromExisting() is called");
+ }
+ if (!ExistingCommands.Exists(name))
+ {
+ throw new InvalidOperationException("Command cannot be built from existing because it does not exist.");
+ }
+ fromExisting = true;
+ return new SimpleCustomCommandEngine(
+ (A a, B b, C c) => { ExistingCommands.Call(name, a, b, c); },
+ name,
+ description);
+ }
+
///
/// Build the command.
///
@@ -149,6 +241,10 @@ namespace GamecraftModdingAPI.Commands
{
throw new InvalidOperationException("Command name must be defined before Build() is called");
}
+ if (fromExisting)
+ {
+ throw new InvalidOperationException("Command was already built by FromExisting()");
+ }
if (commandEngine == null)
{
throw new InvalidOperationException("Command action must be defined before Build() is called");
diff --git a/GamecraftModdingAPI/Commands/SimpleCustomCommandEngine.cs b/GamecraftModdingAPI/Commands/SimpleCustomCommandEngine.cs
index d99edce..ebf0758 100644
--- a/GamecraftModdingAPI/Commands/SimpleCustomCommandEngine.cs
+++ b/GamecraftModdingAPI/Commands/SimpleCustomCommandEngine.cs
@@ -57,5 +57,10 @@ namespace GamecraftModdingAPI.Commands
this.Name = name;
this.Description = description;
}
+
+ public void Invoke()
+ {
+ runCommand();
+ }
}
}
diff --git a/GamecraftModdingAPI/Commands/SimpleCustomCommandEngine1.cs b/GamecraftModdingAPI/Commands/SimpleCustomCommandEngine1.cs
index 307cac6..a8dd96b 100644
--- a/GamecraftModdingAPI/Commands/SimpleCustomCommandEngine1.cs
+++ b/GamecraftModdingAPI/Commands/SimpleCustomCommandEngine1.cs
@@ -47,6 +47,11 @@ namespace GamecraftModdingAPI.Commands
this.runCommand = command;
this.Name = name;
this.Description = description;
+ }
+
+ public void Invoke(A a)
+ {
+ runCommand(a);
}
}
}
diff --git a/GamecraftModdingAPI/Commands/SimpleCustomCommandEngine2.cs b/GamecraftModdingAPI/Commands/SimpleCustomCommandEngine2.cs
index 2e162aa..8333cd2 100644
--- a/GamecraftModdingAPI/Commands/SimpleCustomCommandEngine2.cs
+++ b/GamecraftModdingAPI/Commands/SimpleCustomCommandEngine2.cs
@@ -47,6 +47,11 @@ namespace GamecraftModdingAPI.Commands
this.runCommand = command;
this.Name = name;
this.Description = description;
+ }
+
+ public void Invoke(A a, B b)
+ {
+ runCommand(a, b);
}
}
}
diff --git a/GamecraftModdingAPI/Commands/SimpleCustomCommandEngine3.cs b/GamecraftModdingAPI/Commands/SimpleCustomCommandEngine3.cs
index e88b153..e5570c3 100644
--- a/GamecraftModdingAPI/Commands/SimpleCustomCommandEngine3.cs
+++ b/GamecraftModdingAPI/Commands/SimpleCustomCommandEngine3.cs
@@ -47,6 +47,11 @@ namespace GamecraftModdingAPI.Commands
this.runCommand = command;
this.Name = name;
this.Description = description;
+ }
+
+ public void Invoke(A a, B b, C c)
+ {
+ runCommand(a, b, c);
}
}
}