|
|
@@ -19,6 +19,8 @@ namespace GamecraftModdingAPI.Commands |
|
|
|
|
|
|
|
private ICustomCommandEngine commandEngine; |
|
|
|
|
|
|
|
private bool fromExisting = false; |
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// Create a new command builder. |
|
|
|
/// </summary> |
|
|
@@ -138,6 +140,96 @@ namespace GamecraftModdingAPI.Commands |
|
|
|
return this; |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// Build the command from an existing command. |
|
|
|
/// </summary> |
|
|
|
/// <returns>The command. Use Invoke() to execute it.</returns> |
|
|
|
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); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// Build the command from an existing command. |
|
|
|
/// </summary> |
|
|
|
/// <returns>The command. Use Invoke() to execute it.</returns> |
|
|
|
/// <typeparam name="A">The 1st parameter's type.</typeparam> |
|
|
|
public SimpleCustomCommandEngine<A> FromExisting<A>() |
|
|
|
{ |
|
|
|
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 a) => { ExistingCommands.Call<A>(name, a); }, |
|
|
|
name, |
|
|
|
description); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// Build the command from an existing command. |
|
|
|
/// </summary> |
|
|
|
/// <returns>The command. Use Invoke() to execute it.</returns> |
|
|
|
/// <typeparam name="A">The 1st parameter's type.</typeparam> |
|
|
|
/// <typeparam name="B">The 2nd parameter's type.</typeparam> |
|
|
|
public SimpleCustomCommandEngine<A,B> FromExisting<A,B>() |
|
|
|
{ |
|
|
|
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,B>( |
|
|
|
(A a, B b) => { ExistingCommands.Call<A,B>(name, a, b); }, |
|
|
|
name, |
|
|
|
description); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// Build the command from an existing command. |
|
|
|
/// </summary> |
|
|
|
/// <returns>The command. Use Invoke() to execute it.</returns> |
|
|
|
/// <typeparam name="A">The 1st parameter's type.</typeparam> |
|
|
|
/// <typeparam name="B">The 2nd parameter's type.</typeparam> |
|
|
|
/// <typeparam name="C">The 3rd parameter's type.</typeparam> |
|
|
|
public SimpleCustomCommandEngine<A,B,C> FromExisting<A,B,C>() |
|
|
|
{ |
|
|
|
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,B,C>( |
|
|
|
(A a, B b, C c) => { ExistingCommands.Call<A,B,C>(name, a, b, c); }, |
|
|
|
name, |
|
|
|
description); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// Build the command. |
|
|
|
/// </summary> |
|
|
@@ -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"); |
|
|
|