minor cleanup

This commit is contained in:
Jesse Plamondon-Willard 2020-09-05 15:41:21 -04:00
parent 4f3d7eaafc
commit 55cd31f4f7
No known key found for this signature in database
GPG Key ID: CF8B1456B3E29F49
10 changed files with 13 additions and 27 deletions

View File

@ -95,7 +95,7 @@ namespace StardewModdingAPI.Framework
this.ContentManagers.Add( this.ContentManagers.Add(
this.MainContentManager = new GameContentManager("Game1.content", serviceProvider, rootDirectory, currentCulture, this, monitor, reflection, this.OnDisposing, onLoadingFirstAsset) this.MainContentManager = new GameContentManager("Game1.content", serviceProvider, rootDirectory, currentCulture, this, monitor, reflection, this.OnDisposing, onLoadingFirstAsset)
); );
this.CoreAssets = new CoreAssetPropagator(this.MainContentManager.AssertAndNormalizeAssetName, reflection, monitor); this.CoreAssets = new CoreAssetPropagator(this.MainContentManager.AssertAndNormalizeAssetName, reflection);
} }
/// <summary>Get a new content manager which handles reading files from the game content folder with support for interception.</summary> /// <summary>Get a new content manager which handles reading files from the game content folder with support for interception.</summary>
@ -236,7 +236,7 @@ namespace StardewModdingAPI.Framework
{ {
foreach (var entry in contentManager.InvalidateCache(predicate, dispose)) foreach (var entry in contentManager.InvalidateCache(predicate, dispose))
{ {
if (!removedAssets.TryGetValue(entry.Key, out Type type)) if (!removedAssets.ContainsKey(entry.Key))
removedAssets[entry.Key] = entry.Value.GetType(); removedAssets[entry.Key] = entry.Value.GetType();
} }
} }

View File

