Lizard name datasets (#7890)
Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
using System;
|
||||
using Content.Shared.Dataset;
|
||||
using Content.Shared.Species;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Random;
|
||||
|
||||
namespace Content.Shared.CharacterAppearance
|
||||
{
|
||||
public enum Sex
|
||||
public enum Sex : byte
|
||||
{
|
||||
Male,
|
||||
Female
|
||||
@@ -13,19 +15,50 @@ namespace Content.Shared.CharacterAppearance
|
||||
|
||||
public static class SexExtensions
|
||||
{
|
||||
public static DatasetPrototype FirstNames(this Sex sex, IPrototypeManager? prototypeManager = null)
|
||||
public static string GetName(this Sex sex, string species, IPrototypeManager? prototypeManager = null, IRobustRandom? random = null)
|
||||
{
|
||||
prototypeManager ??= IoCManager.Resolve<IPrototypeManager>();
|
||||
IoCManager.Resolve(ref prototypeManager);
|
||||
IoCManager.Resolve(ref random);
|
||||
|
||||
// if they have an old species or whatever just fall back to human I guess?
|
||||
// Some downstream is probably gonna have this eventually but then they can deal with fallbacks.
|
||||
if (!prototypeManager.TryIndex(species, out SpeciesPrototype? speciesProto))
|
||||
{
|
||||
speciesProto = prototypeManager.Index<SpeciesPrototype>("Human");
|
||||
Logger.Warning($"Unable to find species {species} for name, falling back to Human");
|
||||
}
|
||||
|
||||
switch (speciesProto.Naming)
|
||||
{
|
||||
case SpeciesNaming.FirstDashFirst:
|
||||
return $"{GetFirstName(sex, speciesProto, prototypeManager, random)}-{GetFirstName(sex, speciesProto, prototypeManager, random)}";
|
||||
case SpeciesNaming.FirstLast:
|
||||
default:
|
||||
return $"{GetFirstName(sex, speciesProto, prototypeManager, random)} {GetLastName(sex, speciesProto, prototypeManager, random)}";
|
||||
}
|
||||
}
|
||||
|
||||
public static string GetFirstName(this Sex sex, SpeciesPrototype speciesProto, IPrototypeManager? protoManager = null, IRobustRandom? random = null)
|
||||
{
|
||||
IoCManager.Resolve(ref protoManager);
|
||||
IoCManager.Resolve(ref random);
|
||||
|
||||
switch (sex)
|
||||
{
|
||||
case Sex.Male:
|
||||
return prototypeManager.Index<DatasetPrototype>("names_first_male");
|
||||
return random.Pick(protoManager.Index<DatasetPrototype>(speciesProto.MaleFirstNames).Values);
|
||||
case Sex.Female:
|
||||
return prototypeManager.Index<DatasetPrototype>("names_first_female");
|
||||
return random.Pick(protoManager.Index<DatasetPrototype>(speciesProto.FemaleFirstNames).Values);
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(sex), sex, null);
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
}
|
||||
|
||||
public static string GetLastName(this Sex sex, SpeciesPrototype speciesProto, IPrototypeManager? protoManager = null, IRobustRandom? random = null)
|
||||
{
|
||||
IoCManager.Resolve(ref protoManager);
|
||||
IoCManager.Resolve(ref random);
|
||||
return random.Pick(protoManager.Index<DatasetPrototype>(speciesProto.LastNames).Values);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,17 +112,15 @@ namespace Content.Shared.Preferences
|
||||
|
||||
public static HumanoidCharacterProfile Random()
|
||||
{
|
||||
var prototypeManager = IoCManager.Resolve<IPrototypeManager>();
|
||||
var random = IoCManager.Resolve<IRobustRandom>();
|
||||
|
||||
var species = random.Pick(IoCManager.Resolve<IPrototypeManager>()
|
||||
var species = random.Pick(prototypeManager
|
||||
.EnumeratePrototypes<SpeciesPrototype>().Where(x => x.RoundStart).ToArray()).ID;
|
||||
var sex = random.Prob(0.5f) ? Sex.Male : Sex.Female;
|
||||
var gender = sex == Sex.Male ? Gender.Male : Gender.Female;
|
||||
|
||||
var prototypeManager = IoCManager.Resolve<IPrototypeManager>();
|
||||
var firstName = random.Pick(sex.FirstNames(prototypeManager).Values);
|
||||
var lastName = random.Pick(prototypeManager.Index<DatasetPrototype>("names_last"));
|
||||
var name = $"{firstName} {lastName}";
|
||||
var name = sex.GetName(species, prototypeManager, random);
|
||||
var age = random.Next(MinimumAge, MaximumAge);
|
||||
|
||||
return new HumanoidCharacterProfile(name, species, age, sex, gender, HumanoidCharacterAppearance.Random(sex), ClothingPreference.Jumpsuit, BackpackPreference.Backpack,
|
||||
@@ -279,7 +277,7 @@ namespace Content.Shared.Preferences
|
||||
string name;
|
||||
if (string.IsNullOrEmpty(Name))
|
||||
{
|
||||
name = RandomName();
|
||||
name = Sex.GetName(Species);
|
||||
}
|
||||
else if (Name.Length > MaxNameLength)
|
||||
{
|
||||
@@ -299,7 +297,7 @@ namespace Content.Shared.Preferences
|
||||
|
||||
if (string.IsNullOrEmpty(name))
|
||||
{
|
||||
name = RandomName();
|
||||
name = Sex.GetName(Species);
|
||||
}
|
||||
|
||||
var appearance = HumanoidCharacterAppearance.EnsureValid(Appearance, Species);
|
||||
@@ -361,15 +359,6 @@ namespace Content.Shared.Preferences
|
||||
|
||||
_antagPreferences.Clear();
|
||||
_antagPreferences.AddRange(antags);
|
||||
|
||||
string RandomName()
|
||||
{
|
||||
var random = IoCManager.Resolve<IRobustRandom>();
|
||||
var protoMan = IoCManager.Resolve<IPrototypeManager>();
|
||||
var firstName = random.Pick(Sex.FirstNames(protoMan).Values);
|
||||
var lastName = random.Pick(protoMan.Index<DatasetPrototype>("names_last"));
|
||||
return $"{firstName} {lastName}";
|
||||
}
|
||||
}
|
||||
|
||||
public override bool Equals(object? obj)
|
||||
|
||||
@@ -43,11 +43,29 @@ public sealed class SpeciesPrototype : IPrototype
|
||||
/// </summary>
|
||||
[DataField("skinColoration", required: true)]
|
||||
public SpeciesSkinColor SkinColoration { get; }
|
||||
|
||||
[DataField("maleFirstNames")]
|
||||
public string MaleFirstNames { get; } = "names_first_male";
|
||||
|
||||
[DataField("femaleFirstNames")]
|
||||
public string FemaleFirstNames { get; } = "names_first_female";
|
||||
|
||||
[DataField("lastNames")]
|
||||
public string LastNames { get; } = "names_last";
|
||||
|
||||
[DataField("naming")]
|
||||
public SpeciesNaming Naming { get; } = SpeciesNaming.FirstLast;
|
||||
}
|
||||
|
||||
public enum SpeciesSkinColor
|
||||
public enum SpeciesSkinColor : byte
|
||||
{
|
||||
HumanToned,
|
||||
Hues,
|
||||
TintedHues, //This gives a color tint to a humanoid's skin (10% saturation with full hue range).
|
||||
}
|
||||
|
||||
public enum SpeciesNaming : byte
|
||||
{
|
||||
FirstLast,
|
||||
FirstDashFirst,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user