Add completions to addobjective and localize it (#30456)

* Add completions to addobjective and localise it

* Cleanup

* Fix

* Make a manager to handle subscribtion completion options

This is so we can unsubscribe to prototype reloads properly

* Convert the manager into a system

* Move the system into the systems folder

I forgor

* Merge CompletionsSystem into ObjectivesSystem
This commit is contained in:
nikthechampiongr
2024-09-08 07:28:43 +00:00
committed by GitHub
parent b2007bce19
commit 4b8bedaeef
5 changed files with 109 additions and 39 deletions

View File

@@ -11,6 +11,8 @@ using Robust.Shared.Prototypes;
using Robust.Shared.Random;
using System.Linq;
using System.Text;
using Content.Server.Objectives.Commands;
using Content.Shared.Prototypes;
using Robust.Server.Player;
using Robust.Shared.Utility;
@@ -24,11 +26,22 @@ public sealed class ObjectivesSystem : SharedObjectivesSystem
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly EmergencyShuttleSystem _emergencyShuttle = default!;
private IEnumerable<string>? _objectives;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<RoundEndTextAppendEvent>(OnRoundEndText);
_prototypeManager.PrototypesReloaded += CreateCompletions;
}
public override void Shutdown()
{
base.Shutdown();
_prototypeManager.PrototypesReloaded -= CreateCompletions;
}
/// <summary>
@@ -249,6 +262,32 @@ public sealed class ObjectivesSystem : SharedObjectivesSystem
return Loc.GetString("objectives-player-named", ("name", name));
}
private void CreateCompletions(PrototypesReloadedEventArgs unused)
{
CreateCompletions();
}
/// <summary>
/// Get all objective prototypes by their IDs.
/// This is used for completions in <see cref="AddObjectiveCommand"/>
/// </summary>
public IEnumerable<string> Objectives()
{
if (_objectives == null)
CreateCompletions();
return _objectives!;
}
private void CreateCompletions()
{
_objectives = _prototypeManager.EnumeratePrototypes<EntityPrototype>()
.Where(p => p.HasComponent<ObjectiveComponent>())
.Select(p => p.ID)
.Order();
}
}
/// <summary>