CatStation/Content.Client/Clothing/Systems/ChameleonClothingSystem.cs

54 lines
2.1 KiB
C#

using Content.Client.PDA;
using Content.Shared.Clothing.Components;
using Content.Shared.Clothing.EntitySystems;
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 partial class ChameleonClothingSystem : SharedChameleonClothingSystem
{
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.TryComp(out SpriteComponent? otherSprite, Factory))
{
// TODO no system method to replace this with.
// otherSprite.Owner is Invalid here because the component is being taken from a prototype.
// This is very fragile because if resolves ever start checking if an entity is invalid this will throw
// even though this ends up calling the system, its better to leave this warning here until theres a proper method
sprite.CopyFrom(otherSprite);
}
// Edgecase for PDAs to include visuals when UI is open
if (TryComp(uid, out PdaBorderColorComponent? borderColor)
&& proto.TryComp(out PdaBorderColorComponent? otherBorderColor, Factory))
{
borderColor.BorderColor = otherBorderColor.BorderColor;
borderColor.AccentHColor = otherBorderColor.AccentHColor;
borderColor.AccentVColor = otherBorderColor.AccentVColor;
}
}
}