Allow zoom command to modify an eye's PVS range (#29245)

Allow zoom command to modify an eye's PVS range

Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
This commit is contained in:
Leon Friedrich
2024-07-03 18:44:55 +12:00
committed by GitHub
parent a2a3233f5e
commit 1faa1b5df6
6 changed files with 50 additions and 8 deletions

View File

@@ -20,7 +20,7 @@ public sealed class ZoomCommand : LocalizedCommands
public override void Execute(IConsoleShell shell, string argStr, string[] args)
{
Vector2 zoom;
if (args.Length is not (1 or 2))
if (args.Length is not (1 or 2 or 3))
{
shell.WriteLine(Help);
return;
@@ -57,11 +57,18 @@ public sealed class ZoomCommand : LocalizedCommands
}
}
var scalePvs = true;
if (args.Length == 3 && !bool.TryParse(args[2], out scalePvs))
{
shell.WriteError(LocalizationManager.GetString("cmd-parse-failure-bool", ("arg", args[2])));
return;
}
var player = _playerManager.LocalSession?.AttachedEntity;
if (_entityManager.TryGetComponent<ContentEyeComponent>(player, out var content))
{
_entityManager.System<ContentEyeSystem>().RequestZoom(player.Value, zoom, true, content);
_entityManager.System<ContentEyeSystem>().RequestZoom(player.Value, zoom, true, scalePvs, content);
return;
}

View File

@@ -9,7 +9,7 @@ public sealed class ContentEyeSystem : SharedContentEyeSystem
{
[Dependency] private readonly IPlayerManager _player = default!;
public void RequestZoom(EntityUid uid, Vector2 zoom, bool ignoreLimit, ContentEyeComponent? content = null)
public void RequestZoom(EntityUid uid, Vector2 zoom, bool ignoreLimit, bool scalePvs, ContentEyeComponent? content = null)
{
if (!Resolve(uid, ref content, false))
return;
@@ -19,6 +19,14 @@ public sealed class ContentEyeSystem : SharedContentEyeSystem
TargetZoom = zoom,
IgnoreLimit = ignoreLimit,
});
if (scalePvs)
RequestPvsScale(Math.Max(zoom.X, zoom.Y));
}
public void RequestPvsScale(float scale)
{
RaiseNetworkEvent(new RequestPvsScaleEvent(scale));
}
public void RequestToggleFov()

View File

@@ -7,12 +7,19 @@ namespace Content.Shared.Camera;
[NetworkedComponent]
public sealed partial class CameraRecoilComponent : Component
{
[ViewVariables(VVAccess.ReadWrite)]
public Vector2 CurrentKick { get; set; }
[ViewVariables(VVAccess.ReadWrite)]
public Vector2 LastKick { get; set; }
[ViewVariables(VVAccess.ReadWrite)]
public float LastKickTime { get; set; }
/// <summary>
/// Basically I needed a way to chain this effect for the attack lunge animation. Sorry!
/// </summary>
///
[ViewVariables(VVAccess.ReadWrite)]
public Vector2 BaseOffset { get; set; }
}

View File

@@ -52,9 +52,9 @@ public abstract class SharedCameraRecoilSystem : EntitySystem
private void UpdateEyes(float frameTime)
{
var query = AllEntityQuery<EyeComponent, CameraRecoilComponent>();
var query = AllEntityQuery<CameraRecoilComponent, EyeComponent>();
while (query.MoveNext(out var uid, out var eye, out var recoil))
while (query.MoveNext(out var uid, out var recoil, out var eye))
{
var magnitude = recoil.CurrentKick.Length();
if (magnitude <= 0.005f)

View File

@@ -18,6 +18,9 @@ public abstract class SharedContentEyeSystem : EntitySystem
{
[Dependency] private readonly ISharedAdminManager _admin = default!;
// Admin flags required to ignore normal eye restrictions.
public const AdminFlags EyeFlag = AdminFlags.Debug;
public const float ZoomMod = 1.5f;
public static readonly Vector2 DefaultZoom = Vector2.One;
public static readonly Vector2 MinZoom = DefaultZoom * (float)Math.Pow(ZoomMod, -3);
@@ -29,6 +32,7 @@ public abstract class SharedContentEyeSystem : EntitySystem
base.Initialize();
SubscribeLocalEvent<ContentEyeComponent, ComponentStartup>(OnContentEyeStartup);
SubscribeAllEvent<RequestTargetZoomEvent>(OnContentZoomRequest);
SubscribeAllEvent<RequestPvsScaleEvent>(OnPvsScale);
SubscribeAllEvent<RequestEyeEvent>(OnRequestEye);
CommandBinds.Builder
@@ -84,12 +88,18 @@ public abstract class SharedContentEyeSystem : EntitySystem
private void OnContentZoomRequest(RequestTargetZoomEvent msg, EntitySessionEventArgs args)
{
var ignoreLimit = msg.IgnoreLimit && _admin.HasAdminFlag(args.SenderSession, AdminFlags.Debug);
var ignoreLimit = msg.IgnoreLimit && _admin.HasAdminFlag(args.SenderSession, EyeFlag);
if (TryComp<ContentEyeComponent>(args.SenderSession.AttachedEntity, out var content))
SetZoom(args.SenderSession.AttachedEntity.Value, msg.TargetZoom, ignoreLimit, eye: content);
}
private void OnPvsScale(RequestPvsScaleEvent ev, EntitySessionEventArgs args)
{
if (args.SenderSession.AttachedEntity is {} uid && _admin.HasAdminFlag(args.SenderSession, EyeFlag))
_eye.SetPvsScale(uid, ev.Scale);
}
private void OnRequestEye(RequestEyeEvent msg, EntitySessionEventArgs args)
{
if (args.SenderSession.AttachedEntity is not { } player)
@@ -116,6 +126,7 @@ public abstract class SharedContentEyeSystem : EntitySystem
public void ResetZoom(EntityUid uid, ContentEyeComponent? component = null)
{
_eye.SetPvsScale(uid, 1);
SetZoom(uid, DefaultZoom, eye: component);
}
@@ -146,6 +157,15 @@ public abstract class SharedContentEyeSystem : EntitySystem
public bool IgnoreLimit;
}
/// <summary>
/// Client->Server request for new PVS scale.
/// </summary>
[Serializable, NetSerializable]
public sealed class RequestPvsScaleEvent(float scale) : EntityEventArgs
{
public float Scale = scale;
}
/// <summary>
/// Sendable from client to server to request changing fov.
/// </summary>

View File

@@ -1,3 +1,3 @@
cmd-zoom-desc = Sets the zoom of the main eye.
cmd-zoom-help = zoom ( <scale> | <X-scale> <Y-scale> )
cmd-zoom-desc = Sets the zoom of the main eye. Optionally also changes the eye's PVS range.
cmd-zoom-help = zoom ( <scale> | <X-scale> <Y-scale> [bool])
cmd-zoom-error = scale has to be greater than 0