mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-14 19:29:36 +01:00
Fix some warnings regarding IComponentManager.
This commit is contained in:
@@ -80,7 +80,7 @@ namespace Robust.Client.GameObjects
|
||||
var position = Owner.Transform.Coordinates;
|
||||
foreach (var neighbor in grid.GetInDir(position, dir))
|
||||
{
|
||||
if (Owner.EntityManager.ComponentManager.TryGetComponent(neighbor, out ClientOccluderComponent? comp) && comp.Enabled)
|
||||
if (Owner.EntityManager.TryGetComponent(neighbor, out ClientOccluderComponent? comp) && comp.Enabled)
|
||||
{
|
||||
Occluding |= oclDir;
|
||||
break;
|
||||
|
||||
@@ -98,7 +98,7 @@ namespace Robust.Client.GameObjects
|
||||
currentEye.Rotation = -parentRotation;
|
||||
}
|
||||
|
||||
foreach (var eyeComponent in EntityManager.ComponentManager.EntityQuery<EyeComponent>(true))
|
||||
foreach (var eyeComponent in EntityManager.EntityQuery<EyeComponent>(true))
|
||||
{
|
||||
eyeComponent.UpdateEyePosition();
|
||||
}
|
||||
|
||||
@@ -480,7 +480,7 @@ namespace Robust.Client.GameStates
|
||||
{
|
||||
var ent = kvStates.Key;
|
||||
var entity = (Entity) ent;
|
||||
HandleEntityState(entity.EntityManager.ComponentManager, entity, _entities.EventBus, kvStates.Value.Item1,
|
||||
HandleEntityState(entity.EntityManager, entity, _entities.EventBus, kvStates.Value.Item1,
|
||||
kvStates.Value.Item2);
|
||||
}
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ namespace Robust.Server.Map
|
||||
|
||||
// Seemed easier than having this method on GridFixtureSystem
|
||||
if (!TryGetGrid(chunk.GridId, out var grid) ||
|
||||
!ComponentManager.TryGetComponent(grid.GridEntityId, out PhysicsComponent? body) ||
|
||||
!EntityManager.TryGetComponent(grid.GridEntityId, out PhysicsComponent? body) ||
|
||||
chunk.Fixtures.Count == 0) return;
|
||||
|
||||
// TODO: Like MapManager injecting this is a PITA so need to work out an easy way to do it.
|
||||
|
||||
@@ -16,7 +16,6 @@ namespace Robust.Shared.Scripting
|
||||
public abstract class ScriptGlobalsShared
|
||||
{
|
||||
[field: Dependency] public IEntityManager ent { get; } = default!;
|
||||
[field: Dependency] public IComponentManager comp { get; } = default!;
|
||||
[field: Dependency] public IPrototypeManager prot { get; } = default!;
|
||||
[field: Dependency] public IMapManager map { get; } = default!;
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace Robust.Shared.GameObjects
|
||||
public class ComponentDependencyManager : IComponentDependencyManager
|
||||
{
|
||||
[IoC.Dependency] private readonly IComponentFactory _componentFactory = null!;
|
||||
[IoC.Dependency] private readonly IComponentManager _componentManager = null!;
|
||||
[IoC.Dependency] private readonly IEntityManager _entityManager = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Cache of queries and their corresponding field offsets
|
||||
@@ -42,7 +42,7 @@ namespace Robust.Shared.GameObjects
|
||||
}
|
||||
|
||||
//get all present components in entity
|
||||
foreach (var entityComp in _componentManager.GetComponents(eUid))
|
||||
foreach (var entityComp in _entityManager.GetComponents(eUid))
|
||||
{
|
||||
var entityCompReg = _componentFactory.GetRegistration(entityComp);
|
||||
foreach (var reference in entityCompReg.References)
|
||||
@@ -74,7 +74,7 @@ namespace Robust.Shared.GameObjects
|
||||
var compReg = _componentFactory.GetRegistration(compType);
|
||||
|
||||
//check if any are requesting our component as a dependency
|
||||
var entityComponents = _componentManager.GetComponents(eUid);
|
||||
var entityComponents = _entityManager.GetComponents(eUid);
|
||||
foreach (var entityComponent in entityComponents)
|
||||
{
|
||||
//get entry for out entityComponent
|
||||
|
||||
@@ -668,14 +668,14 @@ namespace Robust.Shared.GameObjects
|
||||
|
||||
MapID = newMapId;
|
||||
MapIdChanged(oldMapId);
|
||||
UpdateChildMapIdsRecursive(MapID, Owner.EntityManager.ComponentManager);
|
||||
UpdateChildMapIdsRecursive(MapID, Owner.EntityManager);
|
||||
}
|
||||
|
||||
private void UpdateChildMapIdsRecursive(MapId newMapId, IComponentManager comp)
|
||||
private void UpdateChildMapIdsRecursive(MapId newMapId, IEntityManager entMan)
|
||||
{
|
||||
foreach (var child in _children)
|
||||
{
|
||||
var concrete = comp.GetComponent<TransformComponent>(child);
|
||||
var concrete = entMan.GetComponent<TransformComponent>(child);
|
||||
var old = concrete.MapID;
|
||||
|
||||
concrete.MapID = newMapId;
|
||||
@@ -683,7 +683,7 @@ namespace Robust.Shared.GameObjects
|
||||
|
||||
if (concrete.ChildCount != 0)
|
||||
{
|
||||
concrete.UpdateChildMapIdsRecursive(newMapId, comp);
|
||||
concrete.UpdateChildMapIdsRecursive(newMapId, entMan);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -244,13 +244,13 @@ namespace Robust.Shared.GameObjects
|
||||
public EventTables(IEntityManager entMan)
|
||||
{
|
||||
_entMan = entMan;
|
||||
_comFac = entMan.ComponentManager.ComponentFactory;
|
||||
_comFac = entMan.ComponentFactory;
|
||||
|
||||
_entMan.EntityAdded += OnEntityAdded;
|
||||
_entMan.EntityDeleted += OnEntityDeleted;
|
||||
|
||||
_entMan.ComponentManager.ComponentAdded += OnComponentAdded;
|
||||
_entMan.ComponentManager.ComponentRemoved += OnComponentRemoved;
|
||||
_entMan.ComponentAdded += OnComponentAdded;
|
||||
_entMan.ComponentRemoved += OnComponentRemoved;
|
||||
|
||||
_eventTables = new();
|
||||
_subscriptions = new();
|
||||
@@ -423,7 +423,7 @@ namespace Robust.Shared.GameObjects
|
||||
if (reg.ReferenceEvent != byRef)
|
||||
ThrowByRefMisMatch();
|
||||
|
||||
var component = _entMan.ComponentManager.GetComponent(euid, compType);
|
||||
var component = _entMan.GetComponent(euid, compType);
|
||||
|
||||
found.Add(((ref Unit ev) => reg.Handler(euid, component, ref ev), reg.Ordering));
|
||||
}
|
||||
@@ -465,8 +465,8 @@ namespace Robust.Shared.GameObjects
|
||||
_entMan.EntityAdded -= OnEntityAdded;
|
||||
_entMan.EntityDeleted -= OnEntityDeleted;
|
||||
|
||||
_entMan.ComponentManager.ComponentAdded -= OnComponentAdded;
|
||||
_entMan.ComponentManager.ComponentRemoved -= OnComponentRemoved;
|
||||
_entMan.ComponentAdded -= OnComponentAdded;
|
||||
_entMan.ComponentRemoved -= OnComponentRemoved;
|
||||
|
||||
// punishment for use-after-free
|
||||
_entMan = null!;
|
||||
@@ -497,8 +497,7 @@ namespace Robust.Shared.GameObjects
|
||||
return false;
|
||||
}
|
||||
|
||||
enumerator = new(eventType, subscribedComps.GetEnumerator(), _subscriptions, euid,
|
||||
_entMan.ComponentManager);
|
||||
enumerator = new(eventType, subscribedComps.GetEnumerator(), _subscriptions, euid, _entMan);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -545,16 +544,16 @@ namespace Robust.Shared.GameObjects
|
||||
private HashSet<Type>.Enumerator _enumerator;
|
||||
private readonly IReadOnlyDictionary<Type, Dictionary<Type, DirectedRegistration>> _subscriptions;
|
||||
private readonly EntityUid _uid;
|
||||
private readonly IComponentManager _componentManager;
|
||||
private readonly IEntityManager _entityManager;
|
||||
|
||||
public SubscriptionsEnumerator(Type eventType, HashSet<Type>.Enumerator enumerator,
|
||||
IReadOnlyDictionary<Type, Dictionary<Type, DirectedRegistration>> subscriptions, EntityUid uid,
|
||||
IComponentManager componentManager)
|
||||
IEntityManager componentManager)
|
||||
{
|
||||
_eventType = eventType;
|
||||
_enumerator = enumerator;
|
||||
_subscriptions = subscriptions;
|
||||
_componentManager = componentManager;
|
||||
_entityManager = componentManager;
|
||||
_uid = uid;
|
||||
}
|
||||
|
||||
@@ -584,7 +583,7 @@ namespace Robust.Shared.GameObjects
|
||||
return false;
|
||||
}
|
||||
|
||||
tuple = (_componentManager.GetComponent(_uid, compType), registration);
|
||||
tuple = (_entityManager.GetComponent(_uid, compType), registration);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -29,8 +29,6 @@ namespace Robust.Shared.GameObjects
|
||||
/// </summary>
|
||||
event EventHandler<ComponentEventArgs>? ComponentDeleted;
|
||||
|
||||
void Initialize();
|
||||
|
||||
/// <summary>
|
||||
/// Adds a Component type to an entity. If the entity is already Initialized, the component will
|
||||
/// automatically be Initialized and Started.
|
||||
|
||||
@@ -16,7 +16,6 @@ namespace Robust.Shared.Map
|
||||
internal class MapManager : IMapManagerInternal
|
||||
{
|
||||
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
||||
[Dependency] protected readonly IComponentManager ComponentManager = default!;
|
||||
[Dependency] private readonly IEntityManager _entityManager = default!;
|
||||
|
||||
public IGameTiming GameTiming => _gameTiming;
|
||||
@@ -254,7 +253,7 @@ namespace Robust.Shared.Map
|
||||
|
||||
if (actualID != MapId.Nullspace) // nullspace isn't bound to an entity
|
||||
{
|
||||
var mapComps = _entityManager.ComponentManager.EntityQuery<IMapComponent>(true);
|
||||
var mapComps = _entityManager.EntityQuery<IMapComponent>(true);
|
||||
|
||||
IMapComponent? result = null;
|
||||
foreach (var mapComp in mapComps)
|
||||
@@ -449,7 +448,7 @@ namespace Robust.Shared.Map
|
||||
{
|
||||
// the entity may already exist from map deserialization
|
||||
IMapGridComponent? result = null;
|
||||
foreach (var comp in _entityManager.ComponentManager.EntityQuery<IMapGridComponent>(true))
|
||||
foreach (var comp in _entityManager.EntityQuery<IMapGridComponent>(true))
|
||||
{
|
||||
if (comp.GridIndex != actualID)
|
||||
continue;
|
||||
@@ -577,10 +576,10 @@ namespace Robust.Shared.Map
|
||||
if (grid.ParentMapId != mapId || !grid.WorldBounds.Intersects(worldArea)) continue;
|
||||
|
||||
var gridEnt = _entityManager.GetEntity(grid.GridEntityId);
|
||||
var xformComp = _entityManager.ComponentManager.GetComponent<TransformComponent>(gridEnt.Uid);
|
||||
var xformComp = _entityManager.GetComponent<TransformComponent>(gridEnt.Uid);
|
||||
var transform = new Transform(xformComp.WorldPosition, xformComp.WorldRotation);
|
||||
|
||||
if (_entityManager.ComponentManager.TryGetComponent<PhysicsComponent>(gridEnt.Uid, out var body))
|
||||
if (_entityManager.TryGetComponent<PhysicsComponent>(gridEnt.Uid, out var body))
|
||||
{
|
||||
var intersects = false;
|
||||
|
||||
@@ -626,10 +625,10 @@ namespace Robust.Shared.Map
|
||||
if (grid.ParentMapId != mapId || !grid.WorldBounds.Intersects(worldBounds)) continue;
|
||||
|
||||
var gridEnt = _entityManager.GetEntity(grid.GridEntityId);
|
||||
var xformComp = _entityManager.ComponentManager.GetComponent<TransformComponent>(gridEnt.Uid);
|
||||
var xformComp = _entityManager.GetComponent<TransformComponent>(gridEnt.Uid);
|
||||
var transform = new Transform(xformComp.WorldPosition, xformComp.WorldRotation);
|
||||
|
||||
if (_entityManager.ComponentManager.TryGetComponent<PhysicsComponent>(gridEnt.Uid, out var body))
|
||||
if (_entityManager.TryGetComponent<PhysicsComponent>(gridEnt.Uid, out var body))
|
||||
{
|
||||
var intersects = false;
|
||||
|
||||
|
||||
@@ -184,7 +184,7 @@ namespace Robust.Shared.Prototypes
|
||||
}
|
||||
|
||||
var factory = IoCManager.Resolve<IComponentFactory>();
|
||||
var componentManager = IoCManager.Resolve<IComponentManager>();
|
||||
var entityManager = IoCManager.Resolve<IEntityManager>();
|
||||
var oldPrototype = entity.Prototype;
|
||||
|
||||
var oldPrototypeComponents = oldPrototype.Components.Keys
|
||||
@@ -207,10 +207,10 @@ namespace Robust.Shared.Prototypes
|
||||
continue;
|
||||
}
|
||||
|
||||
componentManager.RemoveComponent(entity.Uid, type);
|
||||
entityManager.RemoveComponent(entity.Uid, type);
|
||||
}
|
||||
|
||||
componentManager.CullRemovedComponents();
|
||||
entityManager.CullRemovedComponents();
|
||||
|
||||
var componentDependencyManager = IoCManager.Resolve<IComponentDependencyManager>();
|
||||
|
||||
|
||||
@@ -23,23 +23,21 @@ namespace Robust.UnitTesting.Shared.GameObjects
|
||||
|
||||
var entManMock = new Mock<IEntityManager>();
|
||||
|
||||
|
||||
var compManMock = new Mock<IComponentManager>();
|
||||
var compFacMock = new Mock<IComponentFactory>();
|
||||
|
||||
compRegistration.Setup(m => m.References).Returns(new List<Type> {typeof(MetaDataComponent)});
|
||||
compFacMock.Setup(m => m.GetRegistration(typeof(MetaDataComponent))).Returns(compRegistration.Object);
|
||||
compManMock.Setup(m => m.ComponentFactory).Returns(compFacMock.Object);
|
||||
entManMock.Setup(m => m.ComponentFactory).Returns(compFacMock.Object);
|
||||
|
||||
IComponent? outIComponent = compInstance;
|
||||
compManMock.Setup(m => m.TryGetComponent(entUid, typeof(MetaDataComponent), out outIComponent))
|
||||
entManMock.Setup(m => m.TryGetComponent(entUid, typeof(MetaDataComponent), out outIComponent))
|
||||
.Returns(true);
|
||||
|
||||
compManMock.Setup(m => m.GetComponent(entUid, typeof(MetaDataComponent)))
|
||||
entManMock.Setup(m => m.GetComponent(entUid, typeof(MetaDataComponent)))
|
||||
.Returns(compInstance);
|
||||
|
||||
|
||||
entManMock.Setup(m => m.ComponentManager).Returns(compManMock.Object);
|
||||
entManMock.Setup(m => m.ComponentManager).Returns(entManMock.Object);
|
||||
var bus = new EntityEventBus(entManMock.Object);
|
||||
|
||||
// Subscribe
|
||||
@@ -48,7 +46,7 @@ namespace Robust.UnitTesting.Shared.GameObjects
|
||||
|
||||
// add a component to the system
|
||||
entManMock.Raise(m=>m.EntityAdded += null, entManMock.Object, entUid);
|
||||
compManMock.Raise(m => m.ComponentAdded += null, new AddedComponentEventArgs(compInstance, entUid));
|
||||
entManMock.Raise(m => m.ComponentAdded += null, new AddedComponentEventArgs(compInstance, entUid));
|
||||
|
||||
// Raise
|
||||
var evntArgs = new TestEvent(5);
|
||||
@@ -130,21 +128,20 @@ namespace Robust.UnitTesting.Shared.GameObjects
|
||||
|
||||
var compRegistration = new Mock<IComponentRegistration>();
|
||||
|
||||
var compManMock = new Mock<IComponentManager>();
|
||||
var compFacMock = new Mock<IComponentFactory>();
|
||||
|
||||
compRegistration.Setup(m => m.References).Returns(new List<Type> {typeof(MetaDataComponent)});
|
||||
compFacMock.Setup(m => m.GetRegistration(typeof(MetaDataComponent))).Returns(compRegistration.Object);
|
||||
compManMock.Setup(m => m.ComponentFactory).Returns(compFacMock.Object);
|
||||
entManMock.Setup(m => m.ComponentFactory).Returns(compFacMock.Object);
|
||||
|
||||
IComponent? outIComponent = compInstance;
|
||||
compManMock.Setup(m => m.TryGetComponent(entUid, typeof(MetaDataComponent), out outIComponent))
|
||||
entManMock.Setup(m => m.TryGetComponent(entUid, typeof(MetaDataComponent), out outIComponent))
|
||||
.Returns(true);
|
||||
|
||||
compManMock.Setup(m => m.GetComponent(entUid, typeof(MetaDataComponent)))
|
||||
entManMock.Setup(m => m.GetComponent(entUid, typeof(MetaDataComponent)))
|
||||
.Returns(compInstance);
|
||||
|
||||
entManMock.Setup(m => m.ComponentManager).Returns(compManMock.Object);
|
||||
entManMock.Setup(m => m.ComponentManager).Returns(entManMock.Object);
|
||||
var bus = new EntityEventBus(entManMock.Object);
|
||||
|
||||
// Subscribe
|
||||
@@ -153,7 +150,7 @@ namespace Robust.UnitTesting.Shared.GameObjects
|
||||
|
||||
// add a component to the system
|
||||
entManMock.Raise(m=>m.EntityAdded += null, entManMock.Object, entUid);
|
||||
compManMock.Raise(m => m.ComponentAdded += null, new AddedComponentEventArgs(compInstance, entUid));
|
||||
entManMock.Raise(m => m.ComponentAdded += null, new AddedComponentEventArgs(compInstance, entUid));
|
||||
|
||||
// Raise
|
||||
((IEventBus)bus).RaiseComponentEvent(compInstance, new ComponentInit());
|
||||
@@ -175,8 +172,6 @@ namespace Robust.UnitTesting.Shared.GameObjects
|
||||
var entUid = new EntityUid(7);
|
||||
|
||||
var entManMock = new Mock<IEntityManager>();
|
||||
|
||||
var compManMock = new Mock<IComponentManager>();
|
||||
var compFacMock = new Mock<IComponentFactory>();
|
||||
|
||||
void Setup<T>(out T instance) where T : IComponent, new()
|
||||
@@ -186,16 +181,16 @@ namespace Robust.UnitTesting.Shared.GameObjects
|
||||
reg.Setup(m => m.References).Returns(new Type[] {typeof(T)});
|
||||
|
||||
compFacMock.Setup(m => m.GetRegistration(typeof(T))).Returns(reg.Object);
|
||||
compManMock.Setup(m => m.TryGetComponent(entUid, typeof(T), out inst)).Returns(true);
|
||||
compManMock.Setup(m => m.GetComponent(entUid, typeof(T))).Returns(inst);
|
||||
entManMock.Setup(m => m.TryGetComponent(entUid, typeof(T), out inst)).Returns(true);
|
||||
entManMock.Setup(m => m.GetComponent(entUid, typeof(T))).Returns(inst);
|
||||
}
|
||||
|
||||
Setup<OrderComponentA>(out var instA);
|
||||
Setup<OrderComponentB>(out var instB);
|
||||
Setup<OrderComponentC>(out var instC);
|
||||
|
||||
compManMock.Setup(m => m.ComponentFactory).Returns(compFacMock.Object);
|
||||
entManMock.Setup(m => m.ComponentManager).Returns(compManMock.Object);
|
||||
entManMock.Setup(m => m.ComponentFactory).Returns(compFacMock.Object);
|
||||
entManMock.Setup(m => m.ComponentManager).Returns(entManMock.Object);
|
||||
var bus = new EntityEventBus(entManMock.Object);
|
||||
|
||||
// Subscribe
|
||||
@@ -225,9 +220,9 @@ namespace Robust.UnitTesting.Shared.GameObjects
|
||||
|
||||
// add a component to the system
|
||||
entManMock.Raise(m=>m.EntityAdded += null, entManMock.Object, entUid);
|
||||
compManMock.Raise(m => m.ComponentAdded += null, new AddedComponentEventArgs(instA, entUid));
|
||||
compManMock.Raise(m => m.ComponentAdded += null, new AddedComponentEventArgs(instB, entUid));
|
||||
compManMock.Raise(m => m.ComponentAdded += null, new AddedComponentEventArgs(instC, entUid));
|
||||
entManMock.Raise(m => m.ComponentAdded += null, new AddedComponentEventArgs(instA, entUid));
|
||||
entManMock.Raise(m => m.ComponentAdded += null, new AddedComponentEventArgs(instB, entUid));
|
||||
entManMock.Raise(m => m.ComponentAdded += null, new AddedComponentEventArgs(instC, entUid));
|
||||
|
||||
// Raise
|
||||
var evntArgs = new TestEvent(5);
|
||||
|
||||
Reference in New Issue
Block a user