]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Added a test for the MagazineVisualsComponent and fixed found issues (#34491)
authorIgnaz "Ian" Kraft <ignaz.k@live.de>
Tue, 18 Feb 2025 12:32:54 +0000 (13:32 +0100)
committerGitHub <noreply@github.com>
Tue, 18 Feb 2025 12:32:54 +0000 (23:32 +1100)
Content.IntegrationTests/Tests/MagazineVisualsSpriteTest.cs [new file with mode: 0644]
Resources/Prototypes/Entities/Objects/Weapons/Guns/Ammunition/Magazines/caseless_rifle.yml
Resources/Prototypes/Entities/Objects/Weapons/Guns/Ammunition/Magazines/light_rifle.yml
Resources/Prototypes/Entities/Objects/Weapons/Guns/Ammunition/Magazines/magnum.yml
Resources/Prototypes/Entities/Objects/Weapons/Guns/Ammunition/Magazines/pistol.yml
Resources/Prototypes/Entities/Objects/Weapons/Guns/Ammunition/Magazines/rifle.yml
Resources/Prototypes/Entities/Objects/Weapons/Guns/Ammunition/SpeedLoaders/magnum.yml
Resources/Prototypes/Entities/Objects/Weapons/Guns/Battery/battery_guns.yml
Resources/Prototypes/Entities/Objects/Weapons/Guns/HMGs/hmgs.yml
Resources/Prototypes/Entities/Objects/Weapons/Guns/Launchers/launchers.yml

diff --git a/Content.IntegrationTests/Tests/MagazineVisualsSpriteTest.cs b/Content.IntegrationTests/Tests/MagazineVisualsSpriteTest.cs
new file mode 100644 (file)
index 0000000..f0f3b72
--- /dev/null
@@ -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();
+    }
+}
index 5aa1f285c82e0af05b5c3b6b374f1a4183aa982d..b12deec582ca0e2aa4dd6ae43e9834bb1075a554 100644 (file)
     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
index 57845643782e7def40d6550418fc425b75c6f04e..c2bf5efeff915aa4b5bc95588b64b94ee37771b2 100644 (file)
@@ -80,6 +80,8 @@
     layers:
     - state: base
       map: ["enum.GunVisualLayers.Base"]
+    - state: mag-1
+      map: ["enum.GunVisualLayers.Mag"]
 
 - type: entity
   id: MagazineLightRiflePractice
     sprite: Objects/Weapons/Guns/Ammunition/Magazine/LightRifle/pk_box.rsi
   - type: MagazineVisuals
     magState: mag
-    steps: 7
+    steps: 8
     zeroVisible: false
   - type: Appearance
index b7378b9991844b8c5685694fdca4f6d2786460fa..653ac8c06859dcb075a6301ebead14faab66672a 100644 (file)
@@ -59,6 +59,8 @@
     layers:
     - state: base
       map: ["enum.GunVisualLayers.Base"]
+    - state: mag-1
+      map: ["enum.GunVisualLayers.Mag"]
 
 - type: entity
   id: MagazineMagnum
     layers:
     - state: base
       map: ["enum.GunVisualLayers.Base"]
+    - state: mag-1
+      map: ["enum.GunVisualLayers.Mag"]
 
 - type: entity
   id: MagazineMagnumSubMachineGun
index b554a15a98b283966315c63eea9a48a639c90d7d..680ec5d795fdcf8e64aab04d78183910577d2c2d 100644 (file)
@@ -27,7 +27,7 @@
       map: ["enum.GunVisualLayers.Mag"]
   - type: MagazineVisuals
     magState: mag
-    steps: 5
+    steps: 6
     zeroVisible: false
   - type: Appearance
 
     layers:
     - state: base
       map: ["enum.GunVisualLayers.Base"]
+    - state: mag-1
+      map: ["enum.GunVisualLayers.Mag"]
 
 
 - type: entity
     layers:
     - state: base
       map: ["enum.GunVisualLayers.Base"]
+    - state: mag-1
+      map: ["enum.GunVisualLayers.Mag"]
 
 - type: entity
   id: MagazinePistolHighCapacity
     layers:
     - state: base
       map: ["enum.GunVisualLayers.Base"]
+    - state: mag-1
+      map: ["enum.GunVisualLayers.Mag"]
 
 - type: entity
   id: MagazinePistolSubMachineGunPractice
index c882a3b2f173926a652f5b0947c15354e4e2e116..8e15cb18ba49208deb65a23e6607e25b343d23df 100644 (file)
@@ -59,6 +59,8 @@
     layers:
     - state: base
       map: ["enum.GunVisualLayers.Base"]
+    - state: mag-1
+      map: ["enum.GunVisualLayers.Mag"]
 
 - type: entity
   id: MagazineRifleIncendiary
index ae6bf0cebfe3fc845458cab566d178b844ec1d37..fd02fdf21b37a6b0246b856744201375ca846f0c 100644 (file)
     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
index c51aef5fe86b62ab09a61b815b94c5ef6a01265f..6426e59bd5fd3cf905a78c07477d8569b84cca0e 100644 (file)
   - type: Battery
     maxCharge: 1000
     startingCharge: 1000
-  - type: MagazineVisuals
-    magState: mag
-    steps: 5
-    zeroVisible: false
-  - type: Appearance
   - type: StaticPrice
     price: 500
 
     - 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
     - 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
     - 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
     - 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
     - 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
     - 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
     magState: mag
     steps: 5
     zeroVisible: true
+  - type: Appearance
   - type: StaticPrice
     price: 260
 
   - type: BatterySelfRecharger
     autoRecharge: true
     autoRechargeRate: 40
-  - type: MagazineVisuals
-    magState: mag
-    steps: 5
-    zeroVisible: true
-  - type: Appearance
   - type: StaticPrice
     price: 750
 
       - 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
index ebcba7d5e4469fba09a0bb91a0c89f6425824eb6..e1de308b12352d52103697e5874993af02ece40b 100644 (file)
@@ -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
   - type: BallisticAmmoProvider
     proto: CartridgeMinigun
     capacity: 1000
-  - type: MagazineVisuals
-    magState: mag
-    steps: 4
-    zeroVisible: true
-  - type: Appearance
   - type: ContainerContainer
     containers:
       ballistic-ammo: !type:Container
index 4c48ec1f20a8c07d9ff46bf7e1d431efe5b03dd5..64f1fdac297930bf1bf2e6386507eb28fa169739 100644 (file)
       path: /Audio/Weapons/Guns/MagIn/batrifle_magin.ogg
   - type: MagazineVisuals
     magState: mag
-    steps: 1
+    steps: 2
     zeroVisible: true
   - type: Appearance