2021-12-26 17:07:28 +13:00
|
|
|
using Content.Shared.Access.Systems;
|
2022-09-14 19:33:25 +10:00
|
|
|
using Robust.Shared.GameStates;
|
2023-08-12 17:39:58 -04:00
|
|
|
using Robust.Shared.Prototypes;
|
2021-12-01 00:40:46 +11:00
|
|
|
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Set;
|
2019-09-01 22:57:22 +02:00
|
|
|
|
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
|
2019-09-01 22:57:22 +02:00
|
|
|
{
|
2020-06-03 11:46:59 +02:00
|
|
|
/// <summary>
|
2023-12-26 16:24:53 -06:00
|
|
|
/// True if the access provider is enabled and can grant access.
|
2020-06-03 11:46:59 +02:00
|
|
|
/// </summary>
|
2023-12-26 16:24:53 -06:00
|
|
|
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
|
|
|
|
[AutoNetworkedField]
|
|
|
|
|
public bool Enabled = true;
|
|
|
|
|
|
2024-04-01 09:06:13 +03:00
|
|
|
[DataField]
|
2023-12-26 16:24:53 -06:00
|
|
|
[Access(typeof(SharedAccessSystem), Other = AccessPermissions.ReadExecute)] // FIXME Friends
|
|
|
|
|
[AutoNetworkedField]
|
2024-04-01 09:06:13 +03:00
|
|
|
public HashSet<ProtoId<AccessLevelPrototype>> 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>
|
2024-04-01 09:06:13 +03:00
|
|
|
[DataField(readOnly: true)]
|
2023-12-26 16:24:53 -06:00
|
|
|
[AutoNetworkedField]
|
2024-04-01 09:06:13 +03:00
|
|
|
public HashSet<ProtoId<AccessGroupPrototype>> Groups = new();
|
2023-12-26 16:24:53 -06:00
|
|
|
}
|
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-08-12 17:39:58 -04:00
|
|
|
|
2023-12-26 16:24:53 -06:00
|
|
|
[ByRefEvent]
|
2024-04-01 09:06:13 +03:00
|
|
|
public record struct GetAccessTagsEvent(HashSet<ProtoId<AccessLevelPrototype>> Tags, IPrototypeManager PrototypeManager)
|
2023-12-26 16:24:53 -06:00
|
|
|
{
|
2024-04-01 09:06:13 +03:00
|
|
|
public void AddGroup(ProtoId<AccessGroupPrototype> group)
|
2023-08-12 17:39:58 -04:00
|
|
|
{
|
2023-12-26 16:24:53 -06:00
|
|
|
if (!PrototypeManager.TryIndex<AccessGroupPrototype>(group, out var groupPrototype))
|
|
|
|
|
return;
|
2023-08-12 17:39:58 -04:00
|
|
|
|
2023-12-26 16:24:53 -06:00
|
|
|
Tags.UnionWith(groupPrototype.Tags);
|
2023-08-12 17:39:58 -04:00
|
|
|
}
|
2019-09-01 22:57:22 +02:00
|
|
|
}
|