2022-01-19 14:27:15 +05:30
|
|
|
|
using Microsoft.Xna.Framework;
|
2022-01-12 16:01:29 +05:30
|
|
|
|
using StardewModdingAPI;
|
|
|
|
|
using StardewValley;
|
|
|
|
|
|
2022-02-13 18:12:19 +05:30
|
|
|
|
namespace stardew_access.Features
|
2022-01-12 16:01:29 +05:30
|
|
|
|
{
|
2022-08-12 16:37:39 +05:30
|
|
|
|
/// <summary>
|
|
|
|
|
/// Reads the name and information about a tile.
|
|
|
|
|
/// </summary>
|
2022-01-12 16:01:29 +05:30
|
|
|
|
public class ReadTile
|
|
|
|
|
{
|
2022-05-12 15:28:09 +05:30
|
|
|
|
private bool isBusy; // To pause execution of run method between fixed intervals
|
|
|
|
|
private int delay; // Length of each interval (in ms)
|
|
|
|
|
private bool shouldPause; // To pause the execution
|
|
|
|
|
private Vector2 prevTile;
|
2022-01-12 16:01:29 +05:30
|
|
|
|
|
|
|
|
|
public ReadTile()
|
|
|
|
|
{
|
2022-05-12 15:28:09 +05:30
|
|
|
|
isBusy = false;
|
|
|
|
|
delay = 100;
|
2022-01-12 16:01:29 +05:30
|
|
|
|
}
|
|
|
|
|
|
2022-05-12 15:28:09 +05:30
|
|
|
|
public void update()
|
|
|
|
|
{
|
|
|
|
|
if (this.isBusy)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (this.shouldPause)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
this.isBusy = true;
|
|
|
|
|
this.run();
|
|
|
|
|
Task.Delay(delay).ContinueWith(_ => { this.isBusy = false; });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2022-05-16 21:07:08 +05:30
|
|
|
|
/// Pauses the feature for the provided time.
|
2022-05-12 15:28:09 +05:30
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="time">The amount of time we want to pause the execution (in ms).<br/>Default is 2500 (2.5s).</param>
|
2022-05-16 21:07:08 +05:30
|
|
|
|
public void pauseUntil(int time = 2500)
|
2022-05-12 15:28:09 +05:30
|
|
|
|
{
|
|
|
|
|
this.shouldPause = true;
|
|
|
|
|
Task.Delay(time).ContinueWith(_ => { this.shouldPause = false; });
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-16 21:07:08 +05:30
|
|
|
|
/// <summary>
|
|
|
|
|
/// Pauses the feature
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void pause()
|
|
|
|
|
{
|
|
|
|
|
this.shouldPause = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Resumes the feature
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void resume()
|
|
|
|
|
{
|
|
|
|
|
this.shouldPause = false;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-12 15:28:09 +05:30
|
|
|
|
public void run(bool manuallyTriggered = false, bool playersPosition = false)
|
2022-01-12 16:01:29 +05:30
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2022-03-19 12:54:53 +05:30
|
|
|
|
Vector2 tile;
|
2022-05-10 20:47:40 +05:30
|
|
|
|
|
2022-03-19 12:54:53 +05:30
|
|
|
|
#region Get Tile
|
2022-05-10 20:47:40 +05:30
|
|
|
|
int x, y;
|
2022-03-19 12:54:53 +05:30
|
|
|
|
if (!playersPosition)
|
|
|
|
|
{
|
|
|
|
|
// Grab tile
|
2022-05-11 13:14:46 +05:30
|
|
|
|
tile = CurrentPlayer.FacingTile;
|
2022-03-19 12:54:53 +05:30
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Player's standing tile
|
2022-05-11 13:14:46 +05:30
|
|
|
|
tile = CurrentPlayer.Position;
|
2022-03-19 12:54:53 +05:30
|
|
|
|
}
|
|
|
|
|
x = (int)tile.X;
|
|
|
|
|
y = (int)tile.Y;
|
2022-05-10 20:47:40 +05:30
|
|
|
|
#endregion
|
2022-01-12 16:01:29 +05:30
|
|
|
|
|
|
|
|
|
if (Context.IsPlayerFree)
|
|
|
|
|
{
|
2022-02-13 16:57:06 +05:30
|
|
|
|
if (!manuallyTriggered && prevTile != tile)
|
2022-01-12 16:01:29 +05:30
|
|
|
|
{
|
2022-04-09 15:48:13 +05:30
|
|
|
|
if (MainClass.ScreenReader != null)
|
|
|
|
|
MainClass.ScreenReader.PrevTextTile = " ";
|
2022-01-12 16:01:29 +05:30
|
|
|
|
}
|
|
|
|
|
|
2023-03-31 14:53:18 -07:00
|
|
|
|
var currentLocation = Game1.currentLocation;
|
2023-04-04 15:09:49 -07:00
|
|
|
|
bool isColliding = TileInfo.IsCollidingAtTile(currentLocation, x, y);
|
2022-01-26 13:39:32 +05:30
|
|
|
|
|
2023-03-31 14:53:18 -07:00
|
|
|
|
(string? name, string? category) info = TileInfo.getNameWithCategoryNameAtTile(tile, currentLocation);
|
2022-01-12 16:01:29 +05:30
|
|
|
|
|
|
|
|
|
#region Narrate toSpeak
|
2022-05-10 20:47:40 +05:30
|
|
|
|
if (info.name != null)
|
2022-04-09 15:48:13 +05:30
|
|
|
|
if (MainClass.ScreenReader != null)
|
2022-02-13 16:57:06 +05:30
|
|
|
|
if (manuallyTriggered)
|
2022-05-10 20:47:40 +05:30
|
|
|
|
MainClass.ScreenReader.Say($"{info.name}, Category: {info.category}", true);
|
2022-02-13 16:57:06 +05:30
|
|
|
|
else
|
2022-05-10 20:47:40 +05:30
|
|
|
|
MainClass.ScreenReader.SayWithTileQuery(info.name, x, y, true);
|
2022-01-21 14:21:43 +05:30
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Play colliding sound effect
|
2022-02-13 16:57:06 +05:30
|
|
|
|
if (isColliding && prevTile != tile)
|
2022-01-21 14:21:43 +05:30
|
|
|
|
{
|
|
|
|
|
Game1.playSound("colliding");
|
2022-01-21 15:30:16 +05:30
|
|
|
|
}
|
2022-01-12 16:01:29 +05:30
|
|
|
|
#endregion
|
|
|
|
|
|
2022-03-19 12:54:53 +05:30
|
|
|
|
if (!manuallyTriggered)
|
|
|
|
|
prevTile = tile;
|
2022-01-12 16:01:29 +05:30
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
2022-03-19 12:54:53 +05:30
|
|
|
|
MainClass.ErrorLog($"Error in Read Tile:\n{e.Message}\n{e.StackTrace}");
|
2022-01-12 16:01:29 +05:30
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|