From 5ed935f30aa0322ec6d3ed816cd172f2cc64c7e9 Mon Sep 17 00:00:00 2001 From: DrSmugleaf Date: Sun, 28 Mar 2021 08:21:32 +0200 Subject: [PATCH] Add entity list prototype (#3720) * Add entity list prototype * Turn entities property into a method --- .../EntityList/EntityListPrototype.cs | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 Content.Shared/Prototypes/EntityList/EntityListPrototype.cs diff --git a/Content.Shared/Prototypes/EntityList/EntityListPrototype.cs b/Content.Shared/Prototypes/EntityList/EntityListPrototype.cs new file mode 100644 index 0000000000..26b8b4d581 --- /dev/null +++ b/Content.Shared/Prototypes/EntityList/EntityListPrototype.cs @@ -0,0 +1,32 @@ +using System.Collections.Generic; +using System.Collections.Immutable; +using Robust.Shared.IoC; +using Robust.Shared.Prototypes; +using Robust.Shared.Serialization.Manager.Attributes; +using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.List; +using Robust.Shared.ViewVariables; + +namespace Content.Shared.Prototypes.EntityList +{ + [Prototype("entityList")] + public class EntityListPrototype : IPrototype + { + [ViewVariables] + [field: DataField("id", required: true)] + public string ID { get; } = default!; + + [ViewVariables] + [field: DataField("entities", customTypeSerializer: typeof(PrototypeIdListSerializer))] + public ImmutableList EntityIds { get; } = ImmutableList.Empty; + + public IEnumerable Entities(IPrototypeManager? prototypeManager = null) + { + prototypeManager ??= IoCManager.Resolve(); + + foreach (var entityId in EntityIds) + { + yield return prototypeManager.Index(entityId); + } + } + } +}