Inline Prototype

This commit is contained in:
Vera Aguilera Puerto
2021-12-03 11:13:58 +01:00
parent cd43196ea8
commit 70bbd8c502
18 changed files with 54 additions and 38 deletions

View File

@@ -18,6 +18,7 @@ using Robust.Shared.Input.Binding;
using Robust.Shared.IoC;
using Robust.Shared.Log;
using Robust.Shared.Maths;
using Robust.Shared.Prototypes;
using Robust.Shared.Timing;
namespace Content.Client.ContextMenu.UI
{
@@ -84,7 +85,7 @@ namespace Content.Client.ContextMenu.UI
var entitySpriteStates = GroupEntities(entities);
var orderedStates = entitySpriteStates.ToList();
orderedStates.Sort((x, y) => string.CompareOrdinal(x.First().Prototype?.Name, y.First().Prototype?.Name));
orderedStates.Sort((x, y) => string.CompareOrdinal(IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(x.First().Uid).EntityPrototype?.Name, IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(y.First().Uid).EntityPrototype?.Name));
Elements.Clear();
AddToUI(orderedStates);

View File

@@ -3,6 +3,8 @@ using System.Collections.Generic;
using System.Linq;
using Robust.Client.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Prototypes;
namespace Content.Client.ContextMenu.UI
{
@@ -20,7 +22,7 @@ namespace Content.Client.ContextMenu.UI
{
if (GroupingContextMenuType == 0)
{
var newEntities = entities.GroupBy(e => e.Name + (e.Prototype?.ID ?? string.Empty)).ToList();
var newEntities = entities.GroupBy(e => e.Name + (IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(e.Uid).EntityPrototype?.ID ?? string.Empty)).ToList();
return newEntities.Select(grp => grp.ToList()).ToList();
}
else
@@ -34,7 +36,7 @@ namespace Content.Client.ContextMenu.UI
{
private static readonly List<Func<IEntity, IEntity, bool>> EqualsList = new()
{
(a, b) => a.Prototype!.ID == b.Prototype!.ID,
(a, b) => IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(a.Uid).EntityPrototype!.ID == IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(b.Uid).EntityPrototype!.ID,
(a, b) =>
{
a.TryGetComponent<ISpriteComponent>(out var spriteA);
@@ -51,7 +53,7 @@ namespace Content.Client.ContextMenu.UI
};
private static readonly List<Func<IEntity, int>> GetHashCodeList = new()
{
e => EqualityComparer<string>.Default.GetHashCode(e.Prototype!.ID),
e => EqualityComparer<string>.Default.GetHashCode(IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(e.Uid).EntityPrototype!.ID),
e =>
{
var hash = 0;

View File

@@ -73,12 +73,12 @@ namespace Content.IntegrationTests.Tests.Destructible
foreach (var entity in entitiesInRange)
{
if (entity.Prototype == null)
if (IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(entity.Uid).EntityPrototype == null)
{
continue;
}
if (entity.Prototype.Name != SpawnedEntityId)
if (IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(entity.Uid).EntityPrototype.Name != SpawnedEntityId)
{
continue;
}

View File

@@ -8,6 +8,7 @@ using NUnit.Framework;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Prototypes;
using static Content.Shared.Inventory.EquipmentSlotDefines;
namespace Content.IntegrationTests.Tests
@@ -71,7 +72,7 @@ namespace Content.IntegrationTests.Tests
// Do we actually have the uniform equipped?
Assert.That(inventory.TryGetSlotItem(Slots.INNERCLOTHING, out ItemComponent uniform));
Assert.That(uniform.Owner.Prototype != null && uniform.Owner.Prototype.ID == "InventoryJumpsuitJanitorDummy");
Assert.That(IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(uniform.Owner.Uid).EntityPrototype != null && IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(uniform.Owner.Uid).EntityPrototype.ID == "InventoryJumpsuitJanitorDummy");
EntitySystem.Get<StunSystem>().TryStun(human.Uid, TimeSpan.FromSeconds(1f));
@@ -84,7 +85,7 @@ namespace Content.IntegrationTests.Tests
// Let's try skipping the interaction check and see if it equips it!
Assert.That(inventory.SpawnItemInSlot(Slots.IDCARD, "InventoryIDCardDummy"));
Assert.That(inventory.TryGetSlotItem(Slots.IDCARD, out ItemComponent id));
Assert.That(id.Owner.Prototype != null && id.Owner.Prototype.ID == "InventoryIDCardDummy");
Assert.That(IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(id.Owner.Uid).EntityPrototype != null && IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(id.Owner.Uid).EntityPrototype.ID == "InventoryIDCardDummy");
});
await server.WaitIdleAsync();

View File

@@ -3,6 +3,7 @@ using Robust.Shared.Console;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using System.Linq;
using Robust.Shared.Prototypes;
namespace Content.Server.Administration.Commands
{
@@ -23,7 +24,7 @@ namespace Content.Server.Administration.Commands
var id = args[0].ToLower();
var entityManager = IoCManager.Resolve<IEntityManager>();
var entities = entityManager.GetEntities().Where(e => e.Prototype?.ID.ToLower() == id);
var entities = entityManager.GetEntities().Where(e => IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(e.Uid).EntityPrototype?.ID.ToLower() == id);
var i = 0;
foreach (var entity in entities)

View File

@@ -5,6 +5,7 @@ using Content.Shared.Administration;
using Robust.Shared.Console;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Prototypes;
namespace Content.Server.Administration.Commands
{
@@ -52,12 +53,12 @@ namespace Content.Server.Administration.Commands
foreach (var entity in entitiesWithAllComponents)
{
if (entity.Prototype == null)
if (IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(entity.Uid).EntityPrototype == null)
{
continue;
}
entityIds.Add(entity.Prototype.ID);
entityIds.Add(IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(entity.Uid).EntityPrototype.ID);
}
if (entityIds.Count == 0)

View File

@@ -32,7 +32,7 @@ namespace Content.Server.Administration.Commands
foreach (var entity in entityManager.GetEntities())
{
if (checkPrototype && entity.Prototype != prototype || entity.Prototype == null)
if (checkPrototype && IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(entity.Uid).EntityPrototype != prototype || IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(entity.Uid).EntityPrototype == null)
{
continue;
}
@@ -41,7 +41,7 @@ namespace Content.Server.Administration.Commands
foreach (var component in entity.GetAllComponents())
{
if (entity.Prototype.Components.ContainsKey(component.Name))
if (IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(entity.Uid).EntityPrototype.Components.ContainsKey(component.Name))
continue;
entityManager.RemoveComponent(entity.Uid, component);

View File

@@ -62,7 +62,7 @@ namespace Content.Server.Chemistry.Components
/// </summary>
public void Spread()
{
if (Owner.Prototype == null)
if (IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(Owner.Uid).EntityPrototype == null)
{
Logger.Error("AreaEffectComponent needs its owner to be spawned by a prototype.");
return;
@@ -83,7 +83,7 @@ namespace Content.Server.Chemistry.Components
return;
}
var newEffect = IoCManager.Resolve<IEntityManager>().SpawnEntity(Owner.Prototype.ID, grid.DirectionToGrid(coords, dir));
var newEffect = IoCManager.Resolve<IEntityManager>().SpawnEntity(IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(Owner.Uid).EntityPrototype.ID, grid.DirectionToGrid(coords, dir));
if (!newEffect.TryGetComponent(out SolutionAreaEffectComponent? effectComponent))
{

View File

@@ -74,7 +74,7 @@ namespace Content.Server.Construction.Commands
continue;
}
var prototype = childEntity.Prototype;
var prototype = IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(childEntity.Uid).EntityPrototype;
while (true)
{
if (prototype?.Parent == null)

View File

@@ -4,6 +4,7 @@ using Content.Server.Stack;
using Robust.Shared.Containers;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.Manager.Attributes;
namespace Content.Server.Construction.Components
@@ -66,7 +67,7 @@ namespace Content.Server.Construction.Components
if (!_boardContainer.Insert(board))
{
throw new Exception($"Couldn't insert board with prototype {BoardPrototype} to machine with prototype {Owner.Prototype?.ID ?? "N/A"}!");
throw new Exception($"Couldn't insert board with prototype {BoardPrototype} to machine with prototype {IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(Owner.Uid).EntityPrototype?.ID ?? "N/A"}!");
}
if (!board.TryGetComponent<MachineBoardComponent>(out var machineBoard))
@@ -81,7 +82,7 @@ namespace Content.Server.Construction.Components
var p = entityManager.SpawnEntity(MachinePartComponent.Prototypes[part], Owner.Transform.Coordinates);
if (!partContainer.Insert(p))
throw new Exception($"Couldn't insert machine part of type {part} to machine with prototype {Owner.Prototype?.ID ?? "N/A"}!");
throw new Exception($"Couldn't insert machine part of type {part} to machine with prototype {IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(Owner.Uid).EntityPrototype?.ID ?? "N/A"}!");
}
}
@@ -90,7 +91,7 @@ namespace Content.Server.Construction.Components
var stack = EntitySystem.Get<StackSystem>().Spawn(amount, stackType, Owner.Transform.Coordinates);
if (!partContainer.Insert(IoCManager.Resolve<IEntityManager>().GetEntity(stack)))
throw new Exception($"Couldn't insert machine material of type {stackType} to machine with prototype {Owner.Prototype?.ID ?? "N/A"}");
throw new Exception($"Couldn't insert machine material of type {stackType} to machine with prototype {IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(Owner.Uid).EntityPrototype?.ID ?? "N/A"}");
}
foreach (var (compName, info) in machineBoard.ComponentRequirements)
@@ -100,7 +101,7 @@ namespace Content.Server.Construction.Components
var c = entityManager.SpawnEntity(info.DefaultPrototype, Owner.Transform.Coordinates);
if(!partContainer.Insert(c))
throw new Exception($"Couldn't insert machine component part with default prototype '{compName}' to machine with prototype {Owner.Prototype?.ID ?? "N/A"}");
throw new Exception($"Couldn't insert machine component part with default prototype '{compName}' to machine with prototype {IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(Owner.Uid).EntityPrototype?.ID ?? "N/A"}");
}
}
@@ -111,7 +112,7 @@ namespace Content.Server.Construction.Components
var c = entityManager.SpawnEntity(info.DefaultPrototype, Owner.Transform.Coordinates);
if(!partContainer.Insert(c))
throw new Exception($"Couldn't insert machine component part with default prototype '{tagName}' to machine with prototype {Owner.Prototype?.ID ?? "N/A"}");
throw new Exception($"Couldn't insert machine component part with default prototype '{tagName}' to machine with prototype {IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(Owner.Uid).EntityPrototype?.ID ?? "N/A"}");
}
}
}

View File

@@ -51,13 +51,13 @@ namespace Content.Server.Construction
{
if (GetCurrentGraph(uid, construction) is not {} graph)
{
_sawmill.Warning($"Prototype {construction.Owner.Prototype?.ID}'s construction component has an invalid graph specified.");
_sawmill.Warning($"Prototype {IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(construction.Owner.Uid).EntityPrototype?.ID}'s construction component has an invalid graph specified.");
return;
}
if (GetNodeFromGraph(graph, construction.Node) is not {} node)
{
_sawmill.Warning($"Prototype {construction.Owner.Prototype?.ID}'s construction component has an invalid node specified.");
_sawmill.Warning($"Prototype {IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(construction.Owner.Uid).EntityPrototype?.ID}'s construction component has an invalid node specified.");
return;
}
@@ -66,7 +66,7 @@ namespace Content.Server.Construction
{
if (GetEdgeFromNode(node, edgeIndex) is not {} currentEdge)
{
_sawmill.Warning($"Prototype {construction.Owner.Prototype?.ID}'s construction component has an invalid edge index specified.");
_sawmill.Warning($"Prototype {IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(construction.Owner.Uid).EntityPrototype?.ID}'s construction component has an invalid edge index specified.");
return;
}
@@ -77,7 +77,7 @@ namespace Content.Server.Construction
{
if (GetNodeFromGraph(graph, targetNodeId) is not { } targetNode)
{
_sawmill.Warning($"Prototype {construction.Owner.Prototype?.ID}'s construction component has an invalid target node specified.");
_sawmill.Warning($"Prototype {IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(construction.Owner.Uid).EntityPrototype?.ID}'s construction component has an invalid target node specified.");
return;
}

View File

@@ -1,4 +1,7 @@
using Robust.Shared.Containers;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Prototypes;
namespace Content.Server.Containers
{
@@ -11,7 +14,7 @@ namespace Content.Server.Containers
{
foreach (var entity in container.ContainedEntities)
{
if (entity.Prototype?.ID == prototypeId) total++;
if (IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(entity.Uid).EntityPrototype?.ID == prototypeId) total++;
if(!entity.TryGetComponent<ContainerManagerComponent>(out var component)) continue;
total += component.CountPrototypeOccurencesRecursive(prototypeId);
}

View File

@@ -26,6 +26,7 @@ using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Robust.Shared.Player;
using Robust.Shared.Prototypes;
namespace Content.Server.Fluids.EntitySystems
{
@@ -328,7 +329,7 @@ namespace Content.Server.Fluids.EntitySystems
}
puddle ??= () =>
IoCManager.Resolve<IEntityManager>().SpawnEntity(puddleComponent.Owner.Prototype?.ID,
IoCManager.Resolve<IEntityManager>().SpawnEntity(IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(puddleComponent.Owner.Uid).EntityPrototype?.ID,
mapGrid.DirectionToGrid(coords, direction))
.GetComponent<PuddleComponent>();

View File

@@ -6,8 +6,10 @@ using Content.Server.Administration;
using Content.Shared.Administration;
using Robust.Server.Player;
using Robust.Shared.Console;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Prototypes;
using Robust.Shared.Timing;
using Robust.Shared.Utility;
@@ -74,7 +76,8 @@ namespace Content.Server.GameTicking.Commands
shell.ExecuteCommand($"addmap {mapId} false");
shell.ExecuteCommand($"loadbp {mapId} \"{CommandParsing.Escape(mapName)}\" true");
if (player.AttachedEntity?.Prototype?.ID != "AdminObserver")
IEntity? tempQualifier = player.AttachedEntity;
if ((tempQualifier != null ? IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(tempQualifier.Uid).EntityPrototype : null)?.ID != "AdminObserver")
shell.ExecuteCommand("aghost");
shell.ExecuteCommand($"tp 0 0 {mapId}");

View File

@@ -29,6 +29,7 @@ using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Player;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.ViewVariables;
@@ -311,18 +312,18 @@ namespace Content.Server.Kitchen.Components
var solidsDict = new Dictionary<string, int>();
foreach (var item in _storage.ContainedEntities)
{
if (item.Prototype == null)
if (IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(item.Uid).EntityPrototype == null)
{
continue;
}
if (solidsDict.ContainsKey(item.Prototype.ID))
if (solidsDict.ContainsKey(IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(item.Uid).EntityPrototype.ID))
{
solidsDict[item.Prototype.ID]++;
solidsDict[IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(item.Uid).EntityPrototype.ID]++;
}
else
{
solidsDict.Add(item.Prototype.ID, 1);
solidsDict.Add(IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(item.Uid).EntityPrototype.ID, 1);
}
}
@@ -450,12 +451,12 @@ namespace Content.Server.Kitchen.Components
{
foreach (var item in _storage.ContainedEntities)
{
if (item.Prototype == null)
if (IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(item.Uid).EntityPrototype == null)
{
continue;
}
if (item.Prototype.ID == recipeSolid.Key)
if (IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(item.Uid).EntityPrototype.ID == recipeSolid.Key)
{
_storage.Remove(item);
item.Delete();

View File

@@ -50,7 +50,7 @@ namespace Content.Server.Stack
// Get a prototype ID to spawn the new entity. Null is also valid, although it should rarely be picked...
var prototype = _prototypeManager.TryIndex<StackPrototype>(stack.StackTypeId, out var stackType)
? stackType.Spawn
: stack.Owner.Prototype?.ID;
: IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(stack.Owner.Uid).EntityPrototype?.ID;
// Try to remove the amount of things we want to split from the original stack...
if (!Use(uid, amount, stack))

View File

@@ -330,7 +330,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
else
{
projectile =
IoCManager.Resolve<IEntityManager>().SpawnEntity(baseProjectile.Prototype?.ID, baseProjectile.Transform.Coordinates);
IoCManager.Resolve<IEntityManager>().SpawnEntity(IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(baseProjectile.Uid).EntityPrototype?.ID, baseProjectile.Transform.Coordinates);
}
firedProjectiles[i] = projectile.Uid;

View File

@@ -8,6 +8,7 @@ using Robust.Shared.GameObjects;
using Robust.Shared.GameStates;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.Utility;
@@ -113,7 +114,7 @@ namespace Content.Shared.Body.Components
protected virtual void OnAddMechanism(SharedMechanismComponent mechanism)
{
var prototypeId = mechanism.Owner.Prototype!.ID;
var prototypeId = IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(mechanism.Owner.Uid).EntityPrototype!.ID;
if (!_mechanismIds.Contains(prototypeId))
{
@@ -128,7 +129,7 @@ namespace Content.Shared.Body.Components
protected virtual void OnRemoveMechanism(SharedMechanismComponent mechanism)
{
_mechanismIds.Remove(mechanism.Owner.Prototype!.ID);
_mechanismIds.Remove(IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(mechanism.Owner.Uid).EntityPrototype!.ID);
mechanism.Part = null;
SizeUsed -= mechanism.Size;