Remove 700 usages of Component.Owner (#21100)
This commit is contained in:
@@ -4,7 +4,6 @@ using Content.Shared.Atmos;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Map.Components;
|
||||
using Content.Shared.Destructible;
|
||||
|
||||
namespace Content.Server.Atmos.EntitySystems
|
||||
{
|
||||
@@ -24,31 +23,32 @@ namespace Content.Server.Atmos.EntitySystems
|
||||
SubscribeLocalEvent<AirtightComponent, MoveEvent>(OnAirtightMoved);
|
||||
}
|
||||
|
||||
private void OnAirtightInit(EntityUid uid, AirtightComponent airtight, ComponentInit args)
|
||||
private void OnAirtightInit(Entity<AirtightComponent> airtight, ref ComponentInit args)
|
||||
{
|
||||
var xform = EntityManager.GetComponent<TransformComponent>(uid);
|
||||
var xform = EntityManager.GetComponent<TransformComponent>(airtight);
|
||||
|
||||
if (airtight.FixAirBlockedDirectionInitialize)
|
||||
if (airtight.Comp.FixAirBlockedDirectionInitialize)
|
||||
{
|
||||
var moveEvent = new MoveEvent(uid, default, default, Angle.Zero, xform.LocalRotation, xform, false);
|
||||
if (AirtightMove(uid, airtight, ref moveEvent))
|
||||
var moveEvent = new MoveEvent(airtight, default, default, Angle.Zero, xform.LocalRotation, xform, false);
|
||||
if (AirtightMove(airtight, ref moveEvent))
|
||||
return;
|
||||
}
|
||||
|
||||
UpdatePosition(airtight);
|
||||
}
|
||||
|
||||
private void OnAirtightShutdown(EntityUid uid, AirtightComponent airtight, ComponentShutdown args)
|
||||
private void OnAirtightShutdown(Entity<AirtightComponent> airtight, ref ComponentShutdown args)
|
||||
{
|
||||
var xform = Transform(uid);
|
||||
var xform = Transform(airtight);
|
||||
|
||||
// If the grid is deleting no point updating atmos.
|
||||
if (_mapManager.TryGetGrid(xform.GridUid, out var grid))
|
||||
if (HasComp<MapGridComponent>(xform.GridUid) &&
|
||||
MetaData(xform.GridUid.Value).EntityLifeStage > EntityLifeStage.MapInitialized)
|
||||
{
|
||||
if (MetaData(grid.Owner).EntityLifeStage > EntityLifeStage.MapInitialized) return;
|
||||
return;
|
||||
}
|
||||
|
||||
SetAirblocked(uid, airtight, false, xform);
|
||||
SetAirblocked(airtight, false, xform);
|
||||
}
|
||||
|
||||
private void OnAirtightPositionChanged(EntityUid uid, AirtightComponent airtight, ref AnchorStateChangedEvent args)
|
||||
@@ -78,44 +78,47 @@ namespace Content.Server.Atmos.EntitySystems
|
||||
}
|
||||
}
|
||||
|
||||
private void OnAirtightMoved(EntityUid uid, AirtightComponent airtight, ref MoveEvent ev)
|
||||
private void OnAirtightMoved(Entity<AirtightComponent> airtight, ref MoveEvent ev)
|
||||
{
|
||||
AirtightMove(uid, airtight, ref ev);
|
||||
AirtightMove(airtight, ref ev);
|
||||
}
|
||||
|
||||
private bool AirtightMove(EntityUid uid, AirtightComponent airtight, ref MoveEvent ev)
|
||||
private bool AirtightMove(Entity<AirtightComponent> ent, ref MoveEvent ev)
|
||||
{
|
||||
var (owner, airtight) = ent;
|
||||
if (!airtight.RotateAirBlocked || airtight.InitialAirBlockedDirection == (int)AtmosDirection.Invalid)
|
||||
return false;
|
||||
|
||||
airtight.CurrentAirBlockedDirection = (int) Rotate((AtmosDirection)airtight.InitialAirBlockedDirection, ev.NewRotation);
|
||||
var pos = airtight.LastPosition;
|
||||
UpdatePosition(airtight, ev.Component);
|
||||
var airtightEv = new AirtightChanged(uid, airtight, pos);
|
||||
RaiseLocalEvent(uid, ref airtightEv, true);
|
||||
UpdatePosition(ent, ev.Component);
|
||||
var airtightEv = new AirtightChanged(owner, airtight, pos);
|
||||
RaiseLocalEvent(owner, ref airtightEv, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void SetAirblocked(EntityUid uid, AirtightComponent airtight, bool airblocked, TransformComponent? xform = null)
|
||||
public void SetAirblocked(Entity<AirtightComponent> airtight, bool airblocked, TransformComponent? xform = null)
|
||||
{
|
||||
if (airtight.AirBlocked == airblocked)
|
||||
if (airtight.Comp.AirBlocked == airblocked)
|
||||
return;
|
||||
|
||||
if (!Resolve(uid, ref xform))
|
||||
if (!Resolve(airtight, ref xform))
|
||||
return;
|
||||
|
||||
var pos = airtight.LastPosition;
|
||||
airtight.AirBlocked = airblocked;
|
||||
var pos = airtight.Comp.LastPosition;
|
||||
airtight.Comp.AirBlocked = airblocked;
|
||||
UpdatePosition(airtight, xform);
|
||||
var airtightEv = new AirtightChanged(uid, airtight, pos);
|
||||
RaiseLocalEvent(uid, ref airtightEv, true);
|
||||
var airtightEv = new AirtightChanged(airtight, airtight, pos);
|
||||
RaiseLocalEvent(airtight, ref airtightEv, true);
|
||||
}
|
||||
|
||||
public void UpdatePosition(AirtightComponent airtight, TransformComponent? xform = null)
|
||||
public void UpdatePosition(Entity<AirtightComponent> ent, TransformComponent? xform = null)
|
||||
{
|
||||
if (!Resolve(airtight.Owner, ref xform)) return;
|
||||
var (owner, airtight) = ent;
|
||||
if (!Resolve(owner, ref xform))
|
||||
return;
|
||||
|
||||
if (!xform.Anchored || !_mapManager.TryGetGrid(xform.GridUid, out var grid))
|
||||
if (!xform.Anchored || !TryComp(xform.GridUid, out MapGridComponent? grid))
|
||||
return;
|
||||
|
||||
airtight.LastPosition = (xform.GridUid.Value, grid.TileIndicesFor(xform.Coordinates));
|
||||
@@ -124,15 +127,13 @@ namespace Content.Server.Atmos.EntitySystems
|
||||
|
||||
public void InvalidatePosition(EntityUid gridId, Vector2i pos, bool fixVacuum = false)
|
||||
{
|
||||
if (!_mapManager.TryGetGrid(gridId, out var grid))
|
||||
if (!TryComp(gridId, out MapGridComponent? grid))
|
||||
return;
|
||||
|
||||
var gridUid = grid.Owner;
|
||||
|
||||
var query = EntityManager.GetEntityQuery<AirtightComponent>();
|
||||
_explosionSystem.UpdateAirtightMap(gridId, pos, grid, query);
|
||||
// TODO make atmos system use query
|
||||
_atmosphereSystem.InvalidateTile(gridUid, pos);
|
||||
_atmosphereSystem.InvalidateTile(gridId, pos);
|
||||
}
|
||||
|
||||
private AtmosDirection Rotate(AtmosDirection myDirection, Angle myAngle)
|
||||
@@ -146,7 +147,8 @@ namespace Content.Server.Atmos.EntitySystems
|
||||
for (var i = 0; i < Atmospherics.Directions; i++)
|
||||
{
|
||||
var direction = (AtmosDirection) (1 << i);
|
||||
if (!myDirection.IsFlagSet(direction)) continue;
|
||||
if (!myDirection.IsFlagSet(direction))
|
||||
continue;
|
||||
var angle = direction.ToAngle();
|
||||
angle += myAngle;
|
||||
newAirBlockedDirs |= angle.ToAtmosDirectionCardinal();
|
||||
|
||||
Reference in New Issue
Block a user