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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user