Construction spring cleaning (#36163)
* Construction warnings cleanup * More construction warnings cleanup * Fix failing ITests - Remove unnecessary casts and dodgy anchroing implementation. * Checking anchor status before setting * Reusing shared system call * inlining anchor setting
This commit is contained in:
@@ -2,11 +2,8 @@ using Content.Server.Hands.Systems;
|
|||||||
using Content.Shared.Construction;
|
using Content.Shared.Construction;
|
||||||
using Content.Shared.Hands.Components;
|
using Content.Shared.Hands.Components;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using Robust.Server.Containers;
|
|
||||||
using Robust.Server.GameObjects;
|
using Robust.Server.GameObjects;
|
||||||
using Robust.Shared.Containers;
|
using Robust.Shared.Containers;
|
||||||
using Robust.Shared.GameObjects;
|
|
||||||
using Robust.Shared.Map;
|
|
||||||
|
|
||||||
namespace Content.Server.Construction.Completions
|
namespace Content.Server.Construction.Completions
|
||||||
{
|
{
|
||||||
@@ -31,14 +28,14 @@ namespace Content.Server.Construction.Completions
|
|||||||
if (!entityManager.TryGetComponent(uid, out ContainerManagerComponent? containerManager))
|
if (!entityManager.TryGetComponent(uid, out ContainerManagerComponent? containerManager))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var containerSys = entityManager.EntitySysManager.GetEntitySystem<ContainerSystem>();
|
var containerSys = entityManager.EntitySysManager.GetEntitySystem<SharedContainerSystem>();
|
||||||
var handSys = entityManager.EntitySysManager.GetEntitySystem<HandsSystem>();
|
var handSys = entityManager.EntitySysManager.GetEntitySystem<HandsSystem>();
|
||||||
var transformSys = entityManager.EntitySysManager.GetEntitySystem<TransformSystem>();
|
var transformSys = entityManager.EntitySysManager.GetEntitySystem<TransformSystem>();
|
||||||
|
|
||||||
HandsComponent? hands = null;
|
HandsComponent? hands = null;
|
||||||
var pickup = Pickup && entityManager.TryGetComponent(userUid, out hands);
|
var pickup = Pickup && entityManager.TryGetComponent(userUid, out hands);
|
||||||
|
|
||||||
foreach (var container in containerManager.GetAllContainers())
|
foreach (var container in containerSys.GetAllContainers(uid))
|
||||||
{
|
{
|
||||||
foreach (var ent in containerSys.EmptyContainer(container, true, reparent: !pickup))
|
foreach (var ent in containerSys.EmptyContainer(container, true, reparent: !pickup))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -21,10 +21,11 @@ namespace Content.Server.Construction.Completions
|
|||||||
|
|
||||||
public void PerformAction(EntityUid uid, EntityUid? userUid, IEntityManager entityManager)
|
public void PerformAction(EntityUid uid, EntityUid? userUid, IEntityManager entityManager)
|
||||||
{
|
{
|
||||||
if (!entityManager.TryGetComponent(uid, out ContainerManagerComponent? containerManager) ||
|
var containerSys = entityManager.EntitySysManager.GetEntitySystem<SharedContainerSystem>();
|
||||||
!containerManager.TryGetContainer(Container, out var container)) return;
|
|
||||||
|
if (!entityManager.TryGetComponent(uid, out ContainerManagerComponent? containerManager) ||
|
||||||
|
!containerSys.TryGetContainer(uid, Container, out var container, containerManager)) return;
|
||||||
|
|
||||||
var containerSys = entityManager.EntitySysManager.GetEntitySystem<ContainerSystem>();
|
|
||||||
var handSys = entityManager.EntitySysManager.GetEntitySystem<HandsSystem>();
|
var handSys = entityManager.EntitySysManager.GetEntitySystem<HandsSystem>();
|
||||||
|
|
||||||
HandsComponent? hands = null;
|
HandsComponent? hands = null;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using Content.Shared.Construction;
|
using Content.Shared.Construction;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
|
|
||||||
namespace Content.Server.Construction.Completions
|
namespace Content.Server.Construction.Completions
|
||||||
@@ -12,7 +12,17 @@ namespace Content.Server.Construction.Completions
|
|||||||
public void PerformAction(EntityUid uid, EntityUid? userUid, IEntityManager entityManager)
|
public void PerformAction(EntityUid uid, EntityUid? userUid, IEntityManager entityManager)
|
||||||
{
|
{
|
||||||
var transform = entityManager.GetComponent<TransformComponent>(uid);
|
var transform = entityManager.GetComponent<TransformComponent>(uid);
|
||||||
transform.Anchored = Value;
|
|
||||||
|
if (transform.Anchored == Value)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var sys = entityManager.System<SharedTransformSystem>();
|
||||||
|
|
||||||
|
if (Value)
|
||||||
|
sys.AnchorEntity(uid, transform);
|
||||||
|
else
|
||||||
|
sys.Unanchor(uid, transform);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ namespace Content.Server.Construction.Completions
|
|||||||
var transform = entityManager.GetComponent<TransformComponent>(uid);
|
var transform = entityManager.GetComponent<TransformComponent>(uid);
|
||||||
|
|
||||||
if (!transform.Anchored)
|
if (!transform.Anchored)
|
||||||
transform.Coordinates = transform.Coordinates.SnapToGrid(entityManager);
|
entityManager.System<SharedTransformSystem>().SetCoordinates(uid, transform.Coordinates.SnapToGrid(entityManager));
|
||||||
|
|
||||||
if (SouthRotation)
|
if (SouthRotation)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using Content.Shared.Construction;
|
using Content.Shared.Construction;
|
||||||
using Content.Shared.Examine;
|
using Content.Shared.Examine;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using Robust.Server.Containers;
|
using Robust.Server.Containers;
|
||||||
@@ -39,8 +39,9 @@ namespace Content.Server.Construction.Conditions
|
|||||||
|
|
||||||
var entity = args.Examined;
|
var entity = args.Examined;
|
||||||
|
|
||||||
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(entity, out ContainerManagerComponent? containerManager) ||
|
var entityManager = IoCManager.Resolve<IEntityManager>();
|
||||||
!containerManager.TryGetContainer(Container, out var container)) return false;
|
if (!entityManager.TryGetComponent(entity, out ContainerManagerComponent? containerManager) ||
|
||||||
|
!entityManager.System<SharedContainerSystem>().TryGetContainer(entity, Container, out var container, containerManager)) return false;
|
||||||
|
|
||||||
if (container.ContainedEntities.Count == 0)
|
if (container.ContainedEntities.Count == 0)
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -32,8 +32,9 @@ namespace Content.Server.Construction.Conditions
|
|||||||
|
|
||||||
var entity = args.Examined;
|
var entity = args.Examined;
|
||||||
|
|
||||||
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(entity, out ContainerManagerComponent? containerManager) ||
|
var entityManager = IoCManager.Resolve<IEntityManager>();
|
||||||
!containerManager.TryGetContainer(Container, out var container)) return false;
|
if (!entityManager.TryGetComponent(entity, out ContainerManagerComponent? containerManager) ||
|
||||||
|
!entityManager.System<SharedContainerSystem>().TryGetContainer(entity, Container, out var container, containerManager)) return false;
|
||||||
|
|
||||||
if (container.ContainedEntities.Count != 0)
|
if (container.ContainedEntities.Count != 0)
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -66,10 +66,10 @@ namespace Content.Server.Construction
|
|||||||
if (!Resolve(uid, ref construction, false))
|
if (!Resolve(uid, ref construction, false))
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
if (construction.Node is not {} nodeIdentifier)
|
if (construction.Node is not { } nodeIdentifier)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
return GetCurrentGraph(uid, construction) is not {} graph ? null : GetNodeFromGraph(graph, nodeIdentifier);
|
return GetCurrentGraph(uid, construction) is not { } graph ? null : GetNodeFromGraph(graph, nodeIdentifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -85,10 +85,10 @@ namespace Content.Server.Construction
|
|||||||
if (!Resolve(uid, ref construction, false))
|
if (!Resolve(uid, ref construction, false))
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
if (construction.EdgeIndex is not {} edgeIndex)
|
if (construction.EdgeIndex is not { } edgeIndex)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
return GetCurrentNode(uid, construction) is not {} node ? null : GetEdgeFromNode(node, edgeIndex);
|
return GetCurrentNode(uid, construction) is not { } node ? null : GetEdgeFromNode(node, edgeIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -102,7 +102,7 @@ namespace Content.Server.Construction
|
|||||||
if (GetCurrentNode(uid, construction) is not { } node)
|
if (GetCurrentNode(uid, construction) is not { } node)
|
||||||
return (null, null);
|
return (null, null);
|
||||||
|
|
||||||
if (construction.EdgeIndex is not {} edgeIndex)
|
if (construction.EdgeIndex is not { } edgeIndex)
|
||||||
return (node, null);
|
return (node, null);
|
||||||
|
|
||||||
return (node, GetEdgeFromNode(node, edgeIndex));
|
return (node, GetEdgeFromNode(node, edgeIndex));
|
||||||
@@ -121,7 +121,7 @@ namespace Content.Server.Construction
|
|||||||
if (!Resolve(uid, ref construction, false))
|
if (!Resolve(uid, ref construction, false))
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
if (GetCurrentEdge(uid, construction) is not {} edge)
|
if (GetCurrentEdge(uid, construction) is not { } edge)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
return GetStepFromEdge(edge, construction.StepIndex);
|
return GetStepFromEdge(edge, construction.StepIndex);
|
||||||
@@ -141,10 +141,10 @@ namespace Content.Server.Construction
|
|||||||
if (!Resolve(uid, ref construction))
|
if (!Resolve(uid, ref construction))
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
if (construction.TargetNode is not {} targetNodeId)
|
if (construction.TargetNode is not { } targetNodeId)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
if (GetCurrentGraph(uid, construction) is not {} graph)
|
if (GetCurrentGraph(uid, construction) is not { } graph)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
return GetNodeFromGraph(graph, targetNodeId);
|
return GetNodeFromGraph(graph, targetNodeId);
|
||||||
@@ -165,10 +165,10 @@ namespace Content.Server.Construction
|
|||||||
if (!Resolve(uid, ref construction))
|
if (!Resolve(uid, ref construction))
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
if (construction.TargetEdgeIndex is not {} targetEdgeIndex)
|
if (construction.TargetEdgeIndex is not { } targetEdgeIndex)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
if (GetCurrentNode(uid, construction) is not {} node)
|
if (GetCurrentNode(uid, construction) is not { } node)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
return GetEdgeFromNode(node, targetEdgeIndex);
|
return GetEdgeFromNode(node, targetEdgeIndex);
|
||||||
@@ -245,8 +245,8 @@ namespace Content.Server.Construction
|
|||||||
if (!Resolve(uid, ref construction))
|
if (!Resolve(uid, ref construction))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (GetCurrentGraph(uid, construction) is not {} graph
|
if (GetCurrentGraph(uid, construction) is not { } graph
|
||||||
|| GetNodeFromGraph(graph, id) is not {} node)
|
|| GetNodeFromGraph(graph, id) is not { } node)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
var oldNode = construction.Node;
|
var oldNode = construction.Node;
|
||||||
@@ -257,11 +257,11 @@ namespace Content.Server.Construction
|
|||||||
$"{ToPrettyString(userUid.Value):player} changed {ToPrettyString(uid):entity}'s node from \"{oldNode}\" to \"{id}\"");
|
$"{ToPrettyString(userUid.Value):player} changed {ToPrettyString(uid):entity}'s node from \"{oldNode}\" to \"{id}\"");
|
||||||
|
|
||||||
// ChangeEntity will handle the pathfinding update.
|
// ChangeEntity will handle the pathfinding update.
|
||||||
if (node.Entity.GetId(uid, userUid, new(EntityManager)) is {} newEntity
|
if (node.Entity.GetId(uid, userUid, new(EntityManager)) is { } newEntity
|
||||||
&& ChangeEntity(uid, userUid, newEntity, construction) != null)
|
&& ChangeEntity(uid, userUid, newEntity, construction) != null)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if(performActions)
|
if (performActions)
|
||||||
PerformActions(uid, userUid, node.Actions);
|
PerformActions(uid, userUid, node.Actions);
|
||||||
|
|
||||||
// An action might have deleted the entity... Account for this.
|
// An action might have deleted the entity... Account for this.
|
||||||
@@ -347,7 +347,7 @@ namespace Content.Server.Construction
|
|||||||
|
|
||||||
// Retain the target node if an entity change happens in response to deconstruction;
|
// Retain the target node if an entity change happens in response to deconstruction;
|
||||||
// in that case, we must continue to move towards the start node.
|
// in that case, we must continue to move towards the start node.
|
||||||
if (construction.TargetNode is {} targetNode)
|
if (construction.TargetNode is { } targetNode)
|
||||||
SetPathfindingTarget(newUid, targetNode, newConstruction);
|
SetPathfindingTarget(newUid, targetNode, newConstruction);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -358,7 +358,7 @@ namespace Content.Server.Construction
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (newConstruction.InteractionQueue.Count > 0 && _queuedUpdates.Add(newUid))
|
if (newConstruction.InteractionQueue.Count > 0 && _queuedUpdates.Add(newUid))
|
||||||
_constructionUpdateQueue.Enqueue(newUid);
|
_constructionUpdateQueue.Enqueue(newUid);
|
||||||
|
|
||||||
// Transform transferring.
|
// Transform transferring.
|
||||||
var newTransform = Transform(newUid);
|
var newTransform = Transform(newUid);
|
||||||
@@ -430,7 +430,7 @@ namespace Content.Server.Construction
|
|||||||
if (!PrototypeManager.TryIndex<ConstructionGraphPrototype>(graphId, out var graph))
|
if (!PrototypeManager.TryIndex<ConstructionGraphPrototype>(graphId, out var graph))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if(GetNodeFromGraph(graph, nodeId) is not {})
|
if (GetNodeFromGraph(graph, nodeId) is not { })
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
construction.Graph = graphId;
|
construction.Graph = graphId;
|
||||||
|
|||||||
@@ -478,7 +478,7 @@ namespace Content.Server.Construction
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var mapPos = location.ToMap(EntityManager, _transformSystem);
|
var mapPos = _transformSystem.ToMapCoordinates(location);
|
||||||
var predicate = GetPredicate(constructionPrototype.CanBuildInImpassable, mapPos);
|
var predicate = GetPredicate(constructionPrototype.CanBuildInImpassable, mapPos);
|
||||||
|
|
||||||
if (!_interactionSystem.InRangeUnobstructed(user, mapPos, predicate: predicate))
|
if (!_interactionSystem.InRangeUnobstructed(user, mapPos, predicate: predicate))
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ namespace Content.Shared.Construction.Conditions
|
|||||||
// get blueprint and user position
|
// get blueprint and user position
|
||||||
var transformSystem = entManager.System<SharedTransformSystem>();
|
var transformSystem = entManager.System<SharedTransformSystem>();
|
||||||
var userWorldPosition = transformSystem.GetWorldPosition(user);
|
var userWorldPosition = transformSystem.GetWorldPosition(user);
|
||||||
var objWorldPosition = location.ToMap(entManager, transformSystem).Position;
|
var objWorldPosition = transformSystem.ToMapCoordinates(location).Position;
|
||||||
|
|
||||||
// find direction from user to blueprint
|
// find direction from user to blueprint
|
||||||
var userToObject = (objWorldPosition - userWorldPosition);
|
var userToObject = (objWorldPosition - userWorldPosition);
|
||||||
|
|||||||
@@ -280,7 +280,7 @@ public sealed partial class AnchorableSystem : EntitySystem
|
|||||||
private bool TileFree(EntityCoordinates coordinates, PhysicsComponent anchorBody)
|
private bool TileFree(EntityCoordinates coordinates, PhysicsComponent anchorBody)
|
||||||
{
|
{
|
||||||
// Probably ignore CanCollide on the anchoring body?
|
// Probably ignore CanCollide on the anchoring body?
|
||||||
var gridUid = coordinates.GetGridUid(EntityManager);
|
var gridUid = _transformSystem.GetGrid(coordinates);
|
||||||
|
|
||||||
if (!TryComp<MapGridComponent>(gridUid, out var grid))
|
if (!TryComp<MapGridComponent>(gridUid, out var grid))
|
||||||
return false;
|
return false;
|
||||||
@@ -329,7 +329,7 @@ public sealed partial class AnchorableSystem : EntitySystem
|
|||||||
|
|
||||||
public bool AnyUnstackablesAnchoredAt(EntityCoordinates location)
|
public bool AnyUnstackablesAnchoredAt(EntityCoordinates location)
|
||||||
{
|
{
|
||||||
var gridUid = location.GetGridUid(EntityManager);
|
var gridUid = _transformSystem.GetGrid(location);
|
||||||
|
|
||||||
if (!TryComp<MapGridComponent>(gridUid, out var grid))
|
if (!TryComp<MapGridComponent>(gridUid, out var grid))
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
Reference in New Issue
Block a user