forked from space-wizards/RobustToolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Entity console commands system. (space-wizards#5267)
* 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 <[email protected]>
- Loading branch information
1 parent
0ba4a66
commit 08970e7
Showing
10 changed files
with
176 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.