* ogh

* i should save my work

* ogh

* hhcdfhjbghshbxdfhghshc
- lots of bugs in parsing still
- invocation is a stub

* expr parsing works

* awawa

* Saving work

* Improve APIs a bit all around, add shortcuts.

* awa

* awa

* AAAAAA

* save work

* Move shit to engine

* lord

* bql is kill

* forgot the fucking bike rack

* bql is kill for real

* pjb will kill me

* aughfhbdj

* adgddf

* gdsgvfvxshngfgh

* b

* hfsjhghj

* a

* tf you mean i have to document it

* follow C# standards

* Assorted cleanup and documentation pass, minor bugfix in ValueRefParser.

* Start porting old commands, remove that pesky prefix in favor of integrating with the shell.

* bw

* Fix valueref up a bit, improve autocomplete for it.

* awa

* fix tests

* git shut up

* Arithmetic commands.

* parse improvements

* Update engine.

---------

Co-authored-by: moonheart08 <moonheart08@users.noreply.github.com>
This commit is contained in:
Moony
2023-08-02 16:09:08 -05:00
committed by GitHub
parent ad61c21c01
commit e2b22a4cd8
48 changed files with 1204 additions and 793 deletions

View File

@@ -1,47 +0,0 @@
using System.Linq;
using Content.Shared.Administration;
using Robust.Shared.Console;
namespace Content.Server.Administration.Commands
{
[AdminCommand(AdminFlags.Spawn)]
sealed class DeleteEntitiesWithComponent : IConsoleCommand
{
public string Command => "deleteewc";
public string Description => Loc.GetString("delete-entities-with-component-command-description");
public string Help => Loc.GetString("delete-entities-with-component-command-help-text");
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
if (args.Length < 1)
{
shell.WriteLine(Help);
return;
}
var factory = IoCManager.Resolve<IComponentFactory>();
var components = new List<Type>();
foreach (var arg in args)
{
components.Add(factory.GetRegistration(arg).Type);
}
var entityManager = IoCManager.Resolve<IEntityManager>();
var entitiesWithComponents = components.Select(c => entityManager.GetAllComponents(c).Select(x => x.Uid));
var entitiesWithAllComponents = entitiesWithComponents.Skip(1).Aggregate(new HashSet<EntityUid>(entitiesWithComponents.First()), (h, e) => { h.IntersectWith(e); return h; });
var count = 0;
foreach (var entity in entitiesWithAllComponents)
{
entityManager.DeleteEntity(entity);
count += 1;
}
shell.WriteLine(Loc.GetString("delete-entities-with-component-command-deleted-components",("count", count)));
}
}
}

View File

@@ -1,36 +0,0 @@
using System.Linq;
using Content.Shared.Administration;
using Robust.Shared.Console;
namespace Content.Server.Administration.Commands
{
[AdminCommand(AdminFlags.Spawn)]
public sealed class DeleteEntitiesWithId : IConsoleCommand
{
public string Command => "deleteewi";
public string Description => "Deletes entities with the specified prototype ID.";
public string Help => $"Usage: {Command} <prototypeID>";
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
if (args.Length != 1)
{
shell.WriteLine(Help);
return;
}
var id = args[0].ToLower();
var entityManager = IoCManager.Resolve<IEntityManager>();
var entities = entityManager.GetEntities().Where(e => entityManager.GetComponent<MetaDataComponent>(e).EntityPrototype?.ID.ToLower() == id);
var i = 0;
foreach (var entity in entities)
{
entityManager.DeleteEntity(entity);
i++;
}
shell.WriteLine($"Deleted all entities with id {id}. Occurrences: {i}");
}
}
}

View File

@@ -1,39 +0,0 @@
using Content.Shared.Administration;
using Robust.Shared.Console;
namespace Content.Server.Administration.Commands
{
[AdminCommand(AdminFlags.Spawn)]
public sealed class DeleteEntityCommand : IConsoleCommand
{
public string Command => "deleteentity";
public string Description => "Deletes an entity with the given id.";
public string Help => $"Usage: {Command} <id>";
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
if (args.Length != 1)
{
shell.WriteLine($"Invalid amount of arguments.\n{Help}");
return;
}
if (!EntityUid.TryParse(args[0], out var id))
{
shell.WriteLine($"{args[0]} is not a valid entity id.");
return;
}
var entityManager = IoCManager.Resolve<IEntityManager>();
if (!entityManager.EntityExists(id))
{
shell.WriteLine($"No entity found with id {id}.");
return;
}
entityManager.DeleteEntity(id);
shell.WriteLine($"Deleted entity with id {id}.");
}
}
}

