UnlockNode command to LEC. (#38751)

* commit

* Update UnlockNodeCommand.cs

* commit

* move command locale to its own file.

* Update Content.Server/Xenoarchaeology/Artifact/UnlockNodeCommand.cs

---------

Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>
This commit is contained in:
Kyle Tyo
2025-07-04 19:14:12 -04:00
committed by GitHub
parent 24d0453609
commit 78e8d98137
4 changed files with 73 additions and 91 deletions

View File

@@ -0,0 +1,68 @@
using Content.Server.Administration;
using Content.Shared.Administration;
using Content.Shared.Xenoarchaeology.Artifact.Components;
using Robust.Shared.Console;
namespace Content.Server.Xenoarchaeology.Artifact;
/// <summary> Command for unlocking a specific node of a xeno artifact. </summary>
[AdminCommand(AdminFlags.Debug)]
public sealed class UnlockNodeCommand : LocalizedEntityCommands
{
[Dependency] private readonly XenoArtifactSystem _artiSystem = default!;
public override string Command => "unlocknode";
public override void Execute(IConsoleShell shell, string argStr, string[] args)
{
if (args.Length != 2)
{
shell.WriteError(Loc.GetString("shell-wrong-arguments-number"));
return;
}
if (!NetEntity.TryParse(args[1], out var netNode) || !EntityManager.TryGetEntity(netNode, out var entityUid))
{
shell.WriteError(Loc.GetString("shell-could-not-find-entity-with-uid", ("uid", args[1])));
return;
}
_artiSystem.SetNodeUnlocked(entityUid.Value);
}
public override CompletionResult GetCompletion(IConsoleShell shell, string[] args)
{
switch (args.Length)
{
case 1:
{
var query = EntityManager.EntityQueryEnumerator<XenoArtifactComponent>();
var completionOptions = new List<CompletionOption>();
while (query.MoveNext(out var uid, out _))
{
completionOptions.Add(new CompletionOption(uid.ToString()));
}
return CompletionResult.FromHintOptions(completionOptions, Loc.GetString("cmd-unlocknode-artifact-hint"));
}
case 2 when
NetEntity.TryParse(args[0], out var netEnt) &&
EntityManager.TryGetEntity(netEnt, out var artifactUid) &&
EntityManager.TryGetComponent<XenoArtifactComponent>(artifactUid, out var comp):
{
var result = new List<CompletionOption>();
foreach (var node in _artiSystem.GetAllNodes((artifactUid.Value, comp)))
{
var metaData = EntityManager.MetaQuery.Comp(artifactUid.Value);
var entityUidStr = EntityManager.GetNetEntity(node).ToString();
var completionOption = new CompletionOption(entityUidStr, metaData.EntityName);
result.Add(completionOption);
}
return CompletionResult.FromHintOptions(result, Loc.GetString("cmd-unlocknode-node-hint"));
}
default:
return CompletionResult.Empty;
}
}
}

View File

@@ -1,84 +0,0 @@
using Content.Server.Administration;
using Content.Shared.Administration;
using Content.Shared.Xenoarchaeology.Artifact.Components;
using Robust.Shared.Console;
namespace Content.Server.Xenoarchaeology.Artifact;
/// <summary> Command for unlocking specific node of xeno artifact. </summary>
[AdminCommand(AdminFlags.Debug)]
public sealed class XenoArtifactUnlockNodeCommand : LocalizedCommands
{
[Dependency] private readonly EntityManager _entities = default!;
/// <inheritdoc />
public override string Command => "unlocknode";
/// <inheritdoc />
public override string Description => Loc.GetString("cmd-unlocknode-desc");
/// <inheritdoc />
public override string Help => Loc.GetString("cmd-unlocknode-help");
/// <inheritdoc />
public override void Execute(IConsoleShell shell, string argStr, string[] args)
{
if (args.Length != 2)
{
shell.WriteError(Loc.GetString("cmd-parse-failure-unlocknode-arg-num"));
return;
}
if (!NetEntity.TryParse(args[1], out var netNode))
{
shell.WriteError(Loc.GetString("cmd-parse-failure-unlocknode-invalid-entity"));
return;
}
if (!_entities.TryGetEntity(netNode, out var entityUid))
{
shell.WriteError(Loc.GetString("cmd-parse-failure-unlocknode-invalid-entity"));
return;
}
_entities.System<XenoArtifactSystem>()
.SetNodeUnlocked(entityUid.Value);
}
/// <inheritdoc />
public override CompletionResult GetCompletion(IConsoleShell shell, string[] args)
{
if (args.Length == 1)
{
var query = _entities.EntityQueryEnumerator<XenoArtifactComponent>();
var completionOptions = new List<CompletionOption>();
while (query.MoveNext(out var uid, out _))
{
completionOptions.Add(new CompletionOption(uid.ToString()));
}
return CompletionResult.FromHintOptions(completionOptions, "<artifact uid>");
}
if (args.Length == 2 &&
NetEntity.TryParse(args[0], out var netEnt) &&
_entities.TryGetEntity(netEnt, out var artifactUid) &&
_entities.TryGetComponent<XenoArtifactComponent>(artifactUid, out var comp))
{
var artifactSystem = _entities.System<XenoArtifactSystem>();
var result = new List<CompletionOption>();
foreach (var node in artifactSystem.GetAllNodes((artifactUid.Value, comp)))
{
var metaData = _entities.MetaQuery.Comp(artifactUid.Value);
var entityUidStr = _entities.GetNetEntity(node)
.ToString();
var completionOption = new CompletionOption(entityUidStr, metaData.EntityName);
result.Add(completionOption);
}
return CompletionResult.FromHintOptions(result, "<node uid>");
}
return CompletionResult.Empty;
}
}

View File

@@ -0,0 +1,4 @@
cmd-unlocknode-desc = Unlocks a node on a given artifact
cmd-unlocknode-help = unlocknode <artifact uid> <node uid>
cmd-unlocknode-artifact-hint = <artifact uid>
cmd-unlocknode-node-hint = <node uid>

View File

@@ -1,10 +1,4 @@
### Commands
cmd-unlocknode-desc = Unlocks a node on a given artifact
cmd-unlocknode-help = unlocknode <artifact uid> <node uid>
cmd-parse-failure-unlocknode-arg-num = Incorrect number of args
cmd-parse-failure-unlocknode-invalid-entity = Provided netEntity is not valid node
### Verbs
### Verbs
artifact-verb-make-always-active = Make artifact always active
artifact-verb-activate = Activate artifact