From c8b274347e1af772832bb9214d6e23a3bd481fe8 Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Date: Sun, 15 May 2022 11:30:28 +0530 Subject: [PATCH] Added auto walk feature to tile viewer --- stardew-access/Features/TileViewer.cs | 26 ++++++++++++++++++++++++++ stardew-access/ModConfig.cs | 1 + 2 files changed, 27 insertions(+) diff --git a/stardew-access/Features/TileViewer.cs b/stardew-access/Features/TileViewer.cs index 2b07fde..60acdef 100644 --- a/stardew-access/Features/TileViewer.cs +++ b/stardew-access/Features/TileViewer.cs @@ -20,6 +20,8 @@ namespace stardew_access.Features private Vector2 relativeOffsetLockPosition = Vector2.Zero; private Boolean relativeOffsetLock = false; private Vector2 prevPlayerPosition = Vector2.Zero, prevFacing = Vector2.Zero; + private Boolean isAutoWalking = false; + private Vector2 finalTile = Vector2.Zero; private Vector2 PlayerFacingVector { @@ -129,6 +131,22 @@ namespace stardew_access.Features { this.cursorMoveInput(new Vector2(-Game1.tileSize, 0)); } + else if (MainClass.Config.AutoWalkToTile.JustPressed() && StardewModdingAPI.Context.IsPlayerFree) + { + PathFindController controller = new PathFindController(Game1.player, Game1.currentLocation, this.GetViewingTile().ToPoint(), Game1.player.FacingDirection); + controller.allowPlayerPathingInEvent = true; + if (controller.pathToEndPoint != null && controller.pathToEndPoint.Count > 0) + { + Game1.player.controller = controller; + this.isAutoWalking = true; + this.finalTile = this.GetViewingTile(); + MainClass.ScreenReader.Say($"Moving to {this.finalTile.X}x {this.finalTile.Y}y", true); + } + else + { + MainClass.ScreenReader.Say($"Cannot move to {this.finalTile.X}x {this.finalTile.Y}y", true); + } + } } private void cursorMoveInput(Vector2 delta, Boolean precise = false) @@ -200,6 +218,14 @@ namespace stardew_access.Features this.prevPlayerPosition = this.PlayerPosition; if (MainClass.Config.SnapMouse) this.SnapMouseToPlayer(); + + if (this.isAutoWalking && this.finalTile != Vector2.Zero && this.finalTile == CurrentPlayer.Position) + { + MainClass.ScreenReader.Say("Reached destination", true); + this.finalTile = Vector2.Zero; + this.isAutoWalking = false; + } + } private static bool allowMouseSnap(Vector2 point) diff --git a/stardew-access/ModConfig.cs b/stardew-access/ModConfig.cs index 479c25d..7b22ddc 100644 --- a/stardew-access/ModConfig.cs +++ b/stardew-access/ModConfig.cs @@ -38,6 +38,7 @@ namespace stardew_access public KeybindList TileCursorPreciseDownKey { get; set; } = KeybindList.Parse("LeftShift + Down"); public KeybindList TileCursorPreciseLeftKey { get; set; } = KeybindList.Parse("LeftShift + Left"); public KeybindList ToggleRelativeCursorLockKey { get; set; } = KeybindList.Parse("L"); + public KeybindList AutoWalkToTile { get; set; } = KeybindList.Parse("LeftControl + Enter"); #endregion // TODO Add the exclusion and focus list too