Skip to content

Commit

Permalink
???
Browse files Browse the repository at this point in the history
  • Loading branch information
deltanedas committed Jan 13, 2025
1 parent 32cb733 commit 7f1adea
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@
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!;
[Dependency] private readonly MarkingManager _markingManager = default!;
[Dependency] private readonly IPrototypeManager _proto = default!;

[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
private void InitializePartAppearances()
{
base.Initialize();
Expand All @@ -29,7 +28,6 @@ private void InitializePartAppearances()

private void OnPartAppearanceStartup(EntityUid uid, BodyPartAppearanceComponent component, ComponentStartup args)
{
Log.Debug($"BPA added to {ToPrettyString(uid)}");
if (!TryComp(uid, out BodyPartComponent? part)
|| part.ToHumanoidLayers() is not { } relevantLayer)
return;
Expand All @@ -38,12 +36,9 @@ private void OnPartAppearanceStartup(EntityUid uid, BodyPartAppearanceComponent
{
component.ID = part.BaseLayerId;
component.Type = relevantLayer;
Dirty(uid, component);
return;
}

Log.Debug($"Checking {ToPrettyString(uid)} and {part.Body}");

if (part.Body is not { Valid: true } body
|| !TryComp(body, out HumanoidAppearanceComponent? bodyAppearance))
return;
Expand All @@ -54,8 +49,6 @@ private void OnPartAppearanceStartup(EntityUid uid, BodyPartAppearanceComponent

part.Species = bodyAppearance.Species;

Log.Debug($"Updating to {part.Species}, {bodyAppearance.SkinColor}");

if (customLayers.ContainsKey(component.Type))
{
component.ID = customLayers[component.Type].Id;
Expand All @@ -74,7 +67,7 @@ private void OnPartAppearanceStartup(EntityUid uid, BodyPartAppearanceComponent

// I HATE HARDCODED CHECKS I HATE HARDCODED CHECKS I HATE HARDCODED CHECKS
if (part.PartType == BodyPartType.Head)
component.EyeColor = bodyAppearance.EyeColor; // TODO: move this to the eyes...
component.EyeColor = bodyAppearance.EyeColor;

var markingsByLayer = new Dictionary<HumanoidVisualLayers, List<Marking>>();

Expand All @@ -86,48 +79,17 @@ private void OnPartAppearanceStartup(EntityUid uid, BodyPartAppearanceComponent
}

component.Markings = markingsByLayer;
Dirty(uid, component);
}

/// <summary>
/// Makes sure the body part has an appearance, using the default for its species if it doesn't have one from a body.
/// If this part is in a body nothing is done.
/// </summary>
public bool EnsurePartAppearance(EntityUid uid, out BodyPartAppearanceComponent comp)
{
var had = EnsureComp<BodyPartAppearanceComponent>(uid, out comp);
if (!TryComp<BodyPartComponent>(uid, out var part)
|| comp.ID != null // already assigned from a body
|| string.IsNullOrEmpty(part.Species) // bad part prototype
|| part.Body != null // let the body assign correct appearance when detaching this part, don't touch
|| part.ToHumanoidLayers() is not {} relevantLayer) // not something that can have appearance
return had;

var species = _proto.Index<SpeciesPrototype>(part.Species);
comp.ID = GetSpeciesSprite(species, relevantLayer);
comp.Type = relevantLayer;
var skinColor = new Color(_random.NextFloat(1), _random.NextFloat(1), _random.NextFloat(1), 1);
comp.Color = SkinColor.ValidSkinTone(species.SkinColoration, skinColor);
Dirty(uid, comp);
return had;
}

private string? CreateIdFromPart(HumanoidAppearanceComponent bodyAppearance, HumanoidVisualLayers part)
{
if (GetSpeciesSprite(_proto.Index(bodyAppearance.Species), part) is not {} sprite)
return null;

return HumanoidVisualLayersExtension.GetSexMorph(part, bodyAppearance.Sex, sprite);
}

private string? GetSpeciesSprite(SpeciesPrototype species, HumanoidVisualLayers part)
{
var baseSprites = _proto.Index<HumanoidSpeciesBaseSpritesPrototype>(species.SpriteSet);
var speciesProto = _prototypeManager.Index(bodyAppearance.Species);
var baseSprites = _prototypeManager.Index<HumanoidSpeciesBaseSpritesPrototype>(speciesProto.SpriteSet);

if (!baseSprites.Sprites.TryGetValue(part, out var sprite))
if (!baseSprites.Sprites.ContainsKey(part))
return null;

return sprite;
return HumanoidVisualLayersExtension.GetSexMorph(part, bodyAppearance.Sex, baseSprites.Sprites[part]);
}

public void ModifyMarkings(EntityUid uid,
Expand Down Expand Up @@ -172,10 +134,8 @@ private void HandleState(EntityUid uid, BodyPartAppearanceComponent component, r

private void OnPartAttachedToBody(EntityUid uid, BodyComponent component, ref BodyPartAddedEvent args)
{
if (!TryComp(uid, out HumanoidAppearanceComponent? bodyAppearance))
return;

if (EnsurePartAppearance(args.Part, out var partAppearance))
if (!TryComp(args.Part, out BodyPartAppearanceComponent? partAppearance)
|| !TryComp(uid, out HumanoidAppearanceComponent? bodyAppearance))
return;

if (partAppearance.ID != null)
Expand All @@ -191,10 +151,13 @@ private void OnPartDroppedFromBody(EntityUid uid, BodyComponent component, ref B
|| !TryComp(uid, out HumanoidAppearanceComponent? bodyAppearance))
return;

// When this component gets added it copies data from the body.
// This makes sure the markings are removed in RemoveAppearance, and layers hidden.
var partAppearance = EnsureComp<BodyPartAppearanceComponent>(args.Part);
RemoveAppearance(uid, partAppearance, args.Part);
// We check for this conditional here since some entities may not have a profile... If they dont
// have one, and their part is gibbed, the markings will not be removed or applied properly.
if (!HasComp<BodyPartAppearanceComponent>(args.Part))
EnsureComp<BodyPartAppearanceComponent>(args.Part);

if (TryComp<BodyPartAppearanceComponent>(args.Part, out var partAppearance))
RemoveAppearance(uid, partAppearance, args.Part);
}

protected void UpdateAppearance(EntityUid target,
Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "8.0.100",
"version": "9.0.101",
"rollForward": "latestFeature"
}
}

0 comments on commit 7f1adea

Please sign in to comment.