diff --git a/Content.Shared/SubFloor/SubFloorHideComponent.cs b/Content.Shared/SubFloor/SubFloorHideComponent.cs
index 93587e6f8c..100903c855 100644
--- a/Content.Shared/SubFloor/SubFloorHideComponent.cs
+++ b/Content.Shared/SubFloor/SubFloorHideComponent.cs
@@ -1,4 +1,8 @@
+using System;
using Robust.Shared.GameObjects;
+using Robust.Shared.GameStates;
+using Robust.Shared.Players;
+using Robust.Shared.Serialization;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.ViewVariables;
@@ -10,6 +14,7 @@ namespace Content.Shared.SubFloor
/// (plating).
///
///
+ [NetworkedComponent]
[RegisterComponent]
public sealed class SubFloorHideComponent : Component
{
@@ -17,10 +22,35 @@ namespace Content.Shared.SubFloor
public override string Name => "SubFloorHide";
///
- /// This entity needs to be anchored to be hid in the subfloor.
+ /// Whether the entity will be hid when not in subfloor.
+ ///
+ [ViewVariables(VVAccess.ReadWrite)]
+ [DataField("enabled")]
+ public bool Enabled { get; set; } = true;
+
+ ///
+ /// This entity needs to be anchored to be hid when not in subfloor.
///
[ViewVariables(VVAccess.ReadWrite)]
[DataField("requireAnchored")]
public bool RequireAnchored { get; set; } = true;
+
+ public override ComponentState GetComponentState(ICommonSession player)
+ {
+ return new SubFloorHideComponentState(Enabled, RequireAnchored);
+ }
+ }
+
+ [Serializable, NetSerializable]
+ public class SubFloorHideComponentState : ComponentState
+ {
+ public bool Enabled { get; }
+ public bool RequireAnchored { get; }
+
+ public SubFloorHideComponentState(bool enabled, bool requireAnchored)
+ {
+ Enabled = enabled;
+ RequireAnchored = requireAnchored;
+ }
}
}
diff --git a/Content.Shared/SubFloor/SubFloorHideSystem.cs b/Content.Shared/SubFloor/SubFloorHideSystem.cs
index 503a153ea4..d729e2b31a 100644
--- a/Content.Shared/SubFloor/SubFloorHideSystem.cs
+++ b/Content.Shared/SubFloor/SubFloorHideSystem.cs
@@ -2,6 +2,7 @@ using System;
using Content.Shared.Maps;
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
+using Robust.Shared.GameStates;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Maths;
@@ -44,6 +45,7 @@ namespace Content.Shared.SubFloor
SubscribeLocalEvent(OnSubFloorStarted);
SubscribeLocalEvent(OnSubFloorTerminating);
SubscribeLocalEvent(HandleAnchorChanged);
+ SubscribeLocalEvent(HandleComponentState);
}
public override void Shutdown()
@@ -54,6 +56,20 @@ namespace Content.Shared.SubFloor
_mapManager.TileChanged -= MapManagerOnTileChanged;
}
+ public void SetEnabled(SubFloorHideComponent subFloor, bool enabled)
+ {
+ subFloor.Enabled = enabled;
+ subFloor.Dirty();
+ UpdateEntity(subFloor.Owner.Uid);
+ }
+
+ public void SetRequireAnchoring(SubFloorHideComponent subFloor, bool requireAnchored)
+ {
+ subFloor.RequireAnchored = requireAnchored;
+ subFloor.Dirty();
+ UpdateEntity(subFloor.Owner.Uid);
+ }
+
private void OnSubFloorStarted(EntityUid uid, SubFloorHideComponent component, ComponentStartup _)
{
UpdateEntity(uid);
@@ -73,6 +89,16 @@ namespace Content.Shared.SubFloor
UpdateEntity(uid);
}
+ private void HandleComponentState(EntityUid uid, SubFloorHideComponent component, ComponentHandleState args)
+ {
+ if (args.Current is not SubFloorHideComponentState state)
+ return;
+
+ component.Enabled = state.Enabled;
+ component.RequireAnchored = state.RequireAnchored;
+ UpdateEntity(uid);
+ }
+
private void MapManagerOnTileChanged(object? sender, TileChangedEventArgs e)
{
UpdateTile(_mapManager.GetGrid(e.NewTile.GridIndex), e.NewTile.GridIndices);
@@ -136,16 +162,21 @@ namespace Content.Shared.SubFloor
if (subFloorHideEvent.Handled)
return;
- // This might look weird, but basically we only need to query the SubFloorHide and Transform components
- // if we are gonna hide the entity and we require it to be anchored to be hidden. Because getting components
- // is "expensive", we have a slow path where we query them, and a fast path where we don't.
- if (!subFloor
- && ComponentManager.TryGetComponent(uid, out SubFloorHideComponent? subFloorHideComponent) &&
- subFloorHideComponent.RequireAnchored
- && ComponentManager.TryGetComponent(uid, out ITransformComponent? transformComponent))
+ // We only need to query the subfloor component to check if it's enabled or not when we're not on subfloor.
+ // Getting components is expensive, after all.
+ if (!subFloor && ComponentManager.TryGetComponent(uid, out SubFloorHideComponent? subFloorHideComponent))
{
- // If we require the entity to be anchored but it's not, this will set subfloor to true, unhiding it.
- subFloor = !transformComponent.Anchored;
+ // If the component isn't enabled, then subfloor will always be true, and the entity will be shown.
+ if (!subFloorHideComponent.Enabled)
+ {
+ subFloor = true;
+ }
+ // We only need to query the TransformComp if the SubfloorHide is enabled and requires anchoring.
+ else if (subFloorHideComponent.RequireAnchored && ComponentManager.TryGetComponent(uid, out ITransformComponent? transformComponent))
+ {
+ // If we require the entity to be anchored but it's not, this will set subfloor to true, unhiding it.
+ subFloor = !transformComponent.Anchored;
+ }
}
// Whether to show this entity as visible, visually.