From 2516042fa813353f928c0ab4393553ecf0101758 Mon Sep 17 00:00:00 2001 From: Kayzel <43700376+KayzelW@users.noreply.github.com> Date: Sun, 10 Nov 2024 18:34:46 +0300 Subject: [PATCH] fix --- .../Body/SharedBodySystem.PartAppearance.cs | 44 ++++++++++++------- .../Body/Systems/SharedBodySystem.Body.cs | 30 ++++++------- 2 files changed, 44 insertions(+), 30 deletions(-) diff --git a/Content.Shared/Backmen/Surgery/Body/SharedBodySystem.PartAppearance.cs b/Content.Shared/Backmen/Surgery/Body/SharedBodySystem.PartAppearance.cs index dd5c40fe129..8998a687c42 100644 --- a/Content.Shared/Backmen/Surgery/Body/SharedBodySystem.PartAppearance.cs +++ b/Content.Shared/Backmen/Surgery/Body/SharedBodySystem.PartAppearance.cs @@ -3,11 +3,16 @@ using Content.Shared.Body.Part; using Content.Shared.Humanoid; using Content.Shared.Humanoid.Markings; +using Content.Shared.Humanoid.Prototypes; +using Robust.Shared.Prototypes; +using Robust.Shared.Utility; namespace Content.Shared.Body.Systems; + public partial class SharedBodySystem { [Dependency] private readonly SharedHumanoidAppearanceSystem _humanoid = default!; + private void InitializePartAppearances() { base.Initialize(); @@ -20,7 +25,6 @@ private void InitializePartAppearances() private void OnPartAppearanceStartup(EntityUid uid, BodyPartAppearanceComponent component, ComponentStartup args) { - // God this function reeks, it needs some cleanup BADLY. Help is appreciated as always. if (!TryComp(uid, out BodyPartComponent? part) @@ -55,19 +59,8 @@ private void OnPartAppearanceStartup(EntityUid uid, BodyPartAppearanceComponent else { component.Color = bodyAppearance.SkinColor; - var symmetryPrefix = part.Symmetry switch - { - BodyPartSymmetry.Left => "L", - BodyPartSymmetry.Right => "R", - _ => "" - }; - - var genderSuffix = ""; - if (part.PartType == BodyPartType.Torso || part.PartType == BodyPartType.Head) - genderSuffix = part.Sex.ToString(); - - component.ID = $"Mob{part.Species}{symmetryPrefix}{part.PartType}{genderSuffix}"; + component.ID = GetBodyPartPrototype(part); } // I HATE HARDCODED CHECKS I HATE HARDCODED CHECKS I HATE HARDCODED CHECKS @@ -80,15 +73,32 @@ private void OnPartAppearanceStartup(EntityUid uid, BodyPartAppearanceComponent { var category = MarkingCategoriesConversion.FromHumanoidVisualLayers(layer); if (bodyAppearance.MarkingSet.Markings.TryGetValue(category, out var markingList)) - markingsByLayer[layer] = markingList.Select(m => new Marking(m.MarkingId, m.MarkingColors.ToList())).ToList(); + markingsByLayer[layer] = + markingList.Select(m => new Marking(m.MarkingId, m.MarkingColors.ToList())).ToList(); } component.Markings = markingsByLayer; } + + public string GetBodyPartPrototype(BodyPartComponent part) + { + var speciesPrototype = _proto.Index(part.Species); + var spriteSet = _proto.Index(speciesPrototype.SpriteSet); + + var layers = part.ToHumanoidLayers(); + + DebugTools.AssertNotNull(layers); + + DebugTools.Assert(spriteSet.Sprites.ContainsKey(layers!.Value)); + + return HumanoidVisualLayersExtension.GetSexMorph(layers.Value, part.Sex, spriteSet.Sprites[layers.Value]); + } + private void HandleState(EntityUid uid, BodyPartAppearanceComponent component, ref AfterAutoHandleStateEvent args) { ApplyPartMarkings(uid, component); } + private void OnPartAttachedToBody(EntityUid uid, BodyComponent component, ref BodyPartAttachedEvent args) { if (!TryComp(args.Part, out BodyPartAppearanceComponent? partAppearance) @@ -129,6 +139,7 @@ protected void UpdateAppearance(EntityUid target, _humanoid.AddMarking(target, marking.MarkingId, marking.MarkingColors, false, true, bodyAppearance); } } + Dirty(target, bodyAppearance); } @@ -141,10 +152,13 @@ protected void RemoveAppearance(EntityUid entity, BodyPartAppearanceComponent co { _humanoid.SetLayerVisibility(entity, visualLayer, false, true, bodyAppearance); } + RemovePartMarkings(entity, component, bodyAppearance); } protected abstract void ApplyPartMarkings(EntityUid target, BodyPartAppearanceComponent component); - protected abstract void RemovePartMarkings(EntityUid target, BodyPartAppearanceComponent partAppearance, HumanoidAppearanceComponent bodyAppearance); + protected abstract void RemovePartMarkings(EntityUid target, + BodyPartAppearanceComponent partAppearance, + HumanoidAppearanceComponent bodyAppearance); } diff --git a/Content.Shared/Body/Systems/SharedBodySystem.Body.cs b/Content.Shared/Body/Systems/SharedBodySystem.Body.cs index 45335c9b53f..ceddd728301 100644 --- a/Content.Shared/Body/Systems/SharedBodySystem.Body.cs +++ b/Content.Shared/Body/Systems/SharedBodySystem.Body.cs @@ -237,21 +237,21 @@ private void MapInitParts(EntityUid rootPartId, BodyPartComponent rootPart, Body continue; } - // start-backmen: surgery - if (TryComp(parentPartComponent.Body, out HumanoidAppearanceComponent? bodyAppearance)) - { - var appearance = AddComp(childPart); - appearance.OriginalBody = childPartComponent.OriginalBody; - appearance.Color = bodyAppearance.SkinColor; - - var symmetry = ((BodyPartSymmetry) childPartComponent.Symmetry).ToString(); - if (symmetry == "None") - symmetry = ""; - appearance.ID = "removed" + symmetry + ((BodyPartType) childPartComponent.PartType).ToString(); - - Dirty(childPart, appearance); - } - // end-backmen: surgery + // // start-backmen: surgery + // if (TryComp(parentPartComponent.Body, out HumanoidAppearanceComponent? bodyAppearance)) + // { + // var appearance = AddComp(childPart); + // appearance.OriginalBody = childPartComponent.OriginalBody; + // appearance.Color = bodyAppearance.SkinColor; + // + // var symmetry = ((BodyPartSymmetry) childPartComponent.Symmetry).ToString(); + // if (symmetry == "None") + // symmetry = ""; + // appearance.ID = "removed" + symmetry + ((BodyPartType) childPartComponent.PartType).ToString(); + // + // Dirty(childPart, appearance); + // } + // // end-backmen: surgery // Add organs SetupOrgans((childPart, childPartComponent), connectionSlot.Organs);