Skip to content

Commit 3934fb9

Browse files
ElectroJrmetalgearsloth
authored and
deltanedas
committed
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 <[email protected]>
1 parent 7ca7aac commit 3934fb9

File tree

6 files changed

+50
-8
lines changed

6 files changed

+50
-8
lines changed

Content.Client/Commands/ZoomCommand.cs

+9-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public sealed class ZoomCommand : LocalizedCommands
2020
public override void Execute(IConsoleShell shell, string argStr, string[] args)
2121
{
2222
Vector2 zoom;
23-
if (args.Length is not (1 or 2))
23+
if (args.Length is not (1 or 2 or 3))
2424
{
2525
shell.WriteLine(Help);
2626
return;
@@ -57,11 +57,18 @@ public override void Execute(IConsoleShell shell, string argStr, string[] args)
5757
}
5858
}
5959

60+
var scalePvs = true;
61+
if (args.Length == 3 && !bool.TryParse(args[2], out scalePvs))
62+
{
63+
shell.WriteError(LocalizationManager.GetString("cmd-parse-failure-bool", ("arg", args[2])));
64+
return;
65+
}
66+
6067
var player = _playerManager.LocalSession?.AttachedEntity;
6168

6269
if (_entityManager.TryGetComponent<ContentEyeComponent>(player, out var content))
6370
{
64-
_entityManager.System<ContentEyeSystem>().RequestZoom(player.Value, zoom, true, content);
71+
_entityManager.System<ContentEyeSystem>().RequestZoom(player.Value, zoom, true, scalePvs, content);
6572
return;
6673
}
6774

Content.Client/Movement/Systems/ContentEyeSystem.cs

+9-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public sealed class ContentEyeSystem : SharedContentEyeSystem
99
{
1010
[Dependency] private readonly IPlayerManager _player = default!;
1111

12-
public void RequestZoom(EntityUid uid, Vector2 zoom, bool ignoreLimit, ContentEyeComponent? content = null)
12+
public void RequestZoom(EntityUid uid, Vector2 zoom, bool ignoreLimit, bool scalePvs, ContentEyeComponent? content = null)
1313
{
1414
if (!Resolve(uid, ref content, false))
1515
return;
@@ -19,6 +19,14 @@ public void RequestZoom(EntityUid uid, Vector2 zoom, bool ignoreLimit, ContentEy
1919
TargetZoom = zoom,
2020
IgnoreLimit = ignoreLimit,
2121
});
22+
23+
if (scalePvs)
24+
RequestPvsScale(Math.Max(zoom.X, zoom.Y));
25+
}
26+
27+
public void RequestPvsScale(float scale)
28+
{
29+
RaiseNetworkEvent(new RequestPvsScaleEvent(scale));
2230
}
2331

2432
public void RequestToggleFov()

Content.Shared/Camera/CameraRecoilComponent.cs

+7
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,19 @@ namespace Content.Shared.Camera;
77
[NetworkedComponent]
88
public sealed partial class CameraRecoilComponent : Component
99
{
10+
[ViewVariables(VVAccess.ReadWrite)]
1011
public Vector2 CurrentKick { get; set; }
12+
13+
[ViewVariables(VVAccess.ReadWrite)]
1114
public Vector2 LastKick { get; set; }
15+
16+
[ViewVariables(VVAccess.ReadWrite)]
1217
public float LastKickTime { get; set; }
1318

1419
/// <summary>
1520
/// Basically I needed a way to chain this effect for the attack lunge animation. Sorry!
1621
/// </summary>
22+
///
23+
[ViewVariables(VVAccess.ReadWrite)]
1724
public Vector2 BaseOffset { get; set; }
1825
}

