Shared String Dictionary ctd. (#1126)

This commit is contained in:
Tyler Young
2020-06-12 22:09:48 -04:00
committed by GitHub
parent 15ec0e7bd9
commit 9662d52f90
24 changed files with 1855 additions and 1548 deletions

View File

@@ -39,6 +39,8 @@ namespace Robust.Server.Maps
[Dependency] private readonly IComponentManager _componentManager = default!;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
public event Action<YamlStream, string>? LoadedMapData;
/// <inheritdoc />
public void SaveBlueprint(GridId gridId, string yamlPath)
{
@@ -99,6 +101,8 @@ namespace Robust.Server.Maps
var data = new MapData(reader);
LoadedMapData?.Invoke(data.Stream, resPath.ToString());
if (data.GridCount != 1)
{
throw new InvalidDataException("Cannot instance map with multiple grids as blueprint.");
@@ -182,6 +186,8 @@ namespace Robust.Server.Maps
var data = new MapData(reader);
LoadedMapData?.Invoke(data.Stream, resPath.ToString());
var context = new MapContext(_mapManager, _tileDefinitionManager, _serverEntityManager, _pauseManager, _componentManager, _prototypeManager, (YamlMappingNode)data.RootNode, mapId);
context.Deserialize();
@@ -849,7 +855,9 @@ namespace Robust.Server.Maps
/// </summary>
private class MapData
{
public YamlNode RootNode { get; }
public YamlStream Stream { get; }
public YamlNode RootNode => Stream.Documents[0].RootNode;
public int GridCount { get; }
public MapData(TextReader reader)
@@ -869,9 +877,8 @@ namespace Robust.Server.Maps
throw new InvalidDataException("Stream too many YAML documents. Map files store exactly one.");
}
RootNode = stream.Documents[0].RootNode;
Stream = stream;
GridCount = ((YamlSequenceNode)RootNode["grids"]).Children.Count;
RobustSerializer.MappedStringSerializer.AddStrings(stream, "anonymous map YAML stream");
}
}
}