Files
tbd-station-14/Content.Server/GameObjects/Components/Mobs/HumanoidAppearanceComponent.cs
DrSmugleaf 101fa9e466 Fix mechanism events not being called properly, add test (#2279)
* Add mechanism events when added/removed to/from body/parts

* Change old usages

* Add TODO

* Remove BodyExtensions and IHasBody

* Remove unnecessary extensions and fix wrong event call in mechanism behavior component

* Complete test and fix event calls
2020-10-17 12:26:39 +02:00

53 lines
1.5 KiB
C#

using Content.Shared.GameObjects.Components.Body;
using Content.Shared.GameObjects.Components.Mobs;
using Content.Shared.Preferences;
using Robust.Server.GameObjects;
using Robust.Shared.GameObjects;
namespace Content.Server.GameObjects.Components.Mobs
{
[RegisterComponent]
public sealed class HumanoidAppearanceComponent : SharedHumanoidAppearanceComponent
{
public override HumanoidCharacterAppearance Appearance
{
get => base.Appearance;
set
{
base.Appearance = value;
if (Owner.TryGetComponent(out IBody body))
{
foreach (var part in body.Parts.Values)
{
if (!part.Owner.TryGetComponent(out SpriteComponent sprite))
{
continue;
}
sprite.Color = value.SkinColor;
}
}
}
}
protected override void Startup()
{
base.Startup();
if (Appearance != null && Owner.TryGetComponent(out IBody body))
{
foreach (var part in body.Parts.Values)
{
if (!part.Owner.TryGetComponent(out SpriteComponent sprite))
{
continue;
}
sprite.Color = Appearance.SkinColor;
}
}
}
}
}