Skin color validation (#15140)

This commit is contained in:
Flipp Syder
2023-04-05 16:41:11 -07:00
committed by GitHub
parent 661329ab72
commit c02824a85c
3 changed files with 34 additions and 15 deletions

View 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;
skinColor = Humanoid.SkinColor.ValidSkinTone(speciesProto.SkinColoration, skinColor);
}
break;
case HumanoidSkinColor.TintedHues:
if (!Humanoid.SkinColor.VerifyTintedHues(skinColor))
{
skinColor = Humanoid.SkinColor.ValidTintedHuesSkinTone(skinColor);
}
break;
}
markingSet.EnsureSpecies(species, skinColor, markingManager);
}

View 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)

View 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