Files
crystall-punk-14/Content.Shared/Access/Components/AccessComponent.cs

60 lines
1.8 KiB
C#
Raw Normal View History

using Content.Shared.Access.Systems;
using Robust.Shared.GameStates;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Set;
2023-12-26 16:24:53 -06:00
namespace Content.Shared.Access.Components;
/// <summary>
/// Simple mutable access provider found on ID cards and such.
/// </summary>
[RegisterComponent, NetworkedComponent]
[Access(typeof(SharedAccessSystem))]
[AutoGenerateComponentState]
public sealed partial class AccessComponent : Component
{
/// <summary>
2023-12-26 16:24:53 -06:00
/// True if the access provider is enabled and can grant access.
/// </summary>
2023-12-26 16:24:53 -06:00
[DataField, ViewVariables(VVAccess.ReadWrite)]
[AutoNetworkedField]
public bool Enabled = true;
[DataField(customTypeSerializer: typeof(PrototypeIdHashSetSerializer<AccessLevelPrototype>))]
[Access(typeof(SharedAccessSystem), Other = AccessPermissions.ReadExecute)] // FIXME Friends
[AutoNetworkedField]
public HashSet<string> Tags = new();
2022-12-04 19:23:59 -05:00
/// <summary>
2023-12-26 16:24:53 -06:00
/// Access Groups. These are added to the tags during map init. After map init this will have no effect.
2022-12-04 19:23:59 -05:00
/// </summary>
2023-12-26 16:24:53 -06:00
[DataField(readOnly: true, customTypeSerializer: typeof(PrototypeIdHashSetSerializer<AccessGroupPrototype>))]
[AutoNetworkedField]
public HashSet<string> Groups = new();
}
2022-12-04 19:23:59 -05:00
2023-12-26 16:24:53 -06:00
/// <summary>
/// Event raised on an entity to find additional entities which provide access.
/// </summary>
[ByRefEvent]
public struct GetAdditionalAccessEvent
{
public HashSet<EntityUid> Entities = new();
public GetAdditionalAccessEvent()
{
2022-12-04 19:23:59 -05:00
}
2023-12-26 16:24:53 -06:00
}
2023-12-26 16:24:53 -06:00
[ByRefEvent]
public record struct GetAccessTagsEvent(HashSet<string> Tags, IPrototypeManager PrototypeManager)
{
public void AddGroup(string group)
{
2023-12-26 16:24:53 -06:00
if (!PrototypeManager.TryIndex<AccessGroupPrototype>(group, out var groupPrototype))
return;
2023-12-26 16:24:53 -06:00
Tags.UnionWith(groupPrototype.Tags);
}
}