Alerts Cleanup and API (#39544)

* alert cleanup and API

* I expect update loops to be at the top.

* Address review

* Address review x 2

* Merg my PR

* Fix

* Update Content.Shared/Alert/AlertsSystem.cs

webedit

Co-authored-by: Perry Fraser <perryprog@users.noreply.github.com>

* FIX THAT TEST FAIL!!!!

* Me when I forget to actually give you alerts

* Hammedborgar

---------

Co-authored-by: Princess Cheeseballs <66055347+Pronana@users.noreply.github.com>
Co-authored-by: Perry Fraser <perryprog@users.noreply.github.com>
This commit is contained in:
Princess Cheeseballs
2025-09-05 02:45:48 -07:00
committed by GitHub
parent 5e0e5e045a
commit d488ca96b2
18 changed files with 213 additions and 196 deletions

View File

@@ -1,6 +1,5 @@
using Content.Shared.Alert;
using Content.Shared.StatusEffectNew.Components;
using Robust.Shared.Timing;
namespace Content.Shared.StatusEffectNew;
@@ -9,7 +8,6 @@ namespace Content.Shared.StatusEffectNew;
/// </summary>
public sealed class StatusEffectAlertSystem : EntitySystem
{
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly AlertsSystem _alerts = default!;
private EntityQuery<StatusEffectComponent> _effectQuery;
@@ -30,7 +28,7 @@ public sealed class StatusEffectAlertSystem : EntitySystem
if (!_effectQuery.TryComp(ent, out var effectComp))
return;
RefreshAlert(ent, args.Target, effectComp.EndEffectTime);
_alerts.UpdateAlert(args.Target, ent.Comp.Alert, cooldown: ent.Comp.ShowDuration ? effectComp.EndEffectTime : null);
}
private void OnStatusEffectRemoved(Entity<StatusEffectAlertComponent> ent, ref StatusEffectRemovedEvent args)
@@ -40,23 +38,6 @@ public sealed class StatusEffectAlertSystem : EntitySystem
private void OnEndTimeUpdated(Entity<StatusEffectAlertComponent> ent, ref StatusEffectEndTimeUpdatedEvent args)
{
RefreshAlert(ent, args.Target, args.EndTime);
}
private void RefreshAlert(Entity<StatusEffectAlertComponent> ent, EntityUid target, TimeSpan? endTime)
{
(TimeSpan Start, TimeSpan End)? cooldown = null;
// Make sure the start time of the alert cooldown is still accurate
// This ensures the progress wheel doesn't "reset" every duration change.
if (ent.Comp.ShowDuration
&& endTime is not null
&& _alerts.TryGet(ent.Comp.Alert, out var alert))
{
_alerts.TryGetAlertState(target, alert.AlertKey, out var alertState);
cooldown = (alertState.Cooldown?.Item1 ?? _timing.CurTime, endTime.Value);
}
_alerts.ShowAlert(target, ent.Comp.Alert, cooldown: cooldown);
_alerts.UpdateAlert(args.Target, ent.Comp.Alert, cooldown: ent.Comp.ShowDuration ? args.EndTime : null);
}
}