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:
Acruid
2021-04-28 10:49:37 -07:00
committed by GitHub
parent 578b767791
commit 00e01d51fd
74 changed files with 306 additions and 309 deletions

View File

@@ -10,7 +10,6 @@ using Content.Shared.Interfaces.GameObjects.Components;
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.Physics;
using Robust.Shared.Serialization;
using Robust.Shared.ViewVariables;
namespace Content.Server.GameObjects.Components
@@ -105,7 +104,7 @@ namespace Content.Server.GameObjects.Components
}
if (Snap)
Owner.SnapToGrid(SnapGridOffset.Center, Owner.EntityManager);
Owner.SnapToGrid(Owner.EntityManager);
Owner.EntityManager.EventBus.RaiseLocalEvent(Owner.Uid, new AnchoredMessage(), false);

View File

@@ -3,6 +3,8 @@ using Content.Server.GameObjects.EntitySystems;
using Content.Shared.Atmos;
using Robust.Server.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Log;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Serialization.Manager.Attributes;
@@ -14,6 +16,8 @@ namespace Content.Server.GameObjects.Components.Atmos
[RegisterComponent]
public class AirtightComponent : Component, IMapInit
{
[Dependency] private readonly IMapManager _mapManager = default!;
private (GridId, Vector2i) _lastPosition;
private AtmosphereSystem _atmosphereSystem = default!;
@@ -77,14 +81,13 @@ namespace Content.Server.GameObjects.Components.Atmos
_atmosphereSystem = EntitySystem.Get<AtmosphereSystem>();
// Using the SnapGrid is critical for performance, and thus if it is absent the component
// will not be airtight. A warning is much easier to track down than the object magically
// not being airtight, so log one if the SnapGrid component is missing.
Owner.EnsureComponentWarn(out SnapGridComponent _);
if (_fixAirBlockedDirectionInitialize)
RotateEvent(new RotateEvent(Owner, Angle.Zero, Owner.Transform.WorldRotation));
// Adding this component will immediately anchor the entity, because the atmos system
// requires airtight entities to be anchored for performance.
Owner.Transform.Anchored = true;
UpdatePosition();
}
@@ -116,28 +119,25 @@ namespace Content.Server.GameObjects.Components.Atmos
return newAirBlockedDirs;
}
/// <inheritdoc />
public void MapInit()
{
if (Owner.TryGetComponent(out SnapGridComponent? snapGrid))
if (Owner.Transform.Anchored)
{
snapGrid.OnPositionChanged += OnTransformMove;
_lastPosition = (Owner.Transform.GridID, snapGrid.Position);
var grid = _mapManager.GetGrid(Owner.Transform.GridID);
_lastPosition = (Owner.Transform.GridID, grid.TileIndicesFor(Owner.Transform.Coordinates));
}
UpdatePosition();
}
/// <inheritdoc />
protected override void Shutdown()
{
base.Shutdown();
_airBlocked = false;
if (Owner.TryGetComponent(out SnapGridComponent? snapGrid))
{
snapGrid.OnPositionChanged -= OnTransformMove;
}
UpdatePosition(_lastPosition.Item1, _lastPosition.Item2);
if (_fixVacuum)
@@ -146,21 +146,25 @@ namespace Content.Server.GameObjects.Components.Atmos
}
}
private void OnTransformMove()
public void OnTransformMove()
{
UpdatePosition(_lastPosition.Item1, _lastPosition.Item2);
UpdatePosition();
if (Owner.TryGetComponent(out SnapGridComponent? snapGrid))
if (Owner.Transform.Anchored)
{
_lastPosition = (Owner.Transform.GridID, snapGrid.Position);
var grid = _mapManager.GetGrid(Owner.Transform.GridID);
_lastPosition = (Owner.Transform.GridID, grid.TileIndicesFor(Owner.Transform.Coordinates));
}
}
private void UpdatePosition()
{
if (Owner.TryGetComponent(out SnapGridComponent? snapGrid))
UpdatePosition(Owner.Transform.GridID, snapGrid.Position);
if (Owner.Transform.Anchored)
{
var grid = _mapManager.GetGrid(Owner.Transform.GridID);
UpdatePosition(Owner.Transform.GridID, grid.TileIndicesFor(Owner.Transform.Coordinates));
}
}
private void UpdatePosition(GridId gridId, Vector2i pos)

