summaryrefslogtreecommitdiff
path: root/src/StardewModdingAPI/Framework/InternalExtensions.cs
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2017-05-07 13:09:32 -0400
committerJesse Plamondon-Willard <github@jplamondonw.com>2017-05-07 13:09:32 -0400
commit624840efe5f3d4135dafeb2939b182cfeb4ec6c3 (patch)
tree0a791fae54d20320efc4c7cf55bc34f51ddf2d10 /src/StardewModdingAPI/Framework/InternalExtensions.cs
parent8963793bf854bee368b5cd08a3e0eb410ee8e1a9 (diff)
downloadSMAPI-624840efe5f3d4135dafeb2939b182cfeb4ec6c3.tar.gz
SMAPI-624840efe5f3d4135dafeb2939b182cfeb4ec6c3.tar.bz2
SMAPI-624840efe5f3d4135dafeb2939b182cfeb4ec6c3.zip
use more robust sprite batch recovery logic (#283)
Diffstat (limited to 'src/StardewModdingAPI/Framework/InternalExtensions.cs')
-rw-r--r--src/StardewModdingAPI/Framework/InternalExtensions.cs22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/StardewModdingAPI/Framework/InternalExtensions.cs b/src/StardewModdingAPI/Framework/InternalExtensions.cs
index 5199c72d..cadf6598 100644
--- a/src/StardewModdingAPI/Framework/InternalExtensions.cs
+++ b/src/StardewModdingAPI/Framework/InternalExtensions.cs
@@ -2,6 +2,8 @@
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
+using Microsoft.Xna.Framework.Graphics;
+using StardewValley;
namespace StardewModdingAPI.Framework
{
@@ -128,5 +130,25 @@ namespace StardewModdingAPI.Framework
deprecationManager.Warn(modName, nounPhrase, version, severity);
}
}
+
+ /****
+ ** Sprite batch
+ ****/
+ /// <summary>Get whether the sprite batch is between a begin and end pair.</summary>
+ /// <param name="spriteBatch">The sprite batch to check.</param>
+ /// <param name="reflection">The reflection helper with which to access private fields.</param>
+ public static bool IsOpen(this SpriteBatch spriteBatch, IReflectionHelper reflection)
+ {
+ // get field name
+ const string fieldName =
+#if SMAPI_FOR_WINDOWS
+ "inBeginEndPair";
+#else
+ "_beginCalled";
+#endif
+
+ // get result
+ return reflection.GetPrivateValue<bool>(Game1.spriteBatch, fieldName);
+ }
}
}