Humanoid appearance fixes (#7020)

This commit is contained in:
metalgearsloth
2022-03-10 14:48:39 +11:00
committed by GitHub
parent 95aae0a8eb
commit 336318d452
3 changed files with 46 additions and 44 deletions

View File

@@ -1,13 +1,9 @@
using System.Collections.Generic;
using Content.Client.Cuffs.Components;
using Content.Shared.Body.Components;
using Content.Shared.CharacterAppearance;
using Content.Shared.CharacterAppearance.Components;
using Content.Shared.CharacterAppearance.Systems;
using Robust.Client.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Maths;
using Robust.Shared.Prototypes;
namespace Content.Client.CharacterAppearance.Systems
@@ -26,8 +22,7 @@ namespace Content.Client.CharacterAppearance.Systems
SubscribeLocalEvent<HumanoidAppearanceBodyPartRemovedEvent>(BodyPartRemoved);
}
private List<HumanoidVisualLayers> _bodyPartLayers = new List<HumanoidVisualLayers>
{
private readonly HumanoidVisualLayers[] _bodyPartLayers = {
HumanoidVisualLayers.Chest,
HumanoidVisualLayers.Head,
HumanoidVisualLayers.Eyes,
@@ -44,32 +39,63 @@ namespace Content.Client.CharacterAppearance.Systems
private void UpdateLooks(EntityUid uid, HumanoidAppearanceComponent component,
ChangedHumanoidAppearanceEvent args)
{
if (!EntityManager.TryGetComponent(uid, out SpriteComponent? sprite))
var spriteQuery = EntityManager.GetEntityQuery<SpriteComponent>();
if (!spriteQuery.TryGetComponent(uid, out var sprite))
return;
if (EntityManager.TryGetComponent(uid, out SharedBodyComponent? body))
{
foreach (var (part, _) in body.Parts)
{
if (EntityManager.TryGetComponent(part.Owner, out SpriteComponent? partSprite))
if (spriteQuery.TryGetComponent(part.Owner, out var partSprite))
{
partSprite!.Color = component.Appearance.SkinColor;
partSprite.Color = component.Appearance.SkinColor;
}
}
}
var hairColor = component.CanColorHair ? component.Appearance.HairColor : Color.White;
hairColor = component.HairMatchesSkin ? component.Appearance.SkinColor : hairColor;
sprite.LayerSetColor(HumanoidVisualLayers.Hair, hairColor.WithAlpha(component.HairAlpha));
// Like body parts some stuff may not have hair.
if (sprite.LayerMapTryGet(HumanoidVisualLayers.Hair, out var hairLayer))
{
var hairColor = component.CanColorHair ? component.Appearance.HairColor : Color.White;
hairColor = component.HairMatchesSkin ? component.Appearance.SkinColor : hairColor;
sprite.LayerSetColor(hairLayer, hairColor.WithAlpha(component.HairAlpha));
var facialHairColor = component.CanColorHair ? component.Appearance.FacialHairColor : Color.White;
facialHairColor = component.HairMatchesSkin ? component.Appearance.SkinColor : facialHairColor;
sprite.LayerSetColor(HumanoidVisualLayers.FacialHair, facialHairColor.WithAlpha(component.HairAlpha));
var hairStyle = component.Appearance.HairStyleId;
if (string.IsNullOrWhiteSpace(hairStyle) ||
!_accessoryManager.IsValidAccessoryInCategory(hairStyle, component.CategoriesHair))
{
hairStyle = HairStyles.DefaultHairStyle;
}
var hairPrototype = _prototypeManager.Index<SpriteAccessoryPrototype>(hairStyle);
sprite.LayerSetSprite(hairLayer, hairPrototype.Sprite);
}
if (sprite.LayerMapTryGet(HumanoidVisualLayers.FacialHair, out var facialLayer))
{
var facialHairColor = component.CanColorHair ? component.Appearance.FacialHairColor : Color.White;
facialHairColor = component.HairMatchesSkin ? component.Appearance.SkinColor : facialHairColor;
sprite.LayerSetColor(facialLayer, facialHairColor.WithAlpha(component.HairAlpha));
var facialHairStyle = component.Appearance.FacialHairStyleId;
if (string.IsNullOrWhiteSpace(facialHairStyle) ||
!_accessoryManager.IsValidAccessoryInCategory(facialHairStyle, component.CategoriesFacialHair))
{
facialHairStyle = HairStyles.DefaultFacialHairStyle;
}
var facialHairPrototype = _prototypeManager.Index<SpriteAccessoryPrototype>(facialHairStyle);
sprite.LayerSetSprite(facialLayer, facialHairPrototype.Sprite);
}
foreach (var layer in _bodyPartLayers)
{
sprite.LayerSetColor(layer, component.Appearance.SkinColor);
// Not every mob may have the furry layers hence we just skip it.
if (!sprite.LayerMapTryGet(layer, out var actualLayer)) continue;
sprite.LayerSetColor(actualLayer, component.Appearance.SkinColor);
}
sprite.LayerSetColor(HumanoidVisualLayers.Eyes, component.Appearance.EyeColor);
@@ -88,26 +114,6 @@ namespace Content.Client.CharacterAppearance.Systems
{
sprite.LayerSetVisible(HumanoidVisualLayers.Handcuffs, false);
}
var hairStyle = component.Appearance.HairStyleId;
if (string.IsNullOrWhiteSpace(hairStyle) ||
!_accessoryManager.IsValidAccessoryInCategory(hairStyle, component.CategoriesHair))
{
hairStyle = HairStyles.DefaultHairStyle;
}
var facialHairStyle = component.Appearance.FacialHairStyleId;
if (string.IsNullOrWhiteSpace(facialHairStyle) ||
!_accessoryManager.IsValidAccessoryInCategory(facialHairStyle, component.CategoriesFacialHair))
{
facialHairStyle = HairStyles.DefaultFacialHairStyle;
}
var hairPrototype = _prototypeManager.Index<SpriteAccessoryPrototype>(hairStyle);
var facialHairPrototype = _prototypeManager.Index<SpriteAccessoryPrototype>(facialHairStyle);
sprite.LayerSetSprite(HumanoidVisualLayers.Hair, hairPrototype.Sprite);
sprite.LayerSetSprite(HumanoidVisualLayers.FacialHair, facialHairPrototype.Sprite);
}
// Scaffolding until Body is moved to ECS.

View File

@@ -1,7 +1,4 @@
using System;
using Robust.Shared.IoC;
using Robust.Shared.Maths;
using Robust.Shared.Random;
using Robust.Shared.Random;
using Robust.Shared.Serialization;
namespace Content.Shared.CharacterAppearance

View File

@@ -1,10 +1,9 @@
using System;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization;
namespace Content.Shared.CharacterAppearance
{
[Serializable, NetSerializable]
public enum HumanoidVisualLayers
public enum HumanoidVisualLayers : byte
{
Hair,
FacialHair,