Skip to content

Commit 9cd8401

Browse files
Serializer improvement and cleanup (space-wizards#6674)
Co-authored-by: deltanedas <@deltanedas:goida.zip> Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
1 parent 2f6839f commit 9cd8401

37 files changed

Lines changed: 173 additions & 172 deletions

MSBuild/Robust.Engine.Version.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<Project>
22
<!-- This file automatically reset by Tools/version.py -->
3-
<PropertyGroup><Version>283.1.0</Version></PropertyGroup>
3+
<PropertyGroup><Version>283.1.0</Version></PropertyGroup>
44
</Project>

Robust.Server/GameObjects/EntitySystems/PointLightSystem.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ private bool IsContainerOrParentOccluder(BaseContainer container)
120120
{
121121
if (container.OccludesLight)
122122
return true;
123-
123+
124124
if (!_container.TryGetContainingContainer(container.Owner, out var nextContainer))
125125
return false;
126126

Robust.Shared.IntegrationTests/Serialization/SerializationTests/ManagerTests.Resources.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,15 @@ internal sealed partial class ManagerTests : ISerializationContext
2020
private static ValueDataNode SerializerRanDataNode => new ("SerializerRan");
2121
private static ValueDataNode SerializerRanCustomDataNode => new ("SerializerRanCustom");
2222

23-
public SerializationManager.SerializerProvider SerializerProvider { get; } = new();
23+
public SerializationManager.SerializerProvider SerializerProvider { get; private set; }
2424
public bool WritingReadingPrototypes { get; }
2525

2626
[OneTimeSetUp]
2727
public void SetupSerializerProvider()
2828
{
29+
var ser = IoCManager.Resolve<ISerializationManager>();
30+
SerializerProvider = new(ser);
31+
2932
SerializerProvider.RegisterSerializer<CustomTypeSerializerStruct>();
3033
SerializerProvider.RegisterSerializer<CustomTypeSerializerClass>();
3134
}

Robust.Shared/Audio/SoundSpecifier.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public sealed partial class SoundPathSpecifier : SoundSpecifier
2424
{
2525
public const string Node = "path";
2626

27-
[DataField(Node, customTypeSerializer: typeof(ResPathSerializer), required: true)]
27+
[DataField(Node, required: true)]
2828
public ResPath Path { get; private set; }
2929

3030
override public string ToString() =>
@@ -52,8 +52,8 @@ public sealed partial class SoundCollectionSpecifier : SoundSpecifier
5252
{
5353
public const string Node = "collection";
5454

55-
[DataField(Node, customTypeSerializer: typeof(PrototypeIdSerializer<SoundCollectionPrototype>), required: true)]
56-
public string? Collection { get; private set; }
55+
[DataField(Node, required: true)]
56+
public ProtoId<SoundCollectionPrototype>? Collection { get; private set; }
5757

5858
override public string ToString() =>
5959
$"SoundCollectionSpecifier({Collection})";

Robust.Shared/EntitySerialization/EntityDeserializer.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public sealed partial class EntityDeserializer :
4242

4343
public const int NewestSupportedVersion = EntitySerializer.MapFormatVersion;
4444

45-
public SerializationManager.SerializerProvider SerializerProvider { get; } = new();
45+
public SerializationManager.SerializerProvider SerializerProvider { get; }
4646

4747
[Dependency] public EntityManager EntMan = default!;
4848
[Dependency] public IGameTiming Timing = default!;
@@ -126,6 +126,7 @@ public EntityDeserializer(
126126
deps.InjectDependencies(this);
127127
_log = _logMan.GetSawmill("entity_deserializer");
128128
_log.Level = LogLevel.Info;
129+
SerializerProvider = new(_seriMan);
129130
SerializerProvider.RegisterSerializer(this);
130131
Data = data;
131132
Options = options;

Robust.Shared/EntitySerialization/EntitySerializer.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public sealed partial class EntitySerializer : ISerializationContext,
4848
// v3->v4: PR #3913 - Grouped entities by prototype
4949
// v2->v3: PR #3468
5050

51-
public SerializationManager.SerializerProvider SerializerProvider { get; } = new();
51+
public SerializationManager.SerializerProvider SerializerProvider { get; }
5252

5353
[Dependency] public EntityManager EntMan = default!;
5454
[Dependency] public IGameTiming Timing = default!;
@@ -167,6 +167,7 @@ public EntitySerializer(IDependencyCollection dependency, SerializationOptions o
167167
dependency.InjectDependencies(this);
168168

169169
_log = _logMan.GetSawmill("entity_serializer");
170+
SerializerProvider = new(_serialization);
170171
SerializerProvider.RegisterSerializer(this);
171172

172173
_metaName = _factory.GetComponentName<MetaDataComponent>();

Robust.Shared/GameObjects/EntityManager.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public abstract partial class EntityManager : IEntityManager
7878
private Histogram.Child? _queuedDeletionHistogram;
7979
private Histogram.Child? _componentCullHistogram;
8080

81-
private EntityDiffContext _context = new();
81+
private EntityDiffContext _context;
8282

8383
/// <summary>
8484
/// All entities currently stored in the manager.
@@ -139,6 +139,7 @@ public abstract partial class EntityManager : IEntityManager
139139
/// </summary>
140140
public EntityManager()
141141
{
142+
_context = new(_serManager);
142143
}
143144

144145
public virtual void Initialize()

Robust.Shared/Prototypes/IPrototypeManager.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,8 @@ Dictionary<string, HashSet<ErrorNode>> ValidateDirectory(ResPath path,
434434
/// This will validate all known to <see cref="IReflectionManager"/>
435435
/// </summary>
436436
/// <remarks>
437-
/// This will validate any field that has either a <see cref="ValidatePrototypeIdAttribute{T}"/> attribute, or a
437+
/// This will validate any field that uses <see cref="ProtoId"/> or <see cref="EntProtoId"/>.
438+
/// It also looks for these obsolete attributes: either a <see cref="ValidatePrototypeIdAttribute{T}"/> attribute, or a
438439
/// <see cref="DataFieldAttribute"/> with a <see cref="PrototypeIdSerializer{TPrototype}"/> serializer.
439440
/// </remarks>
440441
/// <param name="prototypes">A collection prototypes to use for validation. Any prototype not in this collection

Robust.Shared/Prototypes/PrototypeManager.YamlValidate.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public Dictionary<string, HashSet<ErrorNode>> ValidateDirectory(ResPath path,
8484
}
8585
}
8686

87-
var ctx = new YamlValidationContext();
87+
var ctx = new YamlValidationContext(_serializationManager);
8888
var errors = new List<ErrorNode>();
8989
foreach (var (type, instances) in prototypes)
9090
{

Robust.Shared/Prototypes/YamlValidationContext.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@ internal sealed class YamlValidationContext :
1717
ITypeSerializer<NetEntity, ValueDataNode>,
1818
ITypeSerializer<MapId, ValueDataNode>
1919
{
20-
public SerializationManager.SerializerProvider SerializerProvider { get; } = new();
20+
public SerializationManager.SerializerProvider SerializerProvider { get; }
2121
public bool WritingReadingPrototypes => true;
2222

23-
public YamlValidationContext()
23+
public YamlValidationContext(ISerializationManager ser)
2424
{
25+
SerializerProvider = new(ser);
2526
SerializerProvider.RegisterSerializer(this);
2627
}
2728

0 commit comments

Comments
 (0)