From 828be405e11dd8bc7f8a3692d2c74517734f67a5 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 30 Aug 2020 22:53:19 -0400 Subject: use inheritdoc --- src/SMAPI/Framework/ModHelpers/ContentHelper.cs | 41 +++++++------------------ 1 file changed, 11 insertions(+), 30 deletions(-) (limited to 'src/SMAPI/Framework/ModHelpers/ContentHelper.cs') diff --git a/src/SMAPI/Framework/ModHelpers/ContentHelper.cs b/src/SMAPI/Framework/ModHelpers/ContentHelper.cs index 23e45fd1..80f61c13 100644 --- a/src/SMAPI/Framework/ModHelpers/ContentHelper.cs +++ b/src/SMAPI/Framework/ModHelpers/ContentHelper.cs @@ -40,10 +40,10 @@ namespace StardewModdingAPI.Framework.ModHelpers /********* ** Accessors *********/ - /// The game's current locale code (like pt-BR). + /// public string CurrentLocale => this.GameContentManager.GetLocale(); - /// The game's current locale as an enum value. + /// public LocalizedContentManager.LanguageCode CurrentLocaleConstant => this.GameContentManager.Language; /// The observable implementation of . @@ -52,10 +52,10 @@ namespace StardewModdingAPI.Framework.ModHelpers /// The observable implementation of . internal ObservableCollection ObservableAssetLoaders { get; } = new ObservableCollection(); - /// Interceptors which provide the initial versions of matching content assets. + /// public IList AssetLoaders => this.ObservableAssetLoaders; - /// Interceptors which edit matching content assets after they're loaded. + /// public IList AssetEditors => this.ObservableAssetEditors; @@ -80,12 +80,7 @@ namespace StardewModdingAPI.Framework.ModHelpers this.Monitor = monitor; } - /// Load content from the game folder or mod folder (if not already cached), and return it. When loading a .png file, this must be called outside the game's draw loop. - /// The expected data type. The main supported types are , , and dictionaries; other types may be supported by the game's content pipeline. - /// The asset key to fetch (if the is ), or the local path to a content file relative to the mod folder. - /// Where to search for a matching content asset. - /// The is empty or contains invalid characters. - /// The content asset couldn't be loaded (e.g. because it doesn't exist). + /// public T Load(string key, ContentSource source = ContentSource.ModFolder) { try @@ -109,18 +104,14 @@ namespace StardewModdingAPI.Framework.ModHelpers } } - /// Normalize an asset name so it's consistent with those generated by the game. This is mainly useful for string comparisons like on generated asset names, and isn't necessary when passing asset names into other content helper methods. - /// The asset key. + /// [Pure] public string NormalizeAssetName(string assetName) { return this.ModContentManager.AssertAndNormalizeAssetName(assetName); } - /// Get the underlying key in the game's content cache for an asset. This can be used to load custom map tilesheets, but should be avoided when you can use the content API instead. This does not validate whether the asset exists. - /// The asset key to fetch (if the is ), or the local path to a content file relative to the mod folder. - /// Where to search for a matching content asset. - /// The is empty or contains invalid characters. + /// public string GetActualAssetKey(string key, ContentSource source = ContentSource.ModFolder) { switch (source) @@ -136,10 +127,7 @@ namespace StardewModdingAPI.Framework.ModHelpers } } - /// Remove an asset from the content cache so it's reloaded on the next request. This will reload core game assets if needed, but references to the former asset will still show the previous content. - /// The asset key to invalidate in the content folder. - /// The is empty or contains invalid characters. - /// Returns whether the given asset key was cached. + /// public bool InvalidateCache(string key) { string actualKey = this.GetActualAssetKey(key, ContentSource.GameContent); @@ -147,28 +135,21 @@ namespace StardewModdingAPI.Framework.ModHelpers return this.ContentCore.InvalidateCache(asset => asset.AssetNameEquals(actualKey)).Any(); } - /// Remove all assets of the given type from the cache so they're reloaded on the next request. This can be a very expensive operation and should only be used in very specific cases. This will reload core game assets if needed, but references to the former assets will still show the previous content. - /// The asset type to remove from the cache. - /// Returns whether any assets were invalidated. + /// public bool InvalidateCache() { this.Monitor.Log($"Requested cache invalidation for all assets of type {typeof(T)}. This is an expensive operation and should be avoided if possible.", LogLevel.Trace); return this.ContentCore.InvalidateCache((key, type) => typeof(T).IsAssignableFrom(type)).Any(); } - /// Remove matching assets from the content cache so they're reloaded on the next request. This will reload core game assets if needed, but references to the former asset will still show the previous content. - /// A predicate matching the assets to invalidate. - /// Returns whether any cache entries were invalidated. + /// public bool InvalidateCache(Func predicate) { this.Monitor.Log("Requested cache invalidation for all assets matching a predicate.", LogLevel.Trace); return this.ContentCore.InvalidateCache(predicate).Any(); } - /// Get a patch helper for arbitrary data. - /// The data type. - /// The asset data. - /// The asset name. This is only used for tracking purposes and has no effect on the patch helper. + /// public IAssetData GetPatchHelper(T data, string assetName = null) { if (data == null) -- cgit From 55cd31f4f7d5122149c02abfaf0f408298503c6a Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sat, 5 Sep 2020 15:41:21 -0400 Subject: minor cleanup --- src/SMAPI/Framework/ContentCoordinator.cs | 4 ++-- src/SMAPI/Framework/ContentPack.cs | 3 --- src/SMAPI/Framework/ModHelpers/ContentHelper.cs | 3 --- src/SMAPI/Framework/ModLoading/AssemblyLoader.cs | 4 ++-- .../ModLoading/Finders/ReferenceToMissingMemberFinder.cs | 2 +- src/SMAPI/Framework/Reflection/Reflector.cs | 2 +- src/SMAPI/Framework/Rendering/SXnaDisplayDevice.cs | 8 ++++---- src/SMAPI/Framework/SGame.cs | 5 +---- src/SMAPI/Metadata/CoreAssetPropagator.cs | 7 +------ src/SMAPI/SButton.cs | 2 +- 10 files changed, 13 insertions(+), 27 deletions(-) (limited to 'src/SMAPI/Framework/ModHelpers/ContentHelper.cs') diff --git a/src/SMAPI/Framework/ContentCoordinator.cs b/src/SMAPI/Framework/ContentCoordinator.cs index d1021cad..93371415 100644 --- a/src/SMAPI/Framework/ContentCoordinator.cs +++ b/src/SMAPI/Framework/ContentCoordinator.cs @@ -95,7 +95,7 @@ namespace StardewModdingAPI.Framework this.ContentManagers.Add( 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); } /// Get a new content manager which handles reading files from the game content folder with support for interception. @@ -236,7 +236,7 @@ namespace StardewModdingAPI.Framework { 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(); } } diff --git a/src/SMAPI/Framework/ContentPack.cs b/src/SMAPI/Framework/ContentPack.cs index 43621141..55c1a0b2 100644 --- a/src/SMAPI/Framework/ContentPack.cs +++ b/src/SMAPI/Framework/ContentPack.cs @@ -1,10 +1,7 @@ using System; using System.IO; -using Microsoft.Xna.Framework.Content; -using Microsoft.Xna.Framework.Graphics; using StardewModdingAPI.Toolkit.Serialization; using StardewModdingAPI.Toolkit.Utilities; -using xTile; namespace StardewModdingAPI.Framework { diff --git a/src/SMAPI/Framework/ModHelpers/ContentHelper.cs b/src/SMAPI/Framework/ModHelpers/ContentHelper.cs index 80f61c13..5fd8f5e9 100644 --- a/src/SMAPI/Framework/ModHelpers/ContentHelper.cs +++ b/src/SMAPI/Framework/ModHelpers/ContentHelper.cs @@ -5,13 +5,10 @@ using System.Diagnostics.CodeAnalysis; using System.Diagnostics.Contracts; using System.IO; using System.Linq; -using Microsoft.Xna.Framework.Content; -using Microsoft.Xna.Framework.Graphics; using StardewModdingAPI.Framework.Content; using StardewModdingAPI.Framework.ContentManagers; using StardewModdingAPI.Framework.Exceptions; using StardewValley; -using xTile; namespace StardewModdingAPI.Framework.ModHelpers { diff --git a/src/SMAPI/Framework/ModLoading/AssemblyLoader.cs b/src/SMAPI/Framework/ModLoading/AssemblyLoader.cs index cfe4c747..9fb5384e 100644 --- a/src/SMAPI/Framework/ModLoading/AssemblyLoader.cs +++ b/src/SMAPI/Framework/ModLoading/AssemblyLoader.cs @@ -409,10 +409,10 @@ namespace StardewModdingAPI.Framework.ModLoading if (handler.Phrases.Any()) { foreach (string message in handler.Phrases) - this.Monitor.LogOnce(template.Replace("$phrase", message)); + this.Monitor.LogOnce(loggedMessages, template.Replace("$phrase", message)); } else - this.Monitor.LogOnce(template.Replace("$phrase", handler.DefaultPhrase ?? handler.GetType().Name)); + this.Monitor.LogOnce(loggedMessages, template.Replace("$phrase", handler.DefaultPhrase ?? handler.GetType().Name)); } /// Get the correct reference to use for compatibility with the current platform. diff --git a/src/SMAPI/Framework/ModLoading/Finders/ReferenceToMissingMemberFinder.cs b/src/SMAPI/Framework/ModLoading/Finders/ReferenceToMissingMemberFinder.cs index 75575c97..b64a255e 100644 --- a/src/SMAPI/Framework/ModLoading/Finders/ReferenceToMissingMemberFinder.cs +++ b/src/SMAPI/Framework/ModLoading/Finders/ReferenceToMissingMemberFinder.cs @@ -49,7 +49,7 @@ namespace StardewModdingAPI.Framework.ModLoading.Finders MethodDefinition target = methodRef.Resolve(); if (target == null) { - string phrase = null; + string phrase; if (this.IsProperty(methodRef)) phrase = $"reference to {methodRef.DeclaringType.FullName}.{methodRef.Name.Substring(4)} (no such property)"; else if (methodRef.Name == ".ctor") diff --git a/src/SMAPI/Framework/Reflection/Reflector.cs b/src/SMAPI/Framework/Reflection/Reflector.cs index d4904878..889c7ed6 100644 --- a/src/SMAPI/Framework/Reflection/Reflector.cs +++ b/src/SMAPI/Framework/Reflection/Reflector.cs @@ -263,7 +263,7 @@ namespace StardewModdingAPI.Framework.Reflection CacheEntry entry = (CacheEntry)this.Cache[key]; return entry.IsValid ? (TMemberInfo)entry.MemberInfo - : default(TMemberInfo); + : default; } // fetch & cache new value diff --git a/src/SMAPI/Framework/Rendering/SXnaDisplayDevice.cs b/src/SMAPI/Framework/Rendering/SXnaDisplayDevice.cs index 121e53bc..cb499c6b 100644 --- a/src/SMAPI/Framework/Rendering/SXnaDisplayDevice.cs +++ b/src/SMAPI/Framework/Rendering/SXnaDisplayDevice.cs @@ -93,17 +93,17 @@ namespace StardewModdingAPI.Framework.Rendering { if (tile == null) return; - xTile.Dimensions.Rectangle tileImageBounds = tile.TileSheet.GetTileImageBounds(tile.TileIndex); + Rectangle tileImageBounds = tile.TileSheet.GetTileImageBounds(tile.TileIndex); Texture2D tileSheetTexture = this.m_tileSheetTextures[tile.TileSheet]; if (tileSheetTexture.IsDisposed) return; - this.m_tilePosition.X = (float)location.X; - this.m_tilePosition.Y = (float)location.Y; + this.m_tilePosition.X = location.X; + this.m_tilePosition.Y = location.Y; this.m_sourceRectangle.X = tileImageBounds.X; this.m_sourceRectangle.Y = tileImageBounds.Y; this.m_sourceRectangle.Width = tileImageBounds.Width; 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); } /// Finish drawing to the screen. diff --git a/src/SMAPI/Framework/SGame.cs b/src/SMAPI/Framework/SGame.cs index ae2c028d..6680a6c9 100644 --- a/src/SMAPI/Framework/SGame.cs +++ b/src/SMAPI/Framework/SGame.cs @@ -297,8 +297,6 @@ namespace StardewModdingAPI.Framework } if (Game1.currentMinigame != null) { - bool batchEnded = false; - if (events.Rendering.HasListeners()) { 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.Draw(target_screen, Vector2.Zero, target_screen.Bounds, Color.White, 0f, Vector2.Zero, Game1.options.zoomLevel, SpriteEffects.None, 1f); events.Rendered.RaiseEmpty(); - batchEnded = true; Game1.spriteBatch.End(); } else { - if (!batchEnded && events.Rendered.HasListeners()) + if (events.Rendered.HasListeners()) { Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, null, null); events.Rendered.RaiseEmpty(); diff --git a/src/SMAPI/Metadata/CoreAssetPropagator.cs b/src/SMAPI/Metadata/CoreAssetPropagator.cs index 5c77bf66..41d10cd4 100644 --- a/src/SMAPI/Metadata/CoreAssetPropagator.cs +++ b/src/SMAPI/Metadata/CoreAssetPropagator.cs @@ -34,9 +34,6 @@ namespace StardewModdingAPI.Metadata /// Simplifies access to private game code. private readonly Reflector Reflection; - /// Encapsulates monitoring and logging. - private readonly IMonitor Monitor; - /// Optimized bucket categories for batch reloading assets. private enum AssetBucket { @@ -57,12 +54,10 @@ namespace StardewModdingAPI.Metadata /// Initialize the core asset data. /// Normalizes an asset key to match the cache key and assert that it's valid. /// Simplifies access to private code. - /// Encapsulates monitoring and logging. - public CoreAssetPropagator(Func assertAndNormalizeAssetName, Reflector reflection, IMonitor monitor) + public CoreAssetPropagator(Func assertAndNormalizeAssetName, Reflector reflection) { this.AssertAndNormalizeAssetName = assertAndNormalizeAssetName; this.Reflection = reflection; - this.Monitor = monitor; } /// Reload one of the game's core assets (if applicable). diff --git a/src/SMAPI/SButton.cs b/src/SMAPI/SButton.cs index bc76c91d..cc412946 100644 --- a/src/SMAPI/SButton.cs +++ b/src/SMAPI/SButton.cs @@ -681,7 +681,7 @@ namespace StardewModdingAPI } // not valid - button = default(InputButton); + button = default; return false; } -- cgit