@ -1,10 +1,7 @@
using System; using System;
using System.IO; using System.IO;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using StardewModdingAPI.Toolkit.Serialization; using StardewModdingAPI.Toolkit.Serialization;
using StardewModdingAPI.Toolkit.Utilities; using StardewModdingAPI.Toolkit.Utilities;
using xTile;
namespace StardewModdingAPI.Framework namespace StardewModdingAPI.Framework
{ {

View File

@ -5,13 +5,10 @@ using System.Diagnostics.CodeAnalysis;
using System.Diagnostics.Contracts; using System.Diagnostics.Contracts;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using StardewModdingAPI.Framework.Content; using StardewModdingAPI.Framework.Content;
using StardewModdingAPI.Framework.ContentManagers; using StardewModdingAPI.Framework.ContentManagers;
using StardewModdingAPI.Framework.Exceptions; using StardewModdingAPI.Framework.Exceptions;
using StardewValley; using StardewValley;
using xTile;
namespace StardewModdingAPI.Framework.ModHelpers namespace StardewModdingAPI.Framework.ModHelpers
{ {

View File

@ -409,10 +409,10 @@ namespace StardewModdingAPI.Framework.ModLoading
if (handler.Phrases.Any()) if (handler.Phrases.Any())
{ {
foreach (string message in handler.Phrases) foreach (string message in handler.Phrases)
this.Monitor.LogOnce(template.Replace("$phrase", message)); this.Monitor.LogOnce(loggedMessages, template.Replace("$phrase", message));
} }
else else
this.Monitor.LogOnce(template.Replace("$phrase", handler.DefaultPhrase ?? handler.GetType().Name)); this.Monitor.LogOnce(loggedMessages, template.Replace("$phrase", handler.DefaultPhrase ?? handler.GetType().Name));
} }
/// <summary>Get the correct reference to use for compatibility with the current platform.</summary> /// <summary>Get the correct reference to use for compatibility with the current platform.</summary>

View File

@ -49,7 +49,7 @@ namespace StardewModdingAPI.Framework.ModLoading.Finders
MethodDefinition target = methodRef.Resolve(); MethodDefinition target = methodRef.Resolve();
if (target == null) if (target == null)
{ {
string phrase = null; string phrase;
if (this.IsProperty(methodRef)) if (this.IsProperty(methodRef))
phrase = $"reference to {methodRef.DeclaringType.FullName}.{methodRef.Name.Substring(4)} (no such property)"; phrase = $"reference to {methodRef.DeclaringType.FullName}.{methodRef.Name.Substring(4)} (no such property)";
else if (methodRef.Name == ".ctor") else if (methodRef.Name == ".ctor")

View File

@ -263,7 +263,7 @@ namespace StardewModdingAPI.Framework.Reflection
CacheEntry entry = (CacheEntry)this.Cache[key]; CacheEntry entry = (CacheEntry)this.Cache[key];
return entry.IsValid return entry.IsValid
? (TMemberInfo)entry.MemberInfo ? (TMemberInfo)entry.MemberInfo
: default(TMemberInfo); : default;
} }
// fetch & cache new value // fetch & cache new value

View File

@ -93,17 +93,17 @@ namespace StardewModdingAPI.Framework.Rendering
{ {
if (tile == null) if (tile == null)
return; return;
xTile.Dimensions.Rectangle tileImageBounds = tile.TileSheet.GetTileImageBounds(tile.TileIndex); Rectangle tileImageBounds = tile.TileSheet.GetTileImageBounds(tile.TileIndex);
Texture2D tileSheetTexture = this.m_tileSheetTextures[tile.TileSheet]; Texture2D tileSheetTexture = this.m_tileSheetTextures[tile.TileSheet];
if (tileSheetTexture.IsDisposed) if (tileSheetTexture.IsDisposed)
return; return;
this.m_tilePosition.X = (float)location.X; this.m_tilePosition.X = location.X;
this.m_tilePosition.Y = (float)location.Y; this.m_tilePosition.Y = location.Y;
this.m_sourceRectangle.X = tileImageBounds.X; this.m_sourceRectangle.X = tileImageBounds.X;
this.m_sourceRectangle.Y = tileImageBounds.Y; this.m_sourceRectangle.Y = tileImageBounds.Y;
this.m_sourceRectangle.Width = tileImageBounds.Width; this.m_sourceRectangle.Width = tileImageBounds.Width;
this.m_sourceRectangle.Height = tileImageBounds.Height; this.m_sourceRectangle.Height = tileImageBounds.Height;
this.m_spriteBatchAlpha.Draw(tileSheetTexture, this.m_tilePosition, new Microsoft.Xna.Framework.Rectangle?(this.m_sourceRectangle), this.m_modulationColour, 0.0f, Vector2.Zero, (float)Layer.zoom, SpriteEffects.None, layerDepth); this.m_spriteBatchAlpha.Draw(tileSheetTexture, this.m_tilePosition, this.m_sourceRectangle, this.m_modulationColour, 0.0f, Vector2.Zero, Layer.zoom, SpriteEffects.None, layerDepth);
} }
/// <summary>Finish drawing to the screen.</summary> /// <summary>Finish drawing to the screen.</summary>

View File

@ -297,8 +297,6 @@ namespace StardewModdingAPI.Framework
} }
if (Game1.currentMinigame != null) if (Game1.currentMinigame != null)
{ {
bool batchEnded = false;
if (events.Rendering.HasListeners()) if (events.Rendering.HasListeners())
{ {
Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, null, null); Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, null, null);
@ -321,12 +319,11 @@ namespace StardewModdingAPI.Framework
Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearClamp, DepthStencilState.Default, RasterizerState.CullNone); Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearClamp, DepthStencilState.Default, RasterizerState.CullNone);
Game1.spriteBatch.Draw(target_screen, Vector2.Zero, target_screen.Bounds, Color.White, 0f, Vector2.Zero, Game1.options.zoomLevel, SpriteEffects.None, 1f); Game1.spriteBatch.Draw(target_screen, Vector2.Zero, target_screen.Bounds, Color.White, 0f, Vector2.Zero, Game1.options.zoomLevel, SpriteEffects.None, 1f);
events.Rendered.RaiseEmpty(); events.Rendered.RaiseEmpty();
batchEnded = true;
Game1.spriteBatch.End(); Game1.spriteBatch.End();
} }
else else
{ {
if (!batchEnded && events.Rendered.HasListeners()) if (events.Rendered.HasListeners())
{ {
Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, null, null); Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, null, null);
events.Rendered.RaiseEmpty(); events.Rendered.RaiseEmpty();

View File

@ -34,9 +34,6 @@ namespace StardewModdingAPI.Metadata
/// <summary>Simplifies access to private game code.</summary> /// <summary>Simplifies access to private game code.</summary>
private readonly Reflector Reflection; private readonly Reflector Reflection;
/// <summary>Encapsulates monitoring and logging.</summary>
private readonly IMonitor Monitor;
/// <summary>Optimized bucket categories for batch reloading assets.</summary> /// <summary>Optimized bucket categories for batch reloading assets.</summary>
private enum AssetBucket private enum AssetBucket
{ {
@ -57,12 +54,10 @@ namespace StardewModdingAPI.Metadata
/// <summary>Initialize the core asset data.</summary> /// <summary>Initialize the core asset data.</summary>
/// <param name="assertAndNormalizeAssetName">Normalizes an asset key to match the cache key and assert that it's valid.</param> /// <param name="assertAndNormalizeAssetName">Normalizes an asset key to match the cache key and assert that it's valid.</param>
/// <param name="reflection">Simplifies access to private code.</param> /// <param name="reflection">Simplifies access to private code.</param>
/// <param name="monitor">Encapsulates monitoring and logging.</param> public CoreAssetPropagator(Func<string, string> assertAndNormalizeAssetName, Reflector reflection)
public CoreAssetPropagator(Func<string, string> assertAndNormalizeAssetName, Reflector reflection, IMonitor monitor)
{ {
this.AssertAndNormalizeAssetName = assertAndNormalizeAssetName; this.AssertAndNormalizeAssetName = assertAndNormalizeAssetName;
this.Reflection = reflection; this.Reflection = reflection;
this.Monitor = monitor;
} }
/// <summary>Reload one of the game's core assets (if applicable).</summary> /// <summary>Reload one of the game's core assets (if applicable).</summary>

View File

@ -681,7 +681,7 @@ namespace StardewModdingAPI
} }
// not valid // not valid
button = default(InputButton); button = default;
return false; return false;
} }