diff --git a/Content.Client/Commands/ZoomCommand.cs b/Content.Client/Commands/ZoomCommand.cs index f3adb61ae2..bdcfdaa6fa 100644 --- a/Content.Client/Commands/ZoomCommand.cs +++ b/Content.Client/Commands/ZoomCommand.cs @@ -1,5 +1,9 @@ +using Content.Client.Movement.Systems; +using Content.Shared.Movement.Components; +using Content.Shared.Movement.Systems; using JetBrains.Annotations; using Robust.Client.Graphics; +using Robust.Client.Player; using Robust.Shared.Console; namespace Content.Client.Commands; @@ -7,7 +11,9 @@ namespace Content.Client.Commands; [UsedImplicitly] public sealed class ZoomCommand : IConsoleCommand { + [Dependency] private readonly IEntityManager _entManager = default!; [Dependency] private readonly IEyeManager _eyeMan = default!; + [Dependency] private readonly IPlayerManager _playerManager = default!; public string Command => "zoom"; public string Description => Loc.GetString("zoom-command-description"); @@ -53,6 +59,14 @@ public sealed class ZoomCommand : IConsoleCommand } } + var player = _playerManager.LocalPlayer?.ControlledEntity; + + if (_entManager.TryGetComponent(player, out var content)) + { + _entManager.System().RequestZoom(player.Value, zoom, content); + return; + } + _eyeMan.CurrentEye.Zoom = zoom; } } diff --git a/Content.Client/Movement/Systems/ContentEyeSystem.cs b/Content.Client/Movement/Systems/ContentEyeSystem.cs index 7ed0c771e1..9e7345e199 100644 --- a/Content.Client/Movement/Systems/ContentEyeSystem.cs +++ b/Content.Client/Movement/Systems/ContentEyeSystem.cs @@ -9,6 +9,17 @@ public sealed class ContentEyeSystem : SharedContentEyeSystem { [Dependency] private readonly IPlayerManager _player = default!; + public void RequestZoom(EntityUid uid, Vector2 zoom, ContentEyeComponent? content = null) + { + if (!Resolve(uid, ref content, false)) + return; + + RaisePredictiveEvent(new RequestTargetZoomEvent() + { + TargetZoom = zoom, + }); + } + public override void Update(float frameTime) { base.Update(frameTime); diff --git a/Content.Server/Movement/Systems/ContentEyeSystem.cs b/Content.Server/Movement/Systems/ContentEyeSystem.cs index 9076028b50..54428d9bee 100644 --- a/Content.Server/Movement/Systems/ContentEyeSystem.cs +++ b/Content.Server/Movement/Systems/ContentEyeSystem.cs @@ -9,19 +9,12 @@ public sealed class ContentEyeSystem : SharedContentEyeSystem { base.Update(frameTime); - var eyeQuery = GetEntityQuery(); + var query = AllEntityQuery(); - foreach (var (_, comp) in EntityQuery(true)) + while (query.MoveNext(out var uid, out var comp, out var eyeComp)) { - var uid = comp.Owner; - - // Use a separate query jjuussstt in case any actives mistakenly hang around. - if (!eyeQuery.TryGetComponent(comp.Owner, out var eyeComp) || - eyeComp.Zoom.Equals(comp.TargetZoom)) - { - RemComp(comp.Owner); + if (eyeComp.Zoom.Equals(comp.TargetZoom)) continue; - } UpdateEye(uid, comp, eyeComp, frameTime); } diff --git a/Content.Shared/Movement/Components/ActiveContentEyeComponent.cs b/Content.Shared/Movement/Components/ActiveContentEyeComponent.cs deleted file mode 100644 index d81af9836f..0000000000 --- a/Content.Shared/Movement/Components/ActiveContentEyeComponent.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace Content.Shared.Movement.Components; - -[RegisterComponent] -public sealed class ActiveContentEyeComponent : Component -{ - -} diff --git a/Content.Shared/Movement/Components/ContentEyeComponent.cs b/Content.Shared/Movement/Components/ContentEyeComponent.cs index 4af15ace85..eac5816198 100644 --- a/Content.Shared/Movement/Components/ContentEyeComponent.cs +++ b/Content.Shared/Movement/Components/ContentEyeComponent.cs @@ -1,3 +1,4 @@ +using Content.Shared.Movement.Systems; using Robust.Shared.GameStates; namespace Content.Shared.Movement.Components; @@ -5,18 +6,18 @@ namespace Content.Shared.Movement.Components; /// /// Holds SS14 eye data not relevant for engine, e.g. lerp targets. /// -[RegisterComponent, NetworkedComponent] -public sealed class ContentEyeComponent : Component +[RegisterComponent, NetworkedComponent, AutoGenerateComponentState, Access(typeof(SharedContentEyeSystem))] +public sealed partial class ContentEyeComponent : Component { /// /// Zoom we're lerping to. /// - [DataField("targetZoom")] + [DataField("targetZoom"), AutoNetworkedField] public Vector2 TargetZoom = Vector2.One; /// /// How far we're allowed to zoom out. /// - [ViewVariables(VVAccess.ReadWrite), DataField("maxZoom")] + [ViewVariables(VVAccess.ReadWrite), DataField("maxZoom"), AutoNetworkedField] public Vector2 MaxZoom = Vector2.One; } diff --git a/Content.Shared/Movement/Systems/SharedContentEyeSystem.cs b/Content.Shared/Movement/Systems/SharedContentEyeSystem.cs index 1131beaa96..e58a7f81d7 100644 --- a/Content.Shared/Movement/Systems/SharedContentEyeSystem.cs +++ b/Content.Shared/Movement/Systems/SharedContentEyeSystem.cs @@ -1,11 +1,9 @@ using Content.Shared.Input; using Content.Shared.Movement.Components; -using Robust.Shared.GameStates; using Robust.Shared.Input; using Robust.Shared.Input.Binding; using Robust.Shared.Players; using Robust.Shared.Serialization; -using Robust.Shared.Timing; namespace Content.Shared.Movement.Systems; @@ -24,9 +22,8 @@ public abstract class SharedContentEyeSystem : EntitySystem public override void Initialize() { base.Initialize(); - SubscribeLocalEvent(OnGetState); - SubscribeLocalEvent(OnHandleState); SubscribeLocalEvent(OnContentEyeStartup); + SubscribeAllEvent(OnContentZoomRequest); CommandBinds.Builder .Bind(ContentKeyFunctions.ZoomIn, new ScrollInputCmdHandler(true, this)) @@ -37,6 +34,15 @@ public abstract class SharedContentEyeSystem : EntitySystem Sawmill.Level = LogLevel.Info; } + private void OnContentZoomRequest(RequestTargetZoomEvent msg, EntitySessionEventArgs args) + { + if (!TryComp(args.SenderSession.AttachedEntity, out var content)) + return; + + content.TargetZoom = msg.TargetZoom; + Dirty(content); + } + public override void Shutdown() { base.Shutdown(); @@ -52,24 +58,6 @@ public abstract class SharedContentEyeSystem : EntitySystem Dirty(component); } - private void OnGetState(EntityUid uid, ContentEyeComponent component, ref ComponentGetState args) - { - args.State = new ContentEyeComponentState() - { - TargetZoom = component.TargetZoom, - MaxZoom = component.MaxZoom, - }; - } - - private void OnHandleState(EntityUid uid, ContentEyeComponent component, ref ComponentHandleState args) - { - if (args.Current is not ContentEyeComponentState state) - return; - - component.TargetZoom = state.TargetZoom; - component.MaxZoom = state.MaxZoom; - } - protected void UpdateEye(EntityUid uid, ContentEyeComponent content, SharedEyeComponent eye, float frameTime) { var diff = content.TargetZoom - eye.Zoom; @@ -78,7 +66,6 @@ public abstract class SharedContentEyeSystem : EntitySystem { eye.Zoom = content.TargetZoom; Dirty(eye); - RemComp(uid); return; } @@ -102,7 +89,6 @@ public abstract class SharedContentEyeSystem : EntitySystem return; component.TargetZoom = Vector2.One; - EnsureComp(uid); Dirty(component); } @@ -129,18 +115,10 @@ public abstract class SharedContentEyeSystem : EntitySystem return; component.TargetZoom = actual; - EnsureComp(uid); Dirty(component); Sawmill.Debug($"Set target zoom to {actual}"); } - [Serializable, NetSerializable] - private sealed class ContentEyeComponentState : ComponentState - { - public Vector2 TargetZoom; - public Vector2 MaxZoom; - } - private sealed class ResetZoomInputCmdHandler : InputCmdHandler { private readonly SharedContentEyeSystem _system; @@ -192,4 +170,13 @@ public abstract class SharedContentEyeSystem : EntitySystem return false; } } + + /// + /// Sendable from client to server to request a target zoom. + /// + [Serializable, NetSerializable] + public sealed class RequestTargetZoomEvent : EntityEventArgs + { + public Vector2 TargetZoom; + } }