mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-15 03:30:53 +01:00
* Entity console commands system. This adds a new base type, LocalizedEntityCommands, which is able to import entity systems as dependencies. This is done by only registering these while the entity system is active. Handling registration separately like this required a bit of changes around ConsoleHost to make it more suitable for this purpose: You can now directly register command instances, and also have a system to suppress `UpdateAvailableCommands` on the client so there's no bad O(N*M) behavior. * Convert TeleportCommands.cs to new entity commands. Removes some obsoletion warnings without pain from having to manually import transform system. * Fix RobustServerSimulation dependency issue. --------- Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
55 lines
1.6 KiB
C#
55 lines
1.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using Robust.Shared.GameObjects;
|
|
using Robust.Shared.IoC;
|
|
using Robust.Shared.Reflection;
|
|
using Robust.Shared.Utility;
|
|
|
|
namespace Robust.Shared.Console;
|
|
|
|
/// <summary>
|
|
/// Manages registration for "entity" console commands.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// See <see cref="LocalizedEntityCommands"/> for details on what "entity" console commands are.
|
|
/// </remarks>
|
|
internal sealed class EntityConsoleHost
|
|
{
|
|
[Dependency] private readonly IConsoleHost _consoleHost = default!;
|
|
[Dependency] private readonly IReflectionManager _reflectionManager = default!;
|
|
[Dependency] private readonly IEntitySystemManager _entitySystemManager = default!;
|
|
|
|
private readonly HashSet<string> _entityCommands = [];
|
|
|
|
public void Startup()
|
|
{
|
|
DebugTools.Assert(_entityCommands.Count == 0);
|
|
|
|
var deps = ((EntitySystemManager)_entitySystemManager).SystemDependencyCollection;
|
|
|
|
_consoleHost.BeginRegistrationRegion();
|
|
|
|
// search for all client commands in all assemblies, and register them
|
|
foreach (var type in _reflectionManager.GetAllChildren<IEntityConsoleCommand>())
|
|
{
|
|
var instance = (IConsoleCommand)Activator.CreateInstance(type)!;
|
|
deps.InjectDependencies(instance, oneOff: true);
|
|
|
|
_entityCommands.Add(instance.Command);
|
|
_consoleHost.RegisterCommand(instance);
|
|
}
|
|
|
|
_consoleHost.EndRegistrationRegion();
|
|
}
|
|
|
|
public void Shutdown()
|
|
{
|
|
foreach (var command in _entityCommands)
|
|
{
|
|
_consoleHost.UnregisterCommand(command);
|
|
}
|
|
|
|
_entityCommands.Clear();
|
|
}
|
|
}
|