More borg tweaks (#19143)

* borg tweaks but i'm gonna go code fun stuff first

* werkin' on it

* a ton of tweaks

* fuck everyone and then myself
This commit is contained in:
Nemanja
2023-08-14 19:34:23 -04:00
committed by GitHub
parent 8b0eb7e4de
commit 7ddee71379
40 changed files with 299 additions and 175 deletions

View File

@@ -8,9 +8,9 @@ using Content.Shared.PDA;
using Content.Shared.StationRecords;
using Robust.Shared.Containers;
using Robust.Shared.GameStates;
using System.Collections.ObjectModel;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Robust.Shared.Collections;
using Robust.Shared.Prototypes;
namespace Content.Shared.Access.Systems;
@@ -69,6 +69,8 @@ public sealed class AccessReaderSystem : EntitySystem
/// required entity.
/// </summary>
/// <param name="target">The entity to search for a container</param>
/// <param name="accessReader"></param>
/// <param name="result"></param>
private bool FindAccessReadersInContainer(EntityUid target, AccessReaderComponent accessReader, out List<AccessReaderComponent> result)
{
result = new();
@@ -171,6 +173,11 @@ public sealed class AccessReaderSystem : EntitySystem
{
FindAccessItemsInventory(uid, out var items);
foreach (var item in new ValueList<EntityUid>(items))
{
items.UnionWith(FindPotentialAccessItems(item));
}
var ev = new GetAdditionalAccessEvent
{
Entities = items
@@ -204,6 +211,7 @@ public sealed class AccessReaderSystem : EntitySystem
/// Finds the access tags on the given entity
/// </summary>
/// <param name="uid">The entity that is being searched.</param>
/// <param name="recordKeys"></param>
/// <param name="items">All of the items to search for access. If none are passed in, <see cref="FindPotentialAccessItems"/> will be used.</param>
public bool FindStationRecordKeys(EntityUid uid, out ICollection<StationRecordKey> recordKeys, HashSet<EntityUid>? items = null)
{
@@ -277,17 +285,6 @@ public sealed class AccessReaderSystem : EntitySystem
private bool FindAccessTagsItem(EntityUid uid, out HashSet<string> tags)
{
tags = new();
if (TryComp(uid, out AccessComponent? access))
{
tags.UnionWith(access.Tags);
}
if (TryComp(uid, out PdaComponent? pda) &&
pda.ContainedId is { Valid: true } id)
{
tags.UnionWith(EntityManager.GetComponent<AccessComponent>(id).Tags);
}
var ev = new GetAccessTagsEvent(tags, _prototype);
RaiseLocalEvent(uid, ref ev);

View File

@@ -15,28 +15,7 @@ namespace Content.Shared.Access.Systems
base.Initialize();
SubscribeLocalEvent<AccessComponent, MapInitEvent>(OnAccessInit);
SubscribeLocalEvent<AccessComponent, ComponentGetState>(OnAccessGetState);
SubscribeLocalEvent<AccessComponent, ComponentHandleState>(OnAccessHandleState);
}
private void OnAccessHandleState(EntityUid uid, AccessComponent component, ref ComponentHandleState args)
{
if (args.Current is not AccessComponentState state) return;
// Don't do = because prediction and refs
component.Tags.Clear();
component.Groups.Clear();
component.Tags.UnionWith(state.Tags);
component.Groups.UnionWith(state.Groups);
}
private void OnAccessGetState(EntityUid uid, AccessComponent component, ref ComponentGetState args)
{
args.State = new AccessComponentState()
{
Tags = component.Tags,
Groups = component.Groups,
};
SubscribeLocalEvent<AccessComponent, GetAccessTagsEvent>(OnGetAccessTags);
}
private void OnAccessInit(EntityUid uid, AccessComponent component, MapInitEvent args)
@@ -52,6 +31,22 @@ namespace Content.Shared.Access.Systems
}
}
private void OnGetAccessTags(EntityUid uid, AccessComponent component, ref GetAccessTagsEvent args)
{
if (!component.Enabled)
return;
args.Tags.UnionWith(component.Tags);
}
public void SetAccessEnabled(EntityUid uid, bool val, AccessComponent? component = null)
{
if (!Resolve(uid, ref component, false))
return;
component.Enabled = val;
Dirty(uid, component);
}
/// <summary>
/// Replaces the set of access tags we have with the provided set.
/// </summary>
@@ -122,12 +117,5 @@ namespace Content.Shared.Access.Systems
TryAddGroups(uid, prototype.ExtendedAccessGroups, access);
}
}
[Serializable, NetSerializable]
private sealed class AccessComponentState : ComponentState
{
public HashSet<string> Tags = new();
public HashSet<string> Groups = new();
}
}
}