View File

@@ -1,5 +1,6 @@
#nullable enable
using System;
using System.Collections.Generic;
using System.Linq;
using Content.Server.Atmos;
using Content.Server.GameObjects.Components.Atmos.Piping;
@@ -11,6 +12,8 @@ using Content.Shared.GameObjects.EntitySystems.ActionBlocker;
using Content.Shared.Interfaces.GameObjects.Components;
using Robust.Server.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.ViewVariables;
using Robust.Shared.Physics;
@@ -24,6 +27,8 @@ namespace Content.Server.GameObjects.Components.Atmos
[ComponentReference(typeof(IActivate))]
public class GasCanisterComponent : Component, IGasMixtureHolder, IActivate
{
[Dependency] private readonly IMapManager _mapManager = default!;
public override string Name => "GasCanister";
private const int MaxLabelLength = 32;
@@ -114,9 +119,11 @@ namespace Content.Server.GameObjects.Components.Atmos
public void TryConnectToPort()
{
if (!Owner.TryGetComponent<SnapGridComponent>(out var snapGrid)) return;
var port = snapGrid.GetLocal()
.Select(entity => entity.TryGetComponent<GasCanisterPortComponent>(out var port) ? port : null)
if (!Owner.Transform.Anchored) return;
var grid = _mapManager.GetGrid(Owner.Transform.GridID);
var coords = Owner.Transform.Coordinates;
var port = grid.GetLocal(coords)
.Select(entity => Owner.EntityManager.ComponentManager.TryGetComponent<GasCanisterPortComponent>(entity, out var port) ? port : null)
.Where(port => port != null)
.Where(port => !port!.ConnectedToCanister)
.FirstOrDefault();

View File

@@ -1,9 +1,12 @@
#nullable enable
using System.Collections.Generic;
using System.Linq;
using Content.Server.GameObjects.Components.NodeContainer;
using Content.Server.GameObjects.Components.NodeContainer.Nodes;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Log;
using Robust.Shared.Map;
using Robust.Shared.ViewVariables;
namespace Content.Server.GameObjects.Components.Atmos.Piping
@@ -13,6 +16,8 @@ namespace Content.Server.GameObjects.Components.Atmos.Piping
{
public override string Name => "GasCanisterPort";
[Dependency] private readonly IMapManager _mapManager = default!;
[ViewVariables]
public GasCanisterComponent? ConnectedCanister { get; private set; }
@@ -27,12 +32,14 @@ namespace Content.Server.GameObjects.Components.Atmos.Piping
base.Initialize();
Owner.EnsureComponentWarn<PipeNetDeviceComponent>();
SetGasPort();
if (Owner.TryGetComponent<SnapGridComponent>(out var snapGrid))
if (Owner.Transform.Anchored)
{
var entities = snapGrid.GetLocal();
var grid = _mapManager.GetGrid(Owner.Transform.GridID);
var coords = Owner.Transform.Coordinates;
var entities = grid.GetLocal(coords);
foreach (var entity in entities)
{
if (entity.TryGetComponent<GasCanisterComponent>(out var canister) && canister.Anchored && !canister.ConnectedToPort)
if (Owner.EntityManager.ComponentManager.TryGetComponent<GasCanisterComponent>(entity, out var canister) && canister.Anchored && !canister.ConnectedToPort)
{
canister.TryConnectToPort();
break;

View File

@@ -1,11 +1,10 @@
#nullable enable
#nullable enable
using System;
using System.Linq;
using Content.Server.GameObjects.Components.Atmos;
using Content.Server.Utility;
using Content.Shared.Chemistry;
using Content.Shared.GameObjects.EntitySystems;
using Content.Shared.Interfaces.GameObjects.Components;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Log;
@@ -24,7 +23,6 @@ namespace Content.Server.GameObjects.Components.Chemistry
[Dependency] protected readonly IMapManager MapManager = default!;
[Dependency] protected readonly IPrototypeManager PrototypeManager = default!;
[ComponentDependency] protected readonly SnapGridComponent? SnapGridComponent = default!;
[ComponentDependency] protected readonly SolutionContainerComponent? SolutionContainerComponent = default!;
public int Amount { get; set; }
public SolutionAreaEffectInceptionComponent? Inception { get; set; }
@@ -63,26 +61,20 @@ namespace Content.Server.GameObjects.Components.Chemistry
return;
}
if (SnapGridComponent == null)
{
Logger.Error("AreaEffectComponent attached to " + Owner.Prototype.ID +
" couldn't get SnapGridComponent from owner.");
return;
}
void SpreadToDir(Direction dir)
{
foreach (var neighbor in SnapGridComponent.GetInDir(dir))
var grid = MapManager.GetGrid(Owner.Transform.GridID);
var coords = Owner.Transform.Coordinates;
foreach (var neighbor in grid.GetInDir(coords, dir))
{
if (neighbor.TryGetComponent(out SolutionAreaEffectComponent? comp) && comp.Inception == Inception)
if (Owner.EntityManager.ComponentManager.TryGetComponent(neighbor, out SolutionAreaEffectComponent? comp) && comp.Inception == Inception)
return;
if (neighbor.TryGetComponent(out AirtightComponent? airtight) && airtight.AirBlocked)
if (Owner.EntityManager.ComponentManager.TryGetComponent(neighbor, out AirtightComponent? airtight) && airtight.AirBlocked)
return;
}
var newEffect =
Owner.EntityManager.SpawnEntity(Owner.Prototype.ID, SnapGridComponent.DirectionToGrid(dir));
var newEffect = Owner.EntityManager.SpawnEntity(Owner.Prototype.ID, grid.DirectionToGrid(coords, dir));
if (!newEffect.TryGetComponent(out SolutionAreaEffectComponent? effectComponent))
{

View File

@@ -26,6 +26,7 @@ using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Log;
using Robust.Shared.Map;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.Physics;
using Robust.Shared.Player;
@@ -43,6 +44,7 @@ namespace Content.Server.GameObjects.Components.Disposal
public class DisposalMailingUnitComponent : SharedDisposalMailingUnitComponent, IInteractHand, IActivate, IInteractUsing, IDragDropOn
{
[Dependency] private readonly IGameTiming _gameTiming = default!;
[Dependency] private readonly IMapManager _mapManager = default!;
private const string HolderPrototypeId = "DisposalHolder";
@@ -277,17 +279,17 @@ namespace Content.Server.GameObjects.Components.Disposal
return false;
}
var snapGrid = Owner.GetComponent<SnapGridComponent>();
var entry = snapGrid
.GetLocal()
.FirstOrDefault(entity => entity.HasComponent<DisposalEntryComponent>());
var grid = _mapManager.GetGrid(Owner.Transform.GridID);
var coords = Owner.Transform.Coordinates;
var entry = grid.GetLocal(coords)
.FirstOrDefault(entity => Owner.EntityManager.ComponentManager.HasComponent<DisposalEntryComponent>(entity));
if (entry == null)
if (entry == default)
{
return false;
}
var entryComponent = entry.GetComponent<DisposalEntryComponent>();
var entryComponent = Owner.EntityManager.ComponentManager.GetComponent<DisposalEntryComponent>(entry);
var entities = _container.ContainedEntities.ToList();
foreach (var entity in _container.ContainedEntities.ToList())
{

View File

@@ -1,5 +1,6 @@
#nullable enable
using System;
using System.Collections.Generic;
using System.Linq;
using Content.Shared.GameObjects.Components.Disposal;
using Content.Shared.GameObjects.EntitySystems;
@@ -12,6 +13,7 @@ using Robust.Shared.Containers;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Player;
using Robust.Shared.Prototypes;
@@ -26,6 +28,7 @@ namespace Content.Server.GameObjects.Components.Disposal
public abstract class DisposalTubeComponent : Component, IDisposalTubeComponent, IBreakAct
{
[Dependency] private readonly IGameTiming _gameTiming = default!;
[Dependency] private readonly IMapManager _mapManager = default!;
private static readonly TimeSpan ClangDelay = TimeSpan.FromSeconds(0.5);
private TimeSpan _lastClang;
@@ -67,12 +70,13 @@ namespace Content.Server.GameObjects.Components.Disposal
public IDisposalTubeComponent? NextTube(DisposalHolderComponent holder)
{
var nextDirection = NextDirection(holder);
var snapGrid = Owner.GetComponent<SnapGridComponent>();
var oppositeDirection = new Angle(nextDirection.ToAngle().Theta + Math.PI).GetDir();
foreach (var entity in snapGrid.GetInDir(nextDirection))
var grid = _mapManager.GetGrid(Owner.Transform.GridID);
var position = Owner.Transform.Coordinates;
foreach (var entity in grid.GetInDir(position, nextDirection))
{
if (!entity.TryGetComponent(out IDisposalTubeComponent? tube))
if (!Owner.EntityManager.ComponentManager.TryGetComponent(entity, out IDisposalTubeComponent? tube))
{
continue;
}

View File

@@ -28,6 +28,7 @@ using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Log;
using Robust.Shared.Map;
using Robust.Shared.Physics;
using Robust.Shared.Player;
using Robust.Shared.Random;
@@ -44,6 +45,7 @@ namespace Content.Server.GameObjects.Components.Disposal
public class DisposalUnitComponent : SharedDisposalUnitComponent, IInteractHand, IActivate, IInteractUsing, IThrowCollide, IGasMixtureHolder
{
[Dependency] private readonly IGameTiming _gameTiming = default!;
[Dependency] private readonly IMapManager _mapManager = default!;
public override string Name => "DisposalUnit";
@@ -260,17 +262,17 @@ namespace Content.Server.GameObjects.Components.Disposal
return false;
}
var snapGrid = Owner.GetComponent<SnapGridComponent>();
var entry = snapGrid
.GetLocal()
.FirstOrDefault(entity => entity.HasComponent<DisposalEntryComponent>());
var grid = _mapManager.GetGrid(Owner.Transform.GridID);
var coords = Owner.Transform.Coordinates;
var entry = grid.GetLocal(coords)
.FirstOrDefault(entity => Owner.EntityManager.ComponentManager.HasComponent<DisposalEntryComponent>(entity));
if (entry == null)
if (entry == default)
{
return false;
}
var entryComponent = entry.GetComponent<DisposalEntryComponent>();
var entryComponent = Owner.EntityManager.ComponentManager.GetComponent<DisposalEntryComponent>(entry);
if (Owner.Transform.Coordinates.TryGetTileAtmosphere(out var tileAtmos) &&
tileAtmos.Air != null &&

View File

@@ -78,7 +78,6 @@ namespace Content.Server.GameObjects.Components.Fluids
private bool _overflown;
private SpriteComponent _spriteComponent = default!;
private SnapGridComponent _snapGrid = default!;
public ReagentUnit MaxVolume
{
@@ -112,7 +111,6 @@ namespace Content.Server.GameObjects.Components.Fluids
base.Initialize();
_contents = Owner.EnsureComponentWarn<SolutionContainerComponent>();
_snapGrid = Owner.EnsureComponent<SnapGridComponent>();
// Smaller than 1m^3 for now but realistically this shouldn't be hit
MaxVolume = ReagentUnit.New(1000);
@@ -348,8 +346,9 @@ namespace Content.Server.GameObjects.Components.Fluids
puddle = default;
var mapGrid = _mapManager.GetGrid(Owner.Transform.GridID);
var coords = Owner.Transform.Coordinates;
if (!Owner.Transform.Coordinates.Offset(direction).TryGetTileRef(out var tile))
if (!coords.Offset(direction).TryGetTileRef(out var tile))
{
return false;
}
@@ -360,16 +359,19 @@ namespace Content.Server.GameObjects.Components.Fluids
return false;
}
foreach (var entity in _snapGrid.GetInDir(direction))
if (!Owner.Transform.Anchored)
return false;
foreach (var entity in mapGrid.GetInDir(coords, direction))
{
if (entity.TryGetComponent(out IPhysBody? physics) &&
if (Owner.EntityManager.ComponentManager.TryGetComponent(entity, out IPhysBody? physics) &&
(physics.CollisionLayer & (int) CollisionGroup.Impassable) != 0)
{
puddle = default;
return false;
}
if (entity.TryGetComponent(out PuddleComponent? existingPuddle))
if (Owner.EntityManager.ComponentManager.TryGetComponent(entity, out PuddleComponent? existingPuddle))
{
if (existingPuddle._overflown)
{
@@ -382,8 +384,7 @@ namespace Content.Server.GameObjects.Components.Fluids
if (puddle == default)
{
var grid = _snapGrid.DirectionToGrid(direction);
puddle = () => Owner.EntityManager.SpawnEntity(Owner.Prototype?.ID, grid).GetComponent<PuddleComponent>();
puddle = () => Owner.EntityManager.SpawnEntity(Owner.Prototype?.ID, mapGrid.DirectionToGrid(coords, direction)).GetComponent<PuddleComponent>();
}
return true;

View File

@@ -101,7 +101,7 @@ namespace Content.Server.GameObjects.Components.Items.RCD
var mapGrid = _mapManager.GetGrid(eventArgs.ClickLocation.GetGridId(Owner.EntityManager));
var tile = mapGrid.GetTileRef(eventArgs.ClickLocation);
var snapPos = mapGrid.SnapGridCellFor(eventArgs.ClickLocation, SnapGridOffset.Center);
var snapPos = mapGrid.TileIndicesFor(eventArgs.ClickLocation);
//Using an RCD isn't instantaneous
var cancelToken = new CancellationTokenSource();

View File

@@ -8,6 +8,7 @@ using Content.Server.GameObjects.Components.Power.AME;
using Robust.Shared.GameObjects;
using Robust.Shared.Random;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.ViewVariables;
namespace Content.Server.GameObjects.Components.NodeContainer.NodeGroups
@@ -68,12 +69,13 @@ namespace Content.Server.GameObjects.Components.NodeContainer.NodeGroups
//Check each shield node to see if it meets core criteria
foreach (Node node in Nodes)
{
if (!node.Owner.TryGetComponent<AMEShieldComponent>(out var shield)) { continue; }
var nodeNeighbors = node.Owner
.GetComponent<SnapGridComponent>()
.GetCellsInSquareArea()
.Select(sgc => sgc.Owner)
.Where(entity => entity != node.Owner)
var nodeOwner = node.Owner;
if (!nodeOwner.TryGetComponent<AMEShieldComponent>(out var shield)) { continue; }
var grid = IoCManager.Resolve<IMapManager>().GetGrid(nodeOwner.Transform.GridID);
var nodeNeighbors = grid.GetCellsInSquareArea(nodeOwner.Transform.Coordinates, 1)
.Select(sgc => nodeOwner.EntityManager.GetEntity(sgc))
.Where(entity => entity != nodeOwner)
.Select(entity => entity.TryGetComponent<AMEShieldComponent>(out var adjshield) ? adjshield : null)
.Where(adjshield => adjshield != null);

View File

@@ -1,6 +1,7 @@
#nullable enable
using System.Collections.Generic;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Serialization.Manager.Attributes;
namespace Content.Server.GameObjects.Components.NodeContainer.Nodes
@@ -13,22 +14,27 @@ namespace Content.Server.GameObjects.Components.NodeContainer.Nodes
{
protected override IEnumerable<Node> GetReachableNodes()
{
if (!Owner.TryGetComponent(out SnapGridComponent? snap))
if (!Owner.Transform.Anchored)
yield break;
foreach (var cell in snap.GetCardinalNeighborCells())
foreach (var entity in cell.GetLocal())
var grid = IoCManager.Resolve<IMapManager>().GetGrid(Owner.Transform.GridID);
var coords = Owner.Transform.Coordinates;
foreach (var cell in grid.GetCardinalNeighborCells(coords))
{
if (!entity.TryGetComponent<NodeContainerComponent>(out var container)) continue;
foreach (var node in container.Nodes.Values)
foreach (var entity in grid.GetLocal(Owner.EntityManager.GetEntity(cell).Transform.Coordinates))
{
if (node != null && node != this)
{
yield return node;
}
}
if (!Owner.EntityManager.GetEntity(entity).TryGetComponent<NodeContainerComponent>(out var container))
continue;
foreach (var node in container.Nodes.Values)
{
if (node != null && node != this)
{
yield return node;
}
}
}
}
}
}

View File

@@ -6,6 +6,8 @@ using Content.Server.Interfaces;
using Content.Shared.GameObjects.Components.Atmos;
using Robust.Server.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.ViewVariables;
@@ -169,14 +171,14 @@ namespace Content.Server.GameObjects.Components.NodeContainer.Nodes
/// </summary>
private IEnumerable<PipeNode> PipesInDirection(PipeDirection pipeDir)
{
if (!Owner.TryGetComponent(out SnapGridComponent? grid))
if (!Owner.Transform.Anchored)
yield break;
var entities = grid.GetInDir(pipeDir.ToDirection());
foreach (var entity in entities)
var grid = IoCManager.Resolve<IMapManager>().GetGrid(Owner.Transform.GridID);
var position = Owner.Transform.Coordinates;
foreach (var entity in grid.GetInDir(position, pipeDir.ToDirection()))
{
if (!entity.TryGetComponent<NodeContainerComponent>(out var container))
if (!Owner.EntityManager.ComponentManager.TryGetComponent<NodeContainerComponent>(entity, out var container))
continue;
foreach (var node in container.Nodes.Values)

View File

@@ -13,8 +13,10 @@ using Content.Shared.GameObjects.EntitySystems.ActionBlocker;
using Content.Shared.Interfaces.GameObjects.Components;
using Robust.Server.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Log;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
@@ -36,6 +38,8 @@ namespace Content.Server.GameObjects.Components.PA
[RegisterComponent]
public class ParticleAcceleratorControlBoxComponent : ParticleAcceleratorPartComponent, IActivate, IWires
{
[Dependency] private readonly IMapManager _mapManager = default!;
public override string Name => "ParticleAcceleratorControlBox";
[ViewVariables]
@@ -378,11 +382,13 @@ namespace Content.Server.GameObjects.Components.PA
_partEmitterRight = null;
// Find fuel chamber first by scanning cardinals.
if (SnapGrid != null)
if (Owner.Transform.Anchored)
{
foreach (var maybeFuel in SnapGrid.GetCardinalNeighborCells())
var grid = _mapManager.GetGrid(Owner.Transform.GridID);
var coords = Owner.Transform.Coordinates;
foreach (var maybeFuel in grid.GetCardinalNeighborCells(coords))
{
if (maybeFuel.Owner.TryGetComponent(out _partFuelChamber))
if (Owner.EntityManager.ComponentManager.TryGetComponent(maybeFuel, out _partFuelChamber))
{
break;
}
@@ -452,9 +458,11 @@ namespace Content.Server.GameObjects.Components.PA
private bool ScanPart<T>(Vector2i offset, [NotNullWhen(true)] out T? part)
where T : ParticleAcceleratorPartComponent
{
foreach (var ent in SnapGrid!.GetOffset(offset))
var grid = _mapManager.GetGrid(Owner.Transform.GridID);
var coords = Owner.Transform.Coordinates;
foreach (var ent in grid.GetOffset(coords, offset))
{
if (ent.TryGetComponent(out part) && !part.Deleted)
if (Owner.EntityManager.ComponentManager.TryGetComponent(ent, out part) && !part.Deleted)
{
return true;
}

View File

@@ -1,6 +1,5 @@
#nullable enable
using Robust.Shared.GameObjects;
using Robust.Shared.Log;
using Robust.Shared.ViewVariables;
namespace Content.Server.GameObjects.Components.PA
@@ -8,14 +7,13 @@ namespace Content.Server.GameObjects.Components.PA
public abstract class ParticleAcceleratorPartComponent : Component
{
[ViewVariables] public ParticleAcceleratorControlBoxComponent? Master;
[ViewVariables] protected SnapGridComponent? SnapGrid;
public override void Initialize()
{
base.Initialize();
// FIXME: this has to be an entity system, full stop.
Owner.EnsureComponent<SnapGridComponent>(out SnapGrid);
Owner.Transform.Anchored = true;
}
public override void HandleMessage(ComponentMessage message, IComponent? component)

View File

@@ -40,8 +40,8 @@ namespace Content.Server.GameObjects.Components.Power.AME
if (!_mapManager.TryGetGrid(args.ClickLocation.GetGridId(_serverEntityManager), out var mapGrid))
return false; // No AME in space.
var snapPos = mapGrid.SnapGridCellFor(args.ClickLocation, SnapGridOffset.Center);
if (mapGrid.GetSnapGridCell(snapPos, SnapGridOffset.Center).Any(sc => sc.Owner.HasComponent<AMEShieldComponent>()))
var snapPos = mapGrid.TileIndicesFor(args.ClickLocation);
if (mapGrid.GetAnchoredEntities(snapPos).Any(sc => _serverEntityManager.ComponentManager.HasComponent<AMEShieldComponent>(sc)))
{
Owner.PopupMessage(args.User, Loc.GetString("Shielding is already there!"));
return true;

View File

@@ -1,4 +1,5 @@
#nullable enable
using System.Collections.Generic;
using Content.Server.GameObjects.Components.Stack;
using Content.Shared.Interfaces.GameObjects.Components;
using Content.Shared.Utility;
@@ -38,13 +39,12 @@ namespace Content.Server.GameObjects.Components.Power
return true;
if(!_mapManager.TryGetGrid(eventArgs.ClickLocation.GetGridId(Owner.EntityManager), out var grid))
return true;
var snapPos = grid.SnapGridCellFor(eventArgs.ClickLocation, SnapGridOffset.Center);
var snapCell = grid.GetSnapGridCell(snapPos, SnapGridOffset.Center);
var snapPos = grid.TileIndicesFor(eventArgs.ClickLocation);
if(grid.GetTileRef(snapPos).Tile.IsEmpty)
return true;
foreach (var snapComp in snapCell)
foreach (var anchored in grid.GetAnchoredEntities(snapPos))
{
if (snapComp.Owner.TryGetComponent<WireComponent>(out var wire) && wire.WireType == _blockingWireType)
if (Owner.EntityManager.ComponentManager.TryGetComponent<WireComponent>(anchored, out var wire) && wire.WireType == _blockingWireType)
{
return true;
}