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
@@ -1,7 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Content.Server.GameObjects.Components.Materials;
|
||||
using Content.Server.GameObjects.Components.Sound;
|
||||
using Content.Server.GameObjects.Components.Stack;
|
||||
using Content.Server.GameObjects.EntitySystems;
|
||||
using Content.Shared.Construction;
|
||||
@@ -10,6 +7,7 @@ using Robust.Server.GameObjects;
|
||||
using Robust.Server.GameObjects.EntitySystems;
|
||||
using Robust.Server.Interfaces.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Interfaces.Map;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Interfaces.GameObjects.Components;
|
||||
using Robust.Shared.Interfaces.Network;
|
||||
@@ -22,6 +20,13 @@ namespace Content.Server.GameObjects.Components.Construction
|
||||
{
|
||||
public class ConstructorComponent : SharedConstructorComponent
|
||||
{
|
||||
#pragma warning disable 649
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager;
|
||||
[Dependency] private readonly IMapManager _mapManager;
|
||||
[Dependency] private readonly IServerEntityManager _serverEntityManager;
|
||||
[Dependency] private readonly IEntitySystemManager _entitySystemManager;
|
||||
#pragma warning restore 649
|
||||
|
||||
public override void HandleMessage(ComponentMessage message, INetChannel netChannel = null, IComponent component = null)
|
||||
{
|
||||
base.HandleMessage(message, netChannel, component);
|
||||
@@ -36,11 +41,10 @@ namespace Content.Server.GameObjects.Components.Construction
|
||||
|
||||
void TryStartStructureConstruction(GridCoordinates loc, string prototypeName, Angle angle, int ack)
|
||||
{
|
||||
var protoMan = IoCManager.Resolve<IPrototypeManager>();
|
||||
var prototype = protoMan.Index<ConstructionPrototype>(prototypeName);
|
||||
var prototype = _prototypeManager.Index<ConstructionPrototype>(prototypeName);
|
||||
|
||||
var transform = Owner.GetComponent<ITransformComponent>();
|
||||
if (!loc.InRange(transform.GridPosition, InteractionSystem.INTERACTION_RANGE))
|
||||
var transform = Owner.Transform;
|
||||
if (!loc.InRange(_mapManager, transform.GridPosition, InteractionSystem.INTERACTION_RANGE))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -75,20 +79,19 @@ namespace Content.Server.GameObjects.Components.Construction
|
||||
}
|
||||
|
||||
// OK WE'RE GOOD CONSTRUCTION STARTED.
|
||||
var entMgr = IoCManager.Resolve<IServerEntityManager>();
|
||||
IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<AudioSystem>().Play("/Audio/items/deconstruct.ogg", loc);
|
||||
_entitySystemManager.GetEntitySystem<AudioSystem>().Play("/Audio/items/deconstruct.ogg", loc);
|
||||
if (prototype.Stages.Count == 2)
|
||||
{
|
||||
// Exactly 2 stages, so don't make an intermediate frame.
|
||||
var ent = entMgr.ForceSpawnEntityAt(prototype.Result, loc);
|
||||
ent.GetComponent<ITransformComponent>().LocalRotation = angle;
|
||||
var ent = _serverEntityManager.ForceSpawnEntityAt(prototype.Result, loc);
|
||||
ent.Transform.LocalRotation = angle;
|
||||
}
|
||||
else
|
||||
{
|
||||
var frame = entMgr.ForceSpawnEntityAt("structureconstructionframe", loc);
|
||||
var frame = _serverEntityManager.ForceSpawnEntityAt("structureconstructionframe", loc);
|
||||
var construction = frame.GetComponent<ConstructionComponent>();
|
||||
construction.Init(prototype);
|
||||
frame.GetComponent<ITransformComponent>().LocalRotation = angle;
|
||||
frame.Transform.LocalRotation = angle;
|
||||
}
|
||||
|
||||
var msg = new AckStructureConstructionMessage(ack);
|
||||
|
||||
@@ -13,6 +13,7 @@ namespace Content.Server.GameObjects.Components.Interactable.Tools
|
||||
#pragma warning disable 649
|
||||
[Dependency] private readonly ITileDefinitionManager _tileDefinitionManager;
|
||||
[Dependency] private readonly IEntitySystemManager _entitySystemManager;
|
||||
[Dependency] private readonly IMapManager _mapManager;
|
||||
#pragma warning restore 649
|
||||
|
||||
/// <summary>
|
||||
@@ -20,19 +21,15 @@ namespace Content.Server.GameObjects.Components.Interactable.Tools
|
||||
/// </summary>
|
||||
public override string Name => "Crowbar";
|
||||
|
||||
public CrowbarComponent()
|
||||
{
|
||||
IoCManager.InjectDependencies(this);
|
||||
}
|
||||
|
||||
public void AfterAttack(AfterAttackEventArgs eventArgs)
|
||||
{
|
||||
var tile = eventArgs.ClickLocation.Grid.GetTile(eventArgs.ClickLocation);
|
||||
var tileDef = (ContentTileDefinition) tile.TileDef;
|
||||
var mapGrid = _mapManager.GetGrid(eventArgs.ClickLocation.GridID);
|
||||
var tile = mapGrid.GetTile(eventArgs.ClickLocation);
|
||||
var tileDef = (ContentTileDefinition)_tileDefinitionManager[tile.Tile.TypeId];
|
||||
if (tileDef.CanCrowbar)
|
||||
{
|
||||
var underplating = _tileDefinitionManager["underplating"];
|
||||
eventArgs.ClickLocation.Grid.SetTile(eventArgs.ClickLocation, underplating.TileId);
|
||||
mapGrid.SetTile(eventArgs.ClickLocation, underplating.TileId);
|
||||
_entitySystemManager.GetEntitySystem<AudioSystem>().Play("/Audio/items/crowbar.ogg", Owner);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using Content.Server.GameObjects.EntitySystems;
|
||||
using Content.Server.Interfaces.GameObjects;
|
||||
using Content.Shared.GameObjects.Components.Storage;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Server.GameObjects.Components.Container;
|
||||
@@ -16,6 +15,7 @@ using Robust.Shared.Serialization;
|
||||
using System.Collections.Generic;
|
||||
using Content.Shared.Interfaces;
|
||||
using Robust.Shared.GameObjects.EntitySystemMessages;
|
||||
using Robust.Shared.Interfaces.Map;
|
||||
using Robust.Shared.ViewVariables;
|
||||
using Content.Server.GameObjects.Components;
|
||||
|
||||
@@ -26,6 +26,12 @@ namespace Content.Server.GameObjects
|
||||
/// </summary>
|
||||
public class ServerStorageComponent : SharedStorageComponent, IAttackBy, IUse, IActivate
|
||||
{
|
||||
#pragma warning disable 649
|
||||
[Dependency] private readonly IMapManager _mapManager;
|
||||
[Dependency] private readonly IPlayerManager _playerManager;
|
||||
[Dependency] private readonly IEntityManager _entityManager;
|
||||
#pragma warning restore 649
|
||||
|
||||
private Container storage;
|
||||
|
||||
private bool _storageInitialCalculated = false;
|
||||
@@ -269,18 +275,17 @@ namespace Content.Server.GameObjects
|
||||
case RemoveEntityMessage _:
|
||||
{
|
||||
_ensureInitialCalculated();
|
||||
var playerMan = IoCManager.Resolve<IPlayerManager>();
|
||||
var session = playerMan.GetSessionByChannel(netChannel);
|
||||
var session = _playerManager.GetSessionByChannel(netChannel);
|
||||
var playerentity = session.AttachedEntity;
|
||||
|
||||
var ourtransform = Owner.GetComponent<ITransformComponent>();
|
||||
var playertransform = playerentity.GetComponent<ITransformComponent>();
|
||||
|
||||
if (playertransform.GridPosition.InRange(ourtransform.GridPosition, 2)
|
||||
if (playertransform.GridPosition.InRange(_mapManager, ourtransform.GridPosition, 2)
|
||||
&& (ourtransform.IsMapTransform || playertransform.ContainsEntity(ourtransform)))
|
||||
{
|
||||
var remove = (RemoveEntityMessage)message;
|
||||
var entity = IoCManager.Resolve<IEntityManager>().GetEntity(remove.EntityUid);
|
||||
var entity = _entityManager.GetEntity(remove.EntityUid);
|
||||
if (entity != null && storage.Contains(entity))
|
||||
{
|
||||
Remove(entity);
|
||||
@@ -300,8 +305,7 @@ namespace Content.Server.GameObjects
|
||||
|
||||
case CloseStorageUIMessage _:
|
||||
{
|
||||
var playerMan = IoCManager.Resolve<IPlayerManager>();
|
||||
var session = playerMan.GetSessionByChannel(netChannel);
|
||||
var session = _playerManager.GetSessionByChannel(netChannel);
|
||||
|
||||
UnsubscribeSession(session);
|
||||
}
|
||||
|
||||
@@ -1,22 +1,21 @@
|
||||
using System;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Content.Server.GameObjects.EntitySystems;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Server.Interfaces.GameObjects;
|
||||
using Robust.Shared.Interfaces.Timing;
|
||||
using Robust.Shared.GameObjects.EntitySystemMessages;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Interfaces.GameObjects.Components;
|
||||
using Content.Shared.GameObjects;
|
||||
using Robust.Shared.Interfaces.Map;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Weapon.Melee
|
||||
{
|
||||
public class MeleeWeaponComponent : Component, IAfterAttack
|
||||
{
|
||||
#pragma warning disable 649
|
||||
[Dependency] private readonly IMapManager _mapManager;
|
||||
[Dependency] private readonly IServerEntityManager _serverEntityManager;
|
||||
#pragma warning restore 649
|
||||
|
||||
public override string Name => "MeleeWeapon";
|
||||
|
||||
public int Damage = 1;
|
||||
@@ -34,13 +33,13 @@ namespace Content.Server.GameObjects.Components.Weapon.Melee
|
||||
|
||||
void IAfterAttack.AfterAttack(AfterAttackEventArgs eventArgs)
|
||||
{
|
||||
var location = eventArgs.User.GetComponent<ITransformComponent>().GridPosition;
|
||||
var angle = new Angle(eventArgs.ClickLocation.ToWorld().Position - location.ToWorld().Position);
|
||||
var entities = IoCManager.Resolve<IServerEntityManager>().GetEntitiesInArc(eventArgs.User.GetComponent<ITransformComponent>().GridPosition, Range, angle, ArcWidth);
|
||||
var location = eventArgs.User.Transform.GridPosition;
|
||||
var angle = new Angle(eventArgs.ClickLocation.ToWorld(_mapManager).Position - location.ToWorld(_mapManager).Position);
|
||||
var entities = _serverEntityManager.GetEntitiesInArc(eventArgs.User.Transform.GridPosition, Range, angle, ArcWidth);
|
||||
|
||||
foreach (var entity in entities)
|
||||
{
|
||||
if (!entity.GetComponent<ITransformComponent>().IsMapTransform || entity == eventArgs.User)
|
||||
if (!entity.Transform.IsMapTransform || entity == eventArgs.User)
|
||||
continue;
|
||||
|
||||
if (entity.TryGetComponent(out DamageableComponent damagecomponent))
|
||||
|
||||
Reference in New Issue
Block a user