Added current slot and location narration

master
shoaib11120 2021-12-19 18:32:36 +05:30
parent 6fb4cea854
commit 069769b2d6
3 changed files with 118 additions and 49 deletions

View File

@ -5,24 +5,14 @@ namespace stardew_access.Game
{
internal class CurrentPlayer
{
private static Farmer? player = null;
CurrentPlayer()
{
}
private static void initPlayer()
{
player = Game1.player;
}
internal static int getHealth()
{
if(player == null)
initPlayer();
if(Game1.player == null)
return 0;
int maxHealth = player.maxHealth;
int currentHealth = player.health;
int maxHealth = Game1.player.maxHealth;
int currentHealth = Game1.player.health;
int healthPercentage = (int) (currentHealth * 100)/maxHealth;
return healthPercentage;
@ -30,11 +20,11 @@ namespace stardew_access.Game
internal static int getStamina()
{
if (player == null)
initPlayer();
if (Game1.player == null)
return 0;
int maxStamina = player.maxStamina;
int currentStamine = (int)player.stamina;
int maxStamina = Game1.player.maxStamina;
int currentStamine = (int)Game1.player.stamina;
int staminaPercentage = (int)(currentStamine * 100) / maxStamina;
@ -43,37 +33,19 @@ namespace stardew_access.Game
internal static int getPositionX()
{
if (player == null)
initPlayer();
if (Game1.player == null)
return 0;
int x = (int)player.getTileLocation().X;
int x = (int)Game1.player.getTileLocation().X;
return x;
}
internal static int getPositionY()
{
if (player == null)
initPlayer();
if (Game1.player == null)
return 0;
int y = (int)player.getTileLocation().Y;
return y;
}
internal static int getToolHItPositionX()
{
if (player == null)
initPlayer();
int x = (int)player.GetGrabTile().X;
return x;
}
internal static int getToolHItPositionY()
{
if (player == null)
initPlayer();
int y = (int)player.GetGrabTile().Y;
int y = (int)Game1.player.getTileLocation().Y;
return y;
}
}

View File

@ -0,0 +1,45 @@

using StardewModdingAPI;
using StardewValley;
namespace stardew_access.Game
{
internal class SlotAndLocation
{
private static Item? currentSlotItem;
private static Item? previousSlotItem;
private static GameLocation? currentLocation;
private static GameLocation? previousLocation;
// Narrates current slected slot name
public static void narrateCurrentSlot()
{
currentSlotItem = Game1.player.CurrentItem;
if (currentSlotItem == null)
return;
if (previousSlotItem == currentSlotItem)
return;
previousSlotItem = currentSlotItem;
ScreenReader.say(currentSlotItem.Name, true);
}
// Narrates current location's name
public static void narrateCurrentLocation()
{
currentLocation = Game1.currentLocation;
if (currentLocation == null)
return;
if (previousLocation == currentLocation)
return;
previousLocation = currentLocation;
ScreenReader.say(currentLocation.Name,true);
}
}
}

View File

@ -9,6 +9,8 @@ using stardew_access.Patches;
using AutoHotkey.Interop;
using Microsoft.Xna.Framework;
using StardewValley.TerrainFeatures;
using StardewValley.Locations;
using StardewValley.Objects;
namespace stardew_access
{
@ -119,11 +121,25 @@ namespace stardew_access
snapMouse = !snapMouse;
monitor.Log("Snap Mouse is " + (snapMouse ? "on" : "off"), LogLevel.Info);
});
});
helper.ConsoleCommands.Add("ref_sr", "Refresh screen reader", (string arg1, string[] arg2) =>
{
ScreenReader.initializeScreenReader();
monitor.Log("Screen Reader refreshed!", LogLevel.Info);
});
#endregion
helper.Events.Input.ButtonPressed += this.OnButtonPressed;
helper.Events.GameLoop.UpdateTicked += this.onUpdateTicked;
helper.Events.GameLoop.OneSecondUpdateTicked += this.onOneSecondUpdateTicked;
}
private void onOneSecondUpdateTicked(object sender, OneSecondUpdateTickedEventArgs e)
{
if (!Context.IsPlayerFree)
return;
}
private void onUpdateTicked(object sender, UpdateTickedEventArgs e)
@ -133,7 +149,11 @@ namespace stardew_access
MenuPatch.resetGlobalVars();
if(snapMouse)
SlotAndLocation.narrateCurrentSlot();
SlotAndLocation.narrateCurrentLocation();
if (snapMouse)
SnapMouseToPlayer();
if(!isReadingTile && readTile)
@ -203,7 +223,6 @@ namespace stardew_access
try
{
#region Get Correct Grab Tile
int x = Game1.player.GetBoundingBox().Center.X;
int y = Game1.player.GetBoundingBox().Center.Y;
@ -236,6 +255,11 @@ namespace stardew_access
Dictionary<Vector2, Netcode.NetRef<TerrainFeature>> terrainFeature = Game1.currentLocation.terrainFeatures.FieldDict;
StardewValley.Object obj = Game1.currentLocation.getObjectAtTile((int)gt.X, (int)gt.Y);
// Mine loc x49 y14
// x41 y7 allyway
// x40 y7
// x41 y0 entrance
// x40 y0
if (!Equals(gt, prevTile))
{
prevTile = gt;
@ -243,6 +267,17 @@ namespace stardew_access
{
string name = obj.name;
monitor.Log(obj.parentSheetIndex.ToString(), LogLevel.Debug);
if (Game1.objectInformation.ContainsKey(obj.ParentSheetIndex) && name.ToLower().Equals("stone"))
{
string info = Game1.objectInformation[obj.parentSheetIndex];
if (info.ToLower().Contains("copper"))
name = "Copper " + name;
else if (info.ToLower().Contains("iron"))
name = "Iron " + name;
monitor.Log(info, LogLevel.Debug);
}
ScreenReader.say(name, true);
}
else if (terrainFeature.ContainsKey(gt))
@ -270,7 +305,6 @@ namespace stardew_access
if (isHarvestable)
toSpeak = "Harvestable " + toSpeak;
monitor.Log(toSpeak, LogLevel.Debug);
ScreenReader.say(toSpeak, true);
} else
{
@ -377,10 +411,28 @@ namespace stardew_access
string toSpeak = "Leaf";
ScreenReader.say(toSpeak, true);
}
else
}
else
{
Game1.currentLocation.resourceClumps.ToList().ForEach(x =>
{
monitor.Log($"LTF {terrain.Get() is ResourceClump}", LogLevel.Debug);
}
if(x.occupiesTile((int)gt.X, (int)gt.Y))
{
monitor.Log("here", LogLevel.Debug);
string toSpeak = " ";
if (Game1.objectInformation.ContainsKey(obj.ParentSheetIndex))
{
toSpeak = Game1.objectInformation[x.parentSheetIndex];
} else
{
toSpeak = x.parentSheetIndex.ToString();
}
monitor.Log(toSpeak, LogLevel.Debug);
ScreenReader.say(toSpeak, true);
return;
}
});
}
}
}