prototype composition (#9979) & updates submodule

* prototype composition

* a

* fixes build

* fixes test

* updates submodule

Co-authored-by: Paul Ritter <ritter.paul1@gmail.com>
This commit is contained in:
Paul Ritter
2022-08-01 14:39:37 +02:00
committed by GitHub
parent aae6da27f9
commit f77aff7b94
9 changed files with 33 additions and 37 deletions

View File

@@ -1,5 +1,6 @@
using Robust.Shared.Prototypes; using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype; using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Array;
namespace Content.Server.Wires; namespace Content.Server.Wires;
@@ -16,8 +17,8 @@ public sealed class WireLayoutPrototype : IPrototype, IInheritingPrototype
[IdDataFieldAttribute] [IdDataFieldAttribute]
public string ID { get; } = default!; public string ID { get; } = default!;
[ParentDataField(typeof(AbstractPrototypeIdSerializer<WireLayoutPrototype>))] [ParentDataField(typeof(AbstractPrototypeIdArraySerializer<WireLayoutPrototype>))]
public string? Parent { get; } = default!; public string[]? Parents { get; private set; }
[AbstractDataField] [AbstractDataField]
public bool Abstract { get; } public bool Abstract { get; }

View File

@@ -1,4 +1,5 @@
using Robust.Shared.Audio; using Robust.Shared.Audio;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
namespace Content.Server.Wires; namespace Content.Server.Wires;
@@ -28,7 +29,7 @@ public sealed class WiresComponent : Component
/// The layout ID of this entity's wires. /// The layout ID of this entity's wires.
/// </summary> /// </summary>
[ViewVariables] [ViewVariables]
[DataField("LayoutId", required: true)] [DataField("LayoutId", customTypeSerializer: typeof(PrototypeIdSerializer<WireLayoutPrototype>), required: true)]
public string LayoutId { get; set; } = default!; public string LayoutId { get; set; } = default!;
/// <summary> /// <summary>

View File

@@ -66,30 +66,17 @@ public sealed class WiresSystem : EntitySystem
WireLayout? layout = null; WireLayout? layout = null;
List<Wire>? wireSet = null; List<Wire>? wireSet = null;
if (wires.LayoutId != null) if (!wires.AlwaysRandomize)
{ {
if (!wires.AlwaysRandomize) TryGetLayout(wires.LayoutId, out layout);
{ }
TryGetLayout(wires.LayoutId, out layout);
}
if (!_protoMan.TryIndex(wires.LayoutId, out WireLayoutPrototype? layoutPrototype))
return;
// does the prototype have a parent (and are the wires empty?) if so, we just create
// a new layout based on that
//
// TODO: Merge wire layouts...
if (!string.IsNullOrEmpty(layoutPrototype.Parent) && layoutPrototype.Wires == null)
{
var parent = layoutPrototype.Parent;
if (!_protoMan.TryIndex(parent, out WireLayoutPrototype? parentPrototype))
return;
layoutPrototype = parentPrototype;
}
// does the prototype have a parent (and are the wires empty?) if so, we just create
// a new layout based on that
//
// TODO: Merge wire layouts...
foreach (var layoutPrototype in _protoMan.EnumerateParents<WireLayoutPrototype>(wires.LayoutId))
{
if (layoutPrototype.Wires != null) if (layoutPrototype.Wires != null)
{ {
foreach (var wire in layoutPrototype.Wires) foreach (var wire in layoutPrototype.Wires)
@@ -98,6 +85,7 @@ public sealed class WiresSystem : EntitySystem
} }
wireSet = CreateWireSet(uid, layout, layoutPrototype.Wires, layoutPrototype.DummyWires); wireSet = CreateWireSet(uid, layout, layoutPrototype.Wires, layoutPrototype.DummyWires);
break;
} }
} }
@@ -108,7 +96,7 @@ public sealed class WiresSystem : EntitySystem
wires.WiresList.AddRange(wireSet); wires.WiresList.AddRange(wireSet);
Dictionary<object, int> types = new Dictionary<object, int>(); var types = new Dictionary<object, int>();
if (layout != null) if (layout != null)
{ {

View File

@@ -9,6 +9,7 @@ using Robust.Shared.Map;
using Robust.Shared.Prototypes; using Robust.Shared.Prototypes;
using Robust.Shared.Random; using Robust.Shared.Random;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype; using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Array;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Dictionary; using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Dictionary;
namespace Content.Shared.Chemistry.Reagent namespace Content.Shared.Chemistry.Reagent
@@ -30,8 +31,8 @@ namespace Content.Shared.Chemistry.Reagent
[DataField("group")] [DataField("group")]
public string Group { get; } = "Unknown"; public string Group { get; } = "Unknown";
[ParentDataFieldAttribute(typeof(AbstractPrototypeIdSerializer<ReagentPrototype>))] [ParentDataFieldAttribute(typeof(AbstractPrototypeIdArraySerializer<ReagentPrototype>))]
public string? Parent { get; private set; } public string[]? Parents { get; private set; }
[NeverPushInheritance] [NeverPushInheritance]
[AbstractDataFieldAttribute] [AbstractDataFieldAttribute]

View File

@@ -1,5 +1,7 @@
using Robust.Shared.Prototypes; using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype; using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Array;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Array;
namespace Content.Shared.Disease namespace Content.Shared.Disease
{ {
@@ -18,8 +20,8 @@ namespace Content.Shared.Disease
[DataField("name")] [DataField("name")]
public string Name { get; } = string.Empty; public string Name { get; } = string.Empty;
[ParentDataFieldAttribute(typeof(AbstractPrototypeIdSerializer<DiseasePrototype>))] [ParentDataFieldAttribute(typeof(AbstractPrototypeIdArraySerializer<DiseasePrototype>))]
public string? Parent { get; private set; } public string[]? Parents { get; private set; }
[NeverPushInheritance] [NeverPushInheritance]
[AbstractDataFieldAttribute] [AbstractDataFieldAttribute]

View File

@@ -4,6 +4,7 @@ using Robust.Shared.Audio;
using Robust.Shared.Map; using Robust.Shared.Map;
using Robust.Shared.Prototypes; using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype; using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Array;
namespace Content.Shared.Maps namespace Content.Shared.Maps
{ {
@@ -11,8 +12,8 @@ namespace Content.Shared.Maps
[Prototype("tile")] [Prototype("tile")]
public sealed class ContentTileDefinition : IPrototype, IInheritingPrototype, ITileDefinition public sealed class ContentTileDefinition : IPrototype, IInheritingPrototype, ITileDefinition
{ {
[ParentDataFieldAttribute(typeof(AbstractPrototypeIdSerializer<ContentTileDefinition>))] [ParentDataFieldAttribute(typeof(AbstractPrototypeIdArraySerializer<ContentTileDefinition>))]
public string? Parent { get; private set; } public string[]? Parents { get; private set; }
[NeverPushInheritance] [NeverPushInheritance]
[AbstractDataFieldAttribute] [AbstractDataFieldAttribute]

View File

@@ -1,6 +1,7 @@
using Content.Shared.Stacks; using Content.Shared.Stacks;
using Robust.Shared.Prototypes; using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype; using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Array;
using Robust.Shared.Utility; using Robust.Shared.Utility;
namespace Content.Shared.Materials namespace Content.Shared.Materials
@@ -13,8 +14,8 @@ namespace Content.Shared.Materials
public sealed class MaterialPrototype : IPrototype, IInheritingPrototype public sealed class MaterialPrototype : IPrototype, IInheritingPrototype
{ {
[ViewVariables] [ViewVariables]
[ParentDataField(typeof(AbstractPrototypeIdSerializer<MaterialPrototype>))] [ParentDataField(typeof(AbstractPrototypeIdArraySerializer<MaterialPrototype>))]
public string? Parent { get; } = null; public string[]? Parents { get; }
[ViewVariables] [ViewVariables]
[AbstractDataFieldAttribute] [AbstractDataFieldAttribute]

View File

@@ -1,5 +1,6 @@
using Robust.Shared.Prototypes; using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype; using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Array;
namespace Content.Shared.Polymorph namespace Content.Shared.Polymorph
{ {
@@ -17,8 +18,8 @@ namespace Content.Shared.Polymorph
[DataField("name")] [DataField("name")]
public string Name { get; } = string.Empty; public string Name { get; } = string.Empty;
[ParentDataField(typeof(AbstractPrototypeIdSerializer<PolymorphPrototype>))] [ParentDataField(typeof(AbstractPrototypeIdArraySerializer<PolymorphPrototype>))]
public string? Parent { get; private set; } public string[]? Parents { get; private set; }
[NeverPushInheritance] [NeverPushInheritance]
[AbstractDataFieldAttribute] [AbstractDataFieldAttribute]