CatStation/Content.Client/CrewManifest/CrewManifestSystem.cs
Whatstone f42f8df6d1
Cleanup: ProtoMan Part 2 - remove Client and Server EntitySystem IPrototypeManager instances (#44416)
* Remove all IPrototypeManager instances

* Remove redundant IComponentFactory instances too

* Found some stragglers

* DestructibleSystem.PrototypeManager: no dependency

* not based
2026-06-29 21:33:56 +00:00

74 lines
2.1 KiB
C#

using Content.Shared.CrewManifest;
using Content.Shared.Roles;
using Robust.Shared.Prototypes;
namespace Content.Client.CrewManifest;
public sealed partial class CrewManifestSystem : EntitySystem
{
private Dictionary<string, Dictionary<string, int>> _jobDepartmentLookup = new();
private HashSet<string> _departments = new();
public IReadOnlySet<string> Departments => _departments;
public override void Initialize()
{
base.Initialize();
BuildDepartmentLookup();
SubscribeLocalEvent<PrototypesReloadedEventArgs>(OnPrototypesReload);
}
/// <summary>
/// Requests a crew manifest from the server.
/// </summary>
/// <param name="netEntity">EntityUid of the entity we're requesting the crew manifest from.</param>
public void RequestCrewManifest(NetEntity netEntity)
{
RaiseNetworkEvent(new RequestCrewManifestMessage(netEntity));
}
private void OnPrototypesReload(PrototypesReloadedEventArgs args)
{
if (args.WasModified<DepartmentPrototype>())
BuildDepartmentLookup();
}
private void BuildDepartmentLookup()
{
_jobDepartmentLookup.Clear();
_departments.Clear();
foreach (var department in ProtoMan.EnumeratePrototypes<DepartmentPrototype>())
{
_departments.Add(department.ID);
for (var i = 1; i <= department.Roles.Count; i++)
{
if (!_jobDepartmentLookup.TryGetValue(department.Roles[i - 1], out var departments))
{
departments = new();
_jobDepartmentLookup.Add(department.Roles[i - 1], departments);
}
departments.Add(department.ID, i);
}
}
}
public int GetDepartmentOrder(string department, string jobPrototype)
{
if (!Departments.Contains(department))
{
return -1;
}
if (!_jobDepartmentLookup.TryGetValue(jobPrototype, out var departments))
{
return -1;
}
return departments.TryGetValue(department, out var order)
? order
: -1;
}
}