CatStation/Content.Client/Polymorph/Systems/ChameleonProjectorSystem.cs
xsainteer 7b7379e75b
[HOTFIX] fixing chameleon projector (#45689)
SpriteSystem.CopySprite instead of direct Copy Component
2026-08-28 15:35:38 +03:00

72 lines
2.6 KiB
C#

using Content.Client.Effects;
using Content.Client.Smoking;
using Content.Shared.Chemistry.Components;
using Content.Shared.Polymorph.Components;
using Content.Shared.Polymorph.Systems;
using Robust.Client.GameObjects;
namespace Content.Client.Polymorph.Systems;
public sealed partial class ChameleonProjectorSystem : SharedChameleonProjectorSystem
{
[Dependency] private SharedAppearanceSystem _appearance = default!;
[Dependency] private SpriteSystem _sprite = default!;
[Dependency] private EntityQuery<AppearanceComponent> _appearanceQuery = default!;
[Dependency] private EntityQuery<SpriteComponent> _spriteQuery = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<ChameleonDisguiseComponent, AfterAutoHandleStateEvent>(OnHandleState);
SubscribeLocalEvent<ChameleonDisguisedComponent, ComponentStartup>(OnStartup);
SubscribeLocalEvent<ChameleonDisguisedComponent, ComponentShutdown>(OnShutdown);
SubscribeLocalEvent<ChameleonDisguisedComponent, GetFlashEffectTargetEvent>(OnGetFlashEffectTargetEvent);
}
private void OnHandleState(Entity<ChameleonDisguiseComponent> ent, ref AfterAutoHandleStateEvent args)
{
CopySprite(ent);
CopyComp<GenericVisualizerComponent>(ent);
CopyComp<SolutionContainerVisualsComponent>(ent);
CopyComp<BurnStateVisualsComponent>(ent);
// reload appearance to hopefully prevent any invisible layers
if (_appearanceQuery.TryComp(ent, out var appearance))
_appearance.QueueUpdate(ent, appearance);
}
/// <summary>
/// Copies the source entity/prototype's sprite onto the disguise.
/// </summary>
private void CopySprite(Entity<ChameleonDisguiseComponent> ent)
{
if (!GetSrcEntity<SpriteComponent>(ent.Comp, out var src))
return;
var dest = EnsureComp<SpriteComponent>(ent);
_sprite.CopySprite(src, (ent.Owner, dest));
}
private void OnStartup(Entity<ChameleonDisguisedComponent> ent, ref ComponentStartup args)
{
if (!_spriteQuery.TryComp(ent, out var sprite))
return;
ent.Comp.WasVisible = sprite.Visible;
_sprite.SetVisible((ent.Owner, sprite), false);
}
private void OnShutdown(Entity<ChameleonDisguisedComponent> ent, ref ComponentShutdown args)
{
if (_spriteQuery.TryComp(ent, out var sprite))
_sprite.SetVisible((ent.Owner, sprite), ent.Comp.WasVisible);
}
private void OnGetFlashEffectTargetEvent(Entity<ChameleonDisguisedComponent> ent, ref GetFlashEffectTargetEvent args)
{
args.Target = ent.Comp.Disguise;
}
}