]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Allow `zoom` command to modify an eye's PVS range (#29245)
authorLeon Friedrich <60421075+ElectroJr@users.noreply.github.com>
Wed, 3 Jul 2024 06:44:55 +0000 (18:44 +1200)
committerGitHub <noreply@github.com>
Wed, 3 Jul 2024 06:44:55 +0000 (16:44 +1000)
Allow zoom command to modify an eye's PVS range

Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Content.Client/Commands/ZoomCommand.cs
Content.Client/Movement/Systems/ContentEyeSystem.cs
Content.Shared/Camera/CameraRecoilComponent.cs
Content.Shared/Camera/SharedCameraRecoilSystem.cs
Content.Shared/Movement/Systems/SharedContentEyeSystem.cs
Resources/Locale/en-US/commands/zoom-command.ftl

index 2bdc85e1fee51e2c9958214623125c387152b99a..c63eeea8369ad0a8191f7479435d2d5392cbeccb 100644 (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;
         }
 
index 182ac92ae0550a7551e031a0ba03f2c186af2de9..9fbd4b5c37d0b548a2cee0ab787488940856d0fd 100644 (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()
index 8b8b290845e03964d26288d32ec02a2c4d83059a..2cbb632408640ee68da3e306fa72e831d98a8447 100644 (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; }
 }
index 5ba97dabe2cb68f41e51df6bb32d07037d93427a..a2ce0e77e20cae6b3569eb575a9ba0674b3accab 100644 (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)
index 0c4304d37483ebe1410fb7a6452a9aaf87acba24..faade44c85871d98ebc98fad44635c9b70894f08 100644 (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>
index 0132f222405465ce8ad46c9b03e510fb92c7a26d..64bf6bca7af62075161273465c04aa0f8ecde302 100644 (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