Validate ProtoIds in tests (#38745)
* Convert string literals to protoids in Content.Tests * Convert string literals to protoids or consts in Content.IntegrationTests * Fix linter failures Tricksy static using misled me
This commit is contained in:
@@ -7,10 +7,12 @@ namespace Content.IntegrationTests.Tests.Atmos
|
||||
[TestOf(typeof(AtmosAlarmThreshold))]
|
||||
public sealed class AlarmThresholdTest
|
||||
{
|
||||
private const string AlarmThresholdTestDummyId = "AlarmThresholdTestDummy";
|
||||
|
||||
[TestPrototypes]
|
||||
private const string Prototypes = @"
|
||||
private const string Prototypes = $@"
|
||||
- type: alarmThreshold
|
||||
id: AlarmThresholdTestDummy
|
||||
id: {AlarmThresholdTestDummyId}
|
||||
upperBound: !type:AlarmThresholdSetting
|
||||
threshold: 5
|
||||
lowerBound: !type:AlarmThresholdSetting
|
||||
@@ -30,7 +32,7 @@ namespace Content.IntegrationTests.Tests.Atmos
|
||||
var prototypeManager = server.ResolveDependency<IPrototypeManager>();
|
||||
AtmosAlarmThreshold threshold = default!;
|
||||
|
||||
var proto = prototypeManager.Index<AtmosAlarmThresholdPrototype>("AlarmThresholdTestDummy");
|
||||
var proto = prototypeManager.Index<AtmosAlarmThresholdPrototype>(AlarmThresholdTestDummyId);
|
||||
threshold = new(proto);
|
||||
|
||||
await server.WaitAssertion(() =>
|
||||
|
||||
@@ -15,6 +15,8 @@ namespace Content.IntegrationTests.Tests.Commands
|
||||
[TestOf(typeof(RejuvenateSystem))]
|
||||
public sealed class RejuvenateTest
|
||||
{
|
||||
private static readonly ProtoId<DamageGroupPrototype> TestDamageGroup = "Toxin";
|
||||
|
||||
[TestPrototypes]
|
||||
private const string Prototypes = @"
|
||||
- type: entity
|
||||
@@ -62,7 +64,7 @@ namespace Content.IntegrationTests.Tests.Commands
|
||||
});
|
||||
|
||||
// Kill the entity
|
||||
DamageSpecifier damage = new(prototypeManager.Index<DamageGroupPrototype>("Toxin"), FixedPoint2.New(10000000));
|
||||
DamageSpecifier damage = new(prototypeManager.Index(TestDamageGroup), FixedPoint2.New(10000000));
|
||||
|
||||
damSystem.TryChangeDamage(human, damage, true);
|
||||
|
||||
|
||||
@@ -53,6 +53,8 @@ public sealed class SuicideCommandTests
|
||||
components:
|
||||
- type: MaterialReclaimer";
|
||||
private static readonly ProtoId<TagPrototype> CannotSuicideTag = "CannotSuicide";
|
||||
private static readonly ProtoId<DamageTypePrototype> DamageType = "Slash";
|
||||
|
||||
/// <summary>
|
||||
/// Run the suicide command in the console
|
||||
/// Should successfully kill the player and ghost them
|
||||
@@ -144,7 +146,7 @@ public sealed class SuicideCommandTests
|
||||
mobThresholdsComp = entManager.GetComponent<MobThresholdsComponent>(player);
|
||||
damageableComp = entManager.GetComponent<DamageableComponent>(player);
|
||||
|
||||
if (protoMan.TryIndex<DamageTypePrototype>("Slash", out var slashProto))
|
||||
if (protoMan.TryIndex(DamageType, out var slashProto))
|
||||
damageableSystem.TryChangeDamage(player, new DamageSpecifier(slashProto, FixedPoint2.New(46.5)));
|
||||
});
|
||||
|
||||
|
||||
@@ -8,6 +8,8 @@ namespace Content.IntegrationTests.Tests.Construction.Interaction;
|
||||
|
||||
public sealed class WindowRepair : InteractionTest
|
||||
{
|
||||
private static readonly ProtoId<DamageTypePrototype> BluntDamageType = "Blunt";
|
||||
|
||||
[Test]
|
||||
public async Task RepairReinforcedWindow()
|
||||
{
|
||||
@@ -16,7 +18,7 @@ public sealed class WindowRepair : InteractionTest
|
||||
// Damage the entity.
|
||||
var sys = SEntMan.System<DamageableSystem>();
|
||||
var comp = Comp<DamageableComponent>();
|
||||
var damageType = Server.ResolveDependency<IPrototypeManager>().Index<DamageTypePrototype>("Blunt");
|
||||
var damageType = Server.ProtoMan.Index(BluntDamageType);
|
||||
var damage = new DamageSpecifier(damageType, FixedPoint2.New(10));
|
||||
Assert.That(comp.Damage.GetTotal(), Is.EqualTo(FixedPoint2.Zero));
|
||||
await Server.WaitPost(() => sys.TryChangeDamage(SEntMan.GetEntity(Target), damage, ignoreResistances: true));
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
using System.Linq;
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.Damage.Prototypes;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
@@ -14,66 +12,79 @@ namespace Content.IntegrationTests.Tests.Damageable
|
||||
[TestOf(typeof(DamageableSystem))]
|
||||
public sealed class DamageableTest
|
||||
{
|
||||
private const string TestDamageableEntityId = "TestDamageableEntityId";
|
||||
private const string TestGroup1 = "TestGroup1";
|
||||
private const string TestGroup2 = "TestGroup2";
|
||||
private const string TestGroup3 = "TestGroup3";
|
||||
private const string TestDamage1 = "TestDamage1";
|
||||
private const string TestDamage2a = "TestDamage2a";
|
||||
private const string TestDamage2b = "TestDamage2b";
|
||||
|
||||
private const string TestDamage3a = "TestDamage3a";
|
||||
|
||||
private const string TestDamage3b = "TestDamage3b";
|
||||
private const string TestDamage3c = "TestDamage3c";
|
||||
|
||||
[TestPrototypes]
|
||||
private const string Prototypes = @"
|
||||
private const string Prototypes = $@"
|
||||
# Define some damage groups
|
||||
- type: damageType
|
||||
id: TestDamage1
|
||||
id: {TestDamage1}
|
||||
name: damage-type-blunt
|
||||
|
||||
- type: damageType
|
||||
id: TestDamage2a
|
||||
id: {TestDamage2a}
|
||||
name: damage-type-blunt
|
||||
|
||||
- type: damageType
|
||||
id: TestDamage2b
|
||||
id: {TestDamage2b}
|
||||
name: damage-type-blunt
|
||||
|
||||
- type: damageType
|
||||
id: TestDamage3a
|
||||
id: {TestDamage3a}
|
||||
name: damage-type-blunt
|
||||
|
||||
- type: damageType
|
||||
id: TestDamage3b
|
||||
id: {TestDamage3b}
|
||||
name: damage-type-blunt
|
||||
|
||||
- type: damageType
|
||||
id: TestDamage3c
|
||||
id: {TestDamage3c}
|
||||
name: damage-type-blunt
|
||||
|
||||
# Define damage Groups with 1,2,3 damage types
|
||||
- type: damageGroup
|
||||
id: TestGroup1
|
||||
id: {TestGroup1}
|
||||
name: damage-group-brute
|
||||
damageTypes:
|
||||
- TestDamage1
|
||||
- {TestDamage1}
|
||||
|
||||
- type: damageGroup
|
||||
id: TestGroup2
|
||||
id: {TestGroup2}
|
||||
name: damage-group-brute
|
||||
damageTypes:
|
||||
- TestDamage2a
|
||||
- TestDamage2b
|
||||
- {TestDamage2a}
|
||||
- {TestDamage2b}
|
||||
|
||||
- type: damageGroup
|
||||
id: TestGroup3
|
||||
id: {TestGroup3}
|
||||
name: damage-group-brute
|
||||
damageTypes:
|
||||
- TestDamage3a
|
||||
- TestDamage3b
|
||||
- TestDamage3c
|
||||
- {TestDamage3a}
|
||||
- {TestDamage3b}
|
||||
- {TestDamage3c}
|
||||
|
||||
# This container should not support TestDamage1 or TestDamage2b
|
||||
- type: damageContainer
|
||||
id: testDamageContainer
|
||||
supportedGroups:
|
||||
- TestGroup3
|
||||
- {TestGroup3}
|
||||
supportedTypes:
|
||||
- TestDamage2a
|
||||
- {TestDamage2a}
|
||||
|
||||
- type: entity
|
||||
id: TestDamageableEntityId
|
||||
name: TestDamageableEntityId
|
||||
id: {TestDamageableEntityId}
|
||||
name: {TestDamageableEntityId}
|
||||
components:
|
||||
- type: Damageable
|
||||
damageContainer: testDamageContainer
|
||||
@@ -113,20 +124,20 @@ namespace Content.IntegrationTests.Tests.Damageable
|
||||
{
|
||||
var coordinates = map.MapCoords;
|
||||
|
||||
sDamageableEntity = sEntityManager.SpawnEntity("TestDamageableEntityId", coordinates);
|
||||
sDamageableEntity = sEntityManager.SpawnEntity(TestDamageableEntityId, coordinates);
|
||||
sDamageableComponent = sEntityManager.GetComponent<DamageableComponent>(sDamageableEntity);
|
||||
sDamageableSystem = sEntitySystemManager.GetEntitySystem<DamageableSystem>();
|
||||
|
||||
group1 = sPrototypeManager.Index<DamageGroupPrototype>("TestGroup1");
|
||||
group2 = sPrototypeManager.Index<DamageGroupPrototype>("TestGroup2");
|
||||
group3 = sPrototypeManager.Index<DamageGroupPrototype>("TestGroup3");
|
||||
group1 = sPrototypeManager.Index<DamageGroupPrototype>(TestGroup1);
|
||||
group2 = sPrototypeManager.Index<DamageGroupPrototype>(TestGroup2);
|
||||
group3 = sPrototypeManager.Index<DamageGroupPrototype>(TestGroup3);
|
||||
|
||||
type1 = sPrototypeManager.Index<DamageTypePrototype>("TestDamage1");
|
||||
type2a = sPrototypeManager.Index<DamageTypePrototype>("TestDamage2a");
|
||||
type2b = sPrototypeManager.Index<DamageTypePrototype>("TestDamage2b");
|
||||
type3a = sPrototypeManager.Index<DamageTypePrototype>("TestDamage3a");
|
||||
type3b = sPrototypeManager.Index<DamageTypePrototype>("TestDamage3b");
|
||||
type3c = sPrototypeManager.Index<DamageTypePrototype>("TestDamage3c");
|
||||
type1 = sPrototypeManager.Index<DamageTypePrototype>(TestDamage1);
|
||||
type2a = sPrototypeManager.Index<DamageTypePrototype>(TestDamage2a);
|
||||
type2b = sPrototypeManager.Index<DamageTypePrototype>(TestDamage2b);
|
||||
type3a = sPrototypeManager.Index<DamageTypePrototype>(TestDamage3a);
|
||||
type3b = sPrototypeManager.Index<DamageTypePrototype>(TestDamage3b);
|
||||
type3c = sPrototypeManager.Index<DamageTypePrototype>(TestDamage3c);
|
||||
});
|
||||
|
||||
await server.WaitRunTicks(5);
|
||||
|
||||
@@ -54,8 +54,8 @@ namespace Content.IntegrationTests.Tests.Destructible
|
||||
|
||||
await server.WaitAssertion(() =>
|
||||
{
|
||||
var bruteDamageGroup = sPrototypeManager.Index<DamageGroupPrototype>("TestBrute");
|
||||
var burnDamageGroup = sPrototypeManager.Index<DamageGroupPrototype>("TestBurn");
|
||||
var bruteDamageGroup = sPrototypeManager.Index<DamageGroupPrototype>(TestBruteDamageGroupId);
|
||||
var burnDamageGroup = sPrototypeManager.Index<DamageGroupPrototype>(TestBurnDamageGroupId);
|
||||
|
||||
DamageSpecifier bruteDamage = new(bruteDamageGroup, FixedPoint2.New(5));
|
||||
DamageSpecifier burnDamage = new(burnDamageGroup, FixedPoint2.New(5));
|
||||
|
||||
@@ -49,8 +49,8 @@ namespace Content.IntegrationTests.Tests.Destructible
|
||||
|
||||
await server.WaitAssertion(() =>
|
||||
{
|
||||
var bluntDamageType = protoManager.Index<DamageTypePrototype>("TestBlunt");
|
||||
var slashDamageType = protoManager.Index<DamageTypePrototype>("TestSlash");
|
||||
var bluntDamageType = protoManager.Index<DamageTypePrototype>(TestBluntDamageTypeId);
|
||||
var slashDamageType = protoManager.Index<DamageTypePrototype>(TestSlashDamageTypeId);
|
||||
|
||||
var bluntDamage = new DamageSpecifier(bluntDamageType, 5);
|
||||
var slashDamage = new DamageSpecifier(slashDamageType, 5);
|
||||
|
||||
@@ -39,7 +39,7 @@ namespace Content.IntegrationTests.Tests.Destructible
|
||||
await server.WaitAssertion(() =>
|
||||
{
|
||||
var coordinates = sEntityManager.GetComponent<TransformComponent>(sDestructibleEntity).Coordinates;
|
||||
var bruteDamageGroup = sPrototypeManager.Index<DamageGroupPrototype>("TestBrute");
|
||||
var bruteDamageGroup = sPrototypeManager.Index<DamageGroupPrototype>(TestBruteDamageGroupId);
|
||||
DamageSpecifier bruteDamage = new(bruteDamageGroup, 50);
|
||||
|
||||
#pragma warning disable NUnit2045 // Interdependent assertions.
|
||||
|
||||
@@ -7,48 +7,56 @@ namespace Content.IntegrationTests.Tests.Destructible
|
||||
public const string DestructibleDestructionEntityId = "DestructibleTestsDestructibleDestructionEntity";
|
||||
public const string DestructibleDamageTypeEntityId = "DestructibleTestsDestructibleDamageTypeEntity";
|
||||
public const string DestructibleDamageGroupEntityId = "DestructibleTestsDestructibleDamageGroupEntity";
|
||||
public const string TestBruteDamageGroupId = "TestBrute";
|
||||
public const string TestBurnDamageGroupId = "TestBurn";
|
||||
public const string TestBluntDamageTypeId = "TestBlunt";
|
||||
public const string TestSlashDamageTypeId = "TestSlash";
|
||||
public const string TestPiercingDamageTypeId = "TestPiercing";
|
||||
public const string TestHeatDamageTypeId = "TestHeat";
|
||||
public const string TestShockDamageTypeId = "TestShock";
|
||||
public const string TestColdDamageTypeId = "TestCold";
|
||||
|
||||
[TestPrototypes]
|
||||
public const string DamagePrototypes = $@"
|
||||
- type: damageType
|
||||
id: TestBlunt
|
||||
id: {TestBluntDamageTypeId}
|
||||
name: damage-type-blunt
|
||||
|
||||
- type: damageType
|
||||
id: TestSlash
|
||||
id: {TestSlashDamageTypeId}
|
||||
name: damage-type-slash
|
||||
|
||||
- type: damageType
|
||||
id: TestPiercing
|
||||
id: {TestPiercingDamageTypeId}
|
||||
name: damage-type-piercing
|
||||
|
||||
- type: damageType
|
||||
id: TestHeat
|
||||
id: {TestHeatDamageTypeId}
|
||||
name: damage-type-heat
|
||||
|
||||
- type: damageType
|
||||
id: TestShock
|
||||
id: {TestShockDamageTypeId}
|
||||
name: damage-type-shock
|
||||
|
||||
- type: damageType
|
||||
id: TestCold
|
||||
id: {TestColdDamageTypeId}
|
||||
name: damage-type-cold
|
||||
|
||||
- type: damageGroup
|
||||
id: TestBrute
|
||||
id: {TestBruteDamageGroupId}
|
||||
name: damage-group-brute
|
||||
damageTypes:
|
||||
- TestBlunt
|
||||
- TestSlash
|
||||
- TestPiercing
|
||||
- {TestBluntDamageTypeId}
|
||||
- {TestSlashDamageTypeId}
|
||||
- {TestPiercingDamageTypeId}
|
||||
|
||||
- type: damageGroup
|
||||
id: TestBurn
|
||||
id: {TestBurnDamageGroupId}
|
||||
name: damage-group-burn
|
||||
damageTypes:
|
||||
- TestHeat
|
||||
- TestShock
|
||||
- TestCold
|
||||
- {TestHeatDamageTypeId}
|
||||
- {TestShockDamageTypeId}
|
||||
- {TestColdDamageTypeId}
|
||||
|
||||
- type: entity
|
||||
id: {SpawnedEntityId}
|
||||
@@ -114,10 +122,10 @@ namespace Content.IntegrationTests.Tests.Destructible
|
||||
!type:AndTrigger
|
||||
triggers:
|
||||
- !type:DamageTypeTrigger
|
||||
damageType: TestBlunt
|
||||
damageType: {TestBluntDamageTypeId}
|
||||
damage: 10
|
||||
- !type:DamageTypeTrigger
|
||||
damageType: TestSlash
|
||||
damageType: {TestSlashDamageTypeId}
|
||||
damage: 10
|
||||
|
||||
- type: entity
|
||||
@@ -131,10 +139,10 @@ namespace Content.IntegrationTests.Tests.Destructible
|
||||
!type:AndTrigger
|
||||
triggers:
|
||||
- !type:DamageGroupTrigger
|
||||
damageGroup: TestBrute
|
||||
damageGroup: {TestBruteDamageGroupId}
|
||||
damage: 10
|
||||
- !type:DamageGroupTrigger
|
||||
damageGroup: TestBurn
|
||||
damageGroup: {TestBurnDamageGroupId}
|
||||
damage: 10";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ namespace Content.IntegrationTests.Tests.Destructible
|
||||
|
||||
await server.WaitAssertion(() =>
|
||||
{
|
||||
var bluntDamage = new DamageSpecifier(sPrototypeManager.Index<DamageTypePrototype>("TestBlunt"), 10);
|
||||
var bluntDamage = new DamageSpecifier(sPrototypeManager.Index<DamageTypePrototype>(TestBluntDamageTypeId), 10);
|
||||
|
||||
sDamageableSystem.TryChangeDamage(sDestructibleEntity, bluntDamage, true);
|
||||
|
||||
|
||||
@@ -24,6 +24,8 @@ namespace Content.IntegrationTests.Tests.Minds;
|
||||
[TestFixture]
|
||||
public sealed partial class MindTests
|
||||
{
|
||||
private static readonly ProtoId<DamageTypePrototype> BluntDamageType = "Blunt";
|
||||
|
||||
[TestPrototypes]
|
||||
private const string Prototypes = @"
|
||||
- type: entity
|
||||
@@ -144,7 +146,7 @@ public sealed partial class MindTests
|
||||
await server.WaitAssertion(() =>
|
||||
{
|
||||
var damageable = entMan.GetComponent<DamageableComponent>(entity);
|
||||
if (!protoMan.TryIndex<DamageTypePrototype>("Blunt", out var prototype))
|
||||
if (!protoMan.TryIndex(BluntDamageType, out var prototype))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -77,6 +77,8 @@ namespace Content.IntegrationTests.Tests
|
||||
"Exo",
|
||||
};
|
||||
|
||||
private static readonly ProtoId<EntityCategoryPrototype> DoNotMapCategory = "DoNotMap";
|
||||
|
||||
/// <summary>
|
||||
/// Asserts that specific files have been saved as grids and not maps.
|
||||
/// </summary>
|
||||
@@ -254,7 +256,7 @@ namespace Content.IntegrationTests.Tests
|
||||
return;
|
||||
|
||||
var yamlEntities = node["entities"];
|
||||
if (!protoManager.TryIndex<EntityCategoryPrototype>("DoNotMap", out var dnmCategory))
|
||||
if (!protoManager.TryIndex(DoNotMapCategory, out var dnmCategory))
|
||||
return;
|
||||
|
||||
Assert.Multiple(() =>
|
||||
|
||||
@@ -17,8 +17,10 @@ namespace Content.IntegrationTests.Tests.Station;
|
||||
[TestOf(typeof(StationJobsSystem))]
|
||||
public sealed class StationJobsTest
|
||||
{
|
||||
private const string StationMapId = "FooStation";
|
||||
|
||||
[TestPrototypes]
|
||||
private const string Prototypes = @"
|
||||
private const string Prototypes = $@"
|
||||
- type: playTimeTracker
|
||||
id: PlayTimeDummyAssistant
|
||||
|
||||
@@ -35,13 +37,13 @@ public sealed class StationJobsTest
|
||||
id: PlayTimeDummyChaplain
|
||||
|
||||
- type: gameMap
|
||||
id: FooStation
|
||||
id: {StationMapId}
|
||||
minPlayers: 0
|
||||
mapName: FooStation
|
||||
mapName: {StationMapId}
|
||||
mapPath: /Maps/Test/empty.yml
|
||||
stations:
|
||||
Station:
|
||||
mapNameTemplate: FooStation
|
||||
mapNameTemplate: {StationMapId}
|
||||
stationProto: StandardNanotrasenStation
|
||||
components:
|
||||
- type: StationJobs
|
||||
@@ -87,7 +89,7 @@ public sealed class StationJobsTest
|
||||
var server = pair.Server;
|
||||
|
||||
var prototypeManager = server.ResolveDependency<IPrototypeManager>();
|
||||
var fooStationProto = prototypeManager.Index<GameMapPrototype>("FooStation");
|
||||
var fooStationProto = prototypeManager.Index<GameMapPrototype>(StationMapId);
|
||||
var entSysMan = server.ResolveDependency<IEntityManager>().EntitySysManager;
|
||||
var stationJobs = entSysMan.GetEntitySystem<StationJobsSystem>();
|
||||
var stationSystem = entSysMan.GetEntitySystem<StationSystem>();
|
||||
@@ -161,7 +163,7 @@ public sealed class StationJobsTest
|
||||
var server = pair.Server;
|
||||
|
||||
var prototypeManager = server.ResolveDependency<IPrototypeManager>();
|
||||
var fooStationProto = prototypeManager.Index<GameMapPrototype>("FooStation");
|
||||
var fooStationProto = prototypeManager.Index<GameMapPrototype>(StationMapId);
|
||||
var entSysMan = server.ResolveDependency<IEntityManager>().EntitySysManager;
|
||||
var stationJobs = entSysMan.GetEntitySystem<StationJobsSystem>();
|
||||
var stationSystem = entSysMan.GetEntitySystem<StationSystem>();
|
||||
|
||||
@@ -5,6 +5,7 @@ using Content.Shared.Damage;
|
||||
using Content.Shared.Damage.Prototypes;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Content.Shared.VendingMachines;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.IntegrationTests.Tests.Vending;
|
||||
|
||||
@@ -17,6 +18,7 @@ public sealed class VendingInteractionTest : InteractionTest
|
||||
private const string RestockBoxProtoId = "InteractionTestRestockBox";
|
||||
|
||||
private const string RestockBoxOtherProtoId = "InteractionTestRestockBoxOther";
|
||||
private static readonly ProtoId<DamageTypePrototype> TestDamageType = "Blunt";
|
||||
|
||||
[TestPrototypes]
|
||||
private const string TestPrototypes = $@"
|
||||
@@ -196,7 +198,7 @@ public sealed class VendingInteractionTest : InteractionTest
|
||||
Assert.That(damageableComp.Damage.GetTotal(), Is.EqualTo(FixedPoint2.Zero), $"{VendingMachineProtoId} started with unexpected damage.");
|
||||
|
||||
// Damage the vending machine to the point that it breaks
|
||||
var damageType = ProtoMan.Index<DamageTypePrototype>("Blunt");
|
||||
var damageType = ProtoMan.Index(TestDamageType);
|
||||
var damage = new DamageSpecifier(damageType, FixedPoint2.New(100));
|
||||
await Server.WaitPost(() => damageableSys.TryChangeDamage(SEntMan.GetEntity(Target), damage, ignoreResistances: true));
|
||||
await RunTicks(5);
|
||||
|
||||
@@ -20,6 +20,8 @@ namespace Content.IntegrationTests.Tests
|
||||
[TestOf(typeof(VendingMachineSystem))]
|
||||
public sealed class VendingMachineRestockTest : EntitySystem
|
||||
{
|
||||
private static readonly ProtoId<DamageTypePrototype> TestDamageType = "Blunt";
|
||||
|
||||
[TestPrototypes]
|
||||
private const string Prototypes = @"
|
||||
- type: entity
|
||||
@@ -293,7 +295,7 @@ namespace Content.IntegrationTests.Tests
|
||||
"Did not start with zero ramen.");
|
||||
|
||||
restock = entityManager.SpawnEntity("TestRestockExplode", coordinates);
|
||||
var damageSpec = new DamageSpecifier(prototypeManager.Index<DamageTypePrototype>("Blunt"), 100);
|
||||
var damageSpec = new DamageSpecifier(prototypeManager.Index(TestDamageType), 100);
|
||||
var damageResult = damageableSystem.TryChangeDamage(restock, damageSpec);
|
||||
|
||||
#pragma warning disable NUnit2045
|
||||
|
||||
@@ -15,6 +15,11 @@ namespace Content.Tests.Shared
|
||||
[TestOf(typeof(DamageGroupPrototype))]
|
||||
public sealed class DamageTest : ContentUnitTest
|
||||
{
|
||||
private static readonly ProtoId<DamageGroupPrototype> BruteDamageGroup = "Brute";
|
||||
private static readonly ProtoId<DamageTypePrototype> RadiationDamageType = "Radiation";
|
||||
private static readonly ProtoId<DamageTypePrototype> SlashDamageType = "Slash";
|
||||
private static readonly ProtoId<DamageTypePrototype> PiercingDamageType = "Piercing";
|
||||
|
||||
private IPrototypeManager _prototypeManager;
|
||||
|
||||
private DamageSpecifier _damageSpec;
|
||||
@@ -29,9 +34,9 @@ namespace Content.Tests.Shared
|
||||
_prototypeManager.ResolveResults();
|
||||
|
||||
// Create a damage data set
|
||||
_damageSpec = new(_prototypeManager.Index<DamageGroupPrototype>("Brute"), 6);
|
||||
_damageSpec += new DamageSpecifier(_prototypeManager.Index<DamageTypePrototype>("Radiation"), 3);
|
||||
_damageSpec += new DamageSpecifier(_prototypeManager.Index<DamageTypePrototype>("Slash"), -1); // already exists in brute
|
||||
_damageSpec = new(_prototypeManager.Index(BruteDamageGroup), 6);
|
||||
_damageSpec += new DamageSpecifier(_prototypeManager.Index(RadiationDamageType), 3);
|
||||
_damageSpec += new DamageSpecifier(_prototypeManager.Index(SlashDamageType), -1); // already exists in brute
|
||||
}
|
||||
|
||||
//Check that DamageSpecifier will split groups and can do arithmetic operations
|
||||
@@ -100,7 +105,7 @@ namespace Content.Tests.Shared
|
||||
Assert.That(damage, Is.EqualTo(FixedPoint2.New(3)));
|
||||
|
||||
// Lets also test the constructor with damage types and damage groups works properly.
|
||||
damageSpec = new(_prototypeManager.Index<DamageGroupPrototype>("Brute"), 4);
|
||||
damageSpec = new(_prototypeManager.Index(BruteDamageGroup), 4);
|
||||
Assert.That(damageSpec.DamageDict.TryGetValue("Blunt", out damage));
|
||||
Assert.That(damage, Is.EqualTo(FixedPoint2.New(1.33)));
|
||||
Assert.That(damageSpec.DamageDict.TryGetValue("Slash", out damage));
|
||||
@@ -108,7 +113,7 @@ namespace Content.Tests.Shared
|
||||
Assert.That(damageSpec.DamageDict.TryGetValue("Piercing", out damage));
|
||||
Assert.That(damage, Is.EqualTo(FixedPoint2.New(1.34))); // doesn't divide evenly, so the 0.01 goes to the last one
|
||||
|
||||
damageSpec = new(_prototypeManager.Index<DamageTypePrototype>("Piercing"), 4);
|
||||
damageSpec = new(_prototypeManager.Index(PiercingDamageType), 4);
|
||||
Assert.That(damageSpec.DamageDict.TryGetValue("Piercing", out damage));
|
||||
Assert.That(damage, Is.EqualTo(FixedPoint2.New(4)));
|
||||
}
|
||||
@@ -121,7 +126,7 @@ namespace Content.Tests.Shared
|
||||
DamageSpecifier damageSpec = 10 * new DamageSpecifier(_damageSpec);
|
||||
|
||||
// Create a modifier set
|
||||
var modifierSet = _prototypeManager.Index<DamageModifierSetPrototype>("ModifierTestSet");
|
||||
var modifierSet = _prototypeManager.Index<DamageModifierSetPrototype>(ModifierTestSetId);
|
||||
|
||||
//damage is initially 20 / 20 / 10 / 30
|
||||
//Each time we subtract -5 / 0 / 8 / 0.5
|
||||
@@ -142,8 +147,10 @@ namespace Content.Tests.Shared
|
||||
Assert.That(damageSpec.DamageDict["Radiation"], Is.EqualTo(FixedPoint2.New(65.62)));
|
||||
}
|
||||
|
||||
private const string ModifierTestSetId = "ModifierTestSet";
|
||||
|
||||
// Default damage Yaml
|
||||
private string _damagePrototypes = @"
|
||||
private readonly string _damagePrototypes = $@"
|
||||
- type: damageType
|
||||
id: Blunt
|
||||
name: damage-type-blunt
|
||||
@@ -268,7 +275,7 @@ namespace Content.Tests.Shared
|
||||
Blunt: 5
|
||||
|
||||
- type: damageModifierSet
|
||||
id: ModifierTestSet
|
||||
id: {ModifierTestSetId}
|
||||
coefficients:
|
||||
Piercing: -2
|
||||
Slash: 3
|
||||
|
||||
@@ -12,6 +12,8 @@ namespace Content.Tests.Shared;
|
||||
[TestOf(typeof(LocalizedDatasetPrototype))]
|
||||
public sealed class LocalizedDatasetPrototypeTest : ContentUnitTest
|
||||
{
|
||||
private const string TestDatasetId = "Test";
|
||||
|
||||
private IPrototypeManager _prototypeManager;
|
||||
|
||||
[OneTimeSetUp]
|
||||
@@ -24,9 +26,9 @@ public sealed class LocalizedDatasetPrototypeTest : ContentUnitTest
|
||||
_prototypeManager.ResolveResults();
|
||||
}
|
||||
|
||||
private const string TestPrototypes = @"
|
||||
private const string TestPrototypes = $@"
|
||||
- type: localizedDataset
|
||||
id: Test
|
||||
id: {TestDatasetId}
|
||||
values:
|
||||
prefix: test-dataset-
|
||||
count: 4
|
||||
@@ -35,7 +37,7 @@ public sealed class LocalizedDatasetPrototypeTest : ContentUnitTest
|
||||
[Test]
|
||||
public void LocalizedDatasetTest()
|
||||
{
|
||||
var testPrototype = _prototypeManager.Index<LocalizedDatasetPrototype>("Test");
|
||||
var testPrototype = _prototypeManager.Index<LocalizedDatasetPrototype>(TestDatasetId);
|
||||
var values = new ValueList<string>();
|
||||
foreach (var value in testPrototype.Values)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user