Files
ss14-wega/Content.Client/Nutrition/EntitySystems/CreamPieSystem.cs
T
slarticodefast 7c60ea97e4 Fix banana creampie visuals, allow station AI to be pied (#43388)
* refactor and fixes

* fix ling transformation

* small fix

* Update Content.Shared/Nutrition/EntitySystems/SharedCreamPieSystem.cs

Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>

---------

Co-authored-by: ScarKy0 <106310278+ScarKy0@users.noreply.github.com>
2026-04-03 18:16:17 +00:00

67 lines
2.5 KiB
C#

using Content.Shared.Nutrition.Components;
using Content.Shared.Nutrition.EntitySystems;
using Robust.Client.GameObjects;
namespace Content.Client.Nutrition.EntitySystems;
public sealed class CreamPieSystem : SharedCreamPieSystem
{
[Dependency] private readonly SpriteSystem _sprite = default!;
[Dependency] private readonly AppearanceSystem _appearance = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<CreamPiedComponent, ComponentInit>(OnComponentInit);
SubscribeLocalEvent<CreamPiedComponent, ComponentShutdown>(OnComponentShutdown);
SubscribeLocalEvent<CreamPiedComponent, AppearanceChangeEvent>(OnAppearanceChange);
SubscribeLocalEvent<CreamPiedComponent, AfterAutoHandleStateEvent>(OnAfterAutoHandleState);
}
private void OnComponentInit(Entity<CreamPiedComponent> ent, ref ComponentInit args)
{
UpdateAppearance(ent);
}
private void OnComponentShutdown(Entity<CreamPiedComponent> ent, ref ComponentShutdown args)
{
_sprite.RemoveLayer(ent.Owner, CreamPiedVisualLayer.Key);
}
private void OnAppearanceChange(Entity<CreamPiedComponent> ent, ref AppearanceChangeEvent args)
{
UpdateAppearance((ent.Owner, ent.Comp, args.Sprite, args.Component));
}
private void OnAfterAutoHandleState(Entity<CreamPiedComponent> ent, ref AfterAutoHandleStateEvent args)
{
// Update when the sprite datafield is changed so that changelings can transform properly.
UpdateAppearance(ent);
}
private void UpdateAppearance(Entity<CreamPiedComponent, SpriteComponent?, AppearanceComponent?> ent)
{
if (!Resolve(ent, ref ent.Comp2, false) || !Resolve(ent, ref ent.Comp3, false))
return;
var creamPied = ent.Comp1;
var sprite = ent.Comp2;
var appearance = ent.Comp3;
// If there is no sprite to use, remove the layer. Otherwise ensure that it exists and set the visuals accordingly.
int index;
if (creamPied.Sprite == null)
{
_sprite.RemoveLayer((ent.Owner, sprite), CreamPiedVisualLayer.Key);
return;
}
index = _sprite.LayerMapReserve((ent.Owner, sprite), CreamPiedVisualLayer.Key);
_appearance.TryGetData<bool>(ent.Owner, CreamPiedVisuals.Creamed, out var isCreamPied, appearance);
_sprite.LayerSetSprite((ent.Owner, sprite), index, creamPied.Sprite);
_sprite.LayerSetVisible((ent.Owner, sprite), index, isCreamPied);
}
}