Apply a work-around fix to a bug in the current version of YamlDotNet, where it would not serialize Tags on a mapping.

This commit is contained in:
Acruid
2019-09-16 11:08:37 -07:00
parent 8a61259c11
commit 11046f8068

View File

@@ -16,6 +16,8 @@ using System.Globalization;
using Robust.Shared.Interfaces.GameObjects;
using System.Linq;
using Robust.Server.Interfaces.Timing;
using YamlDotNet.Core;
using YamlDotNet.Core.Events;
namespace Robust.Server.Maps
{
@@ -62,7 +64,7 @@ namespace Robust.Server.Maps
var stream = new YamlStream();
stream.Add(document);
stream.Save(writer, false);
stream.Save(new YamlMappingFix(new Emitter(writer)), false);
}
}
}
@@ -144,7 +146,7 @@ namespace Robust.Server.Maps
var stream = new YamlStream();
stream.Add(document);
stream.Save(writer, false);
stream.Save(new YamlMappingFix(new Emitter(writer)), false);
}
}
}
@@ -698,5 +700,27 @@ namespace Robust.Server.Maps
GridCount = ((YamlSequenceNode)RootNode["grids"]).Children.Count;
}
}
private class YamlMappingFix : IEmitter
{
//TODO: This fix exists because of https://github.com/aaubry/YamlDotNet/issues/409.
//Credit: https://stackoverflow.com/a/56452440
private readonly IEmitter _next;
public YamlMappingFix(IEmitter next)
{
_next = next;
}
public void Emit(ParsingEvent @event)
{
if (@event is MappingStart mapping)
{
@event = new MappingStart(mapping.Anchor, mapping.Tag, false, mapping.Style, mapping.Start, mapping.End);
}
_next.Emit(@event);
}
}
}
}