Content.Shared/Camera/SharedCameraRecoilSystem.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ private void OnCameraRecoilGetEyeOffset(Entity<CameraRecoilComponent> ent, ref G
5252

5353
private void UpdateEyes(float frameTime)
5454
{
55-
var query = AllEntityQuery<EyeComponent, CameraRecoilComponent>();
55+
var query = AllEntityQuery<CameraRecoilComponent, EyeComponent>();
5656

57-
while (query.MoveNext(out var uid, out var eye, out var recoil))
57+
while (query.MoveNext(out var uid, out var recoil, out var eye))
5858
{
5959
var magnitude = recoil.CurrentKick.Length();
6060
if (magnitude <= 0.005f)

Content.Shared/Movement/Systems/SharedContentEyeSystem.cs

+21-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ public abstract class SharedContentEyeSystem : EntitySystem
1818
{
1919
[Dependency] private readonly ISharedAdminManager _admin = default!;
2020

21+
// Admin flags required to ignore normal eye restrictions.
22+
public const AdminFlags EyeFlag = AdminFlags.Debug;
23+
2124
public const float ZoomMod = 1.5f;
2225
public static readonly Vector2 DefaultZoom = Vector2.One;
2326
public static readonly Vector2 MinZoom = DefaultZoom * (float)Math.Pow(ZoomMod, -3);
@@ -29,6 +32,7 @@ public override void Initialize()
2932
base.Initialize();
3033
SubscribeLocalEvent<ContentEyeComponent, ComponentStartup>(OnContentEyeStartup);
3134
SubscribeAllEvent<RequestTargetZoomEvent>(OnContentZoomRequest);
35+
SubscribeAllEvent<RequestPvsScaleEvent>(OnPvsScale);
3236
SubscribeAllEvent<RequestEyeEvent>(OnRequestEye);
3337

3438
CommandBinds.Builder
@@ -84,12 +88,18 @@ public void SetZoom(EntityUid uid, Vector2 zoom, bool ignoreLimits = false, Cont
8488

8589
private void OnContentZoomRequest(RequestTargetZoomEvent msg, EntitySessionEventArgs args)
8690
{
87-
var ignoreLimit = msg.IgnoreLimit && _admin.HasAdminFlag(args.SenderSession, AdminFlags.Debug);
91+
var ignoreLimit = msg.IgnoreLimit && _admin.HasAdminFlag(args.SenderSession, EyeFlag);
8892

8993
if (TryComp<ContentEyeComponent>(args.SenderSession.AttachedEntity, out var content))
9094
SetZoom(args.SenderSession.AttachedEntity.Value, msg.TargetZoom, ignoreLimit, eye: content);
9195
}
9296

97+
private void OnPvsScale(RequestPvsScaleEvent ev, EntitySessionEventArgs args)
98+
{
99+
if (args.SenderSession.AttachedEntity is {} uid && _admin.HasAdminFlag(args.SenderSession, EyeFlag))
100+
_eye.SetPvsScale(uid, ev.Scale);
101+
}
102+
93103
private void OnRequestEye(RequestEyeEvent msg, EntitySessionEventArgs args)
94104
{
95105
if (args.SenderSession.AttachedEntity is not { } player)
@@ -116,6 +126,7 @@ private void OnContentEyeStartup(EntityUid uid, ContentEyeComponent component, C
116126

117127
public void ResetZoom(EntityUid uid, ContentEyeComponent? component = null)
118128
{
129+
_eye.SetPvsScale(uid, 1);
119130
SetZoom(uid, DefaultZoom, eye: component);
120131
}
121132

@@ -146,6 +157,15 @@ public sealed class RequestTargetZoomEvent : EntityEventArgs
146157
public bool IgnoreLimit;
147158
}
148159

160+
/// <summary>
161+
/// Client->Server request for new PVS scale.
162+
/// </summary>
163+
[Serializable, NetSerializable]
164+
public sealed class RequestPvsScaleEvent(float scale) : EntityEventArgs
165+
{
166+
public float Scale = scale;
167+
}
168+
149169
/// <summary>
150170
/// Sendable from client to server to request changing fov.
151171
/// </summary>
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
cmd-zoom-desc = Sets the zoom of the main eye.
2-
cmd-zoom-help = zoom ( <scale> | <X-scale> <Y-scale> )
1+
cmd-zoom-desc = Sets the zoom of the main eye. Optionally also changes the eye's PVS range.
2+
cmd-zoom-help = zoom ( <scale> | <X-scale> <Y-scale> [bool])
33
cmd-zoom-error = scale has to be greater than 0

0 commit comments

Comments
 (0)