Block interactions with subfloor entities (#6732)

This commit is contained in:
Leon Friedrich
2022-02-16 15:34:31 +13:00
committed by GitHub
parent 1719384b3c
commit 9d422d0762
5 changed files with 21 additions and 4 deletions

View File

@@ -1,4 +1,5 @@
using Content.Shared.Interaction; using Content.Shared.Interaction;
using Content.Shared.Interaction.Events;
using Content.Shared.Maps; using Content.Shared.Maps;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Shared.Map; using Robust.Shared.Map;
@@ -26,7 +27,7 @@ namespace Content.Shared.SubFloor
SubscribeLocalEvent<SubFloorHideComponent, ComponentStartup>(OnSubFloorStarted); SubscribeLocalEvent<SubFloorHideComponent, ComponentStartup>(OnSubFloorStarted);
SubscribeLocalEvent<SubFloorHideComponent, ComponentShutdown>(OnSubFloorTerminating); SubscribeLocalEvent<SubFloorHideComponent, ComponentShutdown>(OnSubFloorTerminating);
SubscribeLocalEvent<SubFloorHideComponent, AnchorStateChangedEvent>(HandleAnchorChanged); SubscribeLocalEvent<SubFloorHideComponent, AnchorStateChangedEvent>(HandleAnchorChanged);
SubscribeLocalEvent<SubFloorHideComponent, InteractUsingEvent>(OnInteractionAttempt); SubscribeLocalEvent<SubFloorHideComponent, GettingInteractedWithAttemptEvent>(OnInteractionAttempt);
} }
public override void Shutdown() public override void Shutdown()
@@ -37,10 +38,11 @@ namespace Content.Shared.SubFloor
_mapManager.TileChanged -= MapManagerOnTileChanged; _mapManager.TileChanged -= MapManagerOnTileChanged;
} }
private void OnInteractionAttempt(EntityUid uid, SubFloorHideComponent component, InteractUsingEvent args) private void OnInteractionAttempt(EntityUid uid, SubFloorHideComponent component, GettingInteractedWithAttemptEvent args)
{ {
// TODO make this use an interact attempt event or something. Handling an InteractUsing is not going to work in general. // No interactions with entities hidden under floor tiles.
args.Handled = component.IsUnderCover; if (component.BlockInteractions && component.IsUnderCover)
args.Cancel();
} }
private void OnSubFloorStarted(EntityUid uid, SubFloorHideComponent component, ComponentStartup _) private void OnSubFloorStarted(EntityUid uid, SubFloorHideComponent component, ComponentStartup _)

View File

@@ -20,6 +20,15 @@ namespace Content.Shared.SubFloor
[ViewVariables] [ViewVariables]
public bool IsUnderCover { get; set; } = false; public bool IsUnderCover { get; set; } = false;
/// <summary>
/// Whether interactions with this entity should be blocked while it is under floor tiles.
/// </summary>
/// <remarks>
/// Useful for entities like vents, which are only partially hidden.
/// </remarks>
[DataField("blockInteractions")]
public bool BlockInteractions { get; set; } = true;
/// <summary> /// <summary>
/// When revealed using some scanning tool, what transparency should be used to draw this item? /// When revealed using some scanning tool, what transparency should be used to draw this item?
/// </summary> /// </summary>

View File

@@ -6,6 +6,8 @@
mode: SnapgridCenter mode: SnapgridCenter
components: components:
- type: AtmosDevice - type: AtmosDevice
- type: SubFloorHide
blockInteractions: false
- type: NodeContainer - type: NodeContainer
nodes: nodes:
inlet: inlet:

View File

@@ -6,6 +6,8 @@
mode: SnapgridCenter mode: SnapgridCenter
components: components:
- type: AtmosDevice - type: AtmosDevice
- type: SubFloorHide
blockInteractions: false
- type: NodeContainer - type: NodeContainer
nodes: nodes:
inlet: inlet:

View File

@@ -6,6 +6,8 @@
mode: SnapgridCenter mode: SnapgridCenter
components: components:
- type: AtmosDevice - type: AtmosDevice
- type: SubFloorHide
blockInteractions: false
- type: NodeContainer - type: NodeContainer
nodes: nodes:
pipe: pipe: