Files
tbd-station-14/Content.Server/GameObjects/EntitySystems/PuddleSystem.cs
Acruid 00e01d51fd SnapGridComponent Removal (#3884)
* Removed SnapGridOffset, there is only center now.

* SnapGridComponent methods are now static.

* Removed SnapGridComponent.OnPositionChanged.

* Refactored static functions off SnapGridComponent to MapGrid.
Refactored away usages of SnapGridComponent.Position.

* Added Transform.Anchored for checking if an entity is a tile entity.
More refactoring for static MapGrid functions.

* Static snapgrid methods on MapGrid are no longer static.

* Add setter to ITransformComponent.Anchored.
Removed direct references to SnapGridComponent from content.

* Grid functions now deal with EntityUids instead of SnapGridComponents.
Began renaming public API functions from SnapGrid to Anchor.

* Remove the SnapGridComponent 'Offset' field from all yaml files. This was removed in code previously, so the yaml linter was upset.

* Update engine submodule to v0.4.46.
2021-04-28 10:49:37 -07:00

50 lines
1.8 KiB
C#

using Content.Server.GameObjects.Components.Fluids;
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Maths;
namespace Content.Server.GameObjects.EntitySystems
{
[UsedImplicitly]
internal sealed class PuddleSystem : EntitySystem
{
[Dependency] private readonly IMapManager _mapManager = default!;
public override void Initialize()
{
base.Initialize();
_mapManager.TileChanged += HandleTileChanged;
}
public override void Shutdown()
{
base.Shutdown();
_mapManager.TileChanged -= HandleTileChanged;
}
//TODO: Replace all this with an Unanchored event that deletes the puddle
private void HandleTileChanged(object? sender, TileChangedEventArgs eventArgs)
{
// If this gets hammered you could probably queue up all the tile changes every tick but I doubt that would ever happen.
foreach (var puddle in ComponentManager.EntityQuery<PuddleComponent>(true))
{
// If the tile becomes space then delete it (potentially change by design)
var puddleTransform = puddle.Owner.Transform;
if(!puddleTransform.Anchored)
continue;
var grid = _mapManager.GetGrid(puddleTransform.GridID);
if (eventArgs.NewTile.GridIndex == puddle.Owner.Transform.GridID &&
grid.TileIndicesFor(puddleTransform.Coordinates) == eventArgs.NewTile.GridIndices &&
eventArgs.NewTile.Tile.IsEmpty)
{
puddle.Owner.Delete();
break; // Currently it's one puddle per tile, if that changes remove this
}
}
}
}
}