SharedHumanoidAppearanceSystem.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555
  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. private void OnExamined(EntityUid uid, HumanoidAppearanceComponent component, ExaminedEvent args)
  113. {
  114. var identity = Identity.Entity(uid, EntityManager);
  115. var species = GetSpeciesRepresentation(component.Species).ToLower();
  116. var age = GetAgeRepresentation(component.Species, component.Age);
  117. // WWDP EDIT
  118. string locale = "humanoid-appearance-component-examine";
  119. if (args.Examiner == args.Examined) // Use the selfaware locale when examining yourself
  120. locale += "-selfaware";
  121. args.PushText(Loc.GetString(locale, ("user", identity), ("age", age), ("species", species)), 100); // priority for examine
  122. // WWDP EDIT END
  123. }
  124. /// <summary>
  125. /// Toggles a humanoid's sprite layer visibility.
  126. /// </summary>
  127. /// <param name="uid">Humanoid mob's UID</param>
  128. /// <param name="layer">Layer to toggle visibility for</param>
  129. /// <param name="humanoid">Humanoid component of the entity</param>
  130. public void SetLayerVisibility(EntityUid uid,
  131. HumanoidVisualLayers layer,
  132. bool visible,
  133. bool permanent = false,
  134. HumanoidAppearanceComponent? humanoid = null)
  135. {
  136. if (!Resolve(uid, ref humanoid, false))
  137. return;
  138. var dirty = false;
  139. SetLayerVisibility(uid, humanoid, layer, visible, permanent, ref dirty);
  140. if (dirty)
  141. Dirty(uid, humanoid);
  142. }
  143. /// <summary>
  144. /// Clones a humanoid's appearance to a target mob, provided they both have humanoid components.
  145. /// </summary>
  146. /// <param name="source">Source entity to fetch the original appearance from.</param>
  147. /// <param name="target">Target entity to apply the source entity's appearance to.</param>
  148. /// <param name="sourceHumanoid">Source entity's humanoid component.</param>
  149. /// <param name="targetHumanoid">Target entity's humanoid component.</param>
  150. public void CloneAppearance(EntityUid source, EntityUid target, HumanoidAppearanceComponent? sourceHumanoid = null,
  151. HumanoidAppearanceComponent? targetHumanoid = null)
  152. {
  153. if (!Resolve(source, ref sourceHumanoid) || !Resolve(target, ref targetHumanoid))
  154. return;
  155. targetHumanoid.Species = sourceHumanoid.Species;
  156. targetHumanoid.SkinColor = sourceHumanoid.SkinColor;
  157. targetHumanoid.EyeColor = sourceHumanoid.EyeColor;
  158. targetHumanoid.Age = sourceHumanoid.Age;
  159. SetSex(target, sourceHumanoid.Sex, false, targetHumanoid);
  160. targetHumanoid.CustomBaseLayers = new(sourceHumanoid.CustomBaseLayers);
  161. targetHumanoid.MarkingSet = new(sourceHumanoid.MarkingSet);
  162. targetHumanoid.Gender = sourceHumanoid.Gender;
  163. if (TryComp<GrammarComponent>(target, out var grammar))
  164. grammar.Gender = sourceHumanoid.Gender;
  165. Dirty(target, targetHumanoid);
  166. }
  167. /// <summary>
  168. /// Sets the visibility for multiple layers at once on a humanoid's sprite.
  169. /// </summary>
  170. /// <param name="uid">Humanoid mob's UID</param>
  171. /// <param name="layers">An enumerable of all sprite layers that are going to have their visibility set</param>
  172. /// <param name="visible">The visibility state of the layers given</param>
  173. /// <param name="permanent">If this is a permanent change, or temporary. Permanent layers are stored in their own hash set.</param>
  174. /// <param name="humanoid">Humanoid component of the entity</param>
  175. public void SetLayersVisibility(EntityUid uid, IEnumerable<HumanoidVisualLayers> layers, bool visible, bool permanent = false,
  176. HumanoidAppearanceComponent? humanoid = null)
  177. {
  178. if (!Resolve(uid, ref humanoid))
  179. return;
  180. var dirty = false;
  181. foreach (var layer in layers)
  182. {
  183. SetLayerVisibility(uid, humanoid, layer, visible, permanent, ref dirty);
  184. }
  185. if (dirty)
  186. Dirty(uid, humanoid);
  187. }
  188. protected virtual void SetLayerVisibility(
  189. EntityUid uid,
  190. HumanoidAppearanceComponent humanoid,
  191. HumanoidVisualLayers layer,
  192. bool visible,
  193. bool permanent,
  194. ref bool dirty)
  195. {
  196. if (visible)
  197. {
  198. if (permanent)
  199. dirty |= humanoid.PermanentlyHidden.Remove(layer);
  200. dirty |= humanoid.HiddenLayers.Remove(layer);
  201. }
  202. else
  203. {
  204. if (permanent)
  205. dirty |= humanoid.PermanentlyHidden.Add(layer);
  206. dirty |= humanoid.HiddenLayers.Add(layer);
  207. }
  208. }
  209. /// <summary>
  210. /// Set a humanoid mob's species. This will change their base sprites, as well as their current
  211. /// set of markings to fit against the mob's new species.
  212. /// </summary>
  213. /// <param name="uid">The humanoid mob's UID.</param>
  214. /// <param name="species">The species to set the mob to. Will return if the species prototype was invalid.</param>
  215. /// <param name="sync">Whether to immediately synchronize this to the humanoid mob, or not.</param>
  216. /// <param name="humanoid">Humanoid component of the entity</param>
  217. public void SetSpecies(EntityUid uid, string species, bool sync = true, HumanoidAppearanceComponent? humanoid = null)
  218. {
  219. if (!Resolve(uid, ref humanoid) || !_proto.TryIndex<SpeciesPrototype>(species, out var prototype))
  220. {
  221. return;
  222. }
  223. humanoid.Species = species;
  224. humanoid.MarkingSet.EnsureSpecies(species, humanoid.SkinColor, _markingManager);
  225. var oldMarkings = humanoid.MarkingSet.GetForwardEnumerator().ToList();
  226. humanoid.MarkingSet = new(oldMarkings, prototype.MarkingPoints, _markingManager, _proto);
  227. if (sync)
  228. Dirty(uid, humanoid);
  229. }
  230. /// <summary>
  231. /// Sets the skin color of this humanoid mob. Will only affect base layers that are not custom,
  232. /// custom base layers should use <see cref="SetBaseLayerColor"/> instead.
  233. /// </summary>
  234. /// <param name="uid">The humanoid mob's UID.</param>
  235. /// <param name="skinColor">Skin color to set on the humanoid mob.</param>
  236. /// <param name="sync">Whether to synchronize this to the humanoid mob, or not.</param>
  237. /// <param name="verify">Whether to verify the skin color can be set on this humanoid or not</param>
  238. /// <param name="humanoid">Humanoid component of the entity</param>
  239. public virtual void SetSkinColor(EntityUid uid, Color skinColor, bool sync = true, bool verify = true, HumanoidAppearanceComponent? humanoid = null)
  240. {
  241. if (!Resolve(uid, ref humanoid))
  242. return;
  243. if (!_proto.TryIndex<SpeciesPrototype>(humanoid.Species, out var species))
  244. {
  245. return;
  246. }
  247. if (verify && !SkinColor.VerifySkinColor(species.SkinColoration, skinColor))
  248. {
  249. skinColor = SkinColor.ValidSkinTone(species.SkinColoration, skinColor);
  250. }
  251. humanoid.SkinColor = skinColor;
  252. if (sync)
  253. Dirty(uid, humanoid);
  254. }
  255. /// <summary>
  256. /// Sets the base layer ID of this humanoid mob. A humanoid mob's 'base layer' is
  257. /// the skin sprite that is applied to the mob's sprite upon appearance refresh.
  258. /// </summary>
  259. /// <param name="uid">The humanoid mob's UID.</param>
  260. /// <param name="layer">The layer to target on this humanoid mob.</param>
  261. /// <param name="id">The ID of the sprite to use. See <see cref="HumanoidSpeciesSpriteLayer"/>.</param>
  262. /// <param name="sync">Whether to synchronize this to the humanoid mob, or not.</param>
  263. /// <param name="humanoid">Humanoid component of the entity</param>
  264. public void SetBaseLayerId(EntityUid uid, HumanoidVisualLayers layer, string? id, bool sync = true,
  265. HumanoidAppearanceComponent? humanoid = null)
  266. {
  267. if (!Resolve(uid, ref humanoid))
  268. return;
  269. if (humanoid.CustomBaseLayers.TryGetValue(layer, out var info))
  270. humanoid.CustomBaseLayers[layer] = info with { Id = id };
  271. else
  272. humanoid.CustomBaseLayers[layer] = new(id);
  273. if (sync)
  274. Dirty(uid, humanoid);
  275. }
  276. /// <summary>
  277. /// Sets the color of this humanoid mob's base layer. See <see cref="SetBaseLayerId"/> for a
  278. /// description of how base layers work.
  279. /// </summary>
  280. /// <param name="uid">The humanoid mob's UID.</param>
  281. /// <param name="layer">The layer to target on this humanoid mob.</param>
  282. /// <param name="color">The color to set this base layer to.</param>
  283. public void SetBaseLayerColor(EntityUid uid, HumanoidVisualLayers layer, Color? color, bool sync = true, HumanoidAppearanceComponent? humanoid = null)
  284. {
  285. if (!Resolve(uid, ref humanoid))
  286. return;
  287. if (humanoid.CustomBaseLayers.TryGetValue(layer, out var info))
  288. humanoid.CustomBaseLayers[layer] = info with { Color = color };
  289. else
  290. humanoid.CustomBaseLayers[layer] = new(null, color);
  291. if (sync)
  292. Dirty(uid, humanoid);
  293. }
  294. /// <summary>
  295. /// Set a humanoid mob's sex. This will not change their gender.
  296. /// </summary>
  297. /// <param name="uid">The humanoid mob's UID.</param>
  298. /// <param name="sex">The sex to set the mob to.</param>
  299. /// <param name="sync">Whether to immediately synchronize this to the humanoid mob, or not.</param>
  300. /// <param name="humanoid">Humanoid component of the entity</param>
  301. public void SetSex(EntityUid uid, Sex sex, bool sync = true, HumanoidAppearanceComponent? humanoid = null)
  302. {
  303. if (!Resolve(uid, ref humanoid) || humanoid.Sex == sex)
  304. return;
  305. var oldSex = humanoid.Sex;
  306. humanoid.Sex = sex;
  307. humanoid.MarkingSet.EnsureSexes(sex, _markingManager);
  308. RaiseLocalEvent(uid, new SexChangedEvent(oldSex, sex));
  309. if (sync)
  310. {
  311. Dirty(uid, humanoid);
  312. }
  313. }
  314. /// <summary>
  315. /// Loads a humanoid character profile directly onto this humanoid mob.
  316. /// </summary>
  317. /// <param name="uid">The mob's entity UID.</param>
  318. /// <param name="profile">The character profile to load.</param>
  319. /// <param name="humanoid">Humanoid component of the entity</param>
  320. public virtual void LoadProfile(EntityUid uid, HumanoidCharacterProfile? profile, HumanoidAppearanceComponent? humanoid = null)
  321. {
  322. if (profile == null)
  323. return;
  324. if (!Resolve(uid, ref humanoid))
  325. {
  326. return;
  327. }
  328. SetSpecies(uid, profile.Species, false, humanoid);
  329. SetSex(uid, profile.Sex, false, humanoid);
  330. humanoid.EyeColor = profile.Appearance.EyeColor;
  331. SetSkinColor(uid, profile.Appearance.SkinColor, false);
  332. humanoid.MarkingSet.Clear();
  333. // Add markings that doesn't need coloring. We store them until we add all other markings that doesn't need it.
  334. var markingFColored = new Dictionary<Marking, MarkingPrototype>();
  335. foreach (var marking in profile.Appearance.Markings)
  336. {
  337. if (_markingManager.TryGetMarking(marking, out var prototype))
  338. {
  339. if (!prototype.ForcedColoring)
  340. {
  341. AddMarking(uid, marking.MarkingId, marking.MarkingColors, false);
  342. }
  343. else
  344. {
  345. markingFColored.Add(marking, prototype);
  346. }
  347. }
  348. }
  349. // Hair/facial hair - this may eventually be deprecated.
  350. // We need to ensure hair before applying it or coloring can try depend on markings that can be invalid
  351. var hairColor = _markingManager.MustMatchSkin(profile.Species, HumanoidVisualLayers.Hair, out var hairAlpha, _proto)
  352. ? profile.Appearance.SkinColor.WithAlpha(hairAlpha) : profile.Appearance.HairColor;
  353. var facialHairColor = _markingManager.MustMatchSkin(profile.Species, HumanoidVisualLayers.FacialHair, out var facialHairAlpha, _proto)
  354. ? profile.Appearance.SkinColor.WithAlpha(facialHairAlpha) : profile.Appearance.FacialHairColor;
  355. if (_markingManager.Markings.TryGetValue(profile.Appearance.HairStyleId, out var hairPrototype) &&
  356. _markingManager.CanBeApplied(profile.Species, profile.Sex, hairPrototype, _proto))
  357. {
  358. AddMarking(uid, profile.Appearance.HairStyleId, hairColor, false);
  359. }
  360. if (_markingManager.Markings.TryGetValue(profile.Appearance.FacialHairStyleId, out var facialHairPrototype) &&
  361. _markingManager.CanBeApplied(profile.Species, profile.Sex, facialHairPrototype, _proto))
  362. {
  363. AddMarking(uid, profile.Appearance.FacialHairStyleId, facialHairColor, false);
  364. }
  365. humanoid.MarkingSet.EnsureSpecies(profile.Species, profile.Appearance.SkinColor, _markingManager, _proto);
  366. // Finally adding marking with forced colors
  367. foreach (var (marking, prototype) in markingFColored)
  368. {
  369. var markingColors = MarkingColoring.GetMarkingLayerColors(
  370. prototype,
  371. profile.Appearance.SkinColor,
  372. profile.Appearance.EyeColor,
  373. humanoid.MarkingSet
  374. );
  375. AddMarking(uid, marking.MarkingId, markingColors, false);
  376. }
  377. EnsureDefaultMarkings(uid, humanoid);
  378. humanoid.Gender = profile.Gender;
  379. if (TryComp<GrammarComponent>(uid, out var grammar))
  380. {
  381. grammar.Gender = profile.Gender;
  382. }
  383. humanoid.Age = profile.Age;
  384. RaiseLocalEvent(uid, new ProfileLoadFinishedEvent()); // Shitmed Change
  385. Dirty(uid, humanoid);
  386. }
  387. /// <summary>
  388. /// Adds a marking to this humanoid.
  389. /// </summary>
  390. /// <param name="uid">Humanoid mob's UID</param>
  391. /// <param name="marking">Marking ID to use</param>
  392. /// <param name="color">Color to apply to all marking layers of this marking</param>
  393. /// <param name="sync">Whether to immediately sync this marking or not</param>
  394. /// <param name="forced">If this marking was forced (ignores marking points)</param>
  395. /// <param name="humanoid">Humanoid component of the entity</param>
  396. public void AddMarking(EntityUid uid, string marking, Color? color = null, bool sync = true, bool forced = false, HumanoidAppearanceComponent? humanoid = null)
  397. {
  398. if (!Resolve(uid, ref humanoid)
  399. || !_markingManager.Markings.TryGetValue(marking, out var prototype))
  400. {
  401. return;
  402. }
  403. var markingObject = prototype.AsMarking();
  404. markingObject.Forced = forced;
  405. if (color != null)
  406. {
  407. for (var i = 0; i < prototype.Sprites.Count; i++)
  408. {
  409. markingObject.SetColor(i, color.Value);
  410. }
  411. }
  412. humanoid.MarkingSet.AddBack(prototype.MarkingCategory, markingObject);
  413. if (sync)
  414. Dirty(uid, humanoid);
  415. }
  416. private void EnsureDefaultMarkings(EntityUid uid, HumanoidAppearanceComponent? humanoid)
  417. {
  418. if (!Resolve(uid, ref humanoid))
  419. {
  420. return;
  421. }
  422. humanoid.MarkingSet.EnsureDefault(humanoid.SkinColor, humanoid.EyeColor, _markingManager);
  423. }
  424. /// <summary>
  425. ///
  426. /// </summary>
  427. /// <param name="uid">Humanoid mob's UID</param>
  428. /// <param name="marking">Marking ID to use</param>
  429. /// <param name="colors">Colors to apply against this marking's set of sprites.</param>
  430. /// <param name="sync">Whether to immediately sync this marking or not</param>
  431. /// <param name="forced">If this marking was forced (ignores marking points)</param>
  432. /// <param name="humanoid">Humanoid component of the entity</param>
  433. public void AddMarking(EntityUid uid, string marking, IReadOnlyList<Color> colors, bool sync = true, bool forced = false, HumanoidAppearanceComponent? humanoid = null)
  434. {
  435. if (!Resolve(uid, ref humanoid)
  436. || !_markingManager.Markings.TryGetValue(marking, out var prototype))
  437. {
  438. return;
  439. }
  440. var markingObject = new Marking(marking, colors);
  441. markingObject.Forced = forced;
  442. humanoid.MarkingSet.AddBack(prototype.MarkingCategory, markingObject);
  443. if (sync)
  444. Dirty(uid, humanoid);
  445. }
  446. /// <summary>
  447. /// Takes ID of the species prototype, returns UI-friendly name of the species.
  448. /// </summary>
  449. public string GetSpeciesRepresentation(string speciesId)
  450. {
  451. if (_proto.TryIndex<SpeciesPrototype>(speciesId, out var species))
  452. {
  453. return Loc.GetString(species.Name);
  454. }
  455. Log.Error("Tried to get representation of unknown species: {speciesId}");
  456. return Loc.GetString("humanoid-appearance-component-unknown-species");
  457. }
  458. public string GetAgeRepresentation(string species, int age)
  459. {
  460. if (!_proto.TryIndex<SpeciesPrototype>(species, out var speciesPrototype))
  461. {
  462. Log.Error("Tried to get age representation of species that couldn't be indexed: " + species);
  463. return Loc.GetString("identity-age-young");
  464. }
  465. if (age < speciesPrototype.YoungAge)
  466. {
  467. return Loc.GetString("identity-age-young");
  468. }
  469. if (age < speciesPrototype.OldAge)
  470. {
  471. return Loc.GetString("identity-age-middle-aged");
  472. }
  473. return Loc.GetString("identity-age-old");
  474. }
  475. }