Add component that lets entities ignore BUI range checks (#4264)

This commit is contained in:
DrSmugleaf
2023-08-15 22:41:01 -07:00
committed by GitHub
parent 3ade9ca447
commit d3dc89832a
6 changed files with 35 additions and 9 deletions

View File

@@ -39,7 +39,7 @@ END TEMPLATE-->
### New features
*None yet*
* Added IgnoreUIChecksComponent that lets entities ignore bound user interface range checks which would normally close the UI.
### Bugfixes
@@ -47,7 +47,7 @@ END TEMPLATE-->
### Other
*None yet*
* EntityQuery.HasComponent override for nullable entity uids.
### Internal

View File

@@ -0,0 +1,12 @@
using Robust.Shared.GameObjects;
namespace Robust.Server.GameObjects;
/// <summary>
/// Lets any entities with this component ignore user interface range checks that would normally
/// close the UI automatically.
/// </summary>
[RegisterComponent]
public sealed class IgnoreUIRangeComponent : Component
{
}

View File

@@ -17,6 +17,8 @@ namespace Robust.Server.GameObjects
[Dependency] private readonly IPlayerManager _playerMan = default!;
[Dependency] private readonly TransformSystem _xformSys = default!;
private EntityQuery<IgnoreUIRangeComponent> _ignoreUIRangeQuery;
private readonly List<IPlayerSession> _sessionCache = new();
private readonly Dictionary<IPlayerSession, List<BoundUserInterface>> _openInterfaces = new();
@@ -30,6 +32,8 @@ namespace Robust.Server.GameObjects
SubscribeLocalEvent<ServerUserInterfaceComponent, ComponentInit>(OnUserInterfaceInit);
SubscribeLocalEvent<ServerUserInterfaceComponent, ComponentShutdown>(OnUserInterfaceShutdown);
_playerMan.PlayerStatusChanged += OnPlayerStatusChanged;
_ignoreUIRangeQuery = GetEntityQuery<IgnoreUIRangeComponent>();
}
public override void Shutdown()
@@ -174,6 +178,9 @@ namespace Robust.Server.GameObjects
if (!query.TryGetComponent(session.AttachedEntity, out var xform))
continue;
if (_ignoreUIRangeQuery.HasComponent(session.AttachedEntity))
continue;
if (uiMap != xform.MapID)
{
CloseUi(ui, session, activeUis);

View File

@@ -21,7 +21,7 @@
<PackageReference Include="Serilog.Sinks.Loki" Version="4.0.0-beta3" PrivateAssets="compile" />
<PackageReference Include="Microsoft.Extensions.Primitives" Version="6.0.0" />
<PackageReference Include="prometheus-net.DotNetRuntime" Version="4.2.2" />
<PackageReference Include="TerraFX.Interop.Windows" Version="10.0.20348-rc2" PrivateAssets="compile"/>
<PackageReference Include="TerraFX.Interop.Windows" Version="10.0.20348-rc2" PrivateAssets="compile" />
<PackageReference Include="Microsoft.Extensions.ObjectPool" Version="6.0.2" PrivateAssets="compile" />
<PackageReference Include="SpaceWizards.Sodium" Version="0.2.1" PrivateAssets="compile" />
<PackageReference Include="SharpZstd.Interop" Version="1.5.2-beta2" PrivateAssets="compile" />

View File

@@ -1409,6 +1409,13 @@ namespace Robust.Shared.GameObjects
return _traitDict.TryGetValue(uid, out var comp) && !comp.Deleted;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[Pure]
public bool HasComponent(EntityUid? uid)
{
return uid != null && HasComponent(uid.Value);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[Pure]
public bool Resolve(EntityUid uid, [NotNullWhen(true)] ref TComp1? component, bool logMissing = true)

View File

@@ -10,7 +10,6 @@ using Robust.Shared.Physics.Dynamics;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.Manager;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.Utility;
namespace Robust.UnitTesting.Server.Maps
{
@@ -59,18 +58,19 @@ entities:
[OneTimeSetUp]
public void Setup()
{
// For some reason RobustUnitTest doesn't discover PVSSystem but this does here so ?
var syssy = IoCManager.Resolve<IEntitySystemManager>();
syssy.Shutdown();
syssy.Initialize();
var compFactory = IoCManager.Resolve<IComponentFactory>();
compFactory.RegisterClass<MapDeserializeTestComponent>();
compFactory.RegisterClass<VisibilityComponent>();
compFactory.RegisterClass<ActorComponent>();
compFactory.RegisterClass<IgnoreUIRangeComponent>();
compFactory.GenerateNetIds();
IoCManager.Resolve<ISerializationManager>().Initialize();
// For some reason RobustUnitTest doesn't discover PVSSystem but this does here so ?
var syssy = IoCManager.Resolve<IEntitySystemManager>();
syssy.Shutdown();
syssy.Initialize();
var resourceManager = IoCManager.Resolve<IResourceManagerInternal>();
resourceManager.Initialize(null);
resourceManager.MountString("/TestMap.yml", MapData);