mirror of
https://github.com/space-wizards/space-station-14.git
synced 2026-02-14 19:29:53 +01:00
Co-authored-by: Nemanja <98561806+EmoGarbage404@users.noreply.github.com> Co-authored-by: ArtisticRoomba <145879011+ArtisticRoomba@users.noreply.github.com>
95 lines
2.8 KiB
C#
95 lines
2.8 KiB
C#
using Content.Shared.Silicons.StationAi;
|
|
using Robust.Client.GameObjects;
|
|
using Robust.Client.Graphics;
|
|
using Robust.Client.Player;
|
|
using Robust.Shared.Player;
|
|
|
|
namespace Content.Client.Silicons.StationAi;
|
|
|
|
public sealed partial class StationAiSystem : SharedStationAiSystem
|
|
{
|
|
[Dependency] private readonly IOverlayManager _overlayMgr = default!;
|
|
[Dependency] private readonly IPlayerManager _player = default!;
|
|
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
|
|
|
|
private StationAiOverlay? _overlay;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
InitializeAirlock();
|
|
InitializePowerToggle();
|
|
|
|
SubscribeLocalEvent<StationAiOverlayComponent, LocalPlayerAttachedEvent>(OnAiAttached);
|
|
SubscribeLocalEvent<StationAiOverlayComponent, LocalPlayerDetachedEvent>(OnAiDetached);
|
|
SubscribeLocalEvent<StationAiOverlayComponent, ComponentInit>(OnAiOverlayInit);
|
|
SubscribeLocalEvent<StationAiOverlayComponent, ComponentRemove>(OnAiOverlayRemove);
|
|
SubscribeLocalEvent<StationAiCoreComponent, AppearanceChangeEvent>(OnAppearanceChange);
|
|
}
|
|
|
|
private void OnAiOverlayInit(Entity<StationAiOverlayComponent> ent, ref ComponentInit args)
|
|
{
|
|
var attachedEnt = _player.LocalEntity;
|
|
|
|
if (attachedEnt != ent.Owner)
|
|
return;
|
|
|
|
AddOverlay();
|
|
}
|
|
|
|
private void OnAiOverlayRemove(Entity<StationAiOverlayComponent> ent, ref ComponentRemove args)
|
|
{
|
|
var attachedEnt = _player.LocalEntity;
|
|
|
|
if (attachedEnt != ent.Owner)
|
|
return;
|
|
|
|
RemoveOverlay();
|
|
}
|
|
|
|
private void AddOverlay()
|
|
{
|
|
if (_overlay != null)
|
|
return;
|
|
|
|
_overlay = new StationAiOverlay();
|
|
_overlayMgr.AddOverlay(_overlay);
|
|
}
|
|
|
|
private void RemoveOverlay()
|
|
{
|
|
if (_overlay == null)
|
|
return;
|
|
|
|
_overlayMgr.RemoveOverlay(_overlay);
|
|
_overlay = null;
|
|
}
|
|
|
|
private void OnAiAttached(Entity<StationAiOverlayComponent> ent, ref LocalPlayerAttachedEvent args)
|
|
{
|
|
AddOverlay();
|
|
}
|
|
|
|
private void OnAiDetached(Entity<StationAiOverlayComponent> ent, ref LocalPlayerDetachedEvent args)
|
|
{
|
|
RemoveOverlay();
|
|
}
|
|
|
|
private void OnAppearanceChange(Entity<StationAiCoreComponent> entity, ref AppearanceChangeEvent args)
|
|
{
|
|
if (args.Sprite == null)
|
|
return;
|
|
|
|
if (_appearance.TryGetData<PrototypeLayerData>(entity.Owner, StationAiVisualState.Key, out var layerData, args.Component))
|
|
args.Sprite.LayerSetData(StationAiVisualState.Key, layerData);
|
|
|
|
args.Sprite.LayerSetVisible(StationAiVisualState.Key, layerData != null);
|
|
}
|
|
|
|
public override void Shutdown()
|
|
{
|
|
base.Shutdown();
|
|
_overlayMgr.RemoveOverlay<StationAiOverlay>();
|
|
}
|
|
}
|