SubFloorHide requires entities to be anchored by default.

This commit is contained in:
Vera Aguilera Puerto
2021-07-30 12:25:58 +02:00
parent 8c362fcd9b
commit f4769c00d7
3 changed files with 25 additions and 2 deletions

View File

@@ -1,4 +1,6 @@
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.ViewVariables;
namespace Content.Shared.SubFloor namespace Content.Shared.SubFloor
{ {
@@ -13,5 +15,12 @@ namespace Content.Shared.SubFloor
{ {
/// <inheritdoc /> /// <inheritdoc />
public override string Name => "SubFloorHide"; public override string Name => "SubFloorHide";
/// <summary>
/// This entity needs to be anchored to be hid in the subfloor.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
[DataField("requireAnchored")]
public bool RequireAnchored { get; set; } = true;
} }
} }

View File

@@ -68,8 +68,7 @@ namespace Content.Shared.SubFloor
var transform = ComponentManager.GetComponent<ITransformComponent>(uid); var transform = ComponentManager.GetComponent<ITransformComponent>(uid);
// We do this directly instead of calling UpdateEntity. // We do this directly instead of calling UpdateEntity.
if(_mapManager.TryGetGrid(transform.GridID, out var grid)) UpdateEntity(uid);
UpdateTile(grid, grid.TileIndicesFor(transform.Coordinates));
} }
private void MapManagerOnTileChanged(object? sender, TileChangedEventArgs e) private void MapManagerOnTileChanged(object? sender, TileChangedEventArgs e)
@@ -113,6 +112,7 @@ namespace Content.Shared.SubFloor
private void UpdateEntity(EntityUid uid) private void UpdateEntity(EntityUid uid)
{ {
var transform = ComponentManager.GetComponent<ITransformComponent>(uid); var transform = ComponentManager.GetComponent<ITransformComponent>(uid);
if (!_mapManager.TryGetGrid(transform.GridID, out var grid)) if (!_mapManager.TryGetGrid(transform.GridID, out var grid))
{ {
// Not being on a grid counts as no subfloor, unhide this. // Not being on a grid counts as no subfloor, unhide this.
@@ -134,6 +134,18 @@ namespace Content.Shared.SubFloor
if (subFloorHideEvent.Handled) if (subFloorHideEvent.Handled)
return; 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 // Show sprite
if (ComponentManager.TryGetComponent(uid, out SharedSpriteComponent? spriteComponent)) if (ComponentManager.TryGetComponent(uid, out SharedSpriteComponent? spriteComponent))
{ {

View File

@@ -264,6 +264,7 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=Spirate/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Spirate/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Strippable/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Strippable/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=stunnable/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=stunnable/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=subfloor/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Superconduct/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Superconduct/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=superconduction/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=superconduction/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=swsl/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=swsl/@EntryIndexedValue">True</s:Boolean>
@@ -284,6 +285,7 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=unequip/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=unequip/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=unexcite/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=unexcite/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Unequip/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Unequip/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=unhiding/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=unlockable/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=unlockable/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=unobtanium/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=unobtanium/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Unoccluded/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Unoccluded/@EntryIndexedValue">True</s:Boolean>