diff --git a/stardew-access/API.cs b/stardew-access/API.cs new file mode 100644 index 0000000..c97ecf5 --- /dev/null +++ b/stardew-access/API.cs @@ -0,0 +1,51 @@ +namespace stardew_access.ScreenReader +{ + public class API + { + + public API() + { + } + + public void Say(String text, Boolean interrupt) + { + if (MainClass.GetScreenReader() == null) + return; + + MainClass.GetScreenReader().Say(text, interrupt); + } + + public void SayWithChecker(String text, Boolean interrupt) + { + if (MainClass.GetScreenReader() == null) + return; + + MainClass.GetScreenReader().SayWithChecker(text, interrupt); + } + + public void SayWithMenuChecker(String text, Boolean interrupt) + { + if (MainClass.GetScreenReader() == null) + return; + + MainClass.GetScreenReader().SayWithMenuChecker(text, interrupt); + } + + public void SayWithChatChecker(String text, Boolean interrupt) + { + if (MainClass.GetScreenReader() == null) + return; + + MainClass.GetScreenReader().SayWithChatChecker(text, interrupt); + } + + public void SayWithTileQuery(String text, int x, int y, Boolean interrupt) + { + if (MainClass.GetScreenReader() == null) + return; + + MainClass.GetScreenReader().SayWithTileQuery(text, x, y, interrupt); + } + + } +} \ No newline at end of file diff --git a/stardew-access/CustomCommands.cs b/stardew-access/CustomCommands.cs index d907636..e26cc67 100644 --- a/stardew-access/CustomCommands.cs +++ b/stardew-access/CustomCommands.cs @@ -17,21 +17,21 @@ namespace stardew_access { MainClass.readTile = !MainClass.readTile; - MainClass.Monitor.Log("Read Tile is " + (MainClass.readTile ? "on" : "off"), LogLevel.Info); + MainClass.GetMonitor().Log("Read Tile is " + (MainClass.readTile ? "on" : "off"), LogLevel.Info); }); helper.ConsoleCommands.Add("snapmouse", "Toggle snap mouse feature.", (string commmand, string[] args) => { MainClass.snapMouse = !MainClass.snapMouse; - MainClass.Monitor.Log("Snap Mouse is " + (MainClass.snapMouse ? "on" : "off"), LogLevel.Info); + MainClass.GetMonitor().Log("Snap Mouse is " + (MainClass.snapMouse ? "on" : "off"), LogLevel.Info); }); helper.ConsoleCommands.Add("radar", "Toggle radar feature.", (string commmand, string[] args) => { MainClass.radar = !MainClass.radar; - MainClass.Monitor.Log("Radar " + (MainClass.radar ? "on" : "off"), LogLevel.Info); + MainClass.GetMonitor().Log("Radar " + (MainClass.radar ? "on" : "off"), LogLevel.Info); }); #region Radar Feature @@ -39,21 +39,21 @@ namespace stardew_access { MainClass.radarDebug = !MainClass.radarDebug; - MainClass.Monitor.Log("Radar debugging " + (MainClass.radarDebug ? "on" : "off"), LogLevel.Info); + MainClass.GetMonitor().Log("Radar debugging " + (MainClass.radarDebug ? "on" : "off"), LogLevel.Info); }); helper.ConsoleCommands.Add("rstereo", "Toggle stereo sound in radar feature.", (string commmand, string[] args) => { MainClass.radarStereoSound = !MainClass.radarStereoSound; - MainClass.Monitor.Log("Stereo sound is " + (MainClass.radarStereoSound ? "on" : "off"), LogLevel.Info); + MainClass.GetMonitor().Log("Stereo sound is " + (MainClass.radarStereoSound ? "on" : "off"), LogLevel.Info); }); helper.ConsoleCommands.Add("rfocus", "Toggle focus mode in radar feature.", (string commmand, string[] args) => { bool focus = MainClass.RadarFeature.ToggleFocus(); - MainClass.Monitor.Log("Focus mode is " + (focus ? "on" : "off"), LogLevel.Info); + MainClass.GetMonitor().Log("Focus mode is " + (focus ? "on" : "off"), LogLevel.Info); }); helper.ConsoleCommands.Add("rdelay", "Set the delay of radar feature in milliseconds.", (string commmand, string[] args) => @@ -72,19 +72,19 @@ namespace stardew_access { MainClass.RadarFeature.delay = delay; if (delay >= 1000) - MainClass.Monitor.Log($"Delay set to {MainClass.RadarFeature.delay} milliseconds.", LogLevel.Info); + MainClass.GetMonitor().Log($"Delay set to {MainClass.RadarFeature.delay} milliseconds.", LogLevel.Info); else - MainClass.Monitor.Log($"Delay should be atleast 1 second or 1000 millisecond long.", LogLevel.Info); + MainClass.GetMonitor().Log($"Delay should be atleast 1 second or 1000 millisecond long.", LogLevel.Info); } else { - MainClass.Monitor.Log("Invalid delay amount, it can only be in numeric form.", LogLevel.Info); + MainClass.GetMonitor().Log("Invalid delay amount, it can only be in numeric form.", LogLevel.Info); } } else { - MainClass.Monitor.Log("Enter the delay amount (in milliseconds)!", LogLevel.Info); + MainClass.GetMonitor().Log("Enter the delay amount (in milliseconds)!", LogLevel.Info); } }); @@ -105,19 +105,19 @@ namespace stardew_access { MainClass.RadarFeature.range = range; if (range >= 2 && range <= 10) - MainClass.Monitor.Log($"Range set to {MainClass.RadarFeature.range}.", LogLevel.Info); + MainClass.GetMonitor().Log($"Range set to {MainClass.RadarFeature.range}.", LogLevel.Info); else - MainClass.Monitor.Log($"Range should be atleast 2 and maximum 10.", LogLevel.Info); + MainClass.GetMonitor().Log($"Range should be atleast 2 and maximum 10.", LogLevel.Info); } else { - MainClass.Monitor.Log("Invalid range amount, it can only be in numeric form.", LogLevel.Info); + MainClass.GetMonitor().Log("Invalid range amount, it can only be in numeric form.", LogLevel.Info); } } else { - MainClass.Monitor.Log("Enter the range amount!", LogLevel.Info); + MainClass.GetMonitor().Log("Enter the range amount!", LogLevel.Info); } }); @@ -136,16 +136,16 @@ namespace stardew_access if (!MainClass.RadarFeature.exclusions.Contains(keyToAdd)) { MainClass.RadarFeature.exclusions.Add(keyToAdd); - MainClass.Monitor.Log($"Added {keyToAdd} key to exclusions list.", LogLevel.Info); + MainClass.GetMonitor().Log($"Added {keyToAdd} key to exclusions list.", LogLevel.Info); } else { - MainClass.Monitor.Log($"{keyToAdd} key already present in the list.", LogLevel.Info); + MainClass.GetMonitor().Log($"{keyToAdd} key already present in the list.", LogLevel.Info); } } else { - MainClass.Monitor.Log("Unable to add the key to exclusions list.", LogLevel.Info); + MainClass.GetMonitor().Log("Unable to add the key to exclusions list.", LogLevel.Info); } }); @@ -161,16 +161,16 @@ namespace stardew_access if (MainClass.RadarFeature.exclusions.Contains(keyToAdd)) { MainClass.RadarFeature.exclusions.Remove(keyToAdd); - MainClass.Monitor.Log($"Removed {keyToAdd} key from exclusions list.", LogLevel.Info); + MainClass.GetMonitor().Log($"Removed {keyToAdd} key from exclusions list.", LogLevel.Info); } else { - MainClass.Monitor.Log($"Cannot find {keyToAdd} key in exclusions list.", LogLevel.Info); + MainClass.GetMonitor().Log($"Cannot find {keyToAdd} key in exclusions list.", LogLevel.Info); } } else { - MainClass.Monitor.Log("Unable to remove the key from exclusions list.", LogLevel.Info); + MainClass.GetMonitor().Log("Unable to remove the key from exclusions list.", LogLevel.Info); } }); @@ -183,23 +183,23 @@ namespace stardew_access { toPrint = $"{toPrint}\t{i + 1}: {MainClass.RadarFeature.exclusions[i]}"; } - MainClass.Monitor.Log(toPrint, LogLevel.Info); + MainClass.GetMonitor().Log(toPrint, LogLevel.Info); } else { - MainClass.Monitor.Log("No exclusions found.", LogLevel.Info); + MainClass.GetMonitor().Log("No exclusions found.", LogLevel.Info); } }); helper.ConsoleCommands.Add("reclear", "Clear the focus exclusions in the radar featrure.", (string commmand, string[] args) => { MainClass.RadarFeature.exclusions.Clear(); - MainClass.Monitor.Log($"Cleared the focus list in the exclusions feature.", LogLevel.Info); + MainClass.GetMonitor().Log($"Cleared the focus list in the exclusions feature.", LogLevel.Info); }); helper.ConsoleCommands.Add("recount", "Number of exclusions in the radar feature.", (string commmand, string[] args) => { - MainClass.Monitor.Log($"There are {MainClass.RadarFeature.exclusions.Count} exclusiond in the radar feature.", LogLevel.Info); + MainClass.GetMonitor().Log($"There are {MainClass.RadarFeature.exclusions.Count} exclusiond in the radar feature.", LogLevel.Info); }); #endregion @@ -216,16 +216,16 @@ namespace stardew_access if (!MainClass.RadarFeature.focus.Contains(keyToAdd)) { MainClass.RadarFeature.focus.Add(keyToAdd); - MainClass.Monitor.Log($"Added {keyToAdd} key to focus list.", LogLevel.Info); + MainClass.GetMonitor().Log($"Added {keyToAdd} key to focus list.", LogLevel.Info); } else { - MainClass.Monitor.Log($"{keyToAdd} key already present in the list.", LogLevel.Info); + MainClass.GetMonitor().Log($"{keyToAdd} key already present in the list.", LogLevel.Info); } } else { - MainClass.Monitor.Log("Unable to add the key to focus list.", LogLevel.Info); + MainClass.GetMonitor().Log("Unable to add the key to focus list.", LogLevel.Info); } }); @@ -241,16 +241,16 @@ namespace stardew_access if (MainClass.RadarFeature.focus.Contains(keyToAdd)) { MainClass.RadarFeature.focus.Remove(keyToAdd); - MainClass.Monitor.Log($"Removed {keyToAdd} key from focus list.", LogLevel.Info); + MainClass.GetMonitor().Log($"Removed {keyToAdd} key from focus list.", LogLevel.Info); } else { - MainClass.Monitor.Log($"Cannot find {keyToAdd} key in focus list.", LogLevel.Info); + MainClass.GetMonitor().Log($"Cannot find {keyToAdd} key in focus list.", LogLevel.Info); } } else { - MainClass.Monitor.Log("Unable to remove the key from focus list.", LogLevel.Info); + MainClass.GetMonitor().Log("Unable to remove the key from focus list.", LogLevel.Info); } }); @@ -263,23 +263,23 @@ namespace stardew_access { toPrint = $"{toPrint}\t{i + 1}): {MainClass.RadarFeature.focus[i]}"; } - MainClass.Monitor.Log(toPrint, LogLevel.Info); + MainClass.GetMonitor().Log(toPrint, LogLevel.Info); } else { - MainClass.Monitor.Log("No objects found in the focus list.", LogLevel.Info); + MainClass.GetMonitor().Log("No objects found in the focus list.", LogLevel.Info); } }); helper.ConsoleCommands.Add("rfclear", "Clear the focus list in the radar featrure.", (string commmand, string[] args) => { MainClass.RadarFeature.focus.Clear(); - MainClass.Monitor.Log($"Cleared the focus list in the radar feature.", LogLevel.Info); + MainClass.GetMonitor().Log($"Cleared the focus list in the radar feature.", LogLevel.Info); }); helper.ConsoleCommands.Add("rfcount", "Number of list in the radar feature.", (string commmand, string[] args) => { - MainClass.Monitor.Log($"There are {MainClass.RadarFeature.focus.Count} objects in the focus list in the radar feature.", LogLevel.Info); + MainClass.GetMonitor().Log($"There are {MainClass.RadarFeature.focus.Count} objects in the focus list in the radar feature.", LogLevel.Info); }); #endregion @@ -290,14 +290,14 @@ namespace stardew_access { if (Game1.currentLocation is not Farm) { - MainClass.Monitor.Log("Can only use this command in the farm", LogLevel.Info); + MainClass.GetMonitor().Log("Can only use this command in the farm", LogLevel.Info); return; } string? indexInString = args.ElementAtOrDefault(0); if (indexInString == null) { - MainClass.Monitor.Log("Enter the index too!", LogLevel.Info); + MainClass.GetMonitor().Log("Enter the index too!", LogLevel.Info); return; } @@ -306,12 +306,12 @@ namespace stardew_access if (!isParsable || !(index >= 0 && index <= 9)) { - MainClass.Monitor.Log("Index can only be a number and from 0 to 9 only", LogLevel.Info); + MainClass.GetMonitor().Log("Index can only be a number and from 0 to 9 only", LogLevel.Info); return; } 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 added at {index} index.", LogLevel.Info); + MainClass.GetMonitor().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) => @@ -326,16 +326,16 @@ namespace stardew_access } if (toPrint == "") - MainClass.Monitor.Log("No positions marked!", LogLevel.Info); + MainClass.GetMonitor().Log("No positions marked!", LogLevel.Info); else - MainClass.Monitor.Log($"Marked positions:{toPrint}\nOpen command menu and use pageup and pagedown to check the list", LogLevel.Info); + MainClass.GetMonitor().Log($"Marked positions:{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) => { if ((Game1.activeClickableMenu is not CarpenterMenu && Game1.activeClickableMenu is not PurchaseAnimalsMenu) || !BuildingNAnimalMenuPatches.isOnFarm) { - MainClass.Monitor.Log($"Cannot list buildings.", LogLevel.Info); + MainClass.GetMonitor().Log($"Cannot list buildings.", LogLevel.Info); return; } @@ -356,11 +356,11 @@ namespace stardew_access if (toPrint == "") { - MainClass.Monitor.Log("No appropriate buildings to list", LogLevel.Info); + MainClass.GetMonitor().Log("No appropriate buildings to list", LogLevel.Info); } else { - MainClass.Monitor.Log($"Available buildings:{toPrint}\nOpen command menu and use pageup and pagedown to check the list", LogLevel.Info); + MainClass.GetMonitor().Log($"Available buildings:{toPrint}\nOpen command menu and use pageup and pagedown to check the list", LogLevel.Info); } }); @@ -368,14 +368,14 @@ namespace stardew_access { if ((Game1.activeClickableMenu is not CarpenterMenu && Game1.activeClickableMenu is not PurchaseAnimalsMenu) || !BuildingNAnimalMenuPatches.isOnFarm) { - MainClass.Monitor.Log($"Cannot select building.", LogLevel.Info); + MainClass.GetMonitor().Log($"Cannot select building.", LogLevel.Info); return; } string? indexInString = args.ElementAtOrDefault(0); if (indexInString == null) { - MainClass.Monitor.Log("Enter the index of the building too! Use buildlist", LogLevel.Info); + MainClass.GetMonitor().Log("Enter the index of the building too! Use buildlist", LogLevel.Info); return; } @@ -384,11 +384,11 @@ namespace stardew_access if (!isParsable) { - MainClass.Monitor.Log("Index can only be a number.", LogLevel.Info); + MainClass.GetMonitor().Log("Index can only be a number.", LogLevel.Info); return; } - string positionIndexInString = args.ElementAtOrDefault(1); + string? positionIndexInString = args.ElementAtOrDefault(1); int positionIndex = 0; if (BuildingNAnimalMenuPatches.isMoving) @@ -398,13 +398,13 @@ namespace stardew_access { if (BuildingNAnimalMenuPatches.availableBuildings[index] == null) { - MainClass.Monitor.Log($"No building found with index {index}. Use buildlist.", LogLevel.Info); + MainClass.GetMonitor().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); + MainClass.GetMonitor().Log("Enter the index of marked place too! Use marklist.", LogLevel.Info); return; } @@ -412,7 +412,7 @@ namespace stardew_access if (!isParsable) { - MainClass.Monitor.Log("Index can only be a number.", LogLevel.Info); + MainClass.GetMonitor().Log("Index can only be a number.", LogLevel.Info); return; } } @@ -421,7 +421,7 @@ namespace stardew_access { if (BuildingNAnimalMenuPatches.marked[index] == Vector2.Zero) { - MainClass.Monitor.Log($"No marked position found at {index} index.", LogLevel.Info); + MainClass.GetMonitor().Log($"No marked position found at {index} index.", LogLevel.Info); return; } } @@ -429,7 +429,7 @@ namespace stardew_access { if (BuildingNAnimalMenuPatches.availableBuildings[index] == null) { - MainClass.Monitor.Log($"No building found with index {index}. Use buildlist.", LogLevel.Info); + MainClass.GetMonitor().Log($"No building found with index {index}. Use buildlist.", LogLevel.Info); return; } } @@ -448,16 +448,16 @@ namespace stardew_access if (response != null) { - MainClass.Monitor.Log(response, LogLevel.Info); + MainClass.GetMonitor().Log(response, LogLevel.Info); } }); #endregion helper.ConsoleCommands.Add("refsr", "Refresh screen reader", (string commmand, string[] args) => { - MainClass.ScreenReader.InitializeScreenReader(); + MainClass.GetScreenReader().InitializeScreenReader(); - MainClass.Monitor.Log("Screen Reader refreshed!", LogLevel.Info); + MainClass.GetMonitor().Log("Screen Reader refreshed!", LogLevel.Info); }); } } diff --git a/stardew-access/CustomSoundEffects.cs b/stardew-access/CustomSoundEffects.cs index c78bd4d..8ad60e9 100644 --- a/stardew-access/CustomSoundEffects.cs +++ b/stardew-access/CustomSoundEffects.cs @@ -71,7 +71,7 @@ namespace stardew_access } catch (Exception e) { - MainClass.Monitor.Log($"Unable to initialize custom sounds:\n{e.Message}\n{e.StackTrace}", LogLevel.Error); + MainClass.GetMonitor().Log($"Unable to initialize custom sounds:\n{e.Message}\n{e.StackTrace}", LogLevel.Error); } } } diff --git a/stardew-access/Features/Other.cs b/stardew-access/Features/Other.cs index 5c255af..922ce59 100644 --- a/stardew-access/Features/Other.cs +++ b/stardew-access/Features/Other.cs @@ -23,7 +23,7 @@ namespace stardew_access.Game return; previousSlotItem = currentSlotItem; - MainClass.ScreenReader.Say($"{currentSlotItem.DisplayName} Selected", true); + MainClass.GetScreenReader().Say($"{currentSlotItem.DisplayName} Selected", true); } // Narrates current location's name @@ -38,7 +38,7 @@ namespace stardew_access.Game return; previousLocation = currentLocation; - MainClass.ScreenReader.Say($"{currentLocation.Name} Entered", true); + MainClass.GetScreenReader().Say($"{currentLocation.Name} Entered", true); } public static void SnapMouseToPlayer() @@ -89,14 +89,14 @@ namespace stardew_access.Game { MainClass.hudMessageQueryKey = searchQuery; - MainClass.ScreenReader.Say(toSpeak, true); + MainClass.GetScreenReader().Say(toSpeak, true); } } } } catch (Exception e) { - MainClass.Monitor.Log($"Unable to narrate hud messages:\n{e.Message}\n{e.StackTrace}", StardewModdingAPI.LogLevel.Error); + MainClass.GetMonitor().Log($"Unable to narrate hud messages:\n{e.Message}\n{e.StackTrace}", StardewModdingAPI.LogLevel.Error); } await Task.Delay(300); diff --git a/stardew-access/Features/Radar.cs b/stardew-access/Features/Radar.cs index e9597ec..7bbcdf8 100644 --- a/stardew-access/Features/Radar.cs +++ b/stardew-access/Features/Radar.cs @@ -95,7 +95,7 @@ namespace stardew_access.Game public async void Run() { if (MainClass.radarDebug) - MainClass.Monitor.Log($"\n\nRead Tile started", StardewModdingAPI.LogLevel.Debug); + MainClass.GetMonitor().Log($"\n\nRead Tile started", StardewModdingAPI.LogLevel.Debug); isRunning = true; Vector2 currPosition = Game1.player.getTileLocation(); @@ -107,7 +107,7 @@ namespace stardew_access.Game BFS(currPosition, range); if (MainClass.radarDebug) - MainClass.Monitor.Log($"\nRead Tile stopped\n\n", StardewModdingAPI.LogLevel.Debug); + MainClass.GetMonitor().Log($"\nRead Tile stopped\n\n", StardewModdingAPI.LogLevel.Debug); await Task.Delay(delay); isRunning = false; @@ -241,7 +241,7 @@ namespace stardew_access.Game else if (terrainFeature.ContainsKey(position)) { Netcode.NetRef tr = terrainFeature[position]; - string? terrain = ReadTile.getTerrainFeatureAtTile(tr).ToLower(); + string? terrain = ReadTile.getTerrainFeatureAtTile(tr); if (terrain != null) { if (tr.Get() is HoeDirt) @@ -296,7 +296,7 @@ namespace stardew_access.Game PlaySoundAt(position, "ladder", CATEGORY.Buildings); } // Check for doors - else if (ReadTile.isDoorAtTile((int)position.X, (int)position.Y)) + else if (ReadTile.isDoorAtTile((int)position.X, (int)position.Y).Item1) { PlaySoundAt(position, "door", CATEGORY.Buildings); } @@ -304,7 +304,8 @@ namespace stardew_access.Game else if (ReadTile.getTileInfo((int)position.X, (int)position.Y).Item2 != null) { (CATEGORY?, string?) item = ReadTile.getTileInfo((int)position.X, (int)position.Y); - PlaySoundAt(position, item.Item2, item.Item1); + if (item.Item2 != null && item.Item1 != null) + PlaySoundAt(position, item.Item2, item.Item1); } // Check for resource clumps else if (ReadTile.getResourceClumpAtTile((int)position.X, (int)position.Y) != null) @@ -319,7 +320,7 @@ namespace stardew_access.Game } catch (Exception e) { - MainClass.Monitor.Log($"{e.Message}\n{e.StackTrace}\n{e.Source}", StardewModdingAPI.LogLevel.Error); + MainClass.GetMonitor().Log($"{e.Message}\n{e.StackTrace}\n{e.Source}", StardewModdingAPI.LogLevel.Error); } } @@ -371,7 +372,7 @@ namespace stardew_access.Game #endregion if (MainClass.radarDebug) - MainClass.Monitor.Log($"{radarFocus}\tObject:{searchQuery.ToLower().Trim()}\tPosition: X={position.X} Y={position.Y}", StardewModdingAPI.LogLevel.Debug); + MainClass.GetMonitor().Log($"{radarFocus}\tObject:{searchQuery.ToLower().Trim()}\tPosition: X={position.X} Y={position.Y}", StardewModdingAPI.LogLevel.Debug); int px = (int)Game1.player.getTileX(); // Player's X postion int py = (int)Game1.player.getTileY(); // Player's Y postion diff --git a/stardew-access/Features/ReadTile.cs b/stardew-access/Features/ReadTile.cs index 7b1831d..35715a6 100644 --- a/stardew-access/Features/ReadTile.cs +++ b/stardew-access/Features/ReadTile.cs @@ -25,163 +25,184 @@ namespace stardew_access.Game try { #region Get Next Grab Tile - Vector2 gt = CurrentPlayer.getNextTile(); - int x = (int)gt.X; - int y = (int)gt.Y; + Vector2 tile = CurrentPlayer.getNextTile(); + int x = (int)tile.X; + int y = (int)tile.Y; #endregion if (Context.IsPlayerFree) { - if (!manuallyTriggered && prevTile != gt) + if (!manuallyTriggered && prevTile != tile) { - if (MainClass.ScreenReader != null) - MainClass.ScreenReader.PrevTextTile = " "; + if (MainClass.GetScreenReader() != null) + MainClass.GetScreenReader().PrevTextTile = " "; } bool isColliding = isCollidingAtTile(x, y); - Dictionary> terrainFeature = Game1.currentLocation.terrainFeatures.FieldDict; - string? toSpeak = " "; + string? toSpeak = getNameAtTile(tile); - #region Get objects, crops, resource clumps, etc. - if (Game1.currentLocation.isCharacterAtTile(gt) != null) - { - NPC npc = Game1.currentLocation.isCharacterAtTile(gt); - toSpeak = npc.displayName; - } - else if (getFarmAnimalAt(Game1.currentLocation, x, y) != null) - { - toSpeak = getFarmAnimalAt(Game1.currentLocation, x, y); - } - else if (Game1.currentLocation.isWaterTile(x, y) && isColliding) - { - toSpeak = "Water"; - } - else if (Game1.currentLocation.isObjectAtTile(x, y)) - { - string? objectName = getObjectNameAtTile(x, y); - if (objectName != null) - toSpeak = objectName; - } - else if (terrainFeature.ContainsKey(gt)) - { - string? terrain = getTerrainFeatureAtTile(terrainFeature[gt]); - if (terrain != null) - toSpeak = terrain; - } - else if (Game1.currentLocation.getLargeTerrainFeatureAt(x, y) != null) - { - 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) - { - toSpeak = getResourceClumpAtTile(x, y); - } - else if (isDoorAtTile(x, y)) - { - toSpeak = "Door"; - } - else if (isMineDownLadderAtTile(x, y)) - { - toSpeak = "Ladder"; - } - else if (isMineUpLadderAtTile(x, y)) - { - toSpeak = "Up Ladder"; - } - else if (isElevatorAtTile(x, y)) - { - toSpeak = "Elevator"; - } - else if (getTileInfo(x, y).Item2 != null) - { - toSpeak = getTileInfo(x, y).Item2; - } - else if (getJunimoBundleAt(x, y) != null) - { - toSpeak = getJunimoBundleAt(x, y); - } - else if (getStumpsInWoods(x, y) != null) - { - toSpeak = getStumpsInWoods(x, y); - } - #endregion - #region Narrate toSpeak - if (toSpeak != " ") - if (manuallyTriggered) - MainClass.ScreenReader.Say(toSpeak, true); - else - MainClass.ScreenReader.SayWithTileQuery(toSpeak, x, y, true); + if (toSpeak != null) + if (MainClass.GetScreenReader() != null) + if (manuallyTriggered) + MainClass.GetScreenReader().Say(toSpeak, true); + else + MainClass.GetScreenReader().SayWithTileQuery(toSpeak, x, y, true); #endregion #region Play colliding sound effect - if (isColliding && prevTile != gt) + if (isColliding && prevTile != tile) { Game1.playSound("colliding"); } #endregion - prevTile = gt; + prevTile = tile; } } catch (Exception e) { - MainClass.Monitor.Log($"Error in Read Tile:\n{e.Message}\n{e.StackTrace}", LogLevel.Debug); + MainClass.GetMonitor().Log($"Error in Read Tile:\n{e.Message}\n{e.StackTrace}", LogLevel.Debug); } await Task.Delay(100); isReadingTile = false; } + public static string? getNameAtTile(Vector2 tile) + { + int x = (int)tile.X; + int y = (int)tile.Y; + string? toReturn = ""; + + bool isColliding = isCollidingAtTile(x, y); + Dictionary> terrainFeature = Game1.currentLocation.terrainFeatures.FieldDict; + (bool, string?) door = isDoorAtTile(x, y); + (CATEGORY?, string?) tileInfo = getTileInfo(x, y); + string? junimoBundle = getJunimoBundleAt(x, y); + string? resourceClump = getResourceClumpAtTile(x, y); + string? farmAnimal = getFarmAnimalAt(Game1.currentLocation, x, y); + + if (Game1.currentLocation.isCharacterAtTile(tile) != null) + { + NPC npc = Game1.currentLocation.isCharacterAtTile(tile); + toReturn = npc.displayName; + } + else if (farmAnimal != null) + { + toReturn = farmAnimal; + } + else if (Game1.currentLocation.isWaterTile(x, y) && isColliding) + { + toReturn = "Water"; + } + else if (Game1.currentLocation.isObjectAtTile(x, y)) + { + toReturn = getObjectNameAtTile(x, y); + } + else if (terrainFeature.ContainsKey(tile)) + { + string? terrain = getTerrainFeatureAtTile(terrainFeature[tile]); + if (terrain != null) + toReturn = terrain; + } + else if (Game1.currentLocation.getLargeTerrainFeatureAt(x, y) != null) + { + toReturn = getBushAtTile(x, y); + } + else if (resourceClump != null) + { + toReturn = resourceClump; + } + else if (door.Item1) + { + toReturn = (door.Item2 == null) ? "door" : door.Item2; + } + else if (isMineDownLadderAtTile(x, y)) + { + toReturn = "Ladder"; + } + else if (isMineUpLadderAtTile(x, y)) + { + toReturn = "Up Ladder"; + } + else if (isElevatorAtTile(x, y)) + { + toReturn = "Elevator"; + } + else if (tileInfo.Item2 != null) + { + toReturn = tileInfo.Item2; + } + else if (junimoBundle != null) + { + toReturn = junimoBundle; + } + + if (toReturn == "") + return null; + + return toReturn; + } + + public static string? getBushAtTile(int x, int y) + { + string? toReturn = null; + 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 null; + } + + toReturn = "Harvestable"; + } + #endregion + + if (bush.townBush) + toReturn = $"{toReturn} Town Bush"; + else if (bush.greenhouseBush) + toReturn = $"{toReturn} Greenhouse Bush"; + else + toReturn = $"{toReturn} Bush"; + + return toReturn; + } + public static string? getJunimoBundleAt(int x, int y) { if (Game1.currentLocation is not CommunityCenter) return null; -CommunityCenter communityCenter = (Game1.currentLocation as CommunityCenter); + + CommunityCenter communityCenter = ((CommunityCenter)Game1.currentLocation); string? name = (x, y) switch { @@ -223,9 +244,9 @@ CommunityCenter communityCenter = (Game1.currentLocation as CommunityCenter); List? farmAnimals = null; if (location is Farm) - farmAnimals = (location as Farm).getAllFarmAnimals(); + farmAnimals = ((Farm)location).getAllFarmAnimals(); else if (location is AnimalHouse) - farmAnimals = (location as AnimalHouse).animals.Values.ToList(); + farmAnimals = ((AnimalHouse)location).animals.Values.ToList(); if (farmAnimals == null || farmAnimals.Count <= 0) return null; @@ -314,7 +335,7 @@ CommunityCenter communityCenter = (Game1.currentLocation as CommunityCenter); return (null, null); } - public static string getTerrainFeatureAtTile(Netcode.NetRef terrain) + public static string? getTerrainFeatureAtTile(Netcode.NetRef terrain) { string? toReturn = null; if (terrain.Get() is HoeDirt) @@ -353,7 +374,7 @@ CommunityCenter communityCenter = (Game1.currentLocation as CommunityCenter); } else if (terrain.Get() is GiantCrop) { - int whichCrop = (terrain.Get() as GiantCrop).which.Value; + int whichCrop = ((GiantCrop)terrain.Get()).which.Value; switch (whichCrop) { case 0: @@ -367,10 +388,6 @@ CommunityCenter communityCenter = (Game1.currentLocation as CommunityCenter); break; } } - else if (terrain.Get() is Bush) - { - toReturn = "Bush"; - } else if (terrain.Get() is CosmeticPlant) { CosmeticPlant cosmeticPlant = (CosmeticPlant)terrain.Get(); @@ -412,10 +429,6 @@ CommunityCenter communityCenter = (Game1.currentLocation as CommunityCenter); { toReturn = "Quartz"; } - else if (terrain.Get() is Leaf) - { - toReturn = "Leaf"; - } return toReturn; } @@ -565,8 +578,6 @@ CommunityCenter communityCenter = (Game1.currentLocation as CommunityCenter); case 816: case 817: return "Fossil stone"; - case 25: - return "Stone"; case 118: case 120: case 122: @@ -701,25 +712,29 @@ CommunityCenter communityCenter = (Game1.currentLocation as CommunityCenter); return false; } - public static bool isDoorAtTile(int x, int y) + public static (bool, string?) isDoorAtTile(int x, int y) { Point tilePoint = new Point(x, y); - List> doorList = Game1.currentLocation.doors.ToList(); + StardewValley.Network.NetPointDictionary doorList = Game1.currentLocation.doors; - for (int i = 0; i < doorList.Count; i++) + for (int i = 0; i < doorList.Count(); i++) { - for (int j = 0; j < doorList[i].Keys.Count; j++) + if (doorList.ContainsKey(tilePoint)) { - if (doorList[i].Keys.Contains(tilePoint)) - return true; + string? doorName; + doorList.TryGetValue(tilePoint, out doorName); + + return (true, doorName); } } - return false; + return (false, null); } public static string? getResourceClumpAtTile(int x, int y) { + if (Game1.currentLocation is Woods) + return getStumpsInWoods(x, y); for (int i = 0; i < Game1.currentLocation.resourceClumps.Count; i++) { @@ -750,10 +765,9 @@ CommunityCenter communityCenter = (Game1.currentLocation as CommunityCenter); return null; } - - public static string? getStumpsInWoods(int x, int y) + + public static string? getStumpsInWoods(int x, int y) { - string strIndex = null; if (Game1.currentLocation is not Woods) { return null; @@ -767,7 +781,7 @@ CommunityCenter communityCenter = (Game1.currentLocation as CommunityCenter); } } return null; - } + } } } diff --git a/stardew-access/ModEntry.cs b/stardew-access/ModEntry.cs index 0c35bf9..045777b 100644 --- a/stardew-access/ModEntry.cs +++ b/stardew-access/ModEntry.cs @@ -21,13 +21,32 @@ namespace stardew_access private static IMonitor monitor; public static string hudMessageQueryKey = ""; private static Radar radarFeature; - private static IScreenReader screenReader; + private static IScreenReader? screenReader; private static IModHelper modHelper; public static IModHelper ModHelper { get => modHelper; } public static Radar RadarFeature { get => radarFeature; set => radarFeature = value; } - public static IScreenReader ScreenReader { get => screenReader; set => screenReader = value; } - public static IMonitor Monitor { get => monitor; set => monitor = value; } + + public static IScreenReader GetScreenReader() + { + screenReader = new ScreenReaderController().Initialize(); + return screenReader; + } + + public static void SetScreenReader(IScreenReader value) + { + screenReader = value; + } + + public static IMonitor GetMonitor() + { + return monitor; + } + + public static void SetMonitor(IMonitor value) + { + monitor = value; + } /********* ** Public methods @@ -38,12 +57,12 @@ namespace stardew_access { #region Initializations - Monitor = base.Monitor; // Inititalize monitor + SetMonitor(base.Monitor); // Inititalize monitor modHelper = helper; Game1.options.setGamepadMode("force_on"); - ScreenReader = new ScreenReaderController().Initialize(); + SetScreenReader(new ScreenReaderController().Initialize()); CustomSoundEffects.Initialize(); @@ -75,14 +94,14 @@ namespace stardew_access public void OnExit(object? sender, EventArgs? e) { // Don't if this ever gets called or not but, just in case if it does. - if (ScreenReader != null) - ScreenReader.CloseScreenReader(); + if (GetScreenReader() != null) + GetScreenReader().CloseScreenReader(); } /// Returns the Screen Reader class for other mods to use. public override object GetApi() { - return new ScreenReaderAPI(); + return new API(); } private void onUpdateTicked(object? sender, UpdateTickedEventArgs? e) @@ -151,28 +170,28 @@ namespace stardew_access if (Equals(e.Button, SButton.H)) { string toSpeak = $"Health is {CurrentPlayer.getHealth()} and Stamina is {CurrentPlayer.getStamina()}"; - MainClass.ScreenReader.Say(toSpeak, true); + MainClass.GetScreenReader().Say(toSpeak, true); } // Narrate Position if (Equals(e.Button, SButton.K)) { string toSpeak = $"X: {CurrentPlayer.getPositionX()} , Y: {CurrentPlayer.getPositionY()}"; - MainClass.ScreenReader.Say(toSpeak, true); + MainClass.GetScreenReader().Say(toSpeak, true); } // Narrate money at hand if (Equals(e.Button, SButton.R)) { string toSpeak = $"You have {CurrentPlayer.getMoney()}g"; - MainClass.ScreenReader.Say(toSpeak, true); + MainClass.GetScreenReader().Say(toSpeak, true); } // Narrate time and season if (Equals(e.Button, SButton.Q)) { string toSpeak = $"Time is {CurrentPlayer.getTimeOfDay()} and it is {CurrentPlayer.getDay()} {CurrentPlayer.getDate()} of {CurrentPlayer.getSeason()}"; - MainClass.ScreenReader.Say(toSpeak, true); + MainClass.GetScreenReader().Say(toSpeak, true); } // Manual read tile diff --git a/stardew-access/Patches/BuildingNAnimalMenuPatches.cs b/stardew-access/Patches/BuildingNAnimalMenuPatches.cs index 5a3e4ae..7d346a4 100644 --- a/stardew-access/Patches/BuildingNAnimalMenuPatches.cs +++ b/stardew-access/Patches/BuildingNAnimalMenuPatches.cs @@ -61,7 +61,7 @@ namespace stardew_access.Patches firstTimeInNamingMenu = false; } - MainClass.ScreenReader.Say(toSpeak, true); + MainClass.GetScreenReader().Say(toSpeak, true); } } else if (___onFarm && !___namingAnimal) @@ -90,7 +90,7 @@ namespace stardew_access.Patches if (purchaseAnimalMenuQuery != toSpeak) { purchaseAnimalMenuQuery = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); + MainClass.GetScreenReader().Say(toSpeak, true); } return; } @@ -98,7 +98,7 @@ namespace stardew_access.Patches } catch (Exception e) { - MainClass.Monitor.Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error); + MainClass.GetMonitor().Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error); } } @@ -180,7 +180,7 @@ namespace stardew_access.Patches if (carpenterMenuQuery != toSpeak) { carpenterMenuQuery = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); + MainClass.GetScreenReader().Say(toSpeak, true); } return; } @@ -191,7 +191,7 @@ namespace stardew_access.Patches if (carpenterMenuQuery != toSpeak) { carpenterMenuQuery = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); + MainClass.GetScreenReader().Say(toSpeak, true); } return; } @@ -202,7 +202,7 @@ namespace stardew_access.Patches if (carpenterMenuQuery != toSpeak) { carpenterMenuQuery = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); + MainClass.GetScreenReader().Say(toSpeak, true); } return; } @@ -213,7 +213,7 @@ namespace stardew_access.Patches if (carpenterMenuQuery != toSpeak) { carpenterMenuQuery = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); + MainClass.GetScreenReader().Say(toSpeak, true); } return; } @@ -224,7 +224,7 @@ namespace stardew_access.Patches if (carpenterMenuQuery != toSpeak) { carpenterMenuQuery = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); + MainClass.GetScreenReader().Say(toSpeak, true); } return; } @@ -235,7 +235,7 @@ namespace stardew_access.Patches if (carpenterMenuQuery != toSpeak) { carpenterMenuQuery = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); + MainClass.GetScreenReader().Say(toSpeak, true); } return; } @@ -246,7 +246,7 @@ namespace stardew_access.Patches if (carpenterMenuQuery != toSpeak) { carpenterMenuQuery = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); + MainClass.GetScreenReader().Say(toSpeak, true); } return; } @@ -269,14 +269,14 @@ namespace stardew_access.Patches } catch (Exception e) { - MainClass.Monitor.Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error); + MainClass.GetMonitor().Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error); } } private static async void SayBlueprintInfo(string info) { isSayingBlueprintInfo = true; - MainClass.ScreenReader.Say(info, true); + MainClass.GetScreenReader().Say(info, true); await Task.Delay(300); isSayingBlueprintInfo = false; } @@ -288,7 +288,7 @@ namespace stardew_access.Patches string? response = null; // This code is taken from the game's code (CarpenterMenu.cs::654) - Farm farm = Game1.getLocationFromName("Farm") as Farm; + Farm farm = (Farm)Game1.getLocationFromName("Farm"); Action buildingLockFailed = delegate { if (isDemolishing) @@ -304,7 +304,7 @@ namespace stardew_access.Patches { response = Game1.content.LoadString("Strings\\UI:Carpenter_CantDemolish_DuringConstruction"); } - else if (toDemolish.indoors.Value != null && toDemolish.indoors.Value is AnimalHouse && (toDemolish.indoors.Value as AnimalHouse).animalsThatLiveHere.Count > 0) + else if (toDemolish.indoors.Value != null && toDemolish.indoors.Value is AnimalHouse && ((AnimalHouse)toDemolish.indoors.Value).animalsThatLiveHere.Count > 0) { response = Game1.content.LoadString("Strings\\UI:Carpenter_CantDemolish_AnimalsHere"); } @@ -318,24 +318,24 @@ namespace stardew_access.Patches { foreach (Farmer current in Game1.getAllFarmers()) { - if (current.currentLocation != null && current.currentLocation.Name == (toDemolish.indoors.Value as Cabin).GetCellarName()) + if (current.currentLocation != null && current.currentLocation.Name == ((Cabin)toDemolish.indoors.Value).GetCellarName()) { response = Game1.content.LoadString("Strings\\UI:Carpenter_CantDemolish_PlayerHere"); return; } } } - if (toDemolish.indoors.Value is Cabin && (toDemolish.indoors.Value as Cabin).farmhand.Value.isActive()) + if (toDemolish.indoors.Value is Cabin && ((Cabin)toDemolish.indoors.Value).farmhand.Value.isActive()) { response = Game1.content.LoadString("Strings\\UI:Carpenter_CantDemolish_FarmhandOnline"); } else { toDemolish.BeforeDemolish(); - Chest chest = null; + Chest? chest = null; if (toDemolish.indoors.Value is Cabin) { - List list = (toDemolish.indoors.Value as Cabin).demolish(); + List list = ((Cabin)toDemolish.indoors.Value).demolish(); if (list.Count > 0) { chest = new Chest(playerChest: true); @@ -351,7 +351,8 @@ namespace stardew_access.Patches toDemolish.showDestroyedAnimation(Game1.getFarm()); Game1.playSound("explosion"); Utility.spreadAnimalsAround(toDemolish, farm); - DelayedAction.functionAfterDelay(carpenterMenu.returnToCarpentryMenu, 1500); + if (carpenterMenu != null) + DelayedAction.functionAfterDelay(carpenterMenu.returnToCarpentryMenu, 1500); // freeze = true; if (chest != null) { @@ -370,12 +371,12 @@ namespace stardew_access.Patches toDemolish = null; return response; } - if (!carpenterMenu.CanDemolishThis(toDemolish)) + if (carpenterMenu != null && !carpenterMenu.CanDemolishThis(toDemolish)) { toDemolish = null; return response; } - if (!Game1.IsMasterGame && !carpenterMenu.hasPermissionsToDemolish(toDemolish)) + if (carpenterMenu != null && !Game1.IsMasterGame && !carpenterMenu.hasPermissionsToDemolish(toDemolish)) { toDemolish = null; return response; @@ -383,7 +384,7 @@ namespace stardew_access.Patches } if (toDemolish != null && toDemolish.indoors.Value is Cabin) { - Cabin cabin = toDemolish.indoors.Value as Cabin; + Cabin cabin = (Cabin)toDemolish.indoors.Value; if (cabin.farmhand.Value != null && (bool)cabin.farmhand.Value.isCustomized) { Game1.currentLocation.createQuestionDialogue(Game1.content.LoadString("Strings\\UI:Carpenter_DemolishCabinConfirm", cabin.farmhand.Value.Name), Game1.currentLocation.createYesNoResponses(), delegate (Farmer f, string answer) @@ -395,7 +396,8 @@ namespace stardew_access.Patches } else { - DelayedAction.functionAfterDelay(carpenterMenu.returnToCarpentryMenu, 1000); + if (carpenterMenu != null) + DelayedAction.functionAfterDelay(carpenterMenu.returnToCarpentryMenu, 1000); } }); return response; @@ -419,8 +421,11 @@ namespace stardew_access.Patches { if (tryToBuild(position)) { - carpenterMenu.CurrentBlueprint.consumeResources(); - DelayedAction.functionAfterDelay(carpenterMenu.returnToCarpentryMenuAfterSuccessfulBuild, 2000); + if (carpenterMenu != null) + { + carpenterMenu.CurrentBlueprint.consumeResources(); + DelayedAction.functionAfterDelay(carpenterMenu.returnToCarpentryMenuAfterSuccessfulBuild, 2000); + } // freeze = true; } else @@ -436,6 +441,8 @@ namespace stardew_access.Patches public static bool tryToBuild(Vector2 position) { + if (carpenterMenu == null) + return false; return ((Farm)Game1.getLocationFromName("Farm")).buildStructure(carpenterMenu.CurrentBlueprint, position, Game1.player, isMagicalConstruction); } @@ -443,7 +450,7 @@ namespace stardew_access.Patches { string? response = null; // This code is taken from the game's code (CarpenterMenu.cs::775) - if (toUpgrade != null && carpenterMenu.CurrentBlueprint.name != null && toUpgrade.buildingType.Equals(carpenterMenu.CurrentBlueprint.nameOfBuildingToUpgrade)) + if (carpenterMenu != null && toUpgrade != null && carpenterMenu.CurrentBlueprint.name != null && toUpgrade.buildingType.Equals(carpenterMenu.CurrentBlueprint.nameOfBuildingToUpgrade)) { carpenterMenu.CurrentBlueprint.consumeResources(); toUpgrade.daysUntilUpgrade.Value = 2; @@ -472,13 +479,15 @@ namespace stardew_access.Patches response = Game1.content.LoadString("Strings\\UI:Carpenter_CannotPaint"); return response; } - if (!carpenterMenu.HasPermissionsToPaint(toPaint)) + if (carpenterMenu != null && !carpenterMenu.HasPermissionsToPaint(toPaint)) { response = Game1.content.LoadString("Strings\\UI:Carpenter_CannotPaint_Permission"); return response; } toPaint.color.Value = Color.White; - carpenterMenu.SetChildMenu(new BuildingPaintMenu(toPaint)); + + if (carpenterMenu != null) + carpenterMenu.SetChildMenu(new BuildingPaintMenu(toPaint)); } /* TODO Add painting of farm house else if (farm_location.GetHouseRect().Contains(Utility.Vector2ToPoint(new Vector2(toPaint.tileX, toPaint.tileY)))) @@ -513,7 +522,7 @@ namespace stardew_access.Patches buildingToMove = null; return "Building under construction, cannot move"; } - if (!carpenterMenu.hasPermissionsToMove(buildingToMove)) + if (carpenterMenu != null && !carpenterMenu.hasPermissionsToMove(buildingToMove)) { buildingToMove = null; return "You don't have permission to move this building"; @@ -524,7 +533,7 @@ namespace stardew_access.Patches { if (buildingToMove is ShippingBin) { - (buildingToMove as ShippingBin).initLid(); + ((ShippingBin)buildingToMove).initLid(); } if (buildingToMove is GreenhouseBuilding) { diff --git a/stardew-access/Patches/ChatManuPatches.cs b/stardew-access/Patches/ChatManuPatches.cs index 9bee711..66b7b0a 100644 --- a/stardew-access/Patches/ChatManuPatches.cs +++ b/stardew-access/Patches/ChatManuPatches.cs @@ -42,13 +42,13 @@ namespace stardew_access.Patches toSpeak += $"{message.message}, "; }); if (toSpeak != " ") - MainClass.ScreenReader.SayWithChatChecker(toSpeak, false); + MainClass.GetScreenReader().SayWithChatChecker(toSpeak, false); #endregion } } catch (Exception e) { - MainClass.Monitor.Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error); + MainClass.GetMonitor().Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error); } } @@ -77,7 +77,7 @@ namespace stardew_access.Patches toSpeak += $"{message.message}, "; }); - MainClass.ScreenReader.Say(toSpeak, true); + MainClass.GetScreenReader().Say(toSpeak, true); await Task.Delay(200); isChatRunning = false; } diff --git a/stardew-access/Patches/DialoguePatches.cs b/stardew-access/Patches/DialoguePatches.cs index 651a682..c4e63d7 100644 --- a/stardew-access/Patches/DialoguePatches.cs +++ b/stardew-access/Patches/DialoguePatches.cs @@ -49,9 +49,9 @@ namespace stardew_access.Patches if (toSpeak != " ") { if (hasResponses) - MainClass.ScreenReader.SayWithChecker(toSpeak, false); + MainClass.GetScreenReader().SayWithChecker(toSpeak, false); else - MainClass.ScreenReader.SayWithChecker(toSpeak, true); + MainClass.GetScreenReader().SayWithChecker(toSpeak, true); } } else if (__instance.isQuestion) @@ -80,9 +80,9 @@ namespace stardew_access.Patches if (toSpeak != " ") { if (hasResponses) - MainClass.ScreenReader.SayWithChecker(toSpeak, false); + MainClass.GetScreenReader().SayWithChecker(toSpeak, false); else - MainClass.ScreenReader.SayWithChecker(toSpeak, true); + MainClass.GetScreenReader().SayWithChecker(toSpeak, true); } } else if (Game1.activeClickableMenu is DialogueBox) @@ -91,13 +91,13 @@ namespace stardew_access.Patches if (currentDialogue != __instance.getCurrentString()) { currentDialogue = __instance.getCurrentString(); - MainClass.ScreenReader.Say(__instance.getCurrentString(), true); + MainClass.GetScreenReader().Say(__instance.getCurrentString(), true); } } } catch (Exception e) { - MainClass.Monitor.Log($"Unable to narrate dialog:\n{e.StackTrace}\n{e.Message}", LogLevel.Error); + MainClass.GetMonitor().Log($"Unable to narrate dialog:\n{e.StackTrace}\n{e.Message}", LogLevel.Error); } } @@ -273,15 +273,15 @@ namespace stardew_access.Patches if (toSpeak.ToString() != " ") { if (Context.IsPlayerFree) - MainClass.ScreenReader.SayWithChecker(toSpeak.ToString(), true); // Normal Checker + MainClass.GetScreenReader().SayWithChecker(toSpeak.ToString(), true); // Normal Checker else - MainClass.ScreenReader.SayWithMenuChecker(toSpeak.ToString(), true); // Menu Checker + MainClass.GetScreenReader().SayWithMenuChecker(toSpeak.ToString(), true); // Menu Checker } #endregion } catch (Exception e) { - MainClass.Monitor.Log($"Unable to narrate dialog:\n{e.StackTrace}\n{e.Message}", LogLevel.Error); + MainClass.GetMonitor().Log($"Unable to narrate dialog:\n{e.StackTrace}\n{e.Message}", LogLevel.Error); } } } diff --git a/stardew-access/Patches/GameMenuPatches.cs b/stardew-access/Patches/GameMenuPatches.cs index 6c1cda3..08ca10a 100644 --- a/stardew-access/Patches/GameMenuPatches.cs +++ b/stardew-access/Patches/GameMenuPatches.cs @@ -42,7 +42,7 @@ namespace stardew_access.Patches if (junimoNoteMenuQuery != toSpeak) { junimoNoteMenuQuery = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); + MainClass.GetScreenReader().Say(toSpeak, true); } return; } @@ -54,7 +54,7 @@ namespace stardew_access.Patches if (junimoNoteMenuQuery != toSpeak) { junimoNoteMenuQuery = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); + MainClass.GetScreenReader().Say(toSpeak, true); } return; } @@ -65,7 +65,7 @@ namespace stardew_access.Patches if (junimoNoteMenuQuery != toSpeak) { junimoNoteMenuQuery = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); + MainClass.GetScreenReader().Say(toSpeak, true); } return; } @@ -77,7 +77,7 @@ namespace stardew_access.Patches if (junimoNoteMenuQuery != toSpeak) { junimoNoteMenuQuery = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); + MainClass.GetScreenReader().Say(toSpeak, true); } return; } @@ -87,7 +87,7 @@ namespace stardew_access.Patches if (junimoNoteMenuQuery != toSpeak) { junimoNoteMenuQuery = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); + MainClass.GetScreenReader().Say(toSpeak, true); } return; } @@ -117,19 +117,19 @@ namespace stardew_access.Patches else if (isBackPressed && __instance.backButton != null && !__instance.backButton.containsPoint(x, y)) { __instance.backButton.snapMouseCursorToCenter(); - MainClass.ScreenReader.Say("Back Button", true); + MainClass.GetScreenReader().Say("Back Button", true); } else if (isPPressed && __instance.purchaseButton != null && !__instance.purchaseButton.containsPoint(x, y)) { __instance.purchaseButton.snapMouseCursorToCenter(); - MainClass.ScreenReader.Say("Purchase Button", true); + MainClass.GetScreenReader().Say("Purchase Button", true); } } string reward = __instance.getRewardNameForArea(___whichArea); } catch (Exception e) { - MainClass.Monitor.Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error); + MainClass.GetMonitor().Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error); } } @@ -193,7 +193,7 @@ namespace stardew_access.Patches toSpeak = $"Completed {toSpeak}"; c.snapMouseCursorToCenter(); - MainClass.ScreenReader.Say(toSpeak, true); + MainClass.GetScreenReader().Say(toSpeak, true); } } break; @@ -228,7 +228,7 @@ namespace stardew_access.Patches } c.snapMouseCursorToCenter(); - MainClass.ScreenReader.Say(toSpeak, true); + MainClass.GetScreenReader().Say(toSpeak, true); } } break; @@ -281,7 +281,7 @@ namespace stardew_access.Patches toSpeak = "Empty Slot"; } c.snapMouseCursorToCenter(); - MainClass.ScreenReader.Say(toSpeak, true); + MainClass.GetScreenReader().Say(toSpeak, true); } } break; @@ -289,15 +289,15 @@ namespace stardew_access.Patches } catch (Exception e) { - MainClass.Monitor.Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error); + MainClass.GetMonitor().Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error); } await Task.Delay(200); isUsingCustomButtons = false; } - + internal static void SocialPagePatch(SocialPage __instance, List ___sprites, int ___slotPosition, List ___kidsNames) - { + { try { int x = Game1.getMouseX(), y = Game1.getMouseY(); // Mouse x and y position @@ -335,54 +335,54 @@ namespace stardew_access.Patches { toSpeak = $"{toSpeak}, not talked yet"; } - - - if (datable | housemate) - { - string text2 = (LocalizedContentManager.CurrentLanguageCode != LocalizedContentManager.LanguageCode.pt) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11635") : ((__instance.getGender(name) == 0) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11635").Split('/').First() : Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11635").Split('/').Last()); - if (housemate) - { - text2 = Game1.content.LoadString("Strings\\StringsFromCSFiles:Housemate"); - } - else if (spouse) - { - text2 = ((__instance.getGender(name) == 0) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11636") : Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11637")); - } - else if (__instance.isMarriedToAnyone(name)) - { - text2 = ((__instance.getGender(name) == 0) ? Game1.content.LoadString("Strings\\UI:SocialPage_MarriedToOtherPlayer_MaleNPC") : Game1.content.LoadString("Strings\\UI:SocialPage_MarriedToOtherPlayer_FemaleNPC")); - } - else if (!Game1.player.isMarried() && friendship.IsDating()) - { - text2 = ((__instance.getGender(name) == 0) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11639") : Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11640")); - } - else if (__instance.getFriendship(name).IsDivorced()) - { - text2 = ((__instance.getGender(name) == 0) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11642") : Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11643")); - } - toSpeak = $"{toSpeak}, {text2}"; + + if (datable | housemate) + { + string text2 = (LocalizedContentManager.CurrentLanguageCode != LocalizedContentManager.LanguageCode.pt) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11635") : ((__instance.getGender(name) == 0) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11635").Split('/').First() : Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11635").Split('/').Last()); + if (housemate) + { + text2 = Game1.content.LoadString("Strings\\StringsFromCSFiles:Housemate"); } - if (!__instance.getFriendship(name).IsMarried() && ___kidsNames.Contains(name)) + else if (spouse) { - toSpeak = $"{toSpeak}, married"; - } - if (spouse) - { - toSpeak = $"{toSpeak}, spouse"; + text2 = ((__instance.getGender(name) == 0) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11636") : Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11637")); } - else if (friendship.IsDating()) + else if (__instance.isMarriedToAnyone(name)) { - toSpeak = $"{toSpeak}, dating"; + text2 = ((__instance.getGender(name) == 0) ? Game1.content.LoadString("Strings\\UI:SocialPage_MarriedToOtherPlayer_MaleNPC") : Game1.content.LoadString("Strings\\UI:SocialPage_MarriedToOtherPlayer_FemaleNPC")); + } + else if (!Game1.player.isMarried() && friendship.IsDating()) + { + text2 = ((__instance.getGender(name) == 0) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11639") : Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11640")); + } + else if (__instance.getFriendship(name).IsDivorced()) + { + text2 = ((__instance.getGender(name) == 0) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11642") : Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11643")); } - toSpeak = $"{toSpeak}, {heartLevel} hearts, {giftsThisWeek} gifts given this week."; - + toSpeak = $"{toSpeak}, {text2}"; + } + if (!__instance.getFriendship(name).IsMarried() && ___kidsNames.Contains(name)) + { + toSpeak = $"{toSpeak}, married"; + } + if (spouse) + { + toSpeak = $"{toSpeak}, spouse"; + } + else if (friendship.IsDating()) + { + toSpeak = $"{toSpeak}, dating"; + } + + toSpeak = $"{toSpeak}, {heartLevel} hearts, {giftsThisWeek} gifts given this week."; + if (socialPageQuery != toSpeak) { socialPageQuery = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); + MainClass.GetScreenReader().Say(toSpeak, true); } return; } @@ -427,7 +427,7 @@ namespace stardew_access.Patches if (socialPageQuery != toSpeak) { socialPageQuery = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); + MainClass.GetScreenReader().Say(toSpeak, true); } return; } @@ -440,7 +440,7 @@ namespace stardew_access.Patches } catch (Exception e) { - MainClass.Monitor.Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error); + MainClass.GetMonitor().Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error); } } @@ -471,7 +471,7 @@ namespace stardew_access.Patches { shopMenuQueryKey = toSpeak; hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); + MainClass.GetScreenReader().Say(toSpeak, true); Game1.playSound("drop_item"); } return; @@ -483,7 +483,7 @@ namespace stardew_access.Patches { shopMenuQueryKey = toSpeak; hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); + MainClass.GetScreenReader().Say(toSpeak, true); } return; } @@ -494,7 +494,7 @@ namespace stardew_access.Patches { shopMenuQueryKey = toSpeak; hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); + MainClass.GetScreenReader().Say(toSpeak, true); } return; } @@ -541,14 +541,14 @@ namespace stardew_access.Patches { shopMenuQueryKey = toSpeak; hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); + MainClass.GetScreenReader().Say(toSpeak, true); } } #endregion } catch (Exception e) { - MainClass.Monitor.Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error); + MainClass.GetMonitor().Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error); } } @@ -570,7 +570,7 @@ namespace stardew_access.Patches if (gameMenuQueryKey != toSpeak) { gameMenuQueryKey = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); + MainClass.GetScreenReader().Say(toSpeak, true); } return; } @@ -578,7 +578,7 @@ namespace stardew_access.Patches } catch (Exception e) { - MainClass.Monitor.Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error); + MainClass.GetMonitor().Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error); } } @@ -599,7 +599,7 @@ namespace stardew_access.Patches if (geodeMenuQueryKey != toSpeak) { geodeMenuQueryKey = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); + MainClass.GetScreenReader().Say(toSpeak, true); } return; } @@ -612,7 +612,7 @@ namespace stardew_access.Patches if (geodeMenuQueryKey != toSpeak) { geodeMenuQueryKey = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); + MainClass.GetScreenReader().Say(toSpeak, true); } return; } @@ -624,7 +624,7 @@ namespace stardew_access.Patches if (geodeMenuQueryKey != toSpeak) { geodeMenuQueryKey = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); + MainClass.GetScreenReader().Say(toSpeak, true); Game1.playSound("drop_item"); } return; @@ -637,7 +637,7 @@ namespace stardew_access.Patches if (geodeMenuQueryKey != toSpeak) { geodeMenuQueryKey = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); + MainClass.GetScreenReader().Say(toSpeak, true); } return; } @@ -649,7 +649,7 @@ namespace stardew_access.Patches if (geodeMenuQueryKey != toSpeak) { geodeMenuQueryKey = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); + MainClass.GetScreenReader().Say(toSpeak, true); } return; } @@ -662,7 +662,7 @@ namespace stardew_access.Patches } catch (Exception e) { - MainClass.Monitor.Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error); + MainClass.GetMonitor().Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error); } } @@ -694,7 +694,7 @@ namespace stardew_access.Patches itemGrabMenuQueryKey = toSpeak; hoveredItemQueryKey = ""; gameMenuQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); + MainClass.GetScreenReader().Say(toSpeak, true); } return; } @@ -706,7 +706,7 @@ namespace stardew_access.Patches itemGrabMenuQueryKey = toSpeak; gameMenuQueryKey = ""; hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); + MainClass.GetScreenReader().Say(toSpeak, true); } return; } @@ -719,7 +719,7 @@ namespace stardew_access.Patches itemGrabMenuQueryKey = toSpeak; gameMenuQueryKey = ""; hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); + MainClass.GetScreenReader().Say(toSpeak, true); } return; } @@ -732,7 +732,7 @@ namespace stardew_access.Patches itemGrabMenuQueryKey = toSpeak; gameMenuQueryKey = ""; hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); + MainClass.GetScreenReader().Say(toSpeak, true); } return; } @@ -745,7 +745,7 @@ namespace stardew_access.Patches itemGrabMenuQueryKey = toSpeak; gameMenuQueryKey = ""; hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); + MainClass.GetScreenReader().Say(toSpeak, true); } return; } @@ -759,7 +759,7 @@ namespace stardew_access.Patches itemGrabMenuQueryKey = toSpeak; gameMenuQueryKey = ""; hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); + MainClass.GetScreenReader().Say(toSpeak, true); } return; } @@ -773,7 +773,7 @@ namespace stardew_access.Patches itemGrabMenuQueryKey = toSpeak; gameMenuQueryKey = ""; hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); + MainClass.GetScreenReader().Say(toSpeak, true); } return; } @@ -786,7 +786,7 @@ namespace stardew_access.Patches itemGrabMenuQueryKey = toSpeak; gameMenuQueryKey = ""; hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); + MainClass.GetScreenReader().Say(toSpeak, true); Game1.playSound("drop_item"); } return; @@ -828,7 +828,7 @@ namespace stardew_access.Patches itemGrabMenuQueryKey = toSpeak; gameMenuQueryKey = ""; hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); + MainClass.GetScreenReader().Say(toSpeak, true); } return; } @@ -853,7 +853,7 @@ namespace stardew_access.Patches } catch (Exception e) { - MainClass.Monitor.Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error); + MainClass.GetMonitor().Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error); } } @@ -966,7 +966,7 @@ namespace stardew_access.Patches { craftingPageQueryKey = toSpeak; hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); + MainClass.GetScreenReader().Say(toSpeak, true); } return; } @@ -978,7 +978,7 @@ namespace stardew_access.Patches { craftingPageQueryKey = toSpeak; hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); + MainClass.GetScreenReader().Say(toSpeak, true); } return; } @@ -990,7 +990,7 @@ namespace stardew_access.Patches { craftingPageQueryKey = toSpeak; hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); + MainClass.GetScreenReader().Say(toSpeak, true); } return; } @@ -1002,7 +1002,7 @@ namespace stardew_access.Patches { craftingPageQueryKey = toSpeak; hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); + MainClass.GetScreenReader().Say(toSpeak, true); Game1.playSound("drop_item"); } return; @@ -1082,7 +1082,7 @@ namespace stardew_access.Patches craftingPageQueryKey = toSpeak; gameMenuQueryKey = ""; hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); + MainClass.GetScreenReader().Say(toSpeak, true); } return; } @@ -1099,7 +1099,7 @@ namespace stardew_access.Patches } catch (Exception e) { - MainClass.Monitor.Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error); + MainClass.GetMonitor().Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error); } } @@ -1120,7 +1120,7 @@ namespace stardew_access.Patches // This method is used to get the inventory items to check if the player has enough ingredients for a recipe // Taken from CraftingPage.cs -> 169 line - internal static IList getContainerContents(List materialContainers) + internal static IList? getContainerContents(List materialContainers) { if (materialContainers == null) { @@ -1149,7 +1149,7 @@ namespace stardew_access.Patches inventoryPageQueryKey = toSpeak; gameMenuQueryKey = ""; hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); + MainClass.GetScreenReader().Say(toSpeak, true); Game1.playSound("drop_item"); } return; @@ -1163,7 +1163,7 @@ namespace stardew_access.Patches inventoryPageQueryKey = toSpeak; gameMenuQueryKey = ""; hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); + MainClass.GetScreenReader().Say(toSpeak, true); } return; } @@ -1176,7 +1176,7 @@ namespace stardew_access.Patches inventoryPageQueryKey = toSpeak; gameMenuQueryKey = ""; hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); + MainClass.GetScreenReader().Say(toSpeak, true); } return; } @@ -1189,7 +1189,7 @@ namespace stardew_access.Patches itemGrabMenuQueryKey = toSpeak; gameMenuQueryKey = ""; hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); + MainClass.GetScreenReader().Say(toSpeak, true); } return; } @@ -1203,7 +1203,7 @@ namespace stardew_access.Patches itemGrabMenuQueryKey = toSpeak; gameMenuQueryKey = ""; hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); + MainClass.GetScreenReader().Say(toSpeak, true); } return; } @@ -1299,7 +1299,7 @@ namespace stardew_access.Patches inventoryPageQueryKey = toSpeak; gameMenuQueryKey = ""; hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); + MainClass.GetScreenReader().Say(toSpeak, true); } return; } @@ -1317,7 +1317,7 @@ namespace stardew_access.Patches } catch (Exception e) { - MainClass.Monitor.Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error); + MainClass.GetMonitor().Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error); } } @@ -1337,17 +1337,17 @@ namespace stardew_access.Patches if (optionsElement is OptionsButton) toSpeak = $" {toSpeak} Button"; else if (optionsElement is OptionsCheckbox) - toSpeak = ((optionsElement as OptionsCheckbox).isChecked ? "Enabled" : "Disabled") + $" {toSpeak} Checkbox"; + toSpeak = (((OptionsCheckbox)optionsElement).isChecked ? "Enabled" : "Disabled") + $" {toSpeak} Checkbox"; else if (optionsElement is OptionsDropDown) - toSpeak = $"{toSpeak} Dropdown, option {(optionsElement as OptionsDropDown).dropDownDisplayOptions[(optionsElement as OptionsDropDown).selectedOption]} selected"; + toSpeak = $"{toSpeak} Dropdown, option {((OptionsDropDown)optionsElement).dropDownDisplayOptions[((OptionsDropDown)optionsElement).selectedOption]} selected"; else if (optionsElement is OptionsSlider) - toSpeak = $"{(optionsElement as OptionsSlider).value}% {toSpeak} Slider"; + toSpeak = $"{((OptionsSlider)optionsElement).value}% {toSpeak} Slider"; else if (optionsElement is OptionsPlusMinus) - toSpeak = $"{(optionsElement as OptionsPlusMinus).displayOptions[(optionsElement as OptionsPlusMinus).selected]} selected of {toSpeak}"; + toSpeak = $"{((OptionsPlusMinus)optionsElement).displayOptions[((OptionsPlusMinus)optionsElement).selected]} selected of {toSpeak}"; else if (optionsElement is OptionsInputListener) { string buttons = ""; - (optionsElement as OptionsInputListener).buttonNames.ForEach(name => { buttons += $", {name}"; }); + ((OptionsInputListener)optionsElement).buttonNames.ForEach(name => { buttons += $", {name}"; }); toSpeak = $"{toSpeak} is bound to {buttons}. Left click to change."; } else @@ -1362,7 +1362,7 @@ namespace stardew_access.Patches { gameMenuQueryKey = ""; optionsPageQueryKey = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); + MainClass.GetScreenReader().Say(toSpeak, true); } return; } @@ -1370,7 +1370,7 @@ namespace stardew_access.Patches } catch (Exception e) { - MainClass.Monitor.Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error); + MainClass.GetMonitor().Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error); } } @@ -1386,7 +1386,7 @@ namespace stardew_access.Patches { gameMenuQueryKey = ""; exitPageQueryKey = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); + MainClass.GetScreenReader().Say(toSpeak, true); } return; } @@ -1398,14 +1398,14 @@ namespace stardew_access.Patches { gameMenuQueryKey = ""; exitPageQueryKey = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); + MainClass.GetScreenReader().Say(toSpeak, true); } return; } } catch (Exception e) { - MainClass.Monitor.Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error); + MainClass.GetMonitor().Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error); } } @@ -1431,9 +1431,9 @@ namespace stardew_access.Patches string requirements = ""; #region Add quality of item - if (actualInventory[i] is StardewValley.Object && (actualInventory[i] as StardewValley.Object).quality > 0) + if (actualInventory[i] is StardewValley.Object && ((StardewValley.Object)actualInventory[i]).quality > 0) { - int qualityIndex = (actualInventory[i] as StardewValley.Object).quality; + int qualityIndex = ((StardewValley.Object)actualInventory[i]).quality; if (qualityIndex == 1) { quality = "Silver quality"; @@ -1453,13 +1453,13 @@ namespace stardew_access.Patches { description = actualInventory[i].getDescription(); #region Add health & stamina provided by the item - if (actualInventory[i] is StardewValley.Object && (actualInventory[i] as StardewValley.Object).Edibility != -300) + if (actualInventory[i] is StardewValley.Object && ((StardewValley.Object)actualInventory[i]).Edibility != -300) { - int stamina_recovery = (actualInventory[i] as StardewValley.Object).staminaRecoveredOnConsumption(); + int stamina_recovery = ((StardewValley.Object)actualInventory[i]).staminaRecoveredOnConsumption(); healthNStamine += $"{stamina_recovery} Energy"; if (stamina_recovery >= 0) { - int health_recovery = (actualInventory[i] as StardewValley.Object).healthRecoveredOnConsumption(); + int health_recovery = ((StardewValley.Object)actualInventory[i]).healthRecoveredOnConsumption(); healthNStamine += $"\n\t{health_recovery} Health"; } } @@ -1467,8 +1467,8 @@ namespace stardew_access.Patches #region Add buff items (effects like +1 walking speed) // These variables are taken from the game's code itself (IClickableMenu.cs -> 1016 line) - bool edibleItem = actualInventory[i] != null && actualInventory[i] is StardewValley.Object && (int)(actualInventory[i] as StardewValley.Object).edibility != -300; - string[] buffIconsToDisplay = (edibleItem && Game1.objectInformation[(actualInventory[i] as StardewValley.Object).parentSheetIndex].Split('/').Length > 7) ? actualInventory[i].ModifyItemBuffs(Game1.objectInformation[(actualInventory[i] as StardewValley.Object).parentSheetIndex].Split('/')[7].Split(' ')) : null; + bool edibleItem = actualInventory[i] != null && actualInventory[i] is StardewValley.Object && (int)((StardewValley.Object)actualInventory[i]).edibility != -300; + string[]? buffIconsToDisplay = (edibleItem && Game1.objectInformation[((StardewValley.Object)actualInventory[i]).parentSheetIndex].Split('/').Length > 7) ? actualInventory[i].ModifyItemBuffs(Game1.objectInformation[((StardewValley.Object)actualInventory[i]).parentSheetIndex].Split('/')[7].Split(' ')) : null; if (buffIconsToDisplay != null) { for (int j = 0; j < buffIconsToDisplay.Length; j++) @@ -1537,7 +1537,7 @@ namespace stardew_access.Patches if (hoveredItemQueryKey != $"{toSpeak}:{i}") { hoveredItemQueryKey = $"{toSpeak}:{i}"; - MainClass.ScreenReader.Say(toSpeak, true); + MainClass.GetScreenReader().Say(toSpeak, true); } return true; } diff --git a/stardew-access/Patches/MenuPatches.cs b/stardew-access/Patches/MenuPatches.cs index eee71ad..7192003 100644 --- a/stardew-access/Patches/MenuPatches.cs +++ b/stardew-access/Patches/MenuPatches.cs @@ -38,7 +38,7 @@ namespace stardew_access.Patches } catch (Exception e) { - MainClass.Monitor.Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error); + MainClass.GetMonitor().Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error); } return true; @@ -52,13 +52,13 @@ namespace stardew_access.Patches if (__instance.nextPageButton != null && __instance.nextPageButton.containsPoint(x, y)) { - MainClass.ScreenReader.SayWithMenuChecker($"Next Page Button", true); + MainClass.GetScreenReader().SayWithMenuChecker($"Next Page Button", true); return; } if (__instance.previousPageButton != null && __instance.previousPageButton.containsPoint(x, y)) { - MainClass.ScreenReader.SayWithMenuChecker($"Previous Page Button", true); + MainClass.GetScreenReader().SayWithMenuChecker($"Previous Page Button", true); return; } @@ -66,14 +66,14 @@ namespace stardew_access.Patches { if (__instance.languages[i].containsPoint(x, y)) { - MainClass.ScreenReader.SayWithMenuChecker($"{__instance.languageList[i]} Button", true); + MainClass.GetScreenReader().SayWithMenuChecker($"{__instance.languageList[i]} Button", true); break; } } } catch (Exception e) { - MainClass.Monitor.Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error); + MainClass.GetMonitor().Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error); } } @@ -86,14 +86,14 @@ namespace stardew_access.Patches { if (___elevators[i].containsPoint(x, y)) { - MainClass.ScreenReader.SayWithMenuChecker($"{___elevators[i].name} level", true); + MainClass.GetScreenReader().SayWithMenuChecker($"{___elevators[i].name} level", true); break; } } } catch (Exception e) { - MainClass.Monitor.Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error); + MainClass.GetMonitor().Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error); } } @@ -105,11 +105,11 @@ namespace stardew_access.Patches ___textBox.SelectMe(); string toSpeak = $"{title}"; - MainClass.ScreenReader.SayWithChecker(toSpeak, true); + MainClass.GetScreenReader().SayWithChecker(toSpeak, true); } catch (Exception e) { - MainClass.Monitor.Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error); + MainClass.GetMonitor().Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error); } } @@ -119,19 +119,19 @@ namespace stardew_access.Patches { int x = Game1.getMouseX(), y = Game1.getMouseY(); - MainClass.ScreenReader.SayWithMenuChecker(___message, true); + MainClass.GetScreenReader().SayWithMenuChecker(___message, true); if (__instance.okButton.containsPoint(x, y)) { - MainClass.ScreenReader.SayWithMenuChecker("Ok Button", false); + MainClass.GetScreenReader().SayWithMenuChecker("Ok Button", false); } else if (__instance.cancelButton.containsPoint(x, y)) { - MainClass.ScreenReader.SayWithMenuChecker("Cancel Button", false); + MainClass.GetScreenReader().SayWithMenuChecker("Cancel Button", false); } } catch (Exception e) { - MainClass.Monitor.Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error); + MainClass.GetMonitor().Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error); } } @@ -223,16 +223,16 @@ namespace stardew_access.Patches } if (toSpeak != " ") - MainClass.ScreenReader.SayWithMenuChecker(toSpeak, true); + MainClass.GetScreenReader().SayWithMenuChecker(toSpeak, true); else if (__instance.isProfessionChooser && currentLevelUpTitle != $"{___title}. Select a new profession.") { - MainClass.ScreenReader.SayWithMenuChecker($"{___title}. Select a new profession.", true); + MainClass.GetScreenReader().SayWithMenuChecker($"{___title}. Select a new profession.", true); currentLevelUpTitle = $"{___title}. Select a new profession."; } } catch (Exception e) { - MainClass.Monitor.Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error); + MainClass.GetMonitor().Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error); } } @@ -256,21 +256,21 @@ namespace stardew_access.Patches Game1.activeClickableMenu.receiveLeftClick(Game1.getMouseX(true), Game1.getMouseY(true)); } toSpeak = $"{total}g in total. Press left mouse button to save."; - MainClass.ScreenReader.SayWithChecker(toSpeak, true); + MainClass.GetScreenReader().SayWithChecker(toSpeak, true); } for (int i = 0; i < __instance.categories.Count; i++) { if (__instance.categories[i].containsPoint(Game1.getMouseX(), Game1.getMouseY())) { toSpeak = $"Money recieved from {__instance.getCategoryName(i)}: {___categoryTotals[i]}g."; - MainClass.ScreenReader.SayWithChecker(toSpeak, true); + MainClass.GetScreenReader().SayWithChecker(toSpeak, true); } } } } catch (Exception e) { - MainClass.Monitor.Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error); + MainClass.GetMonitor().Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error); } } @@ -310,7 +310,7 @@ namespace stardew_access.Patches toSpeak += "\t\n Left click to accept quest."; __instance.acceptQuestButton.snapMouseCursorToCenter(); } - MainClass.ScreenReader.Say(toSpeak, false); + MainClass.GetScreenReader().Say(toSpeak, false); } #endregion @@ -323,7 +323,7 @@ namespace stardew_access.Patches string label = c.label; if (c.containsPoint(Game1.getMousePosition().X, Game1.getMousePosition().Y)) - MainClass.ScreenReader.SayWithChecker($"Grab: {name} \t\n {label}", false); + MainClass.GetScreenReader().SayWithChecker($"Grab: {name} \t\n {label}", false); } } #endregion @@ -331,7 +331,7 @@ namespace stardew_access.Patches catch (Exception e) { - MainClass.Monitor.Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error); + MainClass.GetMonitor().Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error); } } @@ -373,7 +373,7 @@ namespace stardew_access.Patches } catch (Exception e) { - MainClass.Monitor.Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error); + MainClass.GetMonitor().Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error); } } @@ -418,14 +418,14 @@ namespace stardew_access.Patches } catch (Exception e) { - MainClass.Monitor.Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error); + MainClass.GetMonitor().Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error); } } internal static void ExitEventPatch() { - if (MainClass.ScreenReader != null) - MainClass.ScreenReader.CloseScreenReader(); + if (MainClass.GetScreenReader() != null) + MainClass.GetScreenReader().CloseScreenReader(); } internal static void resetGlobalVars() { diff --git a/stardew-access/Patches/QuestPatches.cs b/stardew-access/Patches/QuestPatches.cs index ef9bed6..9d958fc 100644 --- a/stardew-access/Patches/QuestPatches.cs +++ b/stardew-access/Patches/QuestPatches.cs @@ -23,7 +23,7 @@ namespace stardew_access.Patches toSpeak = $"Left Quest:\n\t{toSpeak}\n\tPress left click to accept this quest."; - MainClass.ScreenReader.SayWithMenuChecker(toSpeak, true); + MainClass.GetScreenReader().SayWithMenuChecker(toSpeak, true); return; } @@ -33,13 +33,13 @@ namespace stardew_access.Patches toSpeak = $"Right Quest:\n\t{toSpeak}\n\tPress left click to accept this quest."; - MainClass.ScreenReader.SayWithMenuChecker(toSpeak, true); + MainClass.GetScreenReader().SayWithMenuChecker(toSpeak, true); return; } } catch (Exception e) { - MainClass.Monitor.Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error); + MainClass.GetMonitor().Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error); } } @@ -99,7 +99,7 @@ namespace stardew_access.Patches if (Game1.dayOfMonth == i + 1) toSpeak += $", Current"; - MainClass.ScreenReader.SayWithChecker(toSpeak, true); + MainClass.GetScreenReader().SayWithChecker(toSpeak, true); } } #endregion @@ -114,7 +114,7 @@ namespace stardew_access.Patches if (currentDailyQuestText != toSpeak) { currentDailyQuestText = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); + MainClass.GetScreenReader().Say(toSpeak, true); } } else @@ -134,7 +134,7 @@ namespace stardew_access.Patches __instance.acceptQuestButton.snapMouseCursorToCenter(); } - MainClass.ScreenReader.Say(toSpeak, true); + MainClass.GetScreenReader().Say(toSpeak, true); } } #endregion @@ -142,7 +142,7 @@ namespace stardew_access.Patches } catch (Exception e) { - MainClass.Monitor.Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error); + MainClass.GetMonitor().Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error); } } #endregion @@ -171,7 +171,7 @@ namespace stardew_access.Patches toSpeak += ___pages[___currentPage][i].ShouldDisplayAsComplete() ? " completed!" : ""; if (__instance.questLogButtons[i].containsPoint(Game1.getOldMouseX(), Game1.getOldMouseY())) { - MainClass.ScreenReader.SayWithChecker(toSpeak, true); + MainClass.GetScreenReader().SayWithChecker(toSpeak, true); } } } @@ -232,13 +232,13 @@ namespace stardew_access.Patches if (snapMouseToRewardBox) __instance.rewardBox.snapMouseCursorToCenter(); - MainClass.ScreenReader.SayWithChecker(toSpeak, true); + MainClass.GetScreenReader().SayWithChecker(toSpeak, true); #endregion } } catch (Exception e) { - MainClass.Monitor.Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error); + MainClass.GetMonitor().Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error); } } #endregion diff --git a/stardew-access/Patches/TitleMenuPatches.cs b/stardew-access/Patches/TitleMenuPatches.cs index 6f15f69..f9d5b4a 100644 --- a/stardew-access/Patches/TitleMenuPatches.cs +++ b/stardew-access/Patches/TitleMenuPatches.cs @@ -45,11 +45,11 @@ namespace stardew_access.Patches #endregion if (toSpeak != " ") - MainClass.ScreenReader.SayWithChecker(toSpeak, true); + MainClass.GetScreenReader().SayWithChecker(toSpeak, true); } catch (Exception e) { - MainClass.Monitor.Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error); + MainClass.GetMonitor().Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error); } } @@ -95,15 +95,15 @@ namespace stardew_access.Patches if (TitleMenu.subMenu != null && __instance.backButton.containsPoint(Game1.getMouseX(), Game1.getMouseY())) { string text = "Back Button"; - MainClass.ScreenReader.SayWithChecker(text, true); + MainClass.GetScreenReader().SayWithChecker(text, true); } if (TitleMenu.subMenu == null && toSpeak != "") - MainClass.ScreenReader.SayWithChecker(toSpeak, true); + MainClass.GetScreenReader().SayWithChecker(toSpeak, true); } catch (Exception e) { - MainClass.Monitor.Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error); + MainClass.GetMonitor().Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error); } } @@ -119,7 +119,7 @@ namespace stardew_access.Patches #region Farms if (___menu.deleteButtons.Count > 0 && ___menu.deleteButtons[i].containsPoint(x, y)) { - MainClass.ScreenReader.SayWithChecker($"Delete {__instance.Farmer.farmName} Farm", true); + MainClass.GetScreenReader().SayWithChecker($"Delete {__instance.Farmer.farmName} Farm", true); return; } @@ -128,14 +128,14 @@ namespace stardew_access.Patches // Used diff. functions to narrate to prevent it from speaking the message again on selecting another button. string message = "Really delete farm?"; - MainClass.ScreenReader.SayWithChecker(message, true); + MainClass.GetScreenReader().SayWithChecker(message, true); if (___menu.okDeleteButton.containsPoint(x, y)) { - MainClass.ScreenReader.SayWithMenuChecker("Ok Button", false); + MainClass.GetScreenReader().SayWithMenuChecker("Ok Button", false); } else if (___menu.cancelDeleteButton.containsPoint(x, y)) { - MainClass.ScreenReader.SayWithMenuChecker("Cancel Button", false); + MainClass.GetScreenReader().SayWithMenuChecker("Cancel Button", false); } return; } @@ -150,14 +150,14 @@ namespace stardew_access.Patches string toSpeak = $"{farmName} Farm Selected, \t\n Farmer:{farmerName}, \t\nMoney:{money}, \t\nHours Played:{hoursPlayed}, \t\nDate:{dateStringForSaveGame}"; - MainClass.ScreenReader.SayWithChecker(toSpeak, true); + MainClass.GetScreenReader().SayWithChecker(toSpeak, true); #endregion } } } catch (Exception e) { - MainClass.Monitor.Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error); + MainClass.GetMonitor().Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error); } } @@ -179,7 +179,7 @@ namespace stardew_access.Patches } catch (Exception e) { - MainClass.Monitor.Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error); + MainClass.GetMonitor().Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error); } } @@ -640,7 +640,7 @@ namespace stardew_access.Patches if (toSpeak != " ") { - MainClass.ScreenReader.Say(toSpeak, true); + MainClass.GetScreenReader().Say(toSpeak, true); } await Task.Delay(200); diff --git a/stardew-access/ScreenReader/ScreenReaderAPI.cs b/stardew-access/ScreenReader/ScreenReaderAPI.cs deleted file mode 100644 index 22b297d..0000000 --- a/stardew-access/ScreenReader/ScreenReaderAPI.cs +++ /dev/null @@ -1,51 +0,0 @@ -namespace stardew_access.ScreenReader -{ - public class ScreenReaderAPI - { - - public ScreenReaderAPI() - { - } - - public void Say(String text, Boolean interrupt) - { - if (MainClass.ScreenReader == null) - return; - - MainClass.ScreenReader.Say(text, interrupt); - } - - public void SayWithChecker(String text, Boolean interrupt) - { - if (MainClass.ScreenReader == null) - return; - - MainClass.ScreenReader.SayWithChecker(text, interrupt); - } - - public void SayWithMenuChecker(String text, Boolean interrupt) - { - if (MainClass.ScreenReader == null) - return; - - MainClass.ScreenReader.SayWithMenuChecker(text, interrupt); - } - - public void SayWithChatChecker(String text, Boolean interrupt) - { - if (MainClass.ScreenReader == null) - return; - - MainClass.ScreenReader.SayWithChatChecker(text, interrupt); - } - - public void SayWithTileQuery(String text, int x, int y, Boolean interrupt) - { - if (MainClass.ScreenReader == null) - return; - - MainClass.ScreenReader.SayWithTileQuery(text, x, y, interrupt); - } - - } -} \ No newline at end of file diff --git a/stardew-access/ScreenReader/ScreenReaderController.cs b/stardew-access/ScreenReader/ScreenReaderController.cs index 82f071c..b515519 100644 --- a/stardew-access/ScreenReader/ScreenReaderController.cs +++ b/stardew-access/ScreenReader/ScreenReaderController.cs @@ -4,9 +4,9 @@ namespace stardew_access.ScreenReader { public class ScreenReaderController { - public IScreenReader? Initialize() + public IScreenReader Initialize() { - IScreenReader? ScreenReader = null; + IScreenReader ScreenReader = new ScreenReaderWindows(); // Default is windows if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { @@ -22,6 +22,10 @@ namespace stardew_access.ScreenReader ScreenReader = screenReaderLinux; } + else + { + ScreenReader.InitializeScreenReader(); + } return ScreenReader; } diff --git a/stardew-access/ScreenReader/ScreenReaderLinux.cs b/stardew-access/ScreenReader/ScreenReaderLinux.cs index 67ea027..8b85f68 100644 --- a/stardew-access/ScreenReader/ScreenReaderLinux.cs +++ b/stardew-access/ScreenReader/ScreenReaderLinux.cs @@ -54,6 +54,9 @@ namespace stardew_access.ScreenReader public void Say(string text, bool interrupt) { + if (text == null) + return; + if (initialized) { GoString str = new GoString(text, text.Length); diff --git a/stardew-access/ScreenReader/ScreenReaderWindows.cs b/stardew-access/ScreenReader/ScreenReaderWindows.cs index fa858bb..deb8a73 100644 --- a/stardew-access/ScreenReader/ScreenReaderWindows.cs +++ b/stardew-access/ScreenReader/ScreenReaderWindows.cs @@ -56,6 +56,9 @@ namespace stardew_access.ScreenReader public void Say(string text, bool interrupt) { + if (text == null) + return; + if (screenReader == null) return; @@ -64,9 +67,6 @@ namespace stardew_access.ScreenReader public void SayWithChecker(string text, bool interrupt) { - if (screenReader == null) - return; - if (prevText != text) { prevText = text; @@ -76,9 +76,6 @@ namespace stardew_access.ScreenReader public void SayWithMenuChecker(string text, bool interrupt) { - if (screenReader == null) - return; - if (prevMenuText != text) { prevMenuText = text; @@ -88,9 +85,6 @@ namespace stardew_access.ScreenReader public void SayWithChatChecker(string text, bool interrupt) { - if (screenReader == null) - return; - if (prevChatText != text) { prevChatText = text; @@ -100,9 +94,6 @@ namespace stardew_access.ScreenReader public void SayWithTileQuery(string text, int x, int y, bool interrupt) { - if (screenReader == null) - return; - string query = $"{text} x:{x} y:{y}"; if (prevTextTile != query)