diff --git a/Robust.Client/GameObjects/ClientEntityManager.cs b/Robust.Client/GameObjects/ClientEntityManager.cs index 20458742d..fdb19d5e8 100644 --- a/Robust.Client/GameObjects/ClientEntityManager.cs +++ b/Robust.Client/GameObjects/ClientEntityManager.cs @@ -40,12 +40,12 @@ namespace Robust.Client.GameObjects void IClientEntityManagerInternal.InitializeEntity(IEntity entity) { - base.InitializeEntity((Entity)entity); + base.InitializeEntity(entity); } void IClientEntityManagerInternal.StartEntity(IEntity entity) { - base.StartEntity((Entity)entity); + base.StartEntity(entity); } #region IEntityNetworkManager impl diff --git a/Robust.Client/GameStates/ClientGameStateManager.cs b/Robust.Client/GameStates/ClientGameStateManager.cs index 5aa63060e..9e1f1f356 100644 --- a/Robust.Client/GameStates/ClientGameStateManager.cs +++ b/Robust.Client/GameStates/ClientGameStateManager.cs @@ -428,7 +428,7 @@ namespace Robust.Client.GameStates ReadOnlySpan nextEntStates) { var toApply = new Dictionary(); - var toInitialize = new List(); + var toInitialize = new List(); var created = new List(); var toHide = new List(); var toShow = new List(); @@ -453,7 +453,7 @@ namespace Robust.Client.GameStates throw new InvalidOperationException($"Server sent new entity state for {es.Uid} without metadata component!"); } // Logger.Debug($"[{IGameTiming.TickStampStatic}] CREATE {es.Uid} {metaState.PrototypeId}"); - var newEntity = (Entity)_entities.CreateEntity(metaState.PrototypeId, es.Uid); + var newEntity = _entities.CreateEntity(metaState.PrototypeId, es.Uid); toApply.Add(newEntity, (es, null)); toInitialize.Add(newEntity); created.Add(newEntity.Uid); @@ -482,7 +482,7 @@ namespace Robust.Client.GameStates foreach (var kvStates in toApply) { var ent = kvStates.Key; - var entity = (Entity) ent; + var entity = ent; HandleEntityState(entity, _entities.EventBus, kvStates.Value.Item1, kvStates.Value.Item2); } diff --git a/Robust.Server/GameObjects/ServerEntityManager.cs b/Robust.Server/GameObjects/ServerEntityManager.cs index db3a64e36..140fed07b 100644 --- a/Robust.Server/GameObjects/ServerEntityManager.cs +++ b/Robust.Server/GameObjects/ServerEntityManager.cs @@ -50,20 +50,20 @@ namespace Robust.Server.GameObjects void IServerEntityManagerInternal.FinishEntityLoad(IEntity entity, IEntityLoadContext? context) { - LoadEntity((Entity) entity, context); + LoadEntity(entity, context); } void IServerEntityManagerInternal.FinishEntityInitialization(IEntity entity) { - InitializeEntity((Entity) entity); + InitializeEntity(entity); } void IServerEntityManagerInternal.FinishEntityStartup(IEntity entity) { - StartEntity((Entity) entity); + StartEntity(entity); } - private protected override Entity CreateEntity(string? prototypeName, EntityUid? uid = null) + private protected override IEntity CreateEntity(string? prototypeName, EntityUid? uid = null) { var entity = base.CreateEntity(prototypeName, uid); diff --git a/Robust.Shared/GameObjects/Entity.cs b/Robust.Shared/GameObjects/Entity.cs deleted file mode 100644 index 9ae3808ce..000000000 --- a/Robust.Shared/GameObjects/Entity.cs +++ /dev/null @@ -1,253 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using System.Linq; -using Robust.Shared.IoC; -using Robust.Shared.Network; -using Robust.Shared.Physics; -using Robust.Shared.Prototypes; -using Robust.Shared.Timing; -using Robust.Shared.Utility; -using Robust.Shared.ViewVariables; - -namespace Robust.Shared.GameObjects -{ - /// - public sealed class Entity : IEntity - { - #region Members - - /// - public IEntityManager EntityManager => IoCManager.Resolve(); - - /// - [ViewVariables] - public EntityUid Uid { get; } - - /// - EntityLifeStage IEntity.LifeStage { get => LifeStage; set => LifeStage = value; } - - public EntityLifeStage LifeStage - { - get - { - if (!EntityManager.EntityExists(Uid)) - return EntityLifeStage.Deleted; - - return MetaData.EntityLifeStage; - } - internal set => MetaData.EntityLifeStage = value; - } - - [ViewVariables] - GameTick IEntity.LastModifiedTick { get => MetaData.EntityLastModifiedTick; set => MetaData.EntityLastModifiedTick = value; } - - - /// - [ViewVariables] - public EntityPrototype? Prototype - { - get => MetaData.EntityPrototype; - internal set => MetaData.EntityPrototype = value; - } - - /// - [ViewVariables(VVAccess.ReadWrite)] - public string Description - { - get => MetaData.EntityDescription; - set => MetaData.EntityDescription = value; - } - - /// - [ViewVariables(VVAccess.ReadWrite)] - public string Name - { - get => MetaData.EntityName; - set => MetaData.EntityName = value; - } - - /// - public bool Initialized => LifeStage >= EntityLifeStage.Initialized; - - /// - public bool Initializing => LifeStage == EntityLifeStage.Initializing; - - /// - public bool Deleted => LifeStage >= EntityLifeStage.Deleted; - - [ViewVariables] - public bool Paused { get => Deleted || MetaData.EntityPaused; set => MetaData.EntityPaused = value; } - - /// - [ViewVariables] - public TransformComponent Transform - { - get - { - return (TransformComponent)IoCManager.Resolve().GetComponent(Uid, typeof(TransformComponent)); - } - } - - /// - [ViewVariables] - public MetaDataComponent MetaData - { - get - { - return (MetaDataComponent)IoCManager.Resolve().GetComponent(Uid, typeof(MetaDataComponent)); - } - } - - #endregion Members - - #region Initialization - - public Entity(IEntityManager entityManager, EntityUid uid) - { - Uid = uid; - } - - /// - public bool IsValid() - { - return EntityManager.EntityExists(Uid); - } - - #endregion Initialization - - #region Component Messaging - - /// - [Obsolete("Component Messages are deprecated, use Entity Events instead.")] - public void SendMessage(IComponent? owner, ComponentMessage message) - { - var components = EntityManager.GetComponents(Uid); - foreach (var component in components) - { - if (owner != component) - component.HandleMessage(message, owner); - } - } - - /// - [Obsolete("Component Messages are deprecated, use Entity Events instead.")] - public void SendNetworkMessage(IComponent owner, ComponentMessage message, INetChannel? channel = null) - { - EntityManager.EntityNetManager?.SendComponentNetworkMessage(channel, this, owner, message); - } - - #endregion Component Messaging - - #region Components - - /// - /// Public method to add a component to an entity. - /// Calls the component's onAdd method, which also adds it to the component manager. - /// - /// The component to add. - public void AddComponent(Component component) - { - EntityManager.AddComponent(this, component); - } - - /// - public T AddComponent() - where T : Component, new() - { - return EntityManager.AddComponent(this); - } - - /// - public void RemoveComponent() - { - EntityManager.RemoveComponent(Uid); - } - - /// - public bool HasComponent() - { - return EntityManager.HasComponent(Uid); - } - - /// - public bool HasComponent(Type type) - { - return EntityManager.HasComponent(Uid, type); - } - - /// - public T GetComponent() - { - DebugTools.Assert(!Deleted, "Tried to get component on a deleted entity."); - - return (T)EntityManager.GetComponent(Uid, typeof(T)); - } - - /// - public IComponent GetComponent(Type type) - { - DebugTools.Assert(!Deleted, "Tried to get component on a deleted entity."); - - return EntityManager.GetComponent(Uid, type); - } - - /// - public bool TryGetComponent([NotNullWhen(true)] out T? component) where T : class - { - DebugTools.Assert(!Deleted, "Tried to get component on a deleted entity."); - - return EntityManager.TryGetComponent(Uid, out component); - } - - public T? GetComponentOrNull() where T : class - { - return TryGetComponent(out T? component) ? component : default; - } - - /// - public bool TryGetComponent(Type type, [NotNullWhen(true)] out IComponent? component) - { - DebugTools.Assert(!Deleted, "Tried to get component on a deleted entity."); - - return EntityManager.TryGetComponent(Uid, type, out component); - } - - public IComponent? GetComponentOrNull(Type type) - { - return TryGetComponent(type, out var component) ? component : null; - } - - /// - public void QueueDelete() - { - EntityManager.QueueDeleteEntity(this); - } - - /// - public void Delete() - { - EntityManager.DeleteEntity(this); - } - - /// - public IEnumerable GetAllComponents() - { - return EntityManager.GetComponents(Uid); - } - - /// - public IEnumerable GetAllComponents() - { - return EntityManager.GetComponents(Uid); - } - - #endregion Components - - /// - public override string ToString() - { - return EntityManager.ToPrettyString(Uid); - } - } -} diff --git a/Robust.Shared/GameObjects/EntityManager.cs b/Robust.Shared/GameObjects/EntityManager.cs index d8925d54c..c834271d7 100644 --- a/Robust.Shared/GameObjects/EntityManager.cs +++ b/Robust.Shared/GameObjects/EntityManager.cs @@ -43,7 +43,7 @@ namespace Robust.Shared.GameObjects /// /// All entities currently stored in the manager. /// - protected readonly Dictionary Entities = new(); + protected readonly Dictionary Entities = new(); private EntityEventBus _eventBus = null!; @@ -192,7 +192,7 @@ namespace Robust.Shared.GameObjects throw new InvalidOperationException($"Tried to spawn entity {protoName} on invalid coordinates {coordinates}."); var entity = CreateEntityUninitialized(protoName, coordinates); - InitializeAndStartEntity((Entity) entity, coordinates.GetMapId(this)); + InitializeAndStartEntity(entity, coordinates.GetMapId(this)); return entity; } @@ -200,7 +200,7 @@ namespace Robust.Shared.GameObjects public virtual IEntity SpawnEntity(string? protoName, MapCoordinates coordinates) { var entity = CreateEntityUninitialized(protoName, coordinates); - InitializeAndStartEntity((Entity) entity, coordinates.MapId); + InitializeAndStartEntity(entity, coordinates.MapId); return entity; } @@ -367,7 +367,7 @@ namespace Robust.Shared.GameObjects /// /// Allocates an entity and stores it but does not load components or do initialization. /// - private protected Entity AllocEntity(string? prototypeName, EntityUid? uid = null) + private protected IEntity AllocEntity(string? prototypeName, EntityUid? uid = null) { EntityPrototype? prototype = null; if (!string.IsNullOrWhiteSpace(prototypeName)) @@ -386,7 +386,7 @@ namespace Robust.Shared.GameObjects /// /// Allocates an entity and stores it but does not load components or do initialization. /// - private protected Entity AllocEntity(EntityUid? uid = null) + private protected IEntity AllocEntity(EntityUid? uid = null) { if (uid == null) { @@ -398,8 +398,7 @@ namespace Robust.Shared.GameObjects throw new InvalidOperationException($"UID already taken: {uid}"); } - var entity = new Entity(this, uid.Value); - + var entity = new IEntity(uid.Value); // we want this called before adding components EntityAdded?.Invoke(this, entity.Uid); @@ -423,7 +422,7 @@ namespace Robust.Shared.GameObjects /// /// Allocates an entity and loads components but does not do initialization. /// - private protected virtual Entity CreateEntity(string? prototypeName, EntityUid? uid = null) + private protected virtual IEntity CreateEntity(string? prototypeName, EntityUid? uid = null) { if (prototypeName == null) return AllocEntity(uid); @@ -443,12 +442,12 @@ namespace Robust.Shared.GameObjects } } - private protected void LoadEntity(Entity entity, IEntityLoadContext? context) + private protected void LoadEntity(IEntity entity, IEntityLoadContext? context) { EntityPrototype.LoadEntity(entity.Prototype, entity, ComponentFactory, context); } - private void InitializeAndStartEntity(Entity entity, MapId mapId) + private void InitializeAndStartEntity(IEntity entity, MapId mapId) { try { @@ -466,13 +465,13 @@ namespace Robust.Shared.GameObjects } } - protected void InitializeEntity(Entity entity) + protected void InitializeEntity(IEntity entity) { InitializeComponents(entity.Uid); EntityInitialized?.Invoke(this, entity.Uid); } - protected void StartEntity(Entity entity) + protected void StartEntity(IEntity entity) { StartComponents(entity.Uid); EntityStarted?.Invoke(this, entity.Uid); diff --git a/Robust.Shared/GameObjects/IComponentFactory.cs b/Robust.Shared/GameObjects/IComponentFactory.cs index 61bf021bd..d7afe8ac9 100644 --- a/Robust.Shared/GameObjects/IComponentFactory.cs +++ b/Robust.Shared/GameObjects/IComponentFactory.cs @@ -259,7 +259,7 @@ namespace Robust.Shared.GameObjects /// /// A list of type references that can be used to get a reference to an instance of this component, - /// for methods like . + /// for methods like . /// These are not unique and can overlap with other components. /// IReadOnlyList References { get; } diff --git a/Robust.Shared/GameObjects/IEntity.cs b/Robust.Shared/GameObjects/IEntity.cs index 4197222d2..82a5b39c7 100644 --- a/Robust.Shared/GameObjects/IEntity.cs +++ b/Robust.Shared/GameObjects/IEntity.cs @@ -1,204 +1,200 @@ using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; +using Robust.Shared.IoC; using Robust.Shared.Network; using Robust.Shared.Prototypes; using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Timing; +using Robust.Shared.Utility; +using Robust.Shared.ViewVariables; namespace Robust.Shared.GameObjects { - [CopyByRef] - public interface IEntity + [CopyByRef, Serializable] + public sealed class IEntity { - GameTick LastModifiedTick { get; internal set; } + #region Members - /// - /// The Entity Manager that controls this entity. - /// - IEntityManager EntityManager { get; } + public IEntityManager EntityManager => IoCManager.Resolve(); - /// - /// The name of this entity. - /// This is the actual IC display name. - /// - string Name { get; set; } + [ViewVariables] + public EntityUid Uid { get; } - /// - /// The unique ID of this entity. - /// Unique IDs are unique per entity, - /// and correspond to counterparts across the network. - /// - EntityUid Uid { get; } + public EntityLifeStage LifeStage + { + get => !EntityManager.EntityExists(Uid) ? EntityLifeStage.Deleted : MetaData.EntityLifeStage; + internal set => MetaData.EntityLifeStage = value; + } - /// - /// The current lifetime stage of this entity. You can use this to check - /// if the entity is initialized or being deleted. - /// - EntityLifeStage LifeStage { get; internal set; } + [ViewVariables] + public GameTick LastModifiedTick { get => MetaData.EntityLastModifiedTick; internal set => MetaData.EntityLastModifiedTick = value; } - /// - /// Whether this entity has fully initialized. - /// - bool Initialized { get; } - bool Initializing { get; } + [ViewVariables] + public EntityPrototype? Prototype + { + get => MetaData.EntityPrototype; + internal set => MetaData.EntityPrototype = value; + } - /// - /// True if the entity has been deleted. - /// - bool Deleted { get; } + [ViewVariables(VVAccess.ReadWrite)] + public string Description + { + get => MetaData.EntityDescription; + set => MetaData.EntityDescription = value; + } - bool Paused { get; set; } + [ViewVariables(VVAccess.ReadWrite)] + public string Name + { + get => MetaData.EntityName; + set => MetaData.EntityName = value; + } - /// - /// The prototype that was used to create this entity. - /// - EntityPrototype? Prototype { get; } + public bool Initialized => LifeStage >= EntityLifeStage.Initialized; - /// - /// The string that describes this entity via examine - /// - string Description { get; set; } + public bool Initializing => LifeStage == EntityLifeStage.Initializing; - /// - /// Determines if this entity is still valid. - /// - /// True if this entity is still valid. - bool IsValid(); + public bool Deleted => LifeStage >= EntityLifeStage.Deleted; - /// - /// The entity's transform component. - /// - TransformComponent Transform { get; } + [ViewVariables] + public bool Paused { get => Deleted || MetaData.EntityPaused; set => MetaData.EntityPaused = value; } - /// - /// The MetaData Component of this entity. - /// - MetaDataComponent MetaData { get; } + [ViewVariables] + public TransformComponent Transform => EntityManager.GetComponent(Uid); + + [ViewVariables] + public MetaDataComponent MetaData => EntityManager.GetComponent(Uid); + + #endregion Members + + #region Initialization + + public IEntity(EntityUid uid) + { + Uid = uid; + } + + public bool IsValid() + { + return EntityManager.EntityExists(Uid); + } + + #endregion Initialization + + #region Component Messaging + + [Obsolete("Component Messages are deprecated, use Entity Events instead.")] + public void SendMessage(IComponent? owner, ComponentMessage message) + { + var components = EntityManager.GetComponents(Uid); + foreach (var component in components) + { + if (owner != component) + component.HandleMessage(message, owner); + } + } + + [Obsolete("Component Messages are deprecated, use Entity Events instead.")] + public void SendNetworkMessage(IComponent owner, ComponentMessage message, INetChannel? channel = null) + { + EntityManager.EntityNetManager?.SendComponentNetworkMessage(channel, this, owner, message); + } + + #endregion Component Messaging + + #region Components /// /// Public method to add a component to an entity. /// Calls the component's onAdd method, which also adds it to the component manager. /// - /// The component type to add. - /// The newly added component. - T AddComponent() - where T : Component, new(); + /// The component to add. + public void AddComponent(Component component) + { + EntityManager.AddComponent(this, component); + } - /// - /// Removes the component with the specified reference type, - /// Without needing to have the component itself. - /// - /// The component reference type to remove. - void RemoveComponent(); + public T AddComponent() + where T : Component, new() + { + return EntityManager.AddComponent(this); + } - /// - /// Checks to see if the entity has a component of the specified type. - /// - /// The component reference type to check. - /// True if the entity has a component of type , false otherwise. - bool HasComponent(); + public void RemoveComponent() + { + EntityManager.RemoveComponent(Uid); + } - /// - /// Checks to see ift he entity has a component of the specified type. - /// - /// The component reference type to check. - /// - bool HasComponent(Type type); + public bool HasComponent() + { + return EntityManager.HasComponent(Uid); + } - /// - /// Retrieves the component of the specified type. - /// - /// The component reference type to fetch. - /// The retrieved component. - /// - /// Thrown if there is no component with the specified type. - /// - T GetComponent(); + public bool HasComponent(Type type) + { + return EntityManager.HasComponent(Uid, type); + } - /// - /// Retrieves the component of the specified type. - /// - /// The component reference type to fetch. - /// The retrieved component. - /// - /// Thrown if there is no component with the specified type. - /// - IComponent GetComponent(Type type); + public T GetComponent() + { + DebugTools.Assert(!Deleted, "Tried to get component on a deleted entity."); - /// - /// Attempt to retrieve the component with specified type, - /// writing it to the out parameter if it was found. - /// - /// The component reference type to attempt to fetch. - /// The component, if it was found. Null otherwise. - /// True if a component with specified type was found. - bool TryGetComponent([NotNullWhen(true)] out T? component) where T : class; + return EntityManager.GetComponent(Uid); + } - /// - /// Attempt to retrieve the component with specified type, - /// returning it if it was found. - /// - /// The component reference type to attempt to fetch. - /// The component, if it was found. Null otherwise. - T? GetComponentOrNull() where T : class; + public IComponent GetComponent(Type type) + { + DebugTools.Assert(!Deleted, "Tried to get component on a deleted entity."); - /// - /// Attempt to retrieve the component with specified type, - /// writing it to the out parameter if it was found. - /// - /// The component reference type to attempt to fetch. - /// The component, if it was found. Null otherwise. - /// True if a component with specified type was found. - bool TryGetComponent(Type type, [NotNullWhen(true)] out IComponent? component); + return EntityManager.GetComponent(Uid, type); + } - /// - /// Attempt to retrieve the component with specified type, - /// returning it if it was found. - /// - /// The component reference type to attempt to fetch. - /// The component, if it was found. Null otherwise. - IComponent? GetComponentOrNull(Type type); + public bool TryGetComponent([NotNullWhen(true)] out T? component) where T : class + { + DebugTools.Assert(!Deleted, "Tried to get component on a deleted entity."); - /// - /// Queues this entity for deletion at the end of the tick. - /// - void QueueDelete(); + return EntityManager.TryGetComponent(Uid, out component); + } - /// - /// Deletes this entity. - /// - void Delete(); + public T? GetComponentOrNull() where T : class, IComponent + { + return EntityManager.GetComponentOrNull(Uid); + } - /// - /// Returns all components on the entity. - /// - /// An enumerable of components on the entity. - IEnumerable GetAllComponents(); + public bool TryGetComponent(Type type, [NotNullWhen(true)] out IComponent? component) + { + DebugTools.Assert(!Deleted, "Tried to get component on a deleted entity."); - /// - /// Returns all components that are assignable to . - /// This does not go by component references. - /// - /// The type that components must implement. - /// An enumerable over the found components. - IEnumerable GetAllComponents(); + return EntityManager.TryGetComponent(Uid, type, out component); + } - /// - /// Sends a message to all other components in this entity. - /// - /// Object that sent the event. - /// Message to send. - [Obsolete("Component Messages are deprecated, use Entity Events instead.")] - void SendMessage(IComponent? owner, ComponentMessage message); + public void QueueDelete() + { + EntityManager.QueueDeleteEntity(this); + } - /// - /// Sends a message over the network to the counterpart component. This works both ways. - /// - /// - /// Message to send. - [Obsolete("Component Messages are deprecated, use Entity Events instead.")] - void SendNetworkMessage(IComponent owner, ComponentMessage message, INetChannel? channel = null); + public void Delete() + { + EntityManager.DeleteEntity(this); + } + + public IEnumerable GetAllComponents() + { + return EntityManager.GetComponents(Uid); + } + + public IEnumerable GetAllComponents() + { + return EntityManager.GetComponents(Uid); + } + + #endregion Components + + public override string ToString() + { + return EntityManager.ToPrettyString(Uid); + } } } diff --git a/Robust.Shared/GameObjects/IEntityManager.cs b/Robust.Shared/GameObjects/IEntityManager.cs index c2de1babb..651d73a31 100644 --- a/Robust.Shared/GameObjects/IEntityManager.cs +++ b/Robust.Shared/GameObjects/IEntityManager.cs @@ -109,7 +109,7 @@ namespace Robust.Shared.GameObjects public void QueueDeleteEntity(EntityUid uid); /// - /// Shuts-down and removes given . This is also broadcast to all clients. + /// Shuts-down and removes given . This is also broadcast to all clients. /// /// Entity to remove void DeleteEntity(IEntity e); diff --git a/Robust.Shared/GameObjects/IEntitySerializer.cs b/Robust.Shared/GameObjects/IEntitySerializer.cs new file mode 100644 index 000000000..023ad6795 --- /dev/null +++ b/Robust.Shared/GameObjects/IEntitySerializer.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Reflection; +using NetSerializer; + +namespace Robust.Shared.GameObjects; + +public class IEntitySerializer : ITypeSerializer, IStaticTypeSerializer +{ + public bool Handles(Type type) + { + return type == typeof(IEntity); + } + + public IEnumerable GetSubtypes(Type type) + { + yield break; + } + + public MethodInfo? GetStaticWriter(Type type) + { + return this.GetType().GetMethod("Serialize", BindingFlags.Static | BindingFlags.Public); + } + + public MethodInfo? GetStaticReader(Type type) + { + return this.GetType().GetMethod("Deserialize", BindingFlags.Static | BindingFlags.Public); + } + + public static void Serialize(Serializer serializer, Stream stream, object ob) + { + } + + public static void Deserialize(Serializer serializer, Stream stream, out object? ob) + { + ob = null; + } +} diff --git a/Robust.Shared/Map/MapManager.cs b/Robust.Shared/Map/MapManager.cs index 5cca8d40f..b1fb6b578 100644 --- a/Robust.Shared/Map/MapManager.cs +++ b/Robust.Shared/Map/MapManager.cs @@ -272,7 +272,7 @@ namespace Robust.Shared.Map } else { - var newEnt = (Entity) _entityManager.CreateEntityUninitialized(null, entityUid); + var newEnt = (IEntity) _entityManager.CreateEntityUninitialized(null, entityUid); _mapEntities.Add(actualID, newEnt.Uid); var mapComp = newEnt.AddComponent(); @@ -300,7 +300,7 @@ namespace Robust.Shared.Map DebugTools.Assert(_dbgGuardRunning); #endif - var newEntity = (Entity) _entityManager.CreateEntityUninitialized(null); + var newEntity = (IEntity) _entityManager.CreateEntityUninitialized(null); SetMapEntity(mapId, newEntity); _entityManager.InitializeComponents(newEntity.Uid); @@ -464,7 +464,7 @@ namespace Robust.Shared.Map } else { - var gridEnt = (Entity) EntityManager.CreateEntityUninitialized(null, euid); + var gridEnt = (IEntity) EntityManager.CreateEntityUninitialized(null, euid); grid.GridEntityId = gridEnt.Uid; diff --git a/Robust.Shared/Prototypes/EntityPrototype.cs b/Robust.Shared/Prototypes/EntityPrototype.cs index 2a44d3de4..bdbdbecc1 100644 --- a/Robust.Shared/Prototypes/EntityPrototype.cs +++ b/Robust.Shared/Prototypes/EntityPrototype.cs @@ -174,7 +174,7 @@ namespace Robust.Shared.Prototypes return true; } - public void UpdateEntity(Entity entity) + public void UpdateEntity(IEntity entity) { if (ID != entity.Prototype?.ID) { @@ -229,7 +229,7 @@ namespace Robust.Shared.Prototypes entity.MetaData.EntityPrototype = this; } - internal static void LoadEntity(EntityPrototype? prototype, Entity entity, IComponentFactory factory, + internal static void LoadEntity(EntityPrototype? prototype, IEntity entity, IComponentFactory factory, IEntityLoadContext? context) //yeah officer this method right here { /*YamlObjectSerializer.Context? defaultContext = null; @@ -271,7 +271,7 @@ namespace Robust.Shared.Prototypes } } - private static void EnsureCompExistsAndDeserialize(Entity entity, IComponentFactory factory, string compName, + private static void EnsureCompExistsAndDeserialize(IEntity entity, IComponentFactory factory, string compName, IComponent data, ISerializationContext? context) { var compType = factory.GetRegistration(compName).Type; diff --git a/Robust.Shared/Prototypes/PrototypeManager.cs b/Robust.Shared/Prototypes/PrototypeManager.cs index 842466a5d..54205863a 100644 --- a/Robust.Shared/Prototypes/PrototypeManager.cs +++ b/Robust.Shared/Prototypes/PrototypeManager.cs @@ -364,7 +364,7 @@ namespace Robust.Shared.Prototypes foreach (var entity in _entityManager.GetEntities() .Where(e => e.Prototype != null && e.Prototype.ID == prototype)) { - ((EntityPrototype) entityPrototypes[prototype]).UpdateEntity((Entity) entity); + ((EntityPrototype) entityPrototypes[prototype]).UpdateEntity((IEntity) entity); } } #endif diff --git a/Robust.Shared/Serialization/RobustSerializer.cs b/Robust.Shared/Serialization/RobustSerializer.cs index 971faff0e..84da2288d 100644 --- a/Robust.Shared/Serialization/RobustSerializer.cs +++ b/Robust.Shared/Serialization/RobustSerializer.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Reflection; +using Robust.Shared.GameObjects; using Robust.Shared.Log; using Robust.Shared.Maths; using Robust.Shared.Reflection; @@ -79,7 +80,7 @@ namespace Robust.Shared.Serialization var settings = new Settings { - CustomTypeSerializers = new[] {_mappedStringSerializer.TypeSerializer} + CustomTypeSerializers = new[] {_mappedStringSerializer.TypeSerializer, new IEntitySerializer()} }; _serializer = new Serializer(types, settings); _serializableTypes = new HashSet(_serializer.GetTypeMap().Keys); diff --git a/Robust.Shared/ViewVariables/ViewVariablesBlob.cs b/Robust.Shared/ViewVariables/ViewVariablesBlob.cs index 117cfd303..a2080c843 100644 --- a/Robust.Shared/ViewVariables/ViewVariablesBlob.cs +++ b/Robust.Shared/ViewVariables/ViewVariablesBlob.cs @@ -172,7 +172,7 @@ namespace Robust.Shared.ViewVariables } /// - /// Contains the type names of the components of a remote . + /// Contains the type names of the components of a remote . /// Requested by . /// [Serializable, NetSerializable] @@ -198,7 +198,7 @@ namespace Robust.Shared.ViewVariables } /// - /// Contains a list of server-side component that can be added to a remote . + /// Contains a list of server-side component that can be added to a remote . /// Requested by . /// [Serializable, NetSerializable] diff --git a/Robust.UnitTesting/Shared/GameObjects/EntityEventBusTests.ComponentEvent.cs b/Robust.UnitTesting/Shared/GameObjects/EntityEventBusTests.ComponentEvent.cs index 3172ef7e4..c4a074530 100644 --- a/Robust.UnitTesting/Shared/GameObjects/EntityEventBusTests.ComponentEvent.cs +++ b/Robust.UnitTesting/Shared/GameObjects/EntityEventBusTests.ComponentEvent.cs @@ -116,12 +116,12 @@ namespace Robust.UnitTesting.Shared.GameObjects // Arrange var entUid = new EntityUid(7); var compInstance = new MetaDataComponent(); - var mockEnt = new Mock(); - mockEnt.SetupGet(m => m.Uid).Returns(entUid); - compInstance.Owner = mockEnt.Object; var entManMock = new Mock(); + var ent = new IEntity(entUid); + compInstance.Owner = ent; + var compRegistration = new Mock(); var compFacMock = new Mock(); diff --git a/Robust.UnitTesting/Shared/Map/MapManager_Tests.cs b/Robust.UnitTesting/Shared/Map/MapManager_Tests.cs index 48479cb53..3c0352460 100644 --- a/Robust.UnitTesting/Shared/Map/MapManager_Tests.cs +++ b/Robust.UnitTesting/Shared/Map/MapManager_Tests.cs @@ -87,7 +87,7 @@ namespace Robust.UnitTesting.Shared.Map mapMan.CreateNewMapEntity(MapId.Nullspace); - var oldEntity = (Entity)entMan.CreateEntityUninitialized(null, MapCoordinates.Nullspace); + var oldEntity = entMan.CreateEntityUninitialized(null, MapCoordinates.Nullspace); entMan.InitializeComponents(oldEntity.Uid); mapMan.Restart();