diff --git a/stardew-access/Features/MouseHandler.cs b/stardew-access/Features/MouseHandler.cs new file mode 100644 index 0000000..88b09c8 --- /dev/null +++ b/stardew-access/Features/MouseHandler.cs @@ -0,0 +1,50 @@ +using System; +using System.Collections.Generic; +using Microsoft.Xna.Framework; +using StardewValley; + +namespace stardew_access.Features +{ + public class MouseHandler + { + + public Vector2 ViewingOffset { get; set; } = Vector2.Zero; + + public Vector2 PlayerFacingVector + { + get + { +switch (Game1.player.FacingDirection) + { + case 0: + return new Vector2(0, - Game1.tileSize); + case 1: + return new Vector2(Game1.tileSize, 0); + case 2: + return new Vector2(0, Game1.tileSize); + case 3: + return new Vector2(-Game1.tileSize, 0); + default: + return Vector2.Zero; + } + } + } + + public Vector2 PlayerPosition + { + get + { + int x = Game1.player.GetBoundingBox().Center.X - Game1.viewport.X; + int y = Game1.player.GetBoundingBox().Center.Y - Game1.viewport.Y; + return new Vector2(x, y); + } + } + + public void SnapMouseToPlayer() + { + Vector2 snapPosition = this.PlayerPosition + this.PlayerFacingVector + this.ViewingOffset; + if (Utility.isOnScreen(snapPosition, 0)) + Game1.setMousePosition((int)snapPosition.X, (int)snapPosition.Y); + } + } +} diff --git a/stardew-access/Features/Other.cs b/stardew-access/Features/Other.cs index a21698f..826c01d 100644 --- a/stardew-access/Features/Other.cs +++ b/stardew-access/Features/Other.cs @@ -41,32 +41,6 @@ namespace stardew_access.Features MainClass.ScreenReader.Say($"{currentLocation.Name} Entered", true); } - public static void SnapMouseToPlayer() - { - int x = Game1.player.GetBoundingBox().Center.X - Game1.viewport.X; - int y = Game1.player.GetBoundingBox().Center.Y - Game1.viewport.Y; - - int offset = 64; - - switch (Game1.player.FacingDirection) - { - case 0: - y -= offset; - break; - case 1: - x += offset; - break; - case 2: - y += offset; - break; - case 3: - x -= offset; - break; - } - - Game1.setMousePosition(x, y); - } - public static void narrateHudMessages() { try diff --git a/stardew-access/ModEntry.cs b/stardew-access/ModEntry.cs index 59dbb2f..7718b08 100644 --- a/stardew-access/ModEntry.cs +++ b/stardew-access/ModEntry.cs @@ -20,6 +20,7 @@ namespace stardew_access private static StaticTiles? sTiles; private static IScreenReader? screenReader; private static IModHelper? modHelper; + private static MouseHandler? mouse; internal static ModConfig Config { get => config; set => config = value; } public static IModHelper? ModHelper { get => modHelper; } @@ -62,6 +63,17 @@ namespace stardew_access set => screenReader = value; } + + public static MouseHandler Mouse + { +get + { + if (mouse == null) + mouse = new MouseHandler(); + return mouse; + } + } + #endregion /********* @@ -131,7 +143,7 @@ namespace stardew_access Other.narrateCurrentLocation(); if (Config.SnapMouse) - Other.SnapMouseToPlayer(); + Mouse.SnapMouseToPlayer(); if (!ReadTile.isReadingTile && Config.ReadTile) {