Inline Prototype

This commit is contained in:
Vera Aguilera Puerto
2021-12-03 11:13:58 +01:00
parent 7bec76d8d1
commit 69158de99b
12 changed files with 33 additions and 35 deletions

View File

@@ -23,6 +23,7 @@ using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Network;
using Robust.Shared.Prototypes;
using Robust.Shared.Reflection;
using Robust.Shared.Serialization;
using Robust.Shared.Utility;
@@ -43,7 +44,7 @@ namespace Robust.Client.Console.Commands
foreach (var e in entityManager.GetEntities().OrderBy(e => e.Uid))
{
shell.WriteLine($"entity {e.Uid}, {e.Prototype?.ID}, {e.Transform.Coordinates}.");
shell.WriteLine($"entity {e.Uid}, {IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(e.Uid).EntityPrototype?.ID}, {e.Transform.Coordinates}.");
}
}
}
@@ -244,7 +245,7 @@ namespace Robust.Client.Console.Commands
return;
}
shell.WriteLine($"{entity.Uid}: {entity.Prototype?.ID}/{entity.Name}");
shell.WriteLine($"{entity.Uid}: {IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(entity.Uid).EntityPrototype?.ID}/{entity.Name}");
shell.WriteLine($"init/del/lmt: {entity.Initialized}/{entity.Deleted}/{entity.LastModifiedTick}");
foreach (var component in entity.GetAllComponents())
{

View File

@@ -7,6 +7,7 @@ using Robust.Shared.Input;
using Robust.Shared.IoC;
using Robust.Shared.Log;
using Robust.Shared.Players;
using Robust.Shared.Prototypes;
using Robust.Shared.Utility;
namespace Robust.Client.GameObjects
@@ -124,7 +125,7 @@ namespace Robust.Client.GameObjects
if (!entity.TryGetComponent(out InputComponent? inputComp))
{
Logger.DebugS("input.context", $"AttachedEnt has no InputComponent: entId={entity.Uid}, entProto={entity.Prototype}. Setting default \"{InputContextContainer.DefaultContextName}\" context...");
Logger.DebugS("input.context", $"AttachedEnt has no InputComponent: entId={entity.Uid}, entProto={IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(entity.Uid).EntityPrototype}. Setting default \"{InputContextContainer.DefaultContextName}\" context...");
inputMan.Contexts.SetActiveContext(InputContextContainer.DefaultContextName);
return;
}
@@ -135,7 +136,7 @@ namespace Robust.Client.GameObjects
}
else
{
Logger.ErrorS("input.context", $"Unknown context: entId={entity.Uid}, entProto={entity.Prototype}, context={inputComp.ContextName}. . Setting default \"{InputContextContainer.DefaultContextName}\" context...");
Logger.ErrorS("input.context", $"Unknown context: entId={entity.Uid}, entProto={IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(entity.Uid).EntityPrototype}, context={inputComp.ContextName}. . Setting default \"{InputContextContainer.DefaultContextName}\" context...");
inputMan.Contexts.SetActiveContext(InputContextContainer.DefaultContextName);
}
}

View File

@@ -9,6 +9,7 @@ using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Maths;
using Robust.Shared.Network;
using Robust.Shared.Prototypes;
using Robust.Shared.Timing;
using Robust.Shared.Utility;
@@ -176,7 +177,7 @@ namespace Robust.Client.GameStates
var xPos = 100;
var yPos = 10 + _lineHeight * i;
var name = $"({netEnt.Id}) {ent.Prototype?.ID}";
var name = $"({netEnt.Id}) {IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(ent.Uid).EntityPrototype?.ID}";
var color = CalcTextColor(ref netEnt);
screenHandle.DrawString(_font, new Vector2(xPos + (TrafficHistorySize + 4), yPos), name, color);
DrawTrafficBox(screenHandle, ref netEnt, xPos, yPos);

View File

