AccessComponent.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using Content.Shared.Access.Systems;
  2. using Robust.Shared.GameStates;
  3. using Robust.Shared.Prototypes;
  4. using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Set;
  5. namespace Content.Shared.Access.Components;
  6. /// <summary>
  7. /// Simple mutable access provider found on ID cards and such.
  8. /// </summary>
  9. [RegisterComponent, NetworkedComponent]
  10. [Access(typeof(SharedAccessSystem))]
  11. [AutoGenerateComponentState]
  12. public sealed partial class AccessComponent : Component
  13. {
  14. /// <summary>
  15. /// True if the access provider is enabled and can grant access.
  16. /// </summary>
  17. [DataField, ViewVariables(VVAccess.ReadWrite)]
  18. [AutoNetworkedField]
  19. public bool Enabled = true;
  20. [DataField]
  21. [Access(typeof(SharedAccessSystem), Other = AccessPermissions.ReadExecute)] // FIXME Friends
  22. [AutoNetworkedField]
  23. public HashSet<ProtoId<AccessLevelPrototype>> Tags = new();
  24. /// <summary>
  25. /// Access Groups. These are added to the tags during map init. After map init this will have no effect.
  26. /// </summary>
  27. [DataField(readOnly: true)]
  28. [AutoNetworkedField]
  29. public HashSet<ProtoId<AccessGroupPrototype>> Groups = new();
  30. }
  31. /// <summary>
  32. /// Event raised on an entity to find additional entities which provide access.
  33. /// </summary>
  34. [ByRefEvent]
  35. public struct GetAdditionalAccessEvent
  36. {
  37. public HashSet<EntityUid> Entities = new();
  38. public GetAdditionalAccessEvent()
  39. {
  40. }
  41. }
  42. [ByRefEvent]
  43. public record struct GetAccessTagsEvent(HashSet<ProtoId<AccessLevelPrototype>> Tags, IPrototypeManager PrototypeManager)
  44. {
  45. public void AddGroup(ProtoId<AccessGroupPrototype> group)
  46. {
  47. if (!PrototypeManager.TryIndex<AccessGroupPrototype>(group, out var groupPrototype))
  48. return;
  49. Tags.UnionWith(groupPrototype.Tags);
  50. }
  51. }