Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
KayzelW committed Nov 10, 2024
1 parent 48fa80c commit 2516042
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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<SpeciesPrototype>(part.Species);
var spriteSet = _proto.Index<HumanoidSpeciesBaseSpritesPrototype>(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)
Expand Down Expand Up @@ -129,6 +139,7 @@ protected void UpdateAppearance(EntityUid target,
_humanoid.AddMarking(target, marking.MarkingId, marking.MarkingColors, false, true, bodyAppearance);
}
}

Dirty(target, bodyAppearance);
}

Expand All @@ -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);
}
30 changes: 15 additions & 15 deletions Content.Shared/Body/Systems/SharedBodySystem.Body.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<BodyPartAppearanceComponent>(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<BodyPartAppearanceComponent>(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);
Expand Down

0 comments on commit 2516042

Please sign in to comment.