Hopefully fix alerts disappearing (#6986)

This commit is contained in:
Leon Friedrich
2022-03-04 23:52:51 +13:00
committed by GitHub
parent de6b34aaa3
commit ee60ac982e
2 changed files with 49 additions and 35 deletions

View File

@@ -1,10 +1,5 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using Robust.Shared.GameObjects;
using Robust.Shared.GameStates;
using Robust.Shared.IoC;
using Robust.Shared.Log;
using Robust.Shared.Prototypes;
namespace Content.Shared.Alert;
@@ -14,6 +9,8 @@ public abstract class AlertsSystem : EntitySystem
[Dependency]
private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly MetaDataSystem _metaSystem = default!;
private readonly Dictionary<AlertType, AlertPrototype> _typeToAlert = new();
public IReadOnlyDictionary<AlertKey, AlertState>? GetActiveAlerts(EntityUid euid)
@@ -158,19 +155,41 @@ public abstract class AlertsSystem : EntitySystem
{
base.Initialize();
SubscribeLocalEvent<AlertsComponent, ComponentStartup>((uid, _, _) => RaiseLocalEvent(uid, new AlertSyncEvent(uid)));
SubscribeLocalEvent<AlertsComponent, ComponentShutdown>((uid, _, _) => HandleComponentShutdown(uid));
SubscribeLocalEvent<AlertsComponent, ComponentStartup>(HandleComponentStartup);
SubscribeLocalEvent<AlertsComponent, ComponentShutdown>(HandleComponentShutdown);
SubscribeLocalEvent<AlertsComponent, MetaFlagRemoveAttemptEvent>(OnMetaFlagRemoval);
SubscribeLocalEvent<AlertsComponent, ComponentGetState>(ClientAlertsGetState);
SubscribeLocalEvent<AlertsComponent, ComponentGetStateAttemptEvent>(OnCanGetState);
SubscribeNetworkEvent<ClickAlertEvent>(HandleClickAlert);
LoadPrototypes();
_prototypeManager.PrototypesReloaded += HandlePrototypesReloaded;
}
protected virtual void HandleComponentShutdown(EntityUid uid)
private void OnMetaFlagRemoval(EntityUid uid, AlertsComponent component, ref MetaFlagRemoveAttemptEvent args)
{
if (component.LifeStage == ComponentLifeStage.Running)
args.Cancelled = true;
}
private void OnCanGetState(EntityUid uid, AlertsComponent component, ref ComponentGetStateAttemptEvent args)
{
// Only send alert state data to the relevant player.
if (args.Player.AttachedEntity != uid)
args.Cancelled = true;
}
protected virtual void HandleComponentShutdown(EntityUid uid, AlertsComponent component, ComponentShutdown args)
{
RaiseLocalEvent(uid, new AlertSyncEvent(uid));
_metaSystem.RemoveFlag(uid, MetaDataFlags.EntitySpecific);
}
private void HandleComponentStartup(EntityUid uid, AlertsComponent component, ComponentStartup args)
{
RaiseLocalEvent(uid, new AlertSyncEvent(uid));
_metaSystem.AddFlag(uid, MetaDataFlags.EntitySpecific);
}
public override void Shutdown()