mirror of
https://github.com/space-syndicate/space-station-14.git
synced 2026-10-09 18:31:17 +03:00
104 lines
3.5 KiB
C#
104 lines
3.5 KiB
C#
using Content.Shared.Corvax.TTS;
|
|
using Content.Shared.Examine;
|
|
using Content.Shared.Humanoid.Prototypes;
|
|
using Content.Shared.IdentityManagement;
|
|
using Content.Shared.Preferences;
|
|
using Robust.Shared.GameObjects.Components.Localization;
|
|
using Robust.Shared.Prototypes;
|
|
|
|
namespace Content.Shared.Humanoid;
|
|
|
|
public sealed partial class HumanoidProfileSystem : EntitySystem
|
|
{
|
|
[Dependency] private GrammarSystem _grammar = default!;
|
|
|
|
// Corvax-TTS-Start
|
|
public const string DefaultVoice = "Garithos";
|
|
public static readonly Dictionary<Sex, string> DefaultSexVoice = new()
|
|
{
|
|
{Sex.Male, "Garithos"},
|
|
{Sex.Female, "Maiev"},
|
|
{Sex.Unsexed, "Myron"},
|
|
};
|
|
// Corvax-TTS-End
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
SubscribeLocalEvent<HumanoidProfileComponent, ExaminedEvent>(OnExamined);
|
|
}
|
|
|
|
public void ApplyProfileTo(Entity<HumanoidProfileComponent?> ent, HumanoidCharacterProfile profile)
|
|
{
|
|
if (!Resolve(ent, ref ent.Comp))
|
|
return;
|
|
|
|
ent.Comp.Gender = profile.Gender;
|
|
ent.Comp.Age = profile.Age;
|
|
ent.Comp.Species = profile.Species;
|
|
ent.Comp.Voice = profile.Voice;
|
|
ent.Comp.Sex = profile.Sex;
|
|
// Corvax-TTS-start
|
|
ent.Comp.TTSVoice = profile.TTSVoice;
|
|
if (TryComp<TTSComponent>(ent, out var _TTSComponent) && _TTSComponent.VoicePrototypeId == "Taskmaster")
|
|
{
|
|
_TTSComponent.VoicePrototypeId = profile.TTSVoice;
|
|
}
|
|
// Corvax-TTS-end
|
|
Dirty(ent);
|
|
|
|
var voiceChanged = new VoiceChangedEvent(ent.Comp.Voice, profile.Voice);
|
|
RaiseLocalEvent(ent, ref voiceChanged);
|
|
|
|
if (TryComp<GrammarComponent>(ent, out var grammar))
|
|
{
|
|
_grammar.SetGender((ent, grammar), profile.Gender);
|
|
}
|
|
}
|
|
|
|
private void OnExamined(Entity<HumanoidProfileComponent> ent, ref ExaminedEvent args)
|
|
{
|
|
var identity = Identity.Entity(ent, EntityManager);
|
|
var species = GetSpeciesRepresentation(ent.Comp.Species).ToLower();
|
|
var age = GetAgeRepresentation(ent.Comp.Species, ent.Comp.Age);
|
|
|
|
args.PushText(Loc.GetString("humanoid-appearance-component-examine", ("user", identity), ("age", age), ("species", species)));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Takes ID of the species prototype, returns UI-friendly name of the species.
|
|
/// </summary>
|
|
public string GetSpeciesRepresentation(ProtoId<SpeciesPrototype> species)
|
|
{
|
|
if (ProtoMan.TryIndex(species, out var speciesPrototype))
|
|
return Loc.GetString(speciesPrototype.Name);
|
|
|
|
Log.Error("Tried to get representation of unknown species: {speciesId}");
|
|
return Loc.GetString("humanoid-appearance-component-unknown-species");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Takes ID of the species prototype and an age, returns an approximate description
|
|
/// </summary>
|
|
public string GetAgeRepresentation(ProtoId<SpeciesPrototype> species, int age)
|
|
{
|
|
if (!ProtoMan.TryIndex(species, out var speciesPrototype))
|
|
{
|
|
Log.Error("Tried to get age representation of species that couldn't be indexed: " + species);
|
|
return Loc.GetString("identity-age-young");
|
|
}
|
|
|
|
if (age < speciesPrototype.YoungAge)
|
|
{
|
|
return Loc.GetString("identity-age-young");
|
|
}
|
|
|
|
if (age < speciesPrototype.OldAge)
|
|
{
|
|
return Loc.GetString("identity-age-middle-aged");
|
|
}
|
|
|
|
return Loc.GetString("identity-age-old");
|
|
}
|
|
}
|