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,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)
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user