From: deltanedas <39013340+deltanedas@users.noreply.github.com> Date: Mon, 8 Apr 2024 15:16:21 +0000 (+0000) Subject: predict humanoid identity examine (#26769) X-Git-Url: https://git.smokeofanarchy.ru/gitweb.cgi?a=commitdiff_plain;h=2f5c639a151ace90365e929486ba479655b9cd63;p=space-station-14.git predict humanoid identity examine (#26769) * predict humanoid identity examine * actually server doesnt need proto anymore --------- Co-authored-by: deltanedas <@deltanedas:kde.org> --- diff --git a/Content.Server/Humanoid/Systems/HumanoidAppearanceSystem.cs b/Content.Server/Humanoid/Systems/HumanoidAppearanceSystem.cs index 89d28e5102..505ad4f16c 100644 --- a/Content.Server/Humanoid/Systems/HumanoidAppearanceSystem.cs +++ b/Content.Server/Humanoid/Systems/HumanoidAppearanceSystem.cs @@ -1,36 +1,23 @@ -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.Preferences; using Content.Shared.Verbs; using Robust.Shared.GameObjects.Components.Localization; -using Robust.Shared.Prototypes; namespace Content.Server.Humanoid; public sealed partial class HumanoidAppearanceSystem : SharedHumanoidAppearanceSystem { [Dependency] private readonly MarkingManager _markingManager = default!; - [Dependency] private readonly IPrototypeManager _prototypeManager = default!; public override void Initialize() { base.Initialize(); + SubscribeLocalEvent(OnMarkingsSet); SubscribeLocalEvent(OnBaseLayersSet); SubscribeLocalEvent>(OnVerbsRequest); - SubscribeLocalEvent(OnExamined); - } - - private void OnExamined(EntityUid uid, HumanoidAppearanceComponent component, ExaminedEvent args) - { - var identity = Identity.Entity(uid, EntityManager); - var species = GetSpeciesRepresentation(component.Species).ToLower(); - var age = GetAgeRepresentation(component.Species, component.Age); - - args.PushText(Loc.GetString("humanoid-appearance-component-examine", ("user", identity), ("age", age), ("species", species))); } // this was done enough times that it only made sense to do it here @@ -164,42 +151,4 @@ public sealed partial class HumanoidAppearanceSystem : SharedHumanoidAppearanceS Dirty(uid, humanoid); } - - /// - /// Takes ID of the species prototype, returns UI-friendly name of the species. - /// - public string GetSpeciesRepresentation(string speciesId) - { - if (_prototypeManager.TryIndex(speciesId, out var species)) - { - return Loc.GetString(species.Name); - } - else - { - return Loc.GetString("humanoid-appearance-component-unknown-species"); - } - } - - public string GetAgeRepresentation(string species, int age) - { - _prototypeManager.TryIndex(species, out var speciesPrototype); - - if (speciesPrototype == null) - { - 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"); - } } diff --git a/Content.Shared/Humanoid/SharedHumanoidAppearanceSystem.cs b/Content.Shared/Humanoid/SharedHumanoidAppearanceSystem.cs index b7ef784d00..2a846d7fe2 100644 --- a/Content.Shared/Humanoid/SharedHumanoidAppearanceSystem.cs +++ b/Content.Shared/Humanoid/SharedHumanoidAppearanceSystem.cs @@ -1,7 +1,9 @@ using System.Linq; using Content.Shared.Decals; +using Content.Shared.Examine; using Content.Shared.Humanoid.Markings; using Content.Shared.Humanoid.Prototypes; +using Content.Shared.IdentityManagement; using Content.Shared.Preferences; using Robust.Shared.GameObjects.Components.Localization; using Robust.Shared.Network; @@ -21,7 +23,7 @@ namespace Content.Shared.Humanoid; public abstract class SharedHumanoidAppearanceSystem : EntitySystem { [Dependency] private readonly INetManager _netManager = default!; - [Dependency] private readonly IPrototypeManager _prototypeManager = default!; + [Dependency] private readonly IPrototypeManager _proto = default!; [Dependency] private readonly MarkingManager _markingManager = default!; [ValidatePrototypeId] @@ -30,7 +32,9 @@ public abstract class SharedHumanoidAppearanceSystem : EntitySystem public override void Initialize() { base.Initialize(); + SubscribeLocalEvent(OnInit); + SubscribeLocalEvent(OnExamined); } private void OnInit(EntityUid uid, HumanoidAppearanceComponent humanoid, ComponentInit args) @@ -41,7 +45,7 @@ public abstract class SharedHumanoidAppearanceSystem : EntitySystem } if (string.IsNullOrEmpty(humanoid.Initial) - || !_prototypeManager.TryIndex(humanoid.Initial, out HumanoidProfilePrototype? startingSet)) + || !_proto.TryIndex(humanoid.Initial, out HumanoidProfilePrototype? startingSet)) { LoadProfile(uid, HumanoidCharacterProfile.DefaultWithSpecies(humanoid.Species), humanoid); return; @@ -56,6 +60,15 @@ public abstract class SharedHumanoidAppearanceSystem : EntitySystem LoadProfile(uid, startingSet.Profile, humanoid); } + private void OnExamined(EntityUid uid, HumanoidAppearanceComponent component, ExaminedEvent args) + { + var identity = Identity.Entity(uid, EntityManager); + var species = GetSpeciesRepresentation(component.Species).ToLower(); + var age = GetAgeRepresentation(component.Species, component.Age); + + args.PushText(Loc.GetString("humanoid-appearance-component-examine", ("user", identity), ("age", age), ("species", species))); + } + /// /// Toggles a humanoid's sprite layer visibility. /// @@ -136,7 +149,7 @@ public abstract class SharedHumanoidAppearanceSystem : EntitySystem /// Humanoid component of the entity public void SetSpecies(EntityUid uid, string species, bool sync = true, HumanoidAppearanceComponent? humanoid = null) { - if (!Resolve(uid, ref humanoid) || !_prototypeManager.TryIndex(species, out var prototype)) + if (!Resolve(uid, ref humanoid) || !_proto.TryIndex(species, out var prototype)) { return; } @@ -144,7 +157,7 @@ public abstract class SharedHumanoidAppearanceSystem : EntitySystem humanoid.Species = species; humanoid.MarkingSet.EnsureSpecies(species, humanoid.SkinColor, _markingManager); var oldMarkings = humanoid.MarkingSet.GetForwardEnumerator().ToList(); - humanoid.MarkingSet = new(oldMarkings, prototype.MarkingPoints, _markingManager, _prototypeManager); + humanoid.MarkingSet = new(oldMarkings, prototype.MarkingPoints, _markingManager, _proto); if (sync) Dirty(uid, humanoid); @@ -164,7 +177,7 @@ public abstract class SharedHumanoidAppearanceSystem : EntitySystem if (!Resolve(uid, ref humanoid)) return; - if (!_prototypeManager.TryIndex(humanoid.Species, out var species)) + if (!_proto.TryIndex(humanoid.Species, out var species)) { return; } @@ -288,24 +301,24 @@ public abstract class SharedHumanoidAppearanceSystem : EntitySystem // Hair/facial hair - this may eventually be deprecated. // We need to ensure hair before applying it or coloring can try depend on markings that can be invalid - var hairColor = _markingManager.MustMatchSkin(profile.Species, HumanoidVisualLayers.Hair, out var hairAlpha, _prototypeManager) + var hairColor = _markingManager.MustMatchSkin(profile.Species, HumanoidVisualLayers.Hair, out var hairAlpha, _proto) ? profile.Appearance.SkinColor.WithAlpha(hairAlpha) : profile.Appearance.HairColor; - var facialHairColor = _markingManager.MustMatchSkin(profile.Species, HumanoidVisualLayers.FacialHair, out var facialHairAlpha, _prototypeManager) + var facialHairColor = _markingManager.MustMatchSkin(profile.Species, HumanoidVisualLayers.FacialHair, out var facialHairAlpha, _proto) ? profile.Appearance.SkinColor.WithAlpha(facialHairAlpha) : profile.Appearance.FacialHairColor; if (_markingManager.Markings.TryGetValue(profile.Appearance.HairStyleId, out var hairPrototype) && - _markingManager.CanBeApplied(profile.Species, profile.Sex, hairPrototype, _prototypeManager)) + _markingManager.CanBeApplied(profile.Species, profile.Sex, hairPrototype, _proto)) { AddMarking(uid, profile.Appearance.HairStyleId, hairColor, false); } if (_markingManager.Markings.TryGetValue(profile.Appearance.FacialHairStyleId, out var facialHairPrototype) && - _markingManager.CanBeApplied(profile.Species, profile.Sex, facialHairPrototype, _prototypeManager)) + _markingManager.CanBeApplied(profile.Species, profile.Sex, facialHairPrototype, _proto)) { AddMarking(uid, profile.Appearance.FacialHairStyleId, facialHairColor, false); } - humanoid.MarkingSet.EnsureSpecies(profile.Species, profile.Appearance.SkinColor, _markingManager, _prototypeManager); + humanoid.MarkingSet.EnsureSpecies(profile.Species, profile.Appearance.SkinColor, _markingManager, _proto); // Finally adding marking with forced colors foreach (var (marking, prototype) in markingFColored) @@ -398,4 +411,39 @@ public abstract class SharedHumanoidAppearanceSystem : EntitySystem if (sync) Dirty(uid, humanoid); } + + /// + /// Takes ID of the species prototype, returns UI-friendly name of the species. + /// + public string GetSpeciesRepresentation(string speciesId) + { + if (_proto.TryIndex(speciesId, out var species)) + { + return Loc.GetString(species.Name); + } + + Log.Error("Tried to get representation of unknown species: {speciesId}"); + return Loc.GetString("humanoid-appearance-component-unknown-species"); + } + + public string GetAgeRepresentation(string species, int age) + { + if (!_proto.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"); + } }