]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Add support for metamorphic fill levels (#25022)
authorTayrtahn <tayrtahn@gmail.com>
Mon, 19 Feb 2024 21:29:42 +0000 (16:29 -0500)
committerGitHub <noreply@github.com>
Mon, 19 Feb 2024 21:29:42 +0000 (14:29 -0700)
* Added support for fill levels to metamorphic glasses

* Fix warnings and cleanup

* Don't break non-metamorphic fills!

Content.Client/Chemistry/Visualizers/SolutionContainerVisualsSystem.cs
Content.Shared/Chemistry/Reagent/ReagentPrototype.cs

index b4486b8c0ee9859b8a3e20ef252d0660a065805a..f1e8e8d7aa445bd1c19d51e7ecbf22fabbaacd47 100644 (file)
@@ -49,12 +49,17 @@ public sealed class SolutionContainerVisualsSystem : VisualizerSystem<SolutionCo
         if (!args.Sprite.LayerMapTryGet(component.Layer, out var fillLayer))
             return;
 
+        var maxFillLevels = component.MaxFillLevels;
+        var fillBaseName = component.FillBaseName;
+        var changeColor = component.ChangeColor;
+        var fillSprite = component.MetamorphicDefaultSprite;
+
         // Currently some solution methods such as overflowing will try to update appearance with a
         // volume greater than the max volume. We'll clamp it so players don't see
         // a giant error sign and error for debug.
         if (fraction > 1f)
         {
-            Logger.Error("Attempted to set solution container visuals volume ratio on " + ToPrettyString(uid) + " to a value greater than 1. Volume should never be greater than max volume!");
+            Log.Error("Attempted to set solution container visuals volume ratio on " + ToPrettyString(uid) + " to a value greater than 1. Volume should never be greater than max volume!");
             fraction = 1f;
         }
         if (component.Metamorphic)
@@ -72,13 +77,23 @@ public sealed class SolutionContainerVisualsSystem : VisualizerSystem<SolutionCo
                     if (reagentProto?.MetamorphicSprite is { } sprite)
                     {
                         args.Sprite.LayerSetSprite(baseLayer, sprite);
-                        args.Sprite.LayerSetVisible(fillLayer, false);
+                        if (reagentProto.MetamorphicMaxFillLevels > 0)
+                        {
+                            args.Sprite.LayerSetVisible(fillLayer, true);
+                            maxFillLevels = reagentProto.MetamorphicMaxFillLevels;
+                            fillBaseName = reagentProto.MetamorphicFillBaseName;
+                            changeColor = reagentProto.MetamorphicChangeColor;
+                            fillSprite = sprite;
+                        }
+                        else
+                            args.Sprite.LayerSetVisible(fillLayer, false);
+
                         if (hasOverlay)
                             args.Sprite.LayerSetVisible(overlayLayer, false);
-                        return;
                     }
                     else
                     {
+                        args.Sprite.LayerSetVisible(fillLayer, true);
                         if (hasOverlay)
                             args.Sprite.LayerSetVisible(overlayLayer, true);
                         if (component.MetamorphicDefaultSprite != null)
@@ -87,21 +102,27 @@ public sealed class SolutionContainerVisualsSystem : VisualizerSystem<SolutionCo
                 }
             }
         }
+        else
+        {
+            args.Sprite.LayerSetVisible(fillLayer, true);
+        }
 
-        int closestFillSprite = ContentHelpers.RoundToLevels(fraction, 1, component.MaxFillLevels + 1);
+        var closestFillSprite = ContentHelpers.RoundToLevels(fraction, 1, maxFillLevels + 1);
 
         if (closestFillSprite > 0)
         {
-            if (component.FillBaseName == null)
+            if (fillBaseName == null)
                 return;
 
-            args.Sprite.LayerSetVisible(fillLayer, true);
-
-            var stateName = component.FillBaseName + closestFillSprite;
+            var stateName = fillBaseName + closestFillSprite;
+            if (fillSprite != null)
+                args.Sprite.LayerSetSprite(fillLayer, fillSprite);
             args.Sprite.LayerSetState(fillLayer, stateName);
 
-            if (component.ChangeColor && AppearanceSystem.TryGetData<Color>(uid, SolutionContainerVisuals.Color, out var color, args.Component))
+            if (changeColor && AppearanceSystem.TryGetData<Color>(uid, SolutionContainerVisuals.Color, out var color, args.Component))
                 args.Sprite.LayerSetColor(fillLayer, color);
+            else
+                args.Sprite.LayerSetColor(fillLayer, Color.White);
         }
         else
         {
@@ -110,8 +131,10 @@ public sealed class SolutionContainerVisualsSystem : VisualizerSystem<SolutionCo
             else
             {
                 args.Sprite.LayerSetState(fillLayer, component.EmptySpriteName);
-                if (component.ChangeColor)
+                if (changeColor)
                     args.Sprite.LayerSetColor(fillLayer, component.EmptySpriteColor);
+                else
+                    args.Sprite.LayerSetColor(fillLayer, Color.White);
             }
         }
 
@@ -130,7 +153,7 @@ public sealed class SolutionContainerVisualsSystem : VisualizerSystem<SolutionCo
         if (!AppearanceSystem.TryGetData<float>(uid, SolutionContainerVisuals.FillFraction, out var fraction, appearance))
             return;
 
-        int closestFillSprite = ContentHelpers.RoundToLevels(fraction, 1, component.InHandsMaxFillLevels + 1);
+        var closestFillSprite = ContentHelpers.RoundToLevels(fraction, 1, component.InHandsMaxFillLevels + 1);
 
         if (closestFillSprite > 0)
         {
index f71afa7f479273d4c1a43c05caa14bf2c4e7c361..5d6d9d21208efce5e063d8ec88732f391da02ca4 100644 (file)
@@ -89,6 +89,15 @@ namespace Content.Shared.Chemistry.Reagent
         [DataField]
         public SpriteSpecifier? MetamorphicSprite { get; private set; } = null;
 
+        [DataField]
+        public int MetamorphicMaxFillLevels { get; private set; } = 0;
+
+        [DataField]
+        public string? MetamorphicFillBaseName { get; private set; } = null;
+
+        [DataField]
+        public bool MetamorphicChangeColor { get; private set; } = true;
+
         /// <summary>
         /// If this reagent is part of a puddle is it slippery.
         /// </summary>
@@ -102,7 +111,7 @@ namespace Content.Shared.Chemistry.Reagent
         [DataField]
         public float Viscosity;
 
-         /// <summary>
+        /// <summary>
         /// Should this reagent work on the dead?
         /// </summary>
         [DataField]
@@ -163,7 +172,7 @@ namespace Content.Shared.Chemistry.Reagent
                 if (plantMetabolizable.ShouldLog)
                 {
                     var entity = args.SolutionEntity;
-                    EntitySystem.Get<SharedAdminLogSystem>().Add(LogType.ReagentEffect, plantMetabolizable.LogImpact,
+                    entMan.System<SharedAdminLogSystem>().Add(LogType.ReagentEffect, plantMetabolizable.LogImpact,
                         $"Plant metabolism effect {plantMetabolizable.GetType().Name:effect} of reagent {ID:reagent} applied on entity {entMan.ToPrettyString(entity):entity} at {entMan.GetComponent<TransformComponent>(entity).Coordinates:coordinates}");
                 }