]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Skin color validation (#15140)
authorFlipp Syder <76629141+vulppine@users.noreply.github.com>
Wed, 5 Apr 2023 23:41:11 +0000 (16:41 -0700)
committerGitHub <noreply@github.com>
Wed, 5 Apr 2023 23:41:11 +0000 (17:41 -0600)
Content.Shared/Humanoid/HumanoidCharacterAppearance.cs
Content.Shared/Humanoid/SharedHumanoidAppearanceSystem.cs
Content.Shared/Humanoid/SkinColor.cs

index 4682f302aff8531bb4367b80793f5d8e65a515a2..134f71fc2777c802339a5d9de9fcc66824596baa 100644 (file)
@@ -217,23 +217,11 @@ namespace Content.Shared.Humanoid
                 markingSet = new MarkingSet(appearance.Markings, speciesProto.MarkingPoints, markingManager, proto);
                 markingSet.EnsureValid(markingManager);
 
-                switch (speciesProto.SkinColoration)
+                if (!Humanoid.SkinColor.VerifySkinColor(speciesProto.SkinColoration, skinColor))
                 {
-                    case HumanoidSkinColor.HumanToned:
-                        if (!Humanoid.SkinColor.VerifyHumanSkinTone(skinColor))
-                        {
-                            skinColor = Humanoid.SkinColor.ValidHumanSkinTone;
-                        }
-
-                        break;
-                    case HumanoidSkinColor.TintedHues:
-                        if (!Humanoid.SkinColor.VerifyTintedHues(skinColor))
-                        {
-                            skinColor = Humanoid.SkinColor.ValidTintedHuesSkinTone(skinColor);
-                        }
-
-                        break;
+                    skinColor = Humanoid.SkinColor.ValidSkinTone(speciesProto.SkinColoration, skinColor);
                 }
+
                 markingSet.EnsureSpecies(species, skinColor, markingManager);
             }
 
index 4f436bbf408505d54568eade357ceebe90f19741..0121e5adad8f68cfcfeb7d17207258abff249aeb 100644 (file)
@@ -150,6 +150,16 @@ public abstract class SharedHumanoidAppearanceSystem : EntitySystem
         if (!Resolve(uid, ref humanoid))
             return;
 
+        if (!_prototypeManager.TryIndex<SpeciesPrototype>(humanoid.Species, out var species))
+        {
+            return;
+        }
+
+        if (!SkinColor.VerifySkinColor(species.SkinColoration, skinColor))
+        {
+            skinColor = SkinColor.ValidSkinTone(species.SkinColoration, skinColor);
+        }
+
         humanoid.SkinColor = skinColor;
 
         if (sync)
index c3c1fdb509e525a9aefbb01ba3e398125269b552..44f69bf6aad8c2b382dac28b6c375c413034a11e 100644 (file)
@@ -133,6 +133,27 @@ public static class SkinColor
         // tinted hues just ensures saturation is always .1, or 10% saturation at all times
         return Color.ToHsv(color).Y != .1f;
     }
+
+    public static bool VerifySkinColor(HumanoidSkinColor type, Color color)
+    {
+        return type switch
+        {
+            HumanoidSkinColor.HumanToned => VerifyHumanSkinTone(color),
+            HumanoidSkinColor.TintedHues => VerifyTintedHues(color),
+            HumanoidSkinColor.Hues => true,
+            _ => false,
+        };
+    }
+
+    public static Color ValidSkinTone(HumanoidSkinColor type, Color color)
+    {
+        return type switch
+        {
+            HumanoidSkinColor.HumanToned => ValidHumanSkinTone,
+            HumanoidSkinColor.TintedHues => ValidTintedHuesSkinTone(color),
+            _ => color
+        };
+    }
 }
 
 public enum HumanoidSkinColor : byte