Hallway textscreens (#24189)

* hallway screen refactor pending comms console support

* comms console broadcasts

* screen and timer localization
This commit is contained in:
avery
2024-01-27 05:51:24 -08:00
committed by GitHub
parent a923beb21b
commit 7e16ee0b55
23 changed files with 318 additions and 142 deletions

View File

@@ -1,24 +0,0 @@
namespace Content.Server.Shuttles.Components;
[RegisterComponent]
public sealed partial class ShuttleTimerComponent : Component
{
}
/// <summary>
/// Awkward hashable string consts because NetworkPayload requires string keys
/// TODO: Refactor NetworkPayload to accept bytes from enums?
/// </summary>
public sealed class ShuttleTimerMasks
{
public static readonly string ShuttleTime = "ShuttleTime";
public static readonly string DestTime = "DestTime";
public static readonly string SourceTime = "SourceTime";
public static readonly string ShuttleMap = "ShuttleMap";
public static readonly string SourceMap = "SourceMap";
public static readonly string DestMap = "DestMap";
public static readonly string Docked = "Docked";
public static readonly string Text = "Text";
}

View File

@@ -8,6 +8,7 @@ using Content.Server.DeviceNetwork;
using Content.Server.DeviceNetwork.Components;
using Content.Server.DeviceNetwork.Systems;
using Content.Server.Salvage;
using Content.Server.Screens.Components;
using Content.Server.Shuttles.Components;
using Content.Server.Shuttles.Events;
using Content.Server.Spawners.Components;

View File

@@ -1,6 +1,7 @@
using System.Threading;
using Content.Server.DeviceNetwork;
using Content.Server.DeviceNetwork.Components;
using Content.Server.Screens.Components;
using Content.Server.Shuttles.Components;
using Content.Server.Shuttles.Events;
using Content.Server.UserInterface;

View File

@@ -11,6 +11,7 @@ using Content.Server.DeviceNetwork.Systems;
using Content.Server.GameTicking.Events;
using Content.Server.Popups;
using Content.Server.RoundEnd;
using Content.Server.Screens.Components;
using Content.Server.Shuttles.Components;
using Content.Server.Shuttles.Events;
using Content.Server.Station.Components;
@@ -235,8 +236,18 @@ public sealed partial class EmergencyShuttleSystem : EntitySystem
[ShuttleTimerMasks.ShuttleTime] = countdownTime,
[ShuttleTimerMasks.SourceTime] = countdownTime,
[ShuttleTimerMasks.DestTime] = countdownTime,
[ShuttleTimerMasks.Text] = new string?[] { "BYE!" }
};
// by popular request
// https://discord.com/channels/310555209753690112/770682801607278632/1189989482234126356
if (_random.Next(1000) == 0)
{
payload.Add(ScreenMasks.Text, ShuttleTimerMasks.Kill);
payload.Add(ScreenMasks.Color, Color.Red);
}
else
payload.Add(ScreenMasks.Text, ShuttleTimerMasks.Bye);
_deviceNetworkSystem.QueuePacket(shuttle, null, payload, net.TransmitFrequency);
}
}

View File

@@ -1,69 +0,0 @@
using Content.Shared.TextScreen;
using Content.Server.Shuttles.Components;
using Content.Server.DeviceNetwork.Systems;
using Robust.Shared.Timing;
namespace Content.Server.Shuttles.Systems;
/// <summary>
/// Controls the wallmounted screens on stations and shuttles displaying e.g. FTL duration, ETA
/// </summary>
public sealed class ShuttleTimerSystem : EntitySystem
{
[Dependency] private readonly IGameTiming _gameTiming = default!;
[Dependency] private readonly SharedAppearanceSystem _appearanceSystem = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<ShuttleTimerComponent, DeviceNetworkPacketEvent>(OnPacketReceived);
}
/// <summary>
/// Determines if/how a broadcast packet affects this timer.
/// All shuttle timer packets are broadcast in their network, and subnetting is implemented by filtering timer MapUid.
/// </summary>
private void OnPacketReceived(EntityUid uid, ShuttleTimerComponent component, DeviceNetworkPacketEvent args)
{
var timerXform = Transform(uid);
// no false positives.
if (timerXform.MapUid == null)
return;
string key;
args.Data.TryGetValue(ShuttleTimerMasks.ShuttleMap, out EntityUid? shuttleMap);
args.Data.TryGetValue(ShuttleTimerMasks.SourceMap, out EntityUid? source);
args.Data.TryGetValue(ShuttleTimerMasks.DestMap, out EntityUid? dest);
args.Data.TryGetValue(ShuttleTimerMasks.Docked, out bool docked);
string?[] text = new string?[] { docked ? Loc.GetString("shuttle-timer-etd") : Loc.GetString("shuttle-timer-eta")};
switch (timerXform.MapUid)
{
// sometimes the timer transforms on FTL shuttles have a hyperspace mapuid, so matching by grid works as a fallback.
case var local when local == shuttleMap || timerXform.GridUid == shuttleMap:
key = ShuttleTimerMasks.ShuttleTime;
break;
case var origin when origin == source:
key = ShuttleTimerMasks.SourceTime;
break;
case var remote when remote == dest:
key = ShuttleTimerMasks.DestTime;
text = new string?[] { Loc.GetString("shuttle-timer-eta") };
break;
default:
return;
}
if (!args.Data.TryGetValue(key, out TimeSpan duration))
return;
if (args.Data.TryGetValue(ShuttleTimerMasks.Text, out string?[]? label))
text = label;
_appearanceSystem.SetData(uid, TextScreenVisuals.TargetTime, _gameTiming.CurTime + duration);
_appearanceSystem.SetData(uid, TextScreenVisuals.ScreenText, text);
}
}