Add a debug overlay for accessreaders (#9681)
> didnt pjb have issues with doing the control stuff in an overlay and just wanted direct texture draw I ended up doing dis.
This commit is contained in:
79
Content.Client/Access/AccessOverlay.cs
Normal file
79
Content.Client/Access/AccessOverlay.cs
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
using System.Text;
|
||||||
|
using Content.Client.Resources;
|
||||||
|
using Content.Shared.Access.Components;
|
||||||
|
using Robust.Client.Graphics;
|
||||||
|
using Robust.Client.ResourceManagement;
|
||||||
|
using Robust.Shared.Enums;
|
||||||
|
|
||||||
|
namespace Content.Client.Access;
|
||||||
|
|
||||||
|
public sealed class AccessOverlay : Overlay
|
||||||
|
{
|
||||||
|
private readonly IEntityManager _entityManager;
|
||||||
|
private readonly EntityLookupSystem _lookup;
|
||||||
|
private readonly Font _font;
|
||||||
|
|
||||||
|
public override OverlaySpace Space => OverlaySpace.ScreenSpace;
|
||||||
|
|
||||||
|
public AccessOverlay(IEntityManager entManager, IResourceCache cache, EntityLookupSystem lookup)
|
||||||
|
{
|
||||||
|
_entityManager = entManager;
|
||||||
|
_lookup = lookup;
|
||||||
|
|
||||||
|
_font = cache.GetFont("/Fonts/NotoSans/NotoSans-Regular.ttf", 12);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Draw(in OverlayDrawArgs args)
|
||||||
|
{
|
||||||
|
if (args.ViewportControl == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var readerQuery = _entityManager.GetEntityQuery<AccessReaderComponent>();
|
||||||
|
var xformQuery = _entityManager.GetEntityQuery<TransformComponent>();
|
||||||
|
|
||||||
|
foreach (var ent in _lookup.GetEntitiesIntersecting(args.MapId, args.WorldAABB,
|
||||||
|
LookupFlags.Anchored | LookupFlags.Approximate))
|
||||||
|
{
|
||||||
|
if (!readerQuery.TryGetComponent(ent, out var reader) ||
|
||||||
|
!xformQuery.TryGetComponent(ent, out var xform))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
var text = new StringBuilder();
|
||||||
|
var index = 0;
|
||||||
|
var a = $"{_entityManager.ToPrettyString(ent)}";
|
||||||
|
text.Append(a);
|
||||||
|
|
||||||
|
foreach (var list in reader.AccessLists)
|
||||||
|
{
|
||||||
|
a = $"Tag {index}";
|
||||||
|
text.AppendLine(a);
|
||||||
|
|
||||||
|
foreach (var entry in list)
|
||||||
|
{
|
||||||
|
a = $"- {entry}";
|
||||||
|
text.AppendLine(a);
|
||||||
|
}
|
||||||
|
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
|
||||||
|
string textStr;
|
||||||
|
|
||||||
|
if (text.Length >= 2)
|
||||||
|
{
|
||||||
|
textStr = text.ToString();
|
||||||
|
textStr = textStr[..^2];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
textStr = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
var screenPos = args.ViewportControl.WorldToScreen(xform.WorldPosition);
|
||||||
|
|
||||||
|
args.ScreenHandle.DrawString(_font, screenPos, textStr, Color.Gold);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
5
Content.Client/Access/AccessSystem.cs
Normal file
5
Content.Client/Access/AccessSystem.cs
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
using Content.Shared.Access.Systems;
|
||||||
|
|
||||||
|
namespace Content.Client.Access;
|
||||||
|
|
||||||
|
public sealed class AccessSystem : SharedAccessSystem {}
|
||||||
33
Content.Client/Access/Commands/ShowAccessReadersCommand.cs
Normal file
33
Content.Client/Access/Commands/ShowAccessReadersCommand.cs
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
using Robust.Client.Graphics;
|
||||||
|
using Robust.Client.ResourceManagement;
|
||||||
|
using Robust.Shared.Console;
|
||||||
|
|
||||||
|
namespace Content.Client.Access.Commands;
|
||||||
|
|
||||||
|
public sealed class ShowAccessReadersCommand : IConsoleCommand
|
||||||
|
{
|
||||||
|
public string Command => "showaccessreaders";
|
||||||
|
public string Description => "Shows all access readers in the viewport";
|
||||||
|
public string Help => $"{Command}";
|
||||||
|
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||||
|
{
|
||||||
|
var collection = IoCManager.Instance;
|
||||||
|
|
||||||
|
if (collection == null) return;
|
||||||
|
|
||||||
|
var overlay = collection.Resolve<IOverlayManager>();
|
||||||
|
|
||||||
|
if (overlay.RemoveOverlay<AccessOverlay>())
|
||||||
|
{
|
||||||
|
shell.WriteLine($"Set access reader debug overlay to false");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var entManager = collection.Resolve<IEntityManager>();
|
||||||
|
var cache = collection.Resolve<IResourceCache>();
|
||||||
|
var system = entManager.EntitySysManager.GetEntitySystem<EntityLookupSystem>();
|
||||||
|
|
||||||
|
overlay.AddOverlay(new AccessOverlay(entManager, cache, system));
|
||||||
|
shell.WriteLine($"Set access reader debug overlay to true");
|
||||||
|
}
|
||||||
|
}
|
||||||
8
Content.Server/Access/Systems/AccessSystem.cs
Normal file
8
Content.Server/Access/Systems/AccessSystem.cs
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
using Content.Shared.Access.Systems;
|
||||||
|
|
||||||
|
namespace Content.Server.Access.Systems;
|
||||||
|
|
||||||
|
public sealed class AccessSystem : SharedAccessSystem
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
@@ -12,7 +12,7 @@ namespace Content.Server.Access.Systems
|
|||||||
{
|
{
|
||||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||||
[Dependency] private readonly IdCardSystem _cardSystem = default!;
|
[Dependency] private readonly IdCardSystem _cardSystem = default!;
|
||||||
[Dependency] private readonly AccessSystem _accessSystem = default!;
|
[Dependency] private readonly SharedAccessSystem _accessSystem = default!;
|
||||||
[Dependency] private readonly StationSystem _stationSystem = default!;
|
[Dependency] private readonly StationSystem _stationSystem = default!;
|
||||||
|
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ public sealed partial class AdminVerbSystem
|
|||||||
{
|
{
|
||||||
[Dependency] private readonly AirlockSystem _airlockSystem = default!;
|
[Dependency] private readonly AirlockSystem _airlockSystem = default!;
|
||||||
[Dependency] private readonly StackSystem _stackSystem = default!;
|
[Dependency] private readonly StackSystem _stackSystem = default!;
|
||||||
[Dependency] private readonly AccessSystem _accessSystem = default!;
|
[Dependency] private readonly SharedAccessSystem _accessSystem = default!;
|
||||||
[Dependency] private readonly HandsSystem _handsSystem = default!;
|
[Dependency] private readonly HandsSystem _handsSystem = default!;
|
||||||
[Dependency] private readonly QuickDialogSystem _quickDialog = default!;
|
[Dependency] private readonly QuickDialogSystem _quickDialog = default!;
|
||||||
[Dependency] private readonly AdminTestArenaSystem _adminTestArenaSystem = default!;
|
[Dependency] private readonly AdminTestArenaSystem _adminTestArenaSystem = default!;
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ using Content.Server.Maps;
|
|||||||
using Content.Server.Mind;
|
using Content.Server.Mind;
|
||||||
using Content.Server.Players;
|
using Content.Server.Players;
|
||||||
using Content.Shared.CCVar;
|
using Content.Shared.CCVar;
|
||||||
using Content.Shared.Coordinates;
|
|
||||||
using Content.Shared.GameTicking;
|
using Content.Shared.GameTicking;
|
||||||
using Content.Shared.Preferences;
|
using Content.Shared.Preferences;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
@@ -20,7 +19,6 @@ using Robust.Shared.Random;
|
|||||||
using Robust.Shared.Utility;
|
using Robust.Shared.Utility;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Robust.Shared.Players;
|
|
||||||
|
|
||||||
namespace Content.Server.GameTicking
|
namespace Content.Server.GameTicking
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ namespace Content.Server.Sandbox
|
|||||||
[Dependency] private readonly IPlacementManager _placementManager = default!;
|
[Dependency] private readonly IPlacementManager _placementManager = default!;
|
||||||
[Dependency] private readonly IConGroupController _conGroupController = default!;
|
[Dependency] private readonly IConGroupController _conGroupController = default!;
|
||||||
[Dependency] private readonly IServerConsoleHost _host = default!;
|
[Dependency] private readonly IServerConsoleHost _host = default!;
|
||||||
[Dependency] private readonly AccessSystem _access = default!;
|
[Dependency] private readonly SharedAccessSystem _access = default!;
|
||||||
[Dependency] private readonly InventorySystem _inventory = default!;
|
[Dependency] private readonly InventorySystem _inventory = default!;
|
||||||
[Dependency] private readonly ItemSlotsSystem _slots = default!;
|
[Dependency] private readonly ItemSlotsSystem _slots = default!;
|
||||||
[Dependency] private readonly GameTicker _ticker = default!;
|
[Dependency] private readonly GameTicker _ticker = default!;
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ public sealed class StationSpawningSystem : EntitySystem
|
|||||||
[Dependency] private readonly IdCardSystem _cardSystem = default!;
|
[Dependency] private readonly IdCardSystem _cardSystem = default!;
|
||||||
[Dependency] private readonly InventorySystem _inventorySystem = default!;
|
[Dependency] private readonly InventorySystem _inventorySystem = default!;
|
||||||
[Dependency] private readonly PDASystem _pdaSystem = default!;
|
[Dependency] private readonly PDASystem _pdaSystem = default!;
|
||||||
[Dependency] private readonly AccessSystem _accessSystem = default!;
|
[Dependency] private readonly SharedAccessSystem _accessSystem = default!;
|
||||||
[Dependency] private readonly IdentitySystem _identity = default!;
|
[Dependency] private readonly IdentitySystem _identity = default!;
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Content.Shared.Access.Systems;
|
using Content.Shared.Access.Systems;
|
||||||
|
using Robust.Shared.GameStates;
|
||||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Set;
|
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Set;
|
||||||
|
|
||||||
namespace Content.Shared.Access.Components
|
namespace Content.Shared.Access.Components
|
||||||
@@ -6,12 +7,12 @@ namespace Content.Shared.Access.Components
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Simple mutable access provider found on ID cards and such.
|
/// Simple mutable access provider found on ID cards and such.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[RegisterComponent]
|
[RegisterComponent, NetworkedComponent]
|
||||||
[Access(typeof(AccessSystem))]
|
[Access(typeof(SharedAccessSystem))]
|
||||||
public sealed class AccessComponent : Component
|
public sealed class AccessComponent : Component
|
||||||
{
|
{
|
||||||
[DataField("tags", customTypeSerializer: typeof(PrototypeIdHashSetSerializer<AccessLevelPrototype>))]
|
[DataField("tags", customTypeSerializer: typeof(PrototypeIdHashSetSerializer<AccessLevelPrototype>))]
|
||||||
[Access(typeof(AccessSystem), Other = AccessPermissions.ReadExecute)] // FIXME Friends
|
[Access(typeof(SharedAccessSystem), Other = AccessPermissions.ReadExecute)] // FIXME Friends
|
||||||
public HashSet<string> Tags = new();
|
public HashSet<string> Tags = new();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
using Content.Shared.Access.Components;
|
using Content.Shared.Access.Components;
|
||||||
using Content.Shared.Roles;
|
using Content.Shared.Roles;
|
||||||
|
using Robust.Shared.GameStates;
|
||||||
using Robust.Shared.Prototypes;
|
using Robust.Shared.Prototypes;
|
||||||
|
using Robust.Shared.Serialization;
|
||||||
|
|
||||||
namespace Content.Shared.Access.Systems
|
namespace Content.Shared.Access.Systems
|
||||||
{
|
{
|
||||||
public sealed class AccessSystem : EntitySystem
|
public abstract class SharedAccessSystem : EntitySystem
|
||||||
{
|
{
|
||||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||||
|
|
||||||
@@ -13,6 +15,28 @@ namespace Content.Shared.Access.Systems
|
|||||||
base.Initialize();
|
base.Initialize();
|
||||||
|
|
||||||
SubscribeLocalEvent<AccessComponent, MapInitEvent>(OnAccessInit);
|
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,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnAccessInit(EntityUid uid, AccessComponent component, MapInitEvent args)
|
private void OnAccessInit(EntityUid uid, AccessComponent component, MapInitEvent args)
|
||||||
@@ -38,6 +62,7 @@ namespace Content.Shared.Access.Systems
|
|||||||
|
|
||||||
access.Tags.Clear();
|
access.Tags.Clear();
|
||||||
access.Tags.UnionWith(newTags);
|
access.Tags.UnionWith(newTags);
|
||||||
|
Dirty(access);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -55,6 +80,7 @@ namespace Content.Shared.Access.Systems
|
|||||||
access.Tags.UnionWith(proto.Tags);
|
access.Tags.UnionWith(proto.Tags);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Dirty(access);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,5 +111,12 @@ namespace Content.Shared.Access.Systems
|
|||||||
TryAddGroups(uid, prototype.ExtendedAccessGroups, access);
|
TryAddGroups(uid, prototype.ExtendedAccessGroups, access);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Serializable, NetSerializable]
|
||||||
|
private sealed class AccessComponentState : ComponentState
|
||||||
|
{
|
||||||
|
public HashSet<string> Tags = new();
|
||||||
|
public HashSet<string> Groups = new();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user