diff --git a/stardew-access/API.cs b/stardew-access/API.cs
index e967ee0..24a6c8b 100644
--- a/stardew-access/API.cs
+++ b/stardew-access/API.cs
@@ -10,16 +10,49 @@ namespace stardew_access.ScreenReader
{
}
+ ///
+ /// Search the area using Breadth First Search algorithm(BFS).
+ ///
+ /// The starting point.
+ /// The limiting factor or simply radius of the search area.
+ /// A dictionary with all the detected tiles along with the name of the object on it and it's category.
+ public Dictionary SearchNearbyTiles(Vector2 center, int limit)
+ {
+ /*
+ * How to use the Dictionary to get the name and category of a tile:-
+ *
+ * string? objectName = detectedTiles.GetValueOrDefault(center).Item1;
+ * string? objectCategory = detectedTiles.GetValueOrDefault(center).Item2;
+ *
+ * Here detectedTiles is the Dictionary returned by this method
+ */
+
+ return new Radar().SearchNearbyTiles(center, limit, false);
+ }
+
+ ///
+ /// Check the tile for any object
+ ///
+ /// The tile where we want to check the name and category of object if any
+ /// Name of the object as the first item (Item1) and category as the second item (Item2). Returns null if no object found.
public (string?, string?) GetNameWithCategoryNameAtTile(Vector2 tile)
{
return ReadTile.getNameWithCategoryNameAtTile(tile);
}
+ ///
+ /// Check the tile for any object
+ ///
+ /// The tile where we want to check the name and category of object if any
+ /// Name of the object. Returns null if no object found.
public string? GetNameAtTile(Vector2 tile)
{
return ReadTile.getNameAtTile(tile);
}
+ /// Speaks the text via the loaded screen reader (if any).
+ /// The text to be narrated.
+ /// Whether to skip the currently speaking text or not.
public void Say(String text, Boolean interrupt)
{
if (MainClass.GetScreenReader() == null)
@@ -28,6 +61,10 @@ namespace stardew_access.ScreenReader
MainClass.GetScreenReader().Say(text, interrupt);
}
+ /// Speaks the text via the loaded screen reader (if any).
+ ///
Skips the text narration if the previously narrated text was the same as the one provided.
+ /// The text to be narrated.
+ /// Whether to skip the currently speaking text or not.
public void SayWithChecker(String text, Boolean interrupt)
{
if (MainClass.GetScreenReader() == null)
@@ -36,6 +73,11 @@ namespace stardew_access.ScreenReader
MainClass.GetScreenReader().SayWithChecker(text, interrupt);
}
+ /// Speaks the text via the loaded screen reader (if any).
+ ///
Skips the text narration if the previously narrated text was the same as the one provided.
+ ///
Use this when narrating hovered component in menus to avoid interference.
+ /// The text to be narrated.
+ /// Whether to skip the currently speaking text or not.
public void SayWithMenuChecker(String text, Boolean interrupt)
{
if (MainClass.GetScreenReader() == null)
@@ -44,6 +86,11 @@ namespace stardew_access.ScreenReader
MainClass.GetScreenReader().SayWithMenuChecker(text, interrupt);
}
+ /// Speaks the text via the loaded screen reader (if any).
+ ///
Skips the text narration if the previously narrated text was the same as the one provided.
+ ///
Use this when narrating chat messages to avoid interference.
+ /// The text to be narrated.
+ /// Whether to skip the currently speaking text or not.
public void SayWithChatChecker(String text, Boolean interrupt)
{
if (MainClass.GetScreenReader() == null)
@@ -52,6 +99,13 @@ namespace stardew_access.ScreenReader
MainClass.GetScreenReader().SayWithChatChecker(text, interrupt);
}
+ /// Speaks the text via the loaded screen reader (if any).
+ ///
Skips the text narration if the previously narrated text was the same as the one provided.
+ ///
Use this when narrating texts based on tile position to avoid interference.
+ /// The text to be narrated.
+ /// The X location of tile.
+ /// The Y location of tile.
+ /// Whether to skip the currently speaking text or not.
public void SayWithTileQuery(String text, int x, int y, Boolean interrupt)
{
if (MainClass.GetScreenReader() == null)
diff --git a/stardew-access/Features/Radar.cs b/stardew-access/Features/Radar.cs
index f96c67e..3419927 100644
--- a/stardew-access/Features/Radar.cs
+++ b/stardew-access/Features/Radar.cs
@@ -108,7 +108,7 @@ namespace stardew_access.Features
furnitures.Clear();
npcs.Clear();
- BFS(currPosition, range);
+ SearchNearbyTiles(currPosition, range);
if (MainClass.radarDebug)
MainClass.GetMonitor().Log($"\nRead Tile stopped\n\n", StardewModdingAPI.LogLevel.Debug);
@@ -122,8 +122,12 @@ namespace stardew_access.Features
///
/// The starting point.
/// The limiting factor or simply radius of the search area.
- public void BFS(Vector2 center, int limit)
+ /// True by default if False then it will not play sound and only return the list of detected tiles(for api).
+ /// A dictionary with all the detected tiles along with the name of the object on it and it's category.
+ public Dictionary SearchNearbyTiles(Vector2 center, int limit, bool playSound = true)
{
+ Dictionary detectedTiles = new Dictionary();
+
Queue toSearch = new Queue();
List searched = new List();
int[] dirX = { -1, 0, 1, 0 };
@@ -136,7 +140,17 @@ namespace stardew_access.Features
while (toSearch.Count > 0)
{
Vector2 item = toSearch.Dequeue();
- CheckTile(item);
+ if (playSound)
+ CheckTileAndPlaySound(item);
+ else
+ {
+ (bool, string?, string) tileInfo = CheckTile(item);
+ if (tileInfo.Item1 && tileInfo.Item2 != null)
+ {
+ // Add detected tile to the dictionary
+ detectedTiles.Add(item, (tileInfo.Item2, tileInfo.Item3));
+ }
+ }
count++;
for (int i = 0; i < 4; i++)
@@ -151,6 +165,7 @@ namespace stardew_access.Features
}
}
+ return detectedTiles;
}
///
@@ -160,7 +175,7 @@ namespace stardew_access.Features
/// The starting point of the search.
/// The list of searched items.
/// The radius of search
- ///
+ /// Returns true if the tile is valid for search.
public bool isValid(Vector2 item, Vector2 center, List searched, int limit)
{
if (Math.Abs(item.X - center.X) > limit)
@@ -174,12 +189,23 @@ namespace stardew_access.Features
return true;
}
- public void CheckTile(Vector2 position)
+ public (bool, string?, string) CheckTile(Vector2 position)
+ {
+ (string?, CATEGORY?) tileDetail = ReadTile.getNameWithCategoryAtTile(position);
+ if (tileDetail.Item1 == null)
+ return (false, null, CATEGORY.Others.ToString());
+
+ if (tileDetail.Item2 == null)
+ tileDetail.Item2 = CATEGORY.Others;
+
+ return (true, tileDetail.Item1, tileDetail.Item2.ToString());
+
+ }
+
+ public void CheckTileAndPlaySound(Vector2 position)
{
try
{
- Dictionary> terrainFeature = Game1.currentLocation.terrainFeatures.FieldDict;
-
if (Game1.currentLocation.isObjectAtTile((int)position.X, (int)position.Y))
{
(string?, CATEGORY) objDetails = ReadTile.getObjectAtTile((int)position.X, (int)position.Y);