2022-05-17 21:05:31 -07:00
|
|
|
using Content.Server.Station.Systems;
|
|
|
|
|
using Content.Shared.AlertLevel;
|
2023-02-02 17:34:53 +01:00
|
|
|
using Robust.Server.GameObjects;
|
2022-05-17 21:05:31 -07:00
|
|
|
|
|
|
|
|
namespace Content.Server.AlertLevel;
|
|
|
|
|
|
|
|
|
|
public sealed class AlertLevelDisplaySystem : EntitySystem
|
|
|
|
|
{
|
|
|
|
|
[Dependency] private readonly StationSystem _stationSystem = default!;
|
2023-02-02 17:34:53 +01:00
|
|
|
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
|
2022-05-17 21:05:31 -07:00
|
|
|
|
|
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
SubscribeLocalEvent<AlertLevelChangedEvent>(OnAlertChanged);
|
|
|
|
|
SubscribeLocalEvent<AlertLevelDisplayComponent, ComponentInit>(OnDisplayInit);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnAlertChanged(AlertLevelChangedEvent args)
|
|
|
|
|
{
|
|
|
|
|
foreach (var (_, appearance) in EntityManager.EntityQuery<AlertLevelDisplayComponent, AppearanceComponent>())
|
|
|
|
|
{
|
2023-02-02 17:34:53 +01:00
|
|
|
_appearance.SetData(appearance.Owner, AlertLevelDisplay.CurrentLevel, args.AlertLevel, appearance);
|
2022-05-17 21:05:31 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnDisplayInit(EntityUid uid, AlertLevelDisplayComponent component, ComponentInit args)
|
|
|
|
|
{
|
|
|
|
|
if (TryComp(uid, out AppearanceComponent? appearance))
|
|
|
|
|
{
|
|
|
|
|
var stationUid = _stationSystem.GetOwningStation(uid);
|
|
|
|
|
if (stationUid != null && TryComp(stationUid, out AlertLevelComponent? alert))
|
|
|
|
|
{
|
2023-02-02 17:34:53 +01:00
|
|
|
_appearance.SetData(uid, AlertLevelDisplay.CurrentLevel, alert.CurrentLevel, appearance);
|
2022-05-17 21:05:31 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|