70 lines
2.5 KiB
C#
70 lines
2.5 KiB
C#
using System.Linq;
|
|
using Content.Client.PDA;
|
|
using Content.Shared.Clothing.Components;
|
|
using Content.Shared.Clothing.EntitySystems;
|
|
using Content.Shared.Inventory;
|
|
using Robust.Client.GameObjects;
|
|
using Robust.Shared.Prototypes;
|
|
|
|
namespace Content.Client.Clothing.Systems;
|
|
|
|
// All valid items for chameleon are calculated on client startup and stored in dictionary.
|
|
public sealed class ChameleonClothingSystem : SharedChameleonClothingSystem
|
|
{
|
|
[Dependency] private readonly IPrototypeManager _proto = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
SubscribeLocalEvent<ChameleonClothingComponent, AfterAutoHandleStateEvent>(HandleState);
|
|
|
|
PrepareAllVariants();
|
|
SubscribeLocalEvent<PrototypesReloadedEventArgs>(OnProtoReloaded);
|
|
}
|
|
|
|
private void OnProtoReloaded(PrototypesReloadedEventArgs args)
|
|
{
|
|
if (args.WasModified<EntityPrototype>())
|
|
PrepareAllVariants();
|
|
}
|
|
|
|
private void HandleState(EntityUid uid, ChameleonClothingComponent component, ref AfterAutoHandleStateEvent args)
|
|
{
|
|
UpdateVisuals(uid, component);
|
|
}
|
|
|
|
protected override void UpdateSprite(EntityUid uid, EntityPrototype proto)
|
|
{
|
|
base.UpdateSprite(uid, proto);
|
|
if (TryComp(uid, out SpriteComponent? sprite)
|
|
&& proto.TryGetComponent(out SpriteComponent? otherSprite, Factory))
|
|
{
|
|
sprite.CopyFrom(otherSprite);
|
|
}
|
|
// Sunrise-start
|
|
if (!TryComp(uid, out ToggleableClothingComponent? helmet)
|
|
|| !proto.TryGetComponent(out ToggleableClothingComponent? protoHelmet, Factory))
|
|
return;
|
|
|
|
if (!_proto.TryIndex(protoHelmet.ClothingPrototype.Id, out var prototypeHelmetOther))
|
|
return;
|
|
|
|
if (prototypeHelmetOther == null)
|
|
return;
|
|
|
|
if (TryComp(helmet.ClothingUid, out SpriteComponent? helmetSprite)
|
|
&& prototypeHelmetOther.TryGetComponent(out SpriteComponent? otherHelmetSprite, Factory))
|
|
{
|
|
helmetSprite.CopyFrom(otherHelmetSprite);
|
|
}
|
|
// Sunrise-end
|
|
// Edgecase for PDAs to include visuals when UI is open
|
|
if (TryComp(uid, out PdaBorderColorComponent? borderColor)
|
|
&& proto.TryGetComponent(out PdaBorderColorComponent? otherBorderColor, Factory))
|
|
{
|
|
borderColor.BorderColor = otherBorderColor.BorderColor;
|
|
borderColor.AccentHColor = otherBorderColor.AccentHColor;
|
|
borderColor.AccentVColor = otherBorderColor.AccentVColor;
|
|
}
|
|
}
|
|
}
|