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
This commit is contained in:
@@ -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<HumanoidComponent, HumanoidMarkingModifierMarkingSetMessage>(OnMarkingsSet);
|
||||
SubscribeLocalEvent<HumanoidComponent, HumanoidMarkingModifierBaseLayersSetMessage>(OnBaseLayersSet);
|
||||
SubscribeLocalEvent<HumanoidComponent, GetVerbsEvent<Verb>>(OnVerbsRequest);
|
||||
SubscribeLocalEvent<HumanoidComponent, ExaminedEvent>(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)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads a humanoid character profile directly onto this humanoid mob.
|
||||
/// </summary>
|
||||
@@ -464,6 +476,31 @@ public sealed partial class HumanoidSystem : SharedHumanoidSystem
|
||||
Synchronize(uid, humanoid);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Takes ID of the species prototype, returns UI-friendly name of the species.
|
||||
/// </summary>
|
||||
public string GetSpeciesRepresentation(string speciesId)
|
||||
{
|
||||
if (_prototypeManager.TryIndex<SpeciesPrototype>(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))
|
||||
|
||||
@@ -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;
|
||||
/// </summary>
|
||||
public abstract class SharedHumanoidSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private SharedAppearanceSystem _appearance = default!;
|
||||
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
|
||||
|
||||
public const string DefaultSpecies = "Human";
|
||||
|
||||
|
||||
@@ -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));
|
||||
|
||||
/// <summary>
|
||||
/// 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)
|
||||
|
||||
24
Content.Tests/Shared/Preferences/Humanoid/SkinTonesTest.cs
Normal file
24
Content.Tests/Shared/Preferences/Humanoid/SkinTonesTest.cs
Normal file
@@ -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));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user