Skip to content

Commit

Permalink
Add uplink command completions (#9742)
Browse files Browse the repository at this point in the history
  • Loading branch information
ElectroJr authored Jul 15, 2022
1 parent 37b883e commit 4100516
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 10 deletions.
40 changes: 30 additions & 10 deletions Content.Server/Traitor/Uplink/Commands/AddUplinkCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,47 @@ public sealed class AddUplinkCommand : IConsoleCommand
{
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)
{
if (args.Length < 1)
if (args.Length > 2)
{
shell.WriteError(Loc.GetString("shell-wrong-arguments-number"));
return;
}

// Get player entity
if (!IoCManager.Resolve<IPlayerManager>().TryGetSessionByUsername(args[0], out var session))
IPlayerSession? session;
if (args.Length > 0)
{
shell.WriteLine(Loc.GetString("shell-target-player-does-not-exist"));
return;
// Get player entity
if (!IoCManager.Resolve<IPlayerManager>().TryGetSessionByUsername(args[0], out session))
{
shell.WriteLine(Loc.GetString("shell-target-player-does-not-exist"));
return;
}
}
if (session.AttachedEntity is not {} user)
else
{
session = (IPlayerSession?) shell.Player;
}

if (session?.AttachedEntity is not { } user)
{
shell.WriteLine(Loc.GetString("Selected player doesn't controll any entity"));
shell.WriteLine(Loc.GetString("add-uplink-command-error-1"));
return;
}

Expand Down Expand Up @@ -72,7 +92,7 @@ public void Execute(IConsoleShell shell, string argStr, string[] args)
if (!entityManager.EntitySysManager.GetEntitySystem<UplinkSystem>()
.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;
}
}
Expand Down
5 changes: 5 additions & 0 deletions Content.Server/Traitor/Uplink/UplinkSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,11 @@ public bool AddUplink(EntityUid user, UplinkAccount account, EntityUid? uplinkEn
var uplink = uplinkEntity.Value.EnsureComponent<UplinkComponent>();
SetAccount(uplink, account);

if (!HasComp<PDAComponent>(uplinkEntity.Value))
uplink.ActivatesInHands = true;

// TODO add BUI. Currently can't be done outside of yaml -_-

return true;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 4100516

Please sign in to comment.