Fix replay spectating bugs (#21573)
This commit is contained in:
@@ -3,6 +3,7 @@ using Content.Client.Replay.UI;
|
||||
using Content.Shared.Verbs;
|
||||
using Robust.Shared.Console;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Client.Replay.Spectator;
|
||||
@@ -15,19 +16,13 @@ public sealed partial class ReplaySpectatorSystem
|
||||
if (_replayPlayback.Replay == null)
|
||||
return;
|
||||
|
||||
var verb = new AlternativeVerb
|
||||
ev.Verbs.Add(new AlternativeVerb
|
||||
{
|
||||
Priority = 100,
|
||||
Act = () =>
|
||||
{
|
||||
SpectateEntity(ev.Target);
|
||||
},
|
||||
|
||||
Act = () => SpectateEntity(ev.Target),
|
||||
Text = Loc.GetString("replay-verb-spectate"),
|
||||
Icon = new SpriteSpecifier.Texture(new ResPath("/Textures/Interface/VerbIcons/vv.svg.192dpi.png"))
|
||||
};
|
||||
|
||||
ev.Verbs.Add(verb);
|
||||
});
|
||||
}
|
||||
|
||||
public void SpectateEntity(EntityUid target)
|
||||
@@ -35,7 +30,7 @@ public sealed partial class ReplaySpectatorSystem
|
||||
if (_player.LocalSession == null)
|
||||
return;
|
||||
|
||||
var old = _player.LocalSession.AttachedEntity;
|
||||
var old = _player.LocalEntity;
|
||||
|
||||
if (old == target)
|
||||
{
|
||||
@@ -44,8 +39,11 @@ public sealed partial class ReplaySpectatorSystem
|
||||
return;
|
||||
}
|
||||
|
||||
_player.SetAttachedEntity(_player.LocalSession, target);
|
||||
EnsureComp<ReplaySpectatorComponent>(target);
|
||||
if (TryComp(target, out ActorComponent? actor))
|
||||
_player.SetLocalSession(actor.PlayerSession);
|
||||
else
|
||||
_player.SetAttachedEntity(_player.LocalSession, target);
|
||||
|
||||
_stateMan.RequestStateChange<ReplaySpectateEntityState>();
|
||||
if (old == null)
|
||||
@@ -59,10 +57,9 @@ public sealed partial class ReplaySpectatorSystem
|
||||
|
||||
public TransformComponent SpawnSpectatorGhost(EntityCoordinates coords, bool gridAttach)
|
||||
{
|
||||
if (_player.LocalSession == null)
|
||||
throw new InvalidOperationException();
|
||||
|
||||
var old = _player.LocalSession.AttachedEntity;
|
||||
var old = _player.LocalEntity;
|
||||
var session = _player.GetSessionById(DefaultUser);
|
||||
_player.SetLocalSession(session);
|
||||
|
||||
var ent = Spawn("ReplayObserver", coords);
|
||||
_eye.SetMaxZoom(ent, Vector2.One * 5);
|
||||
@@ -73,7 +70,7 @@ public sealed partial class ReplaySpectatorSystem
|
||||
if (gridAttach)
|
||||
_transform.AttachToGridOrMap(ent);
|
||||
|
||||
_player.SetAttachedEntity(_player.LocalSession, ent);
|
||||
_player.SetAttachedEntity(session, ent);
|
||||
|
||||
if (old != null)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user