mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-14 19:29:36 +01:00
Enable NRTs on Robust.Server (#1118)
This commit is contained in:
committed by
GitHub
parent
b2eff5d5eb
commit
0d3cd41382
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
using Robust.Server.Interfaces.GameObjects;
|
||||
using Robust.Server.Interfaces.Maps;
|
||||
@@ -30,23 +31,13 @@ namespace Robust.Server.Maps
|
||||
{
|
||||
private const int MapFormatVersion = 2;
|
||||
|
||||
[Dependency]
|
||||
#pragma warning disable 649
|
||||
private readonly IResourceManager _resMan;
|
||||
|
||||
[Dependency]
|
||||
private readonly IMapManagerInternal _mapManager;
|
||||
|
||||
[Dependency]
|
||||
private readonly ITileDefinitionManager _tileDefinitionManager;
|
||||
|
||||
[Dependency]
|
||||
private readonly IServerEntityManagerInternal _serverEntityManager;
|
||||
|
||||
[Dependency] private readonly IPauseManager _pauseManager;
|
||||
[Dependency] private readonly IComponentManager _componentManager;
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager;
|
||||
#pragma warning restore 649
|
||||
[Dependency] private readonly IResourceManager _resMan = default!;
|
||||
[Dependency] private readonly IMapManagerInternal _mapManager = default!;
|
||||
[Dependency] private readonly ITileDefinitionManager _tileDefinitionManager = default!;
|
||||
[Dependency] private readonly IServerEntityManagerInternal _serverEntityManager = default!;
|
||||
[Dependency] private readonly IPauseManager _pauseManager = default!;
|
||||
[Dependency] private readonly IComponentManager _componentManager = default!;
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||
|
||||
/// <inheritdoc />
|
||||
public void SaveBlueprint(GridId gridId, string yamlPath)
|
||||
@@ -74,7 +65,7 @@ namespace Robust.Server.Maps
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IMapGrid LoadBlueprint(MapId mapId, string path)
|
||||
public IMapGrid? LoadBlueprint(MapId mapId, string path)
|
||||
{
|
||||
TextReader reader;
|
||||
var resPath = new ResourcePath(path).ToRootedPath();
|
||||
@@ -233,12 +224,12 @@ namespace Robust.Server.Maps
|
||||
private readonly YamlMappingNode RootNode;
|
||||
private readonly MapId TargetMap;
|
||||
|
||||
private Dictionary<string, YamlMappingNode> CurrentReadingEntityComponents;
|
||||
private Dictionary<string, YamlMappingNode>? CurrentReadingEntityComponents;
|
||||
|
||||
private string CurrentWritingComponent;
|
||||
private IEntity CurrentWritingEntity;
|
||||
private string? CurrentWritingComponent;
|
||||
private IEntity? CurrentWritingEntity;
|
||||
|
||||
private Dictionary<ushort, string> _tileMap;
|
||||
private Dictionary<ushort, string>? _tileMap;
|
||||
|
||||
public bool MapIsPostInit { get; private set; }
|
||||
|
||||
@@ -340,7 +331,7 @@ namespace Robust.Server.Maps
|
||||
{
|
||||
foreach (var (entity, data) in _entitiesToDeserialize)
|
||||
{
|
||||
if (!data.TryGetNode("components", out YamlSequenceNode componentList))
|
||||
if (!data.TryGetNode("components", out YamlSequenceNode? componentList))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -443,7 +434,7 @@ namespace Robust.Server.Maps
|
||||
_mapManager, TargetMap, ref newId,
|
||||
(YamlMappingNode)grid["settings"],
|
||||
(YamlSequenceNode)grid["chunks"],
|
||||
_tileMap,
|
||||
_tileMap!,
|
||||
_tileDefinitionManager
|
||||
);
|
||||
|
||||
@@ -476,7 +467,7 @@ namespace Robust.Server.Maps
|
||||
var entities = RootNode.GetNode<YamlSequenceNode>("entities");
|
||||
foreach (var entityDef in entities.Cast<YamlMappingNode>())
|
||||
{
|
||||
string type = null;
|
||||
string? type = null;
|
||||
if (entityDef.TryGetNode("type", out var typeNode))
|
||||
{
|
||||
type = typeNode.AsString();
|
||||
@@ -500,7 +491,7 @@ namespace Robust.Server.Maps
|
||||
foreach (var (entity, data) in _entitiesToDeserialize)
|
||||
{
|
||||
CurrentReadingEntityComponents = new Dictionary<string, YamlMappingNode>();
|
||||
if (data.TryGetNode("components", out YamlSequenceNode componentList))
|
||||
if (data.TryGetNode("components", out YamlSequenceNode? componentList))
|
||||
{
|
||||
foreach (var compData in componentList)
|
||||
{
|
||||
@@ -665,7 +656,7 @@ namespace Robust.Server.Maps
|
||||
}
|
||||
}
|
||||
|
||||
public override bool TryNodeToType(YamlNode node, Type type, out object obj)
|
||||
public override bool TryNodeToType(YamlNode node, Type type, [NotNullWhen(true)] out object? obj)
|
||||
{
|
||||
if (type == typeof(GridId))
|
||||
{
|
||||
@@ -722,7 +713,7 @@ namespace Robust.Server.Maps
|
||||
return false;
|
||||
}
|
||||
|
||||
public override bool TryTypeToNode(object obj, out YamlNode node)
|
||||
public override bool TryTypeToNode(object obj, [NotNullWhen(true)] out YamlNode? node)
|
||||
{
|
||||
switch (obj)
|
||||
{
|
||||
@@ -742,7 +733,7 @@ namespace Robust.Server.Maps
|
||||
if (!EntityUidMap.TryGetValue(entityUid, out var entityUidMapped))
|
||||
{
|
||||
// Terrible hack to mute this warning on the grids themselves when serializing blueprints.
|
||||
if (!IsBlueprintMode || !CurrentWritingEntity.HasComponent<MapGridComponent>() ||
|
||||
if (!IsBlueprintMode || !CurrentWritingEntity!.HasComponent<MapGridComponent>() ||
|
||||
CurrentWritingComponent != "Transform")
|
||||
{
|
||||
Logger.WarningS("map", "Cannot write entity UID '{0}'.", entityUid);
|
||||
@@ -774,40 +765,41 @@ namespace Robust.Server.Maps
|
||||
}
|
||||
|
||||
// Create custom object serializers that will correctly allow data to be overriden by the map file.
|
||||
ObjectSerializer IEntityLoadContext.GetComponentSerializer(string componentName, YamlMappingNode protoData)
|
||||
ObjectSerializer IEntityLoadContext.GetComponentSerializer(string componentName, YamlMappingNode? protoData)
|
||||
{
|
||||
if (CurrentReadingEntityComponents == null)
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
|
||||
var list = new List<YamlMappingNode>();
|
||||
if (CurrentReadingEntityComponents.TryGetValue(componentName, out var mapping))
|
||||
{
|
||||
var list = new List<YamlMappingNode> {mapping};
|
||||
if (protoData != null)
|
||||
{
|
||||
list.Add(protoData);
|
||||
}
|
||||
return YamlObjectSerializer.NewReader(list, this);
|
||||
list.Add(mapping);
|
||||
}
|
||||
|
||||
return YamlObjectSerializer.NewReader(protoData, this);
|
||||
if (protoData != null)
|
||||
{
|
||||
list.Add(protoData);
|
||||
}
|
||||
|
||||
return YamlObjectSerializer.NewReader(list, this);
|
||||
}
|
||||
|
||||
public IEnumerable<string> GetExtraComponentTypes()
|
||||
{
|
||||
return CurrentReadingEntityComponents.Keys;
|
||||
return CurrentReadingEntityComponents!.Keys;
|
||||
}
|
||||
|
||||
public override bool IsValueDefault<T>(string field, T value, WithFormat<T> format)
|
||||
{
|
||||
if (CurrentWritingEntity.Prototype == null)
|
||||
if (CurrentWritingEntity!.Prototype == null)
|
||||
{
|
||||
// No prototype, can't be default.
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!CurrentWritingEntity.Prototype.Components.TryGetValue(CurrentWritingComponent, out var compData))
|
||||
if (!CurrentWritingEntity.Prototype.Components.TryGetValue(CurrentWritingComponent!, out var compData))
|
||||
{
|
||||
// This component was added mid-game.
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user