Store what access levels are available on the IDCard console (#8259)

Might be better as an accessgroup instead? LMK
This commit is contained in:
metalgearsloth
2022-05-21 14:19:02 +10:00
committed by GitHub
parent a51c5df14d
commit f066ac2551
7 changed files with 102 additions and 10 deletions

View File

@@ -1,8 +1,11 @@
using Content.Shared.Containers.ItemSlots;
using Robust.Shared.GameStates;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.List;
namespace Content.Shared.Access.Components
{
[NetworkedComponent]
public abstract class SharedIdCardConsoleComponent : Component
{
public const int MaxFullNameLength = 256;
@@ -32,6 +35,42 @@ namespace Content.Shared.Access.Components
}
}
// Put this on shared so we just send the state once in PVS range rather than every time the UI updates.
[ViewVariables]
[DataField("accessLevels", customTypeSerializer: typeof(PrototypeIdListSerializer<AccessLevelPrototype>))]
public List<string> AccessLevels = new()
{
"Armory",
"Atmospherics",
"Bar",
"Brig",
// "Detective",
"Captain",
"Cargo",
"Chapel",
"Chemistry",
"ChiefEngineer",
"ChiefMedicalOfficer",
"Command",
"Engineering",
"External",
"HeadOfPersonnel",
"HeadOfSecurity",
"Hydroponics",
"Janitor",
"Kitchen",
"Maintenance",
"Medical",
"Quartermaster",
"Research",
"ResearchDirector",
"Salvage",
"Security",
"Service",
"Theatre",
};
[Serializable, NetSerializable]
public sealed class IdCardConsoleBoundUserInterfaceState : BoundUserInterfaceState
{
@@ -49,7 +88,9 @@ namespace Content.Shared.Access.Components
bool isTargetIdPresent,
string? targetIdFullName,
string? targetIdJobTitle,
string[]? targetIdAccessList, string privilegedIdName, string targetIdName)
string[]? targetIdAccessList,
string privilegedIdName,
string targetIdName)
{
IsPrivilegedIdPresent = isPrivilegedIdPresent;
IsPrivilegedIdAuthorized = isPrivilegedIdAuthorized;
@@ -63,7 +104,7 @@ namespace Content.Shared.Access.Components
}
[Serializable, NetSerializable]
public enum IdCardConsoleUiKey
public enum IdCardConsoleUiKey : byte
{
Key,
}

View File

@@ -1,6 +1,8 @@
using Content.Shared.Access.Components;
using Content.Shared.Containers.ItemSlots;
using JetBrains.Annotations;
using Robust.Shared.GameStates;
using Robust.Shared.Serialization;
namespace Content.Shared.Access.Systems
{
@@ -9,12 +11,27 @@ namespace Content.Shared.Access.Systems
{
[Dependency] private readonly ItemSlotsSystem _itemSlotsSystem = default!;
public const string Sawmill = "idconsole";
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<SharedIdCardConsoleComponent, ComponentInit>(OnComponentInit);
SubscribeLocalEvent<SharedIdCardConsoleComponent, ComponentRemove>(OnComponentRemove);
SubscribeLocalEvent<SharedIdCardConsoleComponent, ComponentGetState>(OnGetState);
SubscribeLocalEvent<SharedIdCardConsoleComponent, ComponentHandleState>(OnHandleState);
}
private void OnHandleState(EntityUid uid, SharedIdCardConsoleComponent component, ref ComponentHandleState args)
{
if (args.Current is not IdCardConsoleComponentState state) return;
component.AccessLevels = state.AccessLevels;
}
private void OnGetState(EntityUid uid, SharedIdCardConsoleComponent component, ref ComponentGetState args)
{
args.State = new IdCardConsoleComponentState(component.AccessLevels);
}
private void OnComponentInit(EntityUid uid, SharedIdCardConsoleComponent component, ComponentInit args)
@@ -28,5 +45,16 @@ namespace Content.Shared.Access.Systems
_itemSlotsSystem.RemoveItemSlot(uid, component.PrivilegedIdSlot);
_itemSlotsSystem.RemoveItemSlot(uid, component.TargetIdSlot);
}
[Serializable, NetSerializable]
private sealed class IdCardConsoleComponentState : ComponentState
{
public List<string> AccessLevels;
public IdCardConsoleComponentState(List<string> accessLevels)
{
AccessLevels = accessLevels;
}
}
}
}