diff options
| author | Jesse Plamondon-Willard <github@jplamondonw.com> | 2018-08-01 11:07:29 -0400 |
|---|---|---|
| committer | Jesse Plamondon-Willard <github@jplamondonw.com> | 2018-08-01 11:07:29 -0400 |
| commit | 60b41195778af33fd609eab66d9ae3f1d1165e8f (patch) | |
| tree | 7128b906d40e94c56c34ed6058f27bc31c31a08b /src/SMAPI/Framework | |
| parent | b9bc1a6d17cafa0a97b46ffecda432cfc2f23b51 (diff) | |
| parent | 52cf953f685c65b2b6814e375ec9a5ffa03c440a (diff) | |
| download | SMAPI-60b41195778af33fd609eab66d9ae3f1d1165e8f.tar.gz SMAPI-60b41195778af33fd609eab66d9ae3f1d1165e8f.tar.bz2 SMAPI-60b41195778af33fd609eab66d9ae3f1d1165e8f.zip | |
Merge branch 'develop' into stable
Diffstat (limited to 'src/SMAPI/Framework')
100 files changed, 4921 insertions, 4099 deletions
diff --git a/src/SMAPI/Framework/CommandManager.cs b/src/SMAPI/Framework/CommandManager.cs index 79a23d03..f9651ed9 100644 --- a/src/SMAPI/Framework/CommandManager.cs +++ b/src/SMAPI/Framework/CommandManager.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Text; namespace StardewModdingAPI.Framework { @@ -72,7 +73,7 @@ namespace StardewModdingAPI.Framework if (string.IsNullOrWhiteSpace(input)) return false; - string[] args = input.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); + string[] args = this.ParseArgs(input); string name = args[0]; args = args.Skip(1).ToArray(); @@ -103,6 +104,31 @@ namespace StardewModdingAPI.Framework /********* ** Private methods *********/ + /// <summary>Parse a string into command arguments.</summary> + /// <param name="input">The string to parse.</param> + private string[] ParseArgs(string input) + { + bool inQuotes = false; + IList<string> args = new List<string>(); + StringBuilder currentArg = new StringBuilder(); + foreach (char ch in input) + { + if (ch == '"') + inQuotes = !inQuotes; + else if (!inQuotes && char.IsWhiteSpace(ch)) + { + args.Add(currentArg.ToString()); + currentArg.Clear(); + } + else + currentArg.Append(ch); + } + + args.Add(currentArg.ToString()); + + return args.Where(item => !string.IsNullOrWhiteSpace(item)).ToArray(); + } + /// <summary>Get a normalised command name.</summary> /// <param name="name">The command name.</param> private string GetNormalisedName(string name) diff --git a/src/SMAPI/Framework/Content/AssetDataForImage.cs b/src/SMAPI/Framework/Content/AssetDataForImage.cs index 1eef2afb..5c7b87de 100644 --- a/src/SMAPI/Framework/Content/AssetDataForImage.cs +++ b/src/SMAPI/Framework/Content/AssetDataForImage.cs @@ -4,7 +4,7 @@ using Microsoft.Xna.Framework.Graphics; namespace StardewModdingAPI.Framework.Content { - /// <summary>Encapsulates access and changes to dictionary content being read from a data file.</summary> + /// <summary>Encapsulates access and changes to image content being read from a data file.</summary> internal class AssetDataForImage : AssetData<Texture2D>, IAssetDataForImage { /********* @@ -29,6 +29,8 @@ namespace StardewModdingAPI.Framework.Content public void PatchImage(Texture2D source, Rectangle? sourceArea = null, Rectangle? targetArea = null, PatchMode patchMode = PatchMode.Replace) { // get texture + if (source == null) + throw new ArgumentNullException(nameof(source), "Can't patch from a null source texture."); Texture2D target = this.Data; // get areas @@ -36,8 +38,6 @@ namespace StardewModdingAPI.Framework.Content targetArea = targetArea ?? new Rectangle(0, 0, Math.Min(sourceArea.Value.Width, target.Width), Math.Min(sourceArea.Value.Height, target.Height)); // validate - if (source == null) - throw new ArgumentNullException(nameof(source), "Can't patch from a null source texture."); if (sourceArea.Value.X < 0 || sourceArea.Value.Y < 0 || sourceArea.Value.Right > source.Width || sourceArea.Value.Bottom > source.Height) throw new ArgumentOutOfRangeException(nameof(sourceArea), "The source area is outside the bounds of the source texture."); if (targetArea.Value.X < 0 || targetArea.Value.Y < 0 || targetArea.Value.Right > target.Width || targetArea.Value.Bottom > target.Height) diff --git a/src/SMAPI/Framework/Content/ContentCache.cs b/src/SMAPI/Framework/Content/ContentCache.cs index 533da398..a5dfac9d 100644 --- a/src/SMAPI/Framework/Content/ContentCache.cs +++ b/src/SMAPI/Framework/Content/ContentCache.cs @@ -3,9 +3,9 @@ using System.Collections.Generic; using System.Diagnostics.Contracts; using System.Linq; using Microsoft.Xna.Framework; -using StardewModdingAPI.Framework.ModLoading; using StardewModdingAPI.Framework.Reflection; -using StardewModdingAPI.Framework.Utilities; +using StardewModdingAPI.Internal; +using StardewModdingAPI.Toolkit.Utilities; using StardewValley; namespace StardewModdingAPI.Framework.Content @@ -53,7 +53,7 @@ namespace StardewModdingAPI.Framework.Content this.Cache = reflection.GetField<Dictionary<string, object>>(contentManager, "loadedAssets").GetValue(); // get key normalisation logic - if (Constants.TargetPlatform == Platform.Windows) + if (Constants.Platform == Platform.Windows) { IReflectedMethod method = reflection.GetMethod(typeof(TitleContainer), "GetCleanPath"); this.NormaliseAssetNameForPlatform = path => method.Invoke<string>(path); diff --git a/src/SMAPI/Framework/ContentCoordinator.cs b/src/SMAPI/Framework/ContentCoordinator.cs new file mode 100644 index 00000000..d9b2109a --- /dev/null +++ b/src/SMAPI/Framework/ContentCoordinator.cs @@ -0,0 +1,315 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.IO; +using System.Linq; +using System.Reflection; +using Microsoft.Xna.Framework.Content; +using StardewModdingAPI.Framework.Content; +using StardewModdingAPI.Framework.ContentManagers; +using StardewModdingAPI.Framework.Reflection; +using StardewModdingAPI.Metadata; +using StardewModdingAPI.Toolkit.Utilities; +using StardewValley; + +namespace StardewModdingAPI.Framework +{ + /// <summary>The central logic for creating content managers, invalidating caches, and propagating asset changes.</summary> + internal class ContentCoordinator : IDisposable + { + /********* + ** Properties + *********/ + /// <summary>An asset key prefix for assets from SMAPI mod folders.</summary> + private readonly string ManagedPrefix = "SMAPI"; + + /// <summary>Encapsulates monitoring and logging.</summary> + private readonly IMonitor Monitor; + + /// <summary>Provides metadata for core game assets.</summary> + private readonly CoreAssetPropagator CoreAssets; + + /// <summary>Simplifies access to private code.</summary> + private readonly Reflector Reflection; + + /// <summary>The loaded content managers (including the <see cref="MainContentManager"/>).</summary> + private readonly IList<IContentManager> ContentManagers = new List<IContentManager>(); + + /// <summary>Whether the content coordinator has been disposed.</summary> + |
