Let species prototypes define valid sexes (Sex Refactor) (#11520)

This commit is contained in:
Rane
2022-10-15 17:45:47 -04:00
committed by GitHub
parent 0e18ba567c
commit c70e423ff6
14 changed files with 161 additions and 97 deletions

View File

@@ -5,58 +5,11 @@ using Robust.Shared.Random;
namespace Content.Shared.Humanoid
{
// You need to update profile, profile editor, maybe voices and names if you want to expand this further.
public enum Sex : byte
{
Male,
Female
}
public static class SexExtensions
{
public static string GetName(this Sex sex, string species, IPrototypeManager? prototypeManager = null, IRobustRandom? random = null)
{
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 random.Pick(protoManager.Index<DatasetPrototype>(speciesProto.MaleFirstNames).Values);
case Sex.Female:
return random.Pick(protoManager.Index<DatasetPrototype>(speciesProto.FemaleFirstNames).Values);
default:
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);
}
Female,
Unsexed,
}
}