Files
tbd-station-14/Content.Server/GameObjects/EntitySystems/PuddleSystem.cs
metalgearsloth 619386a04a Server EntitySystem cleanup (#1617)
* Server EntitySystem cleanup

I went after low-hanging fruit systems.

* Add / change to internal access modifiers to systems
* Use EntityQuery to get components instead
* Add sealed modifier to systems
* Remove unused imports
* Add jetbrains annotation for unused classes
* Removed some pragmas for dependencies

This should also fix a decent chunk of the server build warnings, at least the ones that matter.

* Also disposals

* Update Content.Server/GameObjects/EntitySystems/GravitySystem.cs

* Fix build

Co-authored-by: Metal Gear Sloth <metalgearsloth@gmail.com>
Co-authored-by: Víctor Aguilera Puerto <6766154+Zumorica@users.noreply.github.com>
2020-08-13 14:17:12 +02:00

46 lines
1.7 KiB
C#

using Content.Server.GameObjects.Components.Fluids;
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Components.Transform;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.Map;
using Robust.Shared.IoC;
using Robust.Shared.Map;
namespace Content.Server.Interfaces.GameObjects.Components.Interaction
{
[UsedImplicitly]
internal sealed class PuddleSystem : EntitySystem
{
public override void Initialize()
{
base.Initialize();
var mapManager = IoCManager.Resolve<IMapManager>();
mapManager.TileChanged += HandleTileChanged;
}
public override void Shutdown()
{
base.Shutdown();
var mapManager = IoCManager.Resolve<IMapManager>();
mapManager.TileChanged -= HandleTileChanged;
}
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, snapGrid) in ComponentManager.EntityQuery<PuddleComponent, SnapGridComponent>())
{
// If the tile becomes space then delete it (potentially change by design)
if (eventArgs.NewTile.GridIndex == puddle.Owner.Transform.GridID &&
snapGrid.Position == eventArgs.NewTile.GridIndices &&
eventArgs.NewTile.Tile.IsEmpty)
{
puddle.Owner.Delete();
break; // Currently it's one puddle per tile, if that changes remove this
}
}
}
}
}