Skip to content

Commit

Permalink
Remove AlertType and AlertCategory (#27933)
Browse files Browse the repository at this point in the history
  • Loading branch information
EmoGarbage404 authored May 24, 2024
1 parent 594a898 commit 8a95cb1
Show file tree
Hide file tree
Showing 69 changed files with 482 additions and 385 deletions.
2 changes: 1 addition & 1 deletion Content.Client/Alerts/ClientAlertsSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ private void OnPlayerDetached(EntityUid uid, AlertsComponent component, LocalPla
ClearAlerts?.Invoke(this, EventArgs.Empty);
}

public void AlertClicked(AlertType alertType)
public void AlertClicked(ProtoId<AlertPrototype> alertType)
{
RaiseNetworkEvent(new ClickAlertEvent(alertType));
}
Expand Down
3 changes: 1 addition & 2 deletions Content.Client/Revenant/RevenantSystem.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Content.Client.Alerts;
using Content.Shared.Alert;
using Content.Shared.Revenant;
using Content.Shared.Revenant.Components;
using Robust.Client.GameObjects;
Expand Down Expand Up @@ -42,7 +41,7 @@ private void OnAppearanceChange(EntityUid uid, RevenantComponent component, ref

private void OnUpdateAlert(Entity<RevenantComponent> ent, ref UpdateAlertSpriteEvent args)
{
if (args.Alert.AlertType != AlertType.Essence)
if (args.Alert.ID != ent.Comp.EssenceAlert)
return;

var sprite = args.SpriteViewEnt.Comp;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Robust.Client.Player;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controllers;
using Robust.Shared.Prototypes;

namespace Content.Client.UserInterface.Systems.Alerts;

Expand Down Expand Up @@ -43,7 +44,7 @@ private void OnScreenLoad()
SyncAlerts();
}

private void OnAlertPressed(object? sender, AlertType e)
private void OnAlertPressed(object? sender, ProtoId<AlertPrototype> e)
{
_alertsSystem?.AlertClicked(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Input;
using Robust.Shared.Prototypes;

namespace Content.Client.UserInterface.Systems.Alerts.Widgets;

Expand All @@ -21,8 +22,10 @@ public AlertsUI()
RobustXamlLoader.Load(this);
}

public void SyncControls(AlertsSystem alertsSystem, AlertOrderPrototype? alertOrderPrototype,
IReadOnlyDictionary<AlertKey, AlertState> alertStates)
public void SyncControls(AlertsSystem alertsSystem,
AlertOrderPrototype? alertOrderPrototype,
IReadOnlyDictionary<AlertKey,
AlertState> alertStates)
{
// remove any controls with keys no longer present
if (SyncRemoveControls(alertStates))
Expand All @@ -46,7 +49,7 @@ public void ClearAllControls()
_alertControls.Clear();
}

public event EventHandler<AlertType>? AlertPressed;
public event EventHandler<ProtoId<AlertPrototype>>? AlertPressed;

private bool SyncRemoveControls(IReadOnlyDictionary<AlertKey, AlertState> alertStates)
{
Expand Down Expand Up @@ -88,7 +91,7 @@ private void SyncUpdateControls(AlertsSystem alertsSystem, AlertOrderPrototype?
}

if (_alertControls.TryGetValue(newAlert.AlertKey, out var existingAlertControl) &&
existingAlertControl.Alert.AlertType == newAlert.AlertType)
existingAlertControl.Alert.ID == newAlert.ID)
{
// key is the same, simply update the existing control severity / cooldown
existingAlertControl.SetSeverity(alertState.Severity);
Expand Down Expand Up @@ -155,6 +158,6 @@ private void AlertControlPressed(BaseButton.ButtonEventArgs args)
if (args.Event.Function != EngineKeyFunctions.UIClick)
return;

AlertPressed?.Invoke(this, control.Alert.AlertType);
AlertPressed?.Invoke(this, control.Alert.ID);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using Robust.Client.UserInterface;
using Robust.Server.Player;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;

namespace Content.IntegrationTests.Tests.GameObjects.Components.Mobs
{
Expand Down Expand Up @@ -45,8 +44,8 @@ await server.WaitAssertion(() =>
Assert.That(alerts, Is.Not.Null);
var alertCount = alerts.Count;

alertsSystem.ShowAlert(playerUid, AlertType.Debug1);
alertsSystem.ShowAlert(playerUid, AlertType.Debug2);
alertsSystem.ShowAlert(playerUid, "Debug1");
alertsSystem.ShowAlert(playerUid, "Debug2");

Assert.That(alerts, Has.Count.EqualTo(alertCount + 2));
});
Expand Down Expand Up @@ -87,14 +86,14 @@ static AlertsUI FindAlertsUI(Control control)
// we should be seeing 3 alerts - our health, and the 2 debug alerts, in a specific order.
Assert.That(clientAlertsUI.AlertContainer.ChildCount, Is.GreaterThanOrEqualTo(3));
var alertControls = clientAlertsUI.AlertContainer.Children.Select(c => (AlertControl) c);
var alertIDs = alertControls.Select(ac => ac.Alert.AlertType).ToArray();
var expectedIDs = new[] { AlertType.HumanHealth, AlertType.Debug1, AlertType.Debug2 };
var alertIDs = alertControls.Select(ac => ac.Alert.ID).ToArray();
var expectedIDs = new[] { "HumanHealth", "Debug1", "Debug2" };
Assert.That(alertIDs, Is.SupersetOf(expectedIDs));
});

await server.WaitAssertion(() =>
{
alertsSystem.ClearAlert(playerUid, AlertType.Debug1);
alertsSystem.ClearAlert(playerUid, "Debug1");
});

await pair.RunTicksSync(5);
Expand All @@ -104,8 +103,8 @@ await client.WaitAssertion(() =>
// we should be seeing 2 alerts now because one was cleared
Assert.That(clientAlertsUI.AlertContainer.ChildCount, Is.GreaterThanOrEqualTo(2));
var alertControls = clientAlertsUI.AlertContainer.Children.Select(c => (AlertControl) c);
var alertIDs = alertControls.Select(ac => ac.Alert.AlertType).ToArray();
var expectedIDs = new[] { AlertType.HumanHealth, AlertType.Debug2 };
var alertIDs = alertControls.Select(ac => ac.Alert.ID).ToArray();
var expectedIDs = new[] { "HumanHealth", "Debug2" };
Assert.That(alertIDs, Is.SupersetOf(expectedIDs));
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Content.Server.Gravity;
using Content.Shared.Alert;
using Content.Shared.Gravity;
using Robust.Shared.GameObjects;

namespace Content.IntegrationTests.Tests.Gravity
Expand Down Expand Up @@ -38,6 +39,7 @@ public async Task WeightlessStatusTest()

var entityManager = server.ResolveDependency<IEntityManager>();
var alertsSystem = server.ResolveDependency<IEntitySystemManager>().GetEntitySystem<AlertsSystem>();
var weightlessAlert = SharedGravitySystem.WeightlessAlert;

EntityUid human = default;

Expand All @@ -56,7 +58,7 @@ await server.WaitAssertion(() =>
await server.WaitAssertion(() =>
{
// No gravity without a gravity generator
Assert.That(alertsSystem.IsShowingAlert(human, AlertType.Weightless));
Assert.That(alertsSystem.IsShowingAlert(human, weightlessAlert));

generatorUid = entityManager.SpawnEntity("WeightlessGravityGeneratorDummy", entityManager.GetComponent<TransformComponent>(human).Coordinates);
});
Expand All @@ -66,7 +68,7 @@ await server.WaitAssertion(() =>

await server.WaitAssertion(() =>
{
Assert.That(alertsSystem.IsShowingAlert(human, AlertType.Weightless), Is.False);
Assert.That(alertsSystem.IsShowingAlert(human, weightlessAlert), Is.False);

// This should kill gravity
entityManager.DeleteEntity(generatorUid);
Expand All @@ -76,7 +78,7 @@ await server.WaitAssertion(() =>

await server.WaitAssertion(() =>
{
Assert.That(alertsSystem.IsShowingAlert(human, AlertType.Weightless));
Assert.That(alertsSystem.IsShowingAlert(human, weightlessAlert));
});

await pair.RunTicksSync(10);
Expand Down
8 changes: 8 additions & 0 deletions Content.Server/Abilities/Mime/MimePowersComponent.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Content.Shared.Alert;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
Expand Down Expand Up @@ -47,5 +48,12 @@ public sealed partial class MimePowersComponent : Component
/// </summary>
[DataField("vowCooldown")]
public TimeSpan VowCooldown = TimeSpan.FromMinutes(5);

[DataField]
public ProtoId<AlertPrototype> VowAlert = "VowOfSilence";

[DataField]
public ProtoId<AlertPrototype> VowBrokenAlert = "VowBroken";

}
}
11 changes: 5 additions & 6 deletions Content.Server/Abilities/Mime/MimePowersSystem.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Content.Server.Popups;
using Content.Server.Speech.Muting;
using Content.Shared.Actions;
using Content.Shared.Actions.Events;
using Content.Shared.Alert;
Expand Down Expand Up @@ -54,7 +53,7 @@ public override void Update(float frameTime)
private void OnComponentInit(EntityUid uid, MimePowersComponent component, ComponentInit args)
{
EnsureComp<MutedComponent>(uid);
_alertsSystem.ShowAlert(uid, AlertType.VowOfSilence);
_alertsSystem.ShowAlert(uid, component.VowAlert);
_actionsSystem.AddAction(uid, ref component.InvisibleWallActionEntity, component.InvisibleWallAction, uid);
}

Expand Down Expand Up @@ -115,8 +114,8 @@ public void BreakVow(EntityUid uid, MimePowersComponent? mimePowers = null)
mimePowers.VowBroken = true;
mimePowers.VowRepentTime = _timing.CurTime + mimePowers.VowCooldown;
RemComp<MutedComponent>(uid);
_alertsSystem.ClearAlert(uid, AlertType.VowOfSilence);
_alertsSystem.ShowAlert(uid, AlertType.VowBroken);
_alertsSystem.ClearAlert(uid, mimePowers.VowAlert);
_alertsSystem.ShowAlert(uid, mimePowers.VowBrokenAlert);
_actionsSystem.RemoveAction(uid, mimePowers.InvisibleWallActionEntity);
}

Expand All @@ -138,8 +137,8 @@ public void RetakeVow(EntityUid uid, MimePowersComponent? mimePowers = null)
mimePowers.ReadyToRepent = false;
mimePowers.VowBroken = false;
AddComp<MutedComponent>(uid);
_alertsSystem.ClearAlert(uid, AlertType.VowBroken);
_alertsSystem.ShowAlert(uid, AlertType.VowOfSilence);
_alertsSystem.ClearAlert(uid, mimePowers.VowAlert);
_alertsSystem.ShowAlert(uid, mimePowers.VowBrokenAlert);
_actionsSystem.AddAction(uid, ref mimePowers.InvisibleWallActionEntity, mimePowers.InvisibleWallAction, uid);
}
}
Expand Down
4 changes: 2 additions & 2 deletions Content.Server/Alert/Commands/ClearAlert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ public void Execute(IConsoleShell shell, string argStr, string[] args)

var alertType = args[0];
var alertsSystem = _e.System<AlertsSystem>();
if (!alertsSystem.TryGet(Enum.Parse<AlertType>(alertType), out var alert))
if (!alertsSystem.TryGet(alertType, out var alert))
{
shell.WriteLine("unrecognized alertType " + alertType);
return;
}

alertsSystem.ClearAlert(attachedEntity, alert.AlertType);
alertsSystem.ClearAlert(attachedEntity, alert.ID);
}
}
}
4 changes: 2 additions & 2 deletions Content.Server/Alert/Commands/ShowAlert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void Execute(IConsoleShell shell, string argStr, string[] args)
var alertType = args[0];
var severity = args[1];
var alertsSystem = _e.System<AlertsSystem>();
if (!alertsSystem.TryGet(Enum.Parse<AlertType>(alertType), out var alert))
if (!alertsSystem.TryGet(alertType, out var alert))
{
shell.WriteLine("unrecognized alertType " + alertType);
return;
Expand All @@ -53,7 +53,7 @@ public void Execute(IConsoleShell shell, string argStr, string[] args)
}

short? severity1 = sevint == -1 ? null : sevint;
alertsSystem.ShowAlert(attachedEntity, alert.AlertType, severity1, null);
alertsSystem.ShowAlert(attachedEntity, alert.ID, severity1, null);
}
}
}
10 changes: 10 additions & 0 deletions Content.Server/Atmos/Components/BarotraumaComponent.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using Content.Shared.Alert;
using Content.Shared.Damage;
using Content.Shared.FixedPoint;
using Robust.Shared.Prototypes;

namespace Content.Server.Atmos.Components
{
Expand Down Expand Up @@ -46,5 +48,13 @@ public sealed partial class BarotraumaComponent : Component
[ViewVariables(VVAccess.ReadWrite)]
public bool HasImmunity = false;

[DataField]
public ProtoId<AlertPrototype> HighPressureAlert = "HighPressure";

[DataField]
public ProtoId<AlertPrototype> LowPressureAlert = "LowPressure";

[DataField]
public ProtoId<AlertCategoryPrototype> PressureAlertCategory = "Pressure";
}
}
5 changes: 5 additions & 0 deletions Content.Server/Atmos/Components/FlammableComponent.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using Content.Shared.Alert;
using Content.Shared.Damage;
using Robust.Shared.Physics.Collision.Shapes;
using Robust.Shared.Prototypes;

namespace Content.Server.Atmos.Components
{
Expand Down Expand Up @@ -77,5 +79,8 @@ public sealed partial class FlammableComponent : Component
/// </summary>
[DataField, ViewVariables(VVAccess.ReadWrite)]
public float FirestackFade = -0.1f;

[DataField]
public ProtoId<AlertPrototype> FireAlert = "Fire";
}
}
10 changes: 5 additions & 5 deletions Content.Server/Atmos/EntitySystems/BarotraumaSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ public override void Update(float frameTime)
_adminLogger.Add(LogType.Barotrauma, $"{ToPrettyString(uid):entity} started taking low pressure damage");
}

_alertsSystem.ShowAlert(uid, AlertType.LowPressure, 2);
_alertsSystem.ShowAlert(uid, barotrauma.LowPressureAlert, 2);
}
else if (pressure >= Atmospherics.HazardHighPressure)
{
Expand All @@ -260,7 +260,7 @@ public override void Update(float frameTime)
_adminLogger.Add(LogType.Barotrauma, $"{ToPrettyString(uid):entity} started taking high pressure damage");
}

_alertsSystem.ShowAlert(uid, AlertType.HighPressure, 2);
_alertsSystem.ShowAlert(uid, barotrauma.HighPressureAlert, 2);
}
else
{
Expand All @@ -275,13 +275,13 @@ public override void Update(float frameTime)
switch (pressure)
{
case <= Atmospherics.WarningLowPressure:
_alertsSystem.ShowAlert(uid, AlertType.LowPressure, 1);
_alertsSystem.ShowAlert(uid, barotrauma.LowPressureAlert, 1);
break;
case >= Atmospherics.WarningHighPressure:
_alertsSystem.ShowAlert(uid, AlertType.HighPressure, 1);
_alertsSystem.ShowAlert(uid, barotrauma.HighPressureAlert, 1);
break;
default:
_alertsSystem.ClearAlertCategory(uid, AlertCategory.Pressure);
_alertsSystem.ClearAlertCategory(uid, barotrauma.PressureAlertCategory);
break;
}
}
Expand Down
4 changes: 2 additions & 2 deletions Content.Server/Atmos/EntitySystems/FlammableSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -415,11 +415,11 @@ public override void Update(float frameTime)

if (!flammable.OnFire)
{
_alertsSystem.ClearAlert(uid, AlertType.Fire);
_alertsSystem.ClearAlert(uid, flammable.FireAlert);
continue;
}

_alertsSystem.ShowAlert(uid, AlertType.Fire);
_alertsSystem.ShowAlert(uid, flammable.FireAlert);

if (flammable.FireStacks > 0)
{
Expand Down
4 changes: 4 additions & 0 deletions Content.Server/Body/Components/BloodstreamComponent.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Content.Server.Body.Systems;
using Content.Server.Chemistry.EntitySystems;
using Content.Shared.Alert;
using Content.Shared.Chemistry.Components;
using Content.Shared.Chemistry.Reagent;
using Content.Shared.Damage;
Expand Down Expand Up @@ -171,5 +172,8 @@ public sealed partial class BloodstreamComponent : Component
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
public TimeSpan StatusTime;

[DataField]
public ProtoId<AlertPrototype> BleedingAlert = "Bleed";
}
}
6 changes: 6 additions & 0 deletions Content.Server/Body/Components/InternalsComponent.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
using Content.Shared.Alert;
using Robust.Shared.Prototypes;

namespace Content.Server.Body.Components
{
/// <summary>
Expand All @@ -18,5 +21,8 @@ public sealed partial class InternalsComponent : Component
[ViewVariables(VVAccess.ReadWrite)]
[DataField]
public TimeSpan Delay = TimeSpan.FromSeconds(3);

[DataField]
public ProtoId<AlertPrototype> InternalsAlert = "Internals";
}
}
Loading

0 comments on commit 8a95cb1

Please sign in to comment.