Station alert levels (#8226)

This commit is contained in:
Flipp Syder
2022-05-17 21:05:31 -07:00
committed by GitHub
parent 2697bbf8c7
commit dcdda39048
21 changed files with 566 additions and 2 deletions

View File

@@ -0,0 +1,35 @@
using Content.Server.Station.Systems;
using Content.Shared.AlertLevel;
namespace Content.Server.AlertLevel;
public sealed class AlertLevelDisplaySystem : EntitySystem
{
[Dependency] private readonly StationSystem _stationSystem = default!;
public override void Initialize()
{
SubscribeLocalEvent<AlertLevelChangedEvent>(OnAlertChanged);
SubscribeLocalEvent<AlertLevelDisplayComponent, ComponentInit>(OnDisplayInit);
}
private void OnAlertChanged(AlertLevelChangedEvent args)
{
foreach (var (_, appearance) in EntityManager.EntityQuery<AlertLevelDisplayComponent, AppearanceComponent>())
{
appearance.SetData(AlertLevelDisplay.CurrentLevel, args.AlertLevel);
}
}
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))
{
appearance.SetData(AlertLevelDisplay.CurrentLevel, alert.CurrentLevel);
}
}
}
}