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:
@@ -20,7 +20,7 @@ public sealed class ZoomCommand : LocalizedCommands
|
|||||||
public override void Execute(IConsoleShell shell, string argStr, string[] args)
|
public override void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||||
{
|
{
|
||||||
Vector2 zoom;
|
Vector2 zoom;
|
||||||
if (args.Length is not (1 or 2))
|
if (args.Length is not (1 or 2 or 3))
|
||||||
{
|
{
|
||||||
shell.WriteLine(Help);
|
shell.WriteLine(Help);
|
||||||
return;
|
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;
|
var player = _playerManager.LocalSession?.AttachedEntity;
|
||||||
|
|
||||||
if (_entityManager.TryGetComponent<ContentEyeComponent>(player, out var content))
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ public sealed class ContentEyeSystem : SharedContentEyeSystem
|
|||||||
{
|
{
|
||||||
[Dependency] private readonly IPlayerManager _player = default!;
|
[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))
|
if (!Resolve(uid, ref content, false))
|
||||||
return;
|
return;
|
||||||
@@ -19,6 +19,14 @@ public sealed class ContentEyeSystem : SharedContentEyeSystem
|
|||||||
TargetZoom = zoom,
|
TargetZoom = zoom,
|
||||||
IgnoreLimit = ignoreLimit,
|
IgnoreLimit = ignoreLimit,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (scalePvs)
|
||||||
|
RequestPvsScale(Math.Max(zoom.X, zoom.Y));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void RequestPvsScale(float scale)
|
||||||
|
{
|
||||||
|
RaiseNetworkEvent(new RequestPvsScaleEvent(scale));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RequestToggleFov()
|
public void RequestToggleFov()
|
||||||
|
|||||||
@@ -7,12 +7,19 @@ namespace Content.Shared.Camera;
|
|||||||
[NetworkedComponent]
|
[NetworkedComponent]
|
||||||
public sealed partial class CameraRecoilComponent : Component
|
public sealed partial class CameraRecoilComponent : Component
|
||||||
{
|
{
|
||||||
|
[ViewVariables(VVAccess.ReadWrite)]
|
||||||
public Vector2 CurrentKick { get; set; }
|
public Vector2 CurrentKick { get; set; }
|
||||||
|
|
||||||
|
[ViewVariables(VVAccess.ReadWrite)]
|
||||||
public Vector2 LastKick { get; set; }
|
public Vector2 LastKick { get; set; }
|
||||||
|
|
||||||
|
[ViewVariables(VVAccess.ReadWrite)]
|
||||||
public float LastKickTime { get; set; }
|
public float LastKickTime { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Basically I needed a way to chain this effect for the attack lunge animation. Sorry!
|
/// Basically I needed a way to chain this effect for the attack lunge animation. Sorry!
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
///
|
||||||
|
[ViewVariables(VVAccess.ReadWrite)]
|
||||||
public Vector2 BaseOffset { get; set; }
|
public Vector2 BaseOffset { get; set; }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,9 +52,9 @@ public abstract class SharedCameraRecoilSystem : EntitySystem
|
|||||||
|
|
||||||
private void UpdateEyes(float frameTime)
|
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();
|
var magnitude = recoil.CurrentKick.Length();
|
||||||
if (magnitude <= 0.005f)
|
if (magnitude <= 0.005f)
|
||||||
|
|||||||
@@ -18,6 +18,9 @@ public abstract class SharedContentEyeSystem : EntitySystem
|
|||||||
{
|
{
|
||||||
[Dependency] private readonly ISharedAdminManager _admin = default!;
|
[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 const float ZoomMod = 1.5f;
|
||||||
public static readonly Vector2 DefaultZoom = Vector2.One;
|
public static readonly Vector2 DefaultZoom = Vector2.One;
|
||||||
public static readonly Vector2 MinZoom = DefaultZoom * (float)Math.Pow(ZoomMod, -3);
|
public static readonly Vector2 MinZoom = DefaultZoom * (float)Math.Pow(ZoomMod, -3);
|
||||||
@@ -29,6 +32,7 @@ public abstract class SharedContentEyeSystem : EntitySystem
|
|||||||
base.Initialize();
|
base.Initialize();
|
||||||
SubscribeLocalEvent<ContentEyeComponent, ComponentStartup>(OnContentEyeStartup);
|
SubscribeLocalEvent<ContentEyeComponent, ComponentStartup>(OnContentEyeStartup);
|
||||||
SubscribeAllEvent<RequestTargetZoomEvent>(OnContentZoomRequest);
|
SubscribeAllEvent<RequestTargetZoomEvent>(OnContentZoomRequest);
|
||||||
|
SubscribeAllEvent<RequestPvsScaleEvent>(OnPvsScale);
|
||||||
SubscribeAllEvent<RequestEyeEvent>(OnRequestEye);
|
SubscribeAllEvent<RequestEyeEvent>(OnRequestEye);
|
||||||
|
|
||||||
CommandBinds.Builder
|
CommandBinds.Builder
|
||||||
@@ -84,12 +88,18 @@ public abstract class SharedContentEyeSystem : EntitySystem
|
|||||||
|
|
||||||
private void OnContentZoomRequest(RequestTargetZoomEvent msg, EntitySessionEventArgs args)
|
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))
|
if (TryComp<ContentEyeComponent>(args.SenderSession.AttachedEntity, out var content))
|
||||||
SetZoom(args.SenderSession.AttachedEntity.Value, msg.TargetZoom, ignoreLimit, eye: 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)
|
private void OnRequestEye(RequestEyeEvent msg, EntitySessionEventArgs args)
|
||||||
{
|
{
|
||||||
if (args.SenderSession.AttachedEntity is not { } player)
|
if (args.SenderSession.AttachedEntity is not { } player)
|
||||||
@@ -116,6 +126,7 @@ public abstract class SharedContentEyeSystem : EntitySystem
|
|||||||
|
|
||||||
public void ResetZoom(EntityUid uid, ContentEyeComponent? component = null)
|
public void ResetZoom(EntityUid uid, ContentEyeComponent? component = null)
|
||||||
{
|
{
|
||||||
|
_eye.SetPvsScale(uid, 1);
|
||||||
SetZoom(uid, DefaultZoom, eye: component);
|
SetZoom(uid, DefaultZoom, eye: component);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -146,6 +157,15 @@ public abstract class SharedContentEyeSystem : EntitySystem
|
|||||||
public bool IgnoreLimit;
|
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>
|
/// <summary>
|
||||||
/// Sendable from client to server to request changing fov.
|
/// Sendable from client to server to request changing fov.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
cmd-zoom-desc = Sets the zoom of the main eye.
|
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> )
|
cmd-zoom-help = zoom ( <scale> | <X-scale> <Y-scale> [bool])
|
||||||
cmd-zoom-error = scale has to be greater than 0
|
cmd-zoom-error = scale has to be greater than 0
|
||||||
|
|||||||
Reference in New Issue
Block a user