From f77aff7b94400ff7dc7fa49c3246dba23c22d8af Mon Sep 17 00:00:00 2001 From: Paul Ritter Date: Mon, 1 Aug 2022 14:39:37 +0200 Subject: [PATCH] prototype composition (#9979) & updates submodule * prototype composition * a * fixes build * fixes test * updates submodule Co-authored-by: Paul Ritter --- Content.Server/Wires/WireLayout.cs | 5 +-- Content.Server/Wires/WiresComponent.cs | 3 +- Content.Server/Wires/WiresSystem.cs | 34 ++++++------------- .../Chemistry/Reagent/ReagentPrototype.cs | 5 +-- Content.Shared/Disease/DiseasePrototype.cs | 6 ++-- Content.Shared/Maps/ContentTileDefinition.cs | 5 +-- Content.Shared/Materials/MaterialPrototype.cs | 5 +-- .../Polymorph/PolymorphPrototype.cs | 5 +-- RobustToolbox | 2 +- 9 files changed, 33 insertions(+), 37 deletions(-) diff --git a/Content.Server/Wires/WireLayout.cs b/Content.Server/Wires/WireLayout.cs index 900fced5b7..c93f632ac6 100644 --- a/Content.Server/Wires/WireLayout.cs +++ b/Content.Server/Wires/WireLayout.cs @@ -1,5 +1,6 @@ using Robust.Shared.Prototypes; using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype; +using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Array; namespace Content.Server.Wires; @@ -16,8 +17,8 @@ public sealed class WireLayoutPrototype : IPrototype, IInheritingPrototype [IdDataFieldAttribute] public string ID { get; } = default!; - [ParentDataField(typeof(AbstractPrototypeIdSerializer))] - public string? Parent { get; } = default!; + [ParentDataField(typeof(AbstractPrototypeIdArraySerializer))] + public string[]? Parents { get; private set; } [AbstractDataField] public bool Abstract { get; } diff --git a/Content.Server/Wires/WiresComponent.cs b/Content.Server/Wires/WiresComponent.cs index 69d9a90762..d9a10c2a61 100644 --- a/Content.Server/Wires/WiresComponent.cs +++ b/Content.Server/Wires/WiresComponent.cs @@ -1,4 +1,5 @@ using Robust.Shared.Audio; +using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype; namespace Content.Server.Wires; @@ -28,7 +29,7 @@ public sealed class WiresComponent : Component /// The layout ID of this entity's wires. /// [ViewVariables] - [DataField("LayoutId", required: true)] + [DataField("LayoutId", customTypeSerializer: typeof(PrototypeIdSerializer), required: true)] public string LayoutId { get; set; } = default!; /// diff --git a/Content.Server/Wires/WiresSystem.cs b/Content.Server/Wires/WiresSystem.cs index 3bf987dd6d..3d452582fd 100644 --- a/Content.Server/Wires/WiresSystem.cs +++ b/Content.Server/Wires/WiresSystem.cs @@ -66,30 +66,17 @@ public sealed class WiresSystem : EntitySystem WireLayout? layout = null; List? wireSet = null; - if (wires.LayoutId != null) + if (!wires.AlwaysRandomize) { - if (!wires.AlwaysRandomize) - { - 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; - } + TryGetLayout(wires.LayoutId, out layout); + } + // 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(wires.LayoutId)) + { if (layoutPrototype.Wires != null) { foreach (var wire in layoutPrototype.Wires) @@ -98,6 +85,7 @@ public sealed class WiresSystem : EntitySystem } wireSet = CreateWireSet(uid, layout, layoutPrototype.Wires, layoutPrototype.DummyWires); + break; } } @@ -108,7 +96,7 @@ public sealed class WiresSystem : EntitySystem wires.WiresList.AddRange(wireSet); - Dictionary types = new Dictionary(); + var types = new Dictionary(); if (layout != null) { diff --git a/Content.Shared/Chemistry/Reagent/ReagentPrototype.cs b/Content.Shared/Chemistry/Reagent/ReagentPrototype.cs index b1c27a031e..30e3a70d91 100644 --- a/Content.Shared/Chemistry/Reagent/ReagentPrototype.cs +++ b/Content.Shared/Chemistry/Reagent/ReagentPrototype.cs @@ -9,6 +9,7 @@ using Robust.Shared.Map; using Robust.Shared.Prototypes; using Robust.Shared.Random; 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; namespace Content.Shared.Chemistry.Reagent @@ -30,8 +31,8 @@ namespace Content.Shared.Chemistry.Reagent [DataField("group")] public string Group { get; } = "Unknown"; - [ParentDataFieldAttribute(typeof(AbstractPrototypeIdSerializer))] - public string? Parent { get; private set; } + [ParentDataFieldAttribute(typeof(AbstractPrototypeIdArraySerializer))] + public string[]? Parents { get; private set; } [NeverPushInheritance] [AbstractDataFieldAttribute] diff --git a/Content.Shared/Disease/DiseasePrototype.cs b/Content.Shared/Disease/DiseasePrototype.cs index fc680fc0a3..67347a6fdf 100644 --- a/Content.Shared/Disease/DiseasePrototype.cs +++ b/Content.Shared/Disease/DiseasePrototype.cs @@ -1,5 +1,7 @@ using Robust.Shared.Prototypes; 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 { @@ -18,8 +20,8 @@ namespace Content.Shared.Disease [DataField("name")] public string Name { get; } = string.Empty; - [ParentDataFieldAttribute(typeof(AbstractPrototypeIdSerializer))] - public string? Parent { get; private set; } + [ParentDataFieldAttribute(typeof(AbstractPrototypeIdArraySerializer))] + public string[]? Parents { get; private set; } [NeverPushInheritance] [AbstractDataFieldAttribute] diff --git a/Content.Shared/Maps/ContentTileDefinition.cs b/Content.Shared/Maps/ContentTileDefinition.cs index fa623249eb..b93a74faf6 100644 --- a/Content.Shared/Maps/ContentTileDefinition.cs +++ b/Content.Shared/Maps/ContentTileDefinition.cs @@ -4,6 +4,7 @@ using Robust.Shared.Audio; using Robust.Shared.Map; using Robust.Shared.Prototypes; using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype; +using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Array; namespace Content.Shared.Maps { @@ -11,8 +12,8 @@ namespace Content.Shared.Maps [Prototype("tile")] public sealed class ContentTileDefinition : IPrototype, IInheritingPrototype, ITileDefinition { - [ParentDataFieldAttribute(typeof(AbstractPrototypeIdSerializer))] - public string? Parent { get; private set; } + [ParentDataFieldAttribute(typeof(AbstractPrototypeIdArraySerializer))] + public string[]? Parents { get; private set; } [NeverPushInheritance] [AbstractDataFieldAttribute] diff --git a/Content.Shared/Materials/MaterialPrototype.cs b/Content.Shared/Materials/MaterialPrototype.cs index d49eed430a..043b94bda4 100644 --- a/Content.Shared/Materials/MaterialPrototype.cs +++ b/Content.Shared/Materials/MaterialPrototype.cs @@ -1,6 +1,7 @@ using Content.Shared.Stacks; using Robust.Shared.Prototypes; using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype; +using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Array; using Robust.Shared.Utility; namespace Content.Shared.Materials @@ -13,8 +14,8 @@ namespace Content.Shared.Materials public sealed class MaterialPrototype : IPrototype, IInheritingPrototype { [ViewVariables] - [ParentDataField(typeof(AbstractPrototypeIdSerializer))] - public string? Parent { get; } = null; + [ParentDataField(typeof(AbstractPrototypeIdArraySerializer))] + public string[]? Parents { get; } [ViewVariables] [AbstractDataFieldAttribute] diff --git a/Content.Shared/Polymorph/PolymorphPrototype.cs b/Content.Shared/Polymorph/PolymorphPrototype.cs index 53891eb8ea..a4598fa0bb 100644 --- a/Content.Shared/Polymorph/PolymorphPrototype.cs +++ b/Content.Shared/Polymorph/PolymorphPrototype.cs @@ -1,5 +1,6 @@ using Robust.Shared.Prototypes; using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype; +using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Array; namespace Content.Shared.Polymorph { @@ -17,8 +18,8 @@ namespace Content.Shared.Polymorph [DataField("name")] public string Name { get; } = string.Empty; - [ParentDataField(typeof(AbstractPrototypeIdSerializer))] - public string? Parent { get; private set; } + [ParentDataField(typeof(AbstractPrototypeIdArraySerializer))] + public string[]? Parents { get; private set; } [NeverPushInheritance] [AbstractDataFieldAttribute] diff --git a/RobustToolbox b/RobustToolbox index 9f25c14707..2decf31a78 160000 --- a/RobustToolbox +++ b/RobustToolbox @@ -1 +1 @@ -Subproject commit 9f25c14707ca8bbb04f3151ca02d99d86558fc40 +Subproject commit 2decf31a78e3c79e7dfaccf701917f5e83d939b3