From cb49832b5afc71693726a611746e2ddb8ea13bdd Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Date: Sun, 15 May 2022 11:47:48 +0530 Subject: [PATCH] Player stops auto walking if WASD is pressed --- stardew-access/Features/TileViewer.cs | 57 ++++++++++++++++++--------- stardew-access/ModEntry.cs | 10 +++++ 2 files changed, 49 insertions(+), 18 deletions(-) diff --git a/stardew-access/Features/TileViewer.cs b/stardew-access/Features/TileViewer.cs index 60acdef..c63e0cd 100644 --- a/stardew-access/Features/TileViewer.cs +++ b/stardew-access/Features/TileViewer.cs @@ -20,9 +20,10 @@ 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; + public Boolean isAutoWalking = false; + private Vector2 PlayerFacingVector { get @@ -133,22 +134,40 @@ namespace stardew_access.Features } 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); - } + this.startAutoWalking(); } } + private void startAutoWalking() + { + 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); + } + } + + /// + /// Stop the auto walk controller and reset variables + /// + /// Narrates a message if set to true. + public void stopAutoWalking(bool wasForced = false) + { + this.finalTile = Vector2.Zero; + this.isAutoWalking = false; + Game1.player.controller = null; + if (wasForced) + MainClass.ScreenReader.Say("Stopped moving", true); + } + private void cursorMoveInput(Vector2 delta, Boolean precise = false) { if (!tryMoveTileView(delta)) return; @@ -219,11 +238,13 @@ namespace stardew_access.Features if (MainClass.Config.SnapMouse) this.SnapMouseToPlayer(); - if (this.isAutoWalking && this.finalTile != Vector2.Zero && this.finalTile == CurrentPlayer.Position) + if (this.isAutoWalking) { - MainClass.ScreenReader.Say("Reached destination", true); - this.finalTile = Vector2.Zero; - this.isAutoWalking = false; + if (this.finalTile != Vector2.Zero && this.finalTile == CurrentPlayer.Position) + { + MainClass.ScreenReader.Say("Reached destination", true); + this.stopAutoWalking(); + } } } diff --git a/stardew-access/ModEntry.cs b/stardew-access/ModEntry.cs index 768a365..4579a36 100644 --- a/stardew-access/ModEntry.cs +++ b/stardew-access/ModEntry.cs @@ -226,6 +226,16 @@ namespace stardew_access if (!Context.IsPlayerFree) return; + // Stops the auto walk controller if any movement key(WASD) is pressed + if (TileViewerFeature.isAutoWalking && + (e.Button.Equals(SButtonExtensions.ToSButton(Game1.options.moveUpButton[0])) + || e.Button.Equals(SButtonExtensions.ToSButton(Game1.options.moveDownButton[0])) + || e.Button.Equals(SButtonExtensions.ToSButton(Game1.options.moveLeftButton[0])) + || e.Button.Equals(SButtonExtensions.ToSButton(Game1.options.moveRightButton[0])))) + { + TileViewerFeature.stopAutoWalking(wasForced: true); + } + // Narrate Current Location if (Config.LocationKey.JustPressed()) {