mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-15 03:30:53 +01:00
Compare commits
33 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dbc4e80e61 | ||
|
|
5eb5ddd96e | ||
|
|
405ed378c0 | ||
|
|
be9db264dd | ||
|
|
2f73f6190d | ||
|
|
f3dfa1f666 | ||
|
|
b0d17e9527 | ||
|
|
4c81e68bf1 | ||
|
|
4490751001 | ||
|
|
bc8d2c154c | ||
|
|
3c83f8e62a | ||
|
|
c36919d76a | ||
|
|
70a853cdd5 | ||
|
|
fd3eb092cc | ||
|
|
c740026014 | ||
|
|
44f9262d1a | ||
|
|
df2160b151 | ||
|
|
5c7b1e6823 | ||
|
|
eaf7a6ba0f | ||
|
|
9ab4286592 | ||
|
|
3f02ef3730 | ||
|
|
2f17cbb1dc | ||
|
|
c2657812f5 | ||
|
|
f17f077849 | ||
|
|
306deddbd2 | ||
|
|
cdd8df743a | ||
|
|
e7ac5ad047 | ||
|
|
0e621a26be | ||
|
|
bbcc7cfe1f | ||
|
|
1208c25dcd | ||
|
|
38c227b692 | ||
|
|
4e73d72753 | ||
|
|
b1e1a0cd88 |
@@ -1,4 +1,4 @@
|
||||
<Project>
|
||||
|
||||
<!-- This file automatically reset by Tools/version.py -->
|
||||
<!-- This file automatically reset by Tools/version.py -->
|
||||
|
||||
|
||||
@@ -54,6 +54,26 @@ END TEMPLATE-->
|
||||
*None yet*
|
||||
|
||||
|
||||
## 233.1.0
|
||||
|
||||
### New features
|
||||
|
||||
* Add GetGridEntities and another GetEntitiesIntersecting overload to EntityLookupSystem.
|
||||
* `MarkupNode` is now `IEquatable<MarkupNode>`. It already supported equality checks, now it implements the interface.
|
||||
* Added `Entity<T>` overloads to the following `SharedMapSystem` methods: `GetTileRef`, `GetAnchoredEntities`, `TileIndicesFor`.
|
||||
* Added `EntityUid`-only overloads to the following `SharedTransformSystem` methods: `AnchorEntity`, `Unanchor`.
|
||||
|
||||
### Bugfixes
|
||||
|
||||
* Fixed equality checks for `MarkupNode` not properly handling attributes.
|
||||
* Fixed toolshed commands failing to generate error messages when working with array types
|
||||
* Fixed `MarkupNode` not having a `GetHashCode()` implementation.
|
||||
|
||||
### Other
|
||||
|
||||
* If `EntityManager.FlushEntities()` fails to delete all entities, it will now attempt to do so a second time before throwing an exception.
|
||||
|
||||
|
||||
## 233.0.2
|
||||
|
||||
### Bugfixes
|
||||
@@ -83,7 +103,7 @@ END TEMPLATE-->
|
||||
|
||||
### Internal
|
||||
|
||||
* `ClientGameStateManager` now only initialises or starts entities after their parents have already been initialized. There are also some new debug asserts to try ensure that this rule isn't broken elsewhere.
|
||||
* `ClientGameStateManager` now only initialises or starts entities after their parents have already been initialized. There are also some new debug asserts to try ensure that this rule isn't broken elsewhere.
|
||||
* Engine version script now supports dashes.
|
||||
|
||||
|
||||
|
||||
96
Robust.Benchmarks/Physics/BoxStackBenchmark.cs
Normal file
96
Robust.Benchmarks/Physics/BoxStackBenchmark.cs
Normal file
@@ -0,0 +1,96 @@
|
||||
using System;
|
||||
using System.Numerics;
|
||||
using BenchmarkDotNet.Attributes;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Robust.Shared.Analyzers;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Physics.Collision.Shapes;
|
||||
using Robust.Shared.Physics.Components;
|
||||
using Robust.Shared.Physics.Dynamics;
|
||||
using Robust.Shared.Physics.Systems;
|
||||
using Robust.UnitTesting.Server;
|
||||
|
||||
namespace Robust.Benchmarks.Physics;
|
||||
|
||||
[Virtual]
|
||||
[MediumRunJob]
|
||||
public class PhysicsBoxStackBenchmark
|
||||
{
|
||||
private ISimulation _sim = default!;
|
||||
|
||||
[GlobalSetup]
|
||||
public void Setup()
|
||||
{
|
||||
_sim = RobustServerSimulation.NewSimulation().InitializeInstance();
|
||||
|
||||
var entManager = _sim.Resolve<IEntityManager>();
|
||||
entManager.System<SharedMapSystem>().CreateMap(out var mapId);
|
||||
SetupTumbler(entManager, mapId);
|
||||
|
||||
for (var i = 0; i < 30; i++)
|
||||
{
|
||||
entManager.TickUpdate(0.016f, false);
|
||||
}
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public void BoxStack()
|
||||
{
|
||||
var entManager = _sim.Resolve<IEntityManager>();
|
||||
|
||||
for (var i = 0; i < 10000; i++)
|
||||
{
|
||||
entManager.TickUpdate(0.016f, false);
|
||||
}
|
||||
}
|
||||
|
||||
private void SetupTumbler(IEntityManager entManager, MapId mapId)
|
||||
{
|
||||
var physics = entManager.System<SharedPhysicsSystem>();
|
||||
var fixtures = entManager.System<FixtureSystem>();
|
||||
|
||||
var groundUid = entManager.SpawnEntity(null, new MapCoordinates(0, 0, mapId));
|
||||
var ground = entManager.AddComponent<PhysicsComponent>(groundUid);
|
||||
|
||||
var horizontal = new EdgeShape(new Vector2(-40, 0), new Vector2(40, 0));
|
||||
fixtures.CreateFixture(groundUid, "fix1", new Fixture(horizontal, 2, 2, true), body: ground);
|
||||
|
||||
var vertical = new EdgeShape(new Vector2(10, 0), new Vector2(10, 10));
|
||||
fixtures.CreateFixture(groundUid, "fix2", new Fixture(vertical, 2, 2, true), body: ground);
|
||||
|
||||
var xs = new[]
|
||||
{
|
||||
0.0f, -10.0f, -5.0f, 5.0f, 10.0f
|
||||
};
|
||||
|
||||
var columnCount = 1;
|
||||
var rowCount = 15;
|
||||
PolygonShape shape;
|
||||
|
||||
for (var j = 0; j < columnCount; j++)
|
||||
{
|
||||
for (var i = 0; i < rowCount; i++)
|
||||
{
|
||||
var x = 0.0f;
|
||||
|
||||
var boxUid = entManager.SpawnEntity(null,
|
||||
new MapCoordinates(new Vector2(xs[j] + x, 0.55f + 1.1f * i), mapId));
|
||||
var box = entManager.AddComponent<PhysicsComponent>(boxUid);
|
||||
|
||||
physics.SetBodyType(boxUid, BodyType.Dynamic, body: box);
|
||||
|
||||
shape = new PolygonShape();
|
||||
shape.SetAsBox(0.5f, 0.5f);
|
||||
physics.SetFixedRotation(boxUid, false, body: box);
|
||||
fixtures.CreateFixture(boxUid, "fix1", new Fixture(shape, 2, 2, true), body: box);
|
||||
|
||||
physics.WakeBody(boxUid, body: box);
|
||||
physics.SetSleepingAllowed(boxUid, box, false);
|
||||
}
|
||||
}
|
||||
|
||||
physics.WakeBody(groundUid, body: ground);
|
||||
}
|
||||
}
|
||||
92
Robust.Benchmarks/Physics/CircleStackBenchmark.cs
Normal file
92
Robust.Benchmarks/Physics/CircleStackBenchmark.cs
Normal file
@@ -0,0 +1,92 @@
|
||||
using System.Numerics;
|
||||
using BenchmarkDotNet.Attributes;
|
||||
using Robust.Shared.Analyzers;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Physics.Collision.Shapes;
|
||||
using Robust.Shared.Physics.Components;
|
||||
using Robust.Shared.Physics.Dynamics;
|
||||
using Robust.Shared.Physics.Systems;
|
||||
using Robust.UnitTesting.Server;
|
||||
|
||||
namespace Robust.Benchmarks.Physics;
|
||||
|
||||
[Virtual]
|
||||
public class PhysicsCircleStackBenchmark
|
||||
{
|
||||
private ISimulation _sim = default!;
|
||||
|
||||
[GlobalSetup]
|
||||
public void Setup()
|
||||
{
|
||||
_sim = RobustServerSimulation.NewSimulation().InitializeInstance();
|
||||
|
||||
var entManager = _sim.Resolve<IEntityManager>();
|
||||
entManager.System<SharedMapSystem>().CreateMap(out var mapId);
|
||||
SetupTumbler(entManager, mapId);
|
||||
|
||||
for (var i = 0; i < 30; i++)
|
||||
{
|
||||
entManager.TickUpdate(0.016f, false);
|
||||
}
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public void CircleStack()
|
||||
{
|
||||
var entManager = _sim.Resolve<IEntityManager>();
|
||||
|
||||
for (var i = 0; i < 10000; i++)
|
||||
{
|
||||
entManager.TickUpdate(0.016f, false);
|
||||
}
|
||||
}
|
||||
|
||||
private void SetupTumbler(IEntityManager entManager, MapId mapId)
|
||||
{
|
||||
var physics = entManager.System<SharedPhysicsSystem>();
|
||||
var fixtures = entManager.System<FixtureSystem>();
|
||||
|
||||
var groundUid = entManager.SpawnEntity(null, new MapCoordinates(0, 0, mapId));
|
||||
var ground = entManager.AddComponent<PhysicsComponent>(groundUid);
|
||||
|
||||
var horizontal = new EdgeShape(new Vector2(-40, 0), new Vector2(40, 0));
|
||||
fixtures.CreateFixture(groundUid, "fix1", new Fixture(horizontal, 2, 2, true), body: ground);
|
||||
|
||||
var vertical = new EdgeShape(new Vector2(20, 0), new Vector2(20, 20));
|
||||
fixtures.CreateFixture(groundUid, "fix2", new Fixture(vertical, 2, 2, true), body: ground);
|
||||
|
||||
var xs = new[]
|
||||
{
|
||||
0.0f, -10.0f, -5.0f, 5.0f, 10.0f
|
||||
};
|
||||
|
||||
var columnCount = 1;
|
||||
var rowCount = 15;
|
||||
PhysShapeCircle shape;
|
||||
|
||||
for (var j = 0; j < columnCount; j++)
|
||||
{
|
||||
for (var i = 0; i < rowCount; i++)
|
||||
{
|
||||
var x = 0.0f;
|
||||
|
||||
var boxUid = entManager.SpawnEntity(null,
|
||||
new MapCoordinates(new Vector2(xs[j] + x, 0.55f + 2.1f * i), mapId));
|
||||
var box = entManager.AddComponent<PhysicsComponent>(boxUid);
|
||||
|
||||
physics.SetBodyType(boxUid, BodyType.Dynamic, body: box);
|
||||
shape = new PhysShapeCircle(0.5f);
|
||||
physics.SetFixedRotation(boxUid, false, body: box);
|
||||
// TODO: Need to detect shape and work out if we need to use fixedrotation
|
||||
|
||||
fixtures.CreateFixture(boxUid, "fix1", new Fixture(shape, 2, 2, true, 5f));
|
||||
physics.WakeBody(boxUid, body: box);
|
||||
physics.SetSleepingAllowed(boxUid, box, false);
|
||||
}
|
||||
}
|
||||
|
||||
physics.WakeBody(groundUid, body: ground);
|
||||
}
|
||||
}
|
||||
91
Robust.Benchmarks/Physics/PyramidBenchmark.cs
Normal file
91
Robust.Benchmarks/Physics/PyramidBenchmark.cs
Normal file
@@ -0,0 +1,91 @@
|
||||
using System;
|
||||
using System.Numerics;
|
||||
using BenchmarkDotNet.Attributes;
|
||||
using Robust.Shared.Analyzers;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Physics.Collision.Shapes;
|
||||
using Robust.Shared.Physics.Components;
|
||||
using Robust.Shared.Physics.Dynamics;
|
||||
using Robust.Shared.Physics.Systems;
|
||||
using Robust.UnitTesting.Server;
|
||||
|
||||
namespace Robust.Benchmarks.Physics;
|
||||
|
||||
[Virtual]
|
||||
public class PhysicsPyramidBenchmark
|
||||
{
|
||||
private ISimulation _sim = default!;
|
||||
|
||||
[GlobalSetup]
|
||||
public void Setup()
|
||||
{
|
||||
_sim = RobustServerSimulation.NewSimulation().InitializeInstance();
|
||||
|
||||
var entManager = _sim.Resolve<IEntityManager>();
|
||||
entManager.System<SharedMapSystem>().CreateMap(out var mapId);
|
||||
SetupTumbler(entManager, mapId);
|
||||
|
||||
for (var i = 0; i < 300; i++)
|
||||
{
|
||||
entManager.TickUpdate(0.016f, false);
|
||||
}
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public void Pyramid()
|
||||
{
|
||||
var entManager = _sim.Resolve<IEntityManager>();
|
||||
|
||||
for (var i = 0; i < 5000; i++)
|
||||
{
|
||||
entManager.TickUpdate(0.016f, false);
|
||||
}
|
||||
}
|
||||
|
||||
private void SetupTumbler(IEntityManager entManager, MapId mapId)
|
||||
{
|
||||
const byte count = 20;
|
||||
|
||||
// Setup ground
|
||||
var physics = entManager.System<SharedPhysicsSystem>();
|
||||
var fixtures = entManager.System<FixtureSystem>();
|
||||
var groundUid = entManager.SpawnEntity(null, new MapCoordinates(0, 0, mapId));
|
||||
var ground = entManager.AddComponent<PhysicsComponent>(groundUid);
|
||||
|
||||
var horizontal = new EdgeShape(new Vector2(40, 0), new Vector2(-40, 0));
|
||||
fixtures.CreateFixture(groundUid, "fix1", new Fixture(horizontal, 2, 2, true), body: ground);
|
||||
physics.WakeBody(groundUid, body: ground);
|
||||
|
||||
// Setup boxes
|
||||
float a = 0.5f;
|
||||
PolygonShape shape = new();
|
||||
shape.SetAsBox(a, a);
|
||||
|
||||
var x = new Vector2(-7.0f, 0.75f);
|
||||
Vector2 y;
|
||||
Vector2 deltaX = new Vector2(0.5625f, 1.25f);
|
||||
Vector2 deltaY = new Vector2(1.125f, 0.0f);
|
||||
|
||||
for (var i = 0; i < count; ++i)
|
||||
{
|
||||
y = x;
|
||||
|
||||
for (var j = i; j < count; ++j)
|
||||
{
|
||||
var boxUid = entManager.SpawnEntity(null, new MapCoordinates(y, mapId));
|
||||
var box = entManager.AddComponent<PhysicsComponent>(boxUid);
|
||||
physics.SetBodyType(boxUid, BodyType.Dynamic, body: box);
|
||||
|
||||
fixtures.CreateFixture(boxUid, "fix1", new Fixture(shape, 2, 2, true, 5f), body: box);
|
||||
y += deltaY;
|
||||
|
||||
physics.WakeBody(boxUid, body: box);
|
||||
physics.SetSleepingAllowed(boxUid, box, false);
|
||||
}
|
||||
|
||||
x += deltaX;
|
||||
}
|
||||
}
|
||||
}
|
||||
105
Robust.Benchmarks/Physics/TumblerBenchmark.cs
Normal file
105
Robust.Benchmarks/Physics/TumblerBenchmark.cs
Normal file
@@ -0,0 +1,105 @@
|
||||
using System;
|
||||
using System.Numerics;
|
||||
using BenchmarkDotNet.Attributes;
|
||||
using Robust.Shared.Analyzers;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Physics.Collision.Shapes;
|
||||
using Robust.Shared.Physics.Components;
|
||||
using Robust.Shared.Physics.Dynamics;
|
||||
using Robust.Shared.Physics.Systems;
|
||||
using Robust.UnitTesting.Server;
|
||||
|
||||
namespace Robust.Benchmarks.Physics;
|
||||
|
||||
[Virtual]
|
||||
public class PhysicsTumblerBenchmark
|
||||
{
|
||||
private ISimulation _sim = default!;
|
||||
|
||||
[GlobalSetup]
|
||||
public void Setup()
|
||||
{
|
||||
_sim = RobustServerSimulation.NewSimulation().InitializeInstance();
|
||||
|
||||
var entManager = _sim.Resolve<IEntityManager>();
|
||||
var physics = entManager.System<SharedPhysicsSystem>();
|
||||
var fixtures = entManager.System<FixtureSystem>();
|
||||
entManager.System<SharedMapSystem>().CreateMap(out var mapId);
|
||||
SetupTumbler(entManager, mapId);
|
||||
|
||||
for (var i = 0; i < 800; i++)
|
||||
{
|
||||
entManager.TickUpdate(0.016f, false);
|
||||
var boxUid = entManager.SpawnEntity(null, new MapCoordinates(0f, 10f, mapId));
|
||||
var box = entManager.AddComponent<PhysicsComponent>(boxUid);
|
||||
physics.SetBodyType(boxUid, BodyType.Dynamic, body: box);
|
||||
physics.SetFixedRotation(boxUid, false, body: box);
|
||||
var shape = new PolygonShape();
|
||||
shape.SetAsBox(0.125f, 0.125f);
|
||||
fixtures.CreateFixture(boxUid, "fix1", new Fixture(shape, 2, 2, true, 0.0625f), body: box);
|
||||
physics.WakeBody(boxUid, body: box);
|
||||
physics.SetSleepingAllowed(boxUid, box, false);
|
||||
}
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public void Tumbler()
|
||||
{
|
||||
var entManager = _sim.Resolve<IEntityManager>();
|
||||
|
||||
for (var i = 0; i < 5000; i++)
|
||||
{
|
||||
entManager.TickUpdate(0.016f, false);
|
||||
}
|
||||
}
|
||||
|
||||
private void SetupTumbler(IEntityManager entManager, MapId mapId)
|
||||
{
|
||||
var physics = entManager.System<SharedPhysicsSystem>();
|
||||
var fixtures = entManager.System<FixtureSystem>();
|
||||
var joints = entManager.System<SharedJointSystem>();
|
||||
|
||||
var groundUid = entManager.SpawnEntity(null, new MapCoordinates(0f, 0f, mapId));
|
||||
var ground = entManager.AddComponent<PhysicsComponent>(groundUid);
|
||||
// Due to lookup changes fixtureless bodies are invalid, so
|
||||
var cShape = new PhysShapeCircle(1f);
|
||||
fixtures.CreateFixture(groundUid, "fix1", new Fixture(cShape, 0, 0, false));
|
||||
|
||||
var bodyUid = entManager.SpawnEntity(null, new MapCoordinates(0f, 10f, mapId));
|
||||
var body = entManager.AddComponent<PhysicsComponent>(bodyUid);
|
||||
|
||||
physics.SetBodyType(bodyUid, BodyType.Dynamic, body: body);
|
||||
physics.SetSleepingAllowed(bodyUid, body, false);
|
||||
physics.SetFixedRotation(bodyUid, false, body: body);
|
||||
|
||||
|
||||
// TODO: Box2D just deref, bleh shape structs someday
|
||||
var shape1 = new PolygonShape();
|
||||
shape1.SetAsBox(0.5f, 10.0f, new Vector2(10.0f, 0.0f), 0.0f);
|
||||
fixtures.CreateFixture(bodyUid, "fix1", new Fixture(shape1, 2, 0, true, 20f));
|
||||
|
||||
var shape2 = new PolygonShape();
|
||||
shape2.SetAsBox(0.5f, 10.0f, new Vector2(-10.0f, 0.0f), 0f);
|
||||
fixtures.CreateFixture(bodyUid, "fix2", new Fixture(shape2, 2, 0, true, 20f));
|
||||
|
||||
var shape3 = new PolygonShape();
|
||||
shape3.SetAsBox(10.0f, 0.5f, new Vector2(0.0f, 10.0f), 0f);
|
||||
fixtures.CreateFixture(bodyUid, "fix3", new Fixture(shape3, 2, 0, true, 20f));
|
||||
|
||||
var shape4 = new PolygonShape();
|
||||
shape4.SetAsBox(10.0f, 0.5f, new Vector2(0.0f, -10.0f), 0f);
|
||||
fixtures.CreateFixture(bodyUid, "fix4", new Fixture(shape4, 2, 0, true, 20f));
|
||||
|
||||
physics.WakeBody(groundUid, body: ground);
|
||||
physics.WakeBody(bodyUid, body: body);
|
||||
var revolute = joints.CreateRevoluteJoint(groundUid, bodyUid);
|
||||
revolute.LocalAnchorA = new Vector2(0f, 10f);
|
||||
revolute.LocalAnchorB = new Vector2(0f, 0f);
|
||||
revolute.ReferenceAngle = 0f;
|
||||
revolute.MotorSpeed = 0.05f * MathF.PI;
|
||||
revolute.MaxMotorTorque = 100000000f;
|
||||
revolute.EnableMotor = true;
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,6 @@ namespace Robust.Client.GameObjects
|
||||
{
|
||||
public sealed class ContainerSystem : SharedContainerSystem
|
||||
{
|
||||
[Dependency] private readonly INetManager _netMan = default!;
|
||||
[Dependency] private readonly IRobustSerializer _serializer = default!;
|
||||
[Dependency] private readonly IDynamicTypeFactoryInternal _dynFactory = default!;
|
||||
[Dependency] private readonly PointLightSystem _lightSys = default!;
|
||||
|
||||
@@ -20,7 +20,6 @@ namespace Robust.Client.GameObjects
|
||||
/// </summary>
|
||||
public sealed class InputSystem : SharedInputSystem, IPostInjectInit
|
||||
{
|
||||
[Dependency] private readonly IEntityManager _entityManager = default!;
|
||||
[Dependency] private readonly IInputManager _inputManager = default!;
|
||||
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
||||
[Dependency] private readonly IClientGameStateManager _stateManager = default!;
|
||||
|
||||
@@ -15,7 +15,6 @@ namespace Robust.Client.GameStates
|
||||
{
|
||||
[Dependency] private readonly IGameTiming _timing = default!;
|
||||
[Dependency] private readonly IEntityManager _entityManager = default!;
|
||||
[Dependency] private readonly IEyeManager _eyeManager = default!;
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||
private readonly EntityLookupSystem _lookup;
|
||||
|
||||
|
||||
@@ -32,7 +32,6 @@ namespace Robust.Client.Graphics.Clyde
|
||||
internal sealed partial class Clyde : IClydeInternal, IPostInjectInit, IEntityEventSubscriber
|
||||
{
|
||||
[Dependency] private readonly IClydeTileDefinitionManager _tileDefinitionManager = default!;
|
||||
[Dependency] private readonly IEyeManager _eyeManager = default!;
|
||||
[Dependency] private readonly ILightManager _lightManager = default!;
|
||||
[Dependency] private readonly ILogManager _logManager = default!;
|
||||
[Dependency] private readonly IMapManager _mapManager = default!;
|
||||
|
||||
@@ -23,7 +23,7 @@ public sealed partial class ReplayLoadManager
|
||||
// Scratch data used by UpdateEntityStates.
|
||||
// Avoids copying changes for every change to an entity between checkpoints, instead copies once per checkpoint on
|
||||
// first change. We can also use this to avoid building a dictionary of ComponentChange inside the inner loop.
|
||||
private class UpdateScratchData
|
||||
private sealed class UpdateScratchData
|
||||
{
|
||||
public Dictionary<ushort, ComponentChange> Changes;
|
||||
public EntityState lastChange;
|
||||
|
||||
@@ -21,7 +21,6 @@ public sealed class EntitySpawningUIController : UIController
|
||||
{
|
||||
[Dependency] private readonly IPlacementManager _placement = default!;
|
||||
[Dependency] private readonly IPrototypeManager _prototypes = default!;
|
||||
[Dependency] private readonly IResourceCache _resources = default!;
|
||||
|
||||
private EntitySpawnWindow? _window;
|
||||
private readonly List<EntityPrototype> _shownEntities = new();
|
||||
|
||||
@@ -1,335 +0,0 @@
|
||||
// MIT License
|
||||
|
||||
// Copyright (c) 2019 Erin Catto
|
||||
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
|
||||
using System;
|
||||
using System.Numerics;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.Console;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Physics.Collision.Shapes;
|
||||
using Robust.Shared.Physics.Components;
|
||||
using Robust.Shared.Physics.Controllers;
|
||||
using Robust.Shared.Physics.Dynamics;
|
||||
using Robust.Shared.Physics.Dynamics.Joints;
|
||||
using Robust.Shared.Physics.Systems;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
namespace Robust.Server.Console.Commands
|
||||
{
|
||||
/*
|
||||
* I didn't use blueprints because this is way easier to iterate upon as I can shit out testbed upon testbed on new maps
|
||||
* and never have to leave my debugger.
|
||||
*/
|
||||
|
||||
/// <summary>
|
||||
/// Copies of Box2D's physics testbed for debugging.
|
||||
/// </summary>
|
||||
public sealed class TestbedCommand : LocalizedCommands
|
||||
{
|
||||
[Dependency] private readonly IEntityManager _ent = default!;
|
||||
[Dependency] private readonly IMapManager _map = default!;
|
||||
|
||||
public override string Command => "testbed";
|
||||
|
||||
public override void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||
{
|
||||
if (args.Length != 2)
|
||||
{
|
||||
shell.WriteError("Require 2 args for testbed!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!int.TryParse(args[0], out var mapInt))
|
||||
{
|
||||
shell.WriteError($"Unable to parse map {args[0]}");
|
||||
return;
|
||||
}
|
||||
|
||||
var mapId = new MapId(mapInt);
|
||||
if (!_map.MapExists(mapId))
|
||||
{
|
||||
shell.WriteError($"map {args[0]} does not exist");
|
||||
return;
|
||||
}
|
||||
|
||||
if (shell.Player == null)
|
||||
{
|
||||
shell.WriteError("No player found");
|
||||
return;
|
||||
}
|
||||
|
||||
Action testbed;
|
||||
SetupPlayer(mapId, shell);
|
||||
|
||||
switch (args[1])
|
||||
{
|
||||
case "boxstack":
|
||||
testbed = () => CreateBoxStack(mapId);
|
||||
break;
|
||||
case "circlestack":
|
||||
testbed = () => CreateCircleStack(mapId);
|
||||
break;
|
||||
case "pyramid":
|
||||
testbed = () => CreatePyramid(mapId);
|
||||
break;
|
||||
case "tumbler":
|
||||
testbed = () => CreateTumbler(mapId);
|
||||
break;
|
||||
default:
|
||||
shell.WriteError($"testbed {args[0]} not found!");
|
||||
return;
|
||||
}
|
||||
|
||||
Timer.Spawn(1000, () =>
|
||||
{
|
||||
if (!_map.MapExists(mapId)) return;
|
||||
testbed();
|
||||
});
|
||||
|
||||
shell.WriteLine($"Testbed on map {mapId}");
|
||||
}
|
||||
|
||||
private void SetupPlayer(MapId mapId, IConsoleShell shell)
|
||||
{
|
||||
_map.SetMapPaused(mapId, false);
|
||||
var mapUid = _map.GetMapEntityIdOrThrow(mapId);
|
||||
_ent.System<Gravity2DController>().SetGravity(mapUid, new Vector2(0, -9.8f));
|
||||
|
||||
shell.ExecuteCommand("aghost");
|
||||
shell.ExecuteCommand($"tp 0 0 {mapId}");
|
||||
shell.RemoteExecuteCommand($"physics shapes");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
private void CreateBoxStack(MapId mapId)
|
||||
{
|
||||
var physics = _ent.System<SharedPhysicsSystem>();
|
||||
var fixtures = _ent.System<FixtureSystem>();
|
||||
|
||||
var groundUid = _ent.SpawnEntity(null, new MapCoordinates(0, 0, mapId));
|
||||
var ground = _ent.AddComponent<PhysicsComponent>(groundUid);
|
||||
|
||||
var horizontal = new EdgeShape(new Vector2(-40, 0), new Vector2(40, 0));
|
||||
fixtures.CreateFixture(groundUid, "fix1", new Fixture(horizontal, 2, 2, true), body: ground);
|
||||
|
||||
var vertical = new EdgeShape(new Vector2(10, 0), new Vector2(10, 10));
|
||||
fixtures.CreateFixture(groundUid, "fix2", new Fixture(vertical, 2, 2, true), body: ground);
|
||||
|
||||
var xs = new[]
|
||||
{
|
||||
0.0f, -10.0f, -5.0f, 5.0f, 10.0f
|
||||
};
|
||||
|
||||
var columnCount = 1;
|
||||
var rowCount = 15;
|
||||
PolygonShape shape;
|
||||
|
||||
for (var j = 0; j < columnCount; j++)
|
||||
{
|
||||
for (var i = 0; i < rowCount; i++)
|
||||
{
|
||||
var x = 0.0f;
|
||||
|
||||
var boxUid = _ent.SpawnEntity(null,
|
||||
new MapCoordinates(new Vector2(xs[j] + x, 0.55f + 1.1f * i), mapId));
|
||||
var box = _ent.AddComponent<PhysicsComponent>(boxUid);
|
||||
|
||||
physics.SetBodyType(boxUid, BodyType.Dynamic, body: box);
|
||||
|
||||
shape = new PolygonShape();
|
||||
shape.SetAsBox(0.5f, 0.5f);
|
||||
physics.SetFixedRotation(boxUid, false, body: box);
|
||||
fixtures.CreateFixture(boxUid, "fix1", new Fixture(shape, 2, 2, true), body: box);
|
||||
|
||||
physics.WakeBody(boxUid, body: box);
|
||||
}
|
||||
}
|
||||
|
||||
physics.WakeBody(groundUid, body: ground);
|
||||
}
|
||||
|
||||
private void CreateCircleStack(MapId mapId)
|
||||
{
|
||||
var physics = _ent.System<SharedPhysicsSystem>();
|
||||
var fixtures = _ent.System<FixtureSystem>();
|
||||
|
||||
var groundUid = _ent.SpawnEntity(null, new MapCoordinates(0, 0, mapId));
|
||||
var ground = _ent.AddComponent<PhysicsComponent>(groundUid);
|
||||
|
||||
var horizontal = new EdgeShape(new Vector2(-40, 0), new Vector2(40, 0));
|
||||
fixtures.CreateFixture(groundUid, "fix1", new Fixture(horizontal, 2, 2, true), body: ground);
|
||||
|
||||
var vertical = new EdgeShape(new Vector2(20, 0), new Vector2(20, 20));
|
||||
fixtures.CreateFixture(groundUid, "fix2", new Fixture(vertical, 2, 2, true), body: ground);
|
||||
|
||||
var xs = new[]
|
||||
{
|
||||
0.0f, -10.0f, -5.0f, 5.0f, 10.0f
|
||||
};
|
||||
|
||||
var columnCount = 1;
|
||||
var rowCount = 15;
|
||||
PhysShapeCircle shape;
|
||||
|
||||
for (var j = 0; j < columnCount; j++)
|
||||
{
|
||||
for (var i = 0; i < rowCount; i++)
|
||||
{
|
||||
var x = 0.0f;
|
||||
|
||||
var boxUid = _ent.SpawnEntity(null,
|
||||
new MapCoordinates(new Vector2(xs[j] + x, 0.55f + 2.1f * i), mapId));
|
||||
var box = _ent.AddComponent<PhysicsComponent>(boxUid);
|
||||
|
||||
physics.SetBodyType(boxUid, BodyType.Dynamic, body: box);
|
||||
shape = new PhysShapeCircle(0.5f);
|
||||
physics.SetFixedRotation(boxUid, false, body: box);
|
||||
// TODO: Need to detect shape and work out if we need to use fixedrotation
|
||||
|
||||
fixtures.CreateFixture(boxUid, "fix1", new Fixture(shape, 2, 2, true, 5f));
|
||||
physics.WakeBody(boxUid, body: box);
|
||||
}
|
||||
}
|
||||
|
||||
physics.WakeBody(groundUid, body: ground);
|
||||
}
|
||||
|
||||
private void CreatePyramid(MapId mapId)
|
||||
{
|
||||
const byte count = 20;
|
||||
|
||||
// Setup ground
|
||||
var physics = _ent.System<SharedPhysicsSystem>();
|
||||
var fixtures = _ent.System<FixtureSystem>();
|
||||
var groundUid = _ent.SpawnEntity(null, new MapCoordinates(0, 0, mapId));
|
||||
var ground = _ent.AddComponent<PhysicsComponent>(groundUid);
|
||||
|
||||
var horizontal = new EdgeShape(new Vector2(40, 0), new Vector2(-40, 0));
|
||||
fixtures.CreateFixture(groundUid, "fix1", new Fixture(horizontal, 2, 2, true), body: ground);
|
||||
physics.WakeBody(groundUid, body: ground);
|
||||
|
||||
// Setup boxes
|
||||
float a = 0.5f;
|
||||
PolygonShape shape = new();
|
||||
shape.SetAsBox(a, a);
|
||||
|
||||
var x = new Vector2(-7.0f, 0.75f);
|
||||
Vector2 y;
|
||||
Vector2 deltaX = new Vector2(0.5625f, 1.25f);
|
||||
Vector2 deltaY = new Vector2(1.125f, 0.0f);
|
||||
|
||||
for (var i = 0; i < count; ++i)
|
||||
{
|
||||
y = x;
|
||||
|
||||
for (var j = i; j < count; ++j)
|
||||
{
|
||||
var boxUid = _ent.SpawnEntity(null, new MapCoordinates(y, mapId));
|
||||
var box = _ent.AddComponent<PhysicsComponent>(boxUid);
|
||||
physics.SetBodyType(boxUid, BodyType.Dynamic, body: box);
|
||||
|
||||
fixtures.CreateFixture(boxUid, "fix1", new Fixture(shape, 2, 2, true, 5f), body: box);
|
||||
y += deltaY;
|
||||
|
||||
physics.WakeBody(boxUid, body: box);
|
||||
}
|
||||
|
||||
x += deltaX;
|
||||
}
|
||||
}
|
||||
|
||||
private void CreateTumbler(MapId mapId)
|
||||
{
|
||||
var physics = _ent.System<SharedPhysicsSystem>();
|
||||
var fixtures = _ent.System<FixtureSystem>();
|
||||
var joints = _ent.System<SharedJointSystem>();
|
||||
|
||||
var groundUid = _ent.SpawnEntity(null, new MapCoordinates(0f, 0f, mapId));
|
||||
var ground = _ent.AddComponent<PhysicsComponent>(groundUid);
|
||||
// Due to lookup changes fixtureless bodies are invalid, so
|
||||
var cShape = new PhysShapeCircle(1f);
|
||||
fixtures.CreateFixture(groundUid, "fix1", new Fixture(cShape, 0, 0, false));
|
||||
|
||||
var bodyUid = _ent.SpawnEntity(null, new MapCoordinates(0f, 10f, mapId));
|
||||
var body = _ent.AddComponent<PhysicsComponent>(bodyUid);
|
||||
|
||||
physics.SetBodyType(bodyUid, BodyType.Dynamic, body: body);
|
||||
physics.SetSleepingAllowed(bodyUid, body, false);
|
||||
physics.SetFixedRotation(bodyUid, false, body: body);
|
||||
|
||||
|
||||
// TODO: Box2D just deref, bleh shape structs someday
|
||||
var shape1 = new PolygonShape();
|
||||
shape1.SetAsBox(0.5f, 10.0f, new Vector2(10.0f, 0.0f), 0.0f);
|
||||
fixtures.CreateFixture(bodyUid, "fix1", new Fixture(shape1, 2, 0, true, 20f));
|
||||
|
||||
var shape2 = new PolygonShape();
|
||||
shape2.SetAsBox(0.5f, 10.0f, new Vector2(-10.0f, 0.0f), 0f);
|
||||
fixtures.CreateFixture(bodyUid, "fix2", new Fixture(shape2, 2, 0, true, 20f));
|
||||
|
||||
var shape3 = new PolygonShape();
|
||||
shape3.SetAsBox(10.0f, 0.5f, new Vector2(0.0f, 10.0f), 0f);
|
||||
fixtures.CreateFixture(bodyUid, "fix3", new Fixture(shape3, 2, 0, true, 20f));
|
||||
|
||||
var shape4 = new PolygonShape();
|
||||
shape4.SetAsBox(10.0f, 0.5f, new Vector2(0.0f, -10.0f), 0f);
|
||||
fixtures.CreateFixture(bodyUid, "fix4", new Fixture(shape4, 2, 0, true, 20f));
|
||||
|
||||
physics.WakeBody(groundUid, body: ground);
|
||||
physics.WakeBody(bodyUid, body: body);
|
||||
var revolute = joints.CreateRevoluteJoint(groundUid, bodyUid);
|
||||
revolute.LocalAnchorA = new Vector2(0f, 10f);
|
||||
revolute.LocalAnchorB = new Vector2(0f, 0f);
|
||||
revolute.ReferenceAngle = 0f;
|
||||
revolute.MotorSpeed = 0.05f * MathF.PI;
|
||||
revolute.MaxMotorTorque = 100000000f;
|
||||
revolute.EnableMotor = true;
|
||||
|
||||
// Box2D has this as 800 which is jesus christo.
|
||||
// Wouldn't recommend higher than 100 in debug and higher than 300 on release unless
|
||||
// you really want a profile.
|
||||
var count = 300;
|
||||
|
||||
for (var i = 0; i < count; i++)
|
||||
{
|
||||
Timer.Spawn(i * 20, () =>
|
||||
{
|
||||
if (!_map.MapExists(mapId)) return;
|
||||
var boxUid = _ent.SpawnEntity(null, new MapCoordinates(0f, 10f, mapId));
|
||||
var box = _ent.AddComponent<PhysicsComponent>(boxUid);
|
||||
physics.SetBodyType(boxUid, BodyType.Dynamic, body: box);
|
||||
physics.SetFixedRotation(boxUid, false, body: box);
|
||||
var shape = new PolygonShape();
|
||||
shape.SetAsBox(0.125f, 0.125f);
|
||||
fixtures.CreateFixture(boxUid, "fix1", new Fixture(shape, 2, 2, true, 0.0625f), body: box);
|
||||
physics.WakeBody(boxUid, body: box);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -300,7 +300,8 @@ internal sealed partial class PvsSystem
|
||||
/// </summary>
|
||||
private void AfterEntityFlush()
|
||||
{
|
||||
DebugTools.Assert(EntityManager.EntityCount == 0);
|
||||
if (EntityManager.EntityCount > 0)
|
||||
throw new Exception("Cannot reset PVS data without first deleting all entities.");
|
||||
|
||||
ClearPvsData();
|
||||
ShrinkDataMemory();
|
||||
|
||||
@@ -81,7 +81,7 @@ public record struct NoSuchPlayerError(string Username) : IConError
|
||||
{
|
||||
public FormattedMessage DescribeInner()
|
||||
{
|
||||
return FormattedMessage.FromMarkup($"No player with the username/GUID {Username} could be found.");
|
||||
return FormattedMessage.FromUnformatted($"No player with the username/GUID {Username} could be found.");
|
||||
}
|
||||
|
||||
public string? Expression { get; set; }
|
||||
|
||||
@@ -206,8 +206,11 @@ namespace Robust.Shared.Scripting
|
||||
public void Dirty(EntityUid uid)
|
||||
=> ent.DirtyEntity(uid);
|
||||
|
||||
#pragma warning disable CS0618 // Type or member is obsolete
|
||||
// Remove this helper when component.Owner finally gets removed.
|
||||
public void Dirty(Component comp)
|
||||
=> ent.Dirty(comp.Owner, comp);
|
||||
#pragma warning restore CS0618 // Type or member is obsolete
|
||||
|
||||
public string Name(EntityUid uid)
|
||||
=> ent.GetComponent<MetaDataComponent>(uid).EntityName;
|
||||
|
||||
@@ -19,7 +19,6 @@ namespace Robust.Shared.Containers
|
||||
[RegisterComponent, ComponentProtoName("ContainerContainer")]
|
||||
public sealed partial class ContainerManagerComponent : Component, ISerializationHooks
|
||||
{
|
||||
[Dependency] private readonly IDynamicTypeFactoryInternal _dynFactory = default!;
|
||||
[Dependency] private readonly IEntityManager _entMan = default!;
|
||||
|
||||
[DataField("containers")]
|
||||
|
||||
@@ -693,6 +693,25 @@ namespace Robust.Shared.GameObjects
|
||||
public virtual void FlushEntities()
|
||||
{
|
||||
BeforeEntityFlush?.Invoke();
|
||||
FlushEntitiesInternal();
|
||||
|
||||
if (Entities.Count != 0)
|
||||
_sawmill.Error("Failed to flush all entities");
|
||||
|
||||
#if EXCEPTION_TOLERANCE
|
||||
// Attempt to flush entities a second time, just in case something somehow caused an entity to be spawned
|
||||
// while flushing entities
|
||||
FlushEntitiesInternal();
|
||||
#endif
|
||||
|
||||
if (Entities.Count != 0)
|
||||
throw new Exception("Failed to flush all entities");
|
||||
|
||||
AfterEntityFlush?.Invoke();
|
||||
}
|
||||
|
||||
private void FlushEntitiesInternal()
|
||||
{
|
||||
QueuedDeletions.Clear();
|
||||
QueuedDeletionsSet.Clear();
|
||||
|
||||
@@ -738,11 +757,6 @@ namespace Robust.Shared.GameObjects
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
if (Entities.Count != 0)
|
||||
_sawmill.Error("Entities were spawned while flushing entities.");
|
||||
|
||||
AfterEntityFlush?.Invoke();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -703,6 +703,19 @@ public sealed partial class EntityLookupSystem
|
||||
return entities;
|
||||
}
|
||||
|
||||
public void GetEntitiesIntersecting(
|
||||
MapId mapId,
|
||||
IPhysShape shape,
|
||||
Transform transform,
|
||||
HashSet<EntityUid> entities,
|
||||
LookupFlags flags = LookupFlags.All)
|
||||
{
|
||||
if (mapId == MapId.Nullspace)
|
||||
return;
|
||||
|
||||
AddEntitiesIntersecting(mapId, entities, shape, transform, flags: flags);
|
||||
}
|
||||
|
||||
public void GetEntitiesInRange(MapId mapId, Vector2 worldPos, float range, HashSet<EntityUid> entities, LookupFlags flags = DefaultFlags)
|
||||
{
|
||||
DebugTools.Assert(range > 0, "Range must be a positive float");
|
||||
|
||||
@@ -784,6 +784,22 @@ public sealed partial class EntityLookupSystem
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Gets entities with the specified component with the specified grid.
|
||||
/// </summary>
|
||||
public void GetGridEntities<TComp1>(EntityUid gridUid, HashSet<Entity<TComp1>> entities) where TComp1 : IComponent
|
||||
{
|
||||
var query = AllEntityQuery<TComp1, TransformComponent>();
|
||||
|
||||
while (query.MoveNext(out var uid, out var comp, out var xform))
|
||||
{
|
||||
if (xform.GridUid != gridUid)
|
||||
continue;
|
||||
|
||||
entities.Add((uid, comp));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets entities with the specified component with the specified parent.
|
||||
/// </summary>
|
||||
|
||||
@@ -707,16 +707,31 @@ public abstract partial class SharedMapSystem
|
||||
|
||||
#region TileAccess
|
||||
|
||||
public TileRef GetTileRef(Entity<MapGridComponent> grid, MapCoordinates coords)
|
||||
{
|
||||
return GetTileRef(grid.Owner, grid.Comp, coords);
|
||||
}
|
||||
|
||||
public TileRef GetTileRef(EntityUid uid, MapGridComponent grid, MapCoordinates coords)
|
||||
{
|
||||
return GetTileRef(uid, grid, CoordinatesToTile(uid, grid, coords));
|
||||
}
|
||||
|
||||
public TileRef GetTileRef(Entity<MapGridComponent> grid, EntityCoordinates coords)
|
||||
{
|
||||
return GetTileRef(grid.Owner, grid.Comp, coords);
|
||||
}
|
||||
|
||||
public TileRef GetTileRef(EntityUid uid, MapGridComponent grid, EntityCoordinates coords)
|
||||
{
|
||||
return GetTileRef(uid, grid, CoordinatesToTile(uid, grid, coords));
|
||||
}
|
||||
|
||||
public TileRef GetTileRef(Entity<MapGridComponent> grid, Vector2i tileCoordinates)
|
||||
{
|
||||
return GetTileRef(grid.Owner, grid.Comp, tileCoordinates);
|
||||
}
|
||||
|
||||
public TileRef GetTileRef(EntityUid uid, MapGridComponent grid, Vector2i tileCoordinates)
|
||||
{
|
||||
var chunkIndices = GridTileToChunkIndices(uid, grid, tileCoordinates);
|
||||
@@ -1089,16 +1104,31 @@ public abstract partial class SharedMapSystem
|
||||
return chunk.GetSnapGrid((ushort)x, (ushort)y)?.Count ?? 0; // ?
|
||||
}
|
||||
|
||||
public IEnumerable<EntityUid> GetAnchoredEntities(Entity<MapGridComponent> grid, MapCoordinates coords)
|
||||
{
|
||||
return GetAnchoredEntities(grid.Owner, grid.Comp, coords);
|
||||
}
|
||||
|
||||
public IEnumerable<EntityUid> GetAnchoredEntities(EntityUid uid, MapGridComponent grid, MapCoordinates coords)
|
||||
{
|
||||
return GetAnchoredEntities(uid, grid, TileIndicesFor(uid, grid, coords));
|
||||
}
|
||||
|
||||
public IEnumerable<EntityUid> GetAnchoredEntities(Entity<MapGridComponent> grid, EntityCoordinates coords)
|
||||
{
|
||||
return GetAnchoredEntities(grid.Owner, grid.Comp, coords);
|
||||
}
|
||||
|
||||
public IEnumerable<EntityUid> GetAnchoredEntities(EntityUid uid, MapGridComponent grid, EntityCoordinates coords)
|
||||
{
|
||||
return GetAnchoredEntities(uid, grid, TileIndicesFor(uid, grid, coords));
|
||||
}
|
||||
|
||||
public IEnumerable<EntityUid> GetAnchoredEntities(Entity<MapGridComponent> grid, Vector2i pos)
|
||||
{
|
||||
return GetAnchoredEntities(grid.Owner, grid.Comp, pos);
|
||||
}
|
||||
|
||||
public IEnumerable<EntityUid> GetAnchoredEntities(EntityUid uid, MapGridComponent grid, Vector2i pos)
|
||||
{
|
||||
// Because some content stuff checks neighboring tiles (which may not actually exist) we won't just
|
||||
@@ -1191,6 +1221,11 @@ public abstract partial class SharedMapSystem
|
||||
return SnapGridLocalCellFor(uid, grid, LocalToGrid(uid, grid, coords));
|
||||
}
|
||||
|
||||
public Vector2i TileIndicesFor(Entity<MapGridComponent> grid, EntityCoordinates coords)
|
||||
{
|
||||
return TileIndicesFor(grid.Owner, grid.Comp, coords);
|
||||
}
|
||||
|
||||
public Vector2i TileIndicesFor(EntityUid uid, MapGridComponent grid, MapCoordinates worldPos)
|
||||
{
|
||||
#if DEBUG
|
||||
@@ -1202,6 +1237,11 @@ public abstract partial class SharedMapSystem
|
||||
return SnapGridLocalCellFor(uid, grid, localPos);
|
||||
}
|
||||
|
||||
public Vector2i TileIndicesFor(Entity<MapGridComponent> grid, MapCoordinates coords)
|
||||
{
|
||||
return TileIndicesFor(grid.Owner, grid.Comp, coords);
|
||||
}
|
||||
|
||||
private Vector2i SnapGridLocalCellFor(EntityUid uid, MapGridComponent grid, Vector2 localPos)
|
||||
{
|
||||
var x = (int)Math.Floor(localPos.X / grid.TileSize);
|
||||
|
||||
@@ -107,6 +107,11 @@ public abstract partial class SharedTransformSystem
|
||||
return AnchorEntity(uid, xform, grid.Owner, grid, tileIndices);
|
||||
}
|
||||
|
||||
public bool AnchorEntity(EntityUid uid)
|
||||
{
|
||||
return AnchorEntity(uid, XformQuery.GetComponent(uid));
|
||||
}
|
||||
|
||||
public bool AnchorEntity(EntityUid uid, TransformComponent xform)
|
||||
{
|
||||
return AnchorEntity((uid, xform));
|
||||
@@ -127,6 +132,11 @@ public abstract partial class SharedTransformSystem
|
||||
return AnchorEntity(entity, grid.Value, tileIndices);
|
||||
}
|
||||
|
||||
public void Unanchor(EntityUid uid)
|
||||
{
|
||||
Unanchor(uid, XformQuery.GetComponent(uid));
|
||||
}
|
||||
|
||||
public void Unanchor(EntityUid uid, TransformComponent xform, bool setPhysics = true)
|
||||
{
|
||||
if (!xform._anchored)
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.Intrinsics;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Physics.Collision.Shapes;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
@@ -197,28 +196,6 @@ internal record struct Polygon : IPhysShape
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Equals(PolygonShape? other)
|
||||
{
|
||||
if (ReferenceEquals(null, other))
|
||||
return false;
|
||||
if (ReferenceEquals(this, other))
|
||||
return true;
|
||||
|
||||
if (!Radius.Equals(other.Radius) || VertexCount != other.VertexCount)
|
||||
return false;
|
||||
|
||||
for (var i = 0; i < VertexCount; i++)
|
||||
{
|
||||
var vert = Vertices[i];
|
||||
var otherVert = other.Vertices[i];
|
||||
|
||||
if (!vert.Equals(otherVert))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return HashCode.Combine(VertexCount, Vertices.AsSpan(0, VertexCount).ToArray(), Radius);
|
||||
|
||||
@@ -2,7 +2,7 @@ using System;
|
||||
|
||||
namespace Robust.Shared.Serialization.Manager.Definition;
|
||||
|
||||
public class DataDefinitionUtility
|
||||
public static class DataDefinitionUtility
|
||||
{
|
||||
public static string AutoGenerateTag(string name)
|
||||
{
|
||||
|
||||
@@ -8,7 +8,7 @@ public sealed class NotForServerConsoleError : IConError
|
||||
{
|
||||
public FormattedMessage DescribeInner()
|
||||
{
|
||||
return FormattedMessage.FromMarkupOrThrow(
|
||||
return FormattedMessage.FromUnformatted(
|
||||
"You must be logged in with a client to use this, the server console isn't workable.");
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ public record SessionHasNoEntityError(ICommonSession Session) : IConError
|
||||
{
|
||||
public FormattedMessage DescribeInner()
|
||||
{
|
||||
return FormattedMessage.FromMarkupOrThrow($"The user {Session.Name} has no attached entity.");
|
||||
return FormattedMessage.FromUnformatted($"The user {Session.Name} has no attached entity.");
|
||||
}
|
||||
|
||||
public string? Expression { get; set; }
|
||||
|
||||
@@ -134,7 +134,7 @@ public record struct MissingClosingBrace() : IConError
|
||||
{
|
||||
public FormattedMessage DescribeInner()
|
||||
{
|
||||
return FormattedMessage.FromMarkup("Expected a closing brace.");
|
||||
return FormattedMessage.FromUnformatted("Expected a closing brace.");
|
||||
}
|
||||
|
||||
public string? Expression { get; set; }
|
||||
|
||||
@@ -182,7 +182,7 @@ public record struct ExpressionOfWrongType(Type Expected, Type Got, bool Once) :
|
||||
{
|
||||
public FormattedMessage DescribeInner()
|
||||
{
|
||||
var msg = FormattedMessage.FromMarkup(
|
||||
var msg = FormattedMessage.FromUnformatted(
|
||||
$"Expected an expression of type {Expected.PrettyName()}, but got {Got.PrettyName()}");
|
||||
|
||||
if (Once)
|
||||
|
||||
@@ -240,7 +240,7 @@ public record struct UnknownCommandError(string Cmd) : IConError
|
||||
{
|
||||
public FormattedMessage DescribeInner()
|
||||
{
|
||||
return FormattedMessage.FromMarkup($"Got unknown command {Cmd}.");
|
||||
return FormattedMessage.FromUnformatted($"Got unknown command {Cmd}.");
|
||||
}
|
||||
|
||||
public string? Expression { get; set; }
|
||||
@@ -252,7 +252,7 @@ public record NoImplementationError(string Cmd, Type[] Types, string? SubCommand
|
||||
{
|
||||
public FormattedMessage DescribeInner()
|
||||
{
|
||||
var msg = FormattedMessage.FromMarkup($"Could not find an implementation for {Cmd} given the input type {PipedType?.PrettyName() ?? "void"}.");
|
||||
var msg = FormattedMessage.FromUnformatted($"Could not find an implementation for {Cmd} given the input type {PipedType?.PrettyName() ?? "void"}.");
|
||||
msg.PushNewline();
|
||||
|
||||
var typeArgs = "";
|
||||
|
||||
@@ -352,7 +352,7 @@ public record OutOfInputError : IConError
|
||||
{
|
||||
public FormattedMessage DescribeInner()
|
||||
{
|
||||
return FormattedMessage.FromMarkupOrThrow("Ran out of input data when data was expected.");
|
||||
return FormattedMessage.FromUnformatted("Ran out of input data when data was expected.");
|
||||
}
|
||||
|
||||
public string? Expression { get; set; }
|
||||
|
||||
@@ -103,8 +103,7 @@ public record BadVarTypeError(Type Got, Type Expected, string VarName) : IConErr
|
||||
{
|
||||
public FormattedMessage DescribeInner()
|
||||
{
|
||||
return FormattedMessage.FromMarkupOrThrow(
|
||||
$"Got unexpected type {Got.PrettyName()} in {VarName}, expected {Expected.PrettyName()}");
|
||||
return FormattedMessage.FromUnformatted($"Got unexpected type {Got.PrettyName()} in {VarName}, expected {Expected.PrettyName()}");
|
||||
}
|
||||
|
||||
public string? Expression { get; set; }
|
||||
|
||||
@@ -14,7 +14,6 @@ public sealed class ToolshedEnvironment
|
||||
{
|
||||
[Dependency] private readonly IReflectionManager _reflection = default!;
|
||||
[Dependency] private readonly ILogManager _logManager = default!;
|
||||
[Dependency] private readonly INetManager _net = default!;
|
||||
[Dependency] private readonly ToolshedManager _toolshedManager = default!;
|
||||
private readonly Dictionary<string, ToolshedCommand> _commands = new();
|
||||
private readonly Dictionary<Type, List<CommandSpec>> _commandPipeValueMap = new();
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace Robust.Shared.Toolshed;
|
||||
|
||||
public sealed partial class ToolshedManager
|
||||
{
|
||||
private readonly Dictionary<Type, ITypeParser> _consoleTypeParsers = new();
|
||||
private readonly Dictionary<Type, ITypeParser?> _consoleTypeParsers = new();
|
||||
private readonly Dictionary<Type, Type> _genericTypeParsers = new();
|
||||
private readonly List<(Type, Type)> _constrainedParsers = new();
|
||||
|
||||
@@ -55,6 +55,14 @@ public sealed partial class ToolshedManager
|
||||
if (_consoleTypeParsers.TryGetValue(t, out var parser))
|
||||
return parser;
|
||||
|
||||
parser = FindParserForType(t);
|
||||
_consoleTypeParsers.TryAdd(t, parser);
|
||||
return parser;
|
||||
|
||||
}
|
||||
|
||||
private ITypeParser? FindParserForType(Type t)
|
||||
{
|
||||
if (t.IsConstructedGenericType)
|
||||
{
|
||||
if (_genericTypeParsers.TryGetValue(t.GetGenericTypeDefinition(), out var genParser))
|
||||
@@ -65,7 +73,6 @@ public sealed partial class ToolshedManager
|
||||
|
||||
var builtParser = (ITypeParser) _typeFactory.CreateInstanceUnchecked(concreteParser, true);
|
||||
builtParser.PostInject();
|
||||
_consoleTypeParsers.Add(builtParser.Parses, builtParser);
|
||||
return builtParser;
|
||||
}
|
||||
catch (SecurityException)
|
||||
@@ -86,7 +93,6 @@ public sealed partial class ToolshedManager
|
||||
|
||||
var builtParser = (ITypeParser) _typeFactory.CreateInstanceUnchecked(concreteParser, true);
|
||||
builtParser.PostInject();
|
||||
_consoleTypeParsers.Add(builtParser.Parses, builtParser);
|
||||
return builtParser;
|
||||
}
|
||||
catch (SecurityException)
|
||||
@@ -181,17 +187,17 @@ public record UnparseableValueError(Type T) : IConError
|
||||
|
||||
if (T.Constructable())
|
||||
{
|
||||
var msg = FormattedMessage.FromMarkup(
|
||||
var msg = FormattedMessage.FromUnformatted(
|
||||
$"The type {T.PrettyName()} has no parser available and cannot be parsed.");
|
||||
msg.PushNewline();
|
||||
msg.AddText("Please contact a programmer with this error, they'd probably like to see it.");
|
||||
msg.PushNewline();
|
||||
msg.AddMarkup("[bold][color=red]THIS IS A BUG.[/color][/bold]");
|
||||
msg.AddMarkupOrThrow("[bold][color=red]THIS IS A BUG.[/color][/bold]");
|
||||
return msg;
|
||||
}
|
||||
else
|
||||
{
|
||||
return FormattedMessage.FromMarkup($"The type {T.PrettyName()} cannot be parsed, as it cannot be constructed.");
|
||||
return FormattedMessage.FromUnformatted($"The type {T.PrettyName()} cannot be parsed, as it cannot be constructed.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ public record InvalidBool(string Value) : IConError
|
||||
{
|
||||
public FormattedMessage DescribeInner()
|
||||
{
|
||||
return FormattedMessage.FromMarkup(
|
||||
return FormattedMessage.FromUnformatted(
|
||||
$"The value {Value} is not a valid boolean.");
|
||||
}
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ public record struct UnknownComponentError(string Component) : IConError
|
||||
{
|
||||
public FormattedMessage DescribeInner()
|
||||
{
|
||||
var msg = FormattedMessage.FromMarkup(
|
||||
var msg = FormattedMessage.FromUnformatted(
|
||||
$"Unknown component {Component}. For a list of all components, try types:components."
|
||||
);
|
||||
if (Component.EndsWith("component", true, CultureInfo.InvariantCulture))
|
||||
|
||||
@@ -49,7 +49,7 @@ public record InvalidEntity(string Value) : IConError
|
||||
{
|
||||
public FormattedMessage DescribeInner()
|
||||
{
|
||||
return FormattedMessage.FromMarkup($"Couldn't parse {Value} as an Entity.");
|
||||
return FormattedMessage.FromUnformatted($"Couldn't parse {Value} as an Entity.");
|
||||
}
|
||||
|
||||
public string? Expression { get; set; }
|
||||
@@ -61,7 +61,7 @@ public record DeadEntity(EntityUid Entity) : IConError
|
||||
{
|
||||
public FormattedMessage DescribeInner()
|
||||
{
|
||||
return FormattedMessage.FromMarkup($"The entity {Entity} does not exist.");
|
||||
return FormattedMessage.FromUnformatted($"The entity {Entity} does not exist.");
|
||||
}
|
||||
|
||||
public string? Expression { get; set; }
|
||||
|
||||
@@ -57,7 +57,7 @@ public record InvalidEnum<T>(string Value) : IConError
|
||||
{
|
||||
public FormattedMessage DescribeInner()
|
||||
{
|
||||
var msg = FormattedMessage.FromMarkup($"The value {Value} is not a valid {typeof(T).PrettyName()}.");
|
||||
var msg = FormattedMessage.FromUnformatted($"The value {Value} is not a valid {typeof(T).PrettyName()}.");
|
||||
msg.AddText($"Valid values are: {string.Join(", ", Enum.GetNames<T>())}");
|
||||
return msg;
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ public record InvalidAngle(string Value) : IConError
|
||||
{
|
||||
public FormattedMessage DescribeInner()
|
||||
{
|
||||
return FormattedMessage.FromMarkup(
|
||||
return FormattedMessage.FromUnformatted(
|
||||
$"The value {Value} is not a valid angle.");
|
||||
}
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ public record InvalidColor(string Value) : IConError
|
||||
{
|
||||
public FormattedMessage DescribeInner()
|
||||
{
|
||||
return FormattedMessage.FromMarkup(
|
||||
return FormattedMessage.FromUnformatted(
|
||||
$"The value {Value} is not a valid RGB color or name of color.");
|
||||
}
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ public record InvalidNumber<T>(string Value) : IConError
|
||||
{
|
||||
public FormattedMessage DescribeInner()
|
||||
{
|
||||
return FormattedMessage.FromMarkup(
|
||||
return FormattedMessage.FromUnformatted(
|
||||
$"The value {Value} is not a valid {typeof(T).PrettyName()}.");
|
||||
}
|
||||
|
||||
|
||||
@@ -97,7 +97,7 @@ public record UnexpectedCloseBrace : IConError
|
||||
{
|
||||
public FormattedMessage DescribeInner()
|
||||
{
|
||||
return FormattedMessage.FromMarkup("Unexpected closing brace.");
|
||||
return FormattedMessage.FromUnformatted("Unexpected closing brace.");
|
||||
}
|
||||
|
||||
public string? Expression { get; set; }
|
||||
|
||||
@@ -69,7 +69,7 @@ public record NotAValidPrototype(string Proto, string Kind) : IConError
|
||||
{
|
||||
public FormattedMessage DescribeInner()
|
||||
{
|
||||
return FormattedMessage.FromMarkup($"{Proto} is not a valid {Kind} prototype");
|
||||
return FormattedMessage.FromUnformatted($"{Proto} is not a valid {Kind} prototype");
|
||||
}
|
||||
|
||||
public string? Expression { get; set; }
|
||||
|
||||
@@ -64,7 +64,7 @@ public record InvalidQuantity(string Value) : IConError
|
||||
{
|
||||
public FormattedMessage DescribeInner()
|
||||
{
|
||||
return FormattedMessage.FromMarkup(
|
||||
return FormattedMessage.FromUnformatted(
|
||||
$"The value {Value} is not a valid quantity. Please input some decimal number, optionally with a % to indicate that it's a percentage.");
|
||||
}
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ internal sealed class SessionTypeParser : TypeParser<ICommonSession>
|
||||
{
|
||||
public FormattedMessage DescribeInner()
|
||||
{
|
||||
return FormattedMessage.FromMarkup(Loc.GetString("cmd-parse-failure-session", ("username", Username)));
|
||||
return FormattedMessage.FromUnformatted(Loc.GetString("cmd-parse-failure-session", ("username", Username)));
|
||||
}
|
||||
|
||||
public string? Expression { get; set; }
|
||||
|
||||
@@ -93,7 +93,7 @@ public record struct StringMustStartWithQuote : IConError
|
||||
{
|
||||
public FormattedMessage DescribeInner()
|
||||
{
|
||||
return FormattedMessage.FromMarkupOrThrow("A string must start with a quote.");
|
||||
return FormattedMessage.FromUnformatted("A string must start with a quote.");
|
||||
}
|
||||
|
||||
public string? Expression { get; set; }
|
||||
|
||||
@@ -10,7 +10,6 @@ using System.Threading.Tasks;
|
||||
using Robust.Shared.Console;
|
||||
using Robust.Shared.ContentPack;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Toolshed.Errors;
|
||||
using Robust.Shared.Toolshed.Syntax;
|
||||
@@ -56,6 +55,7 @@ internal sealed class TypeTypeParser : TypeParser<Type>
|
||||
};
|
||||
|
||||
private readonly HashSet<string> _ambiguousTypes = new();
|
||||
private CompletionResult? _optionsCache;
|
||||
|
||||
public override void PostInject()
|
||||
{
|
||||
@@ -75,6 +75,8 @@ internal sealed class TypeTypeParser : TypeParser<Type>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_optionsCache = CompletionResult.FromHintOptions(Types.Select(x => new CompletionOption(x.Key)), "C# level type");
|
||||
}
|
||||
|
||||
public override bool TryParse(ParserContext parserContext, [NotNullWhen(true)] out object? result, out IConError? error)
|
||||
@@ -168,8 +170,7 @@ internal sealed class TypeTypeParser : TypeParser<Type>
|
||||
string? argName)
|
||||
{
|
||||
// TODO: Suggest generics.
|
||||
var options = Types.Select(x => new CompletionOption(x.Key));
|
||||
return ValueTask.FromResult<(CompletionResult? result, IConError? error)>((CompletionResult.FromHintOptions(options, "C# level type"), null));
|
||||
return ValueTask.FromResult<(CompletionResult? result, IConError? error)>((_optionsCache, null));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -177,9 +178,7 @@ public record struct ExpectedNextType() : IConError
|
||||
{
|
||||
public FormattedMessage DescribeInner()
|
||||
{
|
||||
var msg = new FormattedMessage();
|
||||
msg.AddText($"Expected another type in the generic arguments.");
|
||||
return msg;
|
||||
return FormattedMessage.FromUnformatted("Expected another type in the generic arguments.");
|
||||
}
|
||||
|
||||
public string? Expression { get; set; }
|
||||
@@ -191,9 +190,7 @@ public record struct ExpectedGeneric() : IConError
|
||||
{
|
||||
public FormattedMessage DescribeInner()
|
||||
{
|
||||
var msg = new FormattedMessage();
|
||||
msg.AddText($"Expected a generic type, did you forget the angle brackets?");
|
||||
return msg;
|
||||
return FormattedMessage.FromUnformatted("Expected a generic type, did you forget the angle brackets?");
|
||||
}
|
||||
|
||||
public string? Expression { get; set; }
|
||||
@@ -205,9 +202,7 @@ public record struct UnknownType(string T) : IConError
|
||||
{
|
||||
public FormattedMessage DescribeInner()
|
||||
{
|
||||
var msg = new FormattedMessage();
|
||||
msg.AddText($"The type {T} is not known and cannot be used.");
|
||||
return msg;
|
||||
return FormattedMessage.FromUnformatted($"The type {T} is not known and cannot be used.");
|
||||
}
|
||||
|
||||
public string? Expression { get; set; }
|
||||
@@ -220,9 +215,7 @@ internal record struct TypeIsSandboxViolation(Type T) : IConError
|
||||
{
|
||||
public FormattedMessage DescribeInner()
|
||||
{
|
||||
var msg = new FormattedMessage();
|
||||
msg.AddText($"The type {T.PrettyName()} is not permitted under sandbox rules.");
|
||||
return msg;
|
||||
return FormattedMessage.FromUnformatted($"The type {T.PrettyName()} is not permitted under sandbox rules.");
|
||||
}
|
||||
|
||||
public string? Expression { get; set; }
|
||||
|
||||
@@ -7,7 +7,7 @@ using Robust.Shared.Serialization;
|
||||
namespace Robust.Shared.Utility;
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class MarkupNode : IComparable<MarkupNode>
|
||||
public sealed class MarkupNode : IComparable<MarkupNode>, IEquatable<MarkupNode>
|
||||
{
|
||||
public readonly string? Name;
|
||||
public readonly MarkupParameter Value;
|
||||
@@ -43,7 +43,7 @@ public sealed class MarkupNode : IComparable<MarkupNode>
|
||||
attributesString += $"{k}{v}";
|
||||
}
|
||||
|
||||
return $"[{(Closing ? "/" : "")}{Name}{Value.ToString().ReplaceLineEndings("\\n") ?? ""}{attributesString}]";
|
||||
return $"[{(Closing ? "/" : "")}{Name}{Value.ToString().ReplaceLineEndings("\\n")}{attributesString}]";
|
||||
}
|
||||
|
||||
public override bool Equals(object? obj)
|
||||
@@ -51,14 +51,38 @@ public sealed class MarkupNode : IComparable<MarkupNode>
|
||||
return obj is MarkupNode node && Equals(node);
|
||||
}
|
||||
|
||||
public bool Equals(MarkupNode node)
|
||||
public bool Equals(MarkupNode? node)
|
||||
{
|
||||
var equal = Name == node.Name;
|
||||
equal &= Value.Equals(node.Value);
|
||||
equal &= Attributes.Count == 0 && node.Attributes.Count == 0 || Attributes.Equals(node.Attributes);
|
||||
equal &= Closing == node.Closing;
|
||||
if (node is null)
|
||||
return false;
|
||||
|
||||
return equal;
|
||||
if (Name != node.Name)
|
||||
return false;
|
||||
|
||||
if (!Value.Equals(node.Value))
|
||||
return false;
|
||||
|
||||
if (Closing != node.Closing)
|
||||
return false;
|
||||
|
||||
if (Attributes.Count != node.Attributes.Count)
|
||||
return false;
|
||||
|
||||
foreach (var (key, value) in Attributes)
|
||||
{
|
||||
if (!node.Attributes.TryGetValue(key, out var nodeValue))
|
||||
return false;
|
||||
|
||||
if (!value.Equals(nodeValue))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return HashCode.Combine(Name, Value, Closing);
|
||||
}
|
||||
|
||||
public int CompareTo(MarkupNode? other)
|
||||
@@ -69,7 +93,10 @@ public sealed class MarkupNode : IComparable<MarkupNode>
|
||||
return 1;
|
||||
|
||||
var nameComparison = string.Compare(Name, other.Name, StringComparison.Ordinal);
|
||||
return nameComparison != 0 ? nameComparison : Closing.CompareTo(other.Closing);
|
||||
if (nameComparison != 0)
|
||||
return nameComparison;
|
||||
|
||||
return Closing.CompareTo(other.Closing);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
4
Robust.UnitTesting/.editorconfig
Normal file
4
Robust.UnitTesting/.editorconfig
Normal file
@@ -0,0 +1,4 @@
|
||||
[*.cs]
|
||||
# Doing this via EditorConfig seems to be the only way to suppress in an entire project.
|
||||
# This warning conflicts with NUnit's recommendation to subtype the "Is" type.
|
||||
resharper_access_to_static_member_via_derived_type_highlighting=none
|
||||
@@ -5,7 +5,6 @@ using Robust.Shared.Graphics;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
|
||||
// ReSharper disable AccessToStaticMemberViaDerivedType
|
||||
namespace Robust.UnitTesting.Client.Graphics
|
||||
{
|
||||
[TestFixture, Parallelizable, TestOf(typeof(Eye))]
|
||||
|
||||
@@ -84,7 +84,7 @@ namespace Robust.UnitTesting.Client.UserInterface
|
||||
control1.Visible = true;
|
||||
Assert.That(control2.VisibleInTree, Is.False);
|
||||
|
||||
control1.Dispose();
|
||||
control1.Orphan();
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
||||
@@ -133,10 +133,7 @@ namespace Robust.UnitTesting.Client.UserInterface
|
||||
Assert.That(control3Fired, NUnit.Framework.Is.True);
|
||||
});
|
||||
|
||||
control1.Dispose();
|
||||
control2.Dispose();
|
||||
control3.Dispose();
|
||||
control4.Dispose();
|
||||
control1.Orphan();
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -144,7 +141,6 @@ namespace Robust.UnitTesting.Client.UserInterface
|
||||
{
|
||||
Assert.That(_userInterfaceManager.KeyboardFocused, NUnit.Framework.Is.Null);
|
||||
var control1 = new Control {CanKeyboardFocus = true};
|
||||
var control2 = new Control {CanKeyboardFocus = true};
|
||||
|
||||
control1.GrabKeyboardFocus();
|
||||
Assert.That(_userInterfaceManager.KeyboardFocused, NUnit.Framework.Is.EqualTo(control1));
|
||||
@@ -152,9 +148,6 @@ namespace Robust.UnitTesting.Client.UserInterface
|
||||
|
||||
control1.ReleaseKeyboardFocus();
|
||||
Assert.That(_userInterfaceManager.KeyboardFocused, NUnit.Framework.Is.Null);
|
||||
|
||||
control1.Dispose();
|
||||
control2.Dispose();
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -169,9 +162,6 @@ namespace Robust.UnitTesting.Client.UserInterface
|
||||
Assert.That(_userInterfaceManager.KeyboardFocused, NUnit.Framework.Is.EqualTo(control2));
|
||||
control2.ReleaseKeyboardFocus();
|
||||
Assert.That(_userInterfaceManager.KeyboardFocused, NUnit.Framework.Is.Null);
|
||||
|
||||
control1.Dispose();
|
||||
control2.Dispose();
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -186,9 +176,6 @@ namespace Robust.UnitTesting.Client.UserInterface
|
||||
Assert.That(_userInterfaceManager.KeyboardFocused, NUnit.Framework.Is.EqualTo(control1));
|
||||
_userInterfaceManager.ReleaseKeyboardFocus();
|
||||
Assert.That(_userInterfaceManager.KeyboardFocused, NUnit.Framework.Is.Null);
|
||||
|
||||
control1.Dispose();
|
||||
control2.Dispose();
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -226,7 +213,7 @@ namespace Robust.UnitTesting.Client.UserInterface
|
||||
_userInterfaceManager.ReleaseKeyboardFocus();
|
||||
Assert.That(_userInterfaceManager.KeyboardFocused, NUnit.Framework.Is.Null);
|
||||
|
||||
control.Dispose();
|
||||
control.Orphan();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -253,7 +240,7 @@ namespace Robust.UnitTesting.Client.UserInterface
|
||||
|
||||
Assert.That(_userInterfaceManager.KeyboardFocused, NUnit.Framework.Is.Null);
|
||||
|
||||
control.Dispose();
|
||||
control.Orphan();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace Robust.UnitTesting
|
||||
public GameControllerOptions Options { get; } = new();
|
||||
public bool ContentStart { get; set; }
|
||||
|
||||
public event Action<FrameEventArgs>? TickUpdateOverride;
|
||||
public event Action<FrameEventArgs>? TickUpdateOverride { add { } remove { } }
|
||||
|
||||
public void Shutdown(string? reason = null)
|
||||
{
|
||||
|
||||
@@ -11,8 +11,6 @@ using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Timing;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
// ReSharper disable AccessToStaticMemberViaDerivedType
|
||||
|
||||
namespace Robust.UnitTesting.Server.GameObjects.Components
|
||||
{
|
||||
[TestFixture, Parallelizable]
|
||||
|
||||
@@ -101,7 +101,7 @@ namespace Robust.UnitTesting.Server.GameObjects.Components
|
||||
|
||||
// move the parent, and the child should move with it
|
||||
XformSystem.SetLocalPosition(child, new Vector2(6, 6), childTrans);
|
||||
XformSystem.SetWorldPosition(parentTrans, new Vector2(-8, -8));
|
||||
XformSystem.SetWorldPosition(parent, new Vector2(-8, -8));
|
||||
|
||||
Assert.That(XformSystem.GetWorldPosition(childTrans), NUnit.Framework.Is.EqualTo(new Vector2(-2, -2)));
|
||||
|
||||
@@ -131,8 +131,8 @@ namespace Robust.UnitTesting.Server.GameObjects.Components
|
||||
var child = EntityManager.SpawnEntity(null, InitialPos);
|
||||
var parentTrans = EntityManager.GetComponent<TransformComponent>(parent);
|
||||
var childTrans = EntityManager.GetComponent<TransformComponent>(child);
|
||||
XformSystem.SetWorldPosition(parentTrans, new Vector2(5, 5));
|
||||
XformSystem.SetWorldPosition(childTrans, new Vector2(6, 6));
|
||||
XformSystem.SetWorldPosition(parent, new Vector2(5, 5));
|
||||
XformSystem.SetWorldPosition(child, new Vector2(6, 6));
|
||||
|
||||
// Act
|
||||
var oldWpos = XformSystem.GetWorldPosition(childTrans);
|
||||
@@ -156,9 +156,9 @@ namespace Robust.UnitTesting.Server.GameObjects.Components
|
||||
var parentTrans = EntityManager.GetComponent<TransformComponent>(parent);
|
||||
var childOneTrans = EntityManager.GetComponent<TransformComponent>(childOne);
|
||||
var childTwoTrans = EntityManager.GetComponent<TransformComponent>(childTwo);
|
||||
XformSystem.SetWorldPosition(parentTrans, new Vector2(1, 1));
|
||||
XformSystem.SetWorldPosition(childOneTrans, new Vector2(2, 2));
|
||||
XformSystem.SetWorldPosition(childTwoTrans, new Vector2(3, 3));
|
||||
XformSystem.SetWorldPosition(parent, new Vector2(1, 1));
|
||||
XformSystem.SetWorldPosition(childOne, new Vector2(2, 2));
|
||||
XformSystem.SetWorldPosition(childTwo, new Vector2(3, 3));
|
||||
|
||||
// Act
|
||||
var oldWpos = XformSystem.GetWorldPosition(childOneTrans);
|
||||
@@ -188,8 +188,8 @@ namespace Robust.UnitTesting.Server.GameObjects.Components
|
||||
var child = EntityManager.SpawnEntity(null, InitialPos);
|
||||
var parentTrans = EntityManager.GetComponent<TransformComponent>(parent);
|
||||
var childTrans = EntityManager.GetComponent<TransformComponent>(child);
|
||||
XformSystem.SetWorldPosition(parentTrans, new Vector2(0, 0));
|
||||
XformSystem.SetWorldPosition(childTrans, new Vector2(2, 0));
|
||||
XformSystem.SetWorldPosition(parent, new Vector2(0, 0));
|
||||
XformSystem.SetWorldPosition(child, new Vector2(2, 0));
|
||||
XformSystem.SetParent(child, childTrans, parent, parentXform: parentTrans);
|
||||
|
||||
//Act
|
||||
@@ -215,8 +215,8 @@ namespace Robust.UnitTesting.Server.GameObjects.Components
|
||||
var child = EntityManager.SpawnEntity(null, InitialPos);
|
||||
var parentTrans = EntityManager.GetComponent<TransformComponent>(parent);
|
||||
var childTrans = EntityManager.GetComponent<TransformComponent>(child);
|
||||
XformSystem.SetWorldPosition(parentTrans, new Vector2(1, 1));
|
||||
XformSystem.SetWorldPosition(childTrans, new Vector2(2, 1));
|
||||
XformSystem.SetWorldPosition(parent, new Vector2(1, 1));
|
||||
XformSystem.SetWorldPosition(child, new Vector2(2, 1));
|
||||
XformSystem.SetParent(child, childTrans, parent, parentXform: parentTrans);
|
||||
|
||||
//Act
|
||||
@@ -248,10 +248,10 @@ namespace Robust.UnitTesting.Server.GameObjects.Components
|
||||
var node3Trans = EntityManager.GetComponent<TransformComponent>(node3);
|
||||
var node4Trans = EntityManager.GetComponent<TransformComponent>(node4);
|
||||
|
||||
XformSystem.SetWorldPosition(node1Trans, new Vector2(0, 0));
|
||||
XformSystem.SetWorldPosition(node2Trans, new Vector2(1, 1));
|
||||
XformSystem.SetWorldPosition(node3Trans, new Vector2(2, 2));
|
||||
XformSystem.SetWorldPosition(node4Trans, new Vector2(0, 2));
|
||||
XformSystem.SetWorldPosition(node1, new Vector2(0, 0));
|
||||
XformSystem.SetWorldPosition(node2, new Vector2(1, 1));
|
||||
XformSystem.SetWorldPosition(node3, new Vector2(2, 2));
|
||||
XformSystem.SetWorldPosition(node4, new Vector2(0, 2));
|
||||
|
||||
XformSystem.SetParent(node2, node2Trans, node1, parentXform: node1Trans);
|
||||
XformSystem.SetParent(node3, node3Trans, node2, parentXform: node2Trans);
|
||||
@@ -285,9 +285,9 @@ namespace Robust.UnitTesting.Server.GameObjects.Components
|
||||
var node2Trans = EntityManager.GetComponent<TransformComponent>(node2);
|
||||
var node3Trans = EntityManager.GetComponent<TransformComponent>(node3);
|
||||
|
||||
XformSystem.SetWorldPosition(node1Trans, new Vector2(0, 0));
|
||||
XformSystem.SetWorldPosition(node2Trans, new Vector2(1, 1));
|
||||
XformSystem.SetWorldPosition(node3Trans, new Vector2(2, 2));
|
||||
XformSystem.SetWorldPosition(node1, new Vector2(0, 0));
|
||||
XformSystem.SetWorldPosition(node2, new Vector2(1, 1));
|
||||
XformSystem.SetWorldPosition(node3, new Vector2(2, 2));
|
||||
|
||||
XformSystem.SetParent(node1, node1Trans, node2, parentXform: node2Trans);
|
||||
XformSystem.SetParent(node2, node2Trans, node3, parentXform: node3Trans);
|
||||
@@ -330,9 +330,9 @@ namespace Robust.UnitTesting.Server.GameObjects.Components
|
||||
var node2Trans = EntityManager.GetComponent<TransformComponent>(node2);
|
||||
var node3Trans = EntityManager.GetComponent<TransformComponent>(node3);
|
||||
|
||||
XformSystem.SetWorldPosition(node1Trans, new Vector2(0, 0));
|
||||
XformSystem.SetWorldPosition(node2Trans, new Vector2(1, 1));
|
||||
XformSystem.SetWorldPosition(node3Trans, new Vector2(2, 2));
|
||||
XformSystem.SetWorldPosition(node1, new Vector2(0, 0));
|
||||
XformSystem.SetWorldPosition(node2, new Vector2(1, 1));
|
||||
XformSystem.SetWorldPosition(node3, new Vector2(2, 2));
|
||||
|
||||
XformSystem.SetParent(node2, node2Trans, node1, parentXform: node1Trans);
|
||||
XformSystem.SetParent(node3, node3Trans, node2, parentXform: node2Trans);
|
||||
@@ -379,10 +379,10 @@ namespace Robust.UnitTesting.Server.GameObjects.Components
|
||||
var node3Trans = EntityManager.GetComponent<TransformComponent>(node3);
|
||||
var node4Trans = EntityManager.GetComponent<TransformComponent>(node4);
|
||||
|
||||
XformSystem.SetWorldPosition(node1Trans, new Vector2(0, 0));
|
||||
XformSystem.SetWorldPosition(node2Trans, new Vector2(1, 1));
|
||||
XformSystem.SetWorldPosition(node3Trans, new Vector2(2, 2));
|
||||
XformSystem.SetWorldPosition(node4Trans, new Vector2(0, 2));
|
||||
XformSystem.SetWorldPosition(node1, new Vector2(0, 0));
|
||||
XformSystem.SetWorldPosition(node2, new Vector2(1, 1));
|
||||
XformSystem.SetWorldPosition(node3, new Vector2(2, 2));
|
||||
XformSystem.SetWorldPosition(node4, new Vector2(0, 2));
|
||||
|
||||
XformSystem.SetParent(node2, node2Trans, node1, parentXform: node1Trans);
|
||||
XformSystem.SetParent(node3, node3Trans, node2, parentXform: node2Trans);
|
||||
@@ -390,7 +390,7 @@ namespace Robust.UnitTesting.Server.GameObjects.Components
|
||||
|
||||
//Act
|
||||
node1Trans.LocalRotation = new Angle(MathHelper.Pi / 6.37);
|
||||
XformSystem.SetWorldPosition(node1Trans, new Vector2(1, 1));
|
||||
XformSystem.SetWorldPosition(node1, new Vector2(1, 1));
|
||||
|
||||
var worldMat = XformSystem.GetWorldMatrix(node4Trans);
|
||||
var invWorldMat = XformSystem.GetInvWorldMatrix(node4Trans);
|
||||
|
||||
@@ -30,6 +30,7 @@ public sealed class PvsSystemTests : RobustIntegrationTest
|
||||
var confMan = server.ResolveDependency<IConfigurationManager>();
|
||||
var sPlayerMan = server.ResolveDependency<ISharedPlayerManager>();
|
||||
var xforms = sEntMan.System<SharedTransformSystem>();
|
||||
var maps = sEntMan.System<SharedMapSystem>();
|
||||
|
||||
var cEntMan = client.ResolveDependency<IEntityManager>();
|
||||
var netMan = client.ResolveDependency<IClientNetManager>();
|
||||
@@ -52,7 +53,7 @@ public sealed class PvsSystemTests : RobustIntegrationTest
|
||||
{
|
||||
map = server.System<SharedMapSystem>().CreateMap(out var mapId);
|
||||
var gridComp = mapMan.CreateGridEntity(mapId);
|
||||
gridComp.Comp.SetTile(Vector2i.Zero, new Tile(1));
|
||||
maps.SetTile(gridComp, Vector2i.Zero, new Tile(1));
|
||||
grid = gridComp.Owner;
|
||||
});
|
||||
|
||||
|
||||
@@ -77,6 +77,32 @@ namespace Robust.UnitTesting.Server
|
||||
EntityUid SpawnEntity(string? protoId, MapCoordinates coordinates);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Helper methods for working with <see cref="ISimulation"/>.
|
||||
/// </summary>
|
||||
internal static class SimulationExtensions
|
||||
{
|
||||
public static T System<T>(this ISimulation simulation) where T : IEntitySystem
|
||||
{
|
||||
return simulation.Resolve<IEntitySystemManager>().GetEntitySystem<T>();
|
||||
}
|
||||
|
||||
public static bool HasComp<T>(this ISimulation simulation, EntityUid entity) where T : IComponent
|
||||
{
|
||||
return simulation.Resolve<IEntityManager>().HasComponent<T>(entity);
|
||||
}
|
||||
|
||||
public static T Comp<T>(this ISimulation simulation, EntityUid entity) where T : IComponent
|
||||
{
|
||||
return simulation.Resolve<IEntityManager>().GetComponent<T>(entity);
|
||||
}
|
||||
|
||||
public static TransformComponent Transform(this ISimulation simulation, EntityUid entity)
|
||||
{
|
||||
return simulation.Comp<TransformComponent>(entity);
|
||||
}
|
||||
}
|
||||
|
||||
public delegate void DiContainerDelegate(IDependencyCollection diContainer);
|
||||
|
||||
public delegate void CompRegistrationDelegate(IComponentFactory factory);
|
||||
|
||||
@@ -3,8 +3,6 @@ using NUnit.Framework;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
|
||||
// ReSharper disable AccessToStaticMemberViaDerivedType
|
||||
|
||||
namespace Robust.UnitTesting.Shared.GameObjects
|
||||
{
|
||||
[TestFixture]
|
||||
|
||||
@@ -12,8 +12,6 @@ using Robust.Shared.Map;
|
||||
using Robust.Shared.Network;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
// ReSharper disable AccessToStaticMemberViaDerivedType
|
||||
|
||||
namespace Robust.UnitTesting.Shared.GameObjects
|
||||
{
|
||||
public sealed class ContainerTests : RobustIntegrationTest
|
||||
|
||||
@@ -81,10 +81,7 @@ namespace Robust.UnitTesting.Shared.GameObjects
|
||||
var (sim, coords) = SimulationFactory();
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
var entity = entMan.SpawnEntity(null, coords);
|
||||
var component = new DummyComponent()
|
||||
{
|
||||
Owner = entity
|
||||
};
|
||||
var component = new DummyComponent();
|
||||
|
||||
// Act
|
||||
entMan.AddComponent(entity, component);
|
||||
@@ -101,10 +98,7 @@ namespace Robust.UnitTesting.Shared.GameObjects
|
||||
var (sim, coords) = SimulationFactory();
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
var entity = entMan.SpawnEntity(null, coords);
|
||||
var component = new DummyComponent()
|
||||
{
|
||||
Owner = entity
|
||||
};
|
||||
var component = new DummyComponent();
|
||||
|
||||
// Act
|
||||
entMan.AddComponent(entity, component, true);
|
||||
@@ -121,10 +115,10 @@ namespace Robust.UnitTesting.Shared.GameObjects
|
||||
var (sim, coords) = SimulationFactory();
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
var entity = entMan.SpawnEntity(null, coords);
|
||||
var firstComp = new DummyComponent {Owner = entity};
|
||||
var firstComp = new DummyComponent();
|
||||
entMan.AddComponent(entity, firstComp);
|
||||
entMan.RemoveComponent<DummyComponent>(entity);
|
||||
var secondComp = new DummyComponent { Owner = entity };
|
||||
var secondComp = new DummyComponent();
|
||||
|
||||
// Act
|
||||
entMan.AddComponent(entity, secondComp);
|
||||
|
||||
@@ -13,15 +13,12 @@ using Robust.Shared.Physics.Systems;
|
||||
using Robust.Shared.Reflection;
|
||||
using Robust.UnitTesting.Server;
|
||||
|
||||
// ReSharper disable AccessToStaticMemberViaDerivedType
|
||||
|
||||
namespace Robust.UnitTesting.Shared.GameObjects.Systems
|
||||
{
|
||||
[TestFixture, Parallelizable]
|
||||
public sealed partial class AnchoredSystemTests
|
||||
{
|
||||
private sealed class Subscriber : IEntityEventSubscriber { }
|
||||
|
||||
private const string Prototypes = @"
|
||||
- type: entity
|
||||
name: anchoredEnt
|
||||
@@ -30,7 +27,7 @@ namespace Robust.UnitTesting.Shared.GameObjects.Systems
|
||||
- type: Transform
|
||||
anchored: true";
|
||||
|
||||
private static (ISimulation, EntityUid gridId, MapCoordinates) SimulationFactory()
|
||||
private static (ISimulation, Entity<MapGridComponent> grid, MapCoordinates, SharedTransformSystem xformSys, SharedMapSystem mapSys) SimulationFactory()
|
||||
{
|
||||
var sim = RobustServerSimulation
|
||||
.NewSimulation()
|
||||
@@ -49,7 +46,7 @@ namespace Robust.UnitTesting.Shared.GameObjects.Systems
|
||||
// Add grid 1, as the default grid to anchor things to.
|
||||
var grid = mapManager.CreateGridEntity(testMapId);
|
||||
|
||||
return (sim, grid, coords);
|
||||
return (sim, grid, coords, sim.System<SharedTransformSystem>(), sim.System<SharedMapSystem>());
|
||||
}
|
||||
|
||||
// An entity is anchored to the tile it is over on the target grid.
|
||||
@@ -68,25 +65,23 @@ namespace Robust.UnitTesting.Shared.GameObjects.Systems
|
||||
[Test]
|
||||
public void OnAnchored_WorldPosition_TileCenter()
|
||||
{
|
||||
var (sim, gridId, coordinates) = SimulationFactory();
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
var (sim, grid, coordinates, xformSys, mapSys) = SimulationFactory();
|
||||
|
||||
// can only be anchored to a tile
|
||||
var grid = entMan.GetComponent<MapGridComponent>(gridId);
|
||||
grid.SetTile(grid.TileIndicesFor(coordinates), new Tile(1));
|
||||
mapSys.SetTile(grid, mapSys.TileIndicesFor(grid, coordinates), new Tile(1));
|
||||
|
||||
var ent1 = entMan.SpawnEntity(null, coordinates); // this raises MoveEvent, subscribe after
|
||||
var ent1 = sim.SpawnEntity(null, coordinates); // this raises MoveEvent, subscribe after
|
||||
|
||||
// Act
|
||||
entMan.System<MoveEventTestSystem>().ResetCounters();
|
||||
entMan.GetComponent<TransformComponent>(ent1).Anchored = true;
|
||||
Assert.That(entMan.GetComponent<TransformComponent>(ent1).WorldPosition, Is.EqualTo(new Vector2(7.5f, 7.5f))); // centered on tile
|
||||
entMan.System<MoveEventTestSystem>().AssertMoved(false);
|
||||
sim.System<MoveEventTestSystem>().ResetCounters();
|
||||
xformSys.AnchorEntity(ent1);
|
||||
Assert.That(xformSys.GetWorldPosition(ent1), Is.EqualTo(new Vector2(7.5f, 7.5f))); // centered on tile
|
||||
sim.System<MoveEventTestSystem>().AssertMoved(false);
|
||||
}
|
||||
|
||||
[ComponentProtoName("AnchorOnInit")]
|
||||
[Reflect(false)]
|
||||
private sealed partial class AnchorOnInitComponent : Component { };
|
||||
private sealed partial class AnchorOnInitComponent : Component;
|
||||
|
||||
[Reflect(false)]
|
||||
private sealed class AnchorOnInitTestSystem : EntitySystem
|
||||
@@ -117,9 +112,9 @@ namespace Robust.UnitTesting.Shared.GameObjects.Systems
|
||||
_transform.OnGlobalMoveEvent -= OnMove;
|
||||
}
|
||||
|
||||
public bool FailOnMove = false;
|
||||
public int MoveCounter = 0;
|
||||
public int ParentCounter = 0;
|
||||
public bool FailOnMove;
|
||||
public int MoveCounter;
|
||||
public int ParentCounter;
|
||||
|
||||
private void OnMove(ref MoveEvent ev)
|
||||
{
|
||||
@@ -163,25 +158,27 @@ namespace Robust.UnitTesting.Shared.GameObjects.Systems
|
||||
.RegisterComponents(f => f.RegisterClass<AnchorOnInitComponent>())
|
||||
.InitializeInstance();
|
||||
|
||||
var mapSys = sim.System<SharedMapSystem>();
|
||||
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
var mapMan = sim.Resolve<IMapManager>();
|
||||
var mapId = sim.CreateMap().MapId;
|
||||
var grid = mapMan.CreateGrid(mapId);
|
||||
var grid = mapMan.CreateGridEntity(mapId);
|
||||
var coordinates = new MapCoordinates(new Vector2(7, 7), mapId);
|
||||
var pos = grid.TileIndicesFor(coordinates);
|
||||
grid.SetTile(pos, new Tile(1));
|
||||
var pos = mapSys.TileIndicesFor(grid, coordinates);
|
||||
mapSys.SetTile(grid, pos, new Tile(1));
|
||||
|
||||
var ent1 = entMan.SpawnEntity(null, coordinates);
|
||||
Assert.That(entMan.GetComponent<TransformComponent>(ent1).Anchored, Is.False);
|
||||
Assert.That(!grid.GetAnchoredEntities(pos).Any());
|
||||
Assert.That(sim.Transform(ent1).Anchored, Is.False);
|
||||
Assert.That(!mapSys.GetAnchoredEntities(grid, pos).Any());
|
||||
entMan.DeleteEntity(ent1);
|
||||
|
||||
var ent2 = entMan.CreateEntityUninitialized(null, coordinates);
|
||||
entMan.AddComponent<AnchorOnInitComponent>(ent2);
|
||||
entMan.InitializeAndStartEntity(ent2);
|
||||
Assert.That(entMan.GetComponent<TransformComponent>(ent2).Anchored);
|
||||
Assert.That(grid.GetAnchoredEntities(pos).Count(), Is.EqualTo(1));
|
||||
Assert.That(grid.GetAnchoredEntities(pos).Contains(ent2));
|
||||
Assert.That(sim.Transform(ent2).Anchored);
|
||||
Assert.That(mapSys.GetAnchoredEntities(grid, pos).Count(), Is.EqualTo(1));
|
||||
Assert.That(mapSys.GetAnchoredEntities(grid, pos).Contains(ent2));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -190,22 +187,20 @@ namespace Robust.UnitTesting.Shared.GameObjects.Systems
|
||||
[Test]
|
||||
public void OnAnchored_Parent_SetToGrid()
|
||||
{
|
||||
var (sim, gridId, coordinates) = SimulationFactory();
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
var (sim, grid, coordinates, xformSys, mapSys) = SimulationFactory();
|
||||
|
||||
// can only be anchored to a tile
|
||||
var grid = entMan.GetComponent<MapGridComponent>(gridId);
|
||||
grid.SetTile(grid.TileIndicesFor(coordinates), new Tile(1));
|
||||
mapSys.SetTile(grid, mapSys.TileIndicesFor(grid, coordinates), new Tile(1));
|
||||
|
||||
var traversal = entMan.System<SharedGridTraversalSystem>();
|
||||
var traversal = sim.System<SharedGridTraversalSystem>();
|
||||
traversal.Enabled = false;
|
||||
var ent1 = entMan.SpawnEntity(null, coordinates); // this raises MoveEvent, subscribe after
|
||||
var ent1 = sim.SpawnEntity(null, coordinates); // this raises MoveEvent, subscribe after
|
||||
|
||||
// Act
|
||||
entMan.System<MoveEventTestSystem>().ResetCounters();
|
||||
entMan.GetComponent<TransformComponent>(ent1).Anchored = true;
|
||||
Assert.That(entMan.GetComponent<TransformComponent>(ent1).ParentUid, Is.EqualTo(grid.Owner));
|
||||
entMan.System<MoveEventTestSystem>().AssertMoved();
|
||||
sim.System<MoveEventTestSystem>().ResetCounters();
|
||||
sim.Transform(ent1).Anchored = true;
|
||||
Assert.That(sim.Transform(ent1).ParentUid, Is.EqualTo(grid.Owner));
|
||||
sim.System<MoveEventTestSystem>().AssertMoved();
|
||||
traversal.Enabled = true;
|
||||
}
|
||||
|
||||
@@ -215,19 +210,17 @@ namespace Robust.UnitTesting.Shared.GameObjects.Systems
|
||||
[Test]
|
||||
public void OnAnchored_EmptyTile_Nop()
|
||||
{
|
||||
var (sim, gridId, coords) = SimulationFactory();
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
var (sim, grid, coords, xformSys, mapSys) = SimulationFactory();
|
||||
|
||||
var grid = entMan.GetComponent<MapGridComponent>(gridId);
|
||||
var ent1 = entMan.SpawnEntity(null, coords);
|
||||
var tileIndices = grid.TileIndicesFor(entMan.GetComponent<TransformComponent>(ent1).Coordinates);
|
||||
grid.SetTile(tileIndices, Tile.Empty);
|
||||
var ent1 = sim.SpawnEntity(null, coords);
|
||||
var tileIndices = mapSys.TileIndicesFor(grid, sim.Transform(ent1).Coordinates);
|
||||
mapSys.SetTile(grid, tileIndices, Tile.Empty);
|
||||
|
||||
// Act
|
||||
entMan.GetComponent<TransformComponent>(ent1).Anchored = true;
|
||||
xformSys.AnchorEntity(ent1);
|
||||
|
||||
Assert.That(grid.GetAnchoredEntities(tileIndices).Count(), Is.EqualTo(0));
|
||||
Assert.That(grid.GetTileRef(tileIndices).Tile, Is.EqualTo(Tile.Empty));
|
||||
Assert.That(mapSys.GetAnchoredEntities(grid, tileIndices).Count(), Is.EqualTo(0));
|
||||
Assert.That(mapSys.GetTileRef(grid, tileIndices).Tile, Is.EqualTo(Tile.Empty));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -237,22 +230,20 @@ namespace Robust.UnitTesting.Shared.GameObjects.Systems
|
||||
[Test]
|
||||
public void OnAnchored_NonEmptyTile_Anchors()
|
||||
{
|
||||
var (sim, gridId, coords) = SimulationFactory();
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
var (sim, grid, coords, xformSys, mapSys) = SimulationFactory();
|
||||
|
||||
var grid = entMan.GetComponent<MapGridComponent>(gridId);
|
||||
var ent1 = entMan.SpawnEntity(null, coords);
|
||||
var tileIndices = grid.TileIndicesFor(entMan.GetComponent<TransformComponent>(ent1).Coordinates);
|
||||
grid.SetTile(tileIndices, new Tile(1));
|
||||
var ent1 = sim.SpawnEntity(null, coords);
|
||||
var tileIndices = mapSys.TileIndicesFor(grid, sim.Transform(ent1).Coordinates);
|
||||
mapSys.SetTile(grid, tileIndices, new Tile(1));
|
||||
|
||||
// Act
|
||||
entMan.GetComponent<TransformComponent>(ent1).Anchored = true;
|
||||
sim.Transform(ent1).Anchored = true;
|
||||
|
||||
Assert.That(grid.GetAnchoredEntities(tileIndices).First(), Is.EqualTo(ent1));
|
||||
Assert.That(grid.GetTileRef(tileIndices).Tile, Is.Not.EqualTo(Tile.Empty));
|
||||
Assert.That(entMan.HasComponent<PhysicsComponent>(ent1), Is.False);
|
||||
Assert.That(mapSys.GetAnchoredEntities(grid, tileIndices).First(), Is.EqualTo(ent1));
|
||||
Assert.That(mapSys.GetTileRef(grid, tileIndices).Tile, Is.Not.EqualTo(Tile.Empty));
|
||||
Assert.That(sim.HasComp<PhysicsComponent>(ent1), Is.False);
|
||||
var tempQualifier = grid.Owner;
|
||||
Assert.That(entMan.HasComponent<PhysicsComponent>(tempQualifier), Is.True);
|
||||
Assert.That(sim.HasComp<PhysicsComponent>(tempQualifier), Is.True);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -263,26 +254,24 @@ namespace Robust.UnitTesting.Shared.GameObjects.Systems
|
||||
[Test]
|
||||
public void Anchored_SetPosition_Nop()
|
||||
{
|
||||
var (sim, gridId, coordinates) = SimulationFactory();
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
var (sim, grid, coordinates, xformSys, mapSys) = SimulationFactory();
|
||||
|
||||
// coordinates are already tile centered to prevent snapping and MoveEvent
|
||||
coordinates = coordinates.Offset(new Vector2(0.5f, 0.5f));
|
||||
|
||||
// can only be anchored to a tile
|
||||
var grid = entMan.GetComponent<MapGridComponent>(gridId);
|
||||
grid.SetTile(grid.TileIndicesFor(coordinates), new Tile(1));
|
||||
mapSys.SetTile(grid, mapSys.TileIndicesFor(grid, coordinates), new Tile(1));
|
||||
|
||||
var ent1 = entMan.SpawnEntity(null, coordinates); // this raises MoveEvent, subscribe after
|
||||
entMan.GetComponent<TransformComponent>(ent1).Anchored = true; // Anchoring will change parent if needed, raising MoveEvent, subscribe after
|
||||
entMan.System<MoveEventTestSystem>().FailOnMove = true;
|
||||
var ent1 = sim.SpawnEntity(null, coordinates); // this raises MoveEvent, subscribe after
|
||||
sim.Transform(ent1).Anchored = true;
|
||||
sim.System<MoveEventTestSystem>().FailOnMove = true;
|
||||
|
||||
// Act
|
||||
entMan.GetComponent<TransformComponent>(ent1).WorldPosition = new Vector2(99, 99);
|
||||
entMan.GetComponent<TransformComponent>(ent1).LocalPosition = new Vector2(99, 99);
|
||||
sim.Transform(ent1).WorldPosition = new Vector2(99, 99);
|
||||
sim.Transform(ent1).LocalPosition = new Vector2(99, 99);
|
||||
|
||||
Assert.That(entMan.GetComponent<TransformComponent>(ent1).MapPosition, Is.EqualTo(coordinates));
|
||||
entMan.System<MoveEventTestSystem>().FailOnMove = false;
|
||||
Assert.That(xformSys.GetMapCoordinates(ent1), Is.EqualTo(coordinates));
|
||||
sim.System<MoveEventTestSystem>().FailOnMove = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -291,23 +280,19 @@ namespace Robust.UnitTesting.Shared.GameObjects.Systems
|
||||
[Test]
|
||||
public void Anchored_ChangeParent_Unanchors()
|
||||
{
|
||||
var (sim, gridId, coordinates) = SimulationFactory();
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
var mapMan = sim.Resolve<IMapManager>();
|
||||
var (sim, grid, coordinates, xformSys, mapSys) = SimulationFactory();
|
||||
|
||||
var grid = entMan.GetComponent<MapGridComponent>(gridId);
|
||||
|
||||
var ent1 = entMan.SpawnEntity(null, coordinates);
|
||||
var tileIndices = grid.TileIndicesFor(entMan.GetComponent<TransformComponent>(ent1).Coordinates);
|
||||
grid.SetTile(tileIndices, new Tile(1));
|
||||
entMan.GetComponent<TransformComponent>(ent1).Anchored = true;
|
||||
var ent1 = sim.SpawnEntity(null, coordinates);
|
||||
var tileIndices = mapSys.TileIndicesFor(grid, sim.Transform(ent1).Coordinates);
|
||||
mapSys.SetTile(grid, tileIndices, new Tile(1));
|
||||
xformSys.AnchorEntity(ent1);
|
||||
|
||||
// Act
|
||||
entMan.EntitySysManager.GetEntitySystem<SharedTransformSystem>().SetParent(ent1, mapMan.GetMapEntityId(coordinates.MapId));
|
||||
xformSys.SetParent(ent1, mapSys.GetMap(coordinates.MapId));
|
||||
|
||||
Assert.That(entMan.GetComponent<TransformComponent>(ent1).Anchored, Is.False);
|
||||
Assert.That(grid.GetAnchoredEntities(tileIndices).Count(), Is.EqualTo(0));
|
||||
Assert.That(grid.GetTileRef(tileIndices).Tile, Is.EqualTo(new Tile(1)));
|
||||
Assert.That(sim.Transform(ent1).Anchored, Is.False);
|
||||
Assert.That(mapSys.GetAnchoredEntities(grid, tileIndices).Count(), Is.EqualTo(0));
|
||||
Assert.That(mapSys.GetTileRef(grid, tileIndices).Tile, Is.EqualTo(new Tile(1)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -318,20 +303,19 @@ namespace Robust.UnitTesting.Shared.GameObjects.Systems
|
||||
[Test]
|
||||
public void Anchored_SetParentSame_Nop()
|
||||
{
|
||||
var (sim, gridId, coords) = SimulationFactory();
|
||||
var (sim, grid, coords, xformSys, mapSys) = SimulationFactory();
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
|
||||
var grid = entMan.GetComponent<MapGridComponent>(gridId);
|
||||
var ent1 = entMan.SpawnEntity(null, coords);
|
||||
var tileIndices = grid.TileIndicesFor(entMan.GetComponent<TransformComponent>(ent1).Coordinates);
|
||||
grid.SetTile(tileIndices, new Tile(1));
|
||||
entMan.GetComponent<TransformComponent>(ent1).Anchored = true;
|
||||
var tileIndices = mapSys.TileIndicesFor(grid, sim.Transform(ent1).Coordinates);
|
||||
mapSys.SetTile(grid, tileIndices, new Tile(1));
|
||||
sim.Transform(ent1).Anchored = true;
|
||||
|
||||
// Act
|
||||
entMan.EntitySysManager.GetEntitySystem<SharedTransformSystem>().SetParent(ent1, grid.Owner);
|
||||
xformSys.SetParent(ent1, grid.Owner);
|
||||
|
||||
Assert.That(grid.GetAnchoredEntities(tileIndices).First(), Is.EqualTo(ent1));
|
||||
Assert.That(grid.GetTileRef(tileIndices).Tile, Is.Not.EqualTo(Tile.Empty));
|
||||
Assert.That(mapSys.GetAnchoredEntities(grid, tileIndices).First(), Is.EqualTo(ent1));
|
||||
Assert.That(mapSys.GetTileRef(grid, tileIndices).Tile, Is.Not.EqualTo(Tile.Empty));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -340,22 +324,20 @@ namespace Robust.UnitTesting.Shared.GameObjects.Systems
|
||||
[Test]
|
||||
public void Anchored_TileToSpace_Unanchors()
|
||||
{
|
||||
var (sim, gridId, coords) = SimulationFactory();
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
var (sim, grid, coords, xformSys, mapSys) = SimulationFactory();
|
||||
|
||||
var grid = entMan.GetComponent<MapGridComponent>(gridId);
|
||||
var ent1 = entMan.SpawnEntity(null, coords);
|
||||
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
|
||||
entMan.GetComponent<TransformComponent>(ent1).Anchored = true;
|
||||
var ent1 = sim.SpawnEntity(null, coords);
|
||||
var tileIndices = mapSys.TileIndicesFor(grid, sim.Transform(ent1).Coordinates);
|
||||
mapSys.SetTile(grid, tileIndices, new Tile(1));
|
||||
mapSys.SetTile(grid, new Vector2i(100, 100), new Tile(1)); // Prevents the grid from being deleted when the Act happens
|
||||
xformSys.AnchorEntity(ent1);
|
||||
|
||||
// Act
|
||||
grid.SetTile(tileIndices, Tile.Empty);
|
||||
mapSys.SetTile(grid, tileIndices, Tile.Empty);
|
||||
|
||||
Assert.That(entMan.GetComponent<TransformComponent>(ent1).Anchored, Is.False);
|
||||
Assert.That(grid.GetAnchoredEntities(tileIndices).Count(), Is.EqualTo(0));
|
||||
Assert.That(grid.GetTileRef(tileIndices).Tile, Is.EqualTo(Tile.Empty));
|
||||
Assert.That(sim.Transform(ent1).Anchored, Is.False);
|
||||
Assert.That(mapSys.GetAnchoredEntities(grid, tileIndices).Count(), Is.EqualTo(0));
|
||||
Assert.That(mapSys.GetTileRef(grid, tileIndices).Tile, Is.EqualTo(Tile.Empty));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -368,25 +350,24 @@ namespace Robust.UnitTesting.Shared.GameObjects.Systems
|
||||
[Test]
|
||||
public void Anchored_AddToContainer_Unanchors()
|
||||
{
|
||||
var (sim, gridId, coords) = SimulationFactory();
|
||||
var (sim, grid, coords, xformSys, mapSys) = SimulationFactory();
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
|
||||
var grid = entMan.GetComponent<MapGridComponent>(gridId);
|
||||
var ent1 = entMan.SpawnEntity(null, coords);
|
||||
var tileIndices = grid.TileIndicesFor(entMan.GetComponent<TransformComponent>(ent1).Coordinates);
|
||||
grid.SetTile(tileIndices, new Tile(1));
|
||||
entMan.GetComponent<TransformComponent>(ent1).Anchored = true;
|
||||
var ent1 = sim.SpawnEntity(null, coords);
|
||||
var tileIndices = mapSys.TileIndicesFor(grid, sim.Transform(ent1).Coordinates);
|
||||
mapSys.SetTile(grid, tileIndices, new Tile(1));
|
||||
xformSys.AnchorEntity(ent1);
|
||||
|
||||
// Act
|
||||
// We purposefully use the grid as container so parent stays the same, reparent will unanchor
|
||||
var containerSys = entMan.System<SharedContainerSystem>();
|
||||
var containerMan = entMan.AddComponent<ContainerManagerComponent>(gridId);
|
||||
var container = containerSys.MakeContainer<Container>(gridId, "TestContainer", containerMan);
|
||||
var containerMan = entMan.AddComponent<ContainerManagerComponent>(grid);
|
||||
var container = containerSys.MakeContainer<Container>(grid, "TestContainer", containerMan);
|
||||
containerSys.Insert(ent1, container);
|
||||
|
||||
Assert.That(entMan.GetComponent<TransformComponent>(ent1).Anchored, Is.False);
|
||||
Assert.That(grid.GetAnchoredEntities(tileIndices).Count(), Is.EqualTo(0));
|
||||
Assert.That(grid.GetTileRef(tileIndices).Tile, Is.EqualTo(new Tile(1)));
|
||||
Assert.That(sim.Transform(ent1).Anchored, Is.False);
|
||||
Assert.That(mapSys.GetAnchoredEntities(grid, tileIndices).Count(), Is.EqualTo(0));
|
||||
Assert.That(mapSys.GetTileRef(grid, tileIndices).Tile, Is.EqualTo(new Tile(1)));
|
||||
Assert.That(container.ContainedEntities.Count, Is.EqualTo(1));
|
||||
}
|
||||
|
||||
@@ -396,14 +377,13 @@ namespace Robust.UnitTesting.Shared.GameObjects.Systems
|
||||
[Test]
|
||||
public void Anchored_AddPhysComp_IsStaticBody()
|
||||
{
|
||||
var (sim, gridId, coords) = SimulationFactory();
|
||||
var (sim, grid, coords, xformSys, mapSys) = SimulationFactory();
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
|
||||
var grid = entMan.GetComponent<MapGridComponent>(gridId);
|
||||
var ent1 = entMan.SpawnEntity(null, coords);
|
||||
var tileIndices = grid.TileIndicesFor(entMan.GetComponent<TransformComponent>(ent1).Coordinates);
|
||||
grid.SetTile(tileIndices, new Tile(1));
|
||||
entMan.GetComponent<TransformComponent>(ent1).Anchored = true;
|
||||
var ent1 = sim.SpawnEntity(null, coords);
|
||||
var tileIndices = mapSys.TileIndicesFor(grid, sim.Transform(ent1).Coordinates);
|
||||
mapSys.SetTile(grid, tileIndices, new Tile(1));
|
||||
xformSys.AnchorEntity(ent1);
|
||||
|
||||
// Act
|
||||
// assumed default body is Dynamic
|
||||
@@ -418,20 +398,19 @@ namespace Robust.UnitTesting.Shared.GameObjects.Systems
|
||||
[Test]
|
||||
public void OnAnchored_HasPhysicsComp_IsStaticBody()
|
||||
{
|
||||
var (sim, gridId, coordinates) = SimulationFactory();
|
||||
var (sim, grid, coordinates, xformSys, mapSys) = SimulationFactory();
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
var physSystem = sim.Resolve<IEntitySystemManager>().GetEntitySystem<SharedPhysicsSystem>();
|
||||
var physSystem = sim.System<SharedPhysicsSystem>();
|
||||
|
||||
// can only be anchored to a tile
|
||||
var grid = entMan.GetComponent<MapGridComponent>(gridId);
|
||||
grid.SetTile(grid.TileIndicesFor(coordinates), new Tile(1));
|
||||
mapSys.SetTile(grid, mapSys.TileIndicesFor(grid, coordinates), new Tile(1));
|
||||
|
||||
var ent1 = entMan.SpawnEntity(null, coordinates);
|
||||
var physComp = entMan.AddComponent<PhysicsComponent>(ent1);
|
||||
physSystem.SetBodyType(ent1, BodyType.Dynamic, body: physComp);
|
||||
|
||||
// Act
|
||||
entMan.GetComponent<TransformComponent>(ent1).Anchored = true;
|
||||
xformSys.AnchorEntity(ent1);
|
||||
|
||||
Assert.That(physComp.BodyType, Is.EqualTo(BodyType.Static));
|
||||
}
|
||||
@@ -442,18 +421,17 @@ namespace Robust.UnitTesting.Shared.GameObjects.Systems
|
||||
[Test]
|
||||
public void OnUnanchored_HasPhysicsComp_IsDynamicBody()
|
||||
{
|
||||
var (sim, gridId, coords) = SimulationFactory();
|
||||
var (sim, grid, coords, xformSys, mapSys) = SimulationFactory();
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
|
||||
var grid = entMan.GetComponent<MapGridComponent>(gridId);
|
||||
var ent1 = entMan.SpawnEntity(null, coords);
|
||||
var tileIndices = grid.TileIndicesFor(entMan.GetComponent<TransformComponent>(ent1).Coordinates);
|
||||
grid.SetTile(tileIndices, new Tile(1));
|
||||
var ent1 = sim.SpawnEntity(null, coords);
|
||||
var tileIndices = mapSys.TileIndicesFor(grid, sim.Transform(ent1).Coordinates);
|
||||
mapSys.SetTile(grid, tileIndices, new Tile(1));
|
||||
var physComp = entMan.AddComponent<PhysicsComponent>(ent1);
|
||||
entMan.GetComponent<TransformComponent>(ent1).Anchored = true;
|
||||
sim.Transform(ent1).Anchored = true;
|
||||
|
||||
// Act
|
||||
entMan.GetComponent<TransformComponent>(ent1).Anchored = false;
|
||||
xformSys.Unanchor(ent1);
|
||||
|
||||
Assert.That(physComp.BodyType, Is.EqualTo(BodyType.Dynamic));
|
||||
}
|
||||
@@ -464,18 +442,15 @@ namespace Robust.UnitTesting.Shared.GameObjects.Systems
|
||||
[Test]
|
||||
public void SpawnAnchored_EmptyTile_Unanchors()
|
||||
{
|
||||
var (sim, gridId, coords) = SimulationFactory();
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
|
||||
var grid = entMan.GetComponent<MapGridComponent>(gridId);
|
||||
var (sim, grid, coords, _, mapSys) = SimulationFactory();
|
||||
|
||||
// Act
|
||||
var ent1 = entMan.SpawnEntity("anchoredEnt", coords);
|
||||
var ent1 = sim.SpawnEntity("anchoredEnt", coords);
|
||||
|
||||
var tileIndices = grid.TileIndicesFor(entMan.GetComponent<TransformComponent>(ent1).Coordinates);
|
||||
Assert.That(grid.GetAnchoredEntities(tileIndices).Count(), Is.EqualTo(0));
|
||||
Assert.That(grid.GetTileRef(tileIndices).Tile, Is.EqualTo(Tile.Empty));
|
||||
Assert.That(entMan.GetComponent<TransformComponent>(ent1).Anchored, Is.False);
|
||||
var tileIndices = mapSys.TileIndicesFor(grid, sim.Transform(ent1).Coordinates);
|
||||
Assert.That(mapSys.GetAnchoredEntities(grid, tileIndices).Count(), Is.EqualTo(0));
|
||||
Assert.That(mapSys.GetTileRef(grid, tileIndices).Tile, Is.EqualTo(Tile.Empty));
|
||||
Assert.That(sim.Transform(ent1).Anchored, Is.False);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -484,25 +459,24 @@ namespace Robust.UnitTesting.Shared.GameObjects.Systems
|
||||
[Test]
|
||||
public void OnAnchored_InContainer_Nop()
|
||||
{
|
||||
var (sim, gridId, coords) = SimulationFactory();
|
||||
var (sim, grid, coords, xformSys, mapSys) = SimulationFactory();
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
|
||||
var grid = entMan.GetComponent<MapGridComponent>(gridId);
|
||||
var ent1 = entMan.SpawnEntity(null, coords);
|
||||
var tileIndices = grid.TileIndicesFor(entMan.GetComponent<TransformComponent>(ent1).Coordinates);
|
||||
grid.SetTile(tileIndices, new Tile(1));
|
||||
var ent1 = sim.SpawnEntity(null, coords);
|
||||
var tileIndices = mapSys.TileIndicesFor(grid, sim.Transform(ent1).Coordinates);
|
||||
mapSys.SetTile(grid, tileIndices, new Tile(1));
|
||||
|
||||
var containerSys = entMan.System<SharedContainerSystem>();
|
||||
var containerMan = entMan.AddComponent<ContainerManagerComponent>(gridId);
|
||||
var container = containerSys.MakeContainer<Container>(gridId, "TestContainer", containerMan);
|
||||
var containerMan = entMan.AddComponent<ContainerManagerComponent>(grid);
|
||||
var container = containerSys.MakeContainer<Container>(grid, "TestContainer", containerMan);
|
||||
containerSys.Insert(ent1, container);
|
||||
|
||||
// Act
|
||||
entMan.GetComponent<TransformComponent>(ent1).Anchored = true;
|
||||
xformSys.AnchorEntity(ent1);
|
||||
|
||||
Assert.That(entMan.GetComponent<TransformComponent>(ent1).Anchored, Is.False);
|
||||
Assert.That(grid.GetAnchoredEntities(tileIndices).Count(), Is.EqualTo(0));
|
||||
Assert.That(grid.GetTileRef(tileIndices).Tile, Is.EqualTo(new Tile(1)));
|
||||
Assert.That(sim.Transform(ent1).Anchored, Is.False);
|
||||
Assert.That(mapSys.GetAnchoredEntities(grid, tileIndices).Count(), Is.EqualTo(0));
|
||||
Assert.That(mapSys.GetTileRef(grid, tileIndices).Tile, Is.EqualTo(new Tile(1)));
|
||||
Assert.That(container.ContainedEntities.Count, Is.EqualTo(1));
|
||||
}
|
||||
|
||||
@@ -512,23 +486,20 @@ namespace Robust.UnitTesting.Shared.GameObjects.Systems
|
||||
[Test]
|
||||
public void Unanchored_Unanchor_Nop()
|
||||
{
|
||||
var (sim, gridId, coordinates) = SimulationFactory();
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
var mapMan = sim.Resolve<IMapManager>();
|
||||
var (sim, grid, coordinates, xformSys, mapSys) = SimulationFactory();
|
||||
|
||||
// can only be anchored to a tile
|
||||
var grid = entMan.GetComponent<MapGridComponent>(gridId);
|
||||
grid.SetTile(grid.TileIndicesFor(coordinates), new Tile(1));
|
||||
mapSys.SetTile(grid, mapSys.TileIndicesFor(grid, coordinates), new Tile(1));
|
||||
|
||||
var traversal = entMan.System<SharedGridTraversalSystem>();
|
||||
var traversal = sim.System<SharedGridTraversalSystem>();
|
||||
traversal.Enabled = false;
|
||||
var ent1 = entMan.SpawnEntity(null, coordinates); // this raises MoveEvent, subscribe after
|
||||
var ent1 = sim.SpawnEntity(null, coordinates); // this raises MoveEvent, subscribe after
|
||||
|
||||
// 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)));
|
||||
entMan.System<MoveEventTestSystem>().FailOnMove = false;
|
||||
sim.System<MoveEventTestSystem>().FailOnMove = true;
|
||||
xformSys.Unanchor(ent1);
|
||||
Assert.That(sim.Transform(ent1).ParentUid, Is.EqualTo(mapSys.GetMap(coordinates.MapId)));
|
||||
sim.System<MoveEventTestSystem>().FailOnMove = false;
|
||||
traversal.Enabled = true;
|
||||
}
|
||||
|
||||
@@ -538,17 +509,16 @@ namespace Robust.UnitTesting.Shared.GameObjects.Systems
|
||||
[Test]
|
||||
public void Anchored_Unanchored_ParentUnchanged()
|
||||
{
|
||||
var (sim, gridId, coordinates) = SimulationFactory();
|
||||
var (sim, grid, coordinates, xformSys, mapSys) = SimulationFactory();
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
|
||||
// can only be anchored to a tile
|
||||
var grid = entMan.GetComponent<MapGridComponent>(gridId);
|
||||
grid.SetTile(grid.TileIndicesFor(coordinates), new Tile(1));
|
||||
var ent1 = entMan.SpawnEntity("anchoredEnt", grid.MapToGrid(coordinates));
|
||||
mapSys.SetTile(grid, mapSys.TileIndicesFor(grid, coordinates), new Tile(1));
|
||||
var ent1 = entMan.SpawnEntity("anchoredEnt", mapSys.MapToGrid(grid, coordinates));
|
||||
|
||||
entMan.GetComponent<TransformComponent>(ent1).Anchored = false;
|
||||
xformSys.Unanchor(ent1);
|
||||
|
||||
Assert.That(entMan.GetComponent<TransformComponent>(ent1).ParentUid, Is.EqualTo(grid.Owner));
|
||||
Assert.That(sim.Transform(ent1).ParentUid, Is.EqualTo(grid.Owner));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Numerics;
|
||||
using NUnit.Framework;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
@@ -21,6 +22,7 @@ namespace Robust.UnitTesting.Shared.GameObjects
|
||||
|
||||
var entManager = server.Resolve<IEntityManager>();
|
||||
entManager.System<SharedMapSystem>().CreateMap(out var mapId);
|
||||
var xform = entManager.System<TransformSystem>();
|
||||
|
||||
var ent1 = entManager.SpawnEntity(null, new MapCoordinates(Vector2.Zero, mapId));
|
||||
var ent2 = entManager.SpawnEntity(null, new MapCoordinates(new Vector2(100f, 0f), mapId));
|
||||
@@ -28,19 +30,19 @@ namespace Robust.UnitTesting.Shared.GameObjects
|
||||
var xform1 = entManager.GetComponent<TransformComponent>(ent1);
|
||||
var xform2 = entManager.GetComponent<TransformComponent>(ent2);
|
||||
|
||||
xform2.AttachParent(xform1);
|
||||
xform.SetParent(ent2, ent1);
|
||||
|
||||
xform1.LocalRotation = MathF.PI;
|
||||
|
||||
var (worldPos, worldRot, worldMatrix) = xform2.GetWorldPositionRotationMatrix();
|
||||
var (worldPos, worldRot, worldMatrix) = xform.GetWorldPositionRotationMatrix(xform2);
|
||||
|
||||
Assert.That(worldPos, Is.EqualTo(xform2.WorldPosition));
|
||||
Assert.That(worldRot, Is.EqualTo(xform2.WorldRotation));
|
||||
Assert.That(worldMatrix, Is.EqualTo(xform2.WorldMatrix));
|
||||
Assert.That(worldPos, Is.EqualTo(xform.GetWorldPosition(xform2)));
|
||||
Assert.That(worldRot, Is.EqualTo(xform.GetWorldRotation(xform2)));
|
||||
Assert.That(worldMatrix, Is.EqualTo(xform.GetWorldMatrix(xform2)));
|
||||
|
||||
var (_, _, invWorldMatrix) = xform2.GetWorldPositionRotationInvMatrix();
|
||||
var (_, _, invWorldMatrix) = xform.GetWorldPositionRotationInvMatrix(xform2);
|
||||
|
||||
Assert.That(invWorldMatrix, Is.EqualTo(xform2.InvWorldMatrix));
|
||||
Assert.That(invWorldMatrix, Is.EqualTo(xform.GetInvWorldMatrix(xform2)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -53,20 +55,21 @@ namespace Robust.UnitTesting.Shared.GameObjects
|
||||
|
||||
var entManager = server.Resolve<IEntityManager>();
|
||||
var mapManager = server.Resolve<IMapManager>();
|
||||
var mapSystem = entManager.System<SharedMapSystem>();
|
||||
var xformSystem = entManager.System<TransformSystem>();
|
||||
|
||||
entManager.System<SharedMapSystem>().CreateMap(out var mapId);
|
||||
mapSystem.CreateMap(out var mapId);
|
||||
var grid = mapManager.CreateGridEntity(mapId);
|
||||
grid.Comp.SetTile(new Vector2i(0, 0), new Tile(1));
|
||||
var gridXform = entManager.GetComponent<TransformComponent>(grid);
|
||||
gridXform.LocalPosition = new Vector2(0f, 100f);
|
||||
mapSystem.SetTile(grid, new Vector2i(0, 0), new Tile(1));
|
||||
xformSystem.SetLocalPosition(grid, new Vector2(0f, 100f));
|
||||
|
||||
var ent1 = entManager.SpawnEntity(null, new EntityCoordinates(grid, Vector2.One * grid.Comp.TileSize / 2));
|
||||
var ent2 = entManager.SpawnEntity(null, new EntityCoordinates(ent1, Vector2.Zero));
|
||||
|
||||
var xform2 = entManager.GetComponent<TransformComponent>(ent2);
|
||||
Assert.That(xform2.WorldPosition, Is.EqualTo(new Vector2(0.5f, 100.5f)));
|
||||
Assert.That(xformSystem.GetWorldPosition(ent2), Is.EqualTo(new Vector2(0.5f, 100.5f)));
|
||||
|
||||
xform2.AttachToGridOrMap();
|
||||
xformSystem.AttachToGridOrMap(ent2);
|
||||
Assert.That(xform2.LocalPosition, Is.EqualTo(Vector2.One * grid.Comp.TileSize / 2));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,8 +10,6 @@ using Robust.Shared.Maths;
|
||||
using Robust.Shared.Network;
|
||||
using Robust.Shared.Player;
|
||||
|
||||
// ReSharper disable AccessToStaticMemberViaDerivedType
|
||||
|
||||
namespace Robust.UnitTesting.Shared.GameState;
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -7,7 +7,6 @@ using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization.Manager;
|
||||
|
||||
// ReSharper disable InconsistentNaming
|
||||
// ReSharper disable AccessToStaticMemberViaDerivedType
|
||||
namespace Robust.UnitTesting.Shared.Map
|
||||
{
|
||||
[TestFixture, Parallelizable, TestOf(typeof(EntityCoordinates))]
|
||||
|
||||
@@ -4,8 +4,6 @@ using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.UnitTesting.Server;
|
||||
|
||||
// ReSharper disable AccessToStaticMemberViaDerivedType
|
||||
|
||||
namespace Robust.UnitTesting.Shared.Map;
|
||||
|
||||
[TestFixture]
|
||||
|
||||
@@ -12,7 +12,6 @@ namespace Robust.UnitTesting.Shared.Maths
|
||||
[Parallelizable(ParallelScope.All | ParallelScope.Fixtures)]
|
||||
[TestFixture]
|
||||
[TestOf(typeof(NumericsHelpers))]
|
||||
[SuppressMessage("ReSharper", "AccessToStaticMemberViaDerivedType")]
|
||||
public sealed class NumericsHelpers_Test
|
||||
{
|
||||
#region Utils
|
||||
|
||||
@@ -15,8 +15,6 @@ using Robust.Shared.Physics.Dynamics;
|
||||
using Robust.Shared.Physics.Systems;
|
||||
using Robust.Shared.Player;
|
||||
|
||||
// ReSharper disable AccessToStaticMemberViaDerivedType
|
||||
|
||||
namespace Robust.UnitTesting.Shared.Physics;
|
||||
|
||||
public sealed class BroadphaseNetworkingTest : RobustIntegrationTest
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using NUnit.Framework;
|
||||
@@ -25,11 +26,13 @@ public sealed class Broadphase_Test
|
||||
var sim = RobustServerSimulation.NewSimulation().InitializeInstance();
|
||||
var entManager = sim.Resolve<IEntityManager>();
|
||||
var mapManager = sim.Resolve<IMapManager>();
|
||||
var mapSys = entManager.System<SharedMapSystem>();
|
||||
var xformSys = entManager.System<SharedTransformSystem>();
|
||||
|
||||
var (mapEnt, mapId) = sim.CreateMap();
|
||||
var grid = mapManager.CreateGridEntity(mapId);
|
||||
|
||||
grid.Comp.SetTile(Vector2i.Zero, new Tile(1));
|
||||
mapSys.SetTile(grid, Vector2i.Zero, new Tile(1));
|
||||
Assert.That(entManager.HasComponent<BroadphaseComponent>(grid));
|
||||
var broadphase = entManager.GetComponent<BroadphaseComponent>(grid);
|
||||
|
||||
@@ -40,7 +43,7 @@ public sealed class Broadphase_Test
|
||||
var broadphaseData = xform.Broadphase;
|
||||
Assert.That(broadphaseData!.Value.Uid, Is.EqualTo(grid.Owner));
|
||||
|
||||
xform.Coordinates = new EntityCoordinates(mapEnt, Vector2.One);
|
||||
xformSys.SetCoordinates(ent, new EntityCoordinates(mapEnt, Vector2.One));
|
||||
Assert.That(broadphase.SundriesTree, Does.Not.Contain(ent));
|
||||
|
||||
Assert.That(entManager.GetComponent<BroadphaseComponent>(mapEnt).SundriesTree, Does.Contain(ent));
|
||||
@@ -59,12 +62,14 @@ public sealed class Broadphase_Test
|
||||
var mapManager = sim.Resolve<IMapManager>();
|
||||
var fixturesSystem = entManager.EntitySysManager.GetEntitySystem<FixtureSystem>();
|
||||
var physicsSystem = entManager.EntitySysManager.GetEntitySystem<SharedPhysicsSystem>();
|
||||
var mapSys = entManager.System<SharedMapSystem>();
|
||||
var xformSys = entManager.System<SharedTransformSystem>();
|
||||
|
||||
var (mapEnt, mapId) = sim.CreateMap();
|
||||
var grid = mapManager.CreateGridEntity(mapId);
|
||||
var gridUid = grid.Owner;
|
||||
|
||||
grid.Comp.SetTile(Vector2i.Zero, new Tile(1));
|
||||
mapSys.SetTile(grid, Vector2i.Zero, new Tile(1));
|
||||
Assert.That(entManager.HasComponent<BroadphaseComponent>(gridUid));
|
||||
var broadphase = entManager.GetComponent<BroadphaseComponent>(gridUid);
|
||||
|
||||
@@ -90,7 +95,7 @@ public sealed class Broadphase_Test
|
||||
Assert.That(broadphase.StaticTree.GetProxy(fixture.Proxies[0].ProxyId)!.Equals(fixture.Proxies[0]));
|
||||
|
||||
// Now check we go to the map's tree correctly.
|
||||
xform.Coordinates = new EntityCoordinates(mapEnt, Vector2.One);
|
||||
xformSys.SetCoordinates(ent, new EntityCoordinates(mapEnt, Vector2.One));
|
||||
Assert.That(entManager.GetComponent<BroadphaseComponent>(mapEnt).StaticTree.GetProxy(fixture.Proxies[0].ProxyId)!.Equals(fixture.Proxies[0]));
|
||||
Assert.That(xform.Broadphase!.Value.Uid.Equals(mapEnt));
|
||||
}
|
||||
@@ -107,21 +112,22 @@ public sealed class Broadphase_Test
|
||||
var sim = RobustServerSimulation.NewSimulation().InitializeInstance();
|
||||
var entManager = sim.Resolve<IEntityManager>();
|
||||
var mapManager = sim.Resolve<IMapManager>();
|
||||
var mapSys = entManager.System<SharedMapSystem>();
|
||||
var xformSys = entManager.System<SharedTransformSystem>();
|
||||
|
||||
var mapId1 = sim.CreateMap().MapId;
|
||||
var mapId2 = sim.CreateMap().MapId;
|
||||
var (map1, mapId1) = sim.CreateMap();
|
||||
var (map2, _) = sim.CreateMap();
|
||||
var grid = mapManager.CreateGridEntity(mapId1);
|
||||
var xform = entManager.GetComponent<TransformComponent>(grid);
|
||||
|
||||
grid.Comp.SetTile(Vector2i.Zero, new Tile(1));
|
||||
var mapBroadphase1 = entManager.GetComponent<BroadphaseComponent>(mapManager.GetMapEntityId(mapId1));
|
||||
var mapBroadphase2 = entManager.GetComponent<BroadphaseComponent>(mapManager.GetMapEntityId(mapId2));
|
||||
mapSys.SetTile(grid, Vector2i.Zero, new Tile(1));
|
||||
var mapBroadphase1 = entManager.GetComponent<BroadphaseComponent>(map1);
|
||||
var mapBroadphase2 = entManager.GetComponent<BroadphaseComponent>(map2);
|
||||
entManager.TickUpdate(0.016f, false);
|
||||
#pragma warning disable NUnit2046
|
||||
Assert.That(mapBroadphase1.DynamicTree.Count, Is.EqualTo(0));
|
||||
#pragma warning restore NUnit2046
|
||||
|
||||
xform.Coordinates = new EntityCoordinates(mapManager.GetMapEntityId(mapId2), Vector2.Zero);
|
||||
xformSys.SetCoordinates(grid, new EntityCoordinates(map1, Vector2.One));
|
||||
entManager.TickUpdate(0.016f, false);
|
||||
#pragma warning disable NUnit2046
|
||||
Assert.That(mapBroadphase2.DynamicTree.Count, Is.EqualTo(0));
|
||||
@@ -140,13 +146,14 @@ public sealed class Broadphase_Test
|
||||
var system = entManager.EntitySysManager;
|
||||
var physicsSystem = system.GetEntitySystem<SharedPhysicsSystem>();
|
||||
var lookup = system.GetEntitySystem<EntityLookupSystem>();
|
||||
var mapSys = entManager.System<SharedMapSystem>();
|
||||
|
||||
var mapId = sim.CreateMap().MapId;
|
||||
var (map, mapId) = sim.CreateMap();
|
||||
var grid = mapManager.CreateGridEntity(mapId);
|
||||
|
||||
grid.Comp.SetTile(Vector2i.Zero, new Tile(1));
|
||||
mapSys.SetTile(grid, Vector2i.Zero, new Tile(1));
|
||||
var gridBroadphase = entManager.GetComponent<BroadphaseComponent>(grid);
|
||||
var mapBroadphase = entManager.GetComponent<BroadphaseComponent>(mapManager.GetMapEntityId(mapId));
|
||||
var mapBroadphase = entManager.GetComponent<BroadphaseComponent>(map);
|
||||
|
||||
Assert.That(entManager.EntityQuery<BroadphaseComponent>(true).Count(), Is.EqualTo(2));
|
||||
|
||||
@@ -169,7 +176,7 @@ public sealed class Broadphase_Test
|
||||
Assert.That(lookup.FindBroadphase(child1), Is.EqualTo(gridBroadphase));
|
||||
|
||||
// They should get deparented to the map and updated to the map's broadphase instead.
|
||||
grid.Comp.SetTile(Vector2i.Zero, Tile.Empty);
|
||||
mapSys.SetTile(grid, Vector2i.Zero, Tile.Empty);
|
||||
Assert.That(lookup.FindBroadphase(parent), Is.EqualTo(mapBroadphase));
|
||||
Assert.That(lookup.FindBroadphase(child1), Is.EqualTo(mapBroadphase));
|
||||
Assert.That(lookup.FindBroadphase(child2), Is.EqualTo(mapBroadphase));
|
||||
@@ -191,6 +198,7 @@ public sealed class Broadphase_Test
|
||||
var xforms = system.GetEntitySystem<SharedTransformSystem>();
|
||||
var physSystem = system.GetEntitySystem<SharedPhysicsSystem>();
|
||||
var fixtures = system.GetEntitySystem<FixtureSystem>();
|
||||
var mapSys = entManager.System<SharedMapSystem>();
|
||||
|
||||
// setup maps
|
||||
var (mapA, mapAId) = sim.CreateMap();
|
||||
@@ -204,9 +212,9 @@ public sealed class Broadphase_Test
|
||||
var gridB = gridBComp.Owner;
|
||||
var gridC = gridCComp.Owner;
|
||||
xforms.SetLocalPosition(gridC, new Vector2(10, 10));
|
||||
gridAComp.Comp.SetTile(Vector2i.Zero, new Tile(1));
|
||||
gridBComp.Comp.SetTile(Vector2i.Zero, new Tile(1));
|
||||
gridCComp.Comp.SetTile(Vector2i.Zero, new Tile(1));
|
||||
mapSys.SetTile(gridAComp, Vector2i.Zero, new Tile(1));
|
||||
mapSys.SetTile(gridBComp, Vector2i.Zero, new Tile(1));
|
||||
mapSys.SetTile(gridCComp, Vector2i.Zero, new Tile(1));
|
||||
|
||||
// set up test entities
|
||||
var parent = entManager.SpawnEntity(null, new EntityCoordinates(mapA, new Vector2(200,200)));
|
||||
|
||||
@@ -8,8 +8,6 @@ using Robust.Shared.Maths;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.UnitTesting.Server;
|
||||
|
||||
// ReSharper disable AccessToStaticMemberViaDerivedType
|
||||
|
||||
namespace Robust.UnitTesting.Shared.Physics;
|
||||
|
||||
[TestFixture]
|
||||
|
||||
@@ -6,8 +6,6 @@ using NUnit.Framework;
|
||||
using Robust.Shared.Collections;
|
||||
using Robust.Shared.Random;
|
||||
|
||||
// ReSharper disable AccessToStaticMemberViaDerivedType
|
||||
|
||||
namespace Robust.UnitTesting.Shared.Random;
|
||||
|
||||
/// <summary> Instantiable tests for <see cref="RandomExtensions.GetItems{T}(IRobustRandom,IList{T},int,bool)"/>. </summary>
|
||||
|
||||
@@ -9,7 +9,6 @@ using Robust.Shared.Utility;
|
||||
|
||||
// ReSharper disable UnassignedGetOnlyAutoProperty
|
||||
// ReSharper disable UnusedAutoPropertyAccessor.Global
|
||||
// ReSharper disable AccessToStaticMemberViaDerivedType
|
||||
|
||||
namespace Robust.UnitTesting.Shared.Serialization
|
||||
{
|
||||
|
||||
@@ -11,8 +11,6 @@ using Robust.Shared.Serialization.Markdown.Mapping;
|
||||
using Robust.Shared.Serialization.Markdown.Sequence;
|
||||
using YamlDotNet.RepresentationModel;
|
||||
|
||||
// ReSharper disable AccessToStaticMemberViaDerivedType
|
||||
|
||||
namespace Robust.UnitTesting.Shared.Serialization
|
||||
{
|
||||
public sealed class SerializationPriorityTest : RobustUnitTest
|
||||
|
||||
@@ -23,7 +23,7 @@ public sealed partial class DataDefinitionTests : SerializationTest
|
||||
//copy: null <> cts(cc(+nt), c)/regular(c)
|
||||
|
||||
[DataDefinition]
|
||||
public partial class DataDefTestDummy
|
||||
public sealed partial class DataDefTestDummy
|
||||
{
|
||||
[DataField("a")] public int a = Int32.MaxValue;
|
||||
[DataField("b")] public DataDummyStruct b = new(){Value = "default"};
|
||||
|
||||
@@ -185,7 +185,7 @@ public sealed partial class ManagerTests : ISerializationContext
|
||||
#region Other TypeDefinitions
|
||||
|
||||
[CopyByRef]
|
||||
private class CopyByRefTestClass {}
|
||||
private sealed class CopyByRefTestClass {}
|
||||
|
||||
[CopyByRef]
|
||||
private struct CopyByRefTestStruct
|
||||
|
||||
@@ -137,8 +137,8 @@ public sealed partial class ManagerTests : SerializationTest
|
||||
new object[]
|
||||
{
|
||||
SerializerRanDataNode,
|
||||
SerializerClass.SerializerReturn,
|
||||
SerializerClass.SerializerReturnAlt,
|
||||
(object)SerializerClass.SerializerReturn,
|
||||
(object)SerializerClass.SerializerReturnAlt,
|
||||
false,
|
||||
new Func<SerializerClass, object>[]
|
||||
{
|
||||
@@ -149,8 +149,8 @@ public sealed partial class ManagerTests : SerializationTest
|
||||
new object[]
|
||||
{
|
||||
SerializerRanCustomDataNode,
|
||||
SerializerClass.SerializerCustomReturn,
|
||||
SerializerClass.SerializerCustomReturnAlt,
|
||||
(object)SerializerClass.SerializerCustomReturn,
|
||||
(object)SerializerClass.SerializerCustomReturnAlt,
|
||||
true,
|
||||
new Func<SerializerClass, object>[]
|
||||
{
|
||||
@@ -229,8 +229,8 @@ public sealed partial class ManagerTests : SerializationTest
|
||||
new object[]
|
||||
{
|
||||
SerializerRanDataNode,
|
||||
SerializerStruct.SerializerReturn,
|
||||
SerializerStruct.SerializerReturnAlt,
|
||||
(object)SerializerStruct.SerializerReturn,
|
||||
(object)SerializerStruct.SerializerReturnAlt,
|
||||
false,
|
||||
new Func<SerializerStruct, object>[]
|
||||
{
|
||||
@@ -241,8 +241,8 @@ public sealed partial class ManagerTests : SerializationTest
|
||||
new object[]
|
||||
{
|
||||
SerializerRanCustomDataNode,
|
||||
SerializerStruct.SerializerCustomReturn,
|
||||
SerializerStruct.SerializerCustomReturnAlt,
|
||||
(object)SerializerStruct.SerializerCustomReturn,
|
||||
(object)SerializerStruct.SerializerCustomReturnAlt,
|
||||
true,
|
||||
new Func<SerializerStruct, object>[]
|
||||
{
|
||||
|
||||
@@ -5,8 +5,6 @@ using Robust.Shared.Serialization.Manager;
|
||||
using Robust.Shared.Serialization.Markdown.Value;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations;
|
||||
|
||||
// ReSharper disable AccessToStaticMemberViaDerivedType
|
||||
|
||||
namespace Robust.UnitTesting.Shared.Serialization.TypeSerializers
|
||||
{
|
||||
[TestFixture]
|
||||
|
||||
@@ -4,8 +4,6 @@ using Robust.Shared.Serialization.Markdown.Sequence;
|
||||
using Robust.Shared.Serialization.Markdown.Value;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Generic;
|
||||
|
||||
// ReSharper disable AccessToStaticMemberViaDerivedType
|
||||
|
||||
namespace Robust.UnitTesting.Shared.Serialization.TypeSerializers
|
||||
{
|
||||
[TestFixture]
|
||||
|
||||
@@ -4,8 +4,6 @@ using Robust.Shared.Serialization.Manager;
|
||||
using Robust.Shared.Serialization.Markdown.Value;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations;
|
||||
|
||||
// ReSharper disable AccessToStaticMemberViaDerivedType
|
||||
|
||||
namespace Robust.UnitTesting.Shared.Serialization.TypeSerializers
|
||||
{
|
||||
[TestFixture]
|
||||
|
||||
@@ -4,8 +4,6 @@ using Robust.Shared.Serialization.Manager;
|
||||
using Robust.Shared.Serialization.Markdown.Value;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations;
|
||||
|
||||
// ReSharper disable AccessToStaticMemberViaDerivedType
|
||||
|
||||
namespace Robust.UnitTesting.Shared.Serialization.TypeSerializers
|
||||
{
|
||||
[TestFixture]
|
||||
|
||||
@@ -12,7 +12,6 @@ using Robust.Shared.Serialization.Markdown.Value;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations;
|
||||
using YamlDotNet.RepresentationModel;
|
||||
using static Robust.Shared.Prototypes.EntityPrototype;
|
||||
// ReSharper disable AccessToStaticMemberViaDerivedType
|
||||
|
||||
namespace Robust.UnitTesting.Shared.Serialization.TypeSerializers
|
||||
{
|
||||
|
||||
@@ -8,8 +8,6 @@ using Robust.Shared.Serialization.Markdown.Sequence;
|
||||
using Robust.Shared.Serialization.Markdown.Value;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
|
||||
|
||||
// ReSharper disable AccessToStaticMemberViaDerivedType
|
||||
|
||||
namespace Robust.UnitTesting.Shared.Serialization.TypeSerializers.Custom
|
||||
{
|
||||
[TestFixture]
|
||||
|
||||
@@ -14,8 +14,6 @@ using Robust.Shared.Serialization.Markdown.Value;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.List;
|
||||
using YamlDotNet.RepresentationModel;
|
||||
|
||||
// ReSharper disable AccessToStaticMemberViaDerivedType
|
||||
|
||||
namespace Robust.UnitTesting.Shared.Serialization.TypeSerializers.Custom.Prototype
|
||||
{
|
||||
[TestFixture]
|
||||
|
||||
@@ -5,8 +5,6 @@ using Robust.Shared.Serialization.Markdown.Mapping;
|
||||
using Robust.Shared.Serialization.Markdown.Value;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Generic;
|
||||
|
||||
// ReSharper disable AccessToStaticMemberViaDerivedType
|
||||
|
||||
namespace Robust.UnitTesting.Shared.Serialization.TypeSerializers
|
||||
{
|
||||
[TestFixture]
|
||||
|
||||
@@ -4,8 +4,6 @@ using Robust.Shared.Serialization.Markdown.Value;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
// ReSharper disable AccessToStaticMemberViaDerivedType
|
||||
|
||||
namespace Robust.UnitTesting.Shared.Serialization.TypeSerializers;
|
||||
|
||||
[TestFixture]
|
||||
@@ -17,7 +15,7 @@ public sealed class FormattedMessageSerializerTest : SerializationTest
|
||||
[TestCase("[color=red]message[/color]")]
|
||||
public void SerializationTest(string text)
|
||||
{
|
||||
var message = FormattedMessage.FromMarkup(text);
|
||||
var message = FormattedMessage.FromMarkupOrThrow(text);
|
||||
var node = Serialization.WriteValueAs<ValueDataNode>(message);
|
||||
Assert.That(node.Value, Is.EqualTo(text));
|
||||
}
|
||||
|
||||
@@ -5,8 +5,6 @@ using Robust.Shared.Serialization.Markdown.Sequence;
|
||||
using Robust.Shared.Serialization.Markdown.Value;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Generic;
|
||||
|
||||
// ReSharper disable AccessToStaticMemberViaDerivedType
|
||||
|
||||
namespace Robust.UnitTesting.Shared.Serialization.TypeSerializers
|
||||
{
|
||||
[TestFixture]
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
using NUnit.Framework;
|
||||
using Robust.Shared.Serialization.Markdown.Value;
|
||||
|
||||
// ReSharper disable AccessToStaticMemberViaDerivedType
|
||||
|
||||
namespace Robust.UnitTesting.Shared.Serialization.TypeSerializers
|
||||
{
|
||||
[TestFixture]
|
||||
|
||||
@@ -5,8 +5,6 @@ using Robust.Shared.Serialization.Markdown.Sequence;
|
||||
using Robust.Shared.Serialization.Markdown.Value;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Generic;
|
||||
|
||||
// ReSharper disable AccessToStaticMemberViaDerivedType
|
||||
|
||||
namespace Robust.UnitTesting.Shared.Serialization.TypeSerializers
|
||||
{
|
||||
[TestFixture]
|
||||
|
||||
@@ -4,8 +4,6 @@ using Robust.Shared.Serialization.Manager;
|
||||
using Robust.Shared.Serialization.Markdown.Value;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations;
|
||||
|
||||
// ReSharper disable AccessToStaticMemberViaDerivedType
|
||||
|
||||
namespace Robust.UnitTesting.Shared.Serialization.TypeSerializers
|
||||
{
|
||||
[TestFixture]
|
||||
|
||||
@@ -5,8 +5,6 @@ using Robust.Shared.Serialization.Markdown.Sequence;
|
||||
using Robust.Shared.Serialization.Markdown.Value;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Generic;
|
||||
|
||||
// ReSharper disable AccessToStaticMemberViaDerivedType
|
||||
|
||||
namespace Robust.UnitTesting.Shared.Serialization.TypeSerializers;
|
||||
|
||||
[TestFixture]
|
||||
|
||||
@@ -10,8 +10,6 @@ using Robust.Shared.Utility;
|
||||
using YamlDotNet.Core;
|
||||
using YamlDotNet.RepresentationModel;
|
||||
|
||||
// ReSharper disable AccessToStaticMemberViaDerivedType
|
||||
|
||||
namespace Robust.UnitTesting.Shared.Serialization.YamlObjectSerializerTests
|
||||
{
|
||||
[TestFixture]
|
||||
|
||||
@@ -10,8 +10,6 @@ using Robust.Shared.Serialization.Markdown.Mapping;
|
||||
using Robust.Shared.Serialization.Markdown.Value;
|
||||
using YamlDotNet.RepresentationModel;
|
||||
|
||||
// ReSharper disable AccessToStaticMemberViaDerivedType
|
||||
|
||||
namespace Robust.UnitTesting.Shared.Serialization.YamlObjectSerializerTests
|
||||
{
|
||||
[TestFixture]
|
||||
|
||||
@@ -7,8 +7,6 @@ using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.Serialization.Markdown.Mapping;
|
||||
using YamlDotNet.RepresentationModel;
|
||||
|
||||
// ReSharper disable AccessToStaticMemberViaDerivedType
|
||||
|
||||
namespace Robust.UnitTesting.Shared.Serialization.YamlObjectSerializerTests
|
||||
{
|
||||
[TestFixture]
|
||||
|
||||
@@ -17,7 +17,6 @@ namespace Robust.UnitTesting.Shared.Timing
|
||||
/// With single step enabled, the game loop should run 1 tick and then pause again.
|
||||
/// </summary>
|
||||
[Test]
|
||||
[Timeout(1000)] // comment this out if you want to debug
|
||||
public void SingleStepTest()
|
||||
{
|
||||
// TimeoutAttribute causes this to run on different thread on .NET Core,
|
||||
|
||||
@@ -3,7 +3,6 @@ using System.Collections.Generic;
|
||||
using System.Numerics;
|
||||
using System.Threading.Tasks;
|
||||
using NUnit.Framework;
|
||||
using Is = NUnit.Framework.Is;
|
||||
|
||||
namespace Robust.UnitTesting.Shared.Toolshed;
|
||||
|
||||
@@ -16,9 +15,9 @@ public sealed class ArithmeticTest : ToolshedTest
|
||||
await Server.WaitAssertion(() =>
|
||||
{
|
||||
// Toolshed always parses left-to-right with no precedence.
|
||||
Assert.That(1.0f / 3.0f, Is.EqualTo(InvokeCommand<float>("f 1 / 3")));
|
||||
Assert.That((1.0f + 1.0f) / 3.0f, Is.EqualTo(InvokeCommand<float>("f 1 + 1 / 3")));
|
||||
Assert.That(float.Pow(2.0f + 2.0f, 3.0f), Is.EqualTo(InvokeCommand<float>("f 2 + 2 pow 3")));
|
||||
Assert.That(InvokeCommand<float>("f 1 / 3"), Is.EqualTo(1.0f / 3.0f));
|
||||
Assert.That(InvokeCommand<float>("f 1 + 1 / 3"), Is.EqualTo((1.0f + 1.0f) / 3.0f));
|
||||
Assert.That(InvokeCommand<float>("f 2 + 2 pow 3"), Is.EqualTo(float.Pow(2.0f + 2.0f, 3.0f)));
|
||||
});
|
||||
}
|
||||
[Test]
|
||||
|
||||
@@ -32,10 +32,11 @@ public abstract class ToolshedTest : RobustIntegrationTest, IInvocationContext
|
||||
Server.Dispose();
|
||||
}
|
||||
|
||||
protected virtual async Task TearDown()
|
||||
protected virtual Task TearDown()
|
||||
{
|
||||
Assert.That(_expectedErrors, Is.Empty);
|
||||
ClearErrors();
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
[SetUp]
|
||||
|
||||
@@ -8,7 +8,7 @@ public sealed partial class ToolshedTypesTest
|
||||
{
|
||||
// Assert that T -> Nullable<T> holds and it's inverse does not.
|
||||
[Test]
|
||||
public async Task Bug_Nullables_08_21_2023()
|
||||
public void Bug_Nullables_08_21_2023()
|
||||
{
|
||||
Assert.That(Toolshed.IsTransformableTo(typeof(int), typeof(Nullable<int>)));
|
||||
Assert.That(!Toolshed.IsTransformableTo(typeof(Nullable<int>), typeof(int)));
|
||||
|
||||
@@ -11,7 +11,7 @@ public sealed partial class ToolshedTypesTest : ToolshedTest
|
||||
{
|
||||
// Assert that T -> IEnumerable<T> holds.
|
||||
[Test]
|
||||
public async Task EnumerableAutoCast()
|
||||
public void EnumerableAutoCast()
|
||||
{
|
||||
Assert.That(Toolshed.IsTransformableTo(typeof(int), typeof(IEnumerable<int>)));
|
||||
var l = Expression
|
||||
@@ -24,7 +24,7 @@ public sealed partial class ToolshedTypesTest : ToolshedTest
|
||||
|
||||
// Assert that T -> IEnumerable<T'> where T: T' holds.
|
||||
[Test]
|
||||
public async Task EnumerableSubtypeAutocast()
|
||||
public void EnumerableSubtypeAutocast()
|
||||
{
|
||||
Assert.That(Toolshed.IsTransformableTo(typeof(int), typeof(IEnumerable<IComparable>)));
|
||||
var l = Expression
|
||||
@@ -37,7 +37,7 @@ public sealed partial class ToolshedTypesTest : ToolshedTest
|
||||
|
||||
// Assert that T -> object.
|
||||
[Test]
|
||||
public async Task CastToObject()
|
||||
public void CastToObject()
|
||||
{
|
||||
Assert.That(Toolshed.IsTransformableTo(typeof(int), typeof(object)));
|
||||
var l = Expression
|
||||
|
||||
@@ -33,7 +33,7 @@ public sealed class GridTraversalTest : RobustIntegrationTest
|
||||
grid = gridComp.Owner;
|
||||
mapSys.SetTile(grid, gridComp, Vector2i.Zero, new Tile(1));
|
||||
var gridCentre = new EntityCoordinates(grid, .5f, .5f);
|
||||
gridMapPos = gridCentre.ToMap(sEntMan, xforms).Position;
|
||||
gridMapPos = xforms.ToMapCoordinates(gridCentre).Position;
|
||||
});
|
||||
|
||||
for (int i = 0; i < 10; i++)
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace Robust.UnitTesting.Shared.Utility
|
||||
[Test]
|
||||
public static void TestParseMarkup()
|
||||
{
|
||||
var msg = FormattedMessage.FromMarkup("foo[color=#aabbcc]bar[/color]baz");
|
||||
var msg = FormattedMessage.FromMarkupOrThrow("foo[color=#aabbcc]bar[/color]baz");
|
||||
|
||||
Assert.That(msg.Nodes, NUnit.Framework.Is.EquivalentTo(new MarkupNode[]
|
||||
{
|
||||
@@ -28,7 +28,7 @@ namespace Robust.UnitTesting.Shared.Utility
|
||||
[Test]
|
||||
public static void TestParseMarkupColorName()
|
||||
{
|
||||
var msg = FormattedMessage.FromMarkup("foo[color=orange]bar[/color]baz");
|
||||
var msg = FormattedMessage.FromMarkupOrThrow("foo[color=orange]bar[/color]baz");
|
||||
|
||||
Assert.That(msg.Nodes, NUnit.Framework.Is.EquivalentTo(new MarkupNode[]
|
||||
{
|
||||
@@ -57,7 +57,7 @@ namespace Robust.UnitTesting.Shared.Utility
|
||||
[TestCase("[color=red]Foo[/color]bar", ExpectedResult = "Foobar")]
|
||||
public string TestRemoveMarkup(string test)
|
||||
{
|
||||
return FormattedMessage.RemoveMarkup(test);
|
||||
return FormattedMessage.RemoveMarkupOrThrow(test);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -66,7 +66,7 @@ namespace Robust.UnitTesting.Shared.Utility
|
||||
[TestCase("[color=lime]Foo[/color]bar")]
|
||||
public static void TestToMarkup(string text)
|
||||
{
|
||||
var message = FormattedMessage.FromMarkup(text);
|
||||
var message = FormattedMessage.FromMarkupOrThrow(text);
|
||||
Assert.That(message.ToMarkup(), NUnit.Framework.Is.EqualTo(text));
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ namespace Robust.UnitTesting.Shared.Utility
|
||||
[TestCase("honk honk [color=#00FF00FF]Foo[/color]bar")]
|
||||
public static void TestEnumerateRunes(string text)
|
||||
{
|
||||
var message = FormattedMessage.FromMarkup(text);
|
||||
var message = FormattedMessage.FromMarkupOrThrow(text);
|
||||
|
||||
Assert.That(
|
||||
message.EnumerateRunes(),
|
||||
|
||||
66
Robust.UnitTesting/Shared/Utility/MarkupNodeTest.cs
Normal file
66
Robust.UnitTesting/Shared/Utility/MarkupNodeTest.cs
Normal file
@@ -0,0 +1,66 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Robust.UnitTesting.Shared.Utility;
|
||||
|
||||
[TestFixture]
|
||||
[Parallelizable(ParallelScope.All)]
|
||||
[TestOf(typeof(MarkupNode))]
|
||||
public sealed class MarkupNodeTest
|
||||
{
|
||||
[Test]
|
||||
[SuppressMessage("Assertion", "NUnit2009:The same value has been provided as both the actual and the expected argument")]
|
||||
public void TestEquality()
|
||||
{
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
// Test name match
|
||||
Assert.That(new MarkupNode("A"), Is.EqualTo(new MarkupNode("A")));
|
||||
Assert.That(new MarkupNode("A").GetHashCode(), Is.EqualTo(new MarkupNode("A").GetHashCode()));
|
||||
Assert.That(new MarkupNode("A"), Is.Not.EqualTo(new MarkupNode("B")));
|
||||
|
||||
// Test closing match
|
||||
Assert.That(new MarkupNode("A", null, null, true), Is.EqualTo(new MarkupNode("A", null, null, true)));
|
||||
Assert.That(new MarkupNode("A", null, null, true).GetHashCode(), Is.EqualTo(new MarkupNode("A", null, null, true).GetHashCode()));
|
||||
Assert.That(new MarkupNode("A", null, null, true), Is.Not.EqualTo(new MarkupNode("A")));
|
||||
|
||||
// Test value match
|
||||
var param = new MarkupParameter("A");
|
||||
Assert.That(new MarkupNode("A", param, null), Is.EqualTo(new MarkupNode("A", param, null)));
|
||||
Assert.That(new MarkupNode("A", param, null).GetHashCode(), Is.EqualTo(new MarkupNode("A", param, null).GetHashCode()));
|
||||
Assert.That(new MarkupNode("A", param, null), Is.Not.EqualTo(new MarkupNode("A")));
|
||||
Assert.That(new MarkupNode("A", param, null), Is.Not.EqualTo(new MarkupNode("A", new MarkupParameter("B"), null)));
|
||||
|
||||
// Test attributes match
|
||||
var attrs = new Dictionary<string, MarkupParameter>
|
||||
{
|
||||
{ "A", new MarkupParameter("A") },
|
||||
{ "B", new MarkupParameter(5) },
|
||||
{ "C", new MarkupParameter(Color.Red) },
|
||||
};
|
||||
var wrongAttrs = new Dictionary<string, MarkupParameter>
|
||||
{
|
||||
{ "A", new MarkupParameter("A") },
|
||||
{ "B", new MarkupParameter(6) },
|
||||
{ "C", new MarkupParameter(Color.Red) },
|
||||
};
|
||||
var wrongAttrsTooLong = new Dictionary<string, MarkupParameter>
|
||||
{
|
||||
{ "A", new MarkupParameter("A") },
|
||||
{ "B", new MarkupParameter(5) },
|
||||
{ "C", new MarkupParameter(Color.Red) },
|
||||
{ "D", new MarkupParameter(Color.Red) },
|
||||
};
|
||||
var attrs2 = attrs.Reverse().ToDictionary();
|
||||
Assert.That(new MarkupNode("A", null, attrs), Is.EqualTo(new MarkupNode("A", null, attrs2)));
|
||||
Assert.That(new MarkupNode("A", null, attrs).GetHashCode(), Is.EqualTo(new MarkupNode("A", null, attrs2).GetHashCode()));
|
||||
Assert.That(new MarkupNode("A", null, attrs), Is.Not.EqualTo(new MarkupNode("A")));
|
||||
Assert.That(new MarkupNode("A", null, attrs), Is.Not.EqualTo(new MarkupNode("A", null, wrongAttrs)));
|
||||
Assert.That(new MarkupNode("A", null, attrs), Is.Not.EqualTo(new MarkupNode("A", null, wrongAttrsTooLong)));
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -2,9 +2,6 @@
|
||||
using NUnit.Framework;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
// ReSharper disable AccessToStaticMemberViaDerivedType
|
||||
|
||||
|
||||
namespace Robust.UnitTesting.Shared.Utility;
|
||||
|
||||
[TestFixture]
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user