mirror of
https://github.com/WWhiteDreamProject/wwdpublic.git
synced 2026-04-23 00:27:50 +03:00
## Mirror of PR #25941: [Obsolete `Logger` cleanup for `EntitySystem`s](https://github.com/space-wizards/space-station-14/pull/25941) from <img src="https://avatars.githubusercontent.com/u/10567778?v=4" alt="space-wizards" width="22"/> [space-wizards](https://github.com/space-wizards)/[space-station-14](https://github.com/space-wizards/space-station-14) ###### `aafe81512258b5a80776ada1f471b58e7507ca2d` PR opened by <img src="https://avatars.githubusercontent.com/u/27449516?v=4" width="16"/><a href="https://github.com/LordCarve"> LordCarve</a> at 2024-03-09 12:19:14 UTC PR merged by <img src="https://avatars.githubusercontent.com/u/19864447?v=4" width="16"/><a href="https://github.com/web-flow"> web-flow</a> at 2024-03-10 00:15:13 UTC --- PR changed 25 files with 41 additions and 45 deletions. The PR had the following labels: - Status: Needs Review --- <details open="true"><summary><h1>Original Body</h1></summary> > <!-- Please read these guidelines before opening your PR: https://docs.spacestation14.io/en/getting-started/pr-guideline --> > <!-- The text between the arrows are comments - they will not be visible on your PR. --> > > ## About the PR > <!-- What did you change in this PR? --> > Changed almost all[^1] obsolete `Logger` calls in Content's `EntitySystem`s to use `Log` instead. `Log` automatically selects the system-specific `Sawmill`, so this isn't just a refactor - it makes logs slightly more accurate (puts them in appropriate sawmill/context rather than the root sawmill). > > ## Why / Balance > <!-- Why was it changed? Link any discussions or issues here. Please discuss how this would affect game balance. --> > Using `Logger` directly for logging is marked obsolete. Assumed this is a desired change. > > ## Technical details > <!-- If this is a code change, summarize at high level how your new code works. This makes it easier to review. --> > This changes some log contexts, but generally in a desirable way: > - For most, it put logs in `system.appropriate` `Sawmill` rather than root. > - For some that were forced into another `Sawmill` it changes it to a more specific one, i.e. from `atmos` it becomes `system.gas_filter` or `system.automatic_atmos` and `system.station` into `system.station_jobs`. > - For the rest it remains unchanged > > **I assumed that all of the above was desirable because this seems to be the standard convention** - I imagine that was the idea behind the `Log` in all `EntitySystem`s coupled with `[Obsolete] Logger` methods - **but if my assumptions are incorrect and/or there are exceptions, please let me know and I will adjust.** > > [^1]: There is only one `EntitySystem` that I didn't update - `ExamineSystemShared`. That is because the `Logger` is in a `static` method and refactoring that away causes a lot of cascading changes. May do it as a separate PR to avoid overly diluting this one. > > ## Media > <!-- > PRs which make ingame changes (adding clothing, items, new features, etc) are required to have media attached that showcase the changes. > Small fixes/refactors are exempt. > Any media may be used in SS14 progress reports, with clear credit given. > > If you're unsure whether your PR will require media, ask a maintainer. > > Check the box below to confirm that you have in fact seen this (put an X in the brackets, like [X]): > --> > > - [X] I have added screenshots/videos to this PR showcasing its changes ingame, **or** this PR does not require an ingame showcase > > ## Breaking changes > <!-- > List any breaking changes, including namespace, public class/method/field changes, prototype renames; and provide instructions for fixing them. This will be pasted in #codebase-changes. > --> > Log output changes. `EntitySystem` logs now go to the expected `Sawmill` for the system rather than hardcoded/root one. > Any log analyzers anticipating these logs' context must be updated. </details> Co-authored-by: LordCarve <27449516+LordCarve@users.noreply.github.com>
208 lines
8.1 KiB
C#
208 lines
8.1 KiB
C#
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<HumanoidAppearanceComponent, HumanoidMarkingModifierMarkingSetMessage>(OnMarkingsSet);
|
|
SubscribeLocalEvent<HumanoidAppearanceComponent, HumanoidMarkingModifierBaseLayersSetMessage>(OnBaseLayersSet);
|
|
SubscribeLocalEvent<HumanoidAppearanceComponent, GetVerbsEvent<Verb>>(OnVerbsRequest);
|
|
SubscribeLocalEvent<HumanoidAppearanceComponent, ExaminedEvent>(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
|
|
|
|
/// <summary>
|
|
/// Clones a humanoid's appearance to a target mob, provided they both have humanoid components.
|
|
/// </summary>
|
|
/// <param name="source">Source entity to fetch the original appearance from.</param>
|
|
/// <param name="target">Target entity to apply the source entity's appearance to.</param>
|
|
/// <param name="sourceHumanoid">Source entity's humanoid component.</param>
|
|
/// <param name="targetHumanoid">Target entity's humanoid component.</param>
|
|
public void CloneAppearance(EntityUid source, EntityUid target, HumanoidAppearanceComponent? sourceHumanoid = null,
|
|
HumanoidAppearanceComponent? targetHumanoid = null)
|
|
{
|
|
if (!Resolve(source, ref sourceHumanoid) || !Resolve(target, ref targetHumanoid))
|
|
{
|
|
return;
|
|
}
|
|
|
|
targetHumanoid.Species = sourceHumanoid.Species;
|
|
targetHumanoid.SkinColor = sourceHumanoid.SkinColor;
|
|
targetHumanoid.EyeColor = sourceHumanoid.EyeColor;
|
|
targetHumanoid.Age = sourceHumanoid.Age;
|
|
SetSex(target, sourceHumanoid.Sex, false, targetHumanoid);
|
|
targetHumanoid.CustomBaseLayers = new(sourceHumanoid.CustomBaseLayers);
|
|
targetHumanoid.MarkingSet = new(sourceHumanoid.MarkingSet);
|
|
|
|
targetHumanoid.Gender = sourceHumanoid.Gender;
|
|
if (TryComp<GrammarComponent>(target, out var grammar))
|
|
{
|
|
grammar.Gender = sourceHumanoid.Gender;
|
|
}
|
|
|
|
targetHumanoid.LastProfileLoaded = sourceHumanoid.LastProfileLoaded; // DeltaV - let paradox anomaly be cloned
|
|
|
|
Dirty(targetHumanoid);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Removes a marking from a humanoid by ID.
|
|
/// </summary>
|
|
/// <param name="uid">Humanoid mob's UID</param>
|
|
/// <param name="marking">The marking to try and remove.</param>
|
|
/// <param name="sync">Whether to immediately sync this to the humanoid</param>
|
|
/// <param name="humanoid">Humanoid component of the entity</param>
|
|
public void RemoveMarking(EntityUid uid, string marking, bool sync = true, HumanoidAppearanceComponent? humanoid = null)
|
|
{
|
|
if (!Resolve(uid, ref humanoid)
|
|
|| !_markingManager.Markings.TryGetValue(marking, out var prototype))
|
|
{
|
|
return;
|
|
}
|
|
|
|
humanoid.MarkingSet.Remove(prototype.MarkingCategory, marking);
|
|
|
|
if (sync)
|
|
Dirty(humanoid);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Removes a marking from a humanoid by category and index.
|
|
/// </summary>
|
|
/// <param name="uid">Humanoid mob's UID</param>
|
|
/// <param name="category">Category of the marking</param>
|
|
/// <param name="index">Index of the marking</param>
|
|
/// <param name="humanoid">Humanoid component of the entity</param>
|
|
public void RemoveMarking(EntityUid uid, MarkingCategories category, int index, HumanoidAppearanceComponent? humanoid = null)
|
|
{
|
|
if (index < 0
|
|
|| !Resolve(uid, ref humanoid)
|
|
|| !humanoid.MarkingSet.TryGetCategory(category, out var markings)
|
|
|| index >= markings.Count)
|
|
{
|
|
return;
|
|
}
|
|
|
|
humanoid.MarkingSet.Remove(category, index);
|
|
Dirty(humanoid);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Sets the marking ID of the humanoid in a category at an index in the category's list.
|
|
/// </summary>
|
|
/// <param name="uid">Humanoid mob's UID</param>
|
|
/// <param name="category">Category of the marking</param>
|
|
/// <param name="index">Index of the marking</param>
|
|
/// <param name="markingId">The marking ID to use</param>
|
|
/// <param name="humanoid">Humanoid component of the entity</param>
|
|
public void SetMarkingId(EntityUid uid, MarkingCategories category, int index, string markingId, HumanoidAppearanceComponent? humanoid = null)
|
|
{
|
|
if (index < 0
|
|
|| !_markingManager.MarkingsByCategory(category).TryGetValue(markingId, out var markingPrototype)
|
|
|| !Resolve(uid, ref humanoid)
|
|
|| !humanoid.MarkingSet.TryGetCategory(category, out var markings)
|
|
|| index >= markings.Count)
|
|
{
|
|
return;
|
|
}
|
|
|
|
var marking = markingPrototype.AsMarking();
|
|
for (var i = 0; i < marking.MarkingColors.Count && i < markings[index].MarkingColors.Count; i++)
|
|
{
|
|
marking.SetColor(i, markings[index].MarkingColors[i]);
|
|
}
|
|
|
|
humanoid.MarkingSet.Replace(category, index, marking);
|
|
Dirty(humanoid);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Sets the marking colors of the humanoid in a category at an index in the category's list.
|
|
/// </summary>
|
|
/// <param name="uid">Humanoid mob's UID</param>
|
|
/// <param name="category">Category of the marking</param>
|
|
/// <param name="index">Index of the marking</param>
|
|
/// <param name="colors">The marking colors to use</param>
|
|
/// <param name="humanoid">Humanoid component of the entity</param>
|
|
public void SetMarkingColor(EntityUid uid, MarkingCategories category, int index, List<Color> colors,
|
|
HumanoidAppearanceComponent? humanoid = null)
|
|
{
|
|
if (index < 0
|
|
|| !Resolve(uid, ref humanoid)
|
|
|| !humanoid.MarkingSet.TryGetCategory(category, out var markings)
|
|
|| index >= markings.Count)
|
|
{
|
|
return;
|
|
}
|
|
|
|
for (var i = 0; i < markings[index].MarkingColors.Count && i < colors.Count; i++)
|
|
{
|
|
markings[index].SetColor(i, colors[i]);
|
|
}
|
|
|
|
Dirty(humanoid);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Takes ID of the species prototype, returns UI-friendly name of the species.
|
|
/// </summary>
|
|
public string GetSpeciesRepresentation(string speciesId)
|
|
{
|
|
if (_prototypeManager.TryIndex<SpeciesPrototype>(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<SpeciesPrototype>(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");
|
|
}
|
|
}
|