Code documentation

master
Mohammad Shoaib 2022-05-11 13:14:46 +05:30
parent d27c7c749c
commit eb25243377
5 changed files with 166 additions and 116 deletions

View File

@ -6,121 +6,171 @@ namespace stardew_access.Features
internal class CurrentPlayer internal class CurrentPlayer
{ {
public static int getHealth() /// <summary>
/// Returns the percentage health remaining of player.
/// </summary>
public static int Health
{ {
if (Game1.player == null) get
return 0;
int maxHealth = Game1.player.maxHealth;
int currentHealth = Game1.player.health;
int healthPercentage = (int)(currentHealth * 100) / maxHealth;
return healthPercentage;
}
public static int getStamina()
{
if (Game1.player == null)
return 0;
int maxStamina = Game1.player.maxStamina.Value;
int currentStamine = (int)Game1.player.stamina;
int staminaPercentage = (int)(currentStamine * 100) / maxStamina;
return staminaPercentage;
}
public static Vector2 getPosition()
{
if (Game1.player == null)
return Vector2.Zero;
return Game1.player.getTileLocation();
}
public static int getPositionX()
{
if (Game1.player == null)
return 0;
return (int)getPosition().X;
}
public static int getPositionY()
{
if (Game1.player == null)
return 0;
return (int)getPosition().Y;
}
public static string getTimeOfDay()
{
int timeOfDay = Game1.timeOfDay;
int minutes = timeOfDay % 100;
int hours = timeOfDay / 100;
string amOrpm = "A M";
if (hours >= 12)
{ {
amOrpm = "P M"; if (Game1.player == null)
if (hours > 12) return 0;
hours -= 12;
int maxHealth = Game1.player.maxHealth;
int currentHealth = Game1.player.health;
int healthPercentage = (int)(currentHealth * 100) / maxHealth;
return healthPercentage;
} }
return $"{hours}:{minutes} {amOrpm}";
} }
public static string getSeason() /// <summary>
/// Returns the percentage stamine/energy remaining of player.
/// </summary>
public static int Stamina
{ {
return Game1.CurrentSeasonDisplayName; get
}
public static int getDate()
{
return Game1.dayOfMonth;
}
public static string getDay()
{
return Game1.Date.DayOfWeek.ToString();
}
public static int getMoney()
{
if (Game1.player == null)
return -1;
return Game1.player.Money;
}
public static Vector2 getNextTile()
{
int x = Game1.player.GetBoundingBox().Center.X;
int y = Game1.player.GetBoundingBox().Center.Y;
int offset = 64;
switch (Game1.player.FacingDirection)
{ {
case 0: if (Game1.player == null)
y -= offset; return 0;
break;
case 1:
x += offset;
break;
case 2:
y += offset;
break;
case 3:
x -= offset;
break;
}
x /= Game1.tileSize; int maxStamina = Game1.player.maxStamina.Value;
y /= Game1.tileSize; int currentStamine = (int)Game1.player.stamina;
return new Vector2(x, y);
int staminaPercentage = (int)(currentStamine * 100) / maxStamina;
return staminaPercentage;
}
}
/// <summary>
/// Returns the tile location of the player
/// </summary>
public static Vector2 Position
{
get
{
if (Game1.player == null)
return Vector2.Zero;
return Game1.player.getTileLocation();
}
}
/// <summary>
/// Returns the X coordinate of the player
/// </summary>
public static int PositionX
{
get
{
if (Game1.player == null)
return 0;
return (int)Position.X;
}
}
/// <summary>
/// Returns the Y coordinate of the player
/// </summary>
public static int PositionY
{
get
{
if (Game1.player == null)
return 0;
return (int)Position.Y;
}
}
/// <summary>
/// Returns the time in the 12 hours format
/// </summary>
public static string TimeOfDay
{
get
{
int timeOfDay = Game1.timeOfDay;
int minutes = timeOfDay % 100;
int hours = timeOfDay / 100;
string amOrpm = "A M";
if (hours >= 12)
{
amOrpm = "P M";
if (hours > 12)
hours -= 12;
}
return $"{hours}:{minutes} {amOrpm}";
}
}
/// <summary>
/// Returns the current season
/// </summary>
public static string Season => Game1.CurrentSeasonDisplayName;
/// <summary>
/// Returns the current date of month
/// </summary>
public static int Date => Game1.dayOfMonth;
/// <summary>
/// Returns the current day of week
/// </summary>
/// <returns></returns>
public static string Day => Game1.Date.DayOfWeek.ToString();
/// <summary>
/// Returns the amount of money the player has currently
/// </summary>
public static int Money
{
get
{
if (Game1.player == null)
return -1;
return Game1.player.Money;
}
}
/// <summary>
/// Returns the tile position of the tile the player is facing
/// </summary>
/// <value></value>
public static Vector2 FacingTile
{
get
{
int x = Game1.player.GetBoundingBox().Center.X;
int y = Game1.player.GetBoundingBox().Center.Y;
int offset = 64;
switch (Game1.player.FacingDirection)
{
case 0:
y -= offset;
break;
case 1:
x += offset;
break;
case 2:
y += offset;
break;
case 3:
x -= offset;
break;
}
x /= Game1.tileSize;
y /= Game1.tileSize;
return new Vector2(x, y);
}
} }
} }
} }

