Add support for client-side replays (#17168)

This commit is contained in:
Leon Friedrich
2023-06-19 05:23:31 +12:00
committed by GitHub
parent cc81a7511b
commit b03d9a90ab
22 changed files with 183 additions and 91 deletions

View File

@@ -11,6 +11,7 @@ using Robust.Shared.Map;
using Robust.Shared.Player;
using Robust.Shared.Players;
using Robust.Shared.Prototypes;
using Robust.Shared.Replays;
using Robust.Shared.Timing;
using Robust.Shared.Utility;
@@ -26,6 +27,7 @@ namespace Content.Client.Popups
[Dependency] private readonly IResourceCache _resource = default!;
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly IUserInterfaceManager _uiManager = default!;
[Dependency] private readonly IReplayRecordingManager _replayRecording = default!;
public IReadOnlyList<WorldPopupLabel> WorldLabels => _aliveWorldLabels;
public IReadOnlyList<CursorPopupLabel> CursorLabels => _aliveCursorLabels;
@@ -52,8 +54,16 @@ namespace Content.Client.Popups
.RemoveOverlay<PopupOverlay>();
}
private void PopupMessage(string message, PopupType type, EntityCoordinates coordinates, EntityUid? entity = null)
private void PopupMessage(string message, PopupType type, EntityCoordinates coordinates, EntityUid? entity, bool recordReplay)
{
if (recordReplay && _replayRecording.IsRecording)
{
if (entity != null)
_replayRecording.RecordClientMessage(new PopupEntityEvent(message, type, entity.Value));
else
_replayRecording.RecordClientMessage(new PopupCoordinatesEvent(message, type, coordinates));
}
var label = new WorldPopupLabel(coordinates)
{
Text = message,
@@ -66,23 +76,26 @@ namespace Content.Client.Popups
#region Abstract Method Implementations
public override void PopupCoordinates(string message, EntityCoordinates coordinates, PopupType type = PopupType.Small)
{
PopupMessage(message, type, coordinates, null);
PopupMessage(message, type, coordinates, null, true);
}
public override void PopupCoordinates(string message, EntityCoordinates coordinates, ICommonSession recipient, PopupType type = PopupType.Small)
{
if (_playerManager.LocalPlayer?.Session == recipient)
PopupMessage(message, type, coordinates, null);
PopupMessage(message, type, coordinates, null, true);
}
public override void PopupCoordinates(string message, EntityCoordinates coordinates, EntityUid recipient, PopupType type = PopupType.Small)
{
if (_playerManager.LocalPlayer?.ControlledEntity == recipient)
PopupMessage(message, type, coordinates, null);
PopupMessage(message, type, coordinates, null, true);
}
public override void PopupCursor(string message, PopupType type = PopupType.Small)
private void PopupCursorInternal(string message, PopupType type, bool recordReplay)
{
if (recordReplay && _replayRecording.IsRecording)
_replayRecording.RecordClientMessage(new PopupCursorEvent(message, type));
var label = new CursorPopupLabel(_inputManager.MouseScreenPosition)
{
Text = message,
@@ -92,6 +105,9 @@ namespace Content.Client.Popups
_aliveCursorLabels.Add(label);
}
public override void PopupCursor(string message, PopupType type = PopupType.Small)
=> PopupCursorInternal(message, type, true);
public override void PopupCursor(string message, ICommonSession recipient, PopupType type = PopupType.Small)
{
if (_playerManager.LocalPlayer?.Session == recipient)
@@ -137,12 +153,8 @@ namespace Content.Client.Popups
public override void PopupEntity(string message, EntityUid uid, PopupType type = PopupType.Small)
{
if (!EntityManager.EntityExists(uid))
return;
var transform = EntityManager.GetComponent<TransformComponent>(uid);
PopupMessage(message, type, transform.Coordinates, uid);
if (TryComp(uid, out TransformComponent? transform))
PopupMessage(message, type, transform.Coordinates, uid, true);
}
#endregion
@@ -151,17 +163,18 @@ namespace Content.Client.Popups
private void OnPopupCursorEvent(PopupCursorEvent ev)
{
PopupCursor(ev.Message, ev.Type);
PopupCursorInternal(ev.Message, ev.Type, false);
}
private void OnPopupCoordinatesEvent(PopupCoordinatesEvent ev)
{
PopupCoordinates(ev.Message, ev.Coordinates, ev.Type);
PopupMessage(ev.Message, ev.Type, ev.Coordinates, null, false);
}
private void OnPopupEntityEvent(PopupEntityEvent ev)
{
PopupEntity(ev.Message, ev.Uid, ev.Type);
if (TryComp(ev.Uid, out TransformComponent? transform))
PopupMessage(ev.Message, ev.Type, transform.Coordinates, ev.Uid, false);
}
private void OnRoundRestart(RoundRestartCleanupEvent ev)