1
0

SharedHumanoidAppearanceSystem.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553
  1. // SPDX-FileCopyrightText: 2023 Alex Evgrashin <aevgrashin@yandex.ru>
  2. // SPDX-FileCopyrightText: 2023 DrSmugleaf <DrSmugleaf@users.noreply.github.com>
  3. // SPDX-FileCopyrightText: 2023 Flipp Syder <76629141+vulppine@users.noreply.github.com>
  4. // SPDX-FileCopyrightText: 2023 Leon Friedrich <60421075+ElectroJr@users.noreply.github.com>
  5. // SPDX-FileCopyrightText: 2023 Morb <14136326+Morb0@users.noreply.github.com>
  6. // SPDX-FileCopyrightText: 2023 Visne <39844191+Visne@users.noreply.github.com>
  7. // SPDX-FileCopyrightText: 2023 Vordenburg <114301317+Vordenburg@users.noreply.github.com>
  8. // SPDX-FileCopyrightText: 2023 csqrb <56765288+CaptainSqrBeard@users.noreply.github.com>
  9. // SPDX-FileCopyrightText: 2024 Nemanja <98561806+EmoGarbage404@users.noreply.github.com>
  10. // SPDX-FileCopyrightText: 2024 Piras314 <p1r4s@proton.me>
  11. // SPDX-FileCopyrightText: 2024 Tayrtahn <tayrtahn@gmail.com>
  12. // SPDX-FileCopyrightText: 2024 deltanedas <39013340+deltanedas@users.noreply.github.com>
  13. // SPDX-FileCopyrightText: 2024 deltanedas <@deltanedas:kde.org>
  14. // SPDX-FileCopyrightText: 2024 gluesniffler <159397573+gluesniffler@users.noreply.github.com>
  15. // SPDX-FileCopyrightText: 2024 ike709 <ike709@github.com>
  16. // SPDX-FileCopyrightText: 2024 ike709 <ike709@users.noreply.github.com>
  17. // SPDX-FileCopyrightText: 2024 metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
  18. // SPDX-FileCopyrightText: 2025 Aiden <28298836+Aidenkrz@users.noreply.github.com>
  19. // SPDX-FileCopyrightText: 2025 GoobBot <uristmchands@proton.me>
  20. // SPDX-FileCopyrightText: 2025 Zachary Higgs <compgeek223@gmail.com>
  21. // SPDX-FileCopyrightText: 2025 gluesniffler <linebarrelerenthusiast@gmail.com>
  22. // SPDX-FileCopyrightText: 2025 vanx <61917534+Vaaankas@users.noreply.github.com>
  23. //
  24. // SPDX-License-Identifier: AGPL-3.0-or-later
  25. using System.IO;
  26. using System.Linq;
  27. using Content.Shared.Examine;
  28. using Content.Shared.Humanoid.Markings;
  29. using Content.Shared._Shitmed.Humanoid.Events; // Shitmed Change
  30. using Content.Shared.Humanoid.Prototypes;
  31. using Content.Shared.IdentityManagement;
  32. using Content.Shared.Preferences;
  33. using Robust.Shared;
  34. using Robust.Shared.Configuration;
  35. using Robust.Shared.GameObjects.Components.Localization;
  36. using Robust.Shared.Network;
  37. using Robust.Shared.Player;
  38. using Robust.Shared.Prototypes;
  39. using Robust.Shared.Serialization.Manager;
  40. using Robust.Shared.Serialization.Markdown;
  41. using Robust.Shared.Utility;
  42. using YamlDotNet.RepresentationModel;
  43. namespace Content.Shared.Humanoid;
  44. /// <summary>
  45. /// HumanoidSystem. Primarily deals with the appearance and visual data
  46. /// of a humanoid entity. HumanoidVisualizer is what deals with actually
  47. /// organizing the sprites and setting up the sprite component's layers.
  48. ///
  49. /// This is a shared system, because while it is server authoritative,
  50. /// you still need a local copy so that players can set up their
  51. /// characters.
  52. /// </summary>
  53. public abstract class SharedHumanoidAppearanceSystem : EntitySystem
  54. {
  55. [Dependency] private readonly IConfigurationManager _cfgManager = default!;
  56. [Dependency] private readonly INetManager _netManager = default!;
  57. [Dependency] private readonly IPrototypeManager _proto = default!;
  58. [Dependency] private readonly ISerializationManager _serManager = default!;
  59. [Dependency] private readonly MarkingManager _markingManager = default!;
  60. [ValidatePrototypeId<SpeciesPrototype>]
  61. public const string DefaultSpecies = "Human";
  62. public override void Initialize()
  63. {
  64. base.Initialize();
  65. SubscribeLocalEvent<HumanoidAppearanceComponent, ComponentInit>(OnInit);
  66. SubscribeLocalEvent<HumanoidAppearanceComponent, ExaminedEvent>(OnExamined);
  67. }
  68. public DataNode ToDataNode(HumanoidCharacterProfile profile)
  69. {
  70. var export = new HumanoidProfileExport()
  71. {
  72. ForkId = _cfgManager.GetCVar(CVars.BuildForkId),
  73. Profile = profile,
  74. };
  75. var dataNode = _serManager.WriteValue(export, alwaysWrite: true, notNullableOverride: true);
  76. return dataNode;
  77. }
  78. public HumanoidCharacterProfile FromStream(Stream stream, ICommonSession session)
  79. {
  80. using var reader = new StreamReader(stream, EncodingHelpers.UTF8);
  81. var yamlStream = new YamlStream();
  82. yamlStream.Load(reader);
  83. var root = yamlStream.Documents[0].RootNode;
  84. var export = _serManager.Read<HumanoidProfileExport>(root.ToDataNode(), notNullableOverride: true);
  85. /*
  86. * Add custom handling here for forks / version numbers if you care.
  87. */
  88. var profile = export.Profile;
  89. var collection = IoCManager.Instance;
  90. profile.EnsureValid(session, collection!);
  91. return profile;
  92. }
  93. private void OnInit(EntityUid uid, HumanoidAppearanceComponent humanoid, ComponentInit args)
  94. {
  95. if (string.IsNullOrEmpty(humanoid.Species) || _netManager.IsClient && !IsClientSide(uid))
  96. {
  97. return;
  98. }
  99. if (string.IsNullOrEmpty(humanoid.Initial)
  100. || !_proto.TryIndex(humanoid.Initial, out HumanoidProfilePrototype? startingSet))
  101. {
  102. LoadProfile(uid, HumanoidCharacterProfile.DefaultWithSpecies(humanoid.Species), humanoid);
  103. return;
  104. }
  105. // Do this first, because profiles currently do not support custom base layers
  106. foreach (var (layer, info) in startingSet.CustomBaseLayers)
  107. {
  108. humanoid.CustomBaseLayers.Add(layer, info);
  109. }
  110. LoadProfile(uid, startingSet.Profile, humanoid);
  111. }
  112. /// <summary>
  113. /// Adds a description to the examination text for a humanoid entity, including its identity, species, and age category.
  114. /// </summary>
  115. private void OnExamined(EntityUid uid, HumanoidAppearanceComponent component, ExaminedEvent args)
  116. {
  117. var identity = Identity.Entity(uid, EntityManager);
  118. var species = GetSpeciesRepresentation(component.Species).ToLower();
  119. var age = GetAgeRepresentation(component.Species, component.Age);
  120. string locale = "humanoid-appearance-component-examine";
  121. args.PushText(Loc.GetString(locale, ("user", identity), ("age", age), ("species", species)), 100); // priority for examine
  122. }
  123. /// <summary>
  124. /// Toggles a humanoid's sprite layer visibility.
  125. /// </summary>
  126. /// <param name="uid">Humanoid mob's UID</param>
  127. /// <param name="layer">Layer to toggle visibility for</param>
  128. /// <param name="humanoid">Humanoid component of the entity</param>
  129. public void SetLayerVisibility(EntityUid uid,
  130. HumanoidVisualLayers layer,
  131. bool visible,
  132. bool permanent = false,
  133. HumanoidAppearanceComponent? humanoid = null)
  134. {
  135. if (!Resolve(uid, ref humanoid, false))
  136. return;
  137. var dirty = false;
  138. SetLayerVisibility(uid, humanoid, layer, visible, permanent, ref dirty);
  139. if (dirty)
  140. Dirty(uid, humanoid);
  141. }
  142. /// <summary>
  143. /// Clones a humanoid's appearance to a target mob, provided they both have humanoid components.
  144. /// </summary>
  145. /// <param name="source">Source entity to fetch the original appearance from.</param>
  146. /// <param name="target">Target entity to apply the source entity's appearance to.</param>
  147. /// <param name="sourceHumanoid">Source entity's humanoid component.</param>
  148. /// <param name="targetHumanoid">Target entity's humanoid component.</param>
  149. public void CloneAppearance(EntityUid source, EntityUid target, HumanoidAppearanceComponent? sourceHumanoid = null,
  150. HumanoidAppearanceComponent? targetHumanoid = null)
  151. {
  152. if (!Resolve(source, ref sourceHumanoid) || !Resolve(target, ref targetHumanoid))
  153. return;
  154. targetHumanoid.Species = sourceHumanoid.Species;
  155. targetHumanoid.SkinColor = sourceHumanoid.SkinColor;
  156. targetHumanoid.EyeColor = sourceHumanoid.EyeColor;
  157. targetHumanoid.Age = sourceHumanoid.Age;
  158. SetSex(target, sourceHumanoid.Sex, false, targetHumanoid);
  159. targetHumanoid.CustomBaseLayers = new(sourceHumanoid.CustomBaseLayers);
  160. targetHumanoid.MarkingSet = new(sourceHumanoid.MarkingSet);
  161. targetHumanoid.Gender = sourceHumanoid.Gender;
  162. if (TryComp<GrammarComponent>(target, out var grammar))
  163. grammar.Gender = sourceHumanoid.Gender;
  164. Dirty(target, targetHumanoid);
  165. }
  166. /// <summary>
  167. /// Sets the visibility for multiple layers at once on a humanoid's sprite.
  168. /// </summary>
  169. /// <param name="uid">Humanoid mob's UID</param>
  170. /// <param name="layers">An enumerable of all sprite layers that are going to have their visibility set</param>
  171. /// <param name="visible">The visibility state of the layers given</param>
  172. /// <param name="permanent">If this is a permanent change, or temporary. Permanent layers are stored in their own hash set.</param>
  173. /// <param name="humanoid">Humanoid component of the entity</param>
  174. public void SetLayersVisibility(EntityUid uid, IEnumerable<HumanoidVisualLayers> layers, bool visible, bool permanent = false,
  175. HumanoidAppearanceComponent? humanoid = null)
  176. {
  177. if (!Resolve(uid, ref humanoid))
  178. return;
  179. var dirty = false;
  180. foreach (var layer in layers)
  181. {
  182. SetLayerVisibility(uid, humanoid, layer, visible, permanent, ref dirty);
  183. }
  184. if (dirty)
  185. Dirty(uid, humanoid);
  186. }
  187. protected virtual void SetLayerVisibility(
  188. EntityUid uid,
  189. HumanoidAppearanceComponent humanoid,
  190. HumanoidVisualLayers layer,
  191. bool visible,
  192. bool permanent,
  193. ref bool dirty)
  194. {
  195. if (visible)
  196. {
  197. if (permanent)
  198. dirty |= humanoid.PermanentlyHidden.Remove(layer);
  199. dirty |= humanoid.HiddenLayers.Remove(layer);
  200. }
  201. else
  202. {
  203. if (permanent)
  204. dirty |= humanoid.PermanentlyHidden.Add(layer);
  205. dirty |= humanoid.HiddenLayers.Add(layer);
  206. }
  207. }
  208. /// <summary>
  209. /// Set a humanoid mob's species. This will change their base sprites, as well as their current
  210. /// set of markings to fit against the mob's new species.
  211. /// </summary>
  212. /// <param name="uid">The humanoid mob's UID.</param>
  213. /// <param name="species">The species to set the mob to. Will return if the species prototype was invalid.</param>
  214. /// <param name="sync">Whether to immediately synchronize this to the humanoid mob, or not.</param>
  215. /// <param name="humanoid">Humanoid component of the entity</param>
  216. public void SetSpecies(EntityUid uid, string species, bool sync = true, HumanoidAppearanceComponent? humanoid = null)
  217. {
  218. if (!Resolve(uid, ref humanoid) || !_proto.TryIndex<SpeciesPrototype>(species, out var prototype))
  219. {
  220. return;
  221. }
  222. humanoid.Species = species;
  223. humanoid.MarkingSet.EnsureSpecies(species, humanoid.SkinColor, _markingManager);
  224. var oldMarkings = humanoid.MarkingSet.GetForwardEnumerator().ToList();
  225. humanoid.MarkingSet = new(oldMarkings, prototype.MarkingPoints, _markingManager, _proto);
  226. if (sync)
  227. Dirty(uid, humanoid);
  228. }
  229. /// <summary>
  230. /// Sets the skin color of this humanoid mob. Will only affect base layers that are not custom,
  231. /// custom base layers should use <see cref="SetBaseLayerColor"/> instead.
  232. /// </summary>
  233. /// <param name="uid">The humanoid mob's UID.</param>
  234. /// <param name="skinColor">Skin color to set on the humanoid mob.</param>
  235. /// <param name="sync">Whether to synchronize this to the humanoid mob, or not.</param>
  236. /// <param name="verify">Whether to verify the skin color can be set on this humanoid or not</param>
  237. /// <param name="humanoid">Humanoid component of the entity</param>
  238. public virtual void SetSkinColor(EntityUid uid, Color skinColor, bool sync = true, bool verify = true, HumanoidAppearanceComponent? humanoid = null)
  239. {
  240. if (!Resolve(uid, ref humanoid))
  241. return;
  242. if (!_proto.TryIndex<SpeciesPrototype>(humanoid.Species, out var species))
  243. {
  244. return;
  245. }
  246. if (verify && !SkinColor.VerifySkinColor(species.SkinColoration, skinColor))
  247. {
  248. skinColor = SkinColor.ValidSkinTone(species.SkinColoration, skinColor);
  249. }
  250. humanoid.SkinColor = skinColor;
  251. if (sync)
  252. Dirty(uid, humanoid);
  253. }
  254. /// <summary>
  255. /// Sets the base layer ID of this humanoid mob. A humanoid mob's 'base layer' is
  256. /// the skin sprite that is applied to the mob's sprite upon appearance refresh.
  257. /// </summary>
  258. /// <param name="uid">The humanoid mob's UID.</param>
  259. /// <param name="layer">The layer to target on this humanoid mob.</param>
  260. /// <param name="id">The ID of the sprite to use. See <see cref="HumanoidSpeciesSpriteLayer"/>.</param>
  261. /// <param name="sync">Whether to synchronize this to the humanoid mob, or not.</param>
  262. /// <param name="humanoid">Humanoid component of the entity</param>
  263. public void SetBaseLayerId(EntityUid uid, HumanoidVisualLayers layer, string? id, bool sync = true,
  264. HumanoidAppearanceComponent? humanoid = null)
  265. {
  266. if (!Resolve(uid, ref humanoid))
  267. return;
  268. if (humanoid.CustomBaseLayers.TryGetValue(layer, out var info))
  269. humanoid.CustomBaseLayers[layer] = info with { Id = id };
  270. else
  271. humanoid.CustomBaseLayers[layer] = new(id);
  272. if (sync)
  273. Dirty(uid, humanoid);
  274. }
  275. /// <summary>
  276. /// Sets the color of this humanoid mob's base layer. See <see cref="SetBaseLayerId"/> for a
  277. /// description of how base layers work.
  278. /// </summary>
  279. /// <param name="uid">The humanoid mob's UID.</param>
  280. /// <param name="layer">The layer to target on this humanoid mob.</param>
  281. /// <param name="color">The color to set this base layer to.</param>
  282. public void SetBaseLayerColor(EntityUid uid, HumanoidVisualLayers layer, Color? color, bool sync = true, HumanoidAppearanceComponent? humanoid = null)
  283. {
  284. if (!Resolve(uid, ref humanoid))
  285. return;
  286. if (humanoid.CustomBaseLayers.TryGetValue(layer, out var info))
  287. humanoid.CustomBaseLayers[layer] = info with { Color = color };
  288. else
  289. humanoid.CustomBaseLayers[layer] = new(null, color);
  290. if (sync)
  291. Dirty(uid, humanoid);
  292. }
  293. /// <summary>
  294. /// Set a humanoid mob's sex. This will not change their gender.
  295. /// </summary>
  296. /// <param name="uid">The humanoid mob's UID.</param>
  297. /// <param name="sex">The sex to set the mob to.</param>
  298. /// <param name="sync">Whether to immediately synchronize this to the humanoid mob, or not.</param>
  299. /// <param name="humanoid">Humanoid component of the entity</param>
  300. public void SetSex(EntityUid uid, Sex sex, bool sync = true, HumanoidAppearanceComponent? humanoid = null)
  301. {
  302. if (!Resolve(uid, ref humanoid) || humanoid.Sex == sex)
  303. return;
  304. var oldSex = humanoid.Sex;
  305. humanoid.Sex = sex;
  306. humanoid.MarkingSet.EnsureSexes(sex, _markingManager);
  307. RaiseLocalEvent(uid, new SexChangedEvent(oldSex, sex));
  308. if (sync)
  309. {
  310. Dirty(uid, humanoid);
  311. }
  312. }
  313. /// <summary>
  314. /// Loads a humanoid character profile directly onto this humanoid mob.
  315. /// </summary>
  316. /// <param name="uid">The mob's entity UID.</param>
  317. /// <param name="profile">The character profile to load.</param>
  318. /// <param name="humanoid">Humanoid component of the entity</param>
  319. public virtual void LoadProfile(EntityUid uid, HumanoidCharacterProfile? profile, HumanoidAppearanceComponent? humanoid = null)
  320. {
  321. if (profile == null)
  322. return;
  323. if (!Resolve(uid, ref humanoid))
  324. {
  325. return;
  326. }
  327. SetSpecies(uid, profile.Species, false, humanoid);
  328. SetSex(uid, profile.Sex, false, humanoid);
  329. humanoid.EyeColor = profile.Appearance.EyeColor;
  330. SetSkinColor(uid, profile.Appearance.SkinColor, false);
  331. humanoid.MarkingSet.Clear();
  332. // Add markings that doesn't need coloring. We store them until we add all other markings that doesn't need it.
  333. var markingFColored = new Dictionary<Marking, MarkingPrototype>();
  334. foreach (var marking in profile.Appearance.Markings)
  335. {
  336. if (_markingManager.TryGetMarking(marking, out var prototype))
  337. {
  338. if (!prototype.ForcedColoring)
  339. {
  340. AddMarking(uid, marking.MarkingId, marking.MarkingColors, false);
  341. }
  342. else
  343. {
  344. markingFColored.Add(marking, prototype);
  345. }
  346. }
  347. }
  348. // Hair/facial hair - this may eventually be deprecated.
  349. // We need to ensure hair before applying it or coloring can try depend on markings that can be invalid
  350. var hairColor = _markingManager.MustMatchSkin(profile.Species, HumanoidVisualLayers.Hair, out var hairAlpha, _proto)
  351. ? profile.Appearance.SkinColor.WithAlpha(hairAlpha) : profile.Appearance.HairColor;
  352. var facialHairColor = _markingManager.MustMatchSkin(profile.Species, HumanoidVisualLayers.FacialHair, out var facialHairAlpha, _proto)
  353. ? profile.Appearance.SkinColor.WithAlpha(facialHairAlpha) : profile.Appearance.FacialHairColor;
  354. if (_markingManager.Markings.TryGetValue(profile.Appearance.HairStyleId, out var hairPrototype) &&
  355. _markingManager.CanBeApplied(profile.Species, profile.Sex, hairPrototype, _proto))
  356. {
  357. AddMarking(uid, profile.Appearance.HairStyleId, hairColor, false);
  358. }
  359. if (_markingManager.Markings.TryGetValue(profile.Appearance.FacialHairStyleId, out var facialHairPrototype) &&
  360. _markingManager.CanBeApplied(profile.Species, profile.Sex, facialHairPrototype, _proto))
  361. {
  362. AddMarking(uid, profile.Appearance.FacialHairStyleId, facialHairColor, false);
  363. }
  364. humanoid.MarkingSet.EnsureSpecies(profile.Species, profile.Appearance.SkinColor, _markingManager, _proto);
  365. // Finally adding marking with forced colors
  366. foreach (var (marking, prototype) in markingFColored)
  367. {
  368. var markingColors = MarkingColoring.GetMarkingLayerColors(
  369. prototype,
  370. profile.Appearance.SkinColor,
  371. profile.Appearance.EyeColor,
  372. humanoid.MarkingSet
  373. );
  374. AddMarking(uid, marking.MarkingId, markingColors, false);
  375. }
  376. EnsureDefaultMarkings(uid, humanoid);
  377. humanoid.Gender = profile.Gender;
  378. if (TryComp<GrammarComponent>(uid, out var grammar))
  379. {
  380. grammar.Gender = profile.Gender;
  381. }
  382. humanoid.Age = profile.Age;
  383. RaiseLocalEvent(uid, new ProfileLoadFinishedEvent()); // Shitmed Change
  384. Dirty(uid, humanoid);
  385. }
  386. /// <summary>
  387. /// Adds a marking to this humanoid.
  388. /// </summary>
  389. /// <param name="uid">Humanoid mob's UID</param>
  390. /// <param name="marking">Marking ID to use</param>
  391. /// <param name="color">Color to apply to all marking layers of this marking</param>
  392. /// <param name="sync">Whether to immediately sync this marking or not</param>
  393. /// <param name="forced">If this marking was forced (ignores marking points)</param>
  394. /// <param name="humanoid">Humanoid component of the entity</param>
  395. public void AddMarking(EntityUid uid, string marking, Color? color = null, bool sync = true, bool forced = false, HumanoidAppearanceComponent? humanoid = null)
  396. {
  397. if (!Resolve(uid, ref humanoid)
  398. || !_markingManager.Markings.TryGetValue(marking, out var prototype))
  399. {
  400. return;
  401. }
  402. var markingObject = prototype.AsMarking();
  403. markingObject.Forced = forced;
  404. if (color != null)
  405. {
  406. for (var i = 0; i < prototype.Sprites.Count; i++)
  407. {
  408. markingObject.SetColor(i, color.Value);
  409. }
  410. }
  411. humanoid.MarkingSet.AddBack(prototype.MarkingCategory, markingObject);
  412. if (sync)
  413. Dirty(uid, humanoid);
  414. }
  415. private void EnsureDefaultMarkings(EntityUid uid, HumanoidAppearanceComponent? humanoid)
  416. {
  417. if (!Resolve(uid, ref humanoid))
  418. {
  419. return;
  420. }
  421. humanoid.MarkingSet.EnsureDefault(humanoid.SkinColor, humanoid.EyeColor, _markingManager);
  422. }
  423. /// <summary>
  424. ///
  425. /// </summary>
  426. /// <param name="uid">Humanoid mob's UID</param>
  427. /// <param name="marking">Marking ID to use</param>
  428. /// <param name="colors">Colors to apply against this marking's set of sprites.</param>
  429. /// <param name="sync">Whether to immediately sync this marking or not</param>
  430. /// <param name="forced">If this marking was forced (ignores marking points)</param>
  431. /// <param name="humanoid">Humanoid component of the entity</param>
  432. public void AddMarking(EntityUid uid, string marking, IReadOnlyList<Color> colors, bool sync = true, bool forced = false, HumanoidAppearanceComponent? humanoid = null)
  433. {
  434. if (!Resolve(uid, ref humanoid)
  435. || !_markingManager.Markings.TryGetValue(marking, out var prototype))
  436. {
  437. return;
  438. }
  439. var markingObject = new Marking(marking, colors);
  440. markingObject.Forced = forced;
  441. humanoid.MarkingSet.AddBack(prototype.MarkingCategory, markingObject);
  442. if (sync)
  443. Dirty(uid, humanoid);
  444. }
  445. /// <summary>
  446. /// Takes ID of the species prototype, returns UI-friendly name of the species.
  447. /// </summary>
  448. public string GetSpeciesRepresentation(string speciesId)
  449. {
  450. if (_proto.TryIndex<SpeciesPrototype>(speciesId, out var species))
  451. {
  452. return Loc.GetString(species.Name);
  453. }
  454. Log.Error("Tried to get representation of unknown species: {speciesId}");
  455. return Loc.GetString("humanoid-appearance-component-unknown-species");
  456. }
  457. public string GetAgeRepresentation(string species, int age)
  458. {
  459. if (!_proto.TryIndex<SpeciesPrototype>(species, out var speciesPrototype))
  460. {
  461. Log.Error("Tried to get age representation of species that couldn't be indexed: " + species);
  462. return Loc.GetString("identity-age-young");
  463. }
  464. if (age < speciesPrototype.YoungAge)
  465. {
  466. return Loc.GetString("identity-age-young");
  467. }
  468. if (age < speciesPrototype.OldAge)
  469. {
  470. return Loc.GetString("identity-age-middle-aged");
  471. }
  472. return Loc.GetString("identity-age-old");
  473. }
  474. }