Mind Role Entities (#31318)
* Mind Role Entities wip * headrev count fix * silicon stuff, cleanup * exclusive antag config, cleanup * jobroleadd overwerite * logging stuff * MindHasRole cleanup, admin log stuff * last second cleanup * ocd * minor cleanup * remove createdTime datafield * now actually using the event replacement I made for role time tracking * weh
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Content.Shared.Item;
|
||||
using Content.Shared.Roles;
|
||||
using Content.Shared.Tag;
|
||||
|
||||
namespace Content.Shared.Whitelist;
|
||||
@@ -7,6 +8,7 @@ namespace Content.Shared.Whitelist;
|
||||
public sealed class EntityWhitelistSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly IComponentFactory _factory = default!;
|
||||
[Dependency] private readonly SharedRoleSystem _roles = default!;
|
||||
[Dependency] private readonly TagSystem _tag = default!;
|
||||
|
||||
private EntityQuery<ItemComponent> _itemQuery;
|
||||
@@ -46,9 +48,30 @@ public sealed class EntityWhitelistSystem : EntitySystem
|
||||
public bool IsValid(EntityWhitelist list, EntityUid uid)
|
||||
{
|
||||
if (list.Components != null)
|
||||
EnsureRegistrations(list);
|
||||
{
|
||||
var regs = StringsToRegs(list.Components);
|
||||
|
||||
if (list.Registrations != null)
|
||||
list.Registrations ??= new List<ComponentRegistration>();
|
||||
list.Registrations.AddRange(regs);
|
||||
}
|
||||
|
||||
if (list.MindRoles != null)
|
||||
{
|
||||
var regs = StringsToRegs(list.MindRoles);
|
||||
|
||||
foreach (var role in regs)
|
||||
{
|
||||
if ( _roles.MindHasRole(uid, role.Type, out _))
|
||||
{
|
||||
if (!list.RequireAll)
|
||||
return true;
|
||||
}
|
||||
else if (list.RequireAll)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (list.Registrations != null && list.Registrations.Count > 0)
|
||||
{
|
||||
foreach (var reg in list.Registrations)
|
||||
{
|
||||
@@ -153,7 +176,7 @@ public sealed class EntityWhitelistSystem : EntitySystem
|
||||
return IsWhitelistPassOrNull(blacklist, uid);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// Helper function to determine if Blacklist is either null or the entity is not on the list
|
||||
/// Duplicate of equivalent Whitelist function
|
||||
/// </summary>
|
||||
@@ -162,24 +185,27 @@ public sealed class EntityWhitelistSystem : EntitySystem
|
||||
return IsWhitelistFailOrNull(blacklist, uid);
|
||||
}
|
||||
|
||||
private void EnsureRegistrations(EntityWhitelist list)
|
||||
private List<ComponentRegistration> StringsToRegs(string[]? input)
|
||||
{
|
||||
if (list.Components == null)
|
||||
return;
|
||||
var list = new List<ComponentRegistration>();
|
||||
|
||||
list.Registrations = new List<ComponentRegistration>();
|
||||
foreach (var name in list.Components)
|
||||
if (input == null || input.Length == 0)
|
||||
return list;
|
||||
|
||||
foreach (var name in input)
|
||||
{
|
||||
var availability = _factory.GetComponentAvailability(name);
|
||||
if (_factory.TryGetRegistration(name, out var registration)
|
||||
&& availability == ComponentAvailability.Available)
|
||||
{
|
||||
list.Registrations.Add(registration);
|
||||
list.Add(registration);
|
||||
}
|
||||
else if (availability == ComponentAvailability.Unknown)
|
||||
{
|
||||
Log.Warning($"Unknown component name {name} passed to EntityWhitelist!");
|
||||
Log.Error($"StringsToRegs failed: Unknown component name {name} passed to EntityWhitelist!");
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user