- Supports NVDA, JAWS and SAPI

- Narrates/Speaks dialogues
- Narrates/Speaks health and stamina on pressing `R`
This commit is contained in:
shoaib11120
2021-12-07 19:09:12 +05:30
commit 218e418945
8 changed files with 662 additions and 0 deletions

View File

@@ -0,0 +1,44 @@
using StardewValley;
using StardewModdingAPI;
namespace stardew_access.Game
{
internal class CurrentPlayer
{
private static Farmer player = null;
CurrentPlayer()
{
}
private static void initPlayer()
{
player = Game1.player;
}
public static int getHealth()
{
if(player == null)
initPlayer();
int maxHealth = player.maxHealth;
int currentHealth = player.health;
int healthPercentage = (int) (currentHealth * 100)/maxHealth;
return healthPercentage;
}
public static int getStamina()
{
if (player == null)
initPlayer();
int maxStamina = player.maxStamina;
int currentStamine = (int)player.stamina;
int staminaPercentage = (int)(currentStamine * 100) / maxStamina;
return staminaPercentage;
}
}
}

117
stardew-access/ModEntry.cs Normal file
View File

@@ -0,0 +1,117 @@
using AccessibleOutput;
using stardew_access.Game;
using StardewModdingAPI;
using StardewModdingAPI.Events;
using StardewValley;
using HarmonyLib;
namespace stardew_access
{
/// <summary>The mod entry point.</summary>
public class MainClass : Mod
{
public static IAccessibleOutput screenReader;
Harmony harmony;
public static IMonitor monitor;
/*********
** Public methods
*********/
/// <summary>The mod entry point, called after the mod is first loaded.</summary>
/// <param name="helper">Provides simplified APIs for writing mods.</param>
public override void Entry(IModHelper helper)
{
// Inititalize monitor
monitor = Monitor;
// Initialize the screen reader
initializeScreenReader();
// Init harmony
harmony = new Harmony(ModManifest.UniqueID);
// Add patches
harmony.Patch(
original: AccessTools.Constructor(typeof(StardewValley.Menus.DialogueBox), new Type[] { typeof(Dialogue) }),
postfix: new HarmonyMethod(typeof(MainClass), nameof(MainClass.Dialog_post))
);
harmony.Patch(
original:,
postfix:
);
helper.Events.Input.ButtonPressed += this.OnButtonPressed;
}
private static void Dialog_post(Dialogue dialogue)
{
try
{
string speakerName = dialogue.speaker.Name;
List<string> dialogues = dialogue.dialogues;
int dialogueIndex = dialogue.currentDialogueIndex;
screenReader.Speak($"{speakerName} said, {dialogues[dialogueIndex]}", false);
monitor.Log($"Dialogue", LogLevel.Info);
}catch (Exception e)
{
monitor.Log($"Unable to narrate dialog:\n{e.StackTrace}", LogLevel.Error);
}
}
private void initializeScreenReader()
{
NvdaOutput nvdaOutput = null;
JawsOutput jawsOutput = null;
SapiOutput sapiOutput = null;
// Initialize NVDA
try{
nvdaOutput = new NvdaOutput();
}catch(Exception ex){
Monitor.Log($"Error initializing NVDA:\n{ex.StackTrace}", LogLevel.Error);
}
// Initialize JAWS
try
{
jawsOutput = new JawsOutput();
}catch (Exception ex){
Monitor.Log($"Error initializing JAWS:\n{ex.StackTrace}", LogLevel.Error);
}
// Initialize SAPI
try
{
sapiOutput = new SapiOutput();
}catch (Exception ex){
Monitor.Log($"Error initializing SAPI:\n{ex.StackTrace}", LogLevel.Error);
}
if (nvdaOutput != null && nvdaOutput.IsAvailable())
screenReader = nvdaOutput;
if(jawsOutput != null && jawsOutput.IsAvailable())
screenReader = jawsOutput;
if (sapiOutput != null && sapiOutput.IsAvailable())
screenReader = sapiOutput;
}
private void OnButtonPressed(object sender, ButtonPressedEventArgs e)
{
// ignore if player hasn't loaded a save yet
if (!Context.IsWorldReady)
return;
// Narrate Health And Energy
if (Equals(e.Button, SButton.R))
{
screenReader.Speak($"Health is {CurrentPlayer.getHealth()} and Stamina is {CurrentPlayer.getStamina()}");
}
}
}
}

View File

@@ -0,0 +1,10 @@
{
"Name": "Stardew Access",
"Author": "Mohammad Shoaib",
"Version": "1.0.0",
"Description": "<One or two sentences about the mod>",
"UniqueID": "shoaib.stardewaccess",
"EntryDll": "stardew-access.dll",
"MinimumApiVersion": "3.0.0",
"UpdateKeys": []
}

View File

@@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net452</TargetFramework>
<RootNamespace>stardew_access</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>preview</LangVersion>
<PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AccessibleOutput" Version="1.0.0" />
<PackageReference Include="Lib.Harmony" Version="2.1.1" />
<PackageReference Include="Pathoschild.Stardew.ModBuildConfig" Version="4.0.0" />
</ItemGroup>
<ItemGroup>
<Reference Include="System.Net" />
<Reference Include="System.Net.Http" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net452</TargetFramework>
<RootNamespace>stardew_access</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>preview</LangVersion>
<summary>MainClass.ModEntry</summary>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AccessibleOutput" Version="1.0.0" />
<PackageReference Include="Pathoschild.Stardew.ModBuildConfig" Version="4.0.0" />
</ItemGroup>
</Project>