View File

@ -262,7 +262,7 @@ namespace stardew_access.Features
#region Check whether to skip the object or not #region Check whether to skip the object or not
// Skip if player is directly looking at the tile // Skip if player is directly looking at the tile
if (CurrentPlayer.getNextTile().Equals(position)) if (CurrentPlayer.FacingTile.Equals(position))
return; return;
if (!radarFocus) if (!radarFocus)

View File

@ -25,12 +25,12 @@ namespace stardew_access.Features
if (!playersPosition) if (!playersPosition)
{ {
// Grab tile // Grab tile
tile = CurrentPlayer.getNextTile(); tile = CurrentPlayer.FacingTile;
} }
else else
{ {
// Player's standing tile // Player's standing tile
tile = CurrentPlayer.getPosition(); tile = CurrentPlayer.Position;
} }
x = (int)tile.X; x = (int)tile.X;
y = (int)tile.Y; y = (int)tile.Y;

View File

@ -220,11 +220,11 @@ namespace stardew_access
string toSpeak; string toSpeak;
if (Config.VerboseCoordinates) if (Config.VerboseCoordinates)
{ {
toSpeak = $"X: {CurrentPlayer.getPositionX()}, Y: {CurrentPlayer.getPositionY()}"; toSpeak = $"X: {CurrentPlayer.PositionX}, Y: {CurrentPlayer.PositionY}";
} }
else else
{ {
toSpeak = $"{CurrentPlayer.getPositionX()}, {CurrentPlayer.getPositionY()}"; toSpeak = $"{CurrentPlayer.PositionX}, {CurrentPlayer.PositionY}";
} }
MainClass.ScreenReader.Say(toSpeak, true); MainClass.ScreenReader.Say(toSpeak, true);
@ -234,7 +234,7 @@ namespace stardew_access
// Narrate health and stamina // Narrate health and stamina
if (Config.HealthNStaminaKey.JustPressed()) if (Config.HealthNStaminaKey.JustPressed())
{ {
string toSpeak = $"Health is {CurrentPlayer.getHealth()} and Stamina is {CurrentPlayer.getStamina()}"; string toSpeak = $"Health is {CurrentPlayer.Health} and Stamina is {CurrentPlayer.Stamina}";
MainClass.ScreenReader.Say(toSpeak, true); MainClass.ScreenReader.Say(toSpeak, true);
return; return;
} }
@ -242,7 +242,7 @@ namespace stardew_access
// Narrate money at hand // Narrate money at hand
if (Config.MoneyKey.JustPressed()) if (Config.MoneyKey.JustPressed())
{ {
string toSpeak = $"You have {CurrentPlayer.getMoney()}g"; string toSpeak = $"You have {CurrentPlayer.Money}g";
MainClass.ScreenReader.Say(toSpeak, true); MainClass.ScreenReader.Say(toSpeak, true);
return; return;
} }
@ -250,7 +250,7 @@ namespace stardew_access
// Narrate time and season // Narrate time and season
if (Config.TimeNSeasonKey.JustPressed()) if (Config.TimeNSeasonKey.JustPressed())
{ {
string toSpeak = $"Time is {CurrentPlayer.getTimeOfDay()} and it is {CurrentPlayer.getDay()} {CurrentPlayer.getDate()} of {CurrentPlayer.getSeason()}"; string toSpeak = $"Time is {CurrentPlayer.TimeOfDay} and it is {CurrentPlayer.Day} {CurrentPlayer.Date} of {CurrentPlayer.Season}";
MainClass.ScreenReader.Say(toSpeak, true); MainClass.ScreenReader.Say(toSpeak, true);
return; return;
} }

View File

@ -436,7 +436,7 @@ namespace stardew_access.Patches
if (cueName == "grassyStep" || cueName == "sandyStep" || cueName == "snowyStep" || cueName == "stoneStep" || cueName == "thudStep" || cueName == "woodyStep") if (cueName == "grassyStep" || cueName == "sandyStep" || cueName == "snowyStep" || cueName == "stoneStep" || cueName == "thudStep" || cueName == "woodyStep")
{ {
Vector2 nextTile = CurrentPlayer.getNextTile(); Vector2 nextTile = CurrentPlayer.FacingTile;
if (TileInfo.isCollidingAtTile((int)nextTile.X, (int)nextTile.Y)) if (TileInfo.isCollidingAtTile((int)nextTile.X, (int)nextTile.Y))
{ {
if (prevTile != nextTile) if (prevTile != nextTile)