MouseRotatorComponent.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using System.Numerics;
  2. using Robust.Shared.GameStates;
  3. using Robust.Shared.Serialization;
  4. namespace Content.Shared.MouseRotator;
  5. /// <summary>
  6. /// This component allows overriding an entities local rotation based on the client's mouse movement
  7. /// </summary>
  8. /// <see cref="SharedMouseRotatorSystem"/>
  9. [RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
  10. public sealed partial class MouseRotatorComponent : Component
  11. {
  12. /// <summary>
  13. /// How much the desired angle needs to change before a predictive event is sent
  14. /// </summary>
  15. [DataField, AutoNetworkedField]
  16. public Angle AngleTolerance = Angle.FromDegrees(20.0);
  17. /// <summary>
  18. /// The angle that will be lerped to
  19. /// </summary>
  20. [DataField, AutoNetworkedField]
  21. public Angle? GoalRotation;
  22. /// <summary>
  23. /// Max degrees the entity can rotate per second
  24. /// </summary>
  25. [DataField, AutoNetworkedField]
  26. public double RotationSpeed = float.MaxValue;
  27. /// <summary>
  28. /// This one is important. If this is true, <see cref="AngleTolerance"/> does not apply. In this mode, the client will only send
  29. /// events when an entity should snap to a different cardinal direction, rather than for every angle change.
  30. ///
  31. /// This is useful for cases like humans, where what really matters is the visual sprite direction, as opposed to something
  32. /// like turrets or ship guns, which have finer range of movement.
  33. /// </summary>
  34. [DataField, AutoNetworkedField]
  35. public bool Simple4DirMode = true;
  36. }
  37. /// <summary>
  38. /// Raised on an entity with <see cref="MouseRotatorComponent"/> as a predictive event on the client
  39. /// when mouse rotation changes
  40. /// </summary>
  41. [Serializable, NetSerializable]
  42. public sealed class RequestMouseRotatorRotationEvent : EntityEventArgs
  43. {
  44. public Angle Rotation;
  45. }