* Use new Subs.CVar helper Removes manual config OnValueChanged calls, removes need to remember to manually unsubscribe. This both reduces boilerplate and fixes many issues where subscriptions weren't removed on entity system shutdown. * Fix a bunch of warnings * More warning fixes * Use new DateTime serializer to get rid of ISerializationHooks in changelog code. * Get rid of some more ISerializationHooks for enums * And a little more * Apply suggestions from code review Co-authored-by: 0x6273 <0x40@keemail.me> --------- Co-authored-by: 0x6273 <0x40@keemail.me>
78 lines
2.4 KiB
C#
78 lines
2.4 KiB
C#
using Content.Shared.MouseRotator;
|
|
using Robust.Client.Graphics;
|
|
using Robust.Client.Input;
|
|
using Robust.Client.Player;
|
|
using Robust.Shared.Map;
|
|
using Robust.Shared.Timing;
|
|
|
|
namespace Content.Client.MouseRotator;
|
|
|
|
/// <inheritdoc/>
|
|
public sealed class MouseRotatorSystem : SharedMouseRotatorSystem
|
|
{
|
|
[Dependency] private readonly IInputManager _input = default!;
|
|
[Dependency] private readonly IPlayerManager _player = default!;
|
|
[Dependency] private readonly IGameTiming _timing = default!;
|
|
[Dependency] private readonly IEyeManager _eye = default!;
|
|
[Dependency] private readonly SharedTransformSystem _transform = default!;
|
|
|
|
public override void Update(float frameTime)
|
|
{
|
|
base.Update(frameTime);
|
|
|
|
if (!_timing.IsFirstTimePredicted || !_input.MouseScreenPosition.IsValid)
|
|
return;
|
|
|
|
var player = _player.LocalEntity;
|
|
|
|
if (player == null || !TryComp<MouseRotatorComponent>(player, out var rotator))
|
|
return;
|
|
|
|
var xform = Transform(player.Value);
|
|
|
|
// Get mouse loc and convert to angle based on player location
|
|
var coords = _input.MouseScreenPosition;
|
|
var mapPos = _eye.PixelToMap(coords);
|
|
|
|
if (mapPos.MapId == MapId.Nullspace)
|
|
return;
|
|
|
|
var angle = (mapPos.Position - xform.MapPosition.Position).ToWorldAngle();
|
|
|
|
var curRot = _transform.GetWorldRotation(xform);
|
|
|
|
// 4-dir handling is separate --
|
|
// only raise event if the cardinal direction has changed
|
|
if (rotator.Simple4DirMode)
|
|
{
|
|
var angleDir = angle.GetCardinalDir();
|
|
if (angleDir == curRot.GetCardinalDir())
|
|
return;
|
|
|
|
RaisePredictiveEvent(new RequestMouseRotatorRotationSimpleEvent()
|
|
{
|
|
Direction = angleDir,
|
|
});
|
|
|
|
return;
|
|
}
|
|
|
|
// Don't raise event if mouse ~hasn't moved (or if too close to goal rotation already)
|
|
var diff = Angle.ShortestDistance(angle, curRot);
|
|
if (Math.Abs(diff.Theta) < rotator.AngleTolerance.Theta)
|
|
return;
|
|
|
|
if (rotator.GoalRotation != null)
|
|
{
|
|
var goalDiff = Angle.ShortestDistance(angle, rotator.GoalRotation.Value);
|
|
if (Math.Abs(goalDiff.Theta) < rotator.AngleTolerance.Theta)
|
|
return;
|
|
}
|
|
|
|
RaisePredictiveEvent(new RequestMouseRotatorRotationEvent
|
|
{
|
|
Rotation = angle
|
|
});
|
|
}
|
|
}
|