From caa5efcd6f03543d8adfaa048144930d2357836c Mon Sep 17 00:00:00 2001 From: Flipp Syder <76629141+vulppine@users.noreply.github.com> Date: Thu, 22 Sep 2022 18:25:56 -0700 Subject: [PATCH] Humanoid patches (#11467) * restores species/age on examine * makes the default human skin tone a little less green * ensures human skin tone verification is rounded to the nearest integer value, adds tests for ensuring all human skin tones are valid and that the default skin tone is valid --- .../Humanoid/Systems/HumanoidSystem.cs | 39 ++++++++++++++++++- .../Humanoid/SharedHumanoidSystem.cs | 4 +- Content.Shared/Humanoid/SkinColor.cs | 8 ++-- .../Preferences/Humanoid/SkinTonesTest.cs | 24 ++++++++++++ 4 files changed, 69 insertions(+), 6 deletions(-) create mode 100644 Content.Tests/Shared/Preferences/Humanoid/SkinTonesTest.cs diff --git a/Content.Server/Humanoid/Systems/HumanoidSystem.cs b/Content.Server/Humanoid/Systems/HumanoidSystem.cs index bfbd4e6772..74ba3adc87 100644 --- a/Content.Server/Humanoid/Systems/HumanoidSystem.cs +++ b/Content.Server/Humanoid/Systems/HumanoidSystem.cs @@ -1,8 +1,10 @@ using System.Linq; using Content.Server.GameTicking; +using Content.Shared.Examine; using Content.Shared.Humanoid; using Content.Shared.Humanoid.Markings; using Content.Shared.Humanoid.Prototypes; +using Content.Shared.IdentityManagement; using Content.Shared.Inventory.Events; using Content.Shared.Preferences; using Content.Shared.Tag; @@ -14,8 +16,8 @@ namespace Content.Server.Humanoid; public sealed partial class HumanoidSystem : SharedHumanoidSystem { - [Dependency] private readonly IPrototypeManager _prototypeManager = default!; [Dependency] private readonly MarkingManager _markingManager = default!; + [Dependency] private readonly IPrototypeManager _prototypeManager = default!; public override void Initialize() { @@ -23,6 +25,7 @@ public sealed partial class HumanoidSystem : SharedHumanoidSystem SubscribeLocalEvent(OnMarkingsSet); SubscribeLocalEvent(OnBaseLayersSet); SubscribeLocalEvent>(OnVerbsRequest); + SubscribeLocalEvent(OnExamined); } private void Synchronize(EntityUid uid, HumanoidComponent? component = null) @@ -62,6 +65,15 @@ public sealed partial class HumanoidSystem : SharedHumanoidSystem } } + private void OnExamined(EntityUid uid, HumanoidComponent component, ExaminedEvent args) + { + var identity = Identity.Entity(component.Owner, EntityManager); + var species = GetSpeciesRepresentation(component.Species).ToLower(); + var age = GetAgeRepresentation(component.Age); + + args.PushText(Loc.GetString("humanoid-appearance-component-examine", ("user", identity), ("age", age), ("species", species))); + } + /// /// Loads a humanoid character profile directly onto this humanoid mob. /// @@ -464,6 +476,31 @@ public sealed partial class HumanoidSystem : SharedHumanoidSystem Synchronize(uid, humanoid); } + /// + /// Takes ID of the species prototype, returns UI-friendly name of the species. + /// + public string GetSpeciesRepresentation(string speciesId) + { + if (_prototypeManager.TryIndex(speciesId, out var species)) + { + return Loc.GetString(species.Name); + } + else + { + return Loc.GetString("humanoid-appearance-component-unknown-species"); + } + } + + public string GetAgeRepresentation(int age) + { + return age switch + { + <= 30 => Loc.GetString("identity-age-young"), + > 30 and <= 60 => Loc.GetString("identity-age-middle-aged"), + > 60 => Loc.GetString("identity-age-old") + }; + } + private void EnsureDefaultMarkings(EntityUid uid, HumanoidComponent? humanoid) { if (!Resolve(uid, ref humanoid)) diff --git a/Content.Shared/Humanoid/SharedHumanoidSystem.cs b/Content.Shared/Humanoid/SharedHumanoidSystem.cs index 73df70f951..342f1d8ef3 100644 --- a/Content.Shared/Humanoid/SharedHumanoidSystem.cs +++ b/Content.Shared/Humanoid/SharedHumanoidSystem.cs @@ -1,5 +1,7 @@ using Content.Shared.Humanoid.Markings; +using Content.Shared.Humanoid.Prototypes; using Content.Shared.Preferences; +using Robust.Shared.Prototypes; namespace Content.Shared.Humanoid; @@ -14,7 +16,7 @@ namespace Content.Shared.Humanoid; /// public abstract class SharedHumanoidSystem : EntitySystem { - [Dependency] private SharedAppearanceSystem _appearance = default!; + [Dependency] private readonly SharedAppearanceSystem _appearance = default!; public const string DefaultSpecies = "Human"; diff --git a/Content.Shared/Humanoid/SkinColor.cs b/Content.Shared/Humanoid/SkinColor.cs index 258ad7a1a6..75d24e9e92 100644 --- a/Content.Shared/Humanoid/SkinColor.cs +++ b/Content.Shared/Humanoid/SkinColor.cs @@ -2,7 +2,7 @@ namespace Content.Shared.Humanoid; public static class SkinColor { - public static Color ValidHumanSkinTone => Color.FromHsv(new Vector4(0.25f, 0.2f, 1f, 1f)); + public static Color ValidHumanSkinTone => Color.FromHsv(new Vector4(0.07f, 0.2f, 1f, 1f)); /// /// Turn a color into a valid tinted hue skin tone. @@ -93,9 +93,9 @@ public static class SkinColor { var colorValues = Color.ToHsv(color); - var hue = colorValues.X * 360f; - var sat = colorValues.Y * 100f; - var val = colorValues.Z * 100f; + var hue = Math.Round(colorValues.X * 360f); + var sat = Math.Round(colorValues.Y * 100f); + var val = Math.Round(colorValues.Z * 100f); // rangeOffset makes it so that this value // is 25 <= hue <= 45 if (hue < 25 || hue > 45) diff --git a/Content.Tests/Shared/Preferences/Humanoid/SkinTonesTest.cs b/Content.Tests/Shared/Preferences/Humanoid/SkinTonesTest.cs new file mode 100644 index 0000000000..e13825ea28 --- /dev/null +++ b/Content.Tests/Shared/Preferences/Humanoid/SkinTonesTest.cs @@ -0,0 +1,24 @@ +using Content.Shared.Humanoid; +using NUnit.Framework; + +namespace Content.Tests.Shared.Preferences.Humanoid; + +[TestFixture] +public sealed class SkinTonesTest +{ + [Test] + public void TestHumanSkinToneValidity() + { + for (var i = 0; i <= 100; i++) + { + var color = SkinColor.HumanSkinTone(i); + Assert.That(SkinColor.VerifyHumanSkinTone(color)); + } + } + + [Test] + public void TestDefaultSkinToneValid() + { + Assert.That(SkinColor.VerifyHumanSkinTone(SkinColor.ValidHumanSkinTone)); + } +}