Map System Code Refactor (#204)
* Removes static `IoCManager` service locator calls from `Robust.Shared.Map` namespace. * Misc code cleanup and filling out doc comments for Map classes. * Added Union and Intersect methods to Box2. * Any touched component was converted from static IoC calls to field injection. Sibling PR to https://github.com/space-wizards/RobustToolbox/pull/796.
This commit is contained in:
committed by
Pieter-Jan Briers
parent
50f42d71a2
commit
d3daa83b82
@@ -12,6 +12,8 @@ using Robust.Shared.Map;
|
||||
using Robust.Server.GameObjects.EntitySystems;
|
||||
using Robust.Server.Interfaces.Player;
|
||||
using Robust.Shared.Interfaces.GameObjects.Components;
|
||||
using Robust.Shared.Interfaces.Map;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Players;
|
||||
|
||||
namespace Content.Server.GameObjects.EntitySystems
|
||||
@@ -138,6 +140,10 @@ namespace Content.Server.GameObjects.EntitySystems
|
||||
/// </summary>
|
||||
public class InteractionSystem : EntitySystem
|
||||
{
|
||||
#pragma warning disable 649
|
||||
[Dependency] private readonly IMapManager _mapManager;
|
||||
#pragma warning restore 649
|
||||
|
||||
public const float INTERACTION_RANGE = 2;
|
||||
public const float INTERACTION_RANGE_SQUARED = INTERACTION_RANGE * INTERACTION_RANGE;
|
||||
|
||||
@@ -158,7 +164,7 @@ namespace Content.Server.GameObjects.EntitySystems
|
||||
if(playerEnt == null || !playerEnt.IsValid())
|
||||
return;
|
||||
|
||||
if (!playerEnt.Transform.GridPosition.InRange(used.Transform.GridPosition, INTERACTION_RANGE))
|
||||
if (!playerEnt.Transform.GridPosition.InRange(_mapManager, used.Transform.GridPosition, INTERACTION_RANGE))
|
||||
return;
|
||||
|
||||
var activateMsg = new ActivateInWorldMessage(playerEnt, used);
|
||||
@@ -175,7 +181,7 @@ namespace Content.Server.GameObjects.EntitySystems
|
||||
private void HandleUseItemInHand(ICommonSession session, GridCoordinates coords, EntityUid uid)
|
||||
{
|
||||
// client sanitization
|
||||
if(!coords.IsValidLocation())
|
||||
if(!_mapManager.GridExists(coords.GridID))
|
||||
{
|
||||
Logger.InfoS("system.interaction", $"Invalid Coordinates: client={session}, coords={coords}");
|
||||
return;
|
||||
@@ -202,7 +208,7 @@ namespace Content.Server.GameObjects.EntitySystems
|
||||
return;
|
||||
}
|
||||
//Verify player is on the same map as the entity he clicked on
|
||||
else if (coordinates.MapID != playerTransform.MapID)
|
||||
else if (_mapManager.GetGrid(coordinates.GridID).ParentMap.Index != playerTransform.MapID)
|
||||
{
|
||||
Logger.Warning(string.Format("Player named {0} clicked on a map he isn't located on", player.Name));
|
||||
return;
|
||||
|
||||
@@ -12,6 +12,7 @@ using Robust.Shared.GameObjects.EntitySystemMessages;
|
||||
using Robust.Shared.GameObjects.Systems;
|
||||
using Robust.Shared.Input;
|
||||
using Robust.Shared.Interfaces.GameObjects.Components;
|
||||
using Robust.Shared.Interfaces.Map;
|
||||
using Robust.Shared.Interfaces.Timing;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Map;
|
||||
@@ -22,6 +23,10 @@ namespace Content.Server.GameObjects.EntitySystems
|
||||
{
|
||||
internal class HandsSystem : EntitySystem
|
||||
{
|
||||
#pragma warning disable 649
|
||||
[Dependency] private readonly IMapManager _mapManager;
|
||||
#pragma warning restore 649
|
||||
|
||||
private const float ThrowForce = 1.5f; // Throwing force of mobs in Newtons
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -105,7 +110,7 @@ namespace Content.Server.GameObjects.EntitySystems
|
||||
handsComp.SwapHands();
|
||||
}
|
||||
|
||||
private static void HandleDrop(ICommonSession session, GridCoordinates coords, EntityUid uid)
|
||||
private void HandleDrop(ICommonSession session, GridCoordinates coords, EntityUid uid)
|
||||
{
|
||||
var ent = ((IPlayerSession) session).AttachedEntity;
|
||||
|
||||
@@ -129,7 +134,7 @@ namespace Content.Server.GameObjects.EntitySystems
|
||||
handsComp.ActivateItem();
|
||||
}
|
||||
|
||||
private static void HandleThrowItem(ICommonSession session, GridCoordinates coords, EntityUid uid)
|
||||
private void HandleThrowItem(ICommonSession session, GridCoordinates coords, EntityUid uid)
|
||||
{
|
||||
var plyEnt = ((IPlayerSession)session).AttachedEntity;
|
||||
|
||||
@@ -173,7 +178,7 @@ namespace Content.Server.GameObjects.EntitySystems
|
||||
projComp.IgnoreEntity(plyEnt);
|
||||
|
||||
var transform = plyEnt.Transform;
|
||||
var dirVec = (coords.ToWorld().Position - transform.WorldPosition).Normalized;
|
||||
var dirVec = (coords.ToWorld(_mapManager).Position - transform.WorldPosition).Normalized;
|
||||
|
||||
if (!throwEnt.TryGetComponent(out PhysicsComponent physComp))
|
||||
{
|
||||
|
||||
@@ -15,6 +15,7 @@ using Robust.Shared.GameObjects.Components.Transform;
|
||||
using Robust.Shared.GameObjects.Systems;
|
||||
using Robust.Shared.Input;
|
||||
using Robust.Shared.Interfaces.GameObjects.Components;
|
||||
using Robust.Shared.Interfaces.Map;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
@@ -27,10 +28,10 @@ namespace Content.Server.GameObjects.EntitySystems
|
||||
internal class MoverSystem : EntitySystem
|
||||
{
|
||||
#pragma warning disable 649
|
||||
[Dependency]
|
||||
private IPauseManager _pauseManager;
|
||||
[Dependency]
|
||||
private IPrototypeManager _prototypeManager;
|
||||
[Dependency] private readonly IPauseManager _pauseManager;
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager;
|
||||
[Dependency] private readonly ITileDefinitionManager _tileDefinitionManager;
|
||||
[Dependency] private readonly IMapManager _mapManager;
|
||||
#pragma warning restore 649
|
||||
|
||||
private AudioSystem _audioSystem;
|
||||
@@ -42,8 +43,6 @@ namespace Content.Server.GameObjects.EntitySystems
|
||||
/// <inheritdoc />
|
||||
public override void Initialize()
|
||||
{
|
||||
IoCManager.InjectDependencies(this);
|
||||
|
||||
EntityQuery = new TypeEntityQuery(typeof(PlayerInputMoverComponent));
|
||||
|
||||
var moveUpCmdHandler = InputCmdHandler.FromDelegate(
|
||||
@@ -135,7 +134,7 @@ namespace Content.Server.GameObjects.EntitySystems
|
||||
transform.LocalRotation = mover.VelocityDir.GetDir().ToAngle();
|
||||
|
||||
// Handle footsteps.
|
||||
var distance = transform.GridPosition.Distance(mover.LastPosition);
|
||||
var distance = transform.GridPosition.Distance(_mapManager, mover.LastPosition);
|
||||
mover.StepSoundDistance += distance;
|
||||
mover.LastPosition = transform.GridPosition;
|
||||
float distanceNeeded;
|
||||
@@ -191,13 +190,13 @@ namespace Content.Server.GameObjects.EntitySystems
|
||||
private void PlayFootstepSound(GridCoordinates coordinates)
|
||||
{
|
||||
// Step one: figure out sound collection prototype.
|
||||
var grid = coordinates.Grid;
|
||||
var grid = _mapManager.GetGrid(coordinates.GridID);
|
||||
var tile = grid.GetTile(coordinates);
|
||||
|
||||
// If the coordinates have a catwalk, it's always catwalk.
|
||||
string soundCollectionName;
|
||||
var catwalk = false;
|
||||
foreach (var maybeCatwalk in grid.GetSnapGridCell(tile.GridTile, SnapGridOffset.Center))
|
||||
foreach (var maybeCatwalk in grid.GetSnapGridCell(tile.GridIndices, SnapGridOffset.Center))
|
||||
{
|
||||
if (maybeCatwalk.Owner.HasComponent<CatwalkComponent>())
|
||||
{
|
||||
@@ -214,7 +213,7 @@ namespace Content.Server.GameObjects.EntitySystems
|
||||
else
|
||||
{
|
||||
// Walking on a tile.
|
||||
var def = (ContentTileDefinition)tile.TileDef;
|
||||
var def = (ContentTileDefinition)_tileDefinitionManager[tile.Tile.TypeId];
|
||||
if (def.FootstepSounds == null)
|
||||
{
|
||||
// Nothing to play, oh well.
|
||||
|
||||
Reference in New Issue
Block a user