Add uplink command completions (#9742)

This commit is contained in:
Leon Friedrich
2022-07-15 13:14:37 +12:00
committed by GitHub
parent 37b883e9cb
commit 4100516bde
3 changed files with 42 additions and 10 deletions

View File

@@ -14,27 +14,47 @@ namespace Content.Server.Traitor.Uplink.Commands
{ {
public string Command => "adduplink"; public string Command => "adduplink";
public string Description => "Creates uplink on selected item and link it to users account"; public string Description => Loc.GetString("add-uplink-command-description");
public string Help => "Usage: adduplink <username> <item-id>"; public string Help => Loc.GetString("add-uplink-command-help");
public CompletionResult GetCompletion(IConsoleShell shell, string[] args)
{
return args.Length switch
{
1 => CompletionResult.FromHintOptions(CompletionHelper.SessionNames(), Loc.GetString("add-uplink-command-completion-1")),
2 => CompletionResult.FromHint(Loc.GetString("add-uplink-command-completion-2")),
_ => CompletionResult.Empty
};
}
public void Execute(IConsoleShell shell, string argStr, string[] args) public void Execute(IConsoleShell shell, string argStr, string[] args)
{ {
if (args.Length < 1) if (args.Length > 2)
{ {
shell.WriteError(Loc.GetString("shell-wrong-arguments-number")); shell.WriteError(Loc.GetString("shell-wrong-arguments-number"));
return; return;
} }
IPlayerSession? session;
if (args.Length > 0)
{
// Get player entity // Get player entity
if (!IoCManager.Resolve<IPlayerManager>().TryGetSessionByUsername(args[0], out var session)) if (!IoCManager.Resolve<IPlayerManager>().TryGetSessionByUsername(args[0], out session))
{ {
shell.WriteLine(Loc.GetString("shell-target-player-does-not-exist")); shell.WriteLine(Loc.GetString("shell-target-player-does-not-exist"));
return; return;
} }
if (session.AttachedEntity is not {} user) }
else
{ {
shell.WriteLine(Loc.GetString("Selected player doesn't controll any entity")); session = (IPlayerSession?) shell.Player;
}
if (session?.AttachedEntity is not { } user)
{
shell.WriteLine(Loc.GetString("add-uplink-command-error-1"));
return; return;
} }
@@ -72,7 +92,7 @@ namespace Content.Server.Traitor.Uplink.Commands
if (!entityManager.EntitySysManager.GetEntitySystem<UplinkSystem>() if (!entityManager.EntitySysManager.GetEntitySystem<UplinkSystem>()
.AddUplink(user, uplinkAccount, uplinkEntity)) .AddUplink(user, uplinkAccount, uplinkEntity))
{ {
shell.WriteLine(Loc.GetString("Failed to add uplink to the player")); shell.WriteLine(Loc.GetString("add-uplink-command-error-2"));
return; return;
} }
} }

View File

@@ -188,6 +188,11 @@ namespace Content.Server.Traitor.Uplink
var uplink = uplinkEntity.Value.EnsureComponent<UplinkComponent>(); var uplink = uplinkEntity.Value.EnsureComponent<UplinkComponent>();
SetAccount(uplink, account); SetAccount(uplink, account);
if (!HasComp<PDAComponent>(uplinkEntity.Value))
uplink.ActivatesInHands = true;
// TODO add BUI. Currently can't be done outside of yaml -_-
return true; return true;
} }

View File

@@ -0,0 +1,7 @@
add-uplink-command-description = Creates uplink on selected item and link it to users account
add-uplink-command-help = Usage: adduplink [username] [item-id]
add-uplink-command-completion-1 = Username (defaults to self)
add-uplink-command-completion-2 = Uplink uid (default to PDA)
add-uplink-command-error-1 = Selected player doesn't control any entity
add-uplink-command-error-2 = Failed to add uplink to the player