Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] surgery emergency fix #912

Merged
merged 1 commit into from
Nov 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading