mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-14 19:29:36 +01:00
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:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user