mirror of
https://github.com/D1GQ/BetterAmongUs.git
synced 2026-10-20 01:46:19 +00:00
Better argument handling
This commit is contained in:
1 parent
52ca6d6156
commit
63cb570402
9 files changed
+10
-21
No files matched your search
@@ -1,9 +1,9 @@
|
||||
namespace BetterAmongUs.Commands
|
||||
{
|
||||
public abstract class BaseArgument(BaseCommand? command)
|
||||
public abstract class BaseArgument(BaseCommand? command, string argInfo)
|
||||
{
|
||||
public BaseCommand? Command { get; } = command;
|
||||
public abstract string ArgInfo { get; }
|
||||
public string ArgInfo { get; } = argInfo;
|
||||
public string Arg { get; set; } = string.Empty;
|
||||
protected virtual string[] ArgSuggestions => GetArgSuggestions.Invoke();
|
||||
public Func<string[]> GetArgSuggestions { get; set; } = () => { return []; };
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
namespace BetterAmongUs.Commands;
|
||||
|
||||
public class BoolArgument(BaseCommand? command) : BaseArgument(command)
|
||||
public class BoolArgument(BaseCommand? command, string argInfo = "{bool}") : BaseArgument(command, argInfo)
|
||||
{
|
||||
public override string ArgInfo => suggestion;
|
||||
public string suggestion = "{bool}";
|
||||
protected override string[] ArgSuggestions => ["true", "false"];
|
||||
public bool? GetBool()
|
||||
{
|
||||
|
||||
@@ -2,10 +2,9 @@
|
||||
|
||||
namespace BetterAmongUs.Commands;
|
||||
|
||||
public class PlayerArgument(BaseCommand? command) : BaseArgument(command)
|
||||
public class PlayerArgument(BaseCommand? command, string argInfo = "{player}") : BaseArgument(command, argInfo)
|
||||
{
|
||||
protected override string[] ArgSuggestions => Main.AllPlayerControls.OrderBy(pc => pc.PlayerId).Select(pc => pc.Data.PlayerName.Replace(' ', '_')).ToArray();
|
||||
public override string ArgInfo => "{Player}";
|
||||
public PlayerControl? TryGetTarget()
|
||||
{
|
||||
var player = Main.AllPlayerControls.FirstOrDefault(pc => pc.Data.PlayerName.ToLower().Replace(' ', '_') == Arg.ToLower());
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
namespace BetterAmongUs.Commands;
|
||||
|
||||
public class StringArgument(BaseCommand? command) : BaseArgument(command)
|
||||
public class StringArgument(BaseCommand? command, string argInfo = "{String}") : BaseArgument(command, argInfo)
|
||||
{
|
||||
public override string ArgInfo => suggestion;
|
||||
public string suggestion = "{String}";
|
||||
}
|
||||
@@ -12,10 +12,8 @@ public class KickCommand : BaseCommand
|
||||
_arguments = new Lazy<BaseArgument[]>(() => new BaseArgument[]
|
||||
{
|
||||
new PlayerArgument(this),
|
||||
new BoolArgument(this),
|
||||
new BoolArgument(this, "{ban}"),
|
||||
});
|
||||
|
||||
boolArgument.suggestion = "{Ban}";
|
||||
}
|
||||
private readonly Lazy<BaseArgument[]> _arguments;
|
||||
public override BaseArgument[]? Arguments => _arguments.Value;
|
||||
|
||||
@@ -13,9 +13,8 @@ public class RemovePlayerCommand : BaseCommand
|
||||
{
|
||||
_arguments = new Lazy<BaseArgument[]>(() => new BaseArgument[]
|
||||
{
|
||||
new StringArgument(this),
|
||||
new StringArgument(this, "{identifier}"),
|
||||
});
|
||||
identifierArgument.suggestion = "{Identifier}";
|
||||
identifierArgument.GetArgSuggestions = AntiCheat.GatherAllData;
|
||||
}
|
||||
private readonly Lazy<BaseArgument[]> _arguments;
|
||||
|
||||
@@ -15,9 +15,8 @@ public class RoleCommand : BaseCommand
|
||||
{
|
||||
_arguments = new Lazy<BaseArgument[]>(() => new BaseArgument[]
|
||||
{
|
||||
new StringArgument(this),
|
||||
new StringArgument(this, "{role}"),
|
||||
});
|
||||
roleArgument.suggestion = "{Role}";
|
||||
roleArgument.GetArgSuggestions = () => { return RoleManager.Instance.AllRoles.Select(role => role.NiceName.ToLower()).ToArray(); };
|
||||
}
|
||||
private readonly Lazy<BaseArgument[]> _arguments;
|
||||
|
||||
@@ -9,9 +9,8 @@ public class SetPrefixCommand : BaseCommand
|
||||
{
|
||||
_arguments = new Lazy<BaseArgument[]>(() => new BaseArgument[]
|
||||
{
|
||||
new StringArgument(this),
|
||||
new StringArgument(this, "{prefix}"),
|
||||
});
|
||||
prefixArgument.suggestion = "{Prefix}";
|
||||
}
|
||||
private readonly Lazy<BaseArgument[]> _arguments;
|
||||
public override BaseArgument[]? Arguments => _arguments.Value;
|
||||
|
||||
@@ -16,9 +16,8 @@ public class SetRoleCommand : BaseCommand
|
||||
_arguments = new Lazy<BaseArgument[]>(() => new BaseArgument[]
|
||||
{
|
||||
new PlayerArgument(this),
|
||||
new StringArgument(this),
|
||||
new StringArgument(this, "{role}"),
|
||||
}); ;
|
||||
roleArgument.suggestion = "{Name}";
|
||||
roleArgument.GetArgSuggestions = () => { return RoleManager.Instance.AllRoles.Select(role => role.NiceName.ToLower()).ToArray(); };
|
||||
}
|
||||
private readonly Lazy<BaseArgument[]> _arguments;
|
||||
|
||||
Reference in new issue
Block a user