Read tile pauses when narrating a warning message
parent
d8dbfe78d4
commit
2d74653217
|
@ -6,15 +6,44 @@ namespace stardew_access.Features
|
|||
{
|
||||
public class ReadTile
|
||||
{
|
||||
public static bool isReadingTile = false;
|
||||
public static Vector2 prevTile;
|
||||
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;
|
||||
|
||||
public ReadTile()
|
||||
{
|
||||
isReadingTile = false;
|
||||
isBusy = false;
|
||||
delay = 100;
|
||||
}
|
||||
|
||||
public static void run(bool manuallyTriggered = false, bool playersPosition = false)
|
||||
public void update()
|
||||
{
|
||||
if (this.isBusy)
|
||||
return;
|
||||
|
||||
if (this.shouldPause)
|
||||
return;
|
||||
|
||||
if (!MainClass.Config.ReadTile)
|
||||
return;
|
||||
|
||||
this.isBusy = true;
|
||||
this.run();
|
||||
Task.Delay(delay).ContinueWith(_ => { this.isBusy = false; });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Pauses the read tile for the provided time.
|
||||
/// </summary>
|
||||
/// <param name="time">The amount of time we want to pause the execution (in ms).<br/>Default is 2500 (2.5s).</param>
|
||||
public void pause(int time = 2500)
|
||||
{
|
||||
this.shouldPause = true;
|
||||
Task.Delay(time).ContinueWith(_ => { this.shouldPause = false; });
|
||||
}
|
||||
|
||||
public void run(bool manuallyTriggered = false, bool playersPosition = false)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
|
|
@ -27,8 +27,9 @@ namespace stardew_access.Features
|
|||
|
||||
if ((stamina <= 50 && prevStamina > 50) || (stamina <= 25 && prevStamina > 25) || (stamina <= 10 && prevStamina > 10))
|
||||
{
|
||||
MainClass.DebugLog(toSpeak);
|
||||
MainClass.ScreenReader.Say(toSpeak, true);
|
||||
// Pause the read tile feature to prevent interruption in warning message
|
||||
MainClass.ReadTileFeature.pause();
|
||||
}
|
||||
|
||||
prevStamina = stamina;
|
||||
|
@ -44,8 +45,9 @@ namespace stardew_access.Features
|
|||
|
||||
if ((health <= 50 && prevHealth > 50) || (health <= 25 && prevHealth > 25) || (health <= 10 && prevHealth > 10))
|
||||
{
|
||||
MainClass.DebugLog(toSpeak);
|
||||
MainClass.ScreenReader.Say(toSpeak, true);
|
||||
// Pause the read tile feature to prevent interruption in warning message
|
||||
MainClass.ReadTileFeature.pause();
|
||||
}
|
||||
|
||||
prevHealth = health;
|
||||
|
|
|
@ -21,6 +21,8 @@ namespace stardew_access
|
|||
private static IScreenReader? screenReader;
|
||||
private static IModHelper? modHelper;
|
||||
private static TileViewer? tileViewer;
|
||||
private static Warnings? warnings;
|
||||
private static ReadTile? readTile;
|
||||
|
||||
internal static ModConfig Config { get => config; set => config = value; }
|
||||
public static IModHelper? ModHelper { get => modHelper; }
|
||||
|
@ -64,7 +66,7 @@ namespace stardew_access
|
|||
set => screenReader = value;
|
||||
}
|
||||
|
||||
public static TileViewer TileViewer
|
||||
public static TileViewer TileViewerFeature
|
||||
{
|
||||
get
|
||||
{
|
||||
|
@ -74,6 +76,26 @@ namespace stardew_access
|
|||
}
|
||||
}
|
||||
|
||||
public static ReadTile ReadTileFeature
|
||||
{
|
||||
get
|
||||
{
|
||||
if (readTile == null)
|
||||
readTile = new ReadTile();
|
||||
return readTile;
|
||||
}
|
||||
}
|
||||
|
||||
public static Warnings WarningsFeature
|
||||
{
|
||||
get
|
||||
{
|
||||
if (warnings == null)
|
||||
warnings = new Warnings();
|
||||
|
||||
return warnings;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
/*********
|
||||
|
@ -120,7 +142,8 @@ 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.
|
||||
// This closes the connection with the screen reader, important for linux
|
||||
// Don't know if this ever gets called or not but, just in case if it does.
|
||||
if (ScreenReader != null)
|
||||
ScreenReader.CloseScreenReader();
|
||||
}
|
||||
|
@ -143,14 +166,11 @@ namespace stardew_access
|
|||
Other.narrateCurrentLocation();
|
||||
|
||||
//handle TileCursor update logic
|
||||
TileViewer.update();
|
||||
TileViewerFeature.update();
|
||||
|
||||
if (!ReadTile.isReadingTile && Config.ReadTile)
|
||||
{
|
||||
ReadTile.isReadingTile = true;
|
||||
ReadTile.run();
|
||||
Task.Delay(100).ContinueWith(_ => { ReadTile.isReadingTile = false; });
|
||||
}
|
||||
WarningsFeature.update();
|
||||
|
||||
ReadTileFeature.update();
|
||||
|
||||
if (!RadarFeature.isRunning && Config.Radar)
|
||||
{
|
||||
|
@ -258,19 +278,19 @@ namespace stardew_access
|
|||
// Manual read tile at player's position
|
||||
if (Config.ReadStandingTileKey.JustPressed())
|
||||
{
|
||||
ReadTile.run(manuallyTriggered: true, playersPosition: true);
|
||||
ReadTileFeature.run(manuallyTriggered: true, playersPosition: true);
|
||||
return;
|
||||
}
|
||||
|
||||
// Manual read tile at looking tile
|
||||
if (Config.ReadTileKey.JustPressed())
|
||||
{
|
||||
ReadTile.run(manuallyTriggered: true);
|
||||
ReadTileFeature.run(manuallyTriggered: true);
|
||||
return;
|
||||
}
|
||||
|
||||
// Tile viewing cursor keys
|
||||
TileViewer.HandleInput();
|
||||
TileViewerFeature.HandleInput();
|
||||
}
|
||||
|
||||
public static void ErrorLog(string message)
|
||||
|
|
Loading…
Reference in New Issue