View File

@@ -1,68 +0,0 @@
using System.Linq;
using Content.Shared.Administration;
using Robust.Shared.Console;
namespace Content.Server.Administration.Commands
{
[AdminCommand(AdminFlags.Mapping)]
public sealed class FindEntitiesWithComponents : IConsoleCommand
{
public string Command => "findentitieswithcomponents";
public string Description => "Finds entities with all of the specified components.";
public string Help => $"{Command} <componentName1> <componentName2>...";
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
if (args.Length == 0)
{
shell.WriteLine($"Invalid amount of arguments: {args.Length}.\n{Help}");
return;
}
var components = new List<Type>();
var componentFactory = IoCManager.Resolve<IComponentFactory>();
var invalidArgs = new List<string>();
foreach (var arg in args)
{
if (!componentFactory.TryGetRegistration(arg, out var registration))
{
invalidArgs.Add(arg);
continue;
}
components.Add(registration.Type);
}
if (invalidArgs.Count > 0)
{
shell.WriteLine($"No component found for component names: {string.Join(", ", invalidArgs)}");
return;
}
var entityManager = IoCManager.Resolve<IEntityManager>();
var entityIds = new HashSet<string>();
var entitiesWithComponents = components.Select(c => entityManager.GetAllComponents(c).Select(x => x.Uid)).ToArray();
var entitiesWithAllComponents = entitiesWithComponents.Skip(1).Aggregate(new HashSet<EntityUid>(entitiesWithComponents.First()), (h, e) => { h.IntersectWith(e); return h; });
foreach (var entity in entitiesWithAllComponents)
{
if (entityManager.GetComponent<MetaDataComponent>(entity).EntityPrototype is not { } prototypeId)
{
continue;
}
entityIds.Add(prototypeId.ID);
}
if (entityIds.Count == 0)
{
shell.WriteLine($"No entities found with components {string.Join(", ", args)}.");
return;
}
shell.WriteLine($"{entityIds.Count} entities found:\n{string.Join("\n", entityIds)}");
}
}
}

View File

@@ -1,48 +0,0 @@
using Content.Shared.Administration;
using Content.Shared.Rejuvenate;
using Robust.Server.Player;
using Robust.Shared.Console;
namespace Content.Server.Administration.Commands
{
[AdminCommand(AdminFlags.Admin)]
public sealed class RejuvenateCommand : IConsoleCommand
{
public string Command => "rejuvenate";
public string Description => Loc.GetString("rejuvenate-command-description");
public string Help => Loc.GetString("rejuvenate-command-help-text");
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
if (args.Length < 1 && shell.Player is IPlayerSession player) //Try to heal the users mob if applicable
{
shell.WriteLine(Loc.GetString("rejuvenate-command-self-heal-message"));
if (player.AttachedEntity == null)
{
shell.WriteLine(Loc.GetString("rejuvenate-command-no-entity-attached-message"));
return;
}
PerformRejuvenate(player.AttachedEntity.Value);
}
var entityManager = IoCManager.Resolve<IEntityManager>();
foreach (var arg in args)
{
if (!EntityUid.TryParse(arg, out var entity) || !entityManager.EntityExists(entity))
{
shell.WriteLine(Loc.GetString("shell-could-not-find-entity",("entity", arg)));
continue;
}
PerformRejuvenate(entity);
}
}
public static void PerformRejuvenate(EntityUid target)
{
var entityManager = IoCManager.Resolve<IEntityManager>();
entityManager.EventBus.RaiseLocalEvent(target, new RejuvenateEvent());
}
}
}

View File

