From 77f9f18ecc28adb618addb4ac00aabf62f5899c3 Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Date: Mon, 31 Jan 2022 20:16:47 +0530 Subject: [PATCH] Check if bush is harvestable or not. --- stardew-access/Features/Radar.cs | 8 +--- stardew-access/Features/ReadTile.cs | 44 ++++++++++++++++++- stardew-access/ModEntry.cs | 6 +-- stardew-access/Patches/TitleMenuPatches.cs | 2 +- .../ScreenReader/ScreenReaderLinux.cs | 23 +++++++--- 5 files changed, 65 insertions(+), 18 deletions(-) diff --git a/stardew-access/Features/Radar.cs b/stardew-access/Features/Radar.cs index 77f9bd9..efac4c2 100644 --- a/stardew-access/Features/Radar.cs +++ b/stardew-access/Features/Radar.cs @@ -197,7 +197,7 @@ namespace stardew_access.Game // Check for animals else if (ReadTile.getFarmAnimalAt(Game1.currentLocation, (int)position.X, (int)position.Y) != null) { - string name = ReadTile.getFarmAnimalAt(Game1.currentLocation, (int)position.X, (int)position.Y, onlyName: true); + string? name = ReadTile.getFarmAnimalAt(Game1.currentLocation, (int)position.X, (int)position.Y, onlyName: true); PlaySoundAt(position, name, CATEGORY.FarmAnimals); } // Check for water @@ -286,10 +286,6 @@ namespace stardew_access.Game { PlaySoundAt(position, terrain, CATEGORY.Others); } - else if (tr.Get() is Leaf) - { - PlaySoundAt(position, terrain, CATEGORY.Others); - } } } // Check for Mine ladders @@ -313,7 +309,7 @@ namespace stardew_access.Game // Check for buildings on maps else if (ReadTile.getTileInfo((int)position.X, (int)position.Y).Item2 != null) { - (CATEGORY, string?) item = ReadTile.getTileInfo((int)position.X, (int)position.Y); + (CATEGORY?, string?) item = ReadTile.getTileInfo((int)position.X, (int)position.Y); PlaySoundAt(position, item.Item2, item.Item1); } // Check for resource clumps diff --git a/stardew-access/Features/ReadTile.cs b/stardew-access/Features/ReadTile.cs index adf1681..183c868 100644 --- a/stardew-access/Features/ReadTile.cs +++ b/stardew-access/Features/ReadTile.cs @@ -71,7 +71,49 @@ namespace stardew_access.Game } else if ( Game1.currentLocation.getLargeTerrainFeatureAt(x, y) != null ) { - toSpeak = "Bush"; + Bush bush = (Bush) Game1.currentLocation.getLargeTerrainFeatureAt(x, y); + int size = bush.size; + + #region Check if bush is harvestable or not + if (!bush.townBush && (int)bush.tileSheetOffset == 1 && bush.inBloom(Game1.GetSeasonForLocation(Game1.currentLocation), Game1.dayOfMonth)) + { + // Taken from the game's code + string season = ((int)bush.overrideSeason == -1) ? Game1.GetSeasonForLocation(Game1.currentLocation) : Utility.getSeasonNameFromNumber(bush.overrideSeason); + int shakeOff = -1; + if (!(season == "spring")) + { + if (season == "fall") + { + shakeOff = 410; + } + } + else + { + shakeOff = 296; + } + if ((int)size == 3) + { + shakeOff = 815; + } + if ((int)size == 4) + { + shakeOff = 73; + } + if (shakeOff == -1) + { + return; + } + + toSpeak = "Harvestable"; + } + #endregion + + if(bush.townBush) + toSpeak = $"{toSpeak} Town Bush"; + else if(bush.greenhouseBush) + toSpeak = $"{toSpeak} Greenhouse Bush"; + else + toSpeak = $"{toSpeak} Bush"; } else if (getResourceClumpAtTile(x, y) != null) { diff --git a/stardew-access/ModEntry.cs b/stardew-access/ModEntry.cs index dc3a036..16fcba2 100644 --- a/stardew-access/ModEntry.cs +++ b/stardew-access/ModEntry.cs @@ -19,11 +19,11 @@ namespace stardew_access public static bool radar = true; public static bool radarDebug = false; public static bool radarStereoSound = true; - public static IMonitor? monitor; - AutoHotkeyEngine ahk; + public static IMonitor monitor; + private AutoHotkeyEngine? ahk; public static string hudMessageQueryKey = ""; public static Radar radarFeature; - public static ScreenReaderInterface? screenReader; + public static ScreenReaderInterface screenReader; private static IModHelper _modHelper; public static IModHelper ModHelper diff --git a/stardew-access/Patches/TitleMenuPatches.cs b/stardew-access/Patches/TitleMenuPatches.cs index dad8fb7..5664a74 100644 --- a/stardew-access/Patches/TitleMenuPatches.cs +++ b/stardew-access/Patches/TitleMenuPatches.cs @@ -659,7 +659,7 @@ namespace stardew_access.Patches } else { - hoverTitle = null; + hoverTitle = " "; hoverText = farm.hoverText; } } diff --git a/stardew-access/ScreenReader/ScreenReaderLinux.cs b/stardew-access/ScreenReader/ScreenReaderLinux.cs index e31fc2d..5ec2bb0 100644 --- a/stardew-access/ScreenReader/ScreenReaderLinux.cs +++ b/stardew-access/ScreenReader/ScreenReaderLinux.cs @@ -17,15 +17,16 @@ namespace stardew_access.ScreenReader public class ScreenReaderLinux : ScreenReaderInterface { [DllImport("libspeechdwrapper.so")] - private static extern void Initialize(); + private static extern int Initialize(); [DllImport("libspeechdwrapper.so")] - private static extern void Speak(GoString text, bool interrupt); + private static extern int Speak(GoString text, bool interrupt); [DllImport("libspeechdwrapper.so")] - private static extern void Close(); + private static extern int Close(); public string prevText = "", prevTextTile = " ", prevChatText = "", prevMenuText = ""; + private bool initialized = false; public string PrevTextTile{ get{ return prevTextTile; } @@ -34,17 +35,25 @@ namespace stardew_access.ScreenReader public void InitializeScreenReader() { - Initialize(); + int res = Initialize(); + if(res==1){ + initialized = true; + } } public void CloseScreenReader(){ - Close(); + if(initialized){ + Close(); + initialized = false; + } } public void Say(string text, bool interrupt) { - GoString str = new GoString(text, text.Length); - Speak(str, interrupt); + if(initialized){ + GoString str = new GoString(text, text.Length); + Speak(str, interrupt); + } } public void SayWithChecker(string text, bool interrupt)