Added i18n folder for other language support

and logic for narrating warnings
master
Mohammad Shoaib 2022-05-11 13:47:19 +05:30
parent 04ba44d045
commit d8dbfe78d4
3 changed files with 32 additions and 23 deletions

View File

@ -2,6 +2,15 @@ namespace stardew_access.Features
{ {
public class Warnings public class Warnings
{ {
private int prevStamina;
private int prevHealth;
public Warnings()
{
prevStamina = 100;
prevHealth = 100;
}
public void update() public void update()
{ {
this.checkForHealth(); this.checkForHealth();
@ -10,38 +19,36 @@ namespace stardew_access.Features
public void checkForStamina() public void checkForStamina()
{ {
int stamina = CurrentPlayer.Stamina; if (MainClass.ModHelper == null)
return;
if (stamina <= 50) int stamina = CurrentPlayer.Stamina;
string toSpeak = MainClass.ModHelper.Translation.Get("warnings.label", new { type = "stamina", value = stamina });
if ((stamina <= 50 && prevStamina > 50) || (stamina <= 25 && prevStamina > 25) || (stamina <= 10 && prevStamina > 10))
{ {
// 50% stamina warning MainClass.DebugLog(toSpeak);
} MainClass.ScreenReader.Say(toSpeak, true);
else if (stamina <= 25)
{
// 25% stamina warning
}
else if (stamina <= 10)
{
// 10% stamina warning
} }
prevStamina = stamina;
} }
public void checkForHealth() public void checkForHealth()
{ {
int health = CurrentPlayer.Health; if (MainClass.ModHelper == null)
return;
if (health <= 50) int health = CurrentPlayer.Health;
string toSpeak = MainClass.ModHelper.Translation.Get("warnings.label", new { type = "health", value = health });
if ((health <= 50 && prevHealth > 50) || (health <= 25 && prevHealth > 25) || (health <= 10 && prevHealth > 10))
{ {
// 50% health warning MainClass.DebugLog(toSpeak);
} MainClass.ScreenReader.Say(toSpeak, true);
else if (health <= 25)
{
// 25% health warning
}
else if (health <= 10)
{
// 10% health warning
} }
prevHealth = health;
} }
} }
} }

View File

@ -1,5 +1,4 @@
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using StardewModdingAPI;
using StardewValley; using StardewValley;
using StardewValley.Buildings; using StardewValley.Buildings;
using StardewValley.Locations; using StardewValley.Locations;

View File

@ -0,0 +1,3 @@
{
"warnings.label": "Warning! {{type}} is at {{value}} percent!"
}