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.
This commit is contained in:
@@ -3,34 +3,41 @@ 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();
|
||||
var mapManager = IoCManager.Resolve<IMapManager>();
|
||||
mapManager.TileChanged += HandleTileChanged;
|
||||
_mapManager.TileChanged += HandleTileChanged;
|
||||
}
|
||||
|
||||
public override void Shutdown()
|
||||
{
|
||||
base.Shutdown();
|
||||
var mapManager = IoCManager.Resolve<IMapManager>();
|
||||
mapManager.TileChanged -= HandleTileChanged;
|
||||
_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, snapGrid) in ComponentManager.EntityQuery<PuddleComponent, SnapGridComponent>(true))
|
||||
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 &&
|
||||
snapGrid.Position == eventArgs.NewTile.GridIndices &&
|
||||
grid.TileIndicesFor(puddleTransform.Coordinates) == eventArgs.NewTile.GridIndices &&
|
||||
eventArgs.NewTile.Tile.IsEmpty)
|
||||
{
|
||||
puddle.Owner.Delete();
|
||||
|
||||
Reference in New Issue
Block a user