mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-15 11:40:52 +01:00
Compare commits
3 Commits
prototype-
...
v0.8.53
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
14a3783760 | ||
|
|
b4607f7b1f | ||
|
|
5a28c16cae |
@@ -1,4 +1,4 @@
|
||||
<Project>
|
||||
<!-- This file automatically reset by Tools/version.py -->
|
||||
<PropertyGroup><Version>0.8.52</Version></PropertyGroup>
|
||||
<PropertyGroup><Version>0.8.53</Version></PropertyGroup>
|
||||
</Project>
|
||||
|
||||
@@ -323,7 +323,7 @@ namespace Robust.Client.GameObjects
|
||||
{
|
||||
private readonly IPlayerManager _playerManager;
|
||||
|
||||
public override OverlaySpace Space => OverlaySpace.WorldSpace;
|
||||
public override OverlaySpace Space => OverlaySpace.WorldSpaceBelowFOV;
|
||||
|
||||
private readonly ShaderInstance _unshadedShader;
|
||||
private readonly EffectSystem _owner;
|
||||
|
||||
@@ -29,14 +29,13 @@ namespace Robust.Server.Console.Commands
|
||||
var mapId = new MapId(int.Parse(args[0]));
|
||||
|
||||
var mapMgr = IoCManager.Resolve<IMapManager>();
|
||||
var pauseMgr = IoCManager.Resolve<IPauseManager>();
|
||||
|
||||
if (!mapMgr.MapExists(mapId))
|
||||
{
|
||||
mapMgr.CreateMap(mapId);
|
||||
if (args.Length >= 2 && args[1] == "false")
|
||||
{
|
||||
pauseMgr.AddUninitializedMap(mapId);
|
||||
mapMgr.AddUninitializedMap(mapId);
|
||||
}
|
||||
|
||||
shell.WriteLine($"Map with ID {mapId} created.");
|
||||
@@ -318,7 +317,6 @@ namespace Robust.Server.Console.Commands
|
||||
}
|
||||
|
||||
var mapManager = IoCManager.Resolve<IMapManager>();
|
||||
var pauseManager = IoCManager.Resolve<IPauseManager>();
|
||||
|
||||
var arg = args[0];
|
||||
var mapId = new MapId(int.Parse(arg, CultureInfo.InvariantCulture));
|
||||
@@ -329,13 +327,13 @@ namespace Robust.Server.Console.Commands
|
||||
return;
|
||||
}
|
||||
|
||||
if (pauseManager.IsMapInitialized(mapId))
|
||||
if (mapManager.IsMapInitialized(mapId))
|
||||
{
|
||||
shell.WriteError("Map is already initialized!");
|
||||
return;
|
||||
}
|
||||
|
||||
pauseManager.DoMapInitialize(mapId);
|
||||
mapManager.DoMapInitialize(mapId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -348,15 +346,14 @@ namespace Robust.Server.Console.Commands
|
||||
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||
{
|
||||
var mapManager = IoCManager.Resolve<IMapManager>();
|
||||
var pauseManager = IoCManager.Resolve<IPauseManager>();
|
||||
|
||||
var msg = new StringBuilder();
|
||||
|
||||
foreach (var mapId in mapManager.GetAllMapIds().OrderBy(id => id.Value))
|
||||
{
|
||||
msg.AppendFormat("{0}: init: {1}, paused: {2}, ent: {3}, grids: {4}\n",
|
||||
mapId, pauseManager.IsMapInitialized(mapId),
|
||||
pauseManager.IsMapPaused(mapId),
|
||||
mapId, mapManager.IsMapInitialized(mapId),
|
||||
mapManager.IsMapPaused(mapId),
|
||||
string.Join(",", mapManager.GetAllMapGrids(mapId).Select(grid => grid.Index)),
|
||||
mapManager.GetMapEntityId(mapId));
|
||||
}
|
||||
|
||||
@@ -109,9 +109,8 @@ namespace Robust.Server.Console.Commands
|
||||
private void SetupPlayer(MapId mapId, IConsoleShell shell, IPlayerSession? player, IMapManager mapManager)
|
||||
{
|
||||
if (mapId == MapId.Nullspace) return;
|
||||
var pauseManager = IoCManager.Resolve<IPauseManager>();
|
||||
pauseManager.SetMapPaused(mapId, false);
|
||||
var mapUid = IoCManager.Resolve<IMapManager>().GetMapEntityIdOrThrow(mapId);
|
||||
mapManager.SetMapPaused(mapId, false);
|
||||
var mapUid = mapManager.GetMapEntityIdOrThrow(mapId);
|
||||
IoCManager.Resolve<IEntityManager>().GetComponent<SharedPhysicsMapComponent>(mapUid).Gravity = new Vector2(0, -9.8f);
|
||||
|
||||
return;
|
||||
|
||||
@@ -24,7 +24,6 @@ using Robust.Shared.Serialization.Markdown.Mapping;
|
||||
using Robust.Shared.Serialization.Markdown.Validation;
|
||||
using Robust.Shared.Serialization.Markdown.Value;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Interfaces;
|
||||
using Robust.Shared.Timing;
|
||||
using Robust.Shared.Utility;
|
||||
using YamlDotNet.Core;
|
||||
using YamlDotNet.RepresentationModel;
|
||||
@@ -44,7 +43,6 @@ namespace Robust.Server.Maps
|
||||
[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 IPrototypeManager _prototypeManager = default!;
|
||||
|
||||
public event Action<YamlStream, string>? LoadedMapData;
|
||||
@@ -54,7 +52,7 @@ namespace Robust.Server.Maps
|
||||
{
|
||||
var grid = _mapManager.GetGrid(gridId);
|
||||
|
||||
var context = new MapContext(_mapManager, _tileDefinitionManager, _serverEntityManager, _pauseManager, _prototypeManager);
|
||||
var context = new MapContext(_mapManager, _tileDefinitionManager, _serverEntityManager, _prototypeManager);
|
||||
context.RegisterGrid(grid);
|
||||
var root = context.Serialize();
|
||||
var document = new YamlDocument(root);
|
||||
@@ -100,7 +98,7 @@ namespace Robust.Server.Maps
|
||||
throw new InvalidDataException("Cannot instance map with multiple grids as blueprint.");
|
||||
}
|
||||
|
||||
var context = new MapContext(_mapManager, _tileDefinitionManager, _serverEntityManager, _pauseManager,
|
||||
var context = new MapContext(_mapManager, _tileDefinitionManager, _serverEntityManager,
|
||||
_prototypeManager, (YamlMappingNode) data.RootNode, mapId, options);
|
||||
context.Deserialize();
|
||||
grid = context.Grids[0];
|
||||
@@ -120,7 +118,7 @@ namespace Robust.Server.Maps
|
||||
_serverEntityManager.GetComponent<MetaDataComponent>(entity).EntityLifeStage = EntityLifeStage.MapInitialized;
|
||||
}
|
||||
}
|
||||
else if (_pauseManager.IsMapInitialized(mapId))
|
||||
else if (_mapManager.IsMapInitialized(mapId))
|
||||
{
|
||||
foreach (var entity in context.Entities)
|
||||
{
|
||||
@@ -128,7 +126,7 @@ namespace Robust.Server.Maps
|
||||
}
|
||||
}
|
||||
|
||||
if (_pauseManager.IsMapPaused(mapId))
|
||||
if (_mapManager.IsMapPaused(mapId))
|
||||
{
|
||||
foreach (var entity in context.Entities)
|
||||
{
|
||||
@@ -141,7 +139,7 @@ namespace Robust.Server.Maps
|
||||
public void SaveMap(MapId mapId, string yamlPath)
|
||||
{
|
||||
Logger.InfoS("map", $"Saving map {mapId} to {yamlPath}");
|
||||
var context = new MapContext(_mapManager, _tileDefinitionManager, _serverEntityManager, _pauseManager, _prototypeManager);
|
||||
var context = new MapContext(_mapManager, _tileDefinitionManager, _serverEntityManager, _prototypeManager);
|
||||
foreach (var grid in _mapManager.GetAllMapGrids(mapId))
|
||||
{
|
||||
context.RegisterGrid(grid);
|
||||
@@ -207,7 +205,7 @@ namespace Robust.Server.Maps
|
||||
|
||||
LoadedMapData?.Invoke(data.Stream, resPath.ToString());
|
||||
|
||||
var context = new MapContext(_mapManager, _tileDefinitionManager, _serverEntityManager, _pauseManager,
|
||||
var context = new MapContext(_mapManager, _tileDefinitionManager, _serverEntityManager,
|
||||
_prototypeManager, (YamlMappingNode) data.RootNode, mapId, options);
|
||||
context.Deserialize();
|
||||
|
||||
@@ -226,7 +224,6 @@ namespace Robust.Server.Maps
|
||||
private readonly IMapManagerInternal _mapManager;
|
||||
private readonly ITileDefinitionManager _tileDefinitionManager;
|
||||
private readonly IServerEntityManagerInternal _serverEntityManager;
|
||||
private readonly IPauseManager _pauseManager;
|
||||
private readonly IPrototypeManager _prototypeManager;
|
||||
|
||||
private readonly MapLoadOptions? _loadOptions;
|
||||
@@ -260,12 +257,11 @@ namespace Robust.Server.Maps
|
||||
public bool MapIsPostInit { get; private set; }
|
||||
|
||||
public MapContext(IMapManagerInternal maps, ITileDefinitionManager tileDefs,
|
||||
IServerEntityManagerInternal entities, IPauseManager pauseManager, IPrototypeManager prototypeManager)
|
||||
IServerEntityManagerInternal entities, IPrototypeManager prototypeManager)
|
||||
{
|
||||
_mapManager = maps;
|
||||
_tileDefinitionManager = tileDefs;
|
||||
_serverEntityManager = entities;
|
||||
_pauseManager = pauseManager;
|
||||
_prototypeManager = prototypeManager;
|
||||
|
||||
RootNode = new YamlMappingNode();
|
||||
@@ -283,13 +279,12 @@ namespace Robust.Server.Maps
|
||||
|
||||
public MapContext(IMapManagerInternal maps, ITileDefinitionManager tileDefs,
|
||||
IServerEntityManagerInternal entities,
|
||||
IPauseManager pauseManager, IPrototypeManager prototypeManager,
|
||||
IPrototypeManager prototypeManager,
|
||||
YamlMappingNode node, MapId targetMapId, MapLoadOptions options)
|
||||
{
|
||||
_mapManager = maps;
|
||||
_tileDefinitionManager = tileDefs;
|
||||
_serverEntityManager = entities;
|
||||
_pauseManager = pauseManager;
|
||||
_loadOptions = options;
|
||||
|
||||
RootNode = node;
|
||||
@@ -612,7 +607,7 @@ namespace Robust.Server.Maps
|
||||
|
||||
if (!MapIsPostInit)
|
||||
{
|
||||
_pauseManager.AddUninitializedMap(TargetMap);
|
||||
_mapManager.AddUninitializedMap(TargetMap);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -719,7 +714,7 @@ namespace Robust.Server.Maps
|
||||
var isPostInit = false;
|
||||
foreach (var grid in Grids)
|
||||
{
|
||||
if (_pauseManager.IsMapInitialized(grid.ParentMapId))
|
||||
if (_mapManager.IsMapInitialized(grid.ParentMapId))
|
||||
{
|
||||
isPostInit = true;
|
||||
break;
|
||||
|
||||
@@ -1,25 +1,24 @@
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Timing;
|
||||
using Robust.Shared.Map;
|
||||
|
||||
namespace Robust.Shared.GameObjects
|
||||
{
|
||||
[RegisterComponent]
|
||||
public sealed class IgnorePauseComponent : Component
|
||||
{
|
||||
[Dependency] private readonly IEntityManager _entMan = default!;
|
||||
|
||||
protected override void OnAdd()
|
||||
{
|
||||
base.OnAdd();
|
||||
_entMan.GetComponent<MetaDataComponent>(Owner).EntityPaused = false;
|
||||
IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(Owner).EntityPaused = false;
|
||||
}
|
||||
|
||||
protected override void OnRemove()
|
||||
{
|
||||
base.OnRemove();
|
||||
if (IoCManager.Resolve<IPauseManager>().IsMapPaused(_entMan.GetComponent<TransformComponent>(Owner).MapID))
|
||||
var entMan = IoCManager.Resolve<IEntityManager>();
|
||||
if (IoCManager.Resolve<IMapManager>().IsMapPaused(entMan.GetComponent<TransformComponent>(Owner).MapID))
|
||||
{
|
||||
_entMan.GetComponent<MetaDataComponent>(Owner).EntityPaused = true;
|
||||
entMan.GetComponent<MetaDataComponent>(Owner).EntityPaused = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -147,9 +147,11 @@ namespace Robust.Shared.GameObjects
|
||||
get => _entityPaused;
|
||||
set
|
||||
{
|
||||
if (_entityPaused == value)
|
||||
return;
|
||||
|
||||
var entMan = IoCManager.Resolve<IEntityManager>();
|
||||
|
||||
if (_entityPaused == value || value && entMan.HasComponent<IgnorePauseComponent>(Owner))
|
||||
if (value && entMan.HasComponent<IgnorePauseComponent>(Owner))
|
||||
return;
|
||||
|
||||
_entityPaused = value;
|
||||
|
||||
@@ -728,17 +728,27 @@ namespace Robust.Shared.GameObjects
|
||||
|
||||
var oldMapId = MapID;
|
||||
|
||||
//Set Paused state
|
||||
var mapPaused = _mapManager.IsMapPaused(newMapId);
|
||||
var metaData = _entMan.GetComponent<MetaDataComponent>(Owner);
|
||||
metaData.EntityPaused = mapPaused;
|
||||
|
||||
MapID = newMapId;
|
||||
MapIdChanged(oldMapId);
|
||||
UpdateChildMapIdsRecursive(MapID, _entMan);
|
||||
UpdateChildMapIdsRecursive(MapID, _entMan, mapPaused);
|
||||
}
|
||||
|
||||
private void UpdateChildMapIdsRecursive(MapId newMapId, IEntityManager entMan)
|
||||
private void UpdateChildMapIdsRecursive(MapId newMapId, IEntityManager entMan, bool mapPaused)
|
||||
{
|
||||
var xforms = _entMan.GetEntityQuery<TransformComponent>();
|
||||
var metaEnts = _entMan.GetEntityQuery<MetaDataComponent>();
|
||||
|
||||
foreach (var child in _children)
|
||||
{
|
||||
//Set Paused state
|
||||
var metaData = metaEnts.GetComponent(child);
|
||||
metaData.EntityPaused = mapPaused;
|
||||
|
||||
var concrete = xforms.GetComponent(child);
|
||||
var old = concrete.MapID;
|
||||
|
||||
@@ -747,7 +757,7 @@ namespace Robust.Shared.GameObjects
|
||||
|
||||
if (concrete.ChildCount != 0)
|
||||
{
|
||||
concrete.UpdateChildMapIdsRecursive(newMapId, entMan);
|
||||
concrete.UpdateChildMapIdsRecursive(newMapId, entMan, mapPaused);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ namespace Robust.Shared.GameObjects
|
||||
[IoC.Dependency] protected readonly IEntitySystemManager EntitySystemManager = default!;
|
||||
[IoC.Dependency] private readonly IMapManager _mapManager = default!;
|
||||
[IoC.Dependency] private readonly IGameTiming _gameTiming = default!;
|
||||
[IoC.Dependency] private readonly IPauseManager _pauseManager = default!;
|
||||
|
||||
#endregion Dependencies
|
||||
|
||||
@@ -438,7 +437,7 @@ namespace Robust.Shared.GameObjects
|
||||
StartEntity(entity);
|
||||
|
||||
// If the map we're initializing the entity on is initialized, run map init on it.
|
||||
if (_pauseManager.IsMapInitialized(mapId))
|
||||
if (_mapManager.IsMapInitialized(mapId))
|
||||
entity.RunMapInit();
|
||||
}
|
||||
catch (Exception e)
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using System;
|
||||
using System;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Robust.Shared.Map
|
||||
@@ -13,6 +15,14 @@ namespace Robust.Shared.Map
|
||||
|
||||
internal readonly int Value;
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new instance of <see cref="GridId"/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This should NOT be used in regular code, and is only public for special/legacy
|
||||
/// cases. Generally you should only use this for parsing a GridId in console commands
|
||||
/// and immediately check if the grid actually exists in the <see cref="IMapManager"/>.
|
||||
/// </remarks>
|
||||
public GridId(int value)
|
||||
{
|
||||
Value = value;
|
||||
@@ -57,6 +67,30 @@ namespace Robust.Shared.Map
|
||||
return self.Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <see cref="GridId"/> is an alias of the <see cref="EntityUid"/> that
|
||||
/// holds the <see cref="IMapGridComponent"/>, so it can be implicitly converted.
|
||||
/// </summary>
|
||||
public static implicit operator EntityUid(GridId self)
|
||||
{
|
||||
// If this throws, you are either using an unallocated gridId,
|
||||
// or using it after the grid was freed. Both of these are bugs.
|
||||
return IoCManager.Resolve<IMapManager>().GetGridEuid(self);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <see cref="GridId"/> is an alias of the <see cref="EntityUid"/> that
|
||||
/// holds the <see cref="IMapGridComponent"/>.
|
||||
/// </summary>
|
||||
public static implicit operator GridId(EntityUid euid)
|
||||
{
|
||||
// If this throws, you are using an EntityUid that isn't a grid.
|
||||
// This would raise the question, "Why does your code think this entity is a grid?".
|
||||
// Grid-ness is defined by the entity having an IMapGridComponent,
|
||||
// was the component removed without you knowing?
|
||||
return IoCManager.Resolve<IMapManager>().GetGridComp(euid).GridIndex;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Value.ToString();
|
||||
|
||||
@@ -3,13 +3,14 @@ using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
namespace Robust.Shared.Map
|
||||
{
|
||||
/// <summary>
|
||||
/// This manages all of the grids in the world.
|
||||
/// </summary>
|
||||
public interface IMapManager
|
||||
public interface IMapManager : IPauseManager
|
||||
{
|
||||
/// <summary>
|
||||
/// The default <see cref="MapId" /> that is always available. Equivalent to SS13 Null space.
|
||||
|
||||
@@ -2,101 +2,121 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using Robust.Shared.Console;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Robust.Shared.Timing
|
||||
namespace Robust.Shared.Map
|
||||
{
|
||||
internal sealed class PauseManager : IPauseManager, IPostInjectInit
|
||||
internal partial class MapManager
|
||||
{
|
||||
[Dependency] private readonly IConsoleHost _conhost = default!;
|
||||
[Dependency] private readonly IMapManager _mapManager = default!;
|
||||
[Dependency] private readonly IEntityLookup _entityLookup = default!;
|
||||
[Dependency] private readonly IEntityManager _entityManager = default!;
|
||||
|
||||
[ViewVariables] private readonly HashSet<MapId> _pausedMaps = new();
|
||||
[ViewVariables] private readonly HashSet<MapId> _unInitializedMaps = new();
|
||||
|
||||
/// <inheritdoc />
|
||||
public void SetMapPaused(MapId mapId, bool paused)
|
||||
{
|
||||
if(!MapExists(mapId))
|
||||
throw new ArgumentException("That map does not exist.");
|
||||
|
||||
if (paused)
|
||||
{
|
||||
_pausedMaps.Add(mapId);
|
||||
|
||||
foreach (var entity in _entityLookup.GetEntitiesInMap(mapId))
|
||||
{
|
||||
_entityManager.GetComponent<MetaDataComponent>(entity).EntityPaused = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_pausedMaps.Remove(mapId);
|
||||
}
|
||||
|
||||
foreach (var entity in _entityLookup.GetEntitiesInMap(mapId))
|
||||
{
|
||||
_entityManager.GetComponent<MetaDataComponent>(entity).EntityPaused = false;
|
||||
}
|
||||
var mapEnt = GetMapEntityId(mapId);
|
||||
var xformQuery = EntityManager.GetEntityQuery<TransformComponent>();
|
||||
var metaQuery = EntityManager.GetEntityQuery<MetaDataComponent>();
|
||||
|
||||
RecursiveSetPaused(mapEnt, paused, in xformQuery, in metaQuery);
|
||||
}
|
||||
|
||||
private static void RecursiveSetPaused(EntityUid entity, bool paused,
|
||||
in EntityQuery<TransformComponent> xformQuery,
|
||||
in EntityQuery<MetaDataComponent> metaQuery)
|
||||
{
|
||||
metaQuery.GetComponent(entity).EntityPaused = paused;
|
||||
|
||||
foreach (var child in xformQuery.GetComponent(entity)._children)
|
||||
{
|
||||
RecursiveSetPaused(child, paused, in xformQuery, in metaQuery);
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void DoMapInitialize(MapId mapId)
|
||||
{
|
||||
if(!MapExists(mapId))
|
||||
throw new ArgumentException("That map does not exist.");
|
||||
|
||||
if (IsMapInitialized(mapId))
|
||||
throw new ArgumentException("That map is already initialized.");
|
||||
|
||||
_unInitializedMaps.Remove(mapId);
|
||||
|
||||
foreach (var entity in IoCManager.Resolve<IEntityLookup>().GetEntitiesInMap(mapId).ToArray())
|
||||
{
|
||||
entity.RunMapInit();
|
||||
var mapEnt = GetMapEntityId(mapId);
|
||||
var xformQuery = EntityManager.GetEntityQuery<TransformComponent>();
|
||||
var metaQuery = EntityManager.GetEntityQuery<MetaDataComponent>();
|
||||
|
||||
// MapInit could have deleted this entity.
|
||||
if(_entityManager.TryGetComponent(entity, out MetaDataComponent? meta))
|
||||
meta.EntityPaused = false;
|
||||
RecursiveDoMapInit(mapEnt, in xformQuery, in metaQuery);
|
||||
}
|
||||
|
||||
private static void RecursiveDoMapInit(EntityUid entity,
|
||||
in EntityQuery<TransformComponent> xformQuery,
|
||||
in EntityQuery<MetaDataComponent> metaQuery)
|
||||
{
|
||||
// RunMapInit can modify the TransformTree
|
||||
// ToArray caches deleted euids, we check here if they still exist.
|
||||
if(!metaQuery.TryGetComponent(entity, out var meta))
|
||||
return;
|
||||
|
||||
entity.RunMapInit();
|
||||
meta.EntityPaused = false;
|
||||
|
||||
foreach (var child in xformQuery.GetComponent(entity)._children.ToArray())
|
||||
{
|
||||
RecursiveDoMapInit(child, in xformQuery, in metaQuery);
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void DoGridMapInitialize(IMapGrid grid)
|
||||
{
|
||||
DoGridMapInitialize(grid.Index);
|
||||
// NOP
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void DoGridMapInitialize(GridId gridId)
|
||||
{
|
||||
var mapId = _mapManager.GetGrid(gridId).ParentMapId;
|
||||
|
||||
foreach (var entity in _entityLookup.GetEntitiesInMap(mapId))
|
||||
{
|
||||
if (_entityManager.GetComponent<TransformComponent>(entity).GridID != gridId)
|
||||
continue;
|
||||
|
||||
entity.RunMapInit();
|
||||
_entityManager.GetComponent<MetaDataComponent>(entity).EntityPaused = false;
|
||||
}
|
||||
// NOP
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void AddUninitializedMap(MapId mapId)
|
||||
{
|
||||
_unInitializedMaps.Add(mapId);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool IsMapPaused(MapId mapId)
|
||||
{
|
||||
return _pausedMaps.Contains(mapId) || _unInitializedMaps.Contains(mapId);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool IsGridPaused(IMapGrid grid)
|
||||
{
|
||||
return IsMapPaused(grid.ParentMapId);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool IsGridPaused(GridId gridId)
|
||||
{
|
||||
if (_mapManager.TryGetGrid(gridId, out var grid))
|
||||
if (TryGetGrid(gridId, out var grid))
|
||||
{
|
||||
return IsGridPaused(grid);
|
||||
}
|
||||
@@ -105,15 +125,18 @@ namespace Robust.Shared.Timing
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool IsMapInitialized(MapId mapId)
|
||||
{
|
||||
return !_unInitializedMaps.Contains(mapId);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void PostInject()
|
||||
/// <summary>
|
||||
/// Initializes the map pausing system.
|
||||
/// </summary>
|
||||
private void InitializeMapPausing()
|
||||
{
|
||||
_mapManager.MapDestroyed += (_, args) =>
|
||||
MapDestroyed += (_, args) =>
|
||||
{
|
||||
_pausedMaps.Remove(args.Map);
|
||||
_unInitializedMaps.Add(args.Map);
|
||||
@@ -130,10 +153,9 @@ namespace Robust.Shared.Timing
|
||||
return;
|
||||
}
|
||||
|
||||
string? arg = args[0];
|
||||
var mapId = new MapId(int.Parse(arg, CultureInfo.InvariantCulture));
|
||||
var mapId = new MapId(int.Parse(args[0], CultureInfo.InvariantCulture));
|
||||
|
||||
if (!_mapManager.MapExists(mapId))
|
||||
if (!MapExists(mapId))
|
||||
{
|
||||
shell.WriteError("That map does not exist.");
|
||||
return;
|
||||
@@ -147,10 +169,9 @@ namespace Robust.Shared.Timing
|
||||
"querymappaused <map ID>",
|
||||
(shell, _, args) =>
|
||||
{
|
||||
string? arg = args[0];
|
||||
var mapId = new MapId(int.Parse(arg, CultureInfo.InvariantCulture));
|
||||
var mapId = new MapId(int.Parse(args[0], CultureInfo.InvariantCulture));
|
||||
|
||||
if (!_mapManager.MapExists(mapId))
|
||||
if (!MapExists(mapId))
|
||||
{
|
||||
shell.WriteError("That map does not exist.");
|
||||
return;
|
||||
@@ -170,10 +191,9 @@ namespace Robust.Shared.Timing
|
||||
return;
|
||||
}
|
||||
|
||||
string? arg = args[0];
|
||||
var mapId = new MapId(int.Parse(arg, CultureInfo.InvariantCulture));
|
||||
var mapId = new MapId(int.Parse(args[0], CultureInfo.InvariantCulture));
|
||||
|
||||
if (!_mapManager.MapExists(mapId))
|
||||
if (!MapExists(mapId))
|
||||
{
|
||||
shell.WriteLine("That map does not exist.");
|
||||
return;
|
||||
@@ -1,3 +1,4 @@
|
||||
using Robust.Shared.Console;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Log;
|
||||
@@ -7,20 +8,25 @@ using Robust.Shared.Utility;
|
||||
namespace Robust.Shared.Map;
|
||||
|
||||
/// <inheritdoc cref="IMapManager" />
|
||||
[Virtual]
|
||||
internal partial class MapManager : IMapManagerInternal, IEntityEventSubscriber
|
||||
{
|
||||
[field: Dependency] public IGameTiming GameTiming { get; } = default!;
|
||||
[field: Dependency] public IEntityManager EntityManager { get; } = default!;
|
||||
|
||||
[Dependency] private readonly IConsoleHost _conhost = default!;
|
||||
[Dependency] private readonly IEntityLookup _entityLookup = default!;
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Initialize()
|
||||
{
|
||||
InitializeGridTrees();
|
||||
#if DEBUG
|
||||
DebugTools.Assert(!_dbgGuardInit);
|
||||
DebugTools.Assert(!_dbgGuardRunning);
|
||||
_dbgGuardInit = true;
|
||||
#endif
|
||||
InitializeGridTrees();
|
||||
InitializeMapPausing();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
@@ -1,160 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
using Robust.Shared.Serialization.Markdown.Validation;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
using YamlDotNet.RepresentationModel;
|
||||
|
||||
namespace Robust.Shared.Prototypes
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Handle storage and loading of YAML prototypes.
|
||||
/// </summary>
|
||||
public interface IPrototypeManager
|
||||
{
|
||||
void Initialize();
|
||||
|
||||
/// <summary>
|
||||
/// Return an IEnumerable to iterate all prototypes of a certain type.
|
||||
/// </summary>
|
||||
/// <exception cref="KeyNotFoundException">
|
||||
/// Thrown if the type of prototype is not registered.
|
||||
/// </exception>
|
||||
IEnumerable<T> EnumeratePrototypes<T>() where T : class, IPrototype;
|
||||
|
||||
/// <summary>
|
||||
/// Return an IEnumerable to iterate all prototypes of a certain type.
|
||||
/// </summary>
|
||||
/// <exception cref="KeyNotFoundException">
|
||||
/// Thrown if the type of prototype is not registered.
|
||||
/// </exception>
|
||||
IEnumerable<IPrototype> EnumeratePrototypes(Type type);
|
||||
|
||||
/// <summary>
|
||||
/// Return an IEnumerable to iterate all prototypes of a certain variant.
|
||||
/// </summary>
|
||||
/// <exception cref="KeyNotFoundException">
|
||||
/// Thrown if the variant of prototype is not registered.
|
||||
/// </exception>
|
||||
IEnumerable<IPrototype> EnumeratePrototypes(string variant);
|
||||
|
||||
/// <summary>
|
||||
/// Index for a <see cref="IPrototype"/> by ID.
|
||||
/// </summary>
|
||||
/// <exception cref="KeyNotFoundException">
|
||||
/// Thrown if the type of prototype is not registered.
|
||||
/// </exception>
|
||||
T Index<T>(string id) where T : class, IPrototype;
|
||||
|
||||
/// <summary>
|
||||
/// Index for a <see cref="IPrototype"/> by ID.
|
||||
/// </summary>
|
||||
/// <exception cref="KeyNotFoundException">
|
||||
/// Thrown if the ID does not exist or the type of prototype is not registered.
|
||||
/// </exception>
|
||||
IPrototype Index(Type type, string id);
|
||||
|
||||
/// <summary>
|
||||
/// Returns whether a prototype of type <typeparamref name="T"/> with the specified <param name="id"/> exists.
|
||||
/// </summary>
|
||||
bool HasIndex<T>(string id) where T : class, IPrototype;
|
||||
|
||||
bool TryIndex<T>(string id, [NotNullWhen(true)] out T? prototype) where T : class, IPrototype;
|
||||
bool TryIndex(Type type, string id, [NotNullWhen(true)] out IPrototype? prototype);
|
||||
|
||||
/// <summary>
|
||||
/// Returns whether a prototype variant <param name="variant"/> exists.
|
||||
/// </summary>
|
||||
/// <param name="variant">Identifier for the prototype variant.</param>
|
||||
/// <returns>Whether the prototype variant exists.</returns>
|
||||
bool HasVariant(string variant);
|
||||
|
||||
/// <summary>
|
||||
/// Returns the Type for a prototype variant.
|
||||
/// </summary>
|
||||
/// <param name="variant">Identifier for the prototype variant.</param>
|
||||
/// <returns>The specified prototype Type.</returns>
|
||||
/// <exception cref="KeyNotFoundException">
|
||||
/// Thrown when the specified prototype variant isn't registered or doesn't exist.
|
||||
/// </exception>
|
||||
Type GetVariantType(string variant);
|
||||
|
||||
/// <summary>
|
||||
/// Attempts to get the Type for a prototype variant.
|
||||
/// </summary>
|
||||
/// <param name="variant">Identifier for the prototype variant.</param>
|
||||
/// <param name="prototype">The specified prototype Type, or null.</param>
|
||||
/// <returns>Whether the prototype type was found and <see cref="prototype"/> isn't null.</returns>
|
||||
bool TryGetVariantType(string variant, [NotNullWhen(true)] out Type? prototype);
|
||||
|
||||
/// <summary>
|
||||
/// Attempts to get a prototype's variant.
|
||||
/// </summary>
|
||||
/// <param name="type"></param>
|
||||
/// <param name="variant"></param>
|
||||
/// <returns></returns>
|
||||
bool TryGetVariantFrom(Type type, [NotNullWhen(true)] out string? variant);
|
||||
|
||||
/// <summary>
|
||||
/// Attempts to get a prototype's variant.
|
||||
/// </summary>
|
||||
/// <param name="prototype">The prototype in question.</param>
|
||||
/// <param name="variant">Identifier for the prototype variant, or null.</param>
|
||||
/// <returns>Whether the prototype variant was successfully retrieved.</returns>
|
||||
bool TryGetVariantFrom(IPrototype prototype, [NotNullWhen(true)] out string? variant);
|
||||
|
||||
/// <summary>
|
||||
/// Attempts to get a prototype's variant.
|
||||
/// </summary>
|
||||
/// <param name="variant">Identifier for the prototype variant, or null.</param>
|
||||
/// <typeparam name="T">The prototype in question.</typeparam>
|
||||
/// <returns>Whether the prototype variant was successfully retrieved.</returns>
|
||||
bool TryGetVariantFrom<T>([NotNullWhen(true)] out string? variant) where T : class, IPrototype;
|
||||
|
||||
/// <summary>
|
||||
/// Load prototypes from files in a directory, recursively.
|
||||
/// </summary>
|
||||
List<IPrototype> LoadDirectory(ResourcePath path, bool overwrite = false);
|
||||
|
||||
Dictionary<string, HashSet<ErrorNode>> ValidateDirectory(ResourcePath path);
|
||||
|
||||
HashSet<IPrototype> LoadFromString(string str, bool overwrite = false, string actionMessage="");
|
||||
|
||||
void RemoveString(string prototypes);
|
||||
|
||||
/// <summary>
|
||||
/// Clear out all prototypes and reset to a blank slate.
|
||||
/// </summary>
|
||||
void Clear();
|
||||
|
||||
/// <summary>
|
||||
/// Syncs all inter-prototype data. Call this when operations adding new prototypes are done.
|
||||
/// </summary>
|
||||
void Resync();
|
||||
|
||||
/// <summary>
|
||||
/// Registers a specific prototype name to be ignored.
|
||||
/// </summary>
|
||||
void RegisterIgnore(string name);
|
||||
|
||||
/// <summary>
|
||||
/// Loads a single prototype class type into the manager.
|
||||
/// </summary>
|
||||
/// <param name="protoClass">A prototype class type that implements IPrototype. This type also
|
||||
/// requires a <see cref="PrototypeAttribute"/> with a non-empty class string.</param>
|
||||
void RegisterType(Type protoClass);
|
||||
|
||||
event Action<YamlStream, string>? LoadedData;
|
||||
|
||||
/// <summary>
|
||||
/// Fired when prototype are reloaded. The event args contain the modified prototypes.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This does NOT fire on initial prototype load.
|
||||
/// </remarks>
|
||||
event Action<PrototypesReloadedEventArgs> PrototypesReloaded;
|
||||
}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
using System;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
|
||||
|
||||
namespace Robust.Shared.Prototypes
|
||||
{
|
||||
/// <summary>
|
||||
/// Quick attribute to give the prototype its type string.
|
||||
/// To prevent needing to instantiate it because interfaces can't declare statics.
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Class, Inherited = false)]
|
||||
[BaseTypeRequired(typeof(IPrototype))]
|
||||
[MeansImplicitUse]
|
||||
[MeansDataDefinition]
|
||||
public sealed class PrototypeAttribute : Attribute
|
||||
{
|
||||
private readonly string type;
|
||||
public string Type => type;
|
||||
public readonly int LoadPriority;
|
||||
public readonly string LoadBefore;
|
||||
public readonly string LoadAfter;
|
||||
|
||||
public PrototypeAttribute(string type, int loadPriority = 1, string loadBefore="" ,string loadAfter= "")
|
||||
{
|
||||
this.type = type;
|
||||
LoadPriority = loadPriority;
|
||||
LoadBefore = loadBefore;
|
||||
LoadAfter = loadAfter;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,6 @@ using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Threading;
|
||||
using JetBrains.Annotations;
|
||||
@@ -26,8 +25,175 @@ using YamlDotNet.RepresentationModel;
|
||||
|
||||
namespace Robust.Shared.Prototypes
|
||||
{
|
||||
/// <summary>
|
||||
/// Handle storage and loading of YAML prototypes.
|
||||
/// </summary>
|
||||
public interface IPrototypeManager
|
||||
{
|
||||
void Initialize();
|
||||
|
||||
/// <summary>
|
||||
/// Return an IEnumerable to iterate all prototypes of a certain type.
|
||||
/// </summary>
|
||||
/// <exception cref="KeyNotFoundException">
|
||||
/// Thrown if the type of prototype is not registered.
|
||||
/// </exception>
|
||||
IEnumerable<T> EnumeratePrototypes<T>() where T : class, IPrototype;
|
||||
|
||||
/// <summary>
|
||||
/// Return an IEnumerable to iterate all prototypes of a certain type.
|
||||
/// </summary>
|
||||
/// <exception cref="KeyNotFoundException">
|
||||
/// Thrown if the type of prototype is not registered.
|
||||
/// </exception>
|
||||
IEnumerable<IPrototype> EnumeratePrototypes(Type type);
|
||||
|
||||
/// <summary>
|
||||
/// Return an IEnumerable to iterate all prototypes of a certain variant.
|
||||
/// </summary>
|
||||
/// <exception cref="KeyNotFoundException">
|
||||
/// Thrown if the variant of prototype is not registered.
|
||||
/// </exception>
|
||||
IEnumerable<IPrototype> EnumeratePrototypes(string variant);
|
||||
|
||||
/// <summary>
|
||||
/// Index for a <see cref="IPrototype"/> by ID.
|
||||
/// </summary>
|
||||
/// <exception cref="KeyNotFoundException">
|
||||
/// Thrown if the type of prototype is not registered.
|
||||
/// </exception>
|
||||
T Index<T>(string id) where T : class, IPrototype;
|
||||
|
||||
/// <summary>
|
||||
/// Index for a <see cref="IPrototype"/> by ID.
|
||||
/// </summary>
|
||||
/// <exception cref="KeyNotFoundException">
|
||||
/// Thrown if the ID does not exist or the type of prototype is not registered.
|
||||
/// </exception>
|
||||
IPrototype Index(Type type, string id);
|
||||
|
||||
/// <summary>
|
||||
/// Returns whether a prototype of type <typeparamref name="T"/> with the specified <param name="id"/> exists.
|
||||
/// </summary>
|
||||
bool HasIndex<T>(string id) where T : class, IPrototype;
|
||||
bool TryIndex<T>(string id, [NotNullWhen(true)] out T? prototype) where T : class, IPrototype;
|
||||
bool TryIndex(Type type, string id, [NotNullWhen(true)] out IPrototype? prototype);
|
||||
|
||||
/// <summary>
|
||||
/// Returns whether a prototype variant <param name="variant"/> exists.
|
||||
/// </summary>
|
||||
/// <param name="variant">Identifier for the prototype variant.</param>
|
||||
/// <returns>Whether the prototype variant exists.</returns>
|
||||
bool HasVariant(string variant);
|
||||
|
||||
/// <summary>
|
||||
/// Returns the Type for a prototype variant.
|
||||
/// </summary>
|
||||
/// <param name="variant">Identifier for the prototype variant.</param>
|
||||
/// <returns>The specified prototype Type.</returns>
|
||||
/// <exception cref="KeyNotFoundException">
|
||||
/// Thrown when the specified prototype variant isn't registered or doesn't exist.
|
||||
/// </exception>
|
||||
Type GetVariantType(string variant);
|
||||
|
||||
/// <summary>
|
||||
/// Attempts to get the Type for a prototype variant.
|
||||
/// </summary>
|
||||
/// <param name="variant">Identifier for the prototype variant.</param>
|
||||
/// <param name="prototype">The specified prototype Type, or null.</param>
|
||||
/// <returns>Whether the prototype type was found and <see cref="prototype"/> isn't null.</returns>
|
||||
bool TryGetVariantType(string variant, [NotNullWhen(true)] out Type? prototype);
|
||||
|
||||
/// <summary>
|
||||
/// Attempts to get a prototype's variant.
|
||||
/// </summary>
|
||||
/// <param name="type"></param>
|
||||
/// <param name="variant"></param>
|
||||
/// <returns></returns>
|
||||
bool TryGetVariantFrom(Type type, [NotNullWhen(true)] out string? variant);
|
||||
|
||||
/// <summary>
|
||||
/// Attempts to get a prototype's variant.
|
||||
/// </summary>
|
||||
/// <param name="prototype">The prototype in question.</param>
|
||||
/// <param name="variant">Identifier for the prototype variant, or null.</param>
|
||||
/// <returns>Whether the prototype variant was successfully retrieved.</returns>
|
||||
bool TryGetVariantFrom(IPrototype prototype, [NotNullWhen(true)] out string? variant);
|
||||
|
||||
/// <summary>
|
||||
/// Attempts to get a prototype's variant.
|
||||
/// </summary>
|
||||
/// <param name="variant">Identifier for the prototype variant, or null.</param>
|
||||
/// <typeparam name="T">The prototype in question.</typeparam>
|
||||
/// <returns>Whether the prototype variant was successfully retrieved.</returns>
|
||||
bool TryGetVariantFrom<T>([NotNullWhen(true)] out string? variant) where T : class, IPrototype;
|
||||
|
||||
/// <summary>
|
||||
/// Load prototypes from files in a directory, recursively.
|
||||
/// </summary>
|
||||
List<IPrototype> LoadDirectory(ResourcePath path, bool overwrite = false);
|
||||
|
||||
Dictionary<string, HashSet<ErrorNode>> ValidateDirectory(ResourcePath path);
|
||||
|
||||
List<IPrototype> LoadFromStream(TextReader stream, bool overwrite = false);
|
||||
|
||||
List<IPrototype> LoadString(string str, bool overwrite = false);
|
||||
|
||||
void RemoveString(string prototypes);
|
||||
|
||||
/// <summary>
|
||||
/// Clear out all prototypes and reset to a blank slate.
|
||||
/// </summary>
|
||||
void Clear();
|
||||
|
||||
/// <summary>
|
||||
/// Syncs all inter-prototype data. Call this when operations adding new prototypes are done.
|
||||
/// </summary>
|
||||
void Resync();
|
||||
|
||||
/// <summary>
|
||||
/// Registers a specific prototype name to be ignored.
|
||||
/// </summary>
|
||||
void RegisterIgnore(string name);
|
||||
|
||||
/// <summary>
|
||||
/// Loads a single prototype class type into the manager.
|
||||
/// </summary>
|
||||
/// <param name="protoClass">A prototype class type that implements IPrototype. This type also
|
||||
/// requires a <see cref="PrototypeAttribute"/> with a non-empty class string.</param>
|
||||
void RegisterType(Type protoClass);
|
||||
|
||||
event Action<YamlStream, string>? LoadedData;
|
||||
|
||||
/// <summary>
|
||||
/// Fired when prototype are reloaded. The event args contain the modified prototypes.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This does NOT fire on initial prototype load.
|
||||
/// </remarks>
|
||||
event Action<PrototypesReloadedEventArgs> PrototypesReloaded;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Quick attribute to give the prototype its type string.
|
||||
/// To prevent needing to instantiate it because interfaces can't declare statics.
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Class, Inherited = false)]
|
||||
[BaseTypeRequired(typeof(IPrototype))]
|
||||
[MeansImplicitUse]
|
||||
[MeansDataDefinition]
|
||||
public sealed class PrototypeAttribute : Attribute
|
||||
{
|
||||
private readonly string type;
|
||||
public string Type => type;
|
||||
public readonly int LoadPriority = 1;
|
||||
|
||||
public PrototypeAttribute(string type, int loadPriority = 1)
|
||||
{
|
||||
this.type = type;
|
||||
LoadPriority = loadPriority;
|
||||
}
|
||||
}
|
||||
|
||||
[Virtual]
|
||||
public class PrototypeManager : IPrototypeManager
|
||||
@@ -38,12 +204,11 @@ namespace Robust.Shared.Prototypes
|
||||
[Dependency] protected readonly ITaskManager TaskManager = default!;
|
||||
[Dependency] private readonly ISerializationManager _serializationManager = default!;
|
||||
|
||||
private readonly Dictionary<string, Type> _types = new();
|
||||
private readonly Dictionary<string, Type> _prototypeTypes = new();
|
||||
private readonly Dictionary<Type, int> _prototypePriorities = new();
|
||||
|
||||
private bool _initialized;
|
||||
private bool _hasEverBeenReloaded;
|
||||
private int mappingErrors;
|
||||
|
||||
#region IPrototypeManager members
|
||||
|
||||
@@ -51,13 +216,8 @@ namespace Robust.Shared.Prototypes
|
||||
private readonly Dictionary<Type, Dictionary<string, DeserializationResult>> _prototypeResults = new();
|
||||
private readonly Dictionary<Type, PrototypeInheritanceTree> _inheritanceTrees = new();
|
||||
|
||||
private readonly HashSet<Type> LoadBeforeList = new ();
|
||||
private readonly HashSet<Type> LoadNormalList = new ();
|
||||
private readonly HashSet<Type> LoadAfterList = new ();
|
||||
|
||||
private readonly HashSet<ErrorNode> ErrorNodes = new ();
|
||||
|
||||
private readonly HashSet<string> _ignoredPrototypeTypes = new();
|
||||
|
||||
public virtual void Initialize()
|
||||
{
|
||||
if (_initialized)
|
||||
@@ -65,9 +225,8 @@ namespace Robust.Shared.Prototypes
|
||||
throw new InvalidOperationException($"{nameof(PrototypeManager)} has already been initialized.");
|
||||
}
|
||||
|
||||
mappingErrors = 0;
|
||||
ReloadTypes();
|
||||
_initialized = true;
|
||||
ReloadPrototypeTypes();
|
||||
}
|
||||
|
||||
public IEnumerable<T> EnumeratePrototypes<T>() where T : class, IPrototype
|
||||
@@ -124,8 +283,7 @@ namespace Robust.Shared.Prototypes
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
mappingErrors = 0;
|
||||
_types.Clear();
|
||||
_prototypeTypes.Clear();
|
||||
_prototypes.Clear();
|
||||
_prototypeResults.Clear();
|
||||
_inheritanceTrees.Clear();
|
||||
@@ -139,7 +297,7 @@ namespace Robust.Shared.Prototypes
|
||||
protected void ReloadPrototypes(IEnumerable<ResourcePath> filePaths)
|
||||
{
|
||||
#if !FULL_RELEASE
|
||||
var changed = filePaths.SelectMany(f => LoadFromFile(f.ToRootedPath(), true)).ToList();
|
||||
var changed = filePaths.SelectMany(f => LoadFile(f.ToRootedPath(), true)).ToList();
|
||||
ReloadPrototypes(changed);
|
||||
#endif
|
||||
}
|
||||
@@ -216,7 +374,6 @@ namespace Robust.Shared.Prototypes
|
||||
#endif
|
||||
}
|
||||
|
||||
#region Inheritance Tree
|
||||
public void Resync()
|
||||
{
|
||||
var trees = _inheritanceTrees.Keys.ToList();
|
||||
@@ -285,6 +442,174 @@ namespace Robust.Shared.Prototypes
|
||||
_prototypes[type][id] = (IPrototype) populatedRes.RawValue!;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public List<IPrototype> LoadDirectory(ResourcePath path, bool overwrite = false)
|
||||
{
|
||||
var changedPrototypes = new List<IPrototype>();
|
||||
|
||||
_hasEverBeenReloaded = true;
|
||||
var streams = Resources.ContentFindFiles(path).ToList().AsParallel()
|
||||
.Where(filePath => filePath.Extension == "yml" && !filePath.Filename.StartsWith("."));
|
||||
|
||||
foreach (var resourcePath in streams)
|
||||
{
|
||||
var filePrototypes = LoadFile(resourcePath, overwrite);
|
||||
changedPrototypes.AddRange(filePrototypes);
|
||||
}
|
||||
|
||||
return changedPrototypes;
|
||||
}
|
||||
|
||||
public Dictionary<string, HashSet<ErrorNode>> ValidateDirectory(ResourcePath path)
|
||||
{
|
||||
var streams = Resources.ContentFindFiles(path).ToList().AsParallel()
|
||||
.Where(filePath => filePath.Extension == "yml" && !filePath.Filename.StartsWith("."));
|
||||
|
||||
var dict = new Dictionary<string, HashSet<ErrorNode>>();
|
||||
foreach (var resourcePath in streams)
|
||||
{
|
||||
using var reader = ReadFile(resourcePath);
|
||||
|
||||
if (reader == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var yamlStream = new YamlStream();
|
||||
yamlStream.Load(reader);
|
||||
|
||||
for (var i = 0; i < yamlStream.Documents.Count; i++)
|
||||
{
|
||||
var rootNode = (YamlSequenceNode) yamlStream.Documents[i].RootNode;
|
||||
foreach (YamlMappingNode node in rootNode.Cast<YamlMappingNode>())
|
||||
{
|
||||
var type = node.GetNode("type").AsString();
|
||||
if (!_prototypeTypes.ContainsKey(type))
|
||||
{
|
||||
if (_ignoredPrototypeTypes.Contains(type))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
throw new PrototypeLoadException($"Unknown prototype type: '{type}'");
|
||||
}
|
||||
|
||||
var mapping = node.ToDataNodeCast<MappingDataNode>();
|
||||
mapping.Remove("type");
|
||||
var errorNodes = _serializationManager.ValidateNode(_prototypeTypes[type], mapping).GetErrors()
|
||||
.ToHashSet();
|
||||
if (errorNodes.Count == 0) continue;
|
||||
if (!dict.TryGetValue(resourcePath.ToString(), out var hashSet))
|
||||
dict[resourcePath.ToString()] = new HashSet<ErrorNode>();
|
||||
dict[resourcePath.ToString()].UnionWith(errorNodes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return dict;
|
||||
}
|
||||
|
||||
private StreamReader? ReadFile(ResourcePath file, bool @throw = true)
|
||||
{
|
||||
var retries = 0;
|
||||
|
||||
// This might be shit-code, but its pjb-responded-idk-when-asked shit-code.
|
||||
while (true)
|
||||
{
|
||||
try
|
||||
{
|
||||
var reader = new StreamReader(Resources.ContentFileRead(file), EncodingHelpers.UTF8);
|
||||
return reader;
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
if (retries > 10)
|
||||
{
|
||||
if (@throw)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
|
||||
Logger.Error($"Error reloading prototypes in file {file}.", e);
|
||||
return null;
|
||||
}
|
||||
|
||||
retries++;
|
||||
Thread.Sleep(10);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public HashSet<IPrototype> LoadFile(ResourcePath file, bool overwrite = false)
|
||||
{
|
||||
var changedPrototypes = new HashSet<IPrototype>();
|
||||
|
||||
try
|
||||
{
|
||||
using var reader = ReadFile(file, !overwrite);
|
||||
|
||||
if (reader == null)
|
||||
{
|
||||
return changedPrototypes;
|
||||
}
|
||||
|
||||
var yamlStream = new YamlStream();
|
||||
yamlStream.Load(reader);
|
||||
|
||||
LoadedData?.Invoke(yamlStream, file.ToString());
|
||||
|
||||
for (var i = 0; i < yamlStream.Documents.Count; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
var documentPrototypes = LoadFromDocument(yamlStream.Documents[i], overwrite);
|
||||
changedPrototypes.UnionWith(documentPrototypes);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.ErrorS("eng", $"Exception whilst loading prototypes from {file}#{i}:\n{e}");
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (YamlException e)
|
||||
{
|
||||
var sawmill = Logger.GetSawmill("eng");
|
||||
sawmill.Error("YamlException whilst loading prototypes from {0}: {1}", file, e.Message);
|
||||
}
|
||||
|
||||
return changedPrototypes;
|
||||
}
|
||||
|
||||
public List<IPrototype> LoadFromStream(TextReader stream, bool overwrite = false)
|
||||
{
|
||||
var changedPrototypes = new List<IPrototype>();
|
||||
_hasEverBeenReloaded = true;
|
||||
var yaml = new YamlStream();
|
||||
yaml.Load(stream);
|
||||
|
||||
for (var i = 0; i < yaml.Documents.Count; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
var documentPrototypes = LoadFromDocument(yaml.Documents[i], overwrite);
|
||||
changedPrototypes.AddRange(documentPrototypes);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new PrototypeLoadException($"Failed to load prototypes from document#{i}", e);
|
||||
}
|
||||
}
|
||||
|
||||
LoadedData?.Invoke(yaml, "anonymous prototypes YAML stream");
|
||||
|
||||
return changedPrototypes;
|
||||
}
|
||||
|
||||
public List<IPrototype> LoadString(string str, bool overwrite = false)
|
||||
{
|
||||
return LoadFromStream(new StringReader(str), overwrite);
|
||||
}
|
||||
|
||||
public void RemoveString(string prototypes)
|
||||
{
|
||||
var reader = new StringReader(prototypes);
|
||||
@@ -298,7 +623,7 @@ namespace Robust.Shared.Prototypes
|
||||
foreach (var node in root.Cast<YamlMappingNode>())
|
||||
{
|
||||
var typeString = node.GetNode("type").AsString();
|
||||
var type = _types[typeString];
|
||||
var type = _prototypeTypes[typeString];
|
||||
|
||||
var id = node.GetNode("id").AsString();
|
||||
|
||||
@@ -311,203 +636,62 @@ namespace Robust.Shared.Prototypes
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
public Dictionary<string, HashSet<ErrorNode>> ValidateDirectory(ResourcePath path)
|
||||
{
|
||||
var streams = Resources.ContentFindFiles(path).ToList().AsParallel()
|
||||
.Where(filePath => filePath.Extension == "yml" && !filePath.Filename.StartsWith("."));
|
||||
|
||||
var dict = new Dictionary<string, HashSet<ErrorNode>>();
|
||||
|
||||
foreach (var resourcePath in streams)
|
||||
{
|
||||
LoadFromFile(resourcePath, false, true);
|
||||
|
||||
if (!ErrorNodes.Any())
|
||||
continue;
|
||||
|
||||
if (!dict.TryGetValue(resourcePath.ToString(), out var hashSet))
|
||||
dict[resourcePath.ToString()] = new HashSet<ErrorNode>();
|
||||
|
||||
dict[resourcePath.ToString()].UnionWith(ErrorNodes);
|
||||
|
||||
}
|
||||
|
||||
return dict;
|
||||
}
|
||||
|
||||
#region Prototype Loading
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Loads Prototypes from a path.
|
||||
/// </summary>
|
||||
/// <param name="path">path to files to load as prototype.</param>
|
||||
/// <param name="overwrite">Overwrite if prototype already is loaded and exists</param>
|
||||
/// <returns>HashSet of Loaded Prototypes</returns>
|
||||
public List<IPrototype> LoadDirectory(ResourcePath path, bool overwrite = false)
|
||||
{
|
||||
var changedPrototypes = new List<IPrototype>();
|
||||
|
||||
_hasEverBeenReloaded = true;
|
||||
var streams = Resources.ContentFindFiles(path).ToList().AsParallel()
|
||||
.Where(filePath => filePath.Extension == "yml" && !filePath.Filename.StartsWith("."));
|
||||
|
||||
foreach (var resourcePath in streams)
|
||||
{
|
||||
var filePrototypes = LoadFromFile(resourcePath, overwrite);
|
||||
changedPrototypes.AddRange(filePrototypes);
|
||||
}
|
||||
|
||||
return changedPrototypes;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads Prototypes from a file.
|
||||
/// </summary>
|
||||
/// <param name="file">file to load as prototype.</param>
|
||||
/// <param name="overwrite">Overwrite if prototype already is loaded and exists</param>
|
||||
/// /// <param name="validateMapping">toggle true to receive a count of total mapping errors</param>
|
||||
/// <returns>HashSet of Loaded Prototypes</returns>
|
||||
public HashSet<IPrototype> LoadFromFile(ResourcePath file, bool overwrite = false, bool validateMapping = false)
|
||||
{
|
||||
HashSet<IPrototype> LoadedPrototypes = new();
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
var reader = new StreamReader(Resources.ContentFileRead(file), EncodingHelpers.UTF8);
|
||||
|
||||
var yamlStream = new YamlStream();
|
||||
yamlStream.Load(reader);
|
||||
|
||||
LoadedPrototypes = LoadFromDocument(yamlStream, overwrite, validateMapping, actionMessage: file.ToString());
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
Logger.Error($"Error loading prototypes in file {file}.", e);
|
||||
}
|
||||
}
|
||||
catch (YamlException e)
|
||||
{
|
||||
var sawmill = Logger.GetSawmill("eng");
|
||||
sawmill.Error("Caught YamlException whilst loading prototypes from a File {0}: {1}", file.Filename, e.Message);
|
||||
}
|
||||
|
||||
return LoadedPrototypes;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads Prototypes from a string.
|
||||
/// </summary>
|
||||
/// <param name="str">Input string to load as prototype.</param>
|
||||
/// <param name="overwrite">Overwrite if prototype already is loaded and exists</param>
|
||||
/// <param name="actionMessage">String that will be included in the LoadedData Event</param>
|
||||
/// <returns>HashSet of Loaded Prototypes</returns>
|
||||
public HashSet<IPrototype> LoadFromString(string str, bool overwrite = false, string actionMessage = "")
|
||||
{
|
||||
var yamlStream = new YamlStream();
|
||||
yamlStream.Load(new StringReader(str));
|
||||
|
||||
return LoadFromDocument(yamlStream, overwrite, actionMessage: actionMessage);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads YAML Prototypes via a Yaml Stream
|
||||
/// </summary>
|
||||
/// <param name="yamlStream">YamlStream to process</param>
|
||||
/// <param name="mappingErrors">a count of mapping errors. is 0 until you toggle validateMapping on.</param>
|
||||
/// <param name="validateMapping">toggle true to receive a count of total mapping errors</param>
|
||||
/// <param name="overwrite">Overwrite if prototype already is loaded and exists.</param>
|
||||
/// <param name="actionMessage">String that will be included in the LoadedData Event</param>
|
||||
/// <returns>HashSet of Loaded Prototypes</returns>
|
||||
/// <exception cref="PrototypeLoadException">Thrown when Prototype failed to load</exception>
|
||||
private HashSet<IPrototype> LoadFromDocument(YamlStream yamlStream, bool overwrite = false,
|
||||
bool validateMapping = false, string actionMessage = "")
|
||||
{
|
||||
var loadedPrototypes = new HashSet<IPrototype>();
|
||||
|
||||
|
||||
for (var i = 0; i < yamlStream.Documents.Count(); i++)
|
||||
{
|
||||
var prototypeDocument = yamlStream.Documents[i];
|
||||
var rootNode = (YamlSequenceNode) prototypeDocument.RootNode;
|
||||
|
||||
foreach (YamlMappingNode node in rootNode.Cast<YamlMappingNode>())
|
||||
{
|
||||
var type = node.GetNode("type").AsString();
|
||||
if (!_types.ContainsKey(type))
|
||||
{
|
||||
if (_ignoredPrototypeTypes.Contains(type))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
throw new PrototypeLoadException($"Unknown prototype type: '{type}'");
|
||||
}
|
||||
|
||||
var prototypeType = _types[type];
|
||||
|
||||
var res = _serializationManager.Read(prototypeType, node.ToDataNode(), skipHook: true);
|
||||
var prototype = (IPrototype) res.RawValue!;
|
||||
|
||||
if (!overwrite && _prototypes[prototypeType].ContainsKey(prototype.ID))
|
||||
{
|
||||
throw new PrototypeLoadException($"Duplicate ID: '{prototype.ID}'");
|
||||
}
|
||||
|
||||
_prototypeResults[prototypeType][prototype.ID] = res;
|
||||
if (prototype is IInheritingPrototype inheritingPrototype)
|
||||
{
|
||||
_inheritanceTrees[prototypeType].AddId(prototype.ID, inheritingPrototype.Parent, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
//we call it here since it wont get called when pushing inheritance
|
||||
res.CallAfterDeserializationHook();
|
||||
}
|
||||
|
||||
_prototypes[prototypeType][prototype.ID] = prototype;
|
||||
loadedPrototypes.Add(prototype);
|
||||
|
||||
if (validateMapping)
|
||||
{
|
||||
var mapping = node.ToDataNodeCast<MappingDataNode>();
|
||||
mapping.Remove("type");
|
||||
var errorNodes = _serializationManager.ValidateNode(_types[type], mapping).GetErrors()
|
||||
.ToHashSet();
|
||||
mappingErrors = errorNodes.Count;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
LoadedData?.Invoke(yamlStream, actionMessage);
|
||||
return loadedPrototypes;
|
||||
}
|
||||
#endregion
|
||||
#endregion IPrototypeManager members
|
||||
|
||||
private void ReloadTypes()
|
||||
private void ReloadPrototypeTypes()
|
||||
{
|
||||
Clear();
|
||||
foreach (var type in _reflectionManager.GetAllChildren<IPrototype>())
|
||||
{
|
||||
var prototypeAttributes = (PrototypeAttribute?) Attribute.GetCustomAttribute(type, typeof(PrototypeAttribute));
|
||||
|
||||
if ( prototypeAttributes!.LoadBefore != string.Empty)
|
||||
LoadBeforeList.Add(type);
|
||||
else if (prototypeAttributes!.LoadAfter != string.Empty)
|
||||
LoadAfterList.Add(type);
|
||||
else
|
||||
LoadNormalList.Add(type);
|
||||
|
||||
RegisterType(type);
|
||||
}
|
||||
}
|
||||
|
||||
private HashSet<IPrototype> LoadFromDocument(YamlDocument document, bool overwrite = false)
|
||||
{
|
||||
var changedPrototypes = new HashSet<IPrototype>();
|
||||
var rootNode = (YamlSequenceNode) document.RootNode;
|
||||
|
||||
foreach (YamlMappingNode node in rootNode.Cast<YamlMappingNode>())
|
||||
{
|
||||
var type = node.GetNode("type").AsString();
|
||||
if (!_prototypeTypes.ContainsKey(type))
|
||||
{
|
||||
if (_ignoredPrototypeTypes.Contains(type))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
throw new PrototypeLoadException($"Unknown prototype type: '{type}'");
|
||||
}
|
||||
|
||||
var prototypeType = _prototypeTypes[type];
|
||||
var res = _serializationManager.Read(prototypeType, node.ToDataNode(), skipHook: true);
|
||||
var prototype = (IPrototype) res.RawValue!;
|
||||
|
||||
if (!overwrite && _prototypes[prototypeType].ContainsKey(prototype.ID))
|
||||
{
|
||||
throw new PrototypeLoadException($"Duplicate ID: '{prototype.ID}'");
|
||||
}
|
||||
|
||||
_prototypeResults[prototypeType][prototype.ID] = res;
|
||||
if (prototype is IInheritingPrototype inheritingPrototype)
|
||||
{
|
||||
_inheritanceTrees[prototypeType].AddId(prototype.ID, inheritingPrototype.Parent, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
//we call it here since it wont get called when pushing inheritance
|
||||
res.CallAfterDeserializationHook();
|
||||
}
|
||||
|
||||
_prototypes[prototypeType][prototype.ID] = prototype;
|
||||
changedPrototypes.Add(prototype);
|
||||
}
|
||||
|
||||
return changedPrototypes;
|
||||
}
|
||||
|
||||
public bool HasIndex<T>(string id) where T : class, IPrototype
|
||||
{
|
||||
@@ -539,19 +723,19 @@ namespace Robust.Shared.Prototypes
|
||||
/// <inheritdoc />
|
||||
public bool HasVariant(string variant)
|
||||
{
|
||||
return _types.ContainsKey(variant);
|
||||
return _prototypeTypes.ContainsKey(variant);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Type GetVariantType(string variant)
|
||||
{
|
||||
return _types[variant];
|
||||
return _prototypeTypes[variant];
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool TryGetVariantType(string variant, [NotNullWhen(true)] out Type? prototype)
|
||||
{
|
||||
return _types.TryGetValue(variant, out prototype);
|
||||
return _prototypeTypes.TryGetValue(variant, out prototype);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -609,14 +793,14 @@ namespace Robust.Shared.Prototypes
|
||||
"No " + nameof(PrototypeAttribute) + " to give it a type string.");
|
||||
}
|
||||
|
||||
if (_types.ContainsKey(attribute.Type))
|
||||
if (_prototypeTypes.ContainsKey(attribute.Type))
|
||||
{
|
||||
throw new InvalidImplementationException(type,
|
||||
typeof(IPrototype),
|
||||
$"Duplicate prototype type ID: {attribute.Type}. Current: {_types[attribute.Type]}");
|
||||
$"Duplicate prototype type ID: {attribute.Type}. Current: {_prototypeTypes[attribute.Type]}");
|
||||
}
|
||||
|
||||
_types[attribute.Type] = type;
|
||||
_prototypeTypes[attribute.Type] = type;
|
||||
_prototypePriorities[type] = attribute.LoadPriority;
|
||||
|
||||
if (typeof(IPrototype).IsAssignableFrom(type))
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Robust.Shared.Asynchronous;
|
||||
using Robust.Shared.Asynchronous;
|
||||
using Robust.Shared.Configuration;
|
||||
using Robust.Shared.ContentPack;
|
||||
using Robust.Shared.Exceptions;
|
||||
@@ -32,7 +32,7 @@ namespace Robust.Shared
|
||||
IoCManager.Register<ILocalizationManager, LocalizationManager>();
|
||||
IoCManager.Register<ILocalizationManagerInternal, LocalizationManager>();
|
||||
IoCManager.Register<ILogManager, LogManager>();
|
||||
IoCManager.Register<IPauseManager, PauseManager>();
|
||||
IoCManager.Register<IPauseManager, NetworkedMapManager>();
|
||||
IoCManager.Register<IModLoader, ModLoader>();
|
||||
IoCManager.Register<IModLoaderInternal, ModLoader>();
|
||||
IoCManager.Register<INetManager, NetManager>();
|
||||
|
||||
@@ -1,15 +1,20 @@
|
||||
using System;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Map;
|
||||
|
||||
namespace Robust.Shared.Timing
|
||||
{
|
||||
[Obsolete("Use the same functions on IMapManager.")]
|
||||
public interface IPauseManager
|
||||
{
|
||||
void SetMapPaused(MapId mapId, bool paused);
|
||||
|
||||
void DoMapInitialize(MapId mapId);
|
||||
|
||||
[Obsolete("This function does nothing, per-grid pausing isn't a thing anymore.")]
|
||||
void DoGridMapInitialize(GridId gridId);
|
||||
|
||||
[Obsolete("This function does nothing, per-grid pausing isn't a thing anymore.")]
|
||||
void DoGridMapInitialize(IMapGrid grid);
|
||||
|
||||
void AddUninitializedMap(MapId mapId);
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace Robust.UnitTesting.Server.GameObjects.Components
|
||||
{
|
||||
var sim = RobustServerSimulation
|
||||
.NewSimulation()
|
||||
.RegisterPrototypes(protoMan => protoMan.LoadFromString(Prototypes))
|
||||
.RegisterPrototypes(protoMan => protoMan.LoadString(Prototypes))
|
||||
.InitializeInstance();
|
||||
|
||||
// Adds the map with id 1, and spawns entity 1 as the map entity.
|
||||
|
||||
@@ -72,7 +72,7 @@ namespace Robust.UnitTesting.Server.GameObjects.Components
|
||||
IoCManager.Resolve<ISerializationManager>().Initialize();
|
||||
var manager = IoCManager.Resolve<IPrototypeManager>();
|
||||
manager.RegisterType(typeof(EntityPrototype));
|
||||
manager.LoadFromString(PROTOTYPES);
|
||||
manager.LoadFromStream(new StringReader(PROTOTYPES));
|
||||
manager.Resync();
|
||||
|
||||
// build the net dream
|
||||
|
||||
@@ -51,7 +51,7 @@ namespace Robust.UnitTesting.Server.GameObjects
|
||||
IoCManager.Resolve<ISerializationManager>().Initialize();
|
||||
var manager = IoCManager.Resolve<IPrototypeManager>();
|
||||
manager.RegisterType(typeof(EntityPrototype));
|
||||
manager.LoadFromString(PROTOTYPES);
|
||||
manager.LoadFromStream(new StringReader(PROTOTYPES));
|
||||
manager.Resync();
|
||||
|
||||
//NOTE: The grids have not moved, so we can assert worldpos == localpos for the test
|
||||
|
||||
@@ -207,7 +207,7 @@ namespace Robust.UnitTesting.Server
|
||||
container.Register<IIslandManager, IslandManager>();
|
||||
container.Register<IManifoldManager, CollisionManager>();
|
||||
container.Register<IMapManagerInternal, MapManager>();
|
||||
container.RegisterInstance<IPauseManager>(new Mock<IPauseManager>().Object); // TODO: get timing working similar to RobustIntegrationTest
|
||||
container.Register<IPauseManager, MapManager>();
|
||||
container.Register<IPhysicsManager, PhysicsManager>();
|
||||
|
||||
_diFactory?.Invoke(container);
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace Robust.UnitTesting.Shared.GameObjects
|
||||
{
|
||||
var sim = RobustServerSimulation
|
||||
.NewSimulation()
|
||||
.RegisterPrototypes(protoMan => protoMan.LoadFromString(PROTOTYPE))
|
||||
.RegisterPrototypes(protoMan => protoMan.LoadString(PROTOTYPE))
|
||||
.InitializeInstance();
|
||||
|
||||
var mapManager = sim.Resolve<IMapManager>();
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace Robust.UnitTesting.Shared.GameObjects.Systems
|
||||
.NewSimulation()
|
||||
.RegisterPrototypes(f=>
|
||||
{
|
||||
f.LoadFromString(Prototypes);
|
||||
f.LoadString(Prototypes);
|
||||
})
|
||||
.InitializeInstance();
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ namespace Robust.UnitTesting.Shared.Map
|
||||
IoCManager.Resolve<ISerializationManager>().Initialize();
|
||||
var prototypeManager = IoCManager.Resolve<IPrototypeManager>();
|
||||
prototypeManager.RegisterType(typeof(EntityPrototype));
|
||||
prototypeManager.LoadFromString(PROTOTYPES);
|
||||
prototypeManager.LoadFromStream(new StringReader(PROTOTYPES));
|
||||
prototypeManager.Resync();
|
||||
|
||||
var factory = IoCManager.Resolve<IComponentFactory>();
|
||||
|
||||
@@ -8,44 +8,37 @@ using Robust.Shared.IoC;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Physics.Broadphase;
|
||||
using MapGrid = Robust.Shared.Map.MapGrid;
|
||||
using Robust.UnitTesting.Server;
|
||||
|
||||
namespace Robust.UnitTesting.Shared.Map
|
||||
{
|
||||
[TestFixture, TestOf(typeof(MapGrid))]
|
||||
sealed class MapGrid_Tests : RobustUnitTest
|
||||
sealed class MapGrid_Tests
|
||||
{
|
||||
protected override void OverrideIoC()
|
||||
private static ISimulation SimulationFactory()
|
||||
{
|
||||
base.OverrideIoC();
|
||||
var sim = RobustServerSimulation
|
||||
.NewSimulation()
|
||||
.InitializeInstance();
|
||||
|
||||
var mock = new Mock<IEntitySystemManager>();
|
||||
var broady = new BroadPhaseSystem();
|
||||
var physics = new PhysicsSystem();
|
||||
mock.Setup(m => m.GetEntitySystem<SharedBroadphaseSystem>()).Returns(broady);
|
||||
mock.Setup(m => m.GetEntitySystem<SharedPhysicsSystem>()).Returns(physics);
|
||||
|
||||
IoCManager.RegisterInstance<IEntitySystemManager>(mock.Object, true);
|
||||
}
|
||||
|
||||
[OneTimeSetUp]
|
||||
public void Setup()
|
||||
{
|
||||
IoCManager.Resolve<IComponentFactory>().GenerateNetIds();
|
||||
return sim;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetTileRefCoords()
|
||||
{
|
||||
var grid = MapGridFactory(new GridId(1));
|
||||
var sim = SimulationFactory();
|
||||
var mapMan = sim.Resolve<IMapManager>();
|
||||
var mapId = mapMan.CreateMap();
|
||||
var grid = (IMapGridInternal)mapMan.CreateGrid(mapId, null, 8);
|
||||
|
||||
grid.SetTile(new Vector2i(-9, -1), new Tile(1, 2));
|
||||
|
||||
var result = grid.GetTileRef(new Vector2i(-9, -1));
|
||||
|
||||
Assert.That(grid.ChunkCount, Is.EqualTo(1));
|
||||
Assert.That(grid.GetMapChunks().Keys.ToList()[0], Is.EqualTo(new Vector2i(-2, -1)));
|
||||
Assert.That(result, Is.EqualTo(new TileRef(new MapId(5), new GridId(1), new Vector2i(-9,-1), new Tile(1, 2))));
|
||||
Assert.That(result, Is.EqualTo(new TileRef(mapId, grid.Index, new Vector2i(-9,-1), new Tile(1, 2))));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -54,7 +47,11 @@ namespace Robust.UnitTesting.Shared.Map
|
||||
[Test]
|
||||
public void BoundsExpansion()
|
||||
{
|
||||
var grid = MapGridFactory(new GridId(1));
|
||||
var sim = SimulationFactory();
|
||||
var mapMan = sim.Resolve<IMapManager>();
|
||||
var mapId = mapMan.CreateMap();
|
||||
var grid = (IMapGridInternal)mapMan.CreateGrid(mapId, null, 8);
|
||||
grid.WorldPosition = new Vector2(3, 5);
|
||||
|
||||
grid.SetTile(new Vector2i(-1, -2), new Tile(1));
|
||||
grid.SetTile(new Vector2i(1, 2), new Tile(1));
|
||||
@@ -74,7 +71,11 @@ namespace Robust.UnitTesting.Shared.Map
|
||||
[Test]
|
||||
public void BoundsContract()
|
||||
{
|
||||
var grid = MapGridFactory(new GridId(1));
|
||||
var sim = SimulationFactory();
|
||||
var mapMan = sim.Resolve<IMapManager>();
|
||||
var mapId = mapMan.CreateMap();
|
||||
var grid = (IMapGridInternal)mapMan.CreateGrid(mapId, null, 8);
|
||||
grid.WorldPosition = new Vector2(3, 5);
|
||||
|
||||
grid.SetTile(new Vector2i(-1, -2), new Tile(1));
|
||||
grid.SetTile(new Vector2i(1, 2), new Tile(1));
|
||||
@@ -93,7 +94,10 @@ namespace Robust.UnitTesting.Shared.Map
|
||||
[Test]
|
||||
public void GridTileToChunkIndices()
|
||||
{
|
||||
var grid = MapGridFactory(new GridId(1));
|
||||
var sim = SimulationFactory();
|
||||
var mapMan = sim.Resolve<IMapManager>();
|
||||
var mapId = mapMan.CreateMap();
|
||||
var grid = (IMapGridInternal)mapMan.CreateGrid(mapId, null, 8);
|
||||
|
||||
var result = grid.GridTileToChunkIndices(new Vector2i(-9, -1));
|
||||
|
||||
@@ -106,7 +110,10 @@ namespace Robust.UnitTesting.Shared.Map
|
||||
[Test]
|
||||
public void ToLocalCentered()
|
||||
{
|
||||
var grid = MapGridFactory(new GridId(1));
|
||||
var sim = SimulationFactory();
|
||||
var mapMan = sim.Resolve<IMapManager>();
|
||||
var mapId = mapMan.CreateMap();
|
||||
var grid = (IMapGridInternal)mapMan.CreateGrid(mapId, null, 8);
|
||||
|
||||
var result = grid.GridTileToLocal(new Vector2i(0, 0)).Position;
|
||||
|
||||
@@ -117,7 +124,10 @@ namespace Robust.UnitTesting.Shared.Map
|
||||
[Test]
|
||||
public void TryGetTileRefNoTile()
|
||||
{
|
||||
var grid = MapGridFactory(new GridId(1));
|
||||
var sim = SimulationFactory();
|
||||
var mapMan = sim.Resolve<IMapManager>();
|
||||
var mapId = mapMan.CreateMap();
|
||||
var grid = (IMapGridInternal)mapMan.CreateGrid(mapId, null, 8);
|
||||
|
||||
var foundTile = grid.TryGetTileRef(new Vector2i(-9, -1), out var tileRef);
|
||||
|
||||
@@ -129,7 +139,11 @@ namespace Robust.UnitTesting.Shared.Map
|
||||
[Test]
|
||||
public void TryGetTileRefTileExists()
|
||||
{
|
||||
var grid = MapGridFactory(new GridId(1));
|
||||
var sim = SimulationFactory();
|
||||
var mapMan = sim.Resolve<IMapManager>();
|
||||
var mapId = mapMan.CreateMap();
|
||||
var grid = (IMapGridInternal)mapMan.CreateGrid(mapId, null, 8);
|
||||
|
||||
grid.SetTile(new Vector2i(-9, -1), new Tile(1, 2));
|
||||
|
||||
var foundTile = grid.TryGetTileRef(new Vector2i(-9, -1), out var tileRef);
|
||||
@@ -137,13 +151,17 @@ namespace Robust.UnitTesting.Shared.Map
|
||||
Assert.That(foundTile, Is.True);
|
||||
Assert.That(grid.ChunkCount, Is.EqualTo(1));
|
||||
Assert.That(grid.GetMapChunks().Keys.ToList()[0], Is.EqualTo(new Vector2i(-2, -1)));
|
||||
Assert.That(tileRef, Is.EqualTo(new TileRef(new MapId(5), new GridId(1), new Vector2i(-9, -1), new Tile(1, 2))));
|
||||
Assert.That(tileRef, Is.EqualTo(new TileRef(mapId, grid.Index, new Vector2i(-9, -1), new Tile(1, 2))));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PointCollidesWithGrid()
|
||||
{
|
||||
var grid = MapGridFactory(new GridId(1));
|
||||
var sim = SimulationFactory();
|
||||
var mapMan = sim.Resolve<IMapManager>();
|
||||
var mapId = mapMan.CreateMap();
|
||||
var grid = (IMapGridInternal)mapMan.CreateGrid(mapId, null, 8);
|
||||
|
||||
grid.SetTile(new Vector2i(19, 23), new Tile(1));
|
||||
|
||||
var result = grid.CollidesWithGrid(new Vector2i(19, 23));
|
||||
@@ -154,31 +172,16 @@ namespace Robust.UnitTesting.Shared.Map
|
||||
[Test]
|
||||
public void PointNotCollideWithGrid()
|
||||
{
|
||||
var grid = MapGridFactory(new GridId(1));
|
||||
var sim = SimulationFactory();
|
||||
var mapMan = sim.Resolve<IMapManager>();
|
||||
var mapId = mapMan.CreateMap();
|
||||
var grid = (IMapGridInternal)mapMan.CreateGrid(mapId, null, 8);
|
||||
|
||||
grid.SetTile(new Vector2i(19, 23), new Tile(1));
|
||||
|
||||
var result = grid.CollidesWithGrid(new Vector2i(19, 24));
|
||||
|
||||
Assert.That(result, Is.False);
|
||||
}
|
||||
|
||||
private static IMapGridInternal MapGridFactory(GridId id)
|
||||
{
|
||||
var mapId = new MapId(5);
|
||||
var mapMan = IoCManager.Resolve<IMapManager>();
|
||||
|
||||
if(mapMan.MapExists(mapId))
|
||||
mapMan.DeleteMap(mapId);
|
||||
|
||||
mapMan.CreateMap(mapId);
|
||||
|
||||
if(mapMan.GridExists(id))
|
||||
mapMan.DeleteGrid(id);
|
||||
|
||||
var newGrid = mapMan.CreateGrid(mapId, id, 8);
|
||||
newGrid.WorldPosition = new Vector2(3, 5);
|
||||
|
||||
return (IMapGridInternal)newGrid;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
272
Robust.UnitTesting/Shared/Map/MapPauseTests.cs
Normal file
272
Robust.UnitTesting/Shared/Map/MapPauseTests.cs
Normal file
@@ -0,0 +1,272 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.UnitTesting.Server;
|
||||
|
||||
// ReSharper disable AccessToStaticMemberViaDerivedType
|
||||
|
||||
namespace Robust.UnitTesting.Shared.Map;
|
||||
|
||||
[TestFixture]
|
||||
internal sealed class MapPauseTests
|
||||
{
|
||||
private static ISimulation SimulationFactory()
|
||||
{
|
||||
var sim = RobustServerSimulation
|
||||
.NewSimulation()
|
||||
.RegisterComponents(factory => factory.RegisterClass<IgnorePauseComponent>())
|
||||
.InitializeInstance();
|
||||
|
||||
return sim;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// When an entity is on a paused map, it does not get returned by an EntityQuery.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void Paused_NotIncluded_NotInQuery()
|
||||
{
|
||||
var sim = SimulationFactory();
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
var mapMan = sim.Resolve<IMapManager>();
|
||||
|
||||
// arrange
|
||||
var mapId = mapMan.CreateMap();
|
||||
mapMan.SetMapPaused(mapId, true);
|
||||
|
||||
entMan.SpawnEntity(null, new MapCoordinates(0, 0, mapId));
|
||||
|
||||
var query = entMan.EntityQuery<TransformComponent>(false).ToList();
|
||||
|
||||
// 0 ents, map and the spawned one are not returned
|
||||
Assert.That(query.Count, Is.EqualTo(0));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// When an entity is on an unpaused map, it is returned by an EntityQuery.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void UnPaused_NotIncluded_InQuery()
|
||||
{
|
||||
var sim = SimulationFactory();
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
var mapMan = sim.Resolve<IMapManager>();
|
||||
|
||||
// arrange
|
||||
var mapId = mapMan.CreateMap();
|
||||
mapMan.SetMapPaused(mapId, false);
|
||||
|
||||
var newEnt = entMan.SpawnEntity(null, new MapCoordinates(0, 0, mapId));
|
||||
|
||||
var query = entMan.EntityQuery<TransformComponent>(false).ToList();
|
||||
|
||||
// 2 ents, map and the spawned one
|
||||
Assert.That(query.Count, Is.EqualTo(2));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// When an entity is on a paused map, it is get returned by an EntityQuery when included.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void Paused_Included_InQuery()
|
||||
{
|
||||
var sim = SimulationFactory();
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
var mapMan = sim.Resolve<IMapManager>();
|
||||
|
||||
// arrange
|
||||
var mapId = mapMan.CreateMap();
|
||||
mapMan.SetMapPaused(mapId, true);
|
||||
|
||||
entMan.SpawnEntity(null, new MapCoordinates(0, 0, mapId));
|
||||
|
||||
var query = entMan.EntityQuery<TransformComponent>(true).ToList();
|
||||
|
||||
// 2 ents, map and the spawned one are returned because includePaused
|
||||
Assert.That(query.Count, Is.EqualTo(2));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A new child entity added to a paused map will be created paused.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void Paused_AddEntity_IsPaused()
|
||||
{
|
||||
var sim = SimulationFactory();
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
var mapMan = sim.Resolve<IMapManager>();
|
||||
|
||||
// arrange
|
||||
var mapId = mapMan.CreateMap();
|
||||
mapMan.SetMapPaused(mapId, true);
|
||||
|
||||
var newEnt = entMan.SpawnEntity(null, new MapCoordinates(0, 0, mapId));
|
||||
|
||||
var metaData = entMan.GetComponent<MetaDataComponent>(newEnt);
|
||||
Assert.That(metaData.EntityPaused, Is.True);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A new child entity added to an unpaused map will be created unpaused.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void UnPaused_AddEntity_IsNotPaused()
|
||||
{
|
||||
var sim = SimulationFactory();
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
var mapMan = sim.Resolve<IMapManager>();
|
||||
|
||||
// arrange
|
||||
var mapId = mapMan.CreateMap();
|
||||
mapMan.SetMapPaused(mapId, false);
|
||||
|
||||
var newEnt = entMan.SpawnEntity(null, new MapCoordinates(0, 0, mapId));
|
||||
|
||||
var metaData = entMan.GetComponent<MetaDataComponent>(newEnt);
|
||||
Assert.That(metaData.EntityPaused, Is.False);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// When a new grid is added to a paused map, the grid becomes paused.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void Paused_AddGrid_GridPaused()
|
||||
{
|
||||
var sim = SimulationFactory();
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
var mapMan = sim.Resolve<IMapManager>();
|
||||
|
||||
// arrange
|
||||
var mapId = mapMan.CreateMap();
|
||||
mapMan.SetMapPaused(mapId, true);
|
||||
|
||||
// act
|
||||
var newGrid = mapMan.CreateGrid(mapId);
|
||||
|
||||
// assert
|
||||
Assert.That(mapMan.IsMapPaused(mapId), Is.True);
|
||||
Assert.That(mapMan.IsGridPaused(newGrid.GridEntityId), Is.True);
|
||||
|
||||
var metaData = entMan.GetComponent<MetaDataComponent>(newGrid.GridEntityId);
|
||||
Assert.That(metaData.EntityPaused, Is.True);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// When a tree of entities are teleported from a paused map
|
||||
/// to an unpaused map, all of the entities in the tree are unpaused.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void Paused_TeleportBetweenMaps_Unpaused()
|
||||
{
|
||||
var sim = SimulationFactory();
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
var mapMan = sim.Resolve<IMapManager>();
|
||||
|
||||
// arrange
|
||||
var map1 = mapMan.CreateMap();
|
||||
mapMan.SetMapPaused(map1, true);
|
||||
|
||||
var newEnt = entMan.SpawnEntity(null, new MapCoordinates(0, 0, map1));
|
||||
var xform = entMan.GetComponent<TransformComponent>(newEnt);
|
||||
|
||||
var map2 = mapMan.CreateMap();
|
||||
mapMan.SetMapPaused(map2, false);
|
||||
|
||||
// Act
|
||||
xform.ParentUid = mapMan.GetMapEntityId(map2);
|
||||
|
||||
var metaData = entMan.GetComponent<MetaDataComponent>(newEnt);
|
||||
Assert.That(metaData.EntityPaused, Is.False);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// When a tree of entities are teleported from an unpaused map
|
||||
/// to a paused map, all of the entitites in the tree are paused.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void Unpaused_TeleportBetweenMaps_IsPaused()
|
||||
{
|
||||
var sim = SimulationFactory();
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
var mapMan = sim.Resolve<IMapManager>();
|
||||
|
||||
// arrange
|
||||
var map1 = mapMan.CreateMap();
|
||||
mapMan.SetMapPaused(map1, false);
|
||||
|
||||
var newEnt = entMan.SpawnEntity(null, new MapCoordinates(0, 0, map1));
|
||||
var xform = entMan.GetComponent<TransformComponent>(newEnt);
|
||||
|
||||
var map2 = mapMan.CreateMap();
|
||||
mapMan.SetMapPaused(map2, true);
|
||||
|
||||
// Act
|
||||
xform.ParentUid = mapMan.GetMapEntityId(map2);
|
||||
|
||||
var metaData = entMan.GetComponent<MetaDataComponent>(newEnt);
|
||||
Assert.That(metaData.EntityPaused, Is.True);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// When a paused map is unpaused, all of the entities on the map are unpaused.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void Paused_UnpauseMap_UnpausedEntities()
|
||||
{
|
||||
var sim = SimulationFactory();
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
var mapMan = sim.Resolve<IMapManager>();
|
||||
|
||||
var mapId = mapMan.CreateMap();
|
||||
mapMan.SetMapPaused(mapId, true);
|
||||
var newEnt = entMan.SpawnEntity(null, new MapCoordinates(0, 0, mapId));
|
||||
|
||||
mapMan.SetMapPaused(mapId, false);
|
||||
|
||||
var metaData = entMan.GetComponent<MetaDataComponent>(newEnt);
|
||||
Assert.That(metaData.EntityPaused, Is.False);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// When an unpaused map is paused, all of the entities on the map are paused.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void Unpaused_PauseMap_PausedEntities()
|
||||
{
|
||||
var sim = SimulationFactory();
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
var mapMan = sim.Resolve<IMapManager>();
|
||||
|
||||
var mapId = mapMan.CreateMap();
|
||||
mapMan.SetMapPaused(mapId, false);
|
||||
var newEnt = entMan.SpawnEntity(null, new MapCoordinates(0, 0, mapId));
|
||||
|
||||
mapMan.SetMapPaused(mapId, true);
|
||||
|
||||
var metaData = entMan.GetComponent<MetaDataComponent>(newEnt);
|
||||
Assert.That(metaData.EntityPaused, Is.True);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// An entity that has set IgnorePause will not be paused when the map is paused.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void IgnorePause_PauseMap_NotPaused()
|
||||
{
|
||||
var sim = SimulationFactory();
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
var mapMan = sim.Resolve<IMapManager>();
|
||||
|
||||
var mapId = mapMan.CreateMap();
|
||||
mapMan.SetMapPaused(mapId, false);
|
||||
var newEnt = entMan.SpawnEntity(null, new MapCoordinates(0, 0, mapId));
|
||||
|
||||
entMan.AddComponent<IgnorePauseComponent>(newEnt);
|
||||
mapMan.SetMapPaused(mapId, true);
|
||||
|
||||
var metaData = entMan.GetComponent<MetaDataComponent>(newEnt);
|
||||
Assert.That(metaData.EntityPaused, Is.False);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
@@ -48,7 +47,7 @@ namespace Robust.UnitTesting.Shared.Prototypes
|
||||
IoCManager.Resolve<ISerializationManager>().Initialize();
|
||||
_prototypes = (PrototypeManager) IoCManager.Resolve<IPrototypeManager>();
|
||||
_prototypes.RegisterType(typeof(EntityPrototype));
|
||||
_prototypes.LoadFromString(InitialPrototypes);
|
||||
_prototypes.LoadString(InitialPrototypes);
|
||||
_prototypes.Resync();
|
||||
|
||||
_maps = IoCManager.Resolve<IMapManager>();
|
||||
@@ -76,8 +75,8 @@ namespace Robust.UnitTesting.Shared.Prototypes
|
||||
Assert.That(entityComponent.Value, Is.EqualTo(5));
|
||||
Assert.False(IoCManager.Resolve<IEntityManager>().HasComponent<HotReloadTestTwoComponent>(entity));
|
||||
|
||||
var changedPrototypes = _prototypes.LoadFromString(ReloadedPrototypes, true);
|
||||
_prototypes.ReloadPrototypes(changedPrototypes.ToList());
|
||||
var changedPrototypes = _prototypes.LoadString(ReloadedPrototypes, true);
|
||||
_prototypes.ReloadPrototypes(changedPrototypes);
|
||||
|
||||
Assert.True(reloaded);
|
||||
reloaded = false;
|
||||
@@ -88,8 +87,8 @@ namespace Robust.UnitTesting.Shared.Prototypes
|
||||
// New components are added
|
||||
Assert.True(IoCManager.Resolve<IEntityManager>().HasComponent<HotReloadTestTwoComponent>(entity));
|
||||
|
||||
changedPrototypes = _prototypes.LoadFromString(InitialPrototypes, true);
|
||||
_prototypes.ReloadPrototypes(changedPrototypes.ToList());
|
||||
changedPrototypes = _prototypes.LoadString(InitialPrototypes, true);
|
||||
_prototypes.ReloadPrototypes(changedPrototypes);
|
||||
|
||||
Assert.True(reloaded);
|
||||
reloaded = false;
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace Robust.UnitTesting.Shared.Prototypes
|
||||
IoCManager.Resolve<ISerializationManager>().Initialize();
|
||||
manager = IoCManager.Resolve<IPrototypeManager>();
|
||||
manager.RegisterType(typeof(EntityPrototype));
|
||||
manager.LoadFromString(DOCUMENT);
|
||||
manager.LoadString(DOCUMENT);
|
||||
manager.Resync();
|
||||
}
|
||||
|
||||
@@ -106,7 +106,7 @@ namespace Robust.UnitTesting.Shared.Prototypes
|
||||
[Test]
|
||||
public void TestLoadString()
|
||||
{
|
||||
manager.LoadFromString(LoadStringDocument);
|
||||
manager.LoadString(LoadStringDocument);
|
||||
manager.Resync();
|
||||
|
||||
var prototype = manager.Index<EntityPrototype>(LoadStringTestDummyId);
|
||||
|
||||
@@ -59,7 +59,7 @@ namespace Robust.UnitTesting.Shared.Serialization
|
||||
var prototypeManager = IoCManager.Resolve<IPrototypeManager>();
|
||||
|
||||
prototypeManager.RegisterType(typeof(EntityPrototype));
|
||||
prototypeManager.LoadFromString(Prototypes);
|
||||
prototypeManager.LoadString(Prototypes);
|
||||
prototypeManager.Resync();
|
||||
|
||||
var entityManager = IoCManager.Resolve<IEntityManager>();
|
||||
|
||||
@@ -46,7 +46,7 @@ entitiesImmutableList:
|
||||
var protoMan = IoCManager.Resolve<IPrototypeManager>();
|
||||
|
||||
protoMan.RegisterType(typeof(EntityPrototype));
|
||||
protoMan.LoadFromString(Prototypes);
|
||||
protoMan.LoadString(Prototypes);
|
||||
protoMan.Resync();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user