Update trivial components to use auto comp states (#20539)

This commit is contained in:
DrSmugleaf
2023-09-28 16:20:29 -07:00
committed by GitHub
parent 14cfe44ece
commit a44fa86b68
158 changed files with 806 additions and 2866 deletions

View File

@@ -1,7 +1,6 @@
using Content.Shared.BarSign;
using Content.Shared.Power;
using Robust.Client.GameObjects;
using Robust.Shared.GameStates;
using Robust.Shared.Prototypes;
namespace Content.Client.BarSign;
@@ -13,33 +12,29 @@ public sealed class BarSignSystem : VisualizerSystem<BarSignComponent>
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<BarSignComponent, ComponentHandleState>(OnHandleState);
SubscribeLocalEvent<BarSignComponent, AfterAutoHandleStateEvent>(OnAfterAutoHandleState);
}
private void OnHandleState(EntityUid uid, BarSignComponent component, ref ComponentHandleState args)
private void OnAfterAutoHandleState(EntityUid uid, BarSignComponent component, ref AfterAutoHandleStateEvent args)
{
if (args.Current is not BarSignComponentState state)
return;
component.CurrentSign = state.CurrentSign;
UpdateAppearance(component);
UpdateAppearance(uid, component);
}
protected override void OnAppearanceChange(EntityUid uid, BarSignComponent component, ref AppearanceChangeEvent args)
{
UpdateAppearance(component, args.Component, args.Sprite);
UpdateAppearance(uid, component, args.Component, args.Sprite);
}
private void UpdateAppearance(BarSignComponent sign, AppearanceComponent? appearance = null, SpriteComponent? sprite = null)
private void UpdateAppearance(EntityUid id, BarSignComponent sign, AppearanceComponent? appearance = null, SpriteComponent? sprite = null)
{
if (!Resolve(sign.Owner, ref appearance, ref sprite))
if (!Resolve(id, ref appearance, ref sprite))
return;
AppearanceSystem.TryGetData<bool>(sign.Owner, PowerDeviceVisuals.Powered, out var powered, appearance);
AppearanceSystem.TryGetData<bool>(id, PowerDeviceVisuals.Powered, out var powered, appearance);
if (powered
&& sign.CurrentSign != null
&& _prototypeManager.TryIndex(sign.CurrentSign, out BarSignPrototype? proto))
&& sign.Current != null
&& _prototypeManager.TryIndex(sign.Current, out BarSignPrototype? proto))
{
sprite.LayerSetState(0, proto.Icon);
sprite.LayerSetShader(0, "unshaded");