added a way to create console commands
This commit is contained in:
@@ -310,7 +310,7 @@ namespace Barotrauma
|
|||||||
return client;
|
return client;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void AssignOnClientRequestExecute(string names, Action<Client, Vector2, string[]> onClientRequestExecute)
|
public static void AssignOnClientRequestExecute(string names, Action<Client, Vector2, string[]> onClientRequestExecute)
|
||||||
{
|
{
|
||||||
var matchingCommand = commands.Find(c => c.names.Intersect(names.Split('|')).Count() > 0);
|
var matchingCommand = commands.Find(c => c.names.Intersect(names.Split('|')).Count() > 0);
|
||||||
if (matchingCommand == null)
|
if (matchingCommand == null)
|
||||||
|
|||||||
@@ -73,6 +73,8 @@ namespace Barotrauma
|
|||||||
{
|
{
|
||||||
GameMain.Server.StartGame();
|
GameMain.Server.StartGame();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void AssignOnClientRequestExecute(string names, object onExecute) => DebugConsole.AssignOnClientRequestExecute(names, (Client a, Vector2 b, string[] c) => { env.CallFunction(onExecute, new object[] { a, b, c }); });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ namespace Barotrauma
|
|||||||
private static readonly int messagesPerFile = 5000;
|
private static readonly int messagesPerFile = 5000;
|
||||||
public const string SavePath = "ConsoleLogs";
|
public const string SavePath = "ConsoleLogs";
|
||||||
|
|
||||||
private static void AssignOnExecute(string names, Action<string[]> onExecute)
|
public static void AssignOnExecute(string names, Action<string[]> onExecute)
|
||||||
{
|
{
|
||||||
var matchingCommand = commands.Find(c => c.names.Intersect(names.Split('|')).Count() > 0);
|
var matchingCommand = commands.Find(c => c.names.Intersect(names.Split('|')).Count() > 0);
|
||||||
if (matchingCommand == null)
|
if (matchingCommand == null)
|
||||||
|
|||||||
@@ -288,6 +288,20 @@ namespace Barotrauma
|
|||||||
}
|
}
|
||||||
return enabledPackages;
|
return enabledPackages;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void AddCommand(string name, string help, object onExecute, object getValidArgs = null, bool isCheat = false)
|
||||||
|
{
|
||||||
|
DebugConsole.Commands.Add(new DebugConsole.Command(name, help, (string[] arg1) => { env.CallFunction(onExecute, new object[] { arg1 }); },
|
||||||
|
() => {
|
||||||
|
var result = env.CallFunction(getValidArgs, new object[] { });
|
||||||
|
if (result == null || !(result is string[][])) { return null; }
|
||||||
|
return (string[][])result;
|
||||||
|
|
||||||
|
}, isCheat = false));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AssignOnExecute(string names, object onExecute) => DebugConsole.AssignOnExecute(names, (string[] a) => { env.CallFunction(onExecute, new object[] { a }); });
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user