Added a test for the MagazineVisualsComponent and fixed found issues (#34491)
This commit is contained in:
committed by
GitHub
parent
834e11a482
commit
6d1cdd8639
70
Content.IntegrationTests/Tests/MagazineVisualsSpriteTest.cs
Normal file
70
Content.IntegrationTests/Tests/MagazineVisualsSpriteTest.cs
Normal file
@@ -0,0 +1,70 @@
|
||||
using System.Collections.Generic;
|
||||
using Content.Client.Weapons.Ranged.Components;
|
||||
using Content.Shared.Prototypes;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.IntegrationTests.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// Tests all entity prototypes with the MagazineVisualsComponent.
|
||||
/// </summary>
|
||||
[TestFixture]
|
||||
public sealed class MagazineVisualsSpriteTest
|
||||
{
|
||||
[Test]
|
||||
public async Task MagazineVisualsSpritesExist()
|
||||
{
|
||||
await using var pair = await PoolManager.GetServerClient();
|
||||
var client = pair.Client;
|
||||
var protoMan = client.ResolveDependency<IPrototypeManager>();
|
||||
var componentFactory = client.ResolveDependency<IComponentFactory>();
|
||||
|
||||
await client.WaitAssertion(() =>
|
||||
{
|
||||
foreach (var proto in protoMan.EnumeratePrototypes<EntityPrototype>())
|
||||
{
|
||||
if (proto.Abstract || pair.IsTestPrototype(proto))
|
||||
continue;
|
||||
|
||||
if (!proto.TryGetComponent<MagazineVisualsComponent>(out var visuals, componentFactory))
|
||||
continue;
|
||||
|
||||
Assert.That(proto.TryGetComponent<SpriteComponent>(out var sprite, componentFactory),
|
||||
@$"{proto.ID} has MagazineVisualsComponent but no SpriteComponent.");
|
||||
Assert.That(proto.HasComponent<AppearanceComponent>(componentFactory),
|
||||
@$"{proto.ID} has MagazineVisualsComponent but no AppearanceComponent.");
|
||||
|
||||
var toTest = new List<(int, string)>();
|
||||
if (sprite.LayerMapTryGet(GunVisualLayers.Mag, out var magLayerId))
|
||||
toTest.Add((magLayerId, ""));
|
||||
if (sprite.LayerMapTryGet(GunVisualLayers.MagUnshaded, out var magUnshadedLayerId))
|
||||
toTest.Add((magUnshadedLayerId, "-unshaded"));
|
||||
|
||||
Assert.That(toTest, Is.Not.Empty,
|
||||
@$"{proto.ID} has MagazineVisualsComponent but no Mag or MagUnshaded layer map.");
|
||||
|
||||
var start = visuals.ZeroVisible ? 0 : 1;
|
||||
foreach (var (id, midfix) in toTest)
|
||||
{
|
||||
Assert.That(sprite.TryGetLayer(id, out var layer));
|
||||
var rsi = layer.ActualRsi;
|
||||
for (var i = start; i < visuals.MagSteps; i++)
|
||||
{
|
||||
var state = $"{visuals.MagState}{midfix}-{i}";
|
||||
Assert.That(rsi.TryGetState(state, out _),
|
||||
@$"{proto.ID} has MagazineVisualsComponent with MagSteps = {visuals.MagSteps}, but {rsi.Path} doesn't have state {state}!");
|
||||
}
|
||||
|
||||
// MagSteps includes the 0th step, so sometimes people are off by one.
|
||||
var extraState = $"{visuals.MagState}{midfix}-{visuals.MagSteps}";
|
||||
Assert.That(rsi.TryGetState(extraState, out _), Is.False,
|
||||
@$"{proto.ID} has MagazineVisualsComponent with MagSteps = {visuals.MagSteps}, but more states exist!");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
await pair.CleanReturnAsync();
|
||||
}
|
||||
}
|
||||
@@ -91,6 +91,10 @@
|
||||
capacity: 99
|
||||
- type: Sprite
|
||||
sprite: Objects/Weapons/Guns/Ammunition/Magazine/CaselessRifle/10x24.rsi
|
||||
- type: MagazineVisuals
|
||||
magState: mag
|
||||
steps: 8
|
||||
zeroVisible: false
|
||||
|
||||
- type: entity
|
||||
id: MagazinePistolCaselessRifle
|
||||
|
||||
@@ -80,6 +80,8 @@
|
||||
layers:
|
||||
- state: base
|
||||
map: ["enum.GunVisualLayers.Base"]
|
||||
- state: mag-1
|
||||
map: ["enum.GunVisualLayers.Mag"]
|
||||
|
||||
- type: entity
|
||||
id: MagazineLightRiflePractice
|
||||
@@ -146,6 +148,6 @@
|
||||
sprite: Objects/Weapons/Guns/Ammunition/Magazine/LightRifle/pk_box.rsi
|
||||
- type: MagazineVisuals
|
||||
magState: mag
|
||||
steps: 7
|
||||
steps: 8
|
||||
zeroVisible: false
|
||||
- type: Appearance
|
||||
|
||||
@@ -59,6 +59,8 @@
|
||||
layers:
|
||||
- state: base
|
||||
map: ["enum.GunVisualLayers.Base"]
|
||||
- state: mag-1
|
||||
map: ["enum.GunVisualLayers.Mag"]
|
||||
|
||||
- type: entity
|
||||
id: MagazineMagnum
|
||||
@@ -129,6 +131,8 @@
|
||||
layers:
|
||||
- state: base
|
||||
map: ["enum.GunVisualLayers.Base"]
|
||||
- state: mag-1
|
||||
map: ["enum.GunVisualLayers.Mag"]
|
||||
|
||||
- type: entity
|
||||
id: MagazineMagnumSubMachineGun
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
map: ["enum.GunVisualLayers.Mag"]
|
||||
- type: MagazineVisuals
|
||||
magState: mag
|
||||
steps: 5
|
||||
steps: 6
|
||||
zeroVisible: false
|
||||
- type: Appearance
|
||||
|
||||
@@ -162,6 +162,8 @@
|
||||
layers:
|
||||
- state: base
|
||||
map: ["enum.GunVisualLayers.Base"]
|
||||
- state: mag-1
|
||||
map: ["enum.GunVisualLayers.Mag"]
|
||||
|
||||
|
||||
- type: entity
|
||||
@@ -212,6 +214,8 @@
|
||||
layers:
|
||||
- state: base
|
||||
map: ["enum.GunVisualLayers.Base"]
|
||||
- state: mag-1
|
||||
map: ["enum.GunVisualLayers.Mag"]
|
||||
|
||||
- type: entity
|
||||
id: MagazinePistolHighCapacity
|
||||
@@ -273,6 +277,8 @@
|
||||
layers:
|
||||
- state: base
|
||||
map: ["enum.GunVisualLayers.Base"]
|
||||
- state: mag-1
|
||||
map: ["enum.GunVisualLayers.Mag"]
|
||||
|
||||
- type: entity
|
||||
id: MagazinePistolSubMachineGunPractice
|
||||
|
||||
@@ -59,6 +59,8 @@
|
||||
layers:
|
||||
- state: base
|
||||
map: ["enum.GunVisualLayers.Base"]
|
||||
- state: mag-1
|
||||
map: ["enum.GunVisualLayers.Mag"]
|
||||
|
||||
- type: entity
|
||||
id: MagazineRifleIncendiary
|
||||
|
||||
@@ -51,6 +51,11 @@
|
||||
layers:
|
||||
- state: base
|
||||
map: [ "enum.GunVisualLayers.Base" ]
|
||||
# TODO: This is actually a issue with all the speed loaders:
|
||||
# You can mix different ammo types, but it will always
|
||||
# use the one it was printed for.
|
||||
- state: base-6
|
||||
map: [ "enum.GunVisualLayers.Mag" ]
|
||||
|
||||
- type: entity
|
||||
id: SpeedLoaderMagnumIncendiary
|
||||
|
||||
@@ -23,11 +23,6 @@
|
||||
- type: Battery
|
||||
maxCharge: 1000
|
||||
startingCharge: 1000
|
||||
- type: MagazineVisuals
|
||||
magState: mag
|
||||
steps: 5
|
||||
zeroVisible: false
|
||||
- type: Appearance
|
||||
- type: StaticPrice
|
||||
price: 500
|
||||
|
||||
@@ -160,6 +155,11 @@
|
||||
- state: mag-unshaded-4
|
||||
map: ["enum.GunVisualLayers.MagUnshaded"]
|
||||
shader: unshaded
|
||||
- type: MagazineVisuals
|
||||
magState: mag
|
||||
steps: 5
|
||||
zeroVisible: false
|
||||
- type: Appearance
|
||||
- type: Clothing
|
||||
sprite: Objects/Weapons/Guns/Battery/makeshift.rsi
|
||||
- type: HitscanBatteryAmmoProvider
|
||||
@@ -212,6 +212,11 @@
|
||||
- state: mag-unshaded-4
|
||||
map: ["enum.GunVisualLayers.MagUnshaded"]
|
||||
shader: unshaded
|
||||
- type: MagazineVisuals
|
||||
magState: mag
|
||||
steps: 5
|
||||
zeroVisible: false
|
||||
- type: Appearance
|
||||
- type: Clothing
|
||||
sprite: Objects/Weapons/Guns/Battery/laser_gun.rsi
|
||||
- type: Gun
|
||||
@@ -250,6 +255,11 @@
|
||||
- state: mag-unshaded-4
|
||||
map: ["enum.GunVisualLayers.MagUnshaded"]
|
||||
shader: unshaded
|
||||
- type: MagazineVisuals
|
||||
magState: mag
|
||||
steps: 5
|
||||
zeroVisible: false
|
||||
- type: Appearance
|
||||
- type: Clothing
|
||||
sprite: Objects/Weapons/Guns/Battery/pulse_pistol.rsi
|
||||
- type: Gun
|
||||
@@ -279,6 +289,11 @@
|
||||
- state: mag-unshaded-4
|
||||
map: ["enum.GunVisualLayers.MagUnshaded"]
|
||||
shader: unshaded
|
||||
- type: MagazineVisuals
|
||||
magState: mag
|
||||
steps: 5
|
||||
zeroVisible: false
|
||||
- type: Appearance
|
||||
- type: Clothing
|
||||
sprite: Objects/Weapons/Guns/Battery/pulse_carbine.rsi
|
||||
- type: Gun
|
||||
@@ -310,6 +325,11 @@
|
||||
- state: mag-unshaded-4
|
||||
map: ["enum.GunVisualLayers.MagUnshaded"]
|
||||
shader: unshaded
|
||||
- type: MagazineVisuals
|
||||
magState: mag
|
||||
steps: 5
|
||||
zeroVisible: false
|
||||
- type: Appearance
|
||||
- type: Clothing
|
||||
sprite: Objects/Weapons/Guns/Battery/pulse_rifle.rsi
|
||||
- type: Gun
|
||||
@@ -337,6 +357,11 @@
|
||||
- state: mag-unshaded-4
|
||||
map: ["enum.GunVisualLayers.MagUnshaded"]
|
||||
shader: unshaded
|
||||
- type: MagazineVisuals
|
||||
magState: mag
|
||||
steps: 5
|
||||
zeroVisible: false
|
||||
- type: Appearance
|
||||
- type: Clothing
|
||||
sprite: Objects/Weapons/Guns/Battery/laser_cannon.rsi
|
||||
- type: Gun
|
||||
@@ -507,6 +532,7 @@
|
||||
magState: mag
|
||||
steps: 5
|
||||
zeroVisible: true
|
||||
- type: Appearance
|
||||
- type: StaticPrice
|
||||
price: 260
|
||||
|
||||
@@ -711,11 +737,6 @@
|
||||
- type: BatterySelfRecharger
|
||||
autoRecharge: true
|
||||
autoRechargeRate: 40
|
||||
- type: MagazineVisuals
|
||||
magState: mag
|
||||
steps: 5
|
||||
zeroVisible: true
|
||||
- type: Appearance
|
||||
- type: StaticPrice
|
||||
price: 750
|
||||
|
||||
@@ -733,6 +754,11 @@
|
||||
- state: mag-unshaded-4
|
||||
map: ["enum.GunVisualLayers.MagUnshaded"]
|
||||
shader: unshaded
|
||||
- type: MagazineVisuals
|
||||
magState: mag
|
||||
steps: 5
|
||||
zeroVisible: false
|
||||
- type: Appearance
|
||||
- type: Clothing
|
||||
sprite: Objects/Weapons/Guns/Battery/energy_shotgun.rsi
|
||||
- type: Gun
|
||||
|
||||
@@ -31,7 +31,6 @@
|
||||
sprite: Objects/Weapons/Guns/HMGs/minigun.rsi
|
||||
layers:
|
||||
- state: icon
|
||||
map: ["enum.GunVisualLayers.Base"]
|
||||
- type: Item
|
||||
sprite: Objects/Weapons/Guns/HMGs/minigun.rsi
|
||||
- type: Gun
|
||||
@@ -41,11 +40,6 @@
|
||||
- type: BallisticAmmoProvider
|
||||
proto: CartridgeMinigun
|
||||
capacity: 1000
|
||||
- type: MagazineVisuals
|
||||
magState: mag
|
||||
steps: 4
|
||||
zeroVisible: true
|
||||
- type: Appearance
|
||||
- type: ContainerContainer
|
||||
containers:
|
||||
ballistic-ammo: !type:Container
|
||||
|
||||
@@ -117,7 +117,7 @@
|
||||
path: /Audio/Weapons/Guns/MagIn/batrifle_magin.ogg
|
||||
- type: MagazineVisuals
|
||||
magState: mag
|
||||
steps: 1
|
||||
steps: 2
|
||||
zeroVisible: true
|
||||
- type: Appearance
|
||||
|
||||
|
||||
Reference in New Issue
Block a user