@@ -1,84 +0,0 @@
using Content.Server.Commands;
using Content.Server.Station.Components;
using Content.Server.Station.Systems;
using Content.Shared.Administration;
using Content.Shared.Roles;
using Robust.Shared.Console;
using Robust.Shared.Prototypes;
namespace Content.Server.Administration.Commands.Station;
[AdminCommand(AdminFlags.Round)]
public sealed class AdjustStationJobCommand : IConsoleCommand
{
[Dependency] private readonly IEntityManager _entityManager = default!;
[Dependency] private readonly IEntitySystemManager _entSysManager = default!;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
public string Command => "adjstationjob";
public string Description => "Adjust the job manifest on a station.";
public string Help => "adjstationjob <station id> <job id> <amount>";
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
if (args.Length != 3)
{
shell.WriteError(Loc.GetString("shell-wrong-arguments-number"));
return;
}
var stationJobs = _entSysManager.GetEntitySystem<StationJobsSystem>();
if (!EntityUid.TryParse(args[0], out var station) || !_entityManager.HasComponent<StationDataComponent>(station))
{
shell.WriteError(Loc.GetString("shell-argument-station-id-invalid", ("index", 1)));
return;
}
if (!_prototypeManager.TryIndex<JobPrototype>(args[1], out var job))
{
shell.WriteError(Loc.GetString("shell-argument-must-be-prototype",
("index", 2), ("prototypeName", nameof(JobPrototype))));
return;
}
if (!int.TryParse(args[2], out var amount) || amount < -1)
{
shell.WriteError(Loc.GetString("shell-argument-number-must-be-between",
("index", 3), ("lower", -1), ("upper", int.MaxValue)));
return;
}
if (amount == -1)
{
stationJobs.MakeJobUnlimited(station, job);
return;
}
stationJobs.TrySetJobSlot(station, job, amount, true);
}
public CompletionResult GetCompletion(IConsoleShell shell, string[] args)
{
if (args.Length == 1)
{
var options = ContentCompletionHelper.StationIds(_entityManager);
return CompletionResult.FromHintOptions(options, "<station id>");
}
if (args.Length == 2)
{
var options = CompletionHelper.PrototypeIDs<JobPrototype>();
return CompletionResult.FromHintOptions(options, "<job id>");
}
if (args.Length == 3)
{
return CompletionResult.FromHint("<amount>");
}
return CompletionResult.Empty;
}
}

View File

@@ -1,55 +0,0 @@
using Content.Server.Commands;
using Content.Server.Station.Components;
using Content.Server.Station.Systems;
using Content.Shared.Administration;
using Robust.Shared.Console;
namespace Content.Server.Administration.Commands.Station;
[AdminCommand(AdminFlags.Admin)]
public sealed class ListStationJobsCommand : IConsoleCommand
{
[Dependency] private readonly IEntityManager _entityManager = default!;
[Dependency] private readonly IEntitySystemManager _entSysManager = default!;
public string Command => "lsstationjobs";
public string Description => "Lists all jobs on the given station.";
public string Help => "lsstationjobs <station id>";
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
if (args.Length != 1)
{
shell.WriteError(Loc.GetString("shell-wrong-arguments-number"));
return;
}
var stationSystem = _entSysManager.GetEntitySystem<StationSystem>();
var stationJobs = _entSysManager.GetEntitySystem<StationJobsSystem>();
if (!EntityUid.TryParse(args[0], out var station) || !_entityManager.HasComponent<StationJobsComponent>(station))
{
shell.WriteError(Loc.GetString("shell-argument-station-id-invalid", ("index", 1)));
return;
}
foreach (var (job, amount) in stationJobs.GetJobs(station))
{
var amountText = amount is null ? "Infinite" : amount.ToString();
shell.WriteLine($"{job}: {amountText}");
}
}
public CompletionResult GetCompletion(IConsoleShell shell, string[] args)
{
if (args.Length == 1)
{
var options = ContentCompletionHelper.StationIds(_entityManager);
return CompletionResult.FromHintOptions(options, "<station id>");
}
return CompletionResult.Empty;
}
}

View File

@@ -1,29 +0,0 @@
using Content.Server.Station.Components;
using Content.Server.Station.Systems;
using Content.Shared.Administration;
using Robust.Shared.Console;
namespace Content.Server.Administration.Commands.Station;
[AdminCommand(AdminFlags.Admin)]
public sealed class ListStationsCommand : IConsoleCommand
{
[Dependency] private readonly IEntityManager _entityManager = default!;
public string Command => "lsstations";
public string Description => "List all active stations";
public string Help => "lsstations";
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
var query = _entityManager.EntityQueryEnumerator<StationDataComponent>();
while (query.MoveNext(out var station, out _))
{
var name = _entityManager.GetComponent<MetaDataComponent>(station).EntityName;
shell.WriteLine($"{station, -10} | {name}");
}
}
}

View File

@@ -1,55 +0,0 @@
using Content.Server.Commands;
using Content.Server.Station.Components;
using Content.Server.Station.Systems;
using Content.Shared.Administration;
using Robust.Shared.Console;
namespace Content.Server.Administration.Commands.Station;
[AdminCommand(AdminFlags.Admin)]
public sealed class RenameStationCommand : IConsoleCommand
{
[Dependency] private readonly IEntityManager _entityManager = default!;
[Dependency] private readonly IEntitySystemManager _entSysManager = default!;
public string Command => "renamestation";
public string Description => "Renames the given station";
public string Help => "renamestation <station id> <name>";
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
if (args.Length != 2)
{
shell.WriteError(Loc.GetString("shell-wrong-arguments-number"));
return;
}
var stationSystem = _entSysManager.GetEntitySystem<StationSystem>();
if (!EntityUid.TryParse(args[0], out var station) || !_entityManager.HasComponent<StationDataComponent>(station))
{
shell.WriteError(Loc.GetString("shell-argument-station-id-invalid", ("index", 1)));
return;
}
stationSystem.RenameStation(station, args[1]);
}
public CompletionResult GetCompletion(IConsoleShell shell, string[] args)
{
if (args.Length == 1)
{
var options = ContentCompletionHelper.StationIds(_entityManager);
return CompletionResult.FromHintOptions(options, "<station id>");
}
if (args.Length == 2)
{
return CompletionResult.FromHint("<name>");
}
return CompletionResult.Empty;
}
}

View File

@@ -1,113 +0,0 @@
using Content.Shared.Administration;
using Content.Shared.Tag;
using Robust.Shared.Console;
namespace Content.Server.Administration.Commands
{
[AdminCommand(AdminFlags.Debug)]
public sealed class AddTagCommand : LocalizedCommands
{
[Dependency] private readonly IEntityManager _entityManager = default!;
public override string Command => "addtag";
public override string Description => Loc.GetString("addtag-command-description");
public override string Help => Loc.GetString("addtag-command-help");
public override void Execute(IConsoleShell shell, string argStr, string[] args)
{
if (args.Length != 2)
{
shell.WriteError(Loc.GetString("shell-wrong-arguments-number"));
return;
}
if (!EntityUid.TryParse(args[0], out var entityUid))
{
shell.WriteError(Loc.GetString("shell-entity-uid-must-be-number"));
return;
}
if (!_entityManager.TrySystem(out TagSystem? tagSystem))
return;
_entityManager.EnsureComponent<TagComponent>(entityUid);
if (tagSystem.TryAddTag(entityUid, args[1]))
{
shell.WriteLine(Loc.GetString("addtag-command-success", ("tag", args[1]), ("target", entityUid)));
}
else
{
shell.WriteError(Loc.GetString("addtag-command-fail", ("tag", args[1]), ("target", entityUid)));
}
}
public override CompletionResult GetCompletion(IConsoleShell shell, string[] args)
{
if (args.Length == 1)
{
return CompletionResult.FromHint(Loc.GetString("shell-argument-uid"));
}
if (args.Length == 2)
{
return CompletionResult.FromHintOptions(CompletionHelper.PrototypeIDs<TagPrototype>(),
Loc.GetString("tag-command-arg-tag"));
}
return CompletionResult.Empty;
}
}
[AdminCommand(AdminFlags.Debug)]
public sealed class RemoveTagCommand : LocalizedCommands
{
[Dependency] private readonly IEntityManager _entityManager = default!;
public override string Command => "removetag";
public override string Description => Loc.GetString("removetag-command-description");
public override string Help => Loc.GetString("removetag-command-help");
public override void Execute(IConsoleShell shell, string argStr, string[] args)
{
if (args.Length != 2)
{
shell.WriteError(Loc.GetString("shell-wrong-arguments-number"));
return;
}
if (!EntityUid.TryParse(args[0], out var entityUid))
{
shell.WriteError(Loc.GetString("shell-entity-uid-must-be-number"));
return;
}
if (!_entityManager.TrySystem(out TagSystem? tagSystem))
return;
if (tagSystem.RemoveTag(entityUid, args[1]))
{
shell.WriteLine(Loc.GetString("removetag-command-success", ("tag", args[1]), ("target", entityUid)));
}
else
{
shell.WriteError(Loc.GetString("removetag-command-fail", ("tag", args[1]), ("target", entityUid)));
}
}
public override CompletionResult GetCompletion(IConsoleShell shell, string[] args)
{
if (args.Length == 1)
{
return CompletionResult.FromHint(Loc.GetString("shell-argument-uid"));
}
if (args.Length == 2&& EntityUid.TryParse(args[0], out var entityUid) && _entityManager.TryGetComponent(entityUid, out TagComponent? tagComponent))
{
return CompletionResult.FromHintOptions(tagComponent.Tags,
Loc.GetString("tag-command-arg-tag"));
}
return CompletionResult.Empty;
}
}
}