@@ -4,6 +4,7 @@ using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Prototypes;
namespace Robust.Client.Placement.Modes
{
@@ -31,7 +32,7 @@ namespace Robust.Client.Placement.Modes
var mapId = MouseCoords.GetMapId(pManager.EntityManager);
var snapToEntities = IoCManager.Resolve<IEntityLookup>().GetEntitiesInRange(MouseCoords, SnapToRange)
.Where(entity => entity.Prototype == pManager.CurrentPrototype && entity.Transform.MapID == mapId)
.Where(entity => IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(entity.Uid).EntityPrototype == pManager.CurrentPrototype && entity.Transform.MapID == mapId)
.OrderBy(entity => (entity.Transform.WorldPosition - MouseCoords.ToMapPos(pManager.EntityManager)).LengthSquared)
.ToList();

View File

@@ -403,7 +403,7 @@ namespace Robust.Server.Maps
continue;
}
if (entity.Prototype == null)
if (IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(entity.Uid).EntityPrototype == null)
{
continue;
}
@@ -414,7 +414,7 @@ namespace Robust.Server.Maps
if (componentList.Any(p => p["type"].AsString() == component.Name))
{
if (entity.Prototype.Components.ContainsKey(component.Name))
if (IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(entity.Uid).EntityPrototype.Components.ContainsKey(component.Name))
{
// This component is modified by the map so we have to send state.
// Though it's still in the prototype itself so creation doesn't need to be sent.
@@ -790,15 +790,15 @@ namespace Robust.Server.Maps
{"uid", EntityUidMap[entity.Uid].ToString(CultureInfo.InvariantCulture)}
};
if (entity.Prototype != null)
if (IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(entity.Uid).EntityPrototype != null)
{
mapping.Add("type", entity.Prototype.ID);
if (!prototypeCompCache.ContainsKey(entity.Prototype.ID))
mapping.Add("type", IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(entity.Uid).EntityPrototype.ID);
if (!prototypeCompCache.ContainsKey(IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(entity.Uid).EntityPrototype.ID))
{
prototypeCompCache[entity.Prototype.ID] = new Dictionary<string, MappingDataNode>();
foreach (var (compType, comp) in entity.Prototype.Components)
prototypeCompCache[IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(entity.Uid).EntityPrototype.ID] = new Dictionary<string, MappingDataNode>();
foreach (var (compType, comp) in IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(entity.Uid).EntityPrototype.Components)
{
prototypeCompCache[entity.Prototype.ID].Add(compType, serializationManager.WriteValueAs<MappingDataNode>(comp.GetType(), comp));
prototypeCompCache[IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(entity.Uid).EntityPrototype.ID].Add(compType, serializationManager.WriteValueAs<MappingDataNode>(comp.GetType(), comp));
}
}
}
@@ -813,7 +813,7 @@ namespace Robust.Server.Maps
CurrentWritingComponent = component.Name;
var compMapping = serializationManager.WriteValueAs<MappingDataNode>(component.GetType(), component, context: this);
if (entity.Prototype != null && prototypeCompCache[entity.Prototype.ID].TryGetValue(component.Name, out var protMapping))
if (IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(entity.Uid).EntityPrototype != null && prototypeCompCache[IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(entity.Uid).EntityPrototype.ID].TryGetValue(component.Name, out var protMapping))
{
compMapping = compMapping.Except(protMapping);
if(compMapping == null) continue;
@@ -872,7 +872,7 @@ namespace Robust.Server.Maps
private bool IsMapSavable(IEntity entity)
{
if (entity.Prototype?.MapSavable == false || !GridIDMap.ContainsKey(entity.Transform.GridID))
if (IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(entity.Uid).EntityPrototype?.MapSavable == false || !GridIDMap.ContainsKey(entity.Transform.GridID))
{
return false;
}
@@ -882,7 +882,7 @@ namespace Robust.Server.Maps
var current = entity.Transform;
while (current.Parent != null)
{
if (current.Parent.Owner.Prototype?.MapSavable == false)
if (IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(current.Parent.Owner.Uid).EntityPrototype?.MapSavable == false)
{
return false;
}

View File

@@ -379,7 +379,7 @@ namespace Robust.Shared.GameObjects
var entity = AllocEntity(uid);
entity.Prototype = prototype;
IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(entity.Uid).EntityPrototype = prototype;
return entity;
}
@@ -431,7 +431,7 @@ namespace Robust.Shared.GameObjects
var entity = AllocEntity(prototypeName, uid);
try
{
EntityPrototype.LoadEntity(entity.Prototype, entity, ComponentFactory, null);
EntityPrototype.LoadEntity(IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(entity.Uid).EntityPrototype, entity, ComponentFactory, null);
return entity;
}
catch (Exception e)
@@ -445,7 +445,7 @@ namespace Robust.Shared.GameObjects
private protected void LoadEntity(IEntity entity, IEntityLoadContext? context)
{
EntityPrototype.LoadEntity(entity.Prototype, entity, ComponentFactory, context);
EntityPrototype.LoadEntity(IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(entity.Uid).EntityPrototype, entity, ComponentFactory, context);
}
private void InitializeAndStartEntity(IEntity entity, MapId mapId)

View File

@@ -23,13 +23,6 @@ namespace Robust.Shared.GameObjects
public GameTick LastModifiedTick { get => IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(Uid).EntityLastModifiedTick; internal set => IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(Uid).EntityLastModifiedTick = value; }
[ViewVariables]
public EntityPrototype? Prototype
{
get => IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(Uid).EntityPrototype;
internal set => IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(Uid).EntityPrototype = value;
}
[ViewVariables(VVAccess.ReadWrite)]
public string Description
{

View File

@@ -5,6 +5,7 @@ using System.Diagnostics.CodeAnalysis;
using Linguini.Bundle.Errors;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Components.Localization;
using Robust.Shared.IoC;
using Robust.Shared.Prototypes;
namespace Robust.Shared.Localization
@@ -29,13 +30,13 @@ namespace Robust.Shared.Localization
return true;
}
if (entity.Prototype == null)
if (IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(entity.Uid).EntityPrototype == null)
{
value = null;
return false;
}
var data = GetEntityData(entity.Prototype.ID);
var data = GetEntityData(IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(entity.Uid).EntityPrototype.ID);
return data.Attributes.TryGetValue(attribute, out value);
}

View File

@@ -176,16 +176,16 @@ namespace Robust.Shared.Prototypes
public void UpdateEntity(IEntity entity)
{
if (ID != entity.Prototype?.ID)
if (ID != IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(entity.Uid).EntityPrototype?.ID)
{
Logger.Error(
$"Reloaded prototype used to update entity did not match entity's existing prototype: Expected '{ID}', got '{entity.Prototype?.ID}'");
$"Reloaded prototype used to update entity did not match entity's existing prototype: Expected '{ID}', got '{IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(entity.Uid).EntityPrototype?.ID}'");
return;
}
var factory = IoCManager.Resolve<IComponentFactory>();
var entityManager = IoCManager.Resolve<IEntityManager>();
var oldPrototype = entity.Prototype;
var oldPrototype = IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(entity.Uid).EntityPrototype;
var oldPrototypeComponents = oldPrototype.Components.Keys
.Where(n => n != "Transform" && n != "MetaData")

View File

@@ -362,7 +362,7 @@ namespace Robust.Shared.Prototypes
foreach (var prototype in pushed[typeof(EntityPrototype)])
{
foreach (var entity in _entityManager.GetEntities()
.Where(e => e.Prototype != null && e.Prototype.ID == prototype))
.Where(e => IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(e.Uid).EntityPrototype != null && IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(e.Uid).EntityPrototype.ID == prototype))
{
((EntityPrototype) entityPrototypes[prototype]).UpdateEntity((IEntity) entity);
}

View File

@@ -65,7 +65,7 @@ namespace Robust.UnitTesting.Server.GameObjects
Assert.That(() => EntityManager.SpawnEntity(prototypeName, MapCoordinates.Nullspace),
Throws.TypeOf<EntityCreationException>());
Assert.That(EntityManager.GetEntities().Where(p => p.Prototype?.ID == prototypeName), Is.Empty);
Assert.That(EntityManager.GetEntities().Where(p => IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(p.Uid).EntityPrototype?.ID == prototypeName), Is.Empty);
}
private sealed class ThrowsInAddComponent : Component

View File

@@ -244,7 +244,7 @@ test-message-custom-attrib = { ATTRIB($entity, ""otherAttrib"") }
Assert.That(ent.Name, Is.EqualTo("A"));
Assert.That(ent.Description, Is.EqualTo("B"));
Assert.That(ent.Prototype!.EditorSuffix, Is.EqualTo("C"));
Assert.That(IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(ent.Uid).EntityPrototype!.EditorSuffix, Is.EqualTo("C"));
Assert.That(loc.GetString("test-message-gender", ("entity", ent)), Is.EqualTo("male"));
Assert.That(loc.GetString("test-message-proper", ("entity", ent)), Is.EqualTo("true"));