summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZoryn Aaron <zoryn4163@gmail.com>2016-03-23 01:11:13 -0400
committerZoryn Aaron <zoryn4163@gmail.com>2016-03-23 01:11:13 -0400
commita56e98c87cb67577f3e2e45f192df2835ded81fd (patch)
tree0837380745fc0139fd4880e25c4405a792c6d658
parent24e144d0f1aaae33fb51e80031259d0119acff7c (diff)
downloadSMAPI-a56e98c87cb67577f3e2e45f192df2835ded81fd.tar.gz
SMAPI-a56e98c87cb67577f3e2e45f192df2835ded81fd.tar.bz2
SMAPI-a56e98c87cb67577f3e2e45f192df2835ded81fd.zip
redoes getting keys because sillyness
-rw-r--r--StardewModdingAPI/Constants.cs2
-rw-r--r--StardewModdingAPI/Extensions.cs10
-rw-r--r--StardewModdingAPI/Inheritance/SGame.cs45
3 files changed, 43 insertions, 14 deletions
diff --git a/StardewModdingAPI/Constants.cs b/StardewModdingAPI/Constants.cs
index 41daa905..19425dda 100644
--- a/StardewModdingAPI/Constants.cs
+++ b/StardewModdingAPI/Constants.cs
@@ -48,7 +48,7 @@ namespace StardewModdingAPI
public const int MinorVersion = 38;
- public const int PatchVersion = 7;
+ public const int PatchVersion = 8;
public const string Build = "Alpha";
diff --git a/StardewModdingAPI/Extensions.cs b/StardewModdingAPI/Extensions.cs
index a0e87f04..53c69c29 100644
--- a/StardewModdingAPI/Extensions.cs
+++ b/StardewModdingAPI/Extensions.cs
@@ -21,10 +21,14 @@ namespace StardewModdingAPI
return new Color(Random.Next(0, 255), Random.Next(0, 255), Random.Next(0, 255));
}
- public static string ToSingular(this IEnumerable<Object> enumerable, string split = ", ")
+ public static string ToSingular(this IEnumerable ienum, string split = ", ")
{
- string result = string.Join(split, enumerable);
- return result;
+ //Apparently Keys[] won't split normally :l
+ if (ienum is Keys[])
+ {
+ return string.Join(split, (Keys[])ienum);
+ }
+ return string.Join(split, ienum);
}
public static bool IsInt32(this object o)
diff --git a/StardewModdingAPI/Inheritance/SGame.cs b/StardewModdingAPI/Inheritance/SGame.cs
index 8ba76ed3..da6260be 100644
--- a/StardewModdingAPI/Inheritance/SGame.cs
+++ b/StardewModdingAPI/Inheritance/SGame.cs
@@ -29,16 +29,16 @@ namespace StardewModdingAPI.Inheritance
public MouseState MStateNow { get; private set; }
public MouseState MStatePrior { get; private set; }
- public Keys[] CurrentlyPressedKeys { get; private set; }
- public Keys[] PreviouslyPressedKeys { get; private set; }
+ public Keys[] CurrentlyPressedKeys => KStateNow.GetPressedKeys();
+ public Keys[] PreviouslyPressedKeys => KStatePrior.GetPressedKeys();
public Keys[] FramePressedKeys
{
- get { return CurrentlyPressedKeys.Where(x => !PreviouslyPressedKeys.Contains(x)).ToArray(); }
+ get { return CurrentlyPressedKeys.Except(PreviouslyPressedKeys).ToArray(); }
}
public Keys[] FrameReleasedKeys
{
- get { return PreviouslyPressedKeys.Where(x => !CurrentlyPressedKeys.Contains(x)).ToArray(); }
+ get { return PreviouslyPressedKeys.Except(CurrentlyPressedKeys).ToArray(); }
}
public Buttons[][] PreviouslyPressedButtons;
@@ -180,6 +180,9 @@ namespace StardewModdingAPI.Inheritance
private static SGame instance;
public static SGame Instance => instance;
+ public static float FramesPerSecond { get; private set; }
+ public static bool Debug { get; private set; }
+
public Farmer CurrentFarmer => player;
public SGame()
@@ -192,7 +195,6 @@ namespace StardewModdingAPI.Inheritance
{
Log.Verbose("XNA Initialize");
ModItems = new Dictionary<Int32, SObject>();
- PreviouslyPressedKeys = new Keys[0];
PreviouslyPressedButtons = new Buttons[4][];
for (int i = 0; i < 4; ++i) PreviouslyPressedButtons[i] = new Buttons[0];
@@ -211,6 +213,11 @@ namespace StardewModdingAPI.Inheritance
{
UpdateEventCalls();
+ if (FramePressedKeys.Contains(Keys.F3))
+ {
+ Debug = !Debug;
+ }
+
try
{
base.Update(gameTime);
@@ -250,8 +257,10 @@ namespace StardewModdingAPI.Inheritance
if (CurrentUpdateTick >= 60)
CurrentUpdateTick = 0;
- PreviouslyPressedKeys = CurrentlyPressedKeys;
- for(PlayerIndex i = PlayerIndex.One; i <= PlayerIndex.Four; i++)
+ if (KStatePrior != KStateNow)
+ KStatePrior = KStateNow;
+
+ for (PlayerIndex i = PlayerIndex.One; i <= PlayerIndex.Four; i++)
{
PreviouslyPressedButtons[(int)i] = GetButtonsDown(i);
}
@@ -259,8 +268,26 @@ namespace StardewModdingAPI.Inheritance
protected override void Draw(GameTime gameTime)
{
- base.Draw(gameTime);
+ FramesPerSecond = 1 / (float)gameTime.ElapsedGameTime.TotalSeconds;
+
+ try
+ {
+ base.Draw(gameTime);
+ }
+ catch (Exception ex)
+ {
+ Log.Error("An error occured in the base draw loop: " + ex);
+ Console.ReadKey();
+ }
+
GraphicsEvents.InvokeDrawTick();
+
+ if (Debug)
+ {
+ spriteBatch.Begin();
+ spriteBatch.DrawString(dialogueFont, "FPS: " + FramesPerSecond, Vector2.Zero, Color.CornflowerBlue);
+ spriteBatch.End();
+ }
}
public static Int32 RegisterModItem(SObject modItem)
@@ -301,7 +328,6 @@ namespace StardewModdingAPI.Inheritance
public void UpdateEventCalls()
{
KStateNow = Keyboard.GetState();
- CurrentlyPressedKeys = KStateNow.GetPressedKeys();
MStateNow = Mouse.GetState();
@@ -346,7 +372,6 @@ namespace StardewModdingAPI.Inheritance
if (KStateNow != KStatePrior)
{
ControlEvents.InvokeKeyboardChanged(KStatePrior, KStateNow);
- KStatePrior = KStateNow;
}
if (MStateNow != MStatePrior)