Refactoring mouse handling into a separate class.

master
bradjrenshaw 2022-05-08 01:47:32 -04:00
parent bd29fae9ca
commit 8dd96d84b3
2 changed files with 14 additions and 8 deletions

View File

@ -8,9 +8,9 @@ namespace stardew_access.Features
public class MouseHandler public class MouseHandler
{ {
public Vector2 ViewingOffset { get; set; } = Vector2.Zero; private Vector2 ViewingOffset = Vector2.Zero;
public Vector2 PlayerFacingVector private Vector2 PlayerFacingVector
{ {
get get
{ {
@ -30,7 +30,7 @@ switch (Game1.player.FacingDirection)
} }
} }
public Vector2 PlayerPosition private Vector2 PlayerPosition
{ {
get get
{ {
@ -40,11 +40,18 @@ switch (Game1.player.FacingDirection)
} }
} }
public void SnapMouseToPlayer() private void SnapMouseToPlayer()
{ {
Vector2 snapPosition = this.PlayerPosition + this.PlayerFacingVector + this.ViewingOffset; Vector2 snapPosition = this.PlayerPosition + this.PlayerFacingVector + this.ViewingOffset;
if (Utility.isOnScreen(snapPosition, 0)) Point snapPoint = new Point((int)snapPosition.X, (int)snapPosition.Y);
Game1.setMousePosition((int)snapPosition.X, (int)snapPosition.Y); if (Utility.isOnScreen(snapPoint, 0))
Game1.setMousePosition(snapPoint.X, snapPoint.Y);
}
public void update()
{
if (MainClass.Config.SnapMouse)
this.SnapMouseToPlayer();
} }
} }
} }

View File

@ -142,8 +142,7 @@ get
// Narrate current location's name // Narrate current location's name
Other.narrateCurrentLocation(); Other.narrateCurrentLocation();
if (Config.SnapMouse) Mouse.update();
Mouse.SnapMouseToPlayer();
if (!ReadTile.isReadingTile && Config.ReadTile) if (!ReadTile.isReadingTile && Config.ReadTile)
{ {