Add prototype serialization tests. (#18458)

Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
This commit is contained in:
Leon Friedrich
2023-08-06 14:47:45 +12:00
committed by GitHub
parent b97be440dd
commit 28a5e32f5e
18 changed files with 138 additions and 53 deletions

View File

@@ -1,4 +1,6 @@
using Robust.Shared.Prototypes;
using System.Linq;
using Robust.Shared.Prototypes;
using Robust.Shared.Utility;
namespace Content.Shared.Alert
{
@@ -14,22 +16,25 @@ namespace Content.Shared.Alert
public string ID { get; } = default!;
[DataField("order")]
private List<(string type, string alert)> Order
private (string type, string alert)[] Order
{
// why would paul do this to me.
get
{
var res = new List<(string, string)>(_typeToIdx.Count + _categoryToIdx.Count);
var res = new (string, string)[_typeToIdx.Count + _categoryToIdx.Count];
foreach (var (type, id) in _typeToIdx)
{
res.Insert(id, ("alertType", type.ToString()));
res[id] = ("alertType", type.ToString());
}
foreach (var (category, id) in _categoryToIdx)
{
res.Insert(id, ("category", category.ToString()));
res[id] = ("category", category.ToString());
}
DebugTools.Assert(res.All(x => x != default));
return res;
}
set

View File

@@ -19,6 +19,7 @@ public sealed class BodyPrototypeSerializer : ITypeReader<BodyPrototype, Mapping
{
var nodes = new List<ValidationNode>();
var prototypes = dependencies.Resolve<IPrototypeManager>();
var factory = dependencies.Resolve<IComponentFactory>();
var connections = new List<string>();
if (slot.TryGet("connections", out SequenceDataNode? connectionsNode))
@@ -57,7 +58,7 @@ public sealed class BodyPrototypeSerializer : ITypeReader<BodyPrototype, Mapping
continue;
}
if (!organPrototype.HasComponent<OrganComponent>())
if (!organPrototype.HasComponent<OrganComponent>(factory))
{
nodes.Add(new ErrorNode(value, $"Organ {organ.Value} does not have a body component"));
}

View File

@@ -6,6 +6,7 @@ using Content.Shared.Chemistry.Components;
using Content.Shared.Chemistry.Reaction;
using Content.Shared.Database;
using Content.Shared.FixedPoint;
using Content.Shared.Nutrition;
using Robust.Shared.Audio;
using Robust.Shared.Map;
using Robust.Shared.Prototypes;
@@ -60,8 +61,8 @@ namespace Content.Shared.Chemistry.Reagent
[DataField("recognizable")]
public bool Recognizable = false;
[DataField("flavor")]
public string Flavor { get; } = default!;
[DataField("flavor", customTypeSerializer:typeof(PrototypeIdSerializer<FlavorPrototype>))]
public string? Flavor;
/// <summary>
/// There must be at least this much quantity in a solution to be tasted.

View File

@@ -0,0 +1,22 @@
using Robust.Shared.Prototypes;
namespace Content.Shared.Nutrition;
[Prototype("flavor")]
public sealed class FlavorPrototype : IPrototype
{
[IdDataField]
public string ID { get; } = default!;
[DataField("flavorType")]
public FlavorType FlavorType { get; } = FlavorType.Base;
[DataField("description")]
public string FlavorDescription { get; } = default!;
}
public enum FlavorType : byte
{
Base,
Complex
}