From c83d06a74fc7f03e2f1c4652d62490331873f68c Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Date: Thu, 3 Feb 2022 18:39:03 +0530 Subject: [PATCH] All the features of carpenter menu are accessible --- stardew-access/CustomCommands.cs | 40 +++++++++++++--- .../Patches/BuildingNAnimalMenuPatches.cs | 46 ++++++++++++++++++- stardew-access/manifest.json | 2 +- 3 files changed, 79 insertions(+), 9 deletions(-) diff --git a/stardew-access/CustomCommands.cs b/stardew-access/CustomCommands.cs index b39fec0..1e9f7b9 100644 --- a/stardew-access/CustomCommands.cs +++ b/stardew-access/CustomCommands.cs @@ -311,7 +311,7 @@ namespace stardew_access } BuildingNAnimalMenuPatches.marked[index] = new Vector2((int)Game1.player.getTileX(), (int)Game1.player.getTileY()); - MainClass.monitor.Log($"Location {(int)Game1.player.getTileX()}x {(int)Game1.player.getTileY()}y add at {index} index.", LogLevel.Info); + MainClass.monitor.Log($"Location {(int)Game1.player.getTileX()}x {(int)Game1.player.getTileY()}y added at {index} index.", LogLevel.Info); }); helper.ConsoleCommands.Add("marklist", "List all marked positions.", (string commmand, string[] args) => @@ -321,14 +321,14 @@ namespace stardew_access { if (BuildingNAnimalMenuPatches.marked[i] != Vector2.Zero) { - toPrint = $"{toPrint}\t Index {i}: {BuildingNAnimalMenuPatches.marked[i].X}x {BuildingNAnimalMenuPatches.marked[i].Y}y"; + toPrint = $"{toPrint}\n Index {i}: {BuildingNAnimalMenuPatches.marked[i].X}x {BuildingNAnimalMenuPatches.marked[i].Y}y"; } } if (toPrint == "") MainClass.monitor.Log("No positions marked!", LogLevel.Info); else - MainClass.monitor.Log($"Marked positions:\t{toPrint}", LogLevel.Info); + MainClass.monitor.Log($"Marked positions:\n{toPrint}\nOpen command menu and use pageup and pagedown to check the list", LogLevel.Info); }); helper.ConsoleCommands.Add("buildlist", "List all buildings for selection for upgrading/demolishing/painting", (string commmand, string[] args) => @@ -389,8 +389,36 @@ namespace stardew_access return; } + string positionIndexInString = args.ElementAtOrDefault(1); + int positionIndex = 0; - if (BuildingNAnimalMenuPatches.isConstructing || BuildingNAnimalMenuPatches.isMoving) + if (BuildingNAnimalMenuPatches.isMoving) + { + + if (BuildingNAnimalMenuPatches.isConstructing || BuildingNAnimalMenuPatches.isMoving) + { + if (BuildingNAnimalMenuPatches.availableBuildings[index] == null) + { + MainClass.monitor.Log($"No building found with index {index}. Use buildlist.", LogLevel.Info); + return; + } + + if (positionIndexInString == null) + { + MainClass.monitor.Log("Enter the index of marked place too! Use marklist.", LogLevel.Info); + return; + } + + isParsable = int.TryParse(positionIndexInString, out positionIndex); + + if (!isParsable) + { + MainClass.monitor.Log("Index can only be a number.", LogLevel.Info); + return; + } + } + } + else if (BuildingNAnimalMenuPatches.isConstructing) { if (BuildingNAnimalMenuPatches.marked[index] == Vector2.Zero) { @@ -408,8 +436,8 @@ namespace stardew_access } string? response = null; - if (BuildingNAnimalMenuPatches.isConstructing) { response = BuildingNAnimalMenuPatches.Contstruct(BuildingNAnimalMenuPatches.availableBuildings[index], BuildingNAnimalMenuPatches.marked[index]); } - else if (BuildingNAnimalMenuPatches.isMoving) { response = BuildingNAnimalMenuPatches.Move(BuildingNAnimalMenuPatches.availableBuildings[index], BuildingNAnimalMenuPatches.marked[index]); } + if (BuildingNAnimalMenuPatches.isConstructing) { response = BuildingNAnimalMenuPatches.Contstruct(BuildingNAnimalMenuPatches.marked[index]); } + else if (BuildingNAnimalMenuPatches.isMoving) { response = BuildingNAnimalMenuPatches.Move(BuildingNAnimalMenuPatches.availableBuildings[index], BuildingNAnimalMenuPatches.marked[positionIndex]); } if (BuildingNAnimalMenuPatches.isDemolishing) { response = BuildingNAnimalMenuPatches.Demolish(BuildingNAnimalMenuPatches.availableBuildings[index]); } else if (BuildingNAnimalMenuPatches.isUpgrading) { response = BuildingNAnimalMenuPatches.Upgrade(BuildingNAnimalMenuPatches.availableBuildings[index]); } else if (BuildingNAnimalMenuPatches.isPainting) { response = BuildingNAnimalMenuPatches.Paint(BuildingNAnimalMenuPatches.availableBuildings[index]); } diff --git a/stardew-access/Patches/BuildingNAnimalMenuPatches.cs b/stardew-access/Patches/BuildingNAnimalMenuPatches.cs index b2ac6cc..3ea5af3 100644 --- a/stardew-access/Patches/BuildingNAnimalMenuPatches.cs +++ b/stardew-access/Patches/BuildingNAnimalMenuPatches.cs @@ -322,7 +322,7 @@ namespace stardew_access.Patches return response; } - public static string? Contstruct(Building? toCunstruct, Vector2 position) + public static string? Contstruct(Vector2 position) { string? response = null; Game1.player.team.buildLock.RequestLock(delegate @@ -410,9 +410,51 @@ namespace stardew_access.Patches return response; } - public static string? Move(Building? toMove, Vector2 position) + public static string? Move(Building? buildingToMove, Vector2 position) { string? response = null; + if (buildingToMove != null) + { + string? name = buildingToMove.nameOfIndoorsWithoutUnique; + name = (name == "null") ? buildingToMove.buildingType.Value : name; + + if ((int)buildingToMove.daysOfConstructionLeft > 0) + { + buildingToMove = null; + return "Building under cunstruction, cannot move"; + } + if (!carpenterMenu.hasPermissionsToMove(buildingToMove)) + { + buildingToMove = null; + return "You don't have permission to move this building"; + } + Game1.playSound("axchop"); + + if (((Farm)Game1.getLocationFromName("Farm")).buildStructure(buildingToMove, position, Game1.player)) + { + if (buildingToMove is ShippingBin) + { + (buildingToMove as ShippingBin).initLid(); + } + if (buildingToMove is GreenhouseBuilding) + { + Game1.getFarm().greenhouseMoved.Value = true; + } + buildingToMove.performActionOnBuildingPlacement(); + buildingToMove = null; + Game1.playSound("axchop"); + DelayedAction.playSoundAfterDelay("dirtyHit", 50); + DelayedAction.playSoundAfterDelay("dirtyHit", 150); + + response = $"{buildingToMove} moved to {position.X}x {position.Y}y"; + } + else + { + Game1.playSound("cancel"); + response = $"Cannot move building to {position.X}x {position.Y}y"; + } + + } return response; } diff --git a/stardew-access/manifest.json b/stardew-access/manifest.json index 117f409..fb7e7be 100644 --- a/stardew-access/manifest.json +++ b/stardew-access/manifest.json @@ -1,7 +1,7 @@ { "Name": "Stardew Access", "Author": "Mohammad Shoaib", - "Version": "1.0.20-beta", + "Version": "1.0.21-beta", "Description": "An accessibility mod with screen reader support!", "UniqueID": "shoaib.stardewaccess", "EntryDll": "stardew-access.dll",