Alert level reloads (#8530)
* adds prototype reload for AlertLevelSystem, reorganizes selectable alerts a bit * makes alert levels not necessarily require localization * oops * sus * does the same for announcements as well * oh, that's not how that works at all * ok, NOW it works * fixes localization, adds event for when alerts are reloaded * addresses review
This commit is contained in:
@@ -22,6 +22,15 @@ public sealed class AlertLevelSystem : EntitySystem
|
||||
public override void Initialize()
|
||||
{
|
||||
SubscribeLocalEvent<StationInitializedEvent>(OnStationInitialize);
|
||||
|
||||
_prototypeManager.PrototypesReloaded += OnPrototypeReload;
|
||||
}
|
||||
|
||||
public override void Shutdown()
|
||||
{
|
||||
base.Shutdown();
|
||||
|
||||
_prototypeManager.PrototypesReloaded -= OnPrototypeReload;
|
||||
}
|
||||
|
||||
public override void Update(float time)
|
||||
@@ -67,6 +76,34 @@ public sealed class AlertLevelSystem : EntitySystem
|
||||
SetLevel(args.Station, defaultLevel, false, false, true);
|
||||
}
|
||||
|
||||
private void OnPrototypeReload(PrototypesReloadedEventArgs args)
|
||||
{
|
||||
if (!args.ByType.TryGetValue(typeof(AlertLevelPrototype), out var alertPrototypes)
|
||||
|| !alertPrototypes.Modified.TryGetValue(DefaultAlertLevelSet, out var alertObject)
|
||||
|| alertObject is not AlertLevelPrototype alerts)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var comp in EntityQuery<AlertLevelComponent>())
|
||||
{
|
||||
comp.AlertLevels = alerts;
|
||||
|
||||
if (!comp.AlertLevels.Levels.ContainsKey(comp.CurrentLevel))
|
||||
{
|
||||
var defaultLevel = comp.AlertLevels.DefaultLevel;
|
||||
if (string.IsNullOrEmpty(defaultLevel))
|
||||
{
|
||||
defaultLevel = comp.AlertLevels.Levels.Keys.First();
|
||||
}
|
||||
|
||||
SetLevel(comp.Owner, defaultLevel, true, true, true);
|
||||
}
|
||||
}
|
||||
|
||||
RaiseLocalEvent(new AlertLevelPrototypeReloadedEvent());
|
||||
}
|
||||
|
||||
public float GetAlertLevelDelay(EntityUid station, AlertLevelComponent? alert = null)
|
||||
{
|
||||
if (!Resolve(station, ref alert))
|
||||
@@ -115,10 +152,20 @@ public sealed class AlertLevelSystem : EntitySystem
|
||||
|
||||
var stationName = dataComponent.EntityName;
|
||||
|
||||
var name = Loc.GetString($"alert-level-{level}").ToLower();
|
||||
var name = level.ToLower();
|
||||
|
||||
if (Loc.TryGetString($"alert-level-{level}", out var locName))
|
||||
{
|
||||
name = locName.ToLower();
|
||||
}
|
||||
|
||||
// Announcement text. Is passed into announcementFull.
|
||||
var announcement = Loc.GetString(detail.Announcement);
|
||||
var announcement = detail.Announcement;
|
||||
|
||||
if (Loc.TryGetString(detail.Announcement, out var locAnnouncement))
|
||||
{
|
||||
announcement = locAnnouncement;
|
||||
}
|
||||
|
||||
// The full announcement to be spat out into chat.
|
||||
var announcementFull = Loc.GetString("alert-level-announcement", ("name", name), ("announcement", announcement));
|
||||
@@ -150,6 +197,9 @@ public sealed class AlertLevelSystem : EntitySystem
|
||||
public sealed class AlertLevelDelayFinishedEvent : EntityEventArgs
|
||||
{}
|
||||
|
||||
public sealed class AlertLevelPrototypeReloadedEvent : EntityEventArgs
|
||||
{}
|
||||
|
||||
public sealed class AlertLevelChangedEvent : EntityEventArgs
|
||||
{
|
||||
public string AlertLevel { get; }
|
||||
|
||||
Reference in New Issue
Block a user