mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-15 11:40:52 +01:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6cd442d209 | ||
|
|
62167dfc94 | ||
|
|
472903a0af | ||
|
|
b5fa1c84fc |
@@ -1,4 +1,4 @@
|
||||
<Project>
|
||||
|
||||
<!-- This file automatically reset by Tools/version.py -->
|
||||
<!-- This file automatically reset by Tools/version.py -->
|
||||
|
||||
|
||||
@@ -54,72 +54,10 @@ END TEMPLATE-->
|
||||
*None yet*
|
||||
|
||||
|
||||
## 219.2.3
|
||||
## 218.2.2
|
||||
|
||||
|
||||
## 219.2.2
|
||||
|
||||
|
||||
## 219.2.1
|
||||
|
||||
|
||||
## 219.2.0
|
||||
|
||||
### New features
|
||||
|
||||
* Add SetMapCoordinates to TransformSystem.
|
||||
* Improve YAML Linter and validation of static fields.
|
||||
|
||||
### Bugfixes
|
||||
|
||||
* Fix DebugCoordsPanel freezing when hovering a control.
|
||||
|
||||
### Other
|
||||
|
||||
* Optimise physics networking to not dirty every tick of movement.
|
||||
|
||||
|
||||
## 219.1.3
|
||||
|
||||
### Bugfixes
|
||||
|
||||
* Fix map-loader not pausing pre-init maps when not actively overwriting an existing map.
|
||||
|
||||
|
||||
## 219.1.2
|
||||
|
||||
### Bugfixes
|
||||
|
||||
* Fix map-loader not map-initialising grids when loading into a post-init map.
|
||||
|
||||
|
||||
## 219.1.1
|
||||
|
||||
### Bugfixes
|
||||
|
||||
* Fix map-loader not map-initialising maps when overwriting a post-init map.
|
||||
|
||||
|
||||
## 219.1.0
|
||||
|
||||
### New features
|
||||
|
||||
* Added a new optional arguments to various entity spawning methods, including a new argument to set the entity's rotation.
|
||||
|
||||
### Bugfixes
|
||||
|
||||
* Fixes map initialisation not always initialising all entities on a map.
|
||||
|
||||
### Other
|
||||
|
||||
* The default value of the `auth.mode` cvar has changed
|
||||
|
||||
|
||||
## 219.0.0
|
||||
|
||||
### Breaking changes
|
||||
|
||||
* Move most IMapManager functionality to SharedMapSystem.
|
||||
## 218.2.1
|
||||
|
||||
|
||||
## 218.2.0
|
||||
|
||||
@@ -26,8 +26,9 @@ public partial class AddRemoveComponentBenchmark
|
||||
.InitializeInstance();
|
||||
|
||||
_entityManager = _simulation.Resolve<IEntityManager>();
|
||||
var map = _simulation.CreateMap().Uid;
|
||||
var coords = new EntityCoordinates(map, default);
|
||||
|
||||
var coords = new MapCoordinates(0, 0, new MapId(1));
|
||||
_simulation.AddMap(coords.MapId);
|
||||
|
||||
for (var i = 0; i < N; i++)
|
||||
{
|
||||
|
||||
@@ -29,8 +29,8 @@ public partial class ComponentIteratorBenchmark
|
||||
|
||||
Comps = new A[N+2];
|
||||
|
||||
var map = _simulation.CreateMap().MapId;
|
||||
var coords = new MapCoordinates(default, map);
|
||||
var coords = new MapCoordinates(0, 0, new MapId(1));
|
||||
_simulation.AddMap(coords.MapId);
|
||||
|
||||
for (var i = 0; i < N; i++)
|
||||
{
|
||||
|
||||
@@ -31,8 +31,8 @@ public partial class GetComponentBenchmark
|
||||
|
||||
Comps = new A[N+2];
|
||||
|
||||
var map = _simulation.CreateMap().Uid;
|
||||
var coords = new EntityCoordinates(map, default);
|
||||
var coords = new MapCoordinates(0, 0, new MapId(1));
|
||||
_simulation.AddMap(coords.MapId);
|
||||
|
||||
for (var i = 0; i < N; i++)
|
||||
{
|
||||
|
||||
@@ -29,9 +29,10 @@ public partial class SpawnDeleteEntityBenchmark
|
||||
.InitializeInstance();
|
||||
|
||||
_entityManager = _simulation.Resolve<IEntityManager>();
|
||||
var (map, mapId) = _simulation.CreateMap();
|
||||
_mapCoords = new MapCoordinates(default, mapId);
|
||||
_entCoords = new EntityCoordinates(map, 0, 0);
|
||||
|
||||
_mapCoords = new MapCoordinates(0, 0, new MapId(1));
|
||||
var uid = _simulation.AddMap(_mapCoords.MapId);
|
||||
_entCoords = new EntityCoordinates(uid, 0, 0);
|
||||
}
|
||||
|
||||
[Benchmark(Baseline = true)]
|
||||
|
||||
@@ -91,7 +91,8 @@ public class RecursiveMoveBenchmark : RobustIntegrationTest
|
||||
// Set up map and spawn player
|
||||
server.WaitPost(() =>
|
||||
{
|
||||
var map = server.ResolveDependency<SharedMapSystem>().CreateMap(out var mapId);
|
||||
var mapId = mapMan.CreateMap();
|
||||
var map = mapMan.GetMapEntityId(mapId);
|
||||
var gridComp = mapMan.CreateGridEntity(mapId);
|
||||
var grid = gridComp.Owner;
|
||||
mapSys.SetTile(grid, gridComp, Vector2i.Zero, new Tile(1));
|
||||
|
||||
@@ -74,13 +74,11 @@ public sealed class AudioOverlay : Overlay
|
||||
output.Clear();
|
||||
output.AppendLine("Audio Source");
|
||||
output.AppendLine("Runtime:");
|
||||
output.AppendLine($"- Distance: {_audio.GetAudioDistance(distance.Length()):0.00}");
|
||||
output.AppendLine($"- Occlusion: {posOcclusion:0.0000}");
|
||||
output.AppendLine("Params:");
|
||||
output.AppendLine($"- RolloffFactor: {comp.RolloffFactor:0.0000}");
|
||||
output.AppendLine($"- Volume: {comp.Volume:0.0000}");
|
||||
output.AppendLine($"- Reference distance: {comp.ReferenceDistance:0.00}");
|
||||
output.AppendLine($"- Max distance: {comp.MaxDistance:0.00}");
|
||||
output.AppendLine($"- Reference distance: {comp.ReferenceDistance}");
|
||||
output.AppendLine($"- Max distance: {comp.MaxDistance}");
|
||||
var outputText = output.ToString().Trim();
|
||||
var dimensions = screenHandle.GetDimensions(_font, outputText, 1f);
|
||||
var buffer = new Vector2(3f, 3f);
|
||||
|
||||
@@ -388,7 +388,7 @@ public sealed partial class AudioSystem : SharedAudioSystem
|
||||
var distance = delta.Length();
|
||||
|
||||
// Out of range so just clip it for us.
|
||||
if (GetAudioDistance(distance) > component.MaxDistance)
|
||||
if (distance > component.MaxDistance)
|
||||
{
|
||||
// Still keeps the source playing, just with no volume.
|
||||
component.Gain = 0f;
|
||||
|
||||
@@ -285,7 +285,6 @@ namespace Robust.Client
|
||||
/// <summary>
|
||||
/// Enumeration of the run levels of the BaseClient.
|
||||
/// </summary>
|
||||
/// <seealso cref="ClientRunLevelExt"/>
|
||||
public enum ClientRunLevel : byte
|
||||
{
|
||||
Error = 0,
|
||||
@@ -316,21 +315,6 @@ namespace Robust.Client
|
||||
SinglePlayerGame,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Helper functions for working with <see cref="ClientRunLevel"/>.
|
||||
/// </summary>
|
||||
public static class ClientRunLevelExt
|
||||
{
|
||||
/// <summary>
|
||||
/// Check if a <see cref="ClientRunLevel"/> is <see cref="ClientRunLevel.InGame"/>
|
||||
/// or <see cref="ClientRunLevel.SinglePlayerGame"/>.
|
||||
/// </summary>
|
||||
public static bool IsInGameLike(this ClientRunLevel runLevel)
|
||||
{
|
||||
return runLevel is ClientRunLevel.InGame or ClientRunLevel.SinglePlayerGame;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Event arguments for when something changed with the player.
|
||||
/// </summary>
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.Map;
|
||||
using Robust.Client.Physics;
|
||||
using Robust.Client.ResourceManagement;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Map.Components;
|
||||
using Robust.Shared.Physics.Dynamics;
|
||||
|
||||
namespace Robust.Client.GameObjects;
|
||||
|
||||
@@ -13,17 +16,6 @@ public sealed class MapSystem : SharedMapSystem
|
||||
[Dependency] private readonly IResourceCache _resource = default!;
|
||||
[Dependency] private readonly ITileDefinitionManager _tileDefinitionManager = default!;
|
||||
|
||||
protected override MapId GetNextMapId()
|
||||
{
|
||||
// Client-side map entities use negative map Ids to avoid conflict with server-side maps.
|
||||
var id = new MapId(--LastMapId);
|
||||
while (MapManager.MapExists(id))
|
||||
{
|
||||
id = new MapId(--LastMapId);
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
@@ -35,4 +27,9 @@ public sealed class MapSystem : SharedMapSystem
|
||||
base.Shutdown();
|
||||
_overlayManager.RemoveOverlay<TileEdgeOverlay>();
|
||||
}
|
||||
|
||||
protected override void OnMapAdd(EntityUid uid, MapComponent component, ComponentAdd args)
|
||||
{
|
||||
EnsureComp<PhysicsMapComponent>(uid);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1329,8 +1329,23 @@ namespace Robust.Client.GameStates
|
||||
|
||||
foreach (var (comp, cur, next) in _compStateWork.Values)
|
||||
{
|
||||
var handleState = new ComponentHandleState(cur, next);
|
||||
bus.RaiseComponentEvent(comp, ref handleState);
|
||||
try
|
||||
{
|
||||
var handleState = new ComponentHandleState(cur, next);
|
||||
bus.RaiseComponentEvent(comp, ref handleState);
|
||||
}
|
||||
#pragma warning disable CS0168 // Variable is declared but never used
|
||||
catch (Exception e)
|
||||
#pragma warning restore CS0168 // Variable is declared but never used
|
||||
{
|
||||
#if EXCEPTION_TOLERANCE
|
||||
_sawmill.Error($"Failed to apply comp state: entity={_entities.ToPrettyString(uid)}, comp={comp.GetType()}");
|
||||
_runtimeLog.LogException(e, $"{nameof(ClientGameStateManager)}.{nameof(HandleEntityState)}");
|
||||
#else
|
||||
_sawmill.Error($"Failed to apply comp state: entity={_entities.ToPrettyString(uid)}, comp={comp.GetType()}");
|
||||
throw;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -124,7 +124,7 @@ namespace Robust.Client.Graphics.Clyde
|
||||
{
|
||||
foreach (var (grid, chunks) in _mapChunkData)
|
||||
{
|
||||
var gridComp = _entityManager.GetComponent<MapGridComponent>(grid);
|
||||
var gridComp = _mapManager.GetGridComp(grid);
|
||||
foreach (var (index, chunk) in chunks)
|
||||
{
|
||||
if (!chunk.Dirty || gridComp.Chunks.ContainsKey(index))
|
||||
|
||||
@@ -251,8 +251,10 @@ namespace Robust.Client.Graphics.Clyde
|
||||
private void DrawEntities(Viewport viewport, Box2Rotated worldBounds, Box2 worldAABB, IEye eye)
|
||||
{
|
||||
var mapId = eye.Position.MapId;
|
||||
if (mapId == MapId.Nullspace)
|
||||
if (mapId == MapId.Nullspace || !_mapManager.HasMapEntity(mapId))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
RenderOverlays(viewport, OverlaySpace.WorldSpaceBelowEntities, worldAABB, worldBounds);
|
||||
var worldOverlays = GetOverlaysForSpace(OverlaySpace.WorldSpaceEntities);
|
||||
|
||||
@@ -17,7 +17,7 @@ using Vector4 = Robust.Shared.Maths.Vector4;
|
||||
namespace Robust.Client.Graphics
|
||||
{
|
||||
[Prototype("shader")]
|
||||
public sealed partial class ShaderPrototype : IPrototype, ISerializationHooks
|
||||
public sealed class ShaderPrototype : IPrototype, ISerializationHooks
|
||||
{
|
||||
[ViewVariables]
|
||||
[IdDataField]
|
||||
|
||||
@@ -5,6 +5,7 @@ using Robust.Shared.Timing;
|
||||
|
||||
namespace Robust.Client.UserInterface.Controllers;
|
||||
|
||||
// Notices your UIController, *UwU Whats this?*
|
||||
/// <summary>
|
||||
/// Each <see cref="UIController"/> is instantiated as a singleton by <see cref="UserInterfaceManager"/>
|
||||
/// <see cref="UIController"/> can use <see cref="DependencyAttribute"/> for regular IoC dependencies
|
||||
|
||||
@@ -20,7 +20,6 @@ namespace Robust.Client.UserInterface.CustomControls.DebugMonitorControls
|
||||
[Dependency] private readonly IEntityManager _entityManager = default!;
|
||||
[Dependency] private readonly IClyde _displayManager = default!;
|
||||
[Dependency] private readonly IMapManager _mapManager = default!;
|
||||
[Dependency] private readonly IBaseClient _baseClient = default!;
|
||||
|
||||
private readonly StringBuilder _textBuilder = new();
|
||||
private readonly char[] _textBuffer = new char[1024];
|
||||
@@ -59,36 +58,30 @@ namespace Robust.Client.UserInterface.CustomControls.DebugMonitorControls
|
||||
|
||||
_textBuilder.Clear();
|
||||
|
||||
var isInGame = _baseClient.RunLevel.IsInGameLike();
|
||||
var mouseScreenPos = _inputManager.MouseScreenPosition;
|
||||
var screenSize = _displayManager.ScreenSize;
|
||||
var screenScale = _displayManager.MainWindow.ContentScale;
|
||||
|
||||
EntityCoordinates mouseGridPos = default;
|
||||
TileRef tile = default;
|
||||
MapCoordinates mouseWorldMap = default;
|
||||
EntityCoordinates mouseGridPos;
|
||||
TileRef tile;
|
||||
|
||||
if (isInGame)
|
||||
var mouseWorldMap = _eyeManager.PixelToMap(mouseScreenPos);
|
||||
if (mouseWorldMap == MapCoordinates.Nullspace)
|
||||
return;
|
||||
|
||||
var mapSystem = _entityManager.System<SharedMapSystem>();
|
||||
var xformSystem = _entityManager.System<SharedTransformSystem>();
|
||||
|
||||
if (_mapManager.TryFindGridAt(mouseWorldMap, out var mouseGridUid, out var mouseGrid))
|
||||
{
|
||||
mouseWorldMap = _eyeManager.PixelToMap(mouseScreenPos);
|
||||
if (mouseWorldMap != MapCoordinates.Nullspace)
|
||||
{
|
||||
var mapSystem = _entityManager.System<SharedMapSystem>();
|
||||
var xformSystem = _entityManager.System<SharedTransformSystem>();
|
||||
|
||||
if (_mapManager.TryFindGridAt(mouseWorldMap, out var mouseGridUid, out var mouseGrid))
|
||||
{
|
||||
mouseGridPos = mapSystem.MapToGrid(mouseGridUid, mouseWorldMap);
|
||||
tile = mapSystem.GetTileRef(mouseGridUid, mouseGrid, mouseGridPos);
|
||||
}
|
||||
else
|
||||
{
|
||||
mouseGridPos = new EntityCoordinates(_mapManager.GetMapEntityId(mouseWorldMap.MapId),
|
||||
mouseWorldMap.Position);
|
||||
tile = new TileRef(EntityUid.Invalid,
|
||||
mouseGridPos.ToVector2i(_entityManager, _mapManager, xformSystem), Tile.Empty);
|
||||
}
|
||||
}
|
||||
mouseGridPos = mapSystem.MapToGrid(mouseGridUid, mouseWorldMap);
|
||||
tile = mapSystem.GetTileRef(mouseGridUid, mouseGrid, mouseGridPos);
|
||||
}
|
||||
else
|
||||
{
|
||||
mouseGridPos = new EntityCoordinates(_mapManager.GetMapEntityId(mouseWorldMap.MapId),
|
||||
mouseWorldMap.Position);
|
||||
tile = new TileRef(EntityUid.Invalid, mouseGridPos.ToVector2i(_entityManager, _mapManager, xformSystem), Tile.Empty);
|
||||
}
|
||||
|
||||
var controlHovered = UserInterfaceManager.CurrentlyHovered;
|
||||
@@ -102,37 +95,32 @@ Mouse Pos:
|
||||
{tile}
|
||||
GUI: {controlHovered}");
|
||||
|
||||
if (isInGame)
|
||||
_textBuilder.AppendLine("\nAttached NetEntity:");
|
||||
var controlledEntity = _playerManager.LocalSession?.AttachedEntity ?? EntityUid.Invalid;
|
||||
|
||||
if (controlledEntity == EntityUid.Invalid)
|
||||
{
|
||||
var xformSystem = _entityManager.System<SharedTransformSystem>();
|
||||
_textBuilder.AppendLine("No attached netentity.");
|
||||
}
|
||||
else
|
||||
{
|
||||
var entityTransform = _entityManager.GetComponent<TransformComponent>(controlledEntity);
|
||||
var playerWorldOffset = xformSystem.GetMapCoordinates(entityTransform);
|
||||
var playerScreen = _eyeManager.WorldToScreen(playerWorldOffset.Position);
|
||||
|
||||
_textBuilder.AppendLine("\nAttached NetEntity:");
|
||||
var controlledEntity = _playerManager.LocalSession?.AttachedEntity ?? EntityUid.Invalid;
|
||||
var playerCoordinates = entityTransform.Coordinates;
|
||||
var playerRotation = xformSystem.GetWorldRotation(entityTransform);
|
||||
var gridRotation = entityTransform.GridUid != null
|
||||
? xformSystem.GetWorldRotation(entityTransform.GridUid.Value)
|
||||
: Angle.Zero;
|
||||
|
||||
if (controlledEntity == EntityUid.Invalid)
|
||||
{
|
||||
_textBuilder.AppendLine("No attached netentity.");
|
||||
}
|
||||
else
|
||||
{
|
||||
var entityTransform = _entityManager.GetComponent<TransformComponent>(controlledEntity);
|
||||
var playerWorldOffset = xformSystem.GetMapCoordinates(entityTransform);
|
||||
var playerScreen = _eyeManager.WorldToScreen(playerWorldOffset.Position);
|
||||
|
||||
var playerCoordinates = entityTransform.Coordinates;
|
||||
var playerRotation = xformSystem.GetWorldRotation(entityTransform);
|
||||
var gridRotation = entityTransform.GridUid != null
|
||||
? xformSystem.GetWorldRotation(entityTransform.GridUid.Value)
|
||||
: Angle.Zero;
|
||||
|
||||
_textBuilder.Append($@" Screen: {playerScreen}
|
||||
_textBuilder.Append($@" Screen: {playerScreen}
|
||||
{playerWorldOffset}
|
||||
{_entityManager.GetNetCoordinates(playerCoordinates)}
|
||||
Rotation: {playerRotation.Degrees:F2}°
|
||||
NEntId: {_entityManager.GetNetEntity(controlledEntity)}
|
||||
Grid NEntId: {_entityManager.GetNetEntity(entityTransform.GridUid)}
|
||||
Grid Rotation: {gridRotation.Degrees:F2}°");
|
||||
}
|
||||
}
|
||||
|
||||
_contents.TextMemory = FormatHelpers.BuilderToMemory(_textBuilder, _textBuffer);
|
||||
|
||||
@@ -5,7 +5,7 @@ using Robust.Shared.Utility;
|
||||
namespace Robust.Client.UserInterface.RichText;
|
||||
|
||||
[Prototype("font")]
|
||||
public sealed partial class FontPrototype : IPrototype
|
||||
public sealed class FontPrototype : IPrototype
|
||||
{
|
||||
[IdDataField]
|
||||
public string ID { get; private set; } = default!;
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Frozen;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.ResourceManagement;
|
||||
using Robust.Shared.ContentPack;
|
||||
using Robust.Shared.Graphics;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Maths;
|
||||
@@ -16,7 +18,7 @@ using Robust.Shared.ViewVariables;
|
||||
namespace Robust.Client.UserInterface.Themes;
|
||||
|
||||
[Prototype("uiTheme")]
|
||||
public sealed partial class UITheme : IPrototype
|
||||
public sealed class UITheme : IPrototype
|
||||
{
|
||||
private IResourceCache? _cache;
|
||||
private IUserInterfaceManager? _uiMan;
|
||||
|
||||
@@ -70,11 +70,6 @@ namespace Robust.Server.Console.Commands
|
||||
}
|
||||
|
||||
var mapId = new MapId(mapInt);
|
||||
if (!_map.MapExists(mapId))
|
||||
{
|
||||
shell.WriteError($"map {args[0]} does not exist");
|
||||
return;
|
||||
}
|
||||
|
||||
if (shell.Player == null)
|
||||
{
|
||||
@@ -115,6 +110,13 @@ namespace Robust.Server.Console.Commands
|
||||
|
||||
private void SetupPlayer(MapId mapId, IConsoleShell shell)
|
||||
{
|
||||
if (mapId == MapId.Nullspace) return;
|
||||
|
||||
if (!_map.MapExists(mapId))
|
||||
{
|
||||
_map.CreateMap(mapId);
|
||||
}
|
||||
|
||||
_map.SetMapPaused(mapId, false);
|
||||
var mapUid = _map.GetMapEntityIdOrThrow(mapId);
|
||||
_ent.System<Gravity2DController>().SetGravity(mapUid, new Vector2(0, -9.8f));
|
||||
|
||||
@@ -49,6 +49,7 @@ public sealed class MapLoaderSystem : EntitySystem
|
||||
private ISawmill _logLoader = default!;
|
||||
private ISawmill _logWriter = default!;
|
||||
|
||||
private static readonly MapLoadOptions DefaultLoadOptions = new();
|
||||
private const int MapFormatVersion = 6;
|
||||
private const int BackwardsVersion = 2;
|
||||
|
||||
@@ -131,7 +132,7 @@ public sealed class MapLoaderSystem : EntitySystem
|
||||
public bool TryLoad(MapId mapId, string path, [NotNullWhen(true)] out IReadOnlyList<EntityUid>? rootUids,
|
||||
MapLoadOptions? options = null)
|
||||
{
|
||||
options ??= new();
|
||||
options ??= DefaultLoadOptions;
|
||||
|
||||
var resPath = new ResPath(path).ToRootedPath();
|
||||
|
||||
@@ -657,13 +658,11 @@ public sealed class MapLoaderSystem : EntitySystem
|
||||
var xformQuery = GetEntityQuery<TransformComponent>();
|
||||
// We just need to cache the old mapuid and point to the new mapuid.
|
||||
|
||||
if (TryComp(rootNode, out MapComponent? mapComp))
|
||||
if (HasComp<MapComponent>(rootNode))
|
||||
{
|
||||
// If map exists swap out
|
||||
if (_mapSystem.TryGetMap(data.TargetMap, out var existing))
|
||||
if (_mapManager.MapExists(data.TargetMap))
|
||||
{
|
||||
data.Options.DoMapInit |= _mapSystem.IsInitialized(data.TargetMap);
|
||||
data.MapIsPaused = _mapSystem.IsPaused(existing.Value);
|
||||
// Map exists but we also have a map file with stuff on it soooo swap out the old map.
|
||||
if (data.Options.LoadMap)
|
||||
{
|
||||
@@ -676,28 +675,26 @@ public sealed class MapLoaderSystem : EntitySystem
|
||||
data.Options.Rotation = Angle.Zero;
|
||||
}
|
||||
|
||||
Del(existing);
|
||||
_mapManager.SetMapEntity(data.TargetMap, rootNode);
|
||||
EnsureComp<LoadedMapComponent>(rootNode);
|
||||
|
||||
mapComp.MapId = data.TargetMap;
|
||||
DebugTools.Assert(mapComp.LifeStage < ComponentLifeStage.Initializing);
|
||||
}
|
||||
// Otherwise just ignore the map in the file.
|
||||
else
|
||||
{
|
||||
var oldRootUid = data.Entities[0];
|
||||
data.Entities[0] = existing.Value;
|
||||
var newRootUid = _mapManager.GetMapEntityId(data.TargetMap);
|
||||
data.Entities[0] = newRootUid;
|
||||
|
||||
foreach (var ent in data.Entities)
|
||||
{
|
||||
if (ent == existing)
|
||||
if (ent == newRootUid)
|
||||
continue;
|
||||
|
||||
var xform = xformQuery.GetComponent(ent);
|
||||
|
||||
if (!xform.ParentUid.IsValid() || xform.ParentUid.Equals(oldRootUid))
|
||||
{
|
||||
_transform.SetParent(ent, xform, existing.Value);
|
||||
_transform.SetParent(ent, xform, newRootUid);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -706,9 +703,16 @@ public sealed class MapLoaderSystem : EntitySystem
|
||||
}
|
||||
else
|
||||
{
|
||||
data.MapIsPaused = !data.MapIsPostInit;
|
||||
mapComp.MapId = data.TargetMap;
|
||||
DebugTools.Assert(mapComp.LifeStage < ComponentLifeStage.Initializing);
|
||||
// If we're loading a file with a map then swap out the entityuid
|
||||
// TODO: Mapmanager nonsense
|
||||
var AAAAA = _mapManager.CreateMap(data.TargetMap);
|
||||
|
||||
if (!data.MapIsPostInit)
|
||||
{
|
||||
_mapManager.AddUninitializedMap(data.TargetMap);
|
||||
}
|
||||
|
||||
_mapManager.SetMapEntity(data.TargetMap, rootNode);
|
||||
EnsureComp<LoadedMapComponent>(rootNode);
|
||||
|
||||
// Nothing should have invalid uid except for the root node.
|
||||
@@ -717,15 +721,17 @@ public sealed class MapLoaderSystem : EntitySystem
|
||||
else
|
||||
{
|
||||
// No map file root, in that case create a new map / get the one we're loading onto.
|
||||
if (!_mapSystem.TryGetMap(data.TargetMap, out var mapNode))
|
||||
var mapNode = _mapManager.GetMapEntityId(data.TargetMap);
|
||||
|
||||
if (!mapNode.IsValid())
|
||||
{
|
||||
// Map doesn't exist so we'll start it up now so we can re-attach the preinit entities to it for later.
|
||||
mapNode = _mapSystem.CreateMap(data.TargetMap, false);
|
||||
_mapManager.CreateMap(data.TargetMap);
|
||||
_mapManager.AddUninitializedMap(data.TargetMap);
|
||||
mapNode = _mapManager.GetMapEntityId(data.TargetMap);
|
||||
DebugTools.Assert(mapNode.IsValid());
|
||||
}
|
||||
|
||||
data.Options.DoMapInit |= _mapSystem.IsInitialized(data.TargetMap);
|
||||
data.MapIsPaused = _mapSystem.IsPaused(mapNode.Value);
|
||||
|
||||
// If anything has an invalid parent (e.g. it's some form of root node) then parent it to the map.
|
||||
foreach (var ent in data.Entities)
|
||||
{
|
||||
@@ -737,11 +743,12 @@ public sealed class MapLoaderSystem : EntitySystem
|
||||
|
||||
if (!xform.ParentUid.IsValid())
|
||||
{
|
||||
_transform.SetParent(ent, xform, mapNode.Value);
|
||||
_transform.SetParent(ent, xform, mapNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
data.MapIsPaused = _mapManager.IsMapPaused(data.TargetMap);
|
||||
_logLoader.Debug($"Swapped out root node in {_stopwatch.Elapsed}");
|
||||
}
|
||||
|
||||
@@ -889,7 +896,7 @@ public sealed class MapLoaderSystem : EntitySystem
|
||||
{
|
||||
EntityManager.SetLifeStage(metadata, EntityLifeStage.MapInitialized);
|
||||
}
|
||||
else if (data.Options.DoMapInit)
|
||||
else if (_mapManager.IsMapInitialized(data.TargetMap))
|
||||
{
|
||||
_serverEntityManager.RunMapInit(uid, metadata);
|
||||
}
|
||||
@@ -957,7 +964,7 @@ public sealed class MapLoaderSystem : EntitySystem
|
||||
// Yes, post-init maps do not have EntityLifeStage >= EntityLifeStage.MapInitialized
|
||||
bool postInit;
|
||||
if (TryComp(uid, out MapComponent? mapComp))
|
||||
postInit = mapComp.MapInitialized;
|
||||
postInit = !mapComp.MapPreInit;
|
||||
else
|
||||
postInit = metadata.EntityLifeStage >= EntityLifeStage.MapInitialized;
|
||||
|
||||
@@ -1091,17 +1098,17 @@ public sealed class MapLoaderSystem : EntitySystem
|
||||
}
|
||||
}
|
||||
|
||||
private bool IsSaveable(EntityUid uid)
|
||||
private bool IsSaveable(EntityUid uid, EntityQuery<MetaDataComponent> metaQuery, EntityQuery<TransformComponent> transformQuery)
|
||||
{
|
||||
// Don't serialize things parented to un savable things.
|
||||
// For example clothes inside a person.
|
||||
while (uid.IsValid())
|
||||
{
|
||||
var meta = MetaData(uid);
|
||||
var meta = metaQuery.GetComponent(uid);
|
||||
|
||||
if (meta.EntityDeleted || meta.EntityPrototype?.MapSavable == false) break;
|
||||
|
||||
uid = Transform(uid).ParentUid;
|
||||
uid = transformQuery.GetComponent(uid).ParentUid;
|
||||
}
|
||||
|
||||
// If we manage to get up to the map (root node) then it's saveable.
|
||||
@@ -1116,7 +1123,7 @@ public sealed class MapLoaderSystem : EntitySystem
|
||||
EntityQuery<TransformComponent> transformQuery,
|
||||
EntityQuery<MapSaveIdComponent> saveCompQuery)
|
||||
{
|
||||
if (!IsSaveable(uid))
|
||||
if (!IsSaveable(uid, metaQuery, transformQuery))
|
||||
return;
|
||||
|
||||
entities.Add(uid);
|
||||
|
||||
@@ -5,9 +5,9 @@ using Robust.Shared.Collections;
|
||||
using Robust.Shared.Configuration;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Map.Components;
|
||||
using Robust.Shared.Map.Events;
|
||||
using Robust.Shared.Physics.Dynamics;
|
||||
|
||||
namespace Robust.Server.GameObjects
|
||||
{
|
||||
@@ -18,16 +18,6 @@ namespace Robust.Server.GameObjects
|
||||
|
||||
private bool _deleteEmptyGrids;
|
||||
|
||||
protected override MapId GetNextMapId()
|
||||
{
|
||||
var id = new MapId(++LastMapId);
|
||||
while (MapManager.MapExists(id))
|
||||
{
|
||||
id = new MapId(++LastMapId);
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
protected override void UpdatePvsChunks(Entity<TransformComponent, MetaDataComponent> grid)
|
||||
{
|
||||
_pvs.GridParentChanged(grid);
|
||||
@@ -41,6 +31,11 @@ namespace Robust.Server.GameObjects
|
||||
Subs.CVar(_cfg, CVars.GameDeleteEmptyGrids, SetGridDeletion, true);
|
||||
}
|
||||
|
||||
protected override void OnMapAdd(EntityUid uid, MapComponent component, ComponentAdd args)
|
||||
{
|
||||
EnsureComp<PhysicsMapComponent>(uid);
|
||||
}
|
||||
|
||||
private void SetGridDeletion(bool value)
|
||||
{
|
||||
_deleteEmptyGrids = value;
|
||||
|
||||
@@ -53,7 +53,5 @@ namespace Robust.Server.Maps
|
||||
/// This should be set to false if you want to load a map file onto an existing map and do not wish to overwrite the existing entity.
|
||||
/// </remarks>
|
||||
public bool LoadMap { get; set; } = true;
|
||||
|
||||
public bool DoMapInit = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace Robust.Shared.Audio;
|
||||
/// to allow the server to know audio lengths without shipping the large audio files themselves.
|
||||
/// </summary>
|
||||
[Prototype(ProtoName)]
|
||||
public sealed partial class AudioMetadataPrototype : IPrototype
|
||||
public sealed class AudioMetadataPrototype : IPrototype
|
||||
{
|
||||
public const string ProtoName = "audioMetadata";
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace Robust.Shared.Audio;
|
||||
/// This can be used by <see cref="Content.Shared.Audio.SharedContentAudioSystem"/> to apply an audio preset.
|
||||
/// </summary>
|
||||
[Prototype("audioPreset")]
|
||||
public sealed partial class AudioPresetPrototype : IPrototype
|
||||
public sealed class AudioPresetPrototype : IPrototype
|
||||
{
|
||||
[IdDataField]
|
||||
public string ID { get; } = default!;
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
using System.Collections.Generic;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.Utility;
|
||||
using Robust.Shared.ViewVariables;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Robust.Shared.Audio;
|
||||
|
||||
[Prototype("soundCollection")]
|
||||
public sealed partial class SoundCollectionPrototype : IPrototype
|
||||
public sealed class SoundCollectionPrototype : IPrototype
|
||||
{
|
||||
[ViewVariables]
|
||||
[IdDataField]
|
||||
|
||||
@@ -851,7 +851,7 @@ namespace Robust.Shared
|
||||
/// See the documentation of the <see cref="Network.AuthMode"/> enum for values.
|
||||
/// </summary>
|
||||
public static readonly CVarDef<int> AuthMode =
|
||||
CVarDef.Create("auth.mode", (int) Network.AuthMode.Required, CVar.SERVERONLY);
|
||||
CVarDef.Create("auth.mode", (int) Network.AuthMode.Optional, CVar.SERVERONLY);
|
||||
|
||||
/// <summary>
|
||||
/// Allow unauthenticated localhost connections, even if the auth mode is set to required.
|
||||
|
||||
@@ -10,8 +10,7 @@ namespace Robust.Shared.Console.Commands;
|
||||
|
||||
sealed class AddMapCommand : LocalizedCommands
|
||||
{
|
||||
[Dependency] private readonly IMapManagerInternal _map = default!;
|
||||
[Dependency] private readonly IEntityManager _entMan = default!;
|
||||
[Dependency] private readonly IMapManager _map = default!;
|
||||
|
||||
public override string Command => "addmap";
|
||||
public override bool RequireServerOrSingleplayer => true;
|
||||
@@ -25,8 +24,11 @@ sealed class AddMapCommand : LocalizedCommands
|
||||
|
||||
if (!_map.MapExists(mapId))
|
||||
{
|
||||
var init = args.Length < 2 || !bool.Parse(args[1]);
|
||||
_entMan.System<SharedMapSystem>().CreateMap(mapId, runMapInit: init);
|
||||
_map.CreateMap(mapId);
|
||||
if (args.Length >= 2 && args[1] == "false")
|
||||
{
|
||||
_map.AddUninitializedMap(mapId);
|
||||
}
|
||||
|
||||
shell.WriteLine($"Map with ID {mapId} created.");
|
||||
return;
|
||||
|
||||
@@ -140,7 +140,7 @@ namespace Robust.Shared.ContentPack
|
||||
{
|
||||
Process.Start(new ProcessStartInfo
|
||||
{
|
||||
FileName = $"{Environment.GetEnvironmentVariable("SystemRoot")}\\explorer.exe",
|
||||
FileName = "explorer.exe",
|
||||
Arguments = ".",
|
||||
WorkingDirectory = fullPath,
|
||||
});
|
||||
|
||||
@@ -101,6 +101,7 @@ namespace Robust.Shared.GameObjects
|
||||
internal bool _mapIdInitialized;
|
||||
internal bool _gridInitialized;
|
||||
|
||||
// TODO: Cache this.
|
||||
/// <summary>
|
||||
/// The EntityUid of the map which this object is on, if any.
|
||||
/// </summary>
|
||||
|
||||
@@ -1013,11 +1013,6 @@ namespace Robust.Shared.GameObjects
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Internal variant of <see cref="GetComponents"/> that directly returns the actual component set.
|
||||
/// </summary>
|
||||
internal IReadOnlyCollection<IComponent> GetComponentsInternal(EntityUid uid) => _entCompIndex[uid];
|
||||
|
||||
/// <inheritdoc />
|
||||
public int ComponentCount(EntityUid uid)
|
||||
{
|
||||
|
||||
@@ -5,17 +5,16 @@ using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Runtime.CompilerServices;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.Maths;
|
||||
|
||||
namespace Robust.Shared.GameObjects;
|
||||
|
||||
public partial class EntityManager
|
||||
{
|
||||
// This method will soon(TM) be marked as obsolete.
|
||||
// This method will soon be marked as obsolete.
|
||||
public EntityUid SpawnEntity(string? protoName, EntityCoordinates coordinates, ComponentRegistry? overrides = null)
|
||||
=> SpawnAttachedTo(protoName, coordinates, overrides);
|
||||
|
||||
// This method will soon(TM) be marked as obsolete.
|
||||
// This method will soon be marked as obsolete.
|
||||
public EntityUid SpawnEntity(string? protoName, MapCoordinates coordinates, ComponentRegistry? overrides = null)
|
||||
=> Spawn(protoName, coordinates, overrides);
|
||||
|
||||
@@ -84,16 +83,12 @@ public partial class EntityManager
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public EntityUid Spawn(string? protoName = null, ComponentRegistry? overrides = null, bool doMapInit = true)
|
||||
{
|
||||
var entity = CreateEntityUninitialized(protoName, MapCoordinates.Nullspace, overrides);
|
||||
InitializeAndStartEntity(entity, doMapInit);
|
||||
return entity;
|
||||
}
|
||||
public EntityUid Spawn(string? protoName = null, ComponentRegistry? overrides = null)
|
||||
=> Spawn(protoName, MapCoordinates.Nullspace, overrides);
|
||||
|
||||
public virtual EntityUid Spawn(string? protoName, MapCoordinates coordinates, ComponentRegistry? overrides = null, Angle rotation = default!)
|
||||
public virtual EntityUid Spawn(string? protoName, MapCoordinates coordinates, ComponentRegistry? overrides = null)
|
||||
{
|
||||
var entity = CreateEntityUninitialized(protoName, coordinates, overrides, rotation);
|
||||
var entity = CreateEntityUninitialized(protoName, coordinates, overrides);
|
||||
InitializeAndStartEntity(entity, coordinates.MapId);
|
||||
return entity;
|
||||
}
|
||||
@@ -122,8 +117,7 @@ public partial class EntityManager
|
||||
return true;
|
||||
}
|
||||
|
||||
var doMapInit = _mapSystem.IsInitialized(xform.MapUid);
|
||||
uid = Spawn(protoName, overrides, doMapInit);
|
||||
uid = Spawn(protoName, overrides);
|
||||
if (_containers.Insert(uid.Value, container))
|
||||
return true;
|
||||
|
||||
@@ -147,8 +141,7 @@ public partial class EntityManager
|
||||
if (!containerComp.Containers.TryGetValue(containerId, out var container))
|
||||
return false;
|
||||
|
||||
var doMapInit = _mapSystem.IsInitialized(TransformQuery.GetComponent(containerUid).MapUid);
|
||||
uid = Spawn(protoName, overrides, doMapInit);
|
||||
uid = Spawn(protoName, overrides);
|
||||
|
||||
if (_containers.Insert(uid.Value, container))
|
||||
return true;
|
||||
@@ -164,8 +157,7 @@ public partial class EntityManager
|
||||
if (!xform.ParentUid.IsValid())
|
||||
return Spawn(protoName);
|
||||
|
||||
var doMapInit = _mapSystem.IsInitialized(xform.MapUid);
|
||||
var uid = Spawn(protoName, overrides, doMapInit);
|
||||
var uid = Spawn(protoName, overrides);
|
||||
_xforms.DropNextTo(uid, target);
|
||||
return uid;
|
||||
}
|
||||
@@ -190,16 +182,16 @@ public partial class EntityManager
|
||||
ContainerManagerComponent? containerComp = null,
|
||||
ComponentRegistry? overrides = null)
|
||||
{
|
||||
var uid = Spawn(protoName, overrides);
|
||||
inserted = true;
|
||||
xform ??= TransformQuery.GetComponent(containerUid);
|
||||
var doMapInit = _mapSystem.IsInitialized(xform.MapUid);
|
||||
var uid = Spawn(protoName, overrides, doMapInit);
|
||||
|
||||
if ((containerComp == null && !TryGetComponent(containerUid, out containerComp))
|
||||
|| !containerComp.Containers.TryGetValue(containerId, out var container)
|
||||
|| !_containers.Insert(uid, container))
|
||||
{
|
||||
|
||||
inserted = false;
|
||||
xform ??= TransformQuery.GetComponent(containerUid);
|
||||
if (xform.ParentUid.IsValid())
|
||||
_xforms.DropNextTo(uid, (containerUid, xform));
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Map.Components;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Network;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Profiling;
|
||||
@@ -298,13 +297,14 @@ namespace Robust.Shared.GameObjects
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public virtual EntityUid CreateEntityUninitialized(string? prototypeName, MapCoordinates coordinates, ComponentRegistry? overrides = null, Angle rotation = default!)
|
||||
public virtual EntityUid CreateEntityUninitialized(string? prototypeName, MapCoordinates coordinates, ComponentRegistry? overrides = null)
|
||||
{
|
||||
var newEntity = CreateEntity(prototypeName, out _, overrides);
|
||||
var transform = TransformQuery.GetComponent(newEntity);
|
||||
|
||||
if (coordinates.MapId == MapId.Nullspace)
|
||||
{
|
||||
DebugTools.Assert(_mapManager.GetMapEntityId(coordinates.MapId) == EntityUid.Invalid);
|
||||
transform._parent = EntityUid.Invalid;
|
||||
transform.Anchored = false;
|
||||
return newEntity;
|
||||
@@ -323,7 +323,7 @@ namespace Robust.Shared.GameObjects
|
||||
else
|
||||
{
|
||||
coords = new EntityCoordinates(mapEnt, coordinates.Position);
|
||||
_xforms.SetCoordinates(newEntity, transform, coords, rotation, newParent: mapXform);
|
||||
_xforms.SetCoordinates(newEntity, transform, coords, null, newParent: mapXform);
|
||||
}
|
||||
|
||||
return newEntity;
|
||||
@@ -821,22 +821,15 @@ namespace Robust.Shared.GameObjects
|
||||
|
||||
public void InitializeAndStartEntity(EntityUid entity, MapId? mapId = null)
|
||||
{
|
||||
var doMapInit = _mapManager.IsMapInitialized(mapId ?? TransformQuery.GetComponent(entity).MapID);
|
||||
InitializeAndStartEntity(entity, doMapInit);
|
||||
}
|
||||
|
||||
public void InitializeAndStartEntity(Entity<MetaDataComponent?> entity, bool doMapInit)
|
||||
{
|
||||
if (!MetaQuery.Resolve(entity.Owner, ref entity.Comp))
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
InitializeEntity(entity.Owner, entity.Comp);
|
||||
StartEntity(entity.Owner);
|
||||
var meta = MetaQuery.GetComponent(entity);
|
||||
InitializeEntity(entity, meta);
|
||||
StartEntity(entity);
|
||||
|
||||
if (doMapInit)
|
||||
RunMapInit(entity.Owner, entity.Comp);
|
||||
// If the map we're initializing the entity on is initialized, run map init on it.
|
||||
if (_mapManager.IsMapInitialized(mapId ?? TransformQuery.GetComponent(entity).MapID))
|
||||
RunMapInit(entity, meta);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -866,7 +859,7 @@ namespace Robust.Shared.GameObjects
|
||||
DebugTools.Assert(meta.EntityLifeStage == EntityLifeStage.Initialized, $"Expected entity {ToPrettyString(entity)} to be initialized, was {meta.EntityLifeStage}");
|
||||
SetLifeStage(meta, EntityLifeStage.MapInitialized);
|
||||
|
||||
EventBus.RaiseLocalEvent(entity, MapInitEventInstance);
|
||||
EventBus.RaiseLocalEvent(entity, MapInitEventInstance, false);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
@@ -5,10 +5,8 @@ using System.Runtime.CompilerServices;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Timing;
|
||||
using TerraFX.Interop.Windows;
|
||||
|
||||
namespace Robust.Shared.GameObjects;
|
||||
|
||||
@@ -701,32 +699,32 @@ public partial class EntitySystem
|
||||
|
||||
#region Entity Spawning
|
||||
|
||||
// This method will be obsoleted soon(TM).
|
||||
// This method will be obsoleted soon.
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
protected EntityUid Spawn(string? prototype, EntityCoordinates coordinates)
|
||||
{
|
||||
return ((IEntityManager)EntityManager).SpawnEntity(prototype, coordinates);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IEntityManager.Spawn(string?, MapCoordinates, ComponentRegistry?, Angle)" />
|
||||
/// <inheritdoc cref="IEntityManager.Spawn(string?, MapCoordinates, ComponentRegistry?)" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
protected EntityUid Spawn(string? prototype, MapCoordinates coordinates, ComponentRegistry? overrides = null, Angle rotation = default)
|
||||
=> EntityManager.Spawn(prototype, coordinates, overrides, rotation);
|
||||
protected EntityUid Spawn(string? prototype, MapCoordinates coordinates)
|
||||
=> EntityManager.Spawn(prototype, coordinates);
|
||||
|
||||
/// <inheritdoc cref="IEntityManager.Spawn(string?, ComponentRegistry?, bool)" />
|
||||
/// <inheritdoc cref="IEntityManager.Spawn(string?, ComponentRegistry?)" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
protected EntityUid Spawn(string? prototype = null, ComponentRegistry? overrides = null, bool doMapInit = true)
|
||||
=> EntityManager.Spawn(prototype, overrides, doMapInit);
|
||||
protected EntityUid Spawn(string? prototype = null)
|
||||
=> EntityManager.Spawn(prototype);
|
||||
|
||||
/// <inheritdoc cref="IEntityManager.SpawnAttachedTo" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
protected EntityUid SpawnAttachedTo(string? prototype, EntityCoordinates coordinates, ComponentRegistry? overrides = null)
|
||||
=> EntityManager.SpawnAttachedTo(prototype, coordinates, overrides);
|
||||
protected EntityUid SpawnAttachedTo(string? prototype, EntityCoordinates coordinates)
|
||||
=> EntityManager.SpawnAttachedTo(prototype, coordinates);
|
||||
|
||||
/// <inheritdoc cref="IEntityManager.SpawnAtPosition" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
protected EntityUid SpawnAtPosition(string? prototype, EntityCoordinates coordinates, ComponentRegistry? overrides = null)
|
||||
=> EntityManager.SpawnAtPosition(prototype, coordinates, overrides);
|
||||
protected EntityUid SpawnAtPosition(string? prototype, EntityCoordinates coordinates)
|
||||
=> EntityManager.SpawnAtPosition(prototype, coordinates);
|
||||
|
||||
/// <inheritdoc cref="IEntityManager.TrySpawnInContainer" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
|
||||
@@ -2,7 +2,6 @@ using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Robust.Shared.GameObjects;
|
||||
@@ -28,12 +27,12 @@ public partial interface IEntityManager
|
||||
/// <summary>
|
||||
/// Spawns an entity in nullspace.
|
||||
/// </summary>
|
||||
EntityUid Spawn(string? protoName = null, ComponentRegistry? overrides = null, bool doMapInit = true);
|
||||
EntityUid Spawn(string? protoName = null, ComponentRegistry? overrides = null);
|
||||
|
||||
/// <summary>
|
||||
/// Spawns an entity at a specific world position. The entity will either be parented to the map or a grid.
|
||||
/// </summary>
|
||||
EntityUid Spawn(string? protoName, MapCoordinates coordinates, ComponentRegistry? overrides = null, Angle rotation = default!);
|
||||
EntityUid Spawn(string? protoName, MapCoordinates coordinates, ComponentRegistry? overrides = null);
|
||||
|
||||
/// <summary>
|
||||
/// Spawns an entity and then parents it to the entity that the given entity coordinates are relative to.
|
||||
|
||||
@@ -4,7 +4,6 @@ using System.Diagnostics.CodeAnalysis;
|
||||
using JetBrains.Annotations;
|
||||
using Prometheus;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
@@ -77,12 +76,10 @@ namespace Robust.Shared.GameObjects
|
||||
|
||||
EntityUid CreateEntityUninitialized(string? prototypeName, EntityCoordinates coordinates, ComponentRegistry? overrides = null);
|
||||
|
||||
EntityUid CreateEntityUninitialized(string? prototypeName, MapCoordinates coordinates, ComponentRegistry? overrides = null, Angle rotation = default!);
|
||||
EntityUid CreateEntityUninitialized(string? prototypeName, MapCoordinates coordinates, ComponentRegistry? overrides = null);
|
||||
|
||||
void InitializeAndStartEntity(EntityUid entity, MapId? mapId = null);
|
||||
|
||||
void InitializeAndStartEntity(Entity<MetaDataComponent?> entity, bool doMapInit);
|
||||
|
||||
void InitializeEntity(EntityUid entity, MetaDataComponent? meta = null);
|
||||
|
||||
void StartEntity(EntityUid entity);
|
||||
|
||||
@@ -1,188 +1,68 @@
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Map.Components;
|
||||
using Robust.Shared.Physics.Dynamics;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Robust.Shared.GameObjects;
|
||||
|
||||
public abstract partial class SharedMapSystem
|
||||
{
|
||||
protected int LastMapId;
|
||||
|
||||
private void InitializeMap()
|
||||
{
|
||||
SubscribeLocalEvent<MapComponent, ComponentAdd>(OnComponentAdd);
|
||||
SubscribeLocalEvent<MapComponent, ComponentInit>(OnCompInit);
|
||||
SubscribeLocalEvent<MapComponent, ComponentStartup>(OnCompStartup);
|
||||
SubscribeLocalEvent<MapComponent, MapInitEvent>(OnMapInit);
|
||||
SubscribeLocalEvent<MapComponent, ComponentAdd>(OnMapAdd);
|
||||
SubscribeLocalEvent<MapComponent, ComponentInit>(OnMapInit);
|
||||
SubscribeLocalEvent<MapComponent, ComponentShutdown>(OnMapRemoved);
|
||||
SubscribeLocalEvent<MapComponent, ComponentHandleState>(OnMapHandleState);
|
||||
SubscribeLocalEvent<MapComponent, ComponentGetState>(OnMapGetState);
|
||||
}
|
||||
|
||||
public bool MapExists([NotNullWhen(true)] MapId? mapId)
|
||||
{
|
||||
return mapId != null && Maps.ContainsKey(mapId.Value);
|
||||
}
|
||||
|
||||
public EntityUid GetMap(MapId mapId)
|
||||
{
|
||||
return Maps[mapId];
|
||||
}
|
||||
|
||||
public bool TryGetMap([NotNullWhen(true)] MapId? mapId, [NotNullWhen(true)] out EntityUid? uid)
|
||||
{
|
||||
if (mapId == null || !Maps.TryGetValue(mapId.Value, out var map))
|
||||
{
|
||||
uid = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
uid = map;
|
||||
return true;
|
||||
}
|
||||
|
||||
private void OnMapHandleState(EntityUid uid, MapComponent component, ref ComponentHandleState args)
|
||||
{
|
||||
if (args.Current is not MapComponentState state)
|
||||
return;
|
||||
|
||||
if (component.MapId == MapId.Nullspace)
|
||||
{
|
||||
if (state.MapId == MapId.Nullspace)
|
||||
throw new Exception($"Received invalid map state? {ToPrettyString(uid)}");
|
||||
component.MapId = state.MapId;
|
||||
|
||||
component.MapId = state.MapId;
|
||||
Maps.Add(component.MapId, uid);
|
||||
RecursiveMapIdUpdate(uid, uid, component.MapId);
|
||||
if (!MapManager.MapExists(state.MapId))
|
||||
{
|
||||
var mapInternal = (IMapManagerInternal)MapManager;
|
||||
mapInternal.CreateMap(state.MapId, uid);
|
||||
}
|
||||
|
||||
DebugTools.AssertEqual(component.MapId, state.MapId);
|
||||
component.LightingEnabled = state.LightingEnabled;
|
||||
component.MapInitialized = state.Initialized;
|
||||
var xformQuery = GetEntityQuery<TransformComponent>();
|
||||
|
||||
if (LifeStage(uid) >= EntityLifeStage.Initialized)
|
||||
SetPaused(uid, state.MapPaused);
|
||||
else
|
||||
component.MapPaused = state.MapPaused;
|
||||
}
|
||||
xformQuery.GetComponent(uid).ChangeMapId(state.MapId, xformQuery);
|
||||
|
||||
private void RecursiveMapIdUpdate(EntityUid uid, EntityUid mapUid, MapId mapId)
|
||||
{
|
||||
// This is required only in the event where an entity becomes a map AFTER children have already been attached to it.
|
||||
// AFAIK, this currently only happens when the client applies entity states out of order (i.e., ignoring transform hierarchy),
|
||||
// which itself only happens if PVS is disabled.
|
||||
// TODO MAPS remove this
|
||||
|
||||
var xform = Transform(uid);
|
||||
xform.MapUid = mapUid;
|
||||
xform.MapID = mapId;
|
||||
xform._mapIdInitialized = true;
|
||||
foreach (var child in xform._children)
|
||||
{
|
||||
RecursiveMapIdUpdate(child, mapUid, mapId);
|
||||
}
|
||||
MapManager.SetMapPaused(state.MapId, state.MapPaused);
|
||||
}
|
||||
|
||||
private void OnMapGetState(EntityUid uid, MapComponent component, ref ComponentGetState args)
|
||||
{
|
||||
args.State = new MapComponentState(component.MapId, component.LightingEnabled, component.MapPaused, component.MapInitialized);
|
||||
args.State = new MapComponentState(component.MapId, component.LightingEnabled, component.MapPaused);
|
||||
}
|
||||
|
||||
protected abstract MapId GetNextMapId();
|
||||
protected abstract void OnMapAdd(EntityUid uid, MapComponent component, ComponentAdd args);
|
||||
|
||||
private void OnComponentAdd(EntityUid uid, MapComponent component, ComponentAdd args)
|
||||
private void OnMapInit(EntityUid uid, MapComponent component, ComponentInit args)
|
||||
{
|
||||
// ordered startups when
|
||||
EnsureComp<PhysicsMapComponent>(uid);
|
||||
EnsureComp<GridTreeComponent>(uid);
|
||||
EnsureComp<MovedGridsComponent>(uid);
|
||||
}
|
||||
|
||||
private void OnCompInit(EntityUid uid, MapComponent component, ComponentInit args)
|
||||
{
|
||||
if (component.MapId == MapId.Nullspace)
|
||||
component.MapId = GetNextMapId();
|
||||
|
||||
DebugTools.AssertEqual(component.MapId.IsClientSide, IsClientSide(uid));
|
||||
if (!Maps.TryAdd(component.MapId, uid))
|
||||
{
|
||||
if (Maps[component.MapId] != uid)
|
||||
throw new Exception($"Attempted to initialize a map {ToPrettyString(uid)} with a duplicate map id {component.MapId}");
|
||||
}
|
||||
|
||||
var msg = new MapChangedEvent(uid, component.MapId, true);
|
||||
RaiseLocalEvent(uid, msg, true);
|
||||
}
|
||||
|
||||
private void OnCompStartup(EntityUid uid, MapComponent component, ComponentStartup args)
|
||||
{
|
||||
if (component.MapPaused)
|
||||
RecursiveSetPaused(uid, true);
|
||||
}
|
||||
|
||||
private void OnMapRemoved(EntityUid uid, MapComponent component, ComponentShutdown args)
|
||||
{
|
||||
DebugTools.Assert(component.MapId != MapId.Nullspace);
|
||||
Maps.Remove(component.MapId);
|
||||
Log.Info($"Deleting map {component.MapId}");
|
||||
|
||||
var iMap = (IMapManagerInternal)MapManager;
|
||||
iMap.RemoveMapId(component.MapId);
|
||||
|
||||
var msg = new MapChangedEvent(uid, component.MapId, false);
|
||||
RaiseLocalEvent(uid, msg, true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new map, automatically assigning a map id.
|
||||
/// </summary>
|
||||
public EntityUid CreateMap(out MapId mapId, bool runMapInit = true)
|
||||
{
|
||||
mapId = GetNextMapId();
|
||||
var uid = CreateMap(mapId, runMapInit);
|
||||
return uid;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="CreateMap(out Robust.Shared.Map.MapId,bool)"/>
|
||||
public EntityUid CreateMap(bool runMapInit = true) => CreateMap(out _, runMapInit);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new map with the specified map id.
|
||||
/// </summary>
|
||||
/// <exception cref="ArgumentException">Throws if an invalid or already existing map id is provided.</exception>
|
||||
public EntityUid CreateMap(MapId mapId, bool runMapInit = true)
|
||||
{
|
||||
if (Maps.ContainsKey(mapId))
|
||||
throw new ArgumentException($"Map with id {mapId} already exists");
|
||||
|
||||
if (mapId == MapId.Nullspace)
|
||||
throw new ArgumentException($"Cannot create a null-space map");
|
||||
|
||||
if (_netManager.IsServer && mapId.IsClientSide)
|
||||
throw new ArgumentException($"Attempted to create a client-side map on the server?");
|
||||
|
||||
if (_netManager.IsClient && _netManager.IsConnected && !mapId.IsClientSide)
|
||||
throw new ArgumentException($"Attempted to create a client-side map entity with a non client-side map ID?");
|
||||
|
||||
var uid = EntityManager.CreateEntityUninitialized(null);
|
||||
var map = _factory.GetComponent<MapComponent>();
|
||||
map.MapId = mapId;
|
||||
AddComp(uid, map);
|
||||
|
||||
// Give the entity a name, mainly for debugging. Content can always override this with a localized name.
|
||||
var meta = MetaData(uid);
|
||||
_meta.SetEntityName(uid, $"Map Entity", meta);
|
||||
|
||||
// Initialize components. this should add the map id to the collections.
|
||||
EntityManager.InitializeComponents(uid, meta);
|
||||
EntityManager.StartComponents(uid);
|
||||
DebugTools.Assert(Maps[mapId] == uid);
|
||||
|
||||
if (runMapInit)
|
||||
InitializeMap((uid, map));
|
||||
else
|
||||
SetPaused((uid, map), true);
|
||||
|
||||
return uid;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,83 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Map.Components;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Robust.Shared.GameObjects;
|
||||
|
||||
public abstract partial class SharedMapSystem
|
||||
{
|
||||
public bool IsInitialized(MapId mapId)
|
||||
{
|
||||
if (mapId == MapId.Nullspace)
|
||||
return true; // Nullspace is always initialized
|
||||
|
||||
if(!Maps.TryGetValue(mapId, out var uid))
|
||||
throw new ArgumentException($"Map {mapId} does not exist.");
|
||||
|
||||
return IsInitialized(uid);
|
||||
}
|
||||
public bool IsInitialized(EntityUid? map)
|
||||
{
|
||||
if (map == null)
|
||||
return true; // Nullspace is always initialized
|
||||
|
||||
return IsInitialized(map.Value);
|
||||
}
|
||||
|
||||
public bool IsInitialized(Entity<MapComponent?> map)
|
||||
{
|
||||
if (!_mapQuery.Resolve(map, ref map.Comp))
|
||||
return false;
|
||||
|
||||
return map.Comp.MapInitialized;
|
||||
}
|
||||
|
||||
private void OnMapInit(EntityUid uid, MapComponent component, MapInitEvent args)
|
||||
{
|
||||
DebugTools.Assert(!component.MapInitialized);
|
||||
component.MapInitialized = true;
|
||||
EntityManager.Dirty(uid, component);
|
||||
}
|
||||
|
||||
public void InitializeMap(MapId mapId, bool unpause = true)
|
||||
{
|
||||
if(!Maps.TryGetValue(mapId, out var uid))
|
||||
throw new ArgumentException($"Map {mapId} does not exist.");
|
||||
|
||||
InitializeMap(uid, unpause);
|
||||
}
|
||||
|
||||
public void InitializeMap(Entity<MapComponent?> map, bool unpause = true)
|
||||
{
|
||||
if (!_mapQuery.Resolve(map, ref map.Comp))
|
||||
return;
|
||||
|
||||
if (map.Comp.MapInitialized)
|
||||
throw new ArgumentException($"Map {ToPrettyString(map)} is already initialized.");
|
||||
|
||||
RecursiveMapInit(map.Owner);
|
||||
|
||||
if (unpause)
|
||||
SetPaused(map, false);
|
||||
}
|
||||
|
||||
private void RecursiveMapInit(EntityUid entity)
|
||||
{
|
||||
var toInitialize = new List<EntityUid> {entity};
|
||||
for (var i = 0; i < toInitialize.Count; i++)
|
||||
{
|
||||
var uid = toInitialize[i];
|
||||
// toInitialize might contain deleted entities.
|
||||
if(!_metaQuery.TryComp(uid, out var meta))
|
||||
continue;
|
||||
|
||||
if (meta.EntityLifeStage == EntityLifeStage.MapInitialized)
|
||||
continue;
|
||||
|
||||
toInitialize.AddRange(Transform(uid)._children);
|
||||
EntityManager.RunMapInit(uid, meta);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
using System;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Map.Components;
|
||||
|
||||
namespace Robust.Shared.GameObjects;
|
||||
|
||||
public abstract partial class SharedMapSystem
|
||||
{
|
||||
public bool IsPaused(MapId mapId)
|
||||
{
|
||||
if (mapId == MapId.Nullspace)
|
||||
return false;
|
||||
|
||||
if(!Maps.TryGetValue(mapId, out var uid))
|
||||
throw new ArgumentException($"Map {mapId} does not exist.");
|
||||
|
||||
return IsPaused(uid);
|
||||
}
|
||||
|
||||
public bool IsPaused(Entity<MapComponent?> map)
|
||||
{
|
||||
if (!_mapQuery.Resolve(map, ref map.Comp))
|
||||
return false;
|
||||
|
||||
return map.Comp.MapPaused;
|
||||
}
|
||||
|
||||
public void SetPaused(MapId mapId, bool paused)
|
||||
{
|
||||
if(!Maps.TryGetValue(mapId, out var uid))
|
||||
throw new ArgumentException($"Map {mapId} does not exist.");
|
||||
|
||||
SetPaused(uid, paused);
|
||||
}
|
||||
|
||||
public void SetPaused(Entity<MapComponent?> map, bool paused)
|
||||
{
|
||||
if (!_mapQuery.Resolve(map, ref map.Comp))
|
||||
return;
|
||||
|
||||
if (map.Comp.MapPaused == paused)
|
||||
return;
|
||||
|
||||
map.Comp.MapPaused = paused;
|
||||
if (map.Comp.LifeStage < ComponentLifeStage.Initializing)
|
||||
return;
|
||||
|
||||
Dirty(map);
|
||||
RecursiveSetPaused(map, paused);
|
||||
}
|
||||
|
||||
private void RecursiveSetPaused(EntityUid entity, bool paused)
|
||||
{
|
||||
_meta.SetEntityPaused(entity, paused);
|
||||
foreach (var child in Transform(entity)._children)
|
||||
{
|
||||
RecursiveSetPaused(child, paused);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20,23 +20,17 @@ namespace Robust.Shared.GameObjects
|
||||
[Dependency] private readonly FixtureSystem _fixtures = default!;
|
||||
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
|
||||
[Dependency] private readonly SharedTransformSystem _transform = default!;
|
||||
[Dependency] private readonly IComponentFactory _factory = default!;
|
||||
[Dependency] private readonly MetaDataSystem _meta = default!;
|
||||
|
||||
private EntityQuery<MapComponent> _mapQuery;
|
||||
private EntityQuery<MapGridComponent> _gridQuery;
|
||||
private EntityQuery<MetaDataComponent> _metaQuery;
|
||||
private EntityQuery<TransformComponent> _xformQuery;
|
||||
|
||||
internal Dictionary<MapId, EntityUid> Maps { get; } = new();
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
_mapQuery = GetEntityQuery<MapComponent>();
|
||||
_gridQuery = GetEntityQuery<MapGridComponent>();
|
||||
_metaQuery = GetEntityQuery<MetaDataComponent>();
|
||||
_xformQuery = GetEntityQuery<TransformComponent>();
|
||||
|
||||
InitializeMap();
|
||||
|
||||
@@ -199,34 +199,47 @@ public abstract partial class SharedTransformSystem
|
||||
|
||||
#region Component Lifetime
|
||||
|
||||
private (EntityUid?, MapId) InitializeMapUid(EntityUid uid, TransformComponent xform)
|
||||
{
|
||||
if (xform._mapIdInitialized)
|
||||
return (xform.MapUid, xform.MapID);
|
||||
|
||||
if (xform.ParentUid.IsValid())
|
||||
{
|
||||
(xform.MapUid, xform.MapID) = InitializeMapUid(xform.ParentUid, Transform(xform.ParentUid));
|
||||
}
|
||||
else if (_mapQuery.TryComp(uid, out var mapComp))
|
||||
{
|
||||
DebugTools.AssertNotEqual(mapComp.MapId, MapId.Nullspace);
|
||||
xform.MapUid = uid;
|
||||
xform.MapID = mapComp.MapId;
|
||||
}
|
||||
else
|
||||
{
|
||||
xform.MapUid = null;
|
||||
xform.MapID = MapId.Nullspace;
|
||||
}
|
||||
|
||||
xform._mapIdInitialized = true;
|
||||
return (xform.MapUid, xform.MapID);
|
||||
}
|
||||
|
||||
private void OnCompInit(EntityUid uid, TransformComponent component, ComponentInit args)
|
||||
{
|
||||
InitializeMapUid(uid, component);
|
||||
// Children MAY be initialized here before their parents are.
|
||||
// We do this whole dance to handle this recursively,
|
||||
// setting _mapIdInitialized along the way to avoid going to the MapComponent every iteration.
|
||||
static MapId FindMapIdAndSet(EntityUid uid, TransformComponent xform, IEntityManager entMan, EntityQuery<TransformComponent> xformQuery, IMapManager mapManager)
|
||||
{
|
||||
if (xform._mapIdInitialized)
|
||||
return xform.MapID;
|
||||
|
||||
MapId value;
|
||||
|
||||
if (xform.ParentUid.IsValid())
|
||||
{
|
||||
value = FindMapIdAndSet(xform.ParentUid, xformQuery.GetComponent(xform.ParentUid), entMan, xformQuery, mapManager);
|
||||
}
|
||||
else
|
||||
{
|
||||
// second level node, terminates recursion up the branch of the tree
|
||||
if (entMan.TryGetComponent(uid, out MapComponent? mapComp))
|
||||
{
|
||||
value = mapComp.MapId;
|
||||
}
|
||||
else
|
||||
{
|
||||
// We allow entities to be spawned directly into null-space.
|
||||
value = MapId.Nullspace;
|
||||
}
|
||||
}
|
||||
|
||||
xform.MapUid = value == MapId.Nullspace ? null : mapManager.GetMapEntityId(value);
|
||||
xform.MapID = value;
|
||||
xform._mapIdInitialized = true;
|
||||
return value;
|
||||
}
|
||||
|
||||
if (!component._mapIdInitialized)
|
||||
{
|
||||
FindMapIdAndSet(uid, component, EntityManager, XformQuery, _mapManager);
|
||||
component._mapIdInitialized = true;
|
||||
}
|
||||
|
||||
// Has to be done if _parent is set from ExposeData.
|
||||
if (component.ParentUid.IsValid())
|
||||
@@ -509,8 +522,6 @@ public abstract partial class SharedTransformSystem
|
||||
throw new InvalidOperationException($"Attempted to re-parent to a terminating object. Entity: {ToPrettyString(uid)}, new parent: {ToPrettyString(value.EntityId)}");
|
||||
}
|
||||
|
||||
InitializeMapUid(value.EntityId, newParent);
|
||||
|
||||
// Check for recursive/circular transform hierarchies.
|
||||
if (xform.MapUid == newParent.MapUid)
|
||||
{
|
||||
@@ -870,28 +881,6 @@ public abstract partial class SharedTransformSystem
|
||||
return GetMapCoordinates(entity.Comp);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SetMapCoordinates(EntityUid entity, MapCoordinates coordinates)
|
||||
{
|
||||
var xform = XformQuery.GetComponent(entity);
|
||||
SetMapCoordinates((entity, xform), coordinates);
|
||||
}
|
||||
|
||||
public void SetMapCoordinates(Entity<TransformComponent> entity, MapCoordinates coordinates)
|
||||
{
|
||||
var mapUid = _map.GetMap(coordinates.MapId);
|
||||
if (!_gridQuery.HasComponent(entity) &&
|
||||
_mapManager.TryFindGridAt(mapUid, coordinates.Position, out var targetGrid, out _))
|
||||
{
|
||||
var invWorldMatrix = GetInvWorldMatrix(targetGrid);
|
||||
SetCoordinates(entity, new EntityCoordinates(targetGrid, invWorldMatrix.Transform(coordinates.Position)));
|
||||
}
|
||||
else
|
||||
{
|
||||
SetCoordinates(entity, new EntityCoordinates(mapUid, coordinates.Position));
|
||||
}
|
||||
}
|
||||
|
||||
[Pure]
|
||||
public (Vector2 WorldPosition, Angle WorldRotation) GetWorldPositionRotation(EntityUid uid)
|
||||
{
|
||||
|
||||
@@ -26,7 +26,6 @@ namespace Robust.Shared.GameObjects
|
||||
[Dependency] private readonly INetManager _netMan = default!;
|
||||
[Dependency] private readonly SharedContainerSystem _container = default!;
|
||||
|
||||
private EntityQuery<MapComponent> _mapQuery;
|
||||
private EntityQuery<MapGridComponent> _gridQuery;
|
||||
private EntityQuery<MetaDataComponent> _metaQuery;
|
||||
protected EntityQuery<TransformComponent> XformQuery;
|
||||
@@ -51,7 +50,6 @@ namespace Robust.Shared.GameObjects
|
||||
|
||||
UpdatesOutsidePrediction = true;
|
||||
|
||||
_mapQuery = GetEntityQuery<MapComponent>();
|
||||
_gridQuery = GetEntityQuery<MapGridComponent>();
|
||||
_metaQuery = GetEntityQuery<MetaDataComponent>();
|
||||
XformQuery = GetEntityQuery<TransformComponent>();
|
||||
|
||||
@@ -12,29 +12,35 @@ namespace Robust.Shared.Map.Components
|
||||
public sealed partial class MapComponent : Component
|
||||
{
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField]
|
||||
[DataField("lightingEnabled")]
|
||||
public bool LightingEnabled { get; set; } = true;
|
||||
|
||||
[ViewVariables(VVAccess.ReadOnly)]
|
||||
public MapId MapId { get; internal set; } = MapId.Nullspace;
|
||||
|
||||
[DataField, Access(typeof(SharedMapSystem), typeof(MapManager))]
|
||||
public bool MapPaused;
|
||||
[ViewVariables(VVAccess.ReadOnly)]
|
||||
public bool MapPaused { get; set; } = false;
|
||||
|
||||
[DataField, Access(typeof(SharedMapSystem), typeof(MapManager))]
|
||||
public bool MapInitialized;
|
||||
//TODO replace MapPreInit with the map's entity life stage
|
||||
[ViewVariables(VVAccess.ReadOnly)]
|
||||
public bool MapPreInit { get; set; } = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Serialized state of a <see cref="MapGridComponentState"/>.
|
||||
/// </summary>
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class MapComponentState(MapId mapId, bool lightingEnabled, bool paused, bool init)
|
||||
: ComponentState
|
||||
public sealed class MapComponentState : ComponentState
|
||||
{
|
||||
public MapId MapId = mapId;
|
||||
public bool LightingEnabled = lightingEnabled;
|
||||
public bool MapPaused = paused;
|
||||
public bool Initialized = init;
|
||||
public MapId MapId;
|
||||
public bool LightingEnabled;
|
||||
public bool MapPaused;
|
||||
|
||||
public MapComponentState(MapId mapId, bool lightingEnabled, bool paused)
|
||||
{
|
||||
MapId = mapId;
|
||||
LightingEnabled = lightingEnabled;
|
||||
MapPaused = paused;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,9 @@ namespace Robust.Shared.Map
|
||||
public const bool Approximate = false;
|
||||
public const bool IncludeMap = true;
|
||||
|
||||
[Obsolete("Use EntityQuery<MapGridComponent>")]
|
||||
IEnumerable<MapGridComponent> GetAllGrids();
|
||||
|
||||
/// <summary>
|
||||
/// Should the OnTileChanged event be suppressed? This is useful for initially loading the map
|
||||
/// so that you don't spam an event for each of the million station tiles.
|
||||
@@ -39,7 +42,16 @@ namespace Robust.Shared.Map
|
||||
|
||||
void Restart();
|
||||
|
||||
[Obsolete("Use MapSystem")]
|
||||
/// <summary>
|
||||
/// Creates a new map.
|
||||
/// </summary>
|
||||
/// <param name="mapId">
|
||||
/// If provided, the new map will use this ID. If not provided, a new ID will be selected automatically.
|
||||
/// </param>
|
||||
/// <returns>The new map.</returns>
|
||||
/// <exception cref="InvalidOperationException">
|
||||
/// Throw if an explicit ID for the map or default grid is passed and a map or grid with the specified ID already exists, respectively.
|
||||
/// </exception>
|
||||
MapId CreateMap(MapId? mapId = null);
|
||||
|
||||
/// <summary>
|
||||
@@ -47,12 +59,24 @@ namespace Robust.Shared.Map
|
||||
/// </summary>
|
||||
/// <param name="mapId">The map ID to check existence of.</param>
|
||||
/// <returns>True if the map exists, false otherwise.</returns>
|
||||
bool MapExists([NotNullWhen(true)] MapId? mapId);
|
||||
bool MapExists(MapId mapId);
|
||||
|
||||
/// <summary>
|
||||
/// Returns the map entity ID for a given map, or an invalid entity Id if the map does not exist.
|
||||
/// Creates a new entity, then sets it as the map entity.
|
||||
/// </summary>
|
||||
/// <returns>Newly created entity.</returns>
|
||||
EntityUid CreateNewMapEntity(MapId mapId);
|
||||
|
||||
/// <summary>
|
||||
/// Sets the MapEntity(root node) for a given map. If an entity is already set, it will be deleted
|
||||
/// before the new one is set.
|
||||
/// </summary>
|
||||
/// <param name="updateChildren">Should we re-parent children from the old map to the new one, or delete them.</param>
|
||||
void SetMapEntity(MapId mapId, EntityUid newMapEntityId, bool updateChildren = true);
|
||||
|
||||
/// <summary>
|
||||
/// Returns the map entity ID for a given map.
|
||||
/// </summary>
|
||||
[Obsolete("Use TryGetMap")]
|
||||
EntityUid GetMapEntityId(MapId mapId);
|
||||
|
||||
/// <summary>
|
||||
@@ -69,7 +93,6 @@ namespace Robust.Shared.Map
|
||||
MapGridComponent CreateGrid(MapId currentMapId, in GridCreateOptions options);
|
||||
MapGridComponent CreateGrid(MapId currentMapId);
|
||||
Entity<MapGridComponent> CreateGridEntity(MapId currentMapId, GridCreateOptions? options = null);
|
||||
Entity<MapGridComponent> CreateGridEntity(EntityUid map, GridCreateOptions? options = null);
|
||||
|
||||
[Obsolete("Use GetComponent<MapGridComponent>(uid)")]
|
||||
MapGridComponent GetGrid(EntityUid gridId);
|
||||
@@ -210,13 +233,17 @@ namespace Robust.Shared.Map
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
[Obsolete("Just delete the grid entity")]
|
||||
void DeleteGrid(EntityUid euid);
|
||||
|
||||
bool HasMapEntity(MapId mapId);
|
||||
|
||||
bool IsGrid(EntityUid uid);
|
||||
bool IsMap(EntityUid uid);
|
||||
|
||||
[Obsolete("Whatever this is used for, it is a terrible idea. Create a new map and get it's MapId.")]
|
||||
MapId NextMapId();
|
||||
MapGridComponent GetGridComp(EntityUid euid);
|
||||
|
||||
//
|
||||
// Pausing functions
|
||||
//
|
||||
@@ -225,15 +252,14 @@ namespace Robust.Shared.Map
|
||||
|
||||
void DoMapInitialize(MapId mapId);
|
||||
|
||||
[Obsolete("Use CreateMap's runMapInit argument")]
|
||||
// TODO rename this to actually be descriptive or just remove it.
|
||||
void AddUninitializedMap(MapId mapId);
|
||||
|
||||
[Obsolete("Use MapSystem")]
|
||||
[Pure]
|
||||
bool IsMapPaused(MapId mapId);
|
||||
|
||||
[Obsolete("Use MapSystem")]
|
||||
[Pure]
|
||||
bool IsMapInitialized(MapId mapId);
|
||||
|
||||
}
|
||||
|
||||
public struct GridCreateOptions
|
||||
|
||||
@@ -1,15 +1,23 @@
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
namespace Robust.Shared.Map
|
||||
{
|
||||
/// <inheritdoc />
|
||||
internal interface IMapManagerInternal : IMapManager
|
||||
{
|
||||
IGameTiming GameTiming { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Raises the OnTileChanged event.
|
||||
/// </summary>
|
||||
/// <param name="tileRef">A reference to the new tile.</param>
|
||||
/// <param name="oldTile">The old tile that got replaced.</param>
|
||||
void RaiseOnTileChanged(TileRef tileRef, Tile oldTile, Vector2i chunk);
|
||||
|
||||
MapId CreateMap(MapId? mapId, EntityUid euid);
|
||||
|
||||
void RemoveMapId(MapId mapId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +53,5 @@ namespace Robust.Shared.Map
|
||||
{
|
||||
return Value.ToString();
|
||||
}
|
||||
|
||||
public bool IsClientSide => Value < 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,15 +12,32 @@ using Robust.Shared.Utility;
|
||||
namespace Robust.Shared.Map;
|
||||
internal partial class MapManager
|
||||
{
|
||||
[Obsolete("Use GetComponent<MapGridComponent>(uid)")]
|
||||
public MapGridComponent GetGridComp(EntityUid euid)
|
||||
{
|
||||
return EntityManager.GetComponent<MapGridComponent>(euid);
|
||||
}
|
||||
|
||||
[Obsolete("Use EntityQuery instead.")]
|
||||
public IEnumerable<MapGridComponent> GetAllGrids()
|
||||
{
|
||||
var compQuery = EntityManager.AllEntityQueryEnumerator<MapGridComponent>();
|
||||
|
||||
while (compQuery.MoveNext(out var comp))
|
||||
{
|
||||
yield return comp;
|
||||
}
|
||||
}
|
||||
|
||||
// ReSharper disable once MethodOverloadWithOptionalParameter
|
||||
public MapGridComponent CreateGrid(MapId currentMapId, ushort chunkSize = 16)
|
||||
{
|
||||
return CreateGrid(GetMapEntityIdOrThrow(currentMapId), chunkSize, default);
|
||||
return CreateGrid(currentMapId, chunkSize, default);
|
||||
}
|
||||
|
||||
public MapGridComponent CreateGrid(MapId currentMapId, in GridCreateOptions options)
|
||||
{
|
||||
return CreateGrid(GetMapEntityIdOrThrow(currentMapId), options.ChunkSize, default);
|
||||
return CreateGrid(currentMapId, options.ChunkSize, default);
|
||||
}
|
||||
|
||||
public MapGridComponent CreateGrid(MapId currentMapId)
|
||||
@@ -29,19 +46,18 @@ internal partial class MapManager
|
||||
}
|
||||
|
||||
public Entity<MapGridComponent> CreateGridEntity(MapId currentMapId, GridCreateOptions? options = null)
|
||||
{
|
||||
return CreateGridEntity(GetMapEntityIdOrThrow(currentMapId), options);
|
||||
}
|
||||
|
||||
public Entity<MapGridComponent> CreateGridEntity(EntityUid map, GridCreateOptions? options = null)
|
||||
{
|
||||
options ??= GridCreateOptions.Default;
|
||||
return CreateGrid(map, options.Value.ChunkSize, default);
|
||||
return CreateGrid(currentMapId, options.Value.ChunkSize, default);
|
||||
}
|
||||
|
||||
[Obsolete("Use GetComponent<MapGridComponent>(uid)")]
|
||||
public MapGridComponent GetGrid(EntityUid gridId)
|
||||
=> EntityManager.GetComponent<MapGridComponent>(gridId);
|
||||
{
|
||||
DebugTools.Assert(gridId.IsValid());
|
||||
|
||||
return GetGridComp(gridId);
|
||||
}
|
||||
|
||||
[Obsolete("Use HasComponent<MapGridComponent>(uid)")]
|
||||
public bool IsGrid(EntityUid uid)
|
||||
@@ -92,6 +108,10 @@ internal partial class MapManager
|
||||
|
||||
public virtual void DeleteGrid(EntityUid euid)
|
||||
{
|
||||
#if DEBUG
|
||||
DebugTools.Assert(_dbgGuardRunning);
|
||||
#endif
|
||||
|
||||
// Possible the grid was already deleted / is invalid
|
||||
if (!EntityManager.TryGetComponent<MapGridComponent>(euid, out var iGrid))
|
||||
{
|
||||
@@ -121,6 +141,10 @@ internal partial class MapManager
|
||||
/// <param name="oldTile">The old tile that got replaced.</param>
|
||||
public void RaiseOnTileChanged(TileRef tileRef, Tile oldTile, Vector2i chunk)
|
||||
{
|
||||
#if DEBUG
|
||||
DebugTools.Assert(_dbgGuardRunning);
|
||||
#endif
|
||||
|
||||
if (SuppressOnTileChanged)
|
||||
return;
|
||||
|
||||
@@ -129,7 +153,7 @@ internal partial class MapManager
|
||||
EntityManager.EventBus.RaiseLocalEvent(euid, ref ev, true);
|
||||
}
|
||||
|
||||
protected Entity<MapGridComponent> CreateGrid(EntityUid map, ushort chunkSize, EntityUid forcedGridEuid)
|
||||
protected Entity<MapGridComponent> CreateGrid(MapId currentMapId, ushort chunkSize, EntityUid forcedGridEuid)
|
||||
{
|
||||
var gridEnt = EntityManager.CreateEntityUninitialized(null, forcedGridEuid);
|
||||
|
||||
@@ -142,7 +166,8 @@ internal partial class MapManager
|
||||
//are applied. After they are applied the parent may be different, but the MapId will
|
||||
//be the same. This causes TransformComponent.ParentUid of a grid to be unsafe to
|
||||
//use in transform states anytime before the state parent is properly set.
|
||||
EntityManager.GetComponent<TransformComponent>(gridEnt).AttachParent(map);
|
||||
var fallbackParentEuid = GetMapEntityIdOrThrow(currentMapId);
|
||||
EntityManager.GetComponent<TransformComponent>(gridEnt).AttachParent(fallbackParentEuid);
|
||||
|
||||
var meta = EntityManager.GetComponent<MetaDataComponent>(gridEnt);
|
||||
EntityManager.System<MetaDataSystem>().SetEntityName(gridEnt, $"grid", meta);
|
||||
|
||||
12
Robust.Shared/Map/MapManager.GridTrees.cs
Normal file
12
Robust.Shared/Map/MapManager.GridTrees.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
namespace Robust.Shared.Map;
|
||||
|
||||
internal partial class MapManager
|
||||
{
|
||||
public void RemoveMapId(MapId mapId)
|
||||
{
|
||||
if (mapId == MapId.Nullspace)
|
||||
return;
|
||||
|
||||
_mapEntities.Remove(mapId);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Map.Components;
|
||||
using Robust.Shared.Utility;
|
||||
@@ -28,42 +27,131 @@ public sealed class MapEventArgs : EventArgs
|
||||
|
||||
internal partial class MapManager
|
||||
{
|
||||
private Dictionary<MapId, EntityUid> _mapEntities => _mapSystem.Maps;
|
||||
private readonly Dictionary<MapId, EntityUid> _mapEntities = new();
|
||||
private MapId _highestMapId = MapId.Nullspace;
|
||||
|
||||
/// <inheritdoc />
|
||||
public virtual void DeleteMap(MapId mapId)
|
||||
{
|
||||
#if DEBUG
|
||||
DebugTools.Assert(_dbgGuardRunning);
|
||||
#endif
|
||||
|
||||
if (!_mapEntities.TryGetValue(mapId, out var ent) || !ent.IsValid())
|
||||
throw new InvalidOperationException($"Attempted to delete nonexistent map '{mapId}'");
|
||||
|
||||
EntityManager.DeleteEntity(ent);
|
||||
DebugTools.Assert(!_mapEntities.ContainsKey(mapId));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public MapId CreateMap(MapId? mapId = null)
|
||||
{
|
||||
if (mapId != null)
|
||||
{
|
||||
_mapSystem.CreateMap(mapId.Value);
|
||||
return mapId.Value;
|
||||
}
|
||||
|
||||
_mapSystem.CreateMap(out var map);
|
||||
return map;
|
||||
return ((IMapManagerInternal) this).CreateMap(mapId, default);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool MapExists([NotNullWhen(true)] MapId? mapId)
|
||||
public bool MapExists(MapId mapId)
|
||||
{
|
||||
return _mapSystem.MapExists(mapId);
|
||||
return _mapEntities.ContainsKey(mapId);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public EntityUid CreateNewMapEntity(MapId mapId)
|
||||
{
|
||||
DebugTools.Assert(mapId != MapId.Nullspace);
|
||||
#if DEBUG
|
||||
DebugTools.Assert(_dbgGuardRunning);
|
||||
#endif
|
||||
|
||||
var newEntity = EntityManager.CreateEntityUninitialized(null);
|
||||
SetMapEntity(mapId, newEntity);
|
||||
|
||||
EntityManager.InitializeComponents(newEntity);
|
||||
EntityManager.StartComponents(newEntity);
|
||||
|
||||
return newEntity;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void SetMapEntity(MapId mapId, EntityUid newMapEntity, bool updateChildren = true)
|
||||
{
|
||||
#if DEBUG
|
||||
DebugTools.Assert(_dbgGuardRunning);
|
||||
#endif
|
||||
|
||||
if (!_mapEntities.ContainsKey(mapId))
|
||||
throw new InvalidOperationException($"Map {mapId} does not exist.");
|
||||
|
||||
foreach (var kvEntity in _mapEntities)
|
||||
{
|
||||
if (kvEntity.Value == newMapEntity)
|
||||
{
|
||||
if (mapId == kvEntity.Key)
|
||||
return;
|
||||
|
||||
throw new InvalidOperationException(
|
||||
$"Entity {newMapEntity} is already the root node of another map {kvEntity.Key}.");
|
||||
}
|
||||
}
|
||||
|
||||
MapComponent? mapComp;
|
||||
// If this is being done as part of maploader then we want to copy the preinit state across mainly.
|
||||
bool preInit = false;
|
||||
bool paused = false;
|
||||
|
||||
// remove existing graph
|
||||
if (_mapEntities.TryGetValue(mapId, out var oldEntId))
|
||||
{
|
||||
if (EntityManager.TryGetComponent(oldEntId, out mapComp))
|
||||
{
|
||||
preInit = mapComp.MapPreInit;
|
||||
paused = mapComp.MapPaused;
|
||||
}
|
||||
|
||||
EntityManager.System<SharedTransformSystem>().ReparentChildren(oldEntId, newMapEntity);
|
||||
|
||||
//Note: EntityUid.Invalid gets passed in here
|
||||
//Note: This prevents setting a subgraph as the root, since the subgraph will be deleted
|
||||
EntityManager.DeleteEntity(oldEntId);
|
||||
}
|
||||
|
||||
var raiseEvent = false;
|
||||
|
||||
// re-use or add map component
|
||||
if (!EntityManager.TryGetComponent(newMapEntity, out mapComp))
|
||||
mapComp = EntityManager.AddComponent<MapComponent>(newMapEntity);
|
||||
else
|
||||
{
|
||||
raiseEvent = true;
|
||||
|
||||
if (mapComp.MapId != mapId)
|
||||
{
|
||||
_sawmill.Warning($"Setting map {mapId} root to entity {newMapEntity}, but entity thinks it is root node of map {mapComp.MapId}.");
|
||||
}
|
||||
}
|
||||
|
||||
_sawmill.Debug($"Setting map {mapId} entity to {newMapEntity}");
|
||||
|
||||
// set as new map entity
|
||||
mapComp.MapPreInit = preInit;
|
||||
mapComp.MapPaused = paused;
|
||||
|
||||
mapComp.MapId = mapId;
|
||||
_mapEntities[mapId] = newMapEntity;
|
||||
|
||||
// Yeah this sucks but I just want to save maps for now, deal.
|
||||
if (raiseEvent)
|
||||
{
|
||||
var ev = new MapChangedEvent(newMapEntity, mapId, true);
|
||||
EntityManager.EventBus.RaiseLocalEvent(newMapEntity, ev, true);
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public EntityUid GetMapEntityId(MapId mapId)
|
||||
{
|
||||
if (_mapSystem.TryGetMap(mapId, out var entId))
|
||||
return entId.Value;
|
||||
if (_mapEntities.TryGetValue(mapId, out var entId))
|
||||
return entId;
|
||||
|
||||
return EntityUid.Invalid;
|
||||
}
|
||||
@@ -73,12 +161,13 @@ internal partial class MapManager
|
||||
/// </summary>
|
||||
public EntityUid GetMapEntityIdOrThrow(MapId mapId)
|
||||
{
|
||||
return _mapSystem.GetMap(mapId);
|
||||
return _mapEntities[mapId];
|
||||
}
|
||||
|
||||
public bool TryGetMap([NotNullWhen(true)] MapId? mapId, [NotNullWhen(true)] out EntityUid? uid)
|
||||
/// <inheritdoc />
|
||||
public bool HasMapEntity(MapId mapId)
|
||||
{
|
||||
return _mapSystem.TryGetMap(mapId, out uid);
|
||||
return _mapEntities.ContainsKey(mapId);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -92,4 +181,67 @@ internal partial class MapManager
|
||||
{
|
||||
return EntityManager.HasComponent<MapComponent>(uid);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public MapId NextMapId()
|
||||
{
|
||||
return _highestMapId = new MapId(_highestMapId.Value + 1);
|
||||
}
|
||||
|
||||
MapId IMapManagerInternal.CreateMap(MapId? mapId, EntityUid entityUid)
|
||||
{
|
||||
if (mapId == MapId.Nullspace)
|
||||
throw new InvalidOperationException("Attempted to create a null-space map.");
|
||||
|
||||
#if DEBUG
|
||||
DebugTools.Assert(_dbgGuardRunning);
|
||||
#endif
|
||||
|
||||
var actualId = mapId ?? new MapId(_highestMapId.Value + 1);
|
||||
|
||||
if (MapExists(actualId))
|
||||
throw new InvalidOperationException($"A map with ID {actualId} already exists");
|
||||
|
||||
if (_highestMapId.Value < actualId.Value)
|
||||
_highestMapId = actualId;
|
||||
|
||||
_sawmill.Info($"Creating new map {actualId}");
|
||||
|
||||
if (actualId != MapId.Nullspace) // nullspace isn't bound to an entity
|
||||
{
|
||||
Entity<MapComponent> result = default;
|
||||
var query = EntityManager.AllEntityQueryEnumerator<MapComponent>();
|
||||
while (query.MoveNext(out var uid, out var map))
|
||||
{
|
||||
if (map.MapId != actualId)
|
||||
continue;
|
||||
|
||||
result = (uid, map);
|
||||
break;
|
||||
}
|
||||
|
||||
if (result != default)
|
||||
{
|
||||
DebugTools.Assert(mapId != null);
|
||||
_mapEntities.Add(actualId, result);
|
||||
_sawmill.Debug($"Rebinding map {actualId} to entity {result.Owner}");
|
||||
}
|
||||
else
|
||||
{
|
||||
var newEnt = EntityManager.CreateEntityUninitialized(null, entityUid);
|
||||
_mapEntities.Add(actualId, newEnt);
|
||||
|
||||
var mapComp = EntityManager.AddComponent<MapComponent>(newEnt);
|
||||
mapComp.MapId = actualId;
|
||||
var meta = EntityManager.GetComponent<MetaDataComponent>(newEnt);
|
||||
EntityManager.System<MetaDataSystem>().SetEntityName(newEnt, $"map {actualId}", meta);
|
||||
EntityManager.Dirty(newEnt, mapComp, meta);
|
||||
EntityManager.InitializeComponents(newEnt, meta);
|
||||
EntityManager.StartComponents(newEnt);
|
||||
_sawmill.Debug($"Binding map {actualId} to entity {newEnt}");
|
||||
}
|
||||
}
|
||||
|
||||
return actualId;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Map.Components;
|
||||
|
||||
@@ -7,44 +8,145 @@ namespace Robust.Shared.Map
|
||||
{
|
||||
internal partial class MapManager
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public void SetMapPaused(MapId mapId, bool paused)
|
||||
{
|
||||
_mapSystem.SetPaused(mapId, paused);
|
||||
if(mapId == MapId.Nullspace)
|
||||
return;
|
||||
|
||||
if(!MapExists(mapId))
|
||||
throw new ArgumentException("That map does not exist.");
|
||||
|
||||
var mapUid = GetMapEntityId(mapId);
|
||||
var mapComp = EntityManager.GetComponent<MapComponent>(mapUid);
|
||||
|
||||
if (mapComp.MapPaused == paused)
|
||||
return;
|
||||
|
||||
mapComp.MapPaused = paused;
|
||||
EntityManager.Dirty(mapUid, mapComp);
|
||||
|
||||
var xformQuery = EntityManager.GetEntityQuery<TransformComponent>();
|
||||
var metaQuery = EntityManager.GetEntityQuery<MetaDataComponent>();
|
||||
var metaSystem = EntityManager.EntitySysManager.GetEntitySystem<MetaDataSystem>();
|
||||
|
||||
RecursiveSetPaused(mapUid, paused, in xformQuery, in metaQuery, in metaSystem);
|
||||
}
|
||||
|
||||
public void SetMapPaused(EntityUid uid, bool paused)
|
||||
private static void RecursiveSetPaused(EntityUid entity, bool paused,
|
||||
in EntityQuery<TransformComponent> xformQuery,
|
||||
in EntityQuery<MetaDataComponent> metaQuery,
|
||||
in MetaDataSystem system)
|
||||
{
|
||||
_mapSystem.SetPaused(uid, paused);
|
||||
system.SetEntityPaused(entity, paused, metaQuery.GetComponent(entity));
|
||||
var xform = xformQuery.GetComponent(entity);
|
||||
foreach (var child in xform._children)
|
||||
{
|
||||
RecursiveSetPaused(child, paused, in xformQuery, in metaQuery, in system);
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void DoMapInitialize(MapId mapId)
|
||||
{
|
||||
_mapSystem.InitializeMap(mapId);
|
||||
if(!MapExists(mapId))
|
||||
throw new ArgumentException("That map does not exist.");
|
||||
|
||||
if (IsMapInitialized(mapId))
|
||||
throw new ArgumentException("That map is already initialized.");
|
||||
|
||||
var mapEnt = GetMapEntityId(mapId);
|
||||
var mapComp = EntityManager.GetComponent<MapComponent>(mapEnt);
|
||||
var xformQuery = EntityManager.GetEntityQuery<TransformComponent>();
|
||||
var metaQuery = EntityManager.GetEntityQuery<MetaDataComponent>();
|
||||
var metaSystem = EntityManager.EntitySysManager.GetEntitySystem<MetaDataSystem>();
|
||||
|
||||
mapComp.MapPreInit = false;
|
||||
mapComp.MapPaused = false;
|
||||
EntityManager.Dirty(mapEnt, mapComp);
|
||||
|
||||
RecursiveDoMapInit(mapEnt, in xformQuery, in metaQuery, in metaSystem);
|
||||
}
|
||||
|
||||
public bool IsMapInitialized(MapId mapId)
|
||||
private void RecursiveDoMapInit(EntityUid entity,
|
||||
in EntityQuery<TransformComponent> xformQuery,
|
||||
in EntityQuery<MetaDataComponent> metaQuery,
|
||||
in MetaDataSystem system)
|
||||
{
|
||||
return _mapSystem.IsInitialized(mapId);
|
||||
// RunMapInit can modify the TransformTree
|
||||
// ToArray caches deleted euids, we check here if they still exist.
|
||||
if(!metaQuery.TryGetComponent(entity, out var meta))
|
||||
return;
|
||||
|
||||
EntityManager.RunMapInit(entity, meta);
|
||||
system.SetEntityPaused(entity, false, meta);
|
||||
|
||||
foreach (var child in xformQuery.GetComponent(entity)._children.ToArray())
|
||||
{
|
||||
RecursiveDoMapInit(child, in xformQuery, in metaQuery, in system);
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void AddUninitializedMap(MapId mapId)
|
||||
{
|
||||
var ent = GetMapEntityId(mapId);
|
||||
EntityManager.GetComponent<MapComponent>(ent).MapInitialized = false;
|
||||
var meta = EntityManager.GetComponent<MetaDataComponent>(ent);
|
||||
((EntityManager)EntityManager).SetLifeStage(meta, EntityLifeStage.Initialized);
|
||||
SetMapPreInit(mapId);
|
||||
}
|
||||
|
||||
private bool CheckMapPause(MapId mapId)
|
||||
{
|
||||
if(mapId == MapId.Nullspace)
|
||||
return false;
|
||||
|
||||
var mapEuid = GetMapEntityId(mapId);
|
||||
|
||||
if (!EntityManager.TryGetComponent<MapComponent>(mapEuid, out var map))
|
||||
return false;
|
||||
|
||||
return map.MapPaused;
|
||||
}
|
||||
|
||||
private void SetMapPreInit(MapId mapId)
|
||||
{
|
||||
if(mapId == MapId.Nullspace)
|
||||
return;
|
||||
|
||||
var mapEuid = GetMapEntityId(mapId);
|
||||
var mapComp = EntityManager.GetComponent<MapComponent>(mapEuid);
|
||||
mapComp.MapPreInit = true;
|
||||
}
|
||||
|
||||
private bool CheckMapPreInit(MapId mapId)
|
||||
{
|
||||
if(mapId == MapId.Nullspace)
|
||||
return false;
|
||||
|
||||
var mapEuid = GetMapEntityId(mapId);
|
||||
|
||||
if (!EntityManager.TryGetComponent<MapComponent>(mapEuid, out var map))
|
||||
return false;
|
||||
|
||||
return map.MapPreInit;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool IsMapPaused(MapId mapId)
|
||||
{
|
||||
return _mapSystem.IsPaused(mapId);
|
||||
if(mapId == MapId.Nullspace)
|
||||
return false;
|
||||
|
||||
var mapEuid = GetMapEntityId(mapId);
|
||||
|
||||
if (!EntityManager.TryGetComponent<MapComponent>(mapEuid, out var map))
|
||||
return false;
|
||||
|
||||
return map.MapPaused || map.MapPreInit;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool IsMapPaused(EntityUid uid)
|
||||
public bool IsMapInitialized(MapId mapId)
|
||||
{
|
||||
return _mapSystem.IsPaused(uid);
|
||||
return !CheckMapPreInit(mapId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -3,9 +3,13 @@ using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Map.Components;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Physics.Collision;
|
||||
using Robust.Shared.Physics.Components;
|
||||
using Robust.Shared.Physics.Systems;
|
||||
using Robust.Shared.Timing;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Robust.Shared.Map;
|
||||
|
||||
@@ -19,36 +23,60 @@ internal partial class MapManager : IMapManagerInternal, IEntityEventSubscriber
|
||||
|
||||
[Dependency] private readonly IConsoleHost _conhost = default!;
|
||||
|
||||
private ISawmill _sawmill => _mapSystem.Log;
|
||||
private ISawmill _sawmill = default!;
|
||||
|
||||
private FixtureSystem _fixtureSystem = default!;
|
||||
private SharedMapSystem _mapSystem = default!;
|
||||
private SharedPhysicsSystem _physics = default!;
|
||||
private SharedTransformSystem _transformSystem = default!;
|
||||
|
||||
private EntityQuery<FixturesComponent> _fixturesQuery;
|
||||
private EntityQuery<GridTreeComponent> _gridTreeQuery;
|
||||
private EntityQuery<MapGridComponent> _gridQuery;
|
||||
private EntityQuery<PhysicsComponent> _physicsQuery;
|
||||
private EntityQuery<TransformComponent> _xformQuery;
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Initialize()
|
||||
{
|
||||
_fixturesQuery = EntityManager.GetEntityQuery<FixturesComponent>();
|
||||
_gridTreeQuery = EntityManager.GetEntityQuery<GridTreeComponent>();
|
||||
_gridQuery = EntityManager.GetEntityQuery<MapGridComponent>();
|
||||
_physicsQuery = EntityManager.GetEntityQuery<PhysicsComponent>();
|
||||
_xformQuery = EntityManager.GetEntityQuery<TransformComponent>();
|
||||
|
||||
_sawmill = Logger.GetSawmill("map");
|
||||
|
||||
#if DEBUG
|
||||
DebugTools.Assert(!_dbgGuardInit);
|
||||
DebugTools.Assert(!_dbgGuardRunning);
|
||||
_dbgGuardInit = true;
|
||||
#endif
|
||||
InitializeMapPausing();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Startup()
|
||||
{
|
||||
_fixtureSystem = EntityManager.System<FixtureSystem>();
|
||||
_physics = EntityManager.System<SharedPhysicsSystem>();
|
||||
_transformSystem = EntityManager.System<SharedTransformSystem>();
|
||||
_mapSystem = EntityManager.System<SharedMapSystem>();
|
||||
|
||||
#if DEBUG
|
||||
DebugTools.Assert(_dbgGuardInit);
|
||||
_dbgGuardRunning = true;
|
||||
#endif
|
||||
|
||||
_sawmill.Debug("Starting...");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Shutdown()
|
||||
{
|
||||
#if DEBUG
|
||||
DebugTools.Assert(_dbgGuardInit);
|
||||
#endif
|
||||
_sawmill.Debug("Stopping...");
|
||||
|
||||
// TODO: AllEntityQuery instead???
|
||||
@@ -74,4 +102,9 @@ internal partial class MapManager : IMapManagerInternal, IEntityEventSubscriber
|
||||
EntityManager.DeleteEntity(uid);
|
||||
}
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
private bool _dbgGuardInit;
|
||||
private bool _dbgGuardRunning;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -313,60 +313,55 @@ public partial class SharedPhysicsSystem
|
||||
Dirty(uid, body);
|
||||
}
|
||||
|
||||
public bool SetAngularVelocity(EntityUid uid, float value, bool dirty = true, FixturesComponent? manager = null, PhysicsComponent? body = null)
|
||||
public void SetAngularVelocity(EntityUid uid, float value, bool dirty = true, FixturesComponent? manager = null, PhysicsComponent? body = null)
|
||||
{
|
||||
if (!Resolve(uid, ref body))
|
||||
return false;
|
||||
return;
|
||||
|
||||
if (body.BodyType == BodyType.Static)
|
||||
return false;
|
||||
return;
|
||||
|
||||
if (value * value > 0.0f)
|
||||
{
|
||||
if (!WakeBody(uid, manager: manager, body: body))
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
|
||||
// CloseToPercent tolerance needs to be small enough such that an angular velocity just above
|
||||
// sleep-tolerance can damp down to sleeping.
|
||||
|
||||
if (MathHelper.CloseToPercent(body.AngularVelocity, value, 0.00001f))
|
||||
return false;
|
||||
return;
|
||||
|
||||
body.AngularVelocity = value;
|
||||
|
||||
if (dirty)
|
||||
Dirty(uid, body);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attempts to set the body to collidable, wake it, then move it.
|
||||
/// </summary>
|
||||
public bool SetLinearVelocity(EntityUid uid, Vector2 velocity, bool dirty = true, bool wakeBody = true, FixturesComponent? manager = null, PhysicsComponent? body = null)
|
||||
public void SetLinearVelocity(EntityUid uid, Vector2 velocity, bool dirty = true, bool wakeBody = true, FixturesComponent? manager = null, PhysicsComponent? body = null)
|
||||
{
|
||||
if (!Resolve(uid, ref body))
|
||||
return false;
|
||||
return;
|
||||
|
||||
if (body.BodyType == BodyType.Static)
|
||||
return false;
|
||||
if (body.BodyType == BodyType.Static) return;
|
||||
|
||||
if (wakeBody && Vector2.Dot(velocity, velocity) > 0.0f)
|
||||
{
|
||||
if (!WakeBody(uid, manager: manager, body: body))
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (body.LinearVelocity.EqualsApprox(velocity, 0.0000001f))
|
||||
return false;
|
||||
return;
|
||||
|
||||
body.LinearVelocity = velocity;
|
||||
|
||||
if (dirty)
|
||||
Dirty(uid, body);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void SetAngularDamping(EntityUid uid, PhysicsComponent body, float value, bool dirty = true)
|
||||
|
||||
@@ -660,11 +660,13 @@ public abstract partial class SharedPhysicsSystem
|
||||
});
|
||||
|
||||
// Update data sequentially
|
||||
var metaQuery = GetEntityQuery<MetaDataComponent>();
|
||||
|
||||
for (var i = 0; i < actualIslands.Length; i++)
|
||||
{
|
||||
var island = actualIslands[i];
|
||||
|
||||
UpdateBodies(in island, solvedPositions, solvedAngles, linearVelocities, angularVelocities, xformQuery);
|
||||
UpdateBodies(in island, solvedPositions, solvedAngles, linearVelocities, angularVelocities, xformQuery, metaQuery);
|
||||
SleepBodies(in island, sleepStatus);
|
||||
}
|
||||
|
||||
@@ -999,7 +1001,8 @@ public abstract partial class SharedPhysicsSystem
|
||||
float[] angles,
|
||||
Vector2[] linearVelocities,
|
||||
float[] angularVelocities,
|
||||
EntityQuery<TransformComponent> xformQuery)
|
||||
EntityQuery<TransformComponent> xformQuery,
|
||||
EntityQuery<MetaDataComponent> metaQuery)
|
||||
{
|
||||
foreach (var (joint, error) in island.BrokenJoints)
|
||||
{
|
||||
@@ -1032,22 +1035,21 @@ public abstract partial class SharedPhysicsSystem
|
||||
}
|
||||
|
||||
var linVelocity = linearVelocities[offset + i];
|
||||
var physicsDirtied = false;
|
||||
|
||||
if (!float.IsNaN(linVelocity.X) && !float.IsNaN(linVelocity.Y))
|
||||
{
|
||||
physicsDirtied |= SetLinearVelocity(uid, linVelocity, false, body: body);
|
||||
SetLinearVelocity(uid, linVelocity, false, body: body);
|
||||
}
|
||||
|
||||
var angVelocity = angularVelocities[offset + i];
|
||||
|
||||
if (!float.IsNaN(angVelocity))
|
||||
{
|
||||
physicsDirtied |= SetAngularVelocity(uid, angVelocity, false, body: body);
|
||||
SetAngularVelocity(uid, angVelocity, false, body: body);
|
||||
}
|
||||
|
||||
if (physicsDirtied)
|
||||
Dirty(uid, body);
|
||||
// TODO: Should check if the values update.
|
||||
Dirty(uid, body, metaQuery.GetComponent(uid));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ namespace Robust.Shared.Prototypes;
|
||||
/// Prototype that represents game entities.
|
||||
/// </summary>
|
||||
[Prototype("entityCategory")]
|
||||
public sealed partial class EntityCategoryPrototype : IPrototype
|
||||
public sealed class EntityCategoryPrototype : IPrototype
|
||||
{
|
||||
[IdDataField]
|
||||
public string ID { get; private set; } = default!;
|
||||
@@ -22,4 +22,4 @@ public sealed partial class EntityCategoryPrototype : IPrototype
|
||||
/// </summary>
|
||||
[DataField("description")]
|
||||
public string? Description { get; private set; }
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,6 @@ using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
using Robust.Shared.Random;
|
||||
using Robust.Shared.Reflection;
|
||||
using Robust.Shared.Serialization.Manager;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.Serialization.Markdown;
|
||||
@@ -273,8 +272,7 @@ public interface IPrototypeManager
|
||||
out Dictionary<Type, HashSet<string>> prototypes);
|
||||
|
||||
/// <summary>
|
||||
/// This method uses reflection to validate that all static prototype id fields correspond to valid prototypes.
|
||||
/// This will validate all known to <see cref="IReflectionManager"/>
|
||||
/// This method uses reflection to validate that prototype id fields correspond to valid prototypes.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This will validate any field that has either a <see cref="ValidatePrototypeIdAttribute{T}"/> attribute, or a
|
||||
@@ -282,12 +280,7 @@ public interface IPrototypeManager
|
||||
/// </remarks>
|
||||
/// <param name="prototypes">A collection prototypes to use for validation. Any prototype not in this collection
|
||||
/// will be considered invalid.</param>
|
||||
List<string> ValidateStaticFields(Dictionary<Type, HashSet<string>> prototypes);
|
||||
|
||||
/// <summary>
|
||||
/// This is a variant of <see cref="ValidateStaticFields(System.Collections.Generic.Dictionary{System.Type,System.Collections.Generic.HashSet{string}})"/> that only validates a single type.
|
||||
/// </summary>
|
||||
List<string> ValidateStaticFields(Type type, Dictionary<Type, HashSet<string>> prototypes);
|
||||
List<string> ValidateFields(Dictionary<Type, HashSet<string>> prototypes);
|
||||
|
||||
/// <summary>
|
||||
/// This method will serialize all loaded prototypes into yaml and then validate them. This can be used to ensure
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||
using Robust.Shared.Utility;
|
||||
using BindingFlags = System.Reflection.BindingFlags;
|
||||
|
||||
@@ -12,41 +13,35 @@ namespace Robust.Shared.Prototypes;
|
||||
public partial class PrototypeManager
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public List<string> ValidateStaticFields(Dictionary<Type, HashSet<string>> prototypes)
|
||||
public List<string> ValidateFields(Dictionary<Type, HashSet<string>> prototypes)
|
||||
{
|
||||
var errors = new List<string>();
|
||||
foreach (var type in _reflectionManager.FindAllTypes())
|
||||
{
|
||||
// TODO validate public static fields on abstract classes that have no implementations?
|
||||
if (!type.IsAbstract)
|
||||
ValidateStaticFieldsInternal(type, errors, prototypes);
|
||||
ValidateType(type, errors, prototypes);
|
||||
}
|
||||
|
||||
return errors;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public List<string> ValidateStaticFields(Type type, Dictionary<Type, HashSet<string>> prototypes)
|
||||
{
|
||||
var errors = new List<string>();
|
||||
ValidateStaticFieldsInternal(type, errors, prototypes);
|
||||
return errors;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validate all static fields defined on this type and all base types.
|
||||
/// Validate all fields defined on this type and all base types.
|
||||
/// </summary>
|
||||
private void ValidateStaticFieldsInternal(Type type, List<string> errors, Dictionary<Type, HashSet<string>> prototypes)
|
||||
private void ValidateType(Type type, List<string> errors, Dictionary<Type, HashSet<string>> prototypes)
|
||||
{
|
||||
var baseType = type;
|
||||
var flags = BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.DeclaredOnly;
|
||||
object? instance = null;
|
||||
Type? baseType = type;
|
||||
|
||||
var flags = BindingFlags.Static | BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public |
|
||||
BindingFlags.DeclaredOnly;
|
||||
|
||||
while (baseType != null)
|
||||
{
|
||||
foreach (var field in baseType.GetFields(flags))
|
||||
{
|
||||
DebugTools.Assert(field.IsStatic);
|
||||
ValidateStaticField(field, type, errors, prototypes);
|
||||
ValidateField(field, type, ref instance, errors, prototypes);
|
||||
}
|
||||
|
||||
// We need to get the fields on the base type separately in order to get the private fields
|
||||
@@ -54,110 +49,92 @@ public partial class PrototypeManager
|
||||
}
|
||||
}
|
||||
|
||||
private void ValidateStaticField(
|
||||
private void ValidateField(
|
||||
FieldInfo field,
|
||||
Type type,
|
||||
ref object? instance,
|
||||
List<string> errors,
|
||||
Dictionary<Type, HashSet<string>> prototypes)
|
||||
{
|
||||
DebugTools.Assert(field.IsStatic);
|
||||
DebugTools.Assert(!field.HasCustomAttribute<DataFieldAttribute>(), "Datafields should not be static");
|
||||
|
||||
// Is this even a prototype id related field?
|
||||
if (!TryGetFieldPrototype(field, out var proto))
|
||||
if (!TryGetFieldPrototype(field, out var proto, out var canBeNull, out var canBeEmpty))
|
||||
return;
|
||||
|
||||
if (!prototypes.TryGetValue(proto, out var validIds))
|
||||
if (!TryGetFieldValue(field, type, ref instance, errors, out var value))
|
||||
return;
|
||||
|
||||
var id = value?.ToString();
|
||||
|
||||
if (id == null)
|
||||
{
|
||||
errors.Add($"Prototype id field failed validation. Unknown prototype kind {proto.Name}. Field: {field.Name} in {type.FullName}");
|
||||
if (!canBeNull)
|
||||
errors.Add($"Prototype id field failed validation. Fields should not be null. Field: {field.Name} in {type.FullName}");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!TryGetIds(field, proto, out var ids))
|
||||
if (string.IsNullOrWhiteSpace(id))
|
||||
{
|
||||
TryGetIds(field, proto, out _);
|
||||
DebugTools.Assert($"Failed to get ids, despite resolving the field into a prototype kind?");
|
||||
if (!canBeEmpty)
|
||||
errors.Add($"Prototype id field failed validation. Non-optional non-nullable data-fields must have a default value. Field: {field.Name} in {type.FullName}");
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var id in ids)
|
||||
if (!prototypes.TryGetValue(proto, out var ids))
|
||||
{
|
||||
if (!validIds.Contains(id))
|
||||
errors.Add($"Prototype id field failed validation. Unknown prototype: {id} of type {proto.Name}. Field: {field.Name} in {type.FullName}");
|
||||
errors.Add($"Prototype id field failed validation. Unknown prototype kind. Field: {field.Name} in {type.FullName}");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!ids.Contains(id))
|
||||
{
|
||||
errors.Add($"Prototype id field failed validation. Unknown prototype: {id}. Field: {field.Name} in {type.FullName}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Extract prototype ids from a string, IEnumerable{string}, EntProtoId, IEnumerable{EntProtoId}, ProtoId{T}, or IEnumerable{ProtoId{T}} field.
|
||||
/// Get the value of some field. If this is not a static field, this will create instance of the object in order to
|
||||
/// validate default field values.
|
||||
/// </summary>
|
||||
private bool TryGetIds(FieldInfo field, Type proto, [NotNullWhen(true)] out string[]? ids)
|
||||
private bool TryGetFieldValue(FieldInfo field, Type type, ref object? instance, List<string> errors, out object? value)
|
||||
{
|
||||
ids = null;
|
||||
var value = field.GetValue(null);
|
||||
if (value == null)
|
||||
value = null;
|
||||
|
||||
if (field.IsStatic || instance != null)
|
||||
{
|
||||
value = field.GetValue(instance);
|
||||
return true;
|
||||
}
|
||||
|
||||
var constructor = type.GetConstructor(
|
||||
BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance,
|
||||
Type.EmptyTypes);
|
||||
|
||||
// TODO handle parameterless record constructors.
|
||||
// Figure out how ISerializationManager does it, or just re-use that code somehow.
|
||||
// In the meantime, record data fields need an explicit parameterless ctor.
|
||||
|
||||
if (constructor == null)
|
||||
{
|
||||
errors.Add($"Prototype id field failed validation. Could not create instance to validate default value. Field: {field.Name} in {type.FullName}");
|
||||
return false;
|
||||
|
||||
if (value is string str)
|
||||
{
|
||||
ids = [str];
|
||||
return true;
|
||||
}
|
||||
|
||||
if (value is IEnumerable<string> strEnum)
|
||||
{
|
||||
ids = strEnum.ToArray();
|
||||
return true;
|
||||
}
|
||||
instance = constructor.Invoke(Array.Empty<object>());
|
||||
value = field.GetValue(instance);
|
||||
|
||||
if (value is EntProtoId protoId)
|
||||
{
|
||||
ids = [protoId];
|
||||
return true;
|
||||
}
|
||||
|
||||
if (value is IEnumerable<EntProtoId> protoIdEnum)
|
||||
{
|
||||
ids = protoIdEnum.Select(x=> x.Id).ToArray();
|
||||
return true;
|
||||
}
|
||||
|
||||
if (field.FieldType.IsGenericType && field.FieldType.GetGenericTypeDefinition() == typeof(ProtoId<>))
|
||||
{
|
||||
ids = [value.ToString()!];
|
||||
return true;
|
||||
}
|
||||
|
||||
foreach (var iface in field.FieldType.GetInterfaces())
|
||||
{
|
||||
if (!iface.IsGenericType)
|
||||
continue;
|
||||
|
||||
if (iface.GetGenericTypeDefinition() != typeof(IEnumerable<>))
|
||||
continue;
|
||||
|
||||
var enumType = iface.GetGenericArguments().Single();
|
||||
if (!enumType.IsGenericType)
|
||||
continue;
|
||||
|
||||
if (enumType.GetGenericTypeDefinition() != typeof(ProtoId<>))
|
||||
continue;
|
||||
|
||||
ids = GetIdsMethod.MakeGenericMethod(proto).Invoke(null, [value]) as string[];
|
||||
return ids != null;
|
||||
}
|
||||
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
private static MethodInfo GetIdsMethod = typeof(PrototypeManager).GetMethod(nameof(GetIds), BindingFlags.NonPublic | BindingFlags.Static)!;
|
||||
private static string[] GetIds<T>(IEnumerable<ProtoId<T>> enumerable) where T : class, IPrototype
|
||||
private bool TryGetFieldPrototype(
|
||||
FieldInfo field,
|
||||
[NotNullWhen(true)] out Type? proto,
|
||||
out bool canBeNull,
|
||||
out bool canBeEmpty)
|
||||
{
|
||||
return enumerable.Select(x => x.Id).ToArray();
|
||||
}
|
||||
proto = null;
|
||||
canBeNull = false;
|
||||
canBeEmpty = false;
|
||||
|
||||
private bool TryGetFieldPrototype(FieldInfo field, [NotNullWhen(true)] out Type? proto)
|
||||
{
|
||||
// Validate anything with the attribute
|
||||
var attrib = field.GetCustomAttribute(typeof(ValidatePrototypeIdAttribute<>), false);
|
||||
if (attrib != null)
|
||||
{
|
||||
@@ -165,40 +142,46 @@ public partial class PrototypeManager
|
||||
return true;
|
||||
}
|
||||
|
||||
if (TryGetPrototypeFromType(field.FieldType, out proto))
|
||||
return true;
|
||||
if (!field.TryGetCustomAttribute(out DataFieldAttribute? dataField))
|
||||
return false;
|
||||
|
||||
// Allow validating arrays or lists.
|
||||
foreach (var iface in field.FieldType.GetInterfaces().Where(x => x.IsGenericType))
|
||||
var fieldType = field.FieldType;
|
||||
canBeEmpty = dataField.Required;
|
||||
DebugTools.Assert(!field.IsStatic);
|
||||
|
||||
// Resolve nullable structs
|
||||
if (fieldType.IsGenericType && fieldType.GetGenericTypeDefinition() == typeof(Nullable<>))
|
||||
{
|
||||
if (iface.GetGenericTypeDefinition() != typeof(IEnumerable<>))
|
||||
continue;
|
||||
|
||||
var enumType = iface.GetGenericArguments().Single();
|
||||
if (TryGetPrototypeFromType(enumType, out proto))
|
||||
return true;
|
||||
fieldType = fieldType.GetGenericArguments().Single();
|
||||
canBeNull = true;
|
||||
}
|
||||
|
||||
proto = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool TryGetPrototypeFromType(Type type, [NotNullWhen(true)] out Type? proto)
|
||||
{
|
||||
if (type == typeof(EntProtoId))
|
||||
if (fieldType == typeof(EntProtoId))
|
||||
{
|
||||
proto = typeof(EntityPrototype);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(ProtoId<>))
|
||||
if (fieldType.IsGenericType && field.FieldType.GetGenericTypeDefinition() == typeof(ProtoId<>))
|
||||
{
|
||||
proto = type.GetGenericArguments().Single();
|
||||
DebugTools.Assert(proto != typeof(EntityPrototype), "Use EntProtoId instead of ProtoId<EntityPrototype>");
|
||||
proto = field.FieldType.GetGenericArguments().Single();
|
||||
return true;
|
||||
}
|
||||
|
||||
proto = null;
|
||||
return false;
|
||||
// As far as I know there is no way to check for the nullability of a string field, so we will assume that null
|
||||
// values imply that the field itself is properly marked as nullable.
|
||||
canBeNull = true;
|
||||
|
||||
if (dataField.CustomTypeSerializer == null)
|
||||
return false;
|
||||
|
||||
if (!dataField.CustomTypeSerializer.IsGenericType)
|
||||
return false;
|
||||
|
||||
if (dataField.CustomTypeSerializer.GetGenericTypeDefinition() != typeof(PrototypeIdSerializer<>))
|
||||
return false;
|
||||
|
||||
proto = dataField.CustomTypeSerializer.GetGenericArguments().First();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ public partial class PrototypeManager
|
||||
var mapping = node.ToDataNodeCast<MappingDataNode>();
|
||||
var id = mapping.Get<ValueDataNode>("id").Value;
|
||||
|
||||
var data = new PrototypeValidationData(id, mapping, resourcePath.ToString());
|
||||
var data = new PrototypeValidationData(mapping, resourcePath.ToString());
|
||||
mapping.Remove("type");
|
||||
|
||||
if (prototypes.GetOrNew(type).TryAdd(id, data))
|
||||
@@ -65,14 +65,10 @@ public partial class PrototypeManager
|
||||
}
|
||||
}
|
||||
|
||||
var ctx = new YamlValidationContext();
|
||||
var errors = new List<ErrorNode>();
|
||||
foreach (var (type, instances) in prototypes)
|
||||
{
|
||||
var defaultErrorOccurred = false;
|
||||
foreach (var (id, data) in instances)
|
||||
foreach (var data in instances.Values)
|
||||
{
|
||||
errors.Clear();
|
||||
EnsurePushed(data, instances, type);
|
||||
if (data.Mapping.TryGet("abstract", out ValueDataNode? abstractNode)
|
||||
&& bool.Parse(abstractNode.Value))
|
||||
@@ -80,25 +76,9 @@ public partial class PrototypeManager
|
||||
continue;
|
||||
}
|
||||
|
||||
// Validate yaml directly
|
||||
errors.AddRange(_serializationManager.ValidateNode(type, data.Mapping).GetErrors());
|
||||
if (errors.Count > 0)
|
||||
dict.GetOrNew(data.File).UnionWith(errors);
|
||||
|
||||
// Create instance & re-serialize it, to validate the default values of data-fields. We still validate
|
||||
// the yaml directly just in case reading & writing the fields somehow modifies their values.
|
||||
try
|
||||
{
|
||||
var instance = _serializationManager.Read(type, data.Mapping, ctx);
|
||||
var mapping = _serializationManager.WriteValue(type, instance, alwaysWrite: true, ctx);
|
||||
errors.AddRange(_serializationManager.ValidateNode(type, mapping, ctx).GetErrors());
|
||||
if (errors.Count > 0)
|
||||
dict.GetOrNew(data.File).UnionWith(errors);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
errors.Add(new ErrorNode(new ValueDataNode(), $"Caught Exception while validating {type} prototype {id}. Exception: {ex}"));
|
||||
}
|
||||
var result = _serializationManager.ValidateNode(type, data.Mapping).GetErrors().ToHashSet();
|
||||
if (result.Count > 0)
|
||||
dict.GetOrNew(data.File).UnionWith(result);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -172,17 +152,12 @@ public partial class PrototypeManager
|
||||
|
||||
private sealed class PrototypeValidationData
|
||||
{
|
||||
public readonly string Id;
|
||||
public MappingDataNode Mapping;
|
||||
public readonly string File;
|
||||
public bool Pushed;
|
||||
|
||||
public string[]? Parents;
|
||||
public MappingDataNode[]? ParentMappings;
|
||||
|
||||
public PrototypeValidationData(string id, MappingDataNode mapping, string file)
|
||||
public PrototypeValidationData(MappingDataNode mapping, string file)
|
||||
{
|
||||
Id = id;
|
||||
File = file;
|
||||
Mapping = mapping;
|
||||
}
|
||||
@@ -201,22 +176,23 @@ public partial class PrototypeManager
|
||||
if (!data.Mapping.TryGet(ParentDataFieldAttribute.Name, out var parentNode))
|
||||
return;
|
||||
|
||||
DebugTools.AssertNull(data.Parents);
|
||||
DebugTools.AssertNull(data.ParentMappings);
|
||||
data.Parents = _serializationManager.Read<string[]>(parentNode, notNullableOverride: true);
|
||||
data.ParentMappings = new MappingDataNode[data.Parents.Length];
|
||||
var parents = _serializationManager.Read<string[]>(parentNode, notNullableOverride: true);
|
||||
var parentNodes = new MappingDataNode[parents.Length];
|
||||
|
||||
var i = 0;
|
||||
foreach (var parentId in data.Parents)
|
||||
foreach (var parentId in parents)
|
||||
{
|
||||
var parent = prototypes[parentId];
|
||||
EnsurePushed(parent, prototypes, type);
|
||||
data.ParentMappings[i++] = parent.Mapping;
|
||||
|
||||
for (var i = 0; i < parents.Length; i++)
|
||||
{
|
||||
parentNodes[i] = parent.Mapping;
|
||||
}
|
||||
}
|
||||
|
||||
data.Mapping = _serializationManager.PushCompositionWithGenericNode(
|
||||
type,
|
||||
data.ParentMappings,
|
||||
parentNodes,
|
||||
data.Mapping);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace Robust.Shared.Prototypes;
|
||||
/// Tile alias prototypes, unlike tile prototypes, are implemented here, as they're really just fed to TileDefinitionManager.
|
||||
/// </summary>
|
||||
[Prototype("tileAlias")]
|
||||
public sealed partial class TileAliasPrototype : IPrototype
|
||||
public sealed class TileAliasPrototype : IPrototype
|
||||
{
|
||||
/// <summary>
|
||||
/// The target tile ID to alias to.
|
||||
|
||||
@@ -1,62 +0,0 @@
|
||||
using System.Globalization;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.Manager;
|
||||
using Robust.Shared.Serialization.Markdown;
|
||||
using Robust.Shared.Serialization.Markdown.Validation;
|
||||
using Robust.Shared.Serialization.Markdown.Value;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Interfaces;
|
||||
|
||||
namespace Robust.Shared.Prototypes;
|
||||
|
||||
internal sealed class YamlValidationContext : ISerializationContext, ITypeSerializer<EntityUid, ValueDataNode>
|
||||
{
|
||||
public SerializationManager.SerializerProvider SerializerProvider { get; } = new();
|
||||
public bool WritingReadingPrototypes => true;
|
||||
|
||||
public YamlValidationContext()
|
||||
{
|
||||
SerializerProvider.RegisterSerializer(this);
|
||||
}
|
||||
|
||||
ValidationNode ITypeValidator<EntityUid, ValueDataNode>.Validate(ISerializationManager serializationManager,
|
||||
ValueDataNode node, IDependencyCollection dependencies, ISerializationContext? context)
|
||||
{
|
||||
if (node.Value == "null" || node.Value == "invalid")
|
||||
return new ValidatedValueNode(node);
|
||||
|
||||
return new ErrorNode(node, "Prototypes should not contain EntityUids", true);
|
||||
}
|
||||
|
||||
public DataNode Write(ISerializationManager serializationManager, EntityUid value,
|
||||
IDependencyCollection dependencies, bool alwaysWrite = false,
|
||||
ISerializationContext? context = null)
|
||||
{
|
||||
if (!value.Valid)
|
||||
return new ValueDataNode("invalid");
|
||||
|
||||
return new ValueDataNode(value.Id.ToString(CultureInfo.InvariantCulture));
|
||||
}
|
||||
|
||||
EntityUid ITypeReader<EntityUid, ValueDataNode>.Read(ISerializationManager serializationManager,
|
||||
ValueDataNode node,
|
||||
IDependencyCollection dependencies,
|
||||
SerializationHookContext hookCtx,
|
||||
ISerializationContext? context, ISerializationManager.InstantiationDelegate<EntityUid>? _)
|
||||
{
|
||||
if (node.Value == "invalid")
|
||||
return EntityUid.Invalid;
|
||||
|
||||
return EntityUid.Parse(node.Value);
|
||||
}
|
||||
|
||||
[MustUseReturnValue]
|
||||
public EntityUid Copy(ISerializationManager serializationManager, EntityUid source, EntityUid target,
|
||||
bool skipHook,
|
||||
ISerializationContext? context = null)
|
||||
{
|
||||
return new((int)source);
|
||||
}
|
||||
}
|
||||
@@ -4,9 +4,8 @@ using Robust.Shared.Prototypes;
|
||||
namespace Robust.Shared.Serialization.Manager.Attributes;
|
||||
|
||||
/// <summary>
|
||||
/// This attribute should be used on static string or string collection fields to validate that they correspond to
|
||||
/// valid YAML prototype ids. This attribute is not required for static <see cref="ProtoId{T}"/> and
|
||||
/// <see cref="EntProtoId"/> fields, as they automatically get validated.
|
||||
/// This attribute should be used on string fields to validate that they correspond to a valid YAML prototype id.
|
||||
/// If the field needs to be have a default value.
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Field)]
|
||||
public sealed class ValidatePrototypeIdAttribute<T> : Attribute where T : IPrototype
|
||||
|
||||
@@ -143,7 +143,7 @@ namespace Robust.Shared.Serialization.Manager.Definition
|
||||
nodeVariable),
|
||||
call,
|
||||
dfa.Required
|
||||
? ExpressionUtils.ThrowExpression<RequiredFieldNotMappedException>(fieldDefinition.FieldType, tagConst, typeof(T))
|
||||
? ExpressionUtils.ThrowExpression<RequiredFieldNotMappedException>(fieldDefinition.FieldType, tagConst)
|
||||
: AssignIfNotDefaultExpression(i, targetParam, Expression.Constant(DefaultValues[i], fieldDefinition.FieldType))
|
||||
)));
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ namespace Robust.Shared.Serialization.Manager.Exceptions;
|
||||
|
||||
public sealed class RequiredFieldNotMappedException : Exception
|
||||
{
|
||||
public RequiredFieldNotMappedException(Type type, string field, Type dataDef) : base($"Required field {field} of type {type} in {dataDef} wasn't mapped.")
|
||||
public RequiredFieldNotMappedException(Type type, string field) : base($"Required field {field} of type {type} wasn't mapped.")
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Pro
|
||||
|
||||
/// <summary>
|
||||
/// Checks that a string corresponds to a valid prototype id. Note that any data fields using this serializer will
|
||||
/// also be validated by <see cref="IPrototypeManager.ValidateStaticFields"/>
|
||||
/// also be validated by <see cref="IPrototypeManager.ValidateFields"/>
|
||||
/// </summary>
|
||||
[Virtual]
|
||||
public class PrototypeIdSerializer<TPrototype> : ITypeValidator<string, ValueDataNode> where TPrototype : class, IPrototype
|
||||
|
||||
@@ -13,18 +13,22 @@ namespace Robust.UnitTesting.Client.GameObjects.Components
|
||||
[TestOf(typeof(TransformComponent))]
|
||||
public sealed class TransformComponentTests
|
||||
{
|
||||
private static readonly MapId TestMapId = new(1);
|
||||
|
||||
private static (ISimulation, EntityUid gridA, EntityUid gridB) SimulationFactory()
|
||||
{
|
||||
var sim = RobustServerSimulation
|
||||
.NewSimulation()
|
||||
.InitializeInstance();
|
||||
|
||||
var mapId = sim.Resolve<IEntityManager>().System<SharedMapSystem>().CreateMap();
|
||||
var mapManager = sim.Resolve<IMapManager>();
|
||||
|
||||
// Adds the map with id 1, and spawns entity 1 as the map entity.
|
||||
mapManager.CreateMap(TestMapId);
|
||||
|
||||
// Adds two grids to use in tests.
|
||||
var gridA = mapManager.CreateGridEntity(mapId);
|
||||
var gridB = mapManager.CreateGridEntity(mapId);
|
||||
var gridA = mapManager.CreateGridEntity(TestMapId);
|
||||
var gridB = mapManager.CreateGridEntity(TestMapId);
|
||||
|
||||
return (sim, gridA, gridB);
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ public sealed partial class ComponentMapInitTest
|
||||
var sim = simFactory.InitializeInstance();
|
||||
var entManager = sim.Resolve<IEntityManager>();
|
||||
var mapManager = sim.Resolve<IMapManager>();
|
||||
sim.Resolve<IEntityManager>().System<SharedMapSystem>().CreateMap(out var mapId);
|
||||
var mapId = mapManager.CreateMap();
|
||||
|
||||
var ent = entManager.SpawnEntity(null, new MapCoordinates(Vector2.Zero, mapId));
|
||||
Assert.That(entManager.GetComponent<MetaDataComponent>(ent).EntityLifeStage, Is.EqualTo(EntityLifeStage.MapInitialized));
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using NUnit.Framework;
|
||||
using Robust.Server.Containers;
|
||||
using Robust.Shared.Containers;
|
||||
@@ -18,15 +19,14 @@ namespace Robust.UnitTesting.Server.GameObjects.Components
|
||||
[TestFixture, Parallelizable]
|
||||
public sealed partial class ContainerTest
|
||||
{
|
||||
private static EntityCoordinates _coords;
|
||||
|
||||
private static ISimulation SimulationFactory()
|
||||
{
|
||||
var sim = RobustServerSimulation
|
||||
.NewSimulation()
|
||||
.InitializeInstance();
|
||||
var map = sim.CreateMap();
|
||||
_coords = new EntityCoordinates(map.Item1, default);
|
||||
|
||||
// Adds the map with id 1, and spawns entity 1 as the map entity.
|
||||
sim.AddMap(1);
|
||||
|
||||
return sim;
|
||||
}
|
||||
@@ -37,7 +37,8 @@ namespace Robust.UnitTesting.Server.GameObjects.Components
|
||||
var sim = SimulationFactory();
|
||||
var entManager = sim.Resolve<IEntityManager>();
|
||||
var containerSys = sim.Resolve<IEntitySystemManager>().GetEntitySystem<ContainerSystem>();
|
||||
var entity = sim.SpawnEntity(null,_coords);
|
||||
|
||||
var entity = sim.SpawnEntity(null, new EntityCoordinates(EntityUid.FirstUid, new Vector2(0, 0)));
|
||||
|
||||
var container = containerSys.MakeContainer<Container>(entity, "dummy");
|
||||
|
||||
@@ -73,8 +74,9 @@ namespace Robust.UnitTesting.Server.GameObjects.Components
|
||||
var sim = SimulationFactory();
|
||||
var entManager = sim.Resolve<IEntityManager>();
|
||||
var containerSys = sim.Resolve<IEntitySystemManager>().GetEntitySystem<ContainerSystem>();
|
||||
var owner = sim.SpawnEntity(null,_coords);
|
||||
var inserted = sim.SpawnEntity(null,_coords);
|
||||
|
||||
var owner = sim.SpawnEntity(null, new EntityCoordinates(EntityUid.FirstUid, new Vector2(0, 0)));
|
||||
var inserted = sim.SpawnEntity(null, new EntityCoordinates(EntityUid.FirstUid, new Vector2(0, 0)));
|
||||
var transform = entManager.GetComponent<TransformComponent>(inserted);
|
||||
|
||||
var container = containerSys.MakeContainer<Container>(owner, "dummy");
|
||||
@@ -102,10 +104,11 @@ namespace Robust.UnitTesting.Server.GameObjects.Components
|
||||
var sim = SimulationFactory();
|
||||
var entManager = sim.Resolve<IEntityManager>();
|
||||
var containerSys = sim.Resolve<IEntitySystemManager>().GetEntitySystem<ContainerSystem>();
|
||||
var owner = sim.SpawnEntity(null,_coords);
|
||||
var inserted = sim.SpawnEntity(null,_coords);
|
||||
|
||||
var owner = sim.SpawnEntity(null, new EntityCoordinates(EntityUid.FirstUid, new Vector2(0, 0)));
|
||||
var inserted = sim.SpawnEntity(null, new EntityCoordinates(EntityUid.FirstUid, new Vector2(0, 0)));
|
||||
var transform = entManager.GetComponent<TransformComponent>(inserted);
|
||||
var entity = sim.SpawnEntity(null,_coords);
|
||||
var entity = sim.SpawnEntity(null, new EntityCoordinates(EntityUid.FirstUid, new Vector2(0, 0)));
|
||||
|
||||
var container = containerSys.MakeContainer<Container>(owner, "dummy");
|
||||
Assert.That(containerSys.Insert(inserted, container), Is.True);
|
||||
@@ -129,7 +132,8 @@ namespace Robust.UnitTesting.Server.GameObjects.Components
|
||||
var sim = SimulationFactory();
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
var containerSys = sim.Resolve<IEntitySystemManager>().GetEntitySystem<ContainerSystem>();
|
||||
var coordinates =_coords;
|
||||
|
||||
var coordinates = new EntityCoordinates(EntityUid.FirstUid, new Vector2(0, 0));
|
||||
var entityOne = sim.SpawnEntity(null, coordinates);
|
||||
var entityTwo = sim.SpawnEntity(null, coordinates);
|
||||
var entityThree = sim.SpawnEntity(null, coordinates);
|
||||
@@ -161,7 +165,8 @@ namespace Robust.UnitTesting.Server.GameObjects.Components
|
||||
{
|
||||
var sim = SimulationFactory();
|
||||
var containerSys = sim.Resolve<IEntitySystemManager>().GetEntitySystem<ContainerSystem>();
|
||||
var entity = sim.SpawnEntity(null,_coords);
|
||||
|
||||
var entity = sim.SpawnEntity(null, new EntityCoordinates(EntityUid.FirstUid, new Vector2(0, 0)));
|
||||
var container = containerSys.MakeContainer<Container>(entity, "dummy");
|
||||
|
||||
Assert.That(containerSys.Insert(entity, container), Is.False);
|
||||
@@ -173,8 +178,9 @@ namespace Robust.UnitTesting.Server.GameObjects.Components
|
||||
{
|
||||
var sim = SimulationFactory();
|
||||
var containerSys = sim.Resolve<IEntitySystemManager>().GetEntitySystem<ContainerSystem>();
|
||||
var mapEnt = new EntityUid(1);
|
||||
var entity = sim.SpawnEntity(null,_coords);
|
||||
|
||||
var mapEnt = EntityUid.FirstUid;
|
||||
var entity = sim.SpawnEntity(null, new EntityCoordinates(EntityUid.FirstUid, new Vector2(0, 0)));
|
||||
var container = containerSys.MakeContainer<Container>(entity, "dummy");
|
||||
|
||||
Assert.That(containerSys.Insert(mapEnt, container), Is.False);
|
||||
@@ -188,7 +194,7 @@ namespace Robust.UnitTesting.Server.GameObjects.Components
|
||||
var containerSys = sim.Resolve<IEntitySystemManager>().GetEntitySystem<ContainerSystem>();
|
||||
|
||||
var grid = sim.Resolve<IMapManager>().CreateGridEntity(new MapId(1)).Owner;
|
||||
var entity = sim.SpawnEntity(null,_coords);
|
||||
var entity = sim.SpawnEntity(null, new EntityCoordinates(EntityUid.FirstUid, new Vector2(0, 0)));
|
||||
var container = containerSys.MakeContainer<Container>(entity, "dummy");
|
||||
|
||||
Assert.That(containerSys.Insert(grid, container), Is.False);
|
||||
@@ -201,9 +207,10 @@ namespace Robust.UnitTesting.Server.GameObjects.Components
|
||||
var sim = SimulationFactory();
|
||||
var entManager = sim.Resolve<IEntityManager>();
|
||||
var containerSys = sim.Resolve<IEntitySystemManager>().GetEntitySystem<ContainerSystem>();
|
||||
var containerEntity = sim.SpawnEntity(null,_coords);
|
||||
|
||||
var containerEntity = sim.SpawnEntity(null, new EntityCoordinates(EntityUid.FirstUid, new Vector2(0, 0)));
|
||||
var container = containerSys.MakeContainer<Container>(containerEntity, "dummy");
|
||||
var insertEntity = sim.SpawnEntity(null,_coords);
|
||||
var insertEntity = sim.SpawnEntity(null, new EntityCoordinates(EntityUid.FirstUid, new Vector2(0, 0)));
|
||||
|
||||
var result = containerSys.Insert(insertEntity, container);
|
||||
|
||||
@@ -223,9 +230,10 @@ namespace Robust.UnitTesting.Server.GameObjects.Components
|
||||
{
|
||||
var sim = SimulationFactory();
|
||||
var containerSys = sim.Resolve<IEntitySystemManager>().GetEntitySystem<ContainerSystem>();
|
||||
var containerEntity = sim.SpawnEntity(null,_coords);
|
||||
|
||||
var containerEntity = sim.SpawnEntity(null, new EntityCoordinates(EntityUid.FirstUid, new Vector2(0, 0)));
|
||||
var container = containerSys.MakeContainer<Container>(containerEntity, "dummy");
|
||||
var insertEntity = sim.SpawnEntity(null,_coords);
|
||||
var insertEntity = sim.SpawnEntity(null, new EntityCoordinates(EntityUid.FirstUid, new Vector2(0, 0)));
|
||||
|
||||
var result = containerSys.Remove(insertEntity, container);
|
||||
|
||||
@@ -237,11 +245,12 @@ namespace Robust.UnitTesting.Server.GameObjects.Components
|
||||
{
|
||||
var sim = SimulationFactory();
|
||||
var containerSys = sim.Resolve<IEntitySystemManager>().GetEntitySystem<ContainerSystem>();
|
||||
var entity1 = sim.SpawnEntity(null,_coords);
|
||||
|
||||
var entity1 = sim.SpawnEntity(null, new EntityCoordinates(EntityUid.FirstUid, new Vector2(0, 0)));
|
||||
var container1 = containerSys.MakeContainer<Container>(entity1, "dummy");
|
||||
var entity2 = sim.SpawnEntity(null,_coords);
|
||||
var entity2 = sim.SpawnEntity(null, new EntityCoordinates(EntityUid.FirstUid, new Vector2(0, 0)));
|
||||
var container2 = containerSys.MakeContainer<Container>(entity2, "dummy");
|
||||
var transferEntity = sim.SpawnEntity(null,_coords);
|
||||
var transferEntity = sim.SpawnEntity(null, new EntityCoordinates(EntityUid.FirstUid, new Vector2(0, 0)));
|
||||
containerSys.Insert(transferEntity, container1);
|
||||
|
||||
var result = containerSys.Insert(transferEntity, container2);
|
||||
@@ -257,9 +266,10 @@ namespace Robust.UnitTesting.Server.GameObjects.Components
|
||||
var sim = SimulationFactory();
|
||||
var entManager = sim.Resolve<IEntityManager>();
|
||||
var containerSys = entManager.System<ContainerSystem>();
|
||||
var entity = sim.SpawnEntity(null,_coords);
|
||||
|
||||
var entity = sim.SpawnEntity(null, new EntityCoordinates(EntityUid.FirstUid, new Vector2(0, 0)));
|
||||
var container = containerSys.MakeContainer<Container>(entity, "dummy");
|
||||
var childEnt = sim.SpawnEntity(null,_coords);
|
||||
var childEnt = sim.SpawnEntity(null, new EntityCoordinates(EntityUid.FirstUid, new Vector2(0, 0)));
|
||||
|
||||
container.OccludesLight = true;
|
||||
container.ShowContents = true;
|
||||
|
||||
@@ -20,9 +20,12 @@ public sealed class TransformIntegration_Test
|
||||
var sim = factory.InitializeInstance();
|
||||
|
||||
var entManager = sim.Resolve<IEntityManager>();
|
||||
var mapManager = sim.Resolve<IMapManager>();
|
||||
var containerSystem = entManager.System<SharedContainerSystem>();
|
||||
var xformSystem = entManager.System<SharedTransformSystem>();
|
||||
var map1 = sim.CreateMap().Uid;
|
||||
|
||||
var map1Id = mapManager.CreateMap();
|
||||
var map1 = mapManager.GetMapEntityId(map1Id);
|
||||
|
||||
var ent1 = entManager.SpawnEntity(null, new EntityCoordinates(map1, Vector2.Zero));
|
||||
var ent2 = entManager.SpawnEntity(null, new EntityCoordinates(map1, Vector2.Zero));
|
||||
|
||||
@@ -49,6 +49,7 @@ namespace Robust.UnitTesting.Server.GameObjects.Components
|
||||
|
||||
EntityManager = IoCManager.Resolve<IServerEntityManagerInternal>();
|
||||
MapManager = IoCManager.Resolve<IMapManager>();
|
||||
MapManager.CreateMap();
|
||||
|
||||
IoCManager.Resolve<ISerializationManager>().Initialize();
|
||||
var manager = IoCManager.Resolve<IPrototypeManager>();
|
||||
@@ -56,12 +57,11 @@ namespace Robust.UnitTesting.Server.GameObjects.Components
|
||||
manager.LoadFromStream(new StringReader(Prototypes));
|
||||
manager.ResolveResults();
|
||||
|
||||
var mapSys = EntityManager.System<SharedMapSystem>();
|
||||
// build the net dream
|
||||
mapSys.CreateMap(out MapA);
|
||||
mapSys.CreateMap(out MapB);
|
||||
|
||||
MapA = MapManager.CreateMap();
|
||||
GridA = MapManager.CreateGridEntity(MapA);
|
||||
|
||||
MapB = MapManager.CreateMap();
|
||||
GridB = MapManager.CreateGridEntity(MapB);
|
||||
|
||||
//NOTE: The grids have not moved, so we can assert worldpos == localpos for the test
|
||||
|
||||
@@ -37,6 +37,8 @@ namespace Robust.UnitTesting.Server.GameObjects
|
||||
.RegisterEntitySystems(f => f.LoadExtraSystemType<DebugExceptionSystem>())
|
||||
.RegisterPrototypes(protoMan => protoMan.LoadString(PROTOTYPES))
|
||||
.InitializeInstance();
|
||||
|
||||
_sim.AddMap(1);
|
||||
}
|
||||
|
||||
[TestCase("throwInAdd")]
|
||||
@@ -45,9 +47,8 @@ namespace Robust.UnitTesting.Server.GameObjects
|
||||
public void Test(string prototypeName)
|
||||
{
|
||||
var entMan = _sim.Resolve<IEntityManager>();
|
||||
_sim.Resolve<IEntityManager>().System<SharedMapSystem>().CreateMap(out var map);
|
||||
|
||||
Assert.That(() => entMan.SpawnEntity(prototypeName, new MapCoordinates(0, 0, map)),
|
||||
Assert.That(() => entMan.SpawnEntity(prototypeName, new MapCoordinates(0, 0, new MapId(1))),
|
||||
Throws.TypeOf<EntityCreationException>());
|
||||
|
||||
Assert.That(entMan.GetEntities().Where(p => entMan.GetComponent<MetaDataComponent>(p).EntityPrototype?.ID == prototypeName), Is.Empty);
|
||||
|
||||
@@ -75,7 +75,8 @@ public sealed class DefaultEntityTest : RobustIntegrationTest
|
||||
EntityCoordinates coords = default!;
|
||||
await server.WaitPost(() =>
|
||||
{
|
||||
var map = server.System<SharedMapSystem>().CreateMap();
|
||||
var mapId = mapMan.CreateMap();
|
||||
var map = mapMan.GetMapEntityId(mapId);
|
||||
coords = new(map, default);
|
||||
var playerUid = sEntMan.SpawnEntity(null, coords);
|
||||
player = sEntMan.GetNetEntity(playerUid);
|
||||
|
||||
@@ -71,13 +71,15 @@ public sealed class MissingParentTest : RobustIntegrationTest
|
||||
}
|
||||
|
||||
// Set up map and spawn player
|
||||
EntityUid map = default;
|
||||
NetEntity player = default;
|
||||
NetEntity entity = default;
|
||||
EntityCoordinates coords = default;
|
||||
NetCoordinates nCoords = default;
|
||||
await server.WaitPost(() =>
|
||||
{
|
||||
var map = server.System<SharedMapSystem>().CreateMap();
|
||||
var mapId = mapMan.CreateMap();
|
||||
map = mapMan.GetMapEntityId(mapId);
|
||||
coords = new(map, default);
|
||||
|
||||
var playerUid = sEntMan.SpawnEntity(null, coords);
|
||||
|
||||
@@ -69,11 +69,14 @@ public sealed class PvsChunkTest : RobustIntegrationTest
|
||||
EntityCoordinates mapCoords = default;
|
||||
await server.WaitPost(() =>
|
||||
{
|
||||
map1 = server.System<SharedMapSystem>().CreateMap();
|
||||
var mapId = mapMan.CreateMap();
|
||||
map1 = mapMan.GetMapEntityId(mapId);
|
||||
mapCoords = new(map1, default);
|
||||
|
||||
map2 = server.System<SharedMapSystem>().CreateMap();
|
||||
var gridComp = mapMan.CreateGridEntity(map2);
|
||||
var map2Id = mapMan.CreateMap();
|
||||
map2 = mapMan.GetMapEntityId(map2Id);
|
||||
|
||||
var gridComp = mapMan.CreateGridEntity(map2Id);
|
||||
grid = gridComp.Owner;
|
||||
mapSys.SetTile(grid, gridComp, Vector2i.Zero, new Tile(1));
|
||||
var gridCoords = new EntityCoordinates(grid, .5f, .5f);
|
||||
|
||||
@@ -74,7 +74,8 @@ public sealed class PvsReEntryTest : RobustIntegrationTest
|
||||
EntityCoordinates coords = default;
|
||||
await server.WaitPost(() =>
|
||||
{
|
||||
map = server.System<SharedMapSystem>().CreateMap();
|
||||
var mapId = mapMan.CreateMap();
|
||||
map = mapMan.GetMapEntityId(mapId);
|
||||
coords = new(map, default);
|
||||
|
||||
var playerUid = sEntMan.SpawnEntity(null, coords);
|
||||
|
||||
@@ -50,7 +50,8 @@ public sealed class PvsSystemTests : RobustIntegrationTest
|
||||
EntityUid map = default;
|
||||
await server.WaitPost(() =>
|
||||
{
|
||||
map = server.System<SharedMapSystem>().CreateMap(out var mapId);
|
||||
var mapId = mapMan.CreateMap();
|
||||
map = mapMan.GetMapEntityId(mapId);
|
||||
var gridComp = mapMan.CreateGridEntity(mapId);
|
||||
gridComp.Comp.SetTile(Vector2i.Zero, new Tile(1));
|
||||
grid = gridComp.Owner;
|
||||
|
||||
@@ -11,7 +11,6 @@ using Robust.Shared.Physics.Dynamics;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization.Manager;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Robust.UnitTesting.Server.Maps
|
||||
{
|
||||
@@ -79,10 +78,15 @@ entities:
|
||||
public void TestDataLoadPriority()
|
||||
{
|
||||
// TODO: Fix after serv3
|
||||
// fix what?
|
||||
var map = IoCManager.Resolve<IMapManager>();
|
||||
|
||||
var entMan = IoCManager.Resolve<IEntityManager>();
|
||||
entMan.System<SharedMapSystem>().CreateMap(out var mapId);
|
||||
|
||||
var mapId = map.CreateMap();
|
||||
// Yay test bullshit
|
||||
var mapUid = map.GetMapEntityId(mapId);
|
||||
entMan.EnsureComponent<PhysicsMapComponent>(mapUid);
|
||||
entMan.EnsureComponent<BroadphaseComponent>(mapUid);
|
||||
|
||||
var traversal = entMan.System<SharedGridTraversalSystem>();
|
||||
traversal.Enabled = false;
|
||||
|
||||
@@ -71,7 +71,8 @@ namespace Robust.UnitTesting.Server
|
||||
/// <summary>
|
||||
/// Adds a new map directly to the map manager.
|
||||
/// </summary>
|
||||
(EntityUid Uid, MapId MapId) CreateMap();
|
||||
EntityUid AddMap(int mapId);
|
||||
EntityUid AddMap(MapId mapId);
|
||||
EntityUid SpawnEntity(string? protoId, EntityCoordinates coordinates);
|
||||
EntityUid SpawnEntity(string? protoId, MapCoordinates coordinates);
|
||||
}
|
||||
@@ -98,10 +99,18 @@ namespace Robust.UnitTesting.Server
|
||||
return Collection.Resolve<T>();
|
||||
}
|
||||
|
||||
public (EntityUid Uid, MapId MapId) CreateMap()
|
||||
public EntityUid AddMap(int mapId)
|
||||
{
|
||||
var uid = Collection.Resolve<IEntityManager>().System<SharedMapSystem>().CreateMap(out var mapId);
|
||||
return (uid, mapId);
|
||||
var mapMan = Collection.Resolve<IMapManager>();
|
||||
mapMan.CreateMap(new MapId(mapId));
|
||||
return mapMan.GetMapEntityId(new MapId(mapId));
|
||||
}
|
||||
|
||||
public EntityUid AddMap(MapId mapId)
|
||||
{
|
||||
var mapMan = Collection.Resolve<IMapManager>();
|
||||
mapMan.CreateMap(mapId);
|
||||
return mapMan.GetMapEntityId(mapId);
|
||||
}
|
||||
|
||||
public EntityUid SpawnEntity(string? protoId, EntityCoordinates coordinates)
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace Robust.UnitTesting.Shared
|
||||
var entManager = server.Resolve<IEntityManager>();
|
||||
var mapManager = server.Resolve<IMapManager>();
|
||||
|
||||
var mapId = server.CreateMap().MapId;
|
||||
var mapId = mapManager.CreateMap();
|
||||
|
||||
var theMapSpotBeingUsed = new Box2(Vector2.Zero, Vector2.One);
|
||||
|
||||
@@ -43,7 +43,7 @@ namespace Robust.UnitTesting.Shared
|
||||
var entManager = server.Resolve<IEntityManager>();
|
||||
var mapManager = server.Resolve<IMapManager>();
|
||||
|
||||
var mapId = server.CreateMap().MapId;
|
||||
var mapId = mapManager.CreateMap();
|
||||
var grid = mapManager.CreateGridEntity(mapId);
|
||||
|
||||
var theMapSpotBeingUsed = new Box2(Vector2.Zero, Vector2.One);
|
||||
|
||||
@@ -62,7 +62,7 @@ namespace Robust.UnitTesting.Shared.GameObjects
|
||||
|
||||
await server.WaitAssertion(() =>
|
||||
{
|
||||
sEntManager.System<SharedMapSystem>().CreateMap(out mapId);
|
||||
mapId = sMapManager.CreateMap();
|
||||
mapPos = new MapCoordinates(new Vector2(0, 0), mapId);
|
||||
|
||||
entityUid = sEntManager.SpawnEntity(null, mapPos);
|
||||
@@ -190,7 +190,7 @@ namespace Robust.UnitTesting.Shared.GameObjects
|
||||
|
||||
await server.WaitAssertion(() =>
|
||||
{
|
||||
sEntManager.System<SharedMapSystem>().CreateMap(out mapId);
|
||||
mapId = sMapManager.CreateMap();
|
||||
mapPos = new MapCoordinates(new Vector2(0, 0), mapId);
|
||||
|
||||
sEntityUid = sEntManager.SpawnEntity(null, mapPos);
|
||||
@@ -300,7 +300,7 @@ namespace Robust.UnitTesting.Shared.GameObjects
|
||||
await server.WaitAssertion(() =>
|
||||
{
|
||||
// build the map
|
||||
sEntManager.System<SharedMapSystem>().CreateMap(out var mapIdOne);
|
||||
var mapIdOne = mapManager.CreateMap();
|
||||
Assert.That(mapManager.IsMapInitialized(mapIdOne), Is.True);
|
||||
|
||||
var containerEnt = sEntManager.SpawnEntity(null, new MapCoordinates(1, 1, mapIdOne));
|
||||
@@ -327,7 +327,7 @@ namespace Robust.UnitTesting.Shared.GameObjects
|
||||
await server.WaitAssertion(() =>
|
||||
{
|
||||
var mapLoader = sEntManager.System<MapLoaderSystem>();
|
||||
sEntManager.System<SharedMapSystem>().CreateMap(out var mapIdTwo);
|
||||
var mapIdTwo = mapManager.CreateMap();
|
||||
|
||||
// load the map
|
||||
mapLoader.Load(mapIdTwo, "container_test.yml");
|
||||
|
||||
@@ -30,7 +30,8 @@ public sealed partial class EntityEventBusTests
|
||||
.RegisterComponents(factory => factory.RegisterClass<FooComponent>())
|
||||
.InitializeInstance();
|
||||
|
||||
var map = simulation.CreateMap().MapId;
|
||||
var map = new MapId(1);
|
||||
simulation.AddMap(map);
|
||||
|
||||
var entity = simulation.SpawnEntity(null, new MapCoordinates(0, 0, map));
|
||||
simulation.Resolve<IEntityManager>().AddComponent<FooComponent>(entity);
|
||||
|
||||
@@ -20,7 +20,9 @@ namespace Robust.UnitTesting.Shared.GameObjects
|
||||
.RegisterEntitySystems(factory => factory.LoadExtraSystemType<SubscribeCompRefDirectedEventSystem>())
|
||||
.InitializeInstance();
|
||||
|
||||
var map = simulation.CreateMap().MapId;
|
||||
var map = new MapId(1);
|
||||
simulation.AddMap(map);
|
||||
|
||||
var entity = simulation.SpawnEntity(null, new MapCoordinates(0, 0, map));
|
||||
IoCManager.Resolve<IEntityManager>().AddComponent<DummyComponent>(entity);
|
||||
|
||||
@@ -84,7 +86,9 @@ namespace Robust.UnitTesting.Shared.GameObjects
|
||||
})
|
||||
.InitializeInstance();
|
||||
|
||||
var map = simulation.CreateMap().MapId;
|
||||
var map = new MapId(1);
|
||||
simulation.AddMap(map);
|
||||
|
||||
var entity = simulation.SpawnEntity(null, new MapCoordinates(0, 0, map));
|
||||
IoCManager.Resolve<IEntityManager>().AddComponent<OrderAComponent>(entity);
|
||||
IoCManager.Resolve<IEntityManager>().AddComponent<OrderBComponent>(entity);
|
||||
|
||||
@@ -16,6 +16,8 @@ namespace Robust.UnitTesting.Shared.GameObjects
|
||||
[TestFixture, Parallelizable ,TestOf(typeof(EntityManager))]
|
||||
public sealed partial class EntityManager_Components_Tests
|
||||
{
|
||||
private static readonly EntityCoordinates DefaultCoords = new(EntityUid.FirstUid, Vector2.Zero);
|
||||
|
||||
private const string DummyLoad = @"
|
||||
- type: entity
|
||||
id: DummyLoad
|
||||
@@ -33,12 +35,12 @@ namespace Robust.UnitTesting.Shared.GameObjects
|
||||
.RegisterPrototypes(fac => fac.LoadString(DummyLoad))
|
||||
.InitializeInstance();
|
||||
|
||||
sim.AddMap(1);
|
||||
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
var protoManager = sim.Resolve<IPrototypeManager>();
|
||||
|
||||
var map = sim.CreateMap().Uid;
|
||||
var coords = new EntityCoordinates(map, default);
|
||||
var entity = entMan.SpawnEntity(null, coords);
|
||||
var entity = entMan.SpawnEntity(null, DefaultCoords);
|
||||
Assert.That(!entMan.HasComponent<PhysicsComponent>(entity));
|
||||
var proto = protoManager.Index<EntityPrototype>("DummyLoad");
|
||||
|
||||
@@ -58,12 +60,12 @@ namespace Robust.UnitTesting.Shared.GameObjects
|
||||
.RegisterPrototypes(fac => fac.LoadString(DummyLoad))
|
||||
.InitializeInstance();
|
||||
|
||||
sim.AddMap(1);
|
||||
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
var protoManager = sim.Resolve<IPrototypeManager>();
|
||||
|
||||
var map = sim.CreateMap().Uid;
|
||||
var coords = new EntityCoordinates(map, default);
|
||||
var entity = entMan.SpawnEntity("DummyLoad", coords);
|
||||
var entity = entMan.SpawnEntity("DummyLoad", DefaultCoords);
|
||||
var proto = protoManager.Index<EntityPrototype>("DummyLoad");
|
||||
|
||||
entMan.RemoveComponents(entity, proto);
|
||||
@@ -78,9 +80,9 @@ namespace Robust.UnitTesting.Shared.GameObjects
|
||||
public void AddComponentTest()
|
||||
{
|
||||
// Arrange
|
||||
var (sim, coords) = SimulationFactory();
|
||||
var sim = SimulationFactory();
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
var entity = entMan.SpawnEntity(null, coords);
|
||||
var entity = entMan.SpawnEntity(null, DefaultCoords);
|
||||
var component = new DummyComponent()
|
||||
{
|
||||
Owner = entity
|
||||
@@ -98,9 +100,9 @@ namespace Robust.UnitTesting.Shared.GameObjects
|
||||
public void AddComponentOverwriteTest()
|
||||
{
|
||||
// Arrange
|
||||
var (sim, coords) = SimulationFactory();
|
||||
var sim = SimulationFactory();
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
var entity = entMan.SpawnEntity(null, coords);
|
||||
var entity = entMan.SpawnEntity(null, DefaultCoords);
|
||||
var component = new DummyComponent()
|
||||
{
|
||||
Owner = entity
|
||||
@@ -118,9 +120,9 @@ namespace Robust.UnitTesting.Shared.GameObjects
|
||||
public void AddComponent_ExistingDeleted()
|
||||
{
|
||||
// Arrange
|
||||
var (sim, coords) = SimulationFactory();
|
||||
var sim = SimulationFactory();
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
var entity = entMan.SpawnEntity(null, coords);
|
||||
var entity = entMan.SpawnEntity(null, DefaultCoords);
|
||||
var firstComp = new DummyComponent {Owner = entity};
|
||||
entMan.AddComponent(entity, firstComp);
|
||||
entMan.RemoveComponent<DummyComponent>(entity);
|
||||
@@ -138,9 +140,9 @@ namespace Robust.UnitTesting.Shared.GameObjects
|
||||
public void HasComponentTest()
|
||||
{
|
||||
// Arrange
|
||||
var (sim, coords) = SimulationFactory();
|
||||
var sim = SimulationFactory();
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
var entity = entMan.SpawnEntity(null, coords);
|
||||
var entity = entMan.SpawnEntity(null, DefaultCoords);
|
||||
entMan.AddComponent<DummyComponent>(entity);
|
||||
|
||||
// Act
|
||||
@@ -154,9 +156,9 @@ namespace Robust.UnitTesting.Shared.GameObjects
|
||||
public void HasComponentNoGenericTest()
|
||||
{
|
||||
// Arrange
|
||||
var (sim, coords) = SimulationFactory();
|
||||
var sim = SimulationFactory();
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
var entity = entMan.SpawnEntity(null, coords);
|
||||
var entity = entMan.SpawnEntity(null, DefaultCoords);
|
||||
entMan.AddComponent<DummyComponent>(entity);
|
||||
|
||||
// Act
|
||||
@@ -170,13 +172,13 @@ namespace Robust.UnitTesting.Shared.GameObjects
|
||||
public void HasNetComponentTest()
|
||||
{
|
||||
// Arrange
|
||||
var (sim, coords) = SimulationFactory();
|
||||
var sim = SimulationFactory();
|
||||
|
||||
var factory = sim.Resolve<IComponentFactory>();
|
||||
var netId = factory.GetRegistration<DummyComponent>().NetID!;
|
||||
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
var entity = entMan.SpawnEntity(null, coords);
|
||||
var entity = entMan.SpawnEntity(null, DefaultCoords);
|
||||
entMan.AddComponent<DummyComponent>(entity);
|
||||
|
||||
// Act
|
||||
@@ -190,13 +192,13 @@ namespace Robust.UnitTesting.Shared.GameObjects
|
||||
public void GetNetComponentTest()
|
||||
{
|
||||
// Arrange
|
||||
var (sim, coords) = SimulationFactory();
|
||||
var sim = SimulationFactory();
|
||||
|
||||
var factory = sim.Resolve<IComponentFactory>();
|
||||
var netId = factory.GetRegistration<DummyComponent>().NetID!;
|
||||
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
var entity = entMan.SpawnEntity(null, coords);
|
||||
var entity = entMan.SpawnEntity(null, DefaultCoords);
|
||||
var component = entMan.AddComponent<DummyComponent>(entity);
|
||||
|
||||
// Act
|
||||
@@ -210,9 +212,9 @@ namespace Robust.UnitTesting.Shared.GameObjects
|
||||
public void TryGetComponentTest()
|
||||
{
|
||||
// Arrange
|
||||
var (sim, coords) = SimulationFactory();
|
||||
var sim = SimulationFactory();
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
var entity = entMan.SpawnEntity(null, coords);
|
||||
var entity = entMan.SpawnEntity(null, DefaultCoords);
|
||||
var component = entMan.AddComponent<DummyComponent>(entity);
|
||||
|
||||
// Act
|
||||
@@ -227,13 +229,13 @@ namespace Robust.UnitTesting.Shared.GameObjects
|
||||
public void TryGetNetComponentTest()
|
||||
{
|
||||
// Arrange
|
||||
var (sim, coords) = SimulationFactory();
|
||||
var sim = SimulationFactory();
|
||||
|
||||
var factory = sim.Resolve<IComponentFactory>();
|
||||
var netId = factory.GetRegistration<DummyComponent>().NetID!;
|
||||
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
var entity = entMan.SpawnEntity(null, coords);
|
||||
var entity = entMan.SpawnEntity(null, DefaultCoords);
|
||||
var component = entMan.AddComponent<DummyComponent>(entity);
|
||||
|
||||
// Act
|
||||
@@ -248,9 +250,9 @@ namespace Robust.UnitTesting.Shared.GameObjects
|
||||
public void RemoveComponentTest()
|
||||
{
|
||||
// Arrange
|
||||
var (sim, coords) = SimulationFactory();
|
||||
var sim = SimulationFactory();
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
var entity = entMan.SpawnEntity(null, coords);
|
||||
var entity = entMan.SpawnEntity(null, DefaultCoords);
|
||||
var component = entMan.AddComponent<DummyComponent>(entity);
|
||||
|
||||
// Act
|
||||
@@ -264,9 +266,9 @@ namespace Robust.UnitTesting.Shared.GameObjects
|
||||
[Test]
|
||||
public void EnsureQueuedComponentDeletion()
|
||||
{
|
||||
var (sim, coords) = SimulationFactory();
|
||||
var sim = SimulationFactory();
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
var entity = entMan.SpawnEntity(null, coords);
|
||||
var entity = entMan.SpawnEntity(null, DefaultCoords);
|
||||
var component = entMan.AddComponent<DummyComponent>(entity);
|
||||
|
||||
Assert.That(component.LifeStage, Is.LessThanOrEqualTo(ComponentLifeStage.Running));
|
||||
@@ -282,13 +284,13 @@ namespace Robust.UnitTesting.Shared.GameObjects
|
||||
public void RemoveNetComponentTest()
|
||||
{
|
||||
// Arrange
|
||||
var (sim, coords) = SimulationFactory();
|
||||
var sim = SimulationFactory();
|
||||
|
||||
var factory = sim.Resolve<IComponentFactory>();
|
||||
var netId = factory.GetRegistration<DummyComponent>().NetID!;
|
||||
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
var entity = entMan.SpawnEntity(null, coords);
|
||||
var entity = entMan.SpawnEntity(null, DefaultCoords);
|
||||
var component = entMan.AddComponent<DummyComponent>(entity);
|
||||
|
||||
// Act
|
||||
@@ -303,9 +305,9 @@ namespace Robust.UnitTesting.Shared.GameObjects
|
||||
public void GetComponentsTest()
|
||||
{
|
||||
// Arrange
|
||||
var (sim, coords) = SimulationFactory();
|
||||
var sim = SimulationFactory();
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
var entity = entMan.SpawnEntity(null, coords);
|
||||
var entity = entMan.SpawnEntity(null, DefaultCoords);
|
||||
var component = entMan.AddComponent<DummyComponent>(entity);
|
||||
|
||||
// Act
|
||||
@@ -321,9 +323,9 @@ namespace Robust.UnitTesting.Shared.GameObjects
|
||||
public void GetAllComponentsTest()
|
||||
{
|
||||
// Arrange
|
||||
var (sim, coords) = SimulationFactory();
|
||||
var sim = SimulationFactory();
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
var entity = entMan.SpawnEntity(null, coords);
|
||||
var entity = entMan.SpawnEntity(null, DefaultCoords);
|
||||
var component = entMan.AddComponent<DummyComponent>(entity);
|
||||
|
||||
// Act
|
||||
@@ -339,10 +341,10 @@ namespace Robust.UnitTesting.Shared.GameObjects
|
||||
public void GetAllComponentInstances()
|
||||
{
|
||||
// Arrange
|
||||
var (sim, coords) = SimulationFactory();
|
||||
var sim = SimulationFactory();
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
var fac = sim.Resolve<IComponentFactory>();
|
||||
var entity = entMan.SpawnEntity(null, coords);
|
||||
var entity = entMan.SpawnEntity(null, DefaultCoords);
|
||||
var component = entMan.AddComponent<DummyComponent>(entity);
|
||||
|
||||
// Act
|
||||
@@ -354,16 +356,17 @@ namespace Robust.UnitTesting.Shared.GameObjects
|
||||
Assert.That(list[0], Is.EqualTo(component));
|
||||
}
|
||||
|
||||
private static (ISimulation, EntityCoordinates) SimulationFactory()
|
||||
private static ISimulation SimulationFactory()
|
||||
{
|
||||
var sim = RobustServerSimulation
|
||||
.NewSimulation()
|
||||
.RegisterComponents(factory => factory.RegisterClass<DummyComponent>())
|
||||
.InitializeInstance();
|
||||
|
||||
var map = sim.CreateMap().Uid;
|
||||
var coords = new EntityCoordinates(map, default);
|
||||
return (sim, coords);
|
||||
// Adds the map with id 1, and spawns entity 1 as the map entity.
|
||||
sim.AddMap(1);
|
||||
|
||||
return sim;
|
||||
}
|
||||
|
||||
[NetworkedComponent()]
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using NUnit.Framework;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.UnitTesting.Server;
|
||||
|
||||
namespace Robust.UnitTesting.Shared.GameObjects
|
||||
@@ -8,12 +9,19 @@ namespace Robust.UnitTesting.Shared.GameObjects
|
||||
[TestFixture, Parallelizable]
|
||||
sealed class EntityManagerTests
|
||||
{
|
||||
private static readonly MapId TestMapId = new(1);
|
||||
|
||||
private static ISimulation SimulationFactory()
|
||||
{
|
||||
var sim = RobustServerSimulation
|
||||
.NewSimulation()
|
||||
.InitializeInstance();
|
||||
|
||||
var mapManager = sim.Resolve<IMapManager>();
|
||||
|
||||
// Adds the map with id 1, and spawns entity 1 as the map entity.
|
||||
mapManager.CreateMap(TestMapId);
|
||||
|
||||
return sim;
|
||||
}
|
||||
|
||||
@@ -24,10 +32,9 @@ namespace Robust.UnitTesting.Shared.GameObjects
|
||||
public void SpawnEntity_PrototypeTransform_Works()
|
||||
{
|
||||
var sim = SimulationFactory();
|
||||
var map = sim.CreateMap().MapId;
|
||||
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
var newEnt = entMan.SpawnEntity(null, new MapCoordinates(0, 0, map));
|
||||
var newEnt = entMan.SpawnEntity(null, new MapCoordinates(0, 0, TestMapId));
|
||||
Assert.That(newEnt, Is.Not.EqualTo(EntityUid.Invalid));
|
||||
}
|
||||
|
||||
@@ -41,7 +48,7 @@ namespace Robust.UnitTesting.Shared.GameObjects
|
||||
|
||||
Assert.That(entManager.Count<TransformComponent>(), Is.EqualTo(0));
|
||||
|
||||
var mapId = sim.CreateMap().MapId;
|
||||
var mapId = mapManager.CreateMap();
|
||||
Assert.That(entManager.Count<TransformComponent>(), Is.EqualTo(1));
|
||||
mapManager.DeleteMap(mapId);
|
||||
Assert.That(entManager.Count<TransformComponent>(), Is.EqualTo(0));
|
||||
|
||||
@@ -20,6 +20,8 @@ namespace Robust.UnitTesting.Shared.GameObjects.Systems
|
||||
[TestFixture, Parallelizable]
|
||||
public sealed partial class AnchoredSystemTests
|
||||
{
|
||||
private static readonly MapId TestMapId = new(1);
|
||||
|
||||
private sealed class Subscriber : IEntityEventSubscriber { }
|
||||
|
||||
private const string Prototypes = @"
|
||||
@@ -30,7 +32,7 @@ namespace Robust.UnitTesting.Shared.GameObjects.Systems
|
||||
- type: Transform
|
||||
anchored: true";
|
||||
|
||||
private static (ISimulation, EntityUid gridId, MapCoordinates) SimulationFactory()
|
||||
private static (ISimulation, EntityUid gridId) SimulationFactory()
|
||||
{
|
||||
var sim = RobustServerSimulation
|
||||
.NewSimulation()
|
||||
@@ -44,12 +46,12 @@ namespace Robust.UnitTesting.Shared.GameObjects.Systems
|
||||
var mapManager = sim.Resolve<IMapManager>();
|
||||
|
||||
// Adds the map with id 1, and spawns entity 1 as the map entity.
|
||||
var testMapId = sim.CreateMap().MapId;
|
||||
var coords = new MapCoordinates(new Vector2(7, 7), testMapId);
|
||||
// Add grid 1, as the default grid to anchor things to.
|
||||
var grid = mapManager.CreateGridEntity(testMapId);
|
||||
mapManager.CreateMap(TestMapId);
|
||||
|
||||
return (sim, grid, coords);
|
||||
// Add grid 1, as the default grid to anchor things to.
|
||||
var grid = mapManager.CreateGridEntity(TestMapId);
|
||||
|
||||
return (sim, grid);
|
||||
}
|
||||
|
||||
// An entity is anchored to the tile it is over on the target grid.
|
||||
@@ -68,9 +70,11 @@ namespace Robust.UnitTesting.Shared.GameObjects.Systems
|
||||
[Test]
|
||||
public void OnAnchored_WorldPosition_TileCenter()
|
||||
{
|
||||
var (sim, gridId, coordinates) = SimulationFactory();
|
||||
var (sim, gridId) = SimulationFactory();
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
|
||||
var coordinates = new MapCoordinates(new Vector2(7, 7), TestMapId);
|
||||
|
||||
// can only be anchored to a tile
|
||||
var grid = entMan.GetComponent<MapGridComponent>(gridId);
|
||||
grid.SetTile(grid.TileIndicesFor(coordinates), new Tile(1));
|
||||
@@ -165,9 +169,9 @@ namespace Robust.UnitTesting.Shared.GameObjects.Systems
|
||||
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
var mapMan = sim.Resolve<IMapManager>();
|
||||
var mapId = sim.CreateMap().MapId;
|
||||
var grid = mapMan.CreateGrid(mapId);
|
||||
var coordinates = new MapCoordinates(new Vector2(7, 7), mapId);
|
||||
mapMan.CreateMap(TestMapId);
|
||||
var grid = mapMan.CreateGrid(TestMapId);
|
||||
var coordinates = new MapCoordinates(new Vector2(7, 7), TestMapId);
|
||||
var pos = grid.TileIndicesFor(coordinates);
|
||||
grid.SetTile(pos, new Tile(1));
|
||||
|
||||
@@ -190,9 +194,11 @@ namespace Robust.UnitTesting.Shared.GameObjects.Systems
|
||||
[Test]
|
||||
public void OnAnchored_Parent_SetToGrid()
|
||||
{
|
||||
var (sim, gridId, coordinates) = SimulationFactory();
|
||||
var (sim, gridId) = SimulationFactory();
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
|
||||
var coordinates = new MapCoordinates(new Vector2(7, 7), TestMapId);
|
||||
|
||||
// can only be anchored to a tile
|
||||
var grid = entMan.GetComponent<MapGridComponent>(gridId);
|
||||
grid.SetTile(grid.TileIndicesFor(coordinates), new Tile(1));
|
||||
@@ -215,11 +221,11 @@ namespace Robust.UnitTesting.Shared.GameObjects.Systems
|
||||
[Test]
|
||||
public void OnAnchored_EmptyTile_Nop()
|
||||
{
|
||||
var (sim, gridId, coords) = SimulationFactory();
|
||||
var (sim, gridId) = SimulationFactory();
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
|
||||
var grid = entMan.GetComponent<MapGridComponent>(gridId);
|
||||
var ent1 = entMan.SpawnEntity(null, coords);
|
||||
var ent1 = entMan.SpawnEntity(null, new MapCoordinates(new Vector2(7, 7), TestMapId));
|
||||
var tileIndices = grid.TileIndicesFor(entMan.GetComponent<TransformComponent>(ent1).Coordinates);
|
||||
grid.SetTile(tileIndices, Tile.Empty);
|
||||
|
||||
@@ -237,11 +243,11 @@ namespace Robust.UnitTesting.Shared.GameObjects.Systems
|
||||
[Test]
|
||||
public void OnAnchored_NonEmptyTile_Anchors()
|
||||
{
|
||||
var (sim, gridId, coords) = SimulationFactory();
|
||||
var (sim, gridId) = SimulationFactory();
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
|
||||
var grid = entMan.GetComponent<MapGridComponent>(gridId);
|
||||
var ent1 = entMan.SpawnEntity(null, coords);
|
||||
var ent1 = entMan.SpawnEntity(null, new MapCoordinates(new Vector2(7, 7), TestMapId));
|
||||
var tileIndices = grid.TileIndicesFor(entMan.GetComponent<TransformComponent>(ent1).Coordinates);
|
||||
grid.SetTile(tileIndices, new Tile(1));
|
||||
|
||||
@@ -263,11 +269,11 @@ namespace Robust.UnitTesting.Shared.GameObjects.Systems
|
||||
[Test]
|
||||
public void Anchored_SetPosition_Nop()
|
||||
{
|
||||
var (sim, gridId, coordinates) = SimulationFactory();
|
||||
var (sim, gridId) = SimulationFactory();
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
|
||||
// coordinates are already tile centered to prevent snapping and MoveEvent
|
||||
coordinates = coordinates.Offset(new Vector2(0.5f, 0.5f));
|
||||
var coordinates = new MapCoordinates(new Vector2(7.5f, 7.5f), TestMapId);
|
||||
|
||||
// can only be anchored to a tile
|
||||
var grid = entMan.GetComponent<MapGridComponent>(gridId);
|
||||
@@ -291,10 +297,12 @@ namespace Robust.UnitTesting.Shared.GameObjects.Systems
|
||||
[Test]
|
||||
public void Anchored_ChangeParent_Unanchors()
|
||||
{
|
||||
var (sim, gridId, coordinates) = SimulationFactory();
|
||||
var (sim, gridId) = SimulationFactory();
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
var mapMan = sim.Resolve<IMapManager>();
|
||||
|
||||
var coordinates = new MapCoordinates(new Vector2(7, 7), TestMapId);
|
||||
|
||||
var grid = entMan.GetComponent<MapGridComponent>(gridId);
|
||||
|
||||
var ent1 = entMan.SpawnEntity(null, coordinates);
|
||||
@@ -303,7 +311,7 @@ namespace Robust.UnitTesting.Shared.GameObjects.Systems
|
||||
entMan.GetComponent<TransformComponent>(ent1).Anchored = true;
|
||||
|
||||
// Act
|
||||
entMan.EntitySysManager.GetEntitySystem<SharedTransformSystem>().SetParent(ent1, mapMan.GetMapEntityId(coordinates.MapId));
|
||||
entMan.EntitySysManager.GetEntitySystem<SharedTransformSystem>().SetParent(ent1, mapMan.GetMapEntityId(TestMapId));
|
||||
|
||||
Assert.That(entMan.GetComponent<TransformComponent>(ent1).Anchored, Is.False);
|
||||
Assert.That(grid.GetAnchoredEntities(tileIndices).Count(), Is.EqualTo(0));
|
||||
@@ -318,11 +326,11 @@ namespace Robust.UnitTesting.Shared.GameObjects.Systems
|
||||
[Test]
|
||||
public void Anchored_SetParentSame_Nop()
|
||||
{
|
||||
var (sim, gridId, coords) = SimulationFactory();
|
||||
var (sim, gridId) = SimulationFactory();
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
|
||||
var grid = entMan.GetComponent<MapGridComponent>(gridId);
|
||||
var ent1 = entMan.SpawnEntity(null, coords);
|
||||
var ent1 = entMan.SpawnEntity(null, new MapCoordinates(new Vector2(7, 7), TestMapId));
|
||||
var tileIndices = grid.TileIndicesFor(entMan.GetComponent<TransformComponent>(ent1).Coordinates);
|
||||
grid.SetTile(tileIndices, new Tile(1));
|
||||
entMan.GetComponent<TransformComponent>(ent1).Anchored = true;
|
||||
@@ -340,11 +348,11 @@ namespace Robust.UnitTesting.Shared.GameObjects.Systems
|
||||
[Test]
|
||||
public void Anchored_TileToSpace_Unanchors()
|
||||
{
|
||||
var (sim, gridId, coords) = SimulationFactory();
|
||||
var (sim, gridId) = SimulationFactory();
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
|
||||
var grid = entMan.GetComponent<MapGridComponent>(gridId);
|
||||
var ent1 = entMan.SpawnEntity(null, coords);
|
||||
var ent1 = entMan.SpawnEntity(null, new MapCoordinates(new Vector2(7, 7), TestMapId));
|
||||
var tileIndices = grid.TileIndicesFor(entMan.GetComponent<TransformComponent>(ent1).Coordinates);
|
||||
grid.SetTile(tileIndices, new Tile(1));
|
||||
grid.SetTile(new Vector2i(100, 100), new Tile(1)); // Prevents the grid from being deleted when the Act happens
|
||||
@@ -368,11 +376,11 @@ namespace Robust.UnitTesting.Shared.GameObjects.Systems
|
||||
[Test]
|
||||
public void Anchored_AddToContainer_Unanchors()
|
||||
{
|
||||
var (sim, gridId, coords) = SimulationFactory();
|
||||
var (sim, gridId) = SimulationFactory();
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
|
||||
var grid = entMan.GetComponent<MapGridComponent>(gridId);
|
||||
var ent1 = entMan.SpawnEntity(null, coords);
|
||||
var ent1 = entMan.SpawnEntity(null, new MapCoordinates(new Vector2(7, 7), TestMapId));
|
||||
var tileIndices = grid.TileIndicesFor(entMan.GetComponent<TransformComponent>(ent1).Coordinates);
|
||||
grid.SetTile(tileIndices, new Tile(1));
|
||||
entMan.GetComponent<TransformComponent>(ent1).Anchored = true;
|
||||
@@ -396,11 +404,11 @@ namespace Robust.UnitTesting.Shared.GameObjects.Systems
|
||||
[Test]
|
||||
public void Anchored_AddPhysComp_IsStaticBody()
|
||||
{
|
||||
var (sim, gridId, coords) = SimulationFactory();
|
||||
var (sim, gridId) = SimulationFactory();
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
|
||||
var grid = entMan.GetComponent<MapGridComponent>(gridId);
|
||||
var ent1 = entMan.SpawnEntity(null, coords);
|
||||
var ent1 = entMan.SpawnEntity(null, new MapCoordinates(new Vector2(7, 7), TestMapId));
|
||||
var tileIndices = grid.TileIndicesFor(entMan.GetComponent<TransformComponent>(ent1).Coordinates);
|
||||
grid.SetTile(tileIndices, new Tile(1));
|
||||
entMan.GetComponent<TransformComponent>(ent1).Anchored = true;
|
||||
@@ -418,10 +426,12 @@ namespace Robust.UnitTesting.Shared.GameObjects.Systems
|
||||
[Test]
|
||||
public void OnAnchored_HasPhysicsComp_IsStaticBody()
|
||||
{
|
||||
var (sim, gridId, coordinates) = SimulationFactory();
|
||||
var (sim, gridId) = SimulationFactory();
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
var physSystem = sim.Resolve<IEntitySystemManager>().GetEntitySystem<SharedPhysicsSystem>();
|
||||
|
||||
var coordinates = new MapCoordinates(new Vector2(7, 7), TestMapId);
|
||||
|
||||
// can only be anchored to a tile
|
||||
var grid = entMan.GetComponent<MapGridComponent>(gridId);
|
||||
grid.SetTile(grid.TileIndicesFor(coordinates), new Tile(1));
|
||||
@@ -442,11 +452,11 @@ namespace Robust.UnitTesting.Shared.GameObjects.Systems
|
||||
[Test]
|
||||
public void OnUnanchored_HasPhysicsComp_IsDynamicBody()
|
||||
{
|
||||
var (sim, gridId, coords) = SimulationFactory();
|
||||
var (sim, gridId) = SimulationFactory();
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
|
||||
var grid = entMan.GetComponent<MapGridComponent>(gridId);
|
||||
var ent1 = entMan.SpawnEntity(null, coords);
|
||||
var ent1 = entMan.SpawnEntity(null, new MapCoordinates(new Vector2(7, 7), TestMapId));
|
||||
var tileIndices = grid.TileIndicesFor(entMan.GetComponent<TransformComponent>(ent1).Coordinates);
|
||||
grid.SetTile(tileIndices, new Tile(1));
|
||||
var physComp = entMan.AddComponent<PhysicsComponent>(ent1);
|
||||
@@ -464,13 +474,13 @@ namespace Robust.UnitTesting.Shared.GameObjects.Systems
|
||||
[Test]
|
||||
public void SpawnAnchored_EmptyTile_Unanchors()
|
||||
{
|
||||
var (sim, gridId, coords) = SimulationFactory();
|
||||
var (sim, gridId) = SimulationFactory();
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
|
||||
var grid = entMan.GetComponent<MapGridComponent>(gridId);
|
||||
|
||||
// Act
|
||||
var ent1 = entMan.SpawnEntity("anchoredEnt", coords);
|
||||
var ent1 = entMan.SpawnEntity("anchoredEnt", new MapCoordinates(new Vector2(7, 7), TestMapId));
|
||||
|
||||
var tileIndices = grid.TileIndicesFor(entMan.GetComponent<TransformComponent>(ent1).Coordinates);
|
||||
Assert.That(grid.GetAnchoredEntities(tileIndices).Count(), Is.EqualTo(0));
|
||||
@@ -484,11 +494,11 @@ namespace Robust.UnitTesting.Shared.GameObjects.Systems
|
||||
[Test]
|
||||
public void OnAnchored_InContainer_Nop()
|
||||
{
|
||||
var (sim, gridId, coords) = SimulationFactory();
|
||||
var (sim, gridId) = SimulationFactory();
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
|
||||
var grid = entMan.GetComponent<MapGridComponent>(gridId);
|
||||
var ent1 = entMan.SpawnEntity(null, coords);
|
||||
var ent1 = entMan.SpawnEntity(null, new MapCoordinates(new Vector2(7, 7), TestMapId));
|
||||
var tileIndices = grid.TileIndicesFor(entMan.GetComponent<TransformComponent>(ent1).Coordinates);
|
||||
grid.SetTile(tileIndices, new Tile(1));
|
||||
|
||||
@@ -512,10 +522,12 @@ namespace Robust.UnitTesting.Shared.GameObjects.Systems
|
||||
[Test]
|
||||
public void Unanchored_Unanchor_Nop()
|
||||
{
|
||||
var (sim, gridId, coordinates) = SimulationFactory();
|
||||
var (sim, gridId) = SimulationFactory();
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
var mapMan = sim.Resolve<IMapManager>();
|
||||
|
||||
var coordinates = new MapCoordinates(new Vector2(7, 7), TestMapId);
|
||||
|
||||
// can only be anchored to a tile
|
||||
var grid = entMan.GetComponent<MapGridComponent>(gridId);
|
||||
grid.SetTile(grid.TileIndicesFor(coordinates), new Tile(1));
|
||||
@@ -527,7 +539,7 @@ namespace Robust.UnitTesting.Shared.GameObjects.Systems
|
||||
// Act
|
||||
entMan.System<MoveEventTestSystem>().FailOnMove = true;
|
||||
entMan.GetComponent<TransformComponent>(ent1).Anchored = false;
|
||||
Assert.That(entMan.GetComponent<TransformComponent>(ent1).ParentUid, Is.EqualTo(mapMan.GetMapEntityId(coordinates.MapId)));
|
||||
Assert.That(entMan.GetComponent<TransformComponent>(ent1).ParentUid, Is.EqualTo(mapMan.GetMapEntityId(TestMapId)));
|
||||
entMan.System<MoveEventTestSystem>().FailOnMove = false;
|
||||
traversal.Enabled = true;
|
||||
}
|
||||
@@ -538,9 +550,11 @@ namespace Robust.UnitTesting.Shared.GameObjects.Systems
|
||||
[Test]
|
||||
public void Anchored_Unanchored_ParentUnchanged()
|
||||
{
|
||||
var (sim, gridId, coordinates) = SimulationFactory();
|
||||
var (sim, gridId) = SimulationFactory();
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
|
||||
var coordinates = new MapCoordinates(new Vector2(7, 7), TestMapId);
|
||||
|
||||
// can only be anchored to a tile
|
||||
var grid = entMan.GetComponent<MapGridComponent>(gridId);
|
||||
grid.SetTile(grid.TileIndicesFor(coordinates), new Tile(1));
|
||||
|
||||
@@ -17,6 +17,9 @@ namespace Robust.UnitTesting.Shared.GameObjects.Systems
|
||||
.RegisterEntitySystems(f => f.LoadExtraSystemType<AnchoredSystemTests.MoveEventTestSystem>())
|
||||
.InitializeInstance();
|
||||
|
||||
// Adds the map with id 1, and spawns entity 1 as the map entity.
|
||||
sim.AddMap(1);
|
||||
|
||||
return sim;
|
||||
}
|
||||
|
||||
@@ -28,8 +31,7 @@ namespace Robust.UnitTesting.Shared.GameObjects.Systems
|
||||
{
|
||||
var sim = SimulationFactory();
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
var map = sim.CreateMap().MapId;
|
||||
var ent1 = entMan.SpawnEntity(null, new MapCoordinates(Vector2.Zero, map));
|
||||
var ent1 = entMan.SpawnEntity(null, new MapCoordinates(Vector2.Zero, new MapId(1)));
|
||||
|
||||
entMan.System<AnchoredSystemTests.MoveEventTestSystem>().ResetCounters();
|
||||
IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(ent1).LocalPosition = Vector2.One;
|
||||
@@ -45,7 +47,7 @@ namespace Robust.UnitTesting.Shared.GameObjects.Systems
|
||||
var sim = SimulationFactory();
|
||||
var entManager = sim.Resolve<IEntityManager>();
|
||||
var xformSystem = sim.Resolve<IEntitySystemManager>().GetEntitySystem<SharedTransformSystem>();
|
||||
var mapId = sim.CreateMap().MapId;
|
||||
var mapId = new MapId(1);
|
||||
|
||||
var parent = entManager.SpawnEntity(null, new MapCoordinates(Vector2.One, mapId));
|
||||
var parentXform = entManager.GetComponent<TransformComponent>(parent);
|
||||
@@ -81,7 +83,7 @@ namespace Robust.UnitTesting.Shared.GameObjects.Systems
|
||||
var sim = SimulationFactory();
|
||||
var entManager = sim.Resolve<IEntityManager>();
|
||||
var xformSystem = sim.Resolve<IEntitySystemManager>().GetEntitySystem<SharedTransformSystem>();
|
||||
var mapId = sim.CreateMap().MapId;
|
||||
var mapId = new MapId(1);
|
||||
|
||||
var parent = entManager.SpawnEntity(null, new MapCoordinates(Vector2.One, mapId));
|
||||
var parentXform = entManager.GetComponent<TransformComponent>(parent);
|
||||
|
||||
@@ -20,7 +20,9 @@ namespace Robust.UnitTesting.Shared.GameObjects
|
||||
var server = RobustServerSimulation.NewSimulation().InitializeInstance();
|
||||
|
||||
var entManager = server.Resolve<IEntityManager>();
|
||||
entManager.System<SharedMapSystem>().CreateMap(out var mapId);
|
||||
var mapManager = server.Resolve<IMapManager>();
|
||||
|
||||
var mapId = mapManager.CreateMap();
|
||||
|
||||
var ent1 = entManager.SpawnEntity(null, new MapCoordinates(Vector2.Zero, mapId));
|
||||
var ent2 = entManager.SpawnEntity(null, new MapCoordinates(new Vector2(100f, 0f), mapId));
|
||||
@@ -54,7 +56,7 @@ namespace Robust.UnitTesting.Shared.GameObjects
|
||||
var entManager = server.Resolve<IEntityManager>();
|
||||
var mapManager = server.Resolve<IMapManager>();
|
||||
|
||||
entManager.System<SharedMapSystem>().CreateMap(out var mapId);
|
||||
var mapId = mapManager.CreateMap();
|
||||
var grid = mapManager.CreateGridEntity(mapId);
|
||||
grid.Comp.SetTile(new Vector2i(0, 0), new Tile(1));
|
||||
var gridXform = entManager.GetComponent<TransformComponent>(grid);
|
||||
|
||||
@@ -38,7 +38,12 @@ public sealed partial class ComponentStateTests : RobustIntegrationTest
|
||||
server.Post(() => server.CfgMan.SetCVar(CVars.NetPVS, true));
|
||||
|
||||
// Set up map.
|
||||
var map = server.System<SharedMapSystem>().CreateMap();
|
||||
EntityUid map = default;
|
||||
await server.WaitPost(() =>
|
||||
{
|
||||
var mapId = server.MapMan.CreateMap();
|
||||
map = server.MapMan.GetMapEntityId(mapId);
|
||||
});
|
||||
|
||||
await RunTicks();
|
||||
|
||||
@@ -157,7 +162,12 @@ public sealed partial class ComponentStateTests : RobustIntegrationTest
|
||||
server.Post(() => server.CfgMan.SetCVar(CVars.NetPVS, true));
|
||||
|
||||
// Set up map.
|
||||
var map = server.System<SharedMapSystem>().CreateMap();
|
||||
EntityUid map = default;
|
||||
await server.WaitPost(() =>
|
||||
{
|
||||
var mapId = server.MapMan.CreateMap();
|
||||
map = server.MapMan.GetMapEntityId(mapId);
|
||||
});
|
||||
|
||||
await RunTicks();
|
||||
|
||||
|
||||
@@ -58,10 +58,11 @@ public sealed class DeletionNetworkingTests : RobustIntegrationTest
|
||||
EntityUid grid2 = default;
|
||||
NetEntity grid1Net = default;
|
||||
NetEntity grid2Net = default;
|
||||
server.System<SharedMapSystem>().CreateMap(out var mapId);
|
||||
|
||||
await server.WaitPost(() =>
|
||||
{
|
||||
var mapId = mapMan.CreateMap();
|
||||
mapMan.GetMapEntityId(mapId);
|
||||
var gridComp = mapMan.CreateGridEntity(mapId);
|
||||
gridComp.Comp.SetTile(Vector2i.Zero, new Tile(1));
|
||||
grid1 = gridComp.Owner;
|
||||
|
||||
@@ -37,7 +37,12 @@ public sealed partial class NoSharedReferencesTest : RobustIntegrationTest
|
||||
client.Post(() => netMan.ClientConnect(null!, 0, null!));
|
||||
|
||||
// Set up map.
|
||||
var map = server.System<SharedMapSystem>().CreateMap();
|
||||
EntityUid map = default;
|
||||
await server.WaitPost(() =>
|
||||
{
|
||||
var mapId = server.MapMan.CreateMap();
|
||||
map = server.MapMan.GetMapEntityId(mapId);
|
||||
});
|
||||
|
||||
await RunTicks();
|
||||
|
||||
|
||||
@@ -48,7 +48,8 @@ namespace Robust.UnitTesting.Shared.Map
|
||||
var entityManager = IoCManager.Resolve<IEntityManager>();
|
||||
var mapManager = IoCManager.Resolve<IMapManager>();
|
||||
|
||||
var mapEntity = entityManager.System<SharedMapSystem>().CreateMap(out var mapId);
|
||||
var mapId = mapManager.CreateMap();
|
||||
var mapEntity = mapManager.CreateNewMapEntity(mapId);
|
||||
var newEnt = entityManager.CreateEntityUninitialized(null, new MapCoordinates(Vector2.Zero, mapId));
|
||||
|
||||
var coords = IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(newEnt).Coordinates;
|
||||
@@ -73,7 +74,10 @@ namespace Robust.UnitTesting.Shared.Map
|
||||
public void IsValid_NonFiniteVector_False(float x, float y)
|
||||
{
|
||||
var entityManager = IoCManager.Resolve<IEntityManager>();
|
||||
entityManager.System<SharedMapSystem>().CreateMap(out var mapId);
|
||||
var mapManager = IoCManager.Resolve<IMapManager>();
|
||||
|
||||
var mapId = mapManager.CreateMap();
|
||||
var mapEntity = mapManager.CreateNewMapEntity(mapId);
|
||||
|
||||
var newEnt = entityManager.CreateEntityUninitialized(null, new MapCoordinates(new Vector2(x, y), mapId));
|
||||
var coords = IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(newEnt).Coordinates;
|
||||
@@ -84,7 +88,11 @@ namespace Robust.UnitTesting.Shared.Map
|
||||
[Test]
|
||||
public void EntityCoordinates_Map()
|
||||
{
|
||||
var mapEntity = IoCManager.Resolve<IEntityManager>().System<SharedMapSystem>().CreateMap();
|
||||
var mapManager = IoCManager.Resolve<IMapManager>();
|
||||
|
||||
var mapId = mapManager.CreateMap();
|
||||
var mapEntity = mapManager.CreateNewMapEntity(mapId);
|
||||
|
||||
Assert.That(IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(mapEntity).ParentUid.IsValid(), Is.False);
|
||||
Assert.That(IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(mapEntity).Coordinates.EntityId, Is.EqualTo(mapEntity));
|
||||
}
|
||||
@@ -96,10 +104,12 @@ namespace Robust.UnitTesting.Shared.Map
|
||||
[Test]
|
||||
public void NoParent_OffsetZero()
|
||||
{
|
||||
var mapManager = IoCManager.Resolve<IMapManager>();
|
||||
var entMan = IoCManager.Resolve<IEntityManager>();
|
||||
var uid = entMan.SpawnEntity(null, MapCoordinates.Nullspace);
|
||||
var xform = entMan.GetComponent<TransformComponent>(uid);
|
||||
Assert.That(xform.Coordinates.Position, Is.EqualTo(Vector2.Zero));
|
||||
|
||||
xform.LocalPosition = Vector2.One;
|
||||
Assert.That(xform.Coordinates.Position, Is.EqualTo(Vector2.Zero));
|
||||
}
|
||||
@@ -110,7 +120,8 @@ namespace Robust.UnitTesting.Shared.Map
|
||||
var entityManager = IoCManager.Resolve<IEntityManager>();
|
||||
var mapManager = IoCManager.Resolve<IMapManager>();
|
||||
|
||||
var mapEnt = entityManager.System<SharedMapSystem>().CreateMap(out var mapId);
|
||||
var mapId = mapManager.CreateMap();
|
||||
var mapEnt = mapManager.CreateNewMapEntity(mapId);
|
||||
var newEnt = entityManager.CreateEntityUninitialized(null, new MapCoordinates(Vector2.Zero, mapId));
|
||||
|
||||
Assert.That(IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(mapEnt).Coordinates.GetGridUid(entityManager), Is.Null);
|
||||
@@ -124,7 +135,7 @@ namespace Robust.UnitTesting.Shared.Map
|
||||
var entityManager = IoCManager.Resolve<IEntityManager>();
|
||||
var mapManager = IoCManager.Resolve<IMapManager>();
|
||||
|
||||
entityManager.System<SharedMapSystem>().CreateMap(out var mapId);
|
||||
var mapId = mapManager.CreateMap();
|
||||
var grid = mapManager.CreateGridEntity(mapId);
|
||||
var gridEnt = grid.Owner;
|
||||
var newEnt = entityManager.CreateEntityUninitialized(null, new EntityCoordinates(gridEnt, Vector2.Zero));
|
||||
@@ -141,7 +152,8 @@ namespace Robust.UnitTesting.Shared.Map
|
||||
var entityManager = IoCManager.Resolve<IEntityManager>();
|
||||
var mapManager = IoCManager.Resolve<IMapManager>();
|
||||
|
||||
var mapEnt = entityManager.System<SharedMapSystem>().CreateMap(out var mapId);
|
||||
var mapId = mapManager.CreateMap();
|
||||
var mapEnt = mapManager.CreateNewMapEntity(mapId);
|
||||
var newEnt = entityManager.CreateEntityUninitialized(null, new MapCoordinates(Vector2.Zero, mapId));
|
||||
|
||||
Assert.That(IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(mapEnt).Coordinates.GetMapId(entityManager), Is.EqualTo(mapId));
|
||||
@@ -154,7 +166,7 @@ namespace Robust.UnitTesting.Shared.Map
|
||||
var entityManager = IoCManager.Resolve<IEntityManager>();
|
||||
var mapManager = IoCManager.Resolve<IMapManager>();
|
||||
|
||||
entityManager.System<SharedMapSystem>().CreateMap(out var mapId);
|
||||
var mapId = mapManager.CreateMap();
|
||||
var grid = mapManager.CreateGridEntity(mapId);
|
||||
var gridEnt = grid.Owner;
|
||||
var newEnt = entityManager.CreateEntityUninitialized(null, new EntityCoordinates(gridEnt, Vector2.Zero));
|
||||
@@ -169,8 +181,9 @@ namespace Robust.UnitTesting.Shared.Map
|
||||
var entityManager = IoCManager.Resolve<IEntityManager>();
|
||||
var mapManager = IoCManager.Resolve<IMapManager>();
|
||||
|
||||
var mapEnt = entityManager.System<SharedMapSystem>().CreateMap(out var mapId);
|
||||
var mapId = mapManager.CreateMap();
|
||||
var grid = mapManager.CreateGridEntity(mapId);
|
||||
var mapEnt = mapManager.GetMapEntityId(mapId);
|
||||
var gridEnt = grid.Owner;
|
||||
var newEnt = entityManager.CreateEntityUninitialized(null, new EntityCoordinates(grid, Vector2.Zero));
|
||||
|
||||
@@ -190,8 +203,9 @@ namespace Robust.UnitTesting.Shared.Map
|
||||
var entityManager = IoCManager.Resolve<IEntityManager>();
|
||||
var mapManager = IoCManager.Resolve<IMapManager>();
|
||||
|
||||
var mapEnt = entityManager.System<SharedMapSystem>().CreateMap(out var mapId);
|
||||
var mapId = mapManager.CreateMap();
|
||||
var grid = mapManager.CreateGridEntity(mapId);
|
||||
var mapEnt = mapManager.GetMapEntityId(mapId);
|
||||
var gridEnt = grid.Owner;
|
||||
var newEnt = entityManager.CreateEntityUninitialized(null, new EntityCoordinates(grid, Vector2.Zero));
|
||||
|
||||
@@ -242,7 +256,7 @@ namespace Robust.UnitTesting.Shared.Map
|
||||
|
||||
var transformSystem = entityManager.System<SharedTransformSystem>();
|
||||
|
||||
entityManager.System<SharedMapSystem>().CreateMap(out var mapId);
|
||||
var mapId = mapManager.CreateMap();
|
||||
var grid = mapManager.CreateGridEntity(mapId);
|
||||
var gridEnt = grid.Owner;
|
||||
var newEnt = entityManager.CreateEntityUninitialized(null, new EntityCoordinates(grid, entPos));
|
||||
@@ -260,7 +274,8 @@ namespace Robust.UnitTesting.Shared.Map
|
||||
var entityManager = IoCManager.Resolve<IEntityManager>();
|
||||
var mapManager = IoCManager.Resolve<IMapManager>();
|
||||
|
||||
var mapEnt = entityManager.System<SharedMapSystem>().CreateMap(out var mapId);
|
||||
var mapId = mapManager.CreateMap();
|
||||
var mapEnt = mapManager.GetMapEntityId(mapId);
|
||||
var grid = mapManager.CreateGridEntity(mapId);
|
||||
var gridEnt = grid.Owner;
|
||||
var newEnt = entityManager.CreateEntityUninitialized(null, new EntityCoordinates(grid, Vector2.Zero));
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace Robust.UnitTesting.Shared.Map
|
||||
|
||||
await server.WaitPost(() =>
|
||||
{
|
||||
entManager.System<SharedMapSystem>().CreateMap(out mapId);
|
||||
mapId = mapManager.CreateMap();
|
||||
gridId1 = mapManager.CreateGridEntity(mapId);
|
||||
gridId2 = mapManager.CreateGridEntity(mapId);
|
||||
gridEnt1 = gridId1.Value.Owner;
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace Robust.UnitTesting.Shared.Map
|
||||
|
||||
await server.WaitAssertion(() =>
|
||||
{
|
||||
entManager.System<SharedMapSystem>().CreateMap(out var mapId);
|
||||
var mapId = mapManager.CreateMap();
|
||||
var grid = mapManager.CreateGridEntity(mapId);
|
||||
var gridEntity = grid.Owner;
|
||||
|
||||
@@ -59,7 +59,7 @@ namespace Robust.UnitTesting.Shared.Map
|
||||
|
||||
await server.WaitAssertion(() =>
|
||||
{
|
||||
entManager.System<SharedMapSystem>().CreateMap(out var mapId);
|
||||
var mapId = mapManager.CreateMap();
|
||||
var grid = mapManager.CreateGridEntity(mapId);
|
||||
|
||||
for (var i = 0; i < 10; i++)
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace Robust.UnitTesting.Shared.Map
|
||||
|
||||
await server.WaitAssertion(() =>
|
||||
{
|
||||
entManager.System<SharedMapSystem>().CreateMap(out var mapId);
|
||||
var mapId = mapManager.CreateMap();
|
||||
var grid = mapManager.CreateGridEntity(mapId);
|
||||
|
||||
// Should be nothing if grid empty
|
||||
|
||||
@@ -45,7 +45,7 @@ public sealed class GridMerge_Tests
|
||||
var mapSystem = entMan.System<SharedMapSystem>();
|
||||
var gridFixtures = entMan.System<GridFixtureSystem>();
|
||||
|
||||
var mapId = sim.CreateMap().MapId;
|
||||
var mapId = mapManager.CreateMap();
|
||||
var grid1 = mapManager.CreateGridEntity(mapId);
|
||||
var grid2 = mapManager.CreateGridEntity(mapId);
|
||||
var tiles = new List<(Vector2i, Tile)>();
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace Robust.UnitTesting.Shared.Map
|
||||
|
||||
await server.WaitAssertion(() =>
|
||||
{
|
||||
entMan.System<SharedMapSystem>().CreateMap(out var mapId);
|
||||
var mapId = mapMan.CreateMap();
|
||||
var grid = mapMan.CreateGridEntity(mapId);
|
||||
var gridEnt = grid.Owner;
|
||||
var coordinates = new EntityCoordinates(gridEnt, new Vector2(10, 0));
|
||||
@@ -67,7 +67,7 @@ namespace Robust.UnitTesting.Shared.Map
|
||||
|
||||
await server.WaitAssertion(() =>
|
||||
{
|
||||
entMan.System<SharedMapSystem>().CreateMap(out var mapId);
|
||||
var mapId = mapMan.CreateMap();
|
||||
var grid = mapMan.CreateGridEntity(mapId);
|
||||
var gridEnt = grid.Owner;
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ public sealed class GridSplit_Tests
|
||||
var mapManager = sim.Resolve<IMapManager>();
|
||||
var mapSystem = sim.Resolve<IEntityManager>().System<SharedMapSystem>();
|
||||
|
||||
var mapId = sim.CreateMap().MapId;
|
||||
var mapId = mapManager.CreateMap();
|
||||
var gridEnt = mapManager.CreateGridEntity(mapId);
|
||||
var grid = gridEnt.Comp;
|
||||
grid.CanSplit = false;
|
||||
@@ -62,7 +62,7 @@ public sealed class GridSplit_Tests
|
||||
var sim = GetSim();
|
||||
var mapManager = sim.Resolve<IMapManager>();
|
||||
var mapSystem = sim.Resolve<IEntityManager>().System<SharedMapSystem>();
|
||||
var mapId = sim.CreateMap().MapId;
|
||||
var mapId = mapManager.CreateMap();
|
||||
var gridEnt = mapManager.CreateGridEntity(mapId);
|
||||
|
||||
for (var x = 0; x < 3; x++)
|
||||
@@ -84,7 +84,7 @@ public sealed class GridSplit_Tests
|
||||
var sim = GetSim();
|
||||
var mapManager = sim.Resolve<IMapManager>();
|
||||
var mapSystem = sim.Resolve<IEntityManager>().System<SharedMapSystem>();
|
||||
var mapId = sim.CreateMap().MapId;
|
||||
var mapId = mapManager.CreateMap();
|
||||
var gridEnt = mapManager.CreateGridEntity(mapId);
|
||||
|
||||
for (var x = 0; x < 3; x++)
|
||||
@@ -115,7 +115,7 @@ public sealed class GridSplit_Tests
|
||||
var sim = GetSim();
|
||||
var mapManager = sim.Resolve<IMapManager>();
|
||||
var mapSystem = sim.Resolve<IEntityManager>().System<SharedMapSystem>();
|
||||
var mapId = sim.CreateMap().MapId;
|
||||
var mapId = mapManager.CreateMap();
|
||||
var gridEnt = mapManager.CreateGridEntity(mapId);
|
||||
|
||||
for (var x = 0; x < 3; x++)
|
||||
@@ -143,7 +143,7 @@ public sealed class GridSplit_Tests
|
||||
var entManager = sim.Resolve<IEntityManager>();
|
||||
var mapManager = sim.Resolve<IMapManager>();
|
||||
var mapSystem = sim.Resolve<IEntityManager>().System<SharedMapSystem>();
|
||||
var mapId = sim.CreateMap().MapId;
|
||||
var mapId = mapManager.CreateMap();
|
||||
var gridEnt = mapManager.CreateGridEntity(mapId);
|
||||
var grid = gridEnt.Comp;
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ public sealed class MapGridMap_Tests
|
||||
var entManager = sim.Resolve<IEntityManager>();
|
||||
var mapManager = sim.Resolve<IMapManager>();
|
||||
|
||||
var mapId = sim.CreateMap().MapId;
|
||||
var mapId = mapManager.CreateMap();
|
||||
Assert.That(!mapManager.FindGridsIntersecting(mapId, Box2.UnitCentered).Any());
|
||||
|
||||
entManager.AddComponent<MapGridComponent>(mapManager.GetMapEntityId(mapId));
|
||||
@@ -40,7 +40,7 @@ public sealed class MapGridMap_Tests
|
||||
var entManager = sim.Resolve<IEntityManager>();
|
||||
var mapManager = sim.Resolve<IMapManager>();
|
||||
|
||||
var mapId = sim.CreateMap().MapId;
|
||||
var mapId = mapManager.CreateMap();
|
||||
mapManager.CreateGridEntity(mapId);
|
||||
|
||||
Assert.DoesNotThrow(() =>
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace Robust.UnitTesting.Shared.Map
|
||||
{
|
||||
var sim = SimulationFactory();
|
||||
var mapMan = sim.Resolve<IMapManager>();
|
||||
var mapId = sim.CreateMap().MapId;
|
||||
var mapId = mapMan.CreateMap();
|
||||
var grid = mapMan.CreateGrid(mapId, 8);
|
||||
|
||||
grid.SetTile(new Vector2i(-9, -1), new Tile(1, (TileRenderFlag)1, 1));
|
||||
@@ -52,7 +52,7 @@ namespace Robust.UnitTesting.Shared.Map
|
||||
var sim = SimulationFactory();
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
var mapMan = sim.Resolve<IMapManager>();
|
||||
var mapId = sim.CreateMap().MapId;
|
||||
var mapId = mapMan.CreateMap();
|
||||
var grid = mapMan.CreateGrid(mapId, 8);
|
||||
var gridXform = entMan.GetComponent<TransformComponent>(grid.Owner);
|
||||
gridXform.WorldPosition = new Vector2(3, 5);
|
||||
@@ -78,7 +78,7 @@ namespace Robust.UnitTesting.Shared.Map
|
||||
var sim = SimulationFactory();
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
var mapMan = sim.Resolve<IMapManager>();
|
||||
var mapId = sim.CreateMap().MapId;
|
||||
var mapId = mapMan.CreateMap();
|
||||
var grid = mapMan.CreateGrid(mapId, 8);
|
||||
var gridXform = entMan.GetComponent<TransformComponent>(grid.Owner);
|
||||
|
||||
@@ -103,7 +103,7 @@ namespace Robust.UnitTesting.Shared.Map
|
||||
{
|
||||
var sim = SimulationFactory();
|
||||
var mapMan = sim.Resolve<IMapManager>();
|
||||
var mapId = sim.CreateMap().MapId;
|
||||
var mapId = mapMan.CreateMap();
|
||||
var grid = mapMan.CreateGrid(mapId, 8);
|
||||
|
||||
var result = grid.GridTileToChunkIndices(new Vector2i(-9, -1));
|
||||
@@ -119,7 +119,7 @@ namespace Robust.UnitTesting.Shared.Map
|
||||
{
|
||||
var sim = SimulationFactory();
|
||||
var mapMan = sim.Resolve<IMapManager>();
|
||||
var mapId = sim.CreateMap().MapId;
|
||||
var mapId = mapMan.CreateMap();
|
||||
var grid = mapMan.CreateGrid(mapId, 8);
|
||||
|
||||
var result = grid.GridTileToLocal(new Vector2i(0, 0)).Position;
|
||||
@@ -133,7 +133,7 @@ namespace Robust.UnitTesting.Shared.Map
|
||||
{
|
||||
var sim = SimulationFactory();
|
||||
var mapMan = sim.Resolve<IMapManager>();
|
||||
var mapId = sim.CreateMap().MapId;
|
||||
var mapId = mapMan.CreateMap();
|
||||
var grid = mapMan.CreateGrid(mapId, 8);
|
||||
|
||||
var foundTile = grid.TryGetTileRef(new Vector2i(-9, -1), out var tileRef);
|
||||
@@ -148,7 +148,7 @@ namespace Robust.UnitTesting.Shared.Map
|
||||
{
|
||||
var sim = SimulationFactory();
|
||||
var mapMan = sim.Resolve<IMapManager>();
|
||||
var mapId = sim.CreateMap().MapId;
|
||||
var mapId = mapMan.CreateMap();
|
||||
var grid = mapMan.CreateGrid(mapId, 8);
|
||||
|
||||
grid.SetTile(new Vector2i(-9, -1), new Tile(1, (TileRenderFlag)1, 1));
|
||||
@@ -166,7 +166,7 @@ namespace Robust.UnitTesting.Shared.Map
|
||||
{
|
||||
var sim = SimulationFactory();
|
||||
var mapMan = sim.Resolve<IMapManager>();
|
||||
var mapId = sim.CreateMap().MapId;
|
||||
var mapId = mapMan.CreateMap();
|
||||
var grid = mapMan.CreateGrid(mapId, 8);
|
||||
|
||||
grid.SetTile(new Vector2i(19, 23), new Tile(1));
|
||||
@@ -181,7 +181,7 @@ namespace Robust.UnitTesting.Shared.Map
|
||||
{
|
||||
var sim = SimulationFactory();
|
||||
var mapMan = sim.Resolve<IMapManager>();
|
||||
var mapId = sim.CreateMap().MapId;
|
||||
var mapId = mapMan.CreateMap();
|
||||
var grid = mapMan.CreateGrid(mapId, 8);
|
||||
|
||||
grid.SetTile(new Vector2i(19, 23), new Tile(1));
|
||||
|
||||
@@ -28,7 +28,8 @@ namespace Robust.UnitTesting.Shared.Map
|
||||
var sim = SimulationFactory();
|
||||
var mapMan = sim.Resolve<IMapManager>();
|
||||
|
||||
var mapID = sim.CreateMap().MapId;
|
||||
var mapID = new MapId(11);
|
||||
mapMan.CreateMap(mapID);
|
||||
|
||||
mapMan.Restart();
|
||||
|
||||
@@ -45,7 +46,8 @@ namespace Robust.UnitTesting.Shared.Map
|
||||
var mapMan = sim.Resolve<IMapManager>();
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
|
||||
var mapID = sim.CreateMap().MapId;
|
||||
var mapID = new MapId(11);
|
||||
mapMan.CreateMap(mapID);
|
||||
var grid = mapMan.CreateGridEntity(mapID);
|
||||
|
||||
mapMan.Restart();
|
||||
@@ -67,13 +69,60 @@ namespace Robust.UnitTesting.Shared.Map
|
||||
Assert.That(entMan.Deleted(oldEntity), Is.True);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// When using SetMapEntity, the existing entities on the map are removed, and the new map entity gets a MapComponent.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void SetMapEntity_WithExistingEntity_ExistingEntityDeleted()
|
||||
{
|
||||
// Arrange
|
||||
var sim = SimulationFactory();
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
var mapMan = sim.Resolve<IMapManager>();
|
||||
|
||||
var mapID = new MapId(11);
|
||||
|
||||
mapMan.CreateMap(new MapId(7));
|
||||
mapMan.CreateMap(mapID);
|
||||
var oldMapEntity = mapMan.GetMapEntityId(mapID);
|
||||
var newMapEntity = entMan.CreateEntityUninitialized(null, new MapCoordinates(Vector2.Zero, new MapId(7)));
|
||||
|
||||
// Act
|
||||
mapMan.SetMapEntity(mapID, newMapEntity);
|
||||
|
||||
// Assert
|
||||
Assert.That(entMan.Deleted(oldMapEntity));
|
||||
Assert.That(entMan.HasComponent<MapComponent>(newMapEntity));
|
||||
|
||||
var mapComp = entMan.GetComponent<MapComponent>(newMapEntity);
|
||||
Assert.That(mapComp.MapId == mapID);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// After creating a new map entity for nullspace, you can spawn entities into nullspace like any other map.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void SpawnEntityAt_IntoNullspace_Success()
|
||||
{
|
||||
// Arrange
|
||||
var sim = SimulationFactory();
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
|
||||
// Act
|
||||
var newEntity = entMan.SpawnEntity(null, MapCoordinates.Nullspace);
|
||||
|
||||
// Assert
|
||||
Assert.That(entMan.GetComponent<TransformComponent>(newEntity).MapID, Is.EqualTo(MapId.Nullspace));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Restart_MapEntity_IsRemoved()
|
||||
{
|
||||
var sim = SimulationFactory();
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
var mapMan = sim.Resolve<IMapManager>();
|
||||
var entity = entMan.System<SharedMapSystem>().CreateMap();
|
||||
var map = mapMan.CreateMap();
|
||||
var entity = mapMan.GetMapEntityId(map);
|
||||
mapMan.Restart();
|
||||
Assert.That((!entMan.EntityExists(entity) ? EntityLifeStage.Deleted : entMan.GetComponent<MetaDataComponent>(entity).EntityLifeStage) >= EntityLifeStage.Deleted, Is.True);
|
||||
}
|
||||
|
||||
@@ -31,9 +31,10 @@ internal sealed class MapPauseTests
|
||||
var mapMan = sim.Resolve<IMapManager>();
|
||||
|
||||
// arrange
|
||||
var mapId = sim.CreateMap().Uid;
|
||||
entMan.System<SharedMapSystem>().SetPaused(mapId, true);
|
||||
entMan.SpawnEntity(null, new EntityCoordinates(mapId, default));
|
||||
var mapId = mapMan.CreateMap();
|
||||
mapMan.SetMapPaused(mapId, true);
|
||||
|
||||
entMan.SpawnEntity(null, new MapCoordinates(0, 0, mapId));
|
||||
|
||||
var query = entMan.EntityQuery<TransformComponent>(false).ToList();
|
||||
|
||||
@@ -52,9 +53,10 @@ internal sealed class MapPauseTests
|
||||
var mapMan = sim.Resolve<IMapManager>();
|
||||
|
||||
// arrange
|
||||
var mapId = sim.CreateMap().Uid;
|
||||
entMan.System<SharedMapSystem>().SetPaused(mapId, false);
|
||||
entMan.SpawnEntity(null, new EntityCoordinates(mapId, default));
|
||||
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();
|
||||
|
||||
@@ -73,9 +75,10 @@ internal sealed class MapPauseTests
|
||||
var mapMan = sim.Resolve<IMapManager>();
|
||||
|
||||
// arrange
|
||||
var mapId = sim.CreateMap().Uid;
|
||||
entMan.System<SharedMapSystem>().SetPaused(mapId, true);
|
||||
entMan.SpawnEntity(null, new EntityCoordinates(mapId, default));
|
||||
var mapId = mapMan.CreateMap();
|
||||
mapMan.SetMapPaused(mapId, true);
|
||||
|
||||
entMan.SpawnEntity(null, new MapCoordinates(0, 0, mapId));
|
||||
|
||||
var query = entMan.EntityQuery<TransformComponent>(true).ToList();
|
||||
|
||||
@@ -94,9 +97,10 @@ internal sealed class MapPauseTests
|
||||
var mapMan = sim.Resolve<IMapManager>();
|
||||
|
||||
// arrange
|
||||
var mapId = sim.CreateMap().Uid;
|
||||
entMan.System<SharedMapSystem>().SetPaused(mapId, true);
|
||||
var newEnt = entMan.SpawnEntity(null, new EntityCoordinates(mapId, default));
|
||||
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);
|
||||
@@ -113,9 +117,10 @@ internal sealed class MapPauseTests
|
||||
var mapMan = sim.Resolve<IMapManager>();
|
||||
|
||||
// arrange
|
||||
var mapId = sim.CreateMap().Uid;
|
||||
entMan.System<SharedMapSystem>().SetPaused(mapId, false);
|
||||
var newEnt = entMan.SpawnEntity(null, new EntityCoordinates(mapId, default));
|
||||
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);
|
||||
@@ -132,8 +137,8 @@ internal sealed class MapPauseTests
|
||||
var mapMan = sim.Resolve<IMapManager>();
|
||||
|
||||
// arrange
|
||||
var mapId = sim.CreateMap().MapId;
|
||||
entMan.System<SharedMapSystem>().SetPaused(mapId, true);
|
||||
var mapId = mapMan.CreateMap();
|
||||
mapMan.SetMapPaused(mapId, true);
|
||||
|
||||
// act
|
||||
var newGrid = mapMan.CreateGridEntity(mapId);
|
||||
@@ -155,16 +160,17 @@ internal sealed class MapPauseTests
|
||||
var mapMan = sim.Resolve<IMapManager>();
|
||||
|
||||
// arrange
|
||||
var map1 = sim.CreateMap().Uid;
|
||||
entMan.System<SharedMapSystem>().SetPaused(map1, true);
|
||||
var newEnt = entMan.SpawnEntity(null, new EntityCoordinates(map1, default));
|
||||
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 = sim.CreateMap().Uid;
|
||||
entMan.System<SharedMapSystem>().SetPaused(map2, false);
|
||||
var map2 = mapMan.CreateMap();
|
||||
mapMan.SetMapPaused(map2, false);
|
||||
|
||||
// Act
|
||||
entMan.EntitySysManager.GetEntitySystem<SharedTransformSystem>().SetParent(xform.Owner, map2);
|
||||
entMan.EntitySysManager.GetEntitySystem<SharedTransformSystem>().SetParent(xform.Owner, mapMan.GetMapEntityId(map2));
|
||||
|
||||
var metaData = entMan.GetComponent<MetaDataComponent>(newEnt);
|
||||
Assert.That(metaData.EntityPaused, Is.False);
|
||||
@@ -182,16 +188,17 @@ internal sealed class MapPauseTests
|
||||
var mapMan = sim.Resolve<IMapManager>();
|
||||
|
||||
// arrange
|
||||
var map1 = sim.CreateMap().Uid;
|
||||
entMan.System<SharedMapSystem>().SetPaused(map1, false);
|
||||
var newEnt = entMan.SpawnEntity(null, new EntityCoordinates(map1, default));
|
||||
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 = sim.CreateMap().Uid;
|
||||
entMan.System<SharedMapSystem>().SetPaused(map2, true);
|
||||
var map2 = mapMan.CreateMap();
|
||||
mapMan.SetMapPaused(map2, true);
|
||||
|
||||
// Act
|
||||
entMan.EntitySysManager.GetEntitySystem<SharedTransformSystem>().SetParent(xform.Owner, map2);
|
||||
entMan.EntitySysManager.GetEntitySystem<SharedTransformSystem>().SetParent(xform.Owner, mapMan.GetMapEntityId(map2));
|
||||
|
||||
var metaData = entMan.GetComponent<MetaDataComponent>(newEnt);
|
||||
Assert.That(metaData.EntityPaused, Is.True);
|
||||
@@ -207,11 +214,11 @@ internal sealed class MapPauseTests
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
var mapMan = sim.Resolve<IMapManager>();
|
||||
|
||||
var mapId = sim.CreateMap().Uid;
|
||||
entMan.System<SharedMapSystem>().SetPaused(mapId, true);
|
||||
var newEnt = entMan.SpawnEntity(null, new EntityCoordinates(mapId, default));
|
||||
var mapId = mapMan.CreateMap();
|
||||
mapMan.SetMapPaused(mapId, true);
|
||||
var newEnt = entMan.SpawnEntity(null, new MapCoordinates(0, 0, mapId));
|
||||
|
||||
entMan.System<SharedMapSystem>().SetPaused(mapId, false);
|
||||
mapMan.SetMapPaused(mapId, false);
|
||||
|
||||
var metaData = entMan.GetComponent<MetaDataComponent>(newEnt);
|
||||
Assert.That(metaData.EntityPaused, Is.False);
|
||||
@@ -227,13 +234,75 @@ internal sealed class MapPauseTests
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
var mapMan = sim.Resolve<IMapManager>();
|
||||
|
||||
var mapId = sim.CreateMap().Uid;
|
||||
entMan.System<SharedMapSystem>().SetPaused(mapId, false);
|
||||
var newEnt = entMan.SpawnEntity(null, new EntityCoordinates(mapId, default));
|
||||
var mapId = mapMan.CreateMap();
|
||||
mapMan.SetMapPaused(mapId, false);
|
||||
var newEnt = entMan.SpawnEntity(null, new MapCoordinates(0, 0, mapId));
|
||||
|
||||
entMan.System<SharedMapSystem>().SetPaused(mapId, true);
|
||||
mapMan.SetMapPaused(mapId, true);
|
||||
|
||||
var metaData = entMan.GetComponent<MetaDataComponent>(newEnt);
|
||||
Assert.That(metaData.EntityPaused, Is.True);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// An unallocated MapId is always unpaused.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void UnallocatedMap_IsUnPaused()
|
||||
{
|
||||
var sim = SimulationFactory();
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
var mapMan = (IMapManagerInternal)sim.Resolve<IMapManager>();
|
||||
|
||||
// some random unallocated MapId
|
||||
var paused = mapMan.IsMapPaused(new MapId(12));
|
||||
|
||||
Assert.That(paused, Is.False);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Nullspace is always unpaused, and setting it is a no-op.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void Nullspace_Pause_IsUnPaused()
|
||||
{
|
||||
var sim = SimulationFactory();
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
var mapMan = (IMapManagerInternal)sim.Resolve<IMapManager>();
|
||||
|
||||
mapMan.SetMapPaused(MapId.Nullspace, true);
|
||||
|
||||
var paused = mapMan.IsMapPaused(MapId.Nullspace);
|
||||
Assert.That(paused, Is.False);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// An allocated MapId without an allocated entity (Nullspace) is always unpaused.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void Nullspace_IsUnPaused()
|
||||
{
|
||||
var sim = SimulationFactory();
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
var mapMan = (IMapManagerInternal)sim.Resolve<IMapManager>();
|
||||
|
||||
var paused = mapMan.IsMapPaused(MapId.Nullspace);
|
||||
|
||||
Assert.That(paused, Is.False);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A freed MapId is always unpaused.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void Unpaused_Freed_IsUnPaused()
|
||||
{
|
||||
var sim = SimulationFactory();
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
var mapMan = (IMapManagerInternal)sim.Resolve<IMapManager>();
|
||||
|
||||
var paused = mapMan.IsMapPaused(MapId.Nullspace);
|
||||
|
||||
Assert.That(paused, Is.False);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,7 +75,9 @@ public sealed class GridDeleteSingleTileRemoveTestTest : RobustIntegrationTest
|
||||
var sys = sEntMan.System<SharedMapSystem>();
|
||||
await server.WaitPost(() =>
|
||||
{
|
||||
sMap = sys.CreateMap(out var mapId);
|
||||
var mapId = mapMan.CreateMap();
|
||||
sMap = mapMan.GetMapEntityId(mapId);
|
||||
|
||||
var comp = mapMan.CreateGridEntity(mapId);
|
||||
grid = (comp.Owner, comp);
|
||||
sys.SetTile(grid, grid, new Vector2i(0, 0), new Tile(1, (TileRenderFlag)1, 1));
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user