diff --git a/Content.Shared/SubFloor/SubFloorHideComponent.cs b/Content.Shared/SubFloor/SubFloorHideComponent.cs index a76c73473e..93587e6f8c 100644 --- a/Content.Shared/SubFloor/SubFloorHideComponent.cs +++ b/Content.Shared/SubFloor/SubFloorHideComponent.cs @@ -1,4 +1,6 @@ using Robust.Shared.GameObjects; +using Robust.Shared.Serialization.Manager.Attributes; +using Robust.Shared.ViewVariables; namespace Content.Shared.SubFloor { @@ -13,5 +15,12 @@ namespace Content.Shared.SubFloor { /// public override string Name => "SubFloorHide"; + + /// + /// This entity needs to be anchored to be hid in the subfloor. + /// + [ViewVariables(VVAccess.ReadWrite)] + [DataField("requireAnchored")] + public bool RequireAnchored { get; set; } = true; } } diff --git a/Content.Shared/SubFloor/SubFloorHideSystem.cs b/Content.Shared/SubFloor/SubFloorHideSystem.cs index 5dd30a86a3..6f3f5bd9f2 100644 --- a/Content.Shared/SubFloor/SubFloorHideSystem.cs +++ b/Content.Shared/SubFloor/SubFloorHideSystem.cs @@ -68,8 +68,7 @@ namespace Content.Shared.SubFloor var transform = ComponentManager.GetComponent(uid); // We do this directly instead of calling UpdateEntity. - if(_mapManager.TryGetGrid(transform.GridID, out var grid)) - UpdateTile(grid, grid.TileIndicesFor(transform.Coordinates)); + UpdateEntity(uid); } private void MapManagerOnTileChanged(object? sender, TileChangedEventArgs e) @@ -113,6 +112,7 @@ namespace Content.Shared.SubFloor private void UpdateEntity(EntityUid uid) { var transform = ComponentManager.GetComponent(uid); + if (!_mapManager.TryGetGrid(transform.GridID, out var grid)) { // Not being on a grid counts as no subfloor, unhide this. @@ -134,6 +134,18 @@ 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)) + { + // If we require the entity to be anchored but it's not, this will set subfloor to true, unhiding it. + subFloor = !transformComponent.Anchored; + } + // Show sprite if (ComponentManager.TryGetComponent(uid, out SharedSpriteComponent? spriteComponent)) { diff --git a/SpaceStation14.sln.DotSettings b/SpaceStation14.sln.DotSettings index 5ff7f8d1e5..692912bc33 100644 --- a/SpaceStation14.sln.DotSettings +++ b/SpaceStation14.sln.DotSettings @@ -264,6 +264,7 @@ True True True + True True True True @@ -284,6 +285,7 @@ True True True + True True True True