Refactor ExtinguisherCabinet->ItemCabinet and actually maps them in, adds EntityWhitelist (#4154)
* i probably shouldnt have done this in one commit * map nonsense * fix example code * unnecessary * test * reviews * little fix for open datafield * add soul
This commit is contained in:
@@ -5,9 +5,9 @@ using Robust.Shared.Serialization;
|
||||
namespace Content.Shared.GameObjects.Components
|
||||
{
|
||||
[Serializable, NetSerializable]
|
||||
public enum ExtinguisherCabinetVisuals
|
||||
public enum ItemCabinetVisuals : byte
|
||||
{
|
||||
IsOpen,
|
||||
ContainsExtinguisher
|
||||
ContainsItem
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ namespace Content.Shared.Interfaces.GameObjects.Components
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raised when clicking on another object and no attack event was handled.
|
||||
/// Raised directed on the used object when clicking on another object and no attack event was handled.
|
||||
/// </summary>
|
||||
[PublicAPI]
|
||||
public class AfterInteractEvent : HandledEntityEventArgs
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace Content.Shared.Interfaces.GameObjects.Components
|
||||
/// <summary>
|
||||
/// Called when a player directly interacts with an empty hand when user is in range of the target entity.
|
||||
/// </summary>
|
||||
[Obsolete("Use AttackHandMessage instead")]
|
||||
[Obsolete("Use InteractHandEvent instead")]
|
||||
bool InteractHand(InteractHandEventArgs eventArgs);
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace Content.Shared.Interfaces.GameObjects.Components
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raised when a target entity is interacted with by a user with an empty hand.
|
||||
/// Raised directed on a target entity when it is interacted with by a user with an empty hand.
|
||||
/// </summary>
|
||||
[PublicAPI]
|
||||
public class InteractHandEvent : HandledEntityEventArgs
|
||||
|
||||
85
Content.Shared/Utility/EntityWhitelist.cs
Normal file
85
Content.Shared/Utility/EntityWhitelist.cs
Normal file
@@ -0,0 +1,85 @@
|
||||
using System.Collections.Generic;
|
||||
using Content.Shared.GameObjects.Components.Tag;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
|
||||
namespace Content.Shared.Utility
|
||||
{
|
||||
/// <summary>
|
||||
/// Used to determine whether an entity fits a certain whitelist.
|
||||
/// Does not whitelist by prototypes, since that is undesirable; you're better off just adding a tag to all
|
||||
/// entity prototypes that need to be whitelisted, and checking for that.
|
||||
/// </summary>
|
||||
/// <code>
|
||||
/// whitelist:
|
||||
/// tags:
|
||||
/// - Cigarette
|
||||
/// - FirelockElectronics
|
||||
/// components:
|
||||
/// - Buckle
|
||||
/// - AsteroidRock
|
||||
/// </code>
|
||||
[DataDefinition]
|
||||
public class EntityWhitelist : ISerializationHooks
|
||||
{
|
||||
/// <summary>
|
||||
/// Component names that are allowed in the whitelist.
|
||||
/// </summary>
|
||||
[DataField("components")] public string[]? Components = null;
|
||||
|
||||
private List<IComponentRegistration>? _registrations = null;
|
||||
|
||||
/// <summary>
|
||||
/// Tags that are allowed in the whitelist.
|
||||
/// </summary>
|
||||
[DataField("tags")] public string[]? Tags = null;
|
||||
|
||||
void ISerializationHooks.AfterDeserialization()
|
||||
{
|
||||
UpdateRegistrations();
|
||||
}
|
||||
|
||||
public void UpdateRegistrations()
|
||||
{
|
||||
if (Components == null) return;
|
||||
|
||||
var compfact = IoCManager.Resolve<IComponentFactory>();
|
||||
_registrations = new List<IComponentRegistration>();
|
||||
foreach (var name in Components)
|
||||
{
|
||||
if (!compfact.TryGetRegistration(name, out var registration))
|
||||
{
|
||||
Logger.Warning($"Invalid component name {name} passed to EntityWhitelist!");
|
||||
continue;
|
||||
}
|
||||
|
||||
_registrations.Add(registration);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns whether a given entity fits the whitelist.
|
||||
/// </summary>
|
||||
public bool IsValid(IEntity entity)
|
||||
{
|
||||
if (Tags != null)
|
||||
{
|
||||
if (entity.HasAnyTag(Tags))
|
||||
return true;
|
||||
}
|
||||
|
||||
if (_registrations != null)
|
||||
{
|
||||
foreach (var reg in _registrations)
|
||||
{
|
||||
if (entity.TryGetComponent(reg.Type, out _))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user