summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/SMAPI.Tests/Core/ModResolverTests.cs2
-rw-r--r--src/SMAPI/Constants.cs26
-rw-r--r--src/SMAPI/Framework/IModMetadata.cs2
-rw-r--r--src/SMAPI/Framework/ModLoading/ModMetadata.cs2
-rw-r--r--src/SMAPI/Framework/ModLoading/ModResolver.cs2
-rw-r--r--src/SMAPI/Program.cs9
-rw-r--r--src/SMAPI/StardewModdingAPI.csproj7
-rw-r--r--src/StardewModdingAPI.Toolkit/Framework/ModData/ModDataField.cs (renamed from src/SMAPI/Framework/ModData/ModDataField.cs)4
-rw-r--r--src/StardewModdingAPI.Toolkit/Framework/ModData/ModDataFieldKey.cs (renamed from src/SMAPI/Framework/ModData/ModDataFieldKey.cs)2
-rw-r--r--src/StardewModdingAPI.Toolkit/Framework/ModData/ModDataRecord.cs (renamed from src/SMAPI/Framework/ModData/ModDataRecord.cs)4
-rw-r--r--src/StardewModdingAPI.Toolkit/Framework/ModData/ModDatabase.cs (renamed from src/SMAPI/Framework/ModData/ModDatabase.cs)4
-rw-r--r--src/StardewModdingAPI.Toolkit/Framework/ModData/ModStatus.cs (renamed from src/SMAPI/Framework/ModData/ModStatus.cs)4
-rw-r--r--src/StardewModdingAPI.Toolkit/Framework/ModData/ParsedModDataRecord.cs (renamed from src/SMAPI/Framework/ModData/ParsedModDataRecord.cs)4
-rw-r--r--src/StardewModdingAPI.Toolkit/Framework/ModData/SMetadata.cs (renamed from src/SMAPI/Framework/Models/SMetadata.cs)3
-rw-r--r--src/StardewModdingAPI.Toolkit/ModToolkit.cs39
15 files changed, 60 insertions, 54 deletions
diff --git a/src/SMAPI.Tests/Core/ModResolverTests.cs b/src/SMAPI.Tests/Core/ModResolverTests.cs
index a0fe2023..e63057b3 100644
--- a/src/SMAPI.Tests/Core/ModResolverTests.cs
+++ b/src/SMAPI.Tests/Core/ModResolverTests.cs
@@ -6,8 +6,8 @@ using Moq;
using Newtonsoft.Json;
using NUnit.Framework;
using StardewModdingAPI.Framework;
-using StardewModdingAPI.Framework.ModData;
using StardewModdingAPI.Framework.ModLoading;
+using StardewModdingAPI.Toolkit.Framework.ModData;
using StardewModdingAPI.Toolkit.Serialisation;
using StardewModdingAPI.Toolkit.Serialisation.Models;
diff --git a/src/SMAPI/Constants.cs b/src/SMAPI/Constants.cs
index 01b99d62..c4a3813e 100644
--- a/src/SMAPI/Constants.cs
+++ b/src/SMAPI/Constants.cs
@@ -1,5 +1,4 @@
using System;
-using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
@@ -22,14 +21,6 @@ namespace StardewModdingAPI
/// <summary>Whether the directory containing the current save's data exists on disk.</summary>
private static bool SavePathReady => Context.IsSaveLoaded && Directory.Exists(Constants.RawSavePath);
- /// <summary>Maps vendor keys (like <c>Nexus</c>) to their mod URL template (where <c>{0}</c> is the mod ID). This doesn't affect update checks, which defer to the remote web API.</summary>
- private static readonly IDictionary<string, string> VendorModUrls = new Dictionary<string, string>(StringComparer.InvariantCultureIgnoreCase)
- {
- ["Chucklefish"] = "https://community.playstarbound.com/resources/{0}",
- ["GitHub"] = "https://github.com/{0}/releases",
- ["Nexus"] = "https://www.nexusmods.com/stardewvalley/mods/{0}"
- };
-
/*********
** Accessors
@@ -159,23 +150,6 @@ namespace StardewModdingAPI
return new PlatformAssemblyMap(targetPlatform, removeAssemblyReferences, targetAssemblies);
}
- /// <summary>Get an update URL for an update key (if valid).</summary>
- /// <param name="updateKey">The update key.</param>
- internal static string GetUpdateUrl(string updateKey)
- {
- string[] parts = updateKey.Split(new[] { ':' }, 2);
- if (parts.Length != 2)
- return null;
-
- string vendorKey = parts[0].Trim();
- string modID = parts[1].Trim();
-
- if (Constants.VendorModUrls.TryGetValue(vendorKey, out string urlTemplate))
- return string.Format(urlTemplate, modID);
-
- return null;
- }
-
/*********
** Private methods
diff --git a/src/SMAPI/Framework/IModMetadata.cs b/src/SMAPI/Framework/IModMetadata.cs
index 6281c052..5a8689de 100644
--- a/src/SMAPI/Framework/IModMetadata.cs
+++ b/src/SMAPI/Framework/IModMetadata.cs
@@ -1,6 +1,6 @@
-using StardewModdingAPI.Framework.ModData;
using StardewModdingAPI.Framework.ModLoading;
using StardewModdingAPI.Toolkit.Framework.Clients.WebApi;
+using StardewModdingAPI.Toolkit.Framework.ModData;
namespace StardewModdingAPI.Framework
{
diff --git a/src/SMAPI/Framework/ModLoading/ModMetadata.cs b/src/SMAPI/Framework/ModLoading/ModMetadata.cs
index 3a412009..4db25932 100644
--- a/src/SMAPI/Framework/ModLoading/ModMetadata.cs
+++ b/src/SMAPI/Framework/ModLoading/ModMetadata.cs
@@ -1,7 +1,7 @@
using System;
using System.Linq;
-using StardewModdingAPI.Framework.ModData;
using StardewModdingAPI.Toolkit.Framework.Clients.WebApi;
+using StardewModdingAPI.Toolkit.Framework.ModData;
namespace StardewModdingAPI.Framework.ModLoading
{
diff --git a/src/SMAPI/Framework/ModLoading/ModResolver.cs b/src/SMAPI/Framework/ModLoading/ModResolver.cs
index fde921e6..c1bc51ec 100644
--- a/src/SMAPI/Framework/ModLoading/ModResolver.cs
+++ b/src/SMAPI/Framework/ModLoading/ModResolver.cs
@@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
-using StardewModdingAPI.Framework.ModData;
+using StardewModdingAPI.Toolkit.Framework.ModData;
using StardewModdingAPI.Toolkit.Serialisation;
using StardewModdingAPI.Toolkit.Serialisation.Models;
using StardewModdingAPI.Toolkit.Utilities;
diff --git a/src/SMAPI/Program.cs b/src/SMAPI/Program.cs
index 09d9969c..6f1fe761 100644
--- a/src/SMAPI/Program.cs
+++ b/src/SMAPI/Program.cs
@@ -21,7 +21,6 @@ using StardewModdingAPI.Framework;
using StardewModdingAPI.Framework.Events;
using StardewModdingAPI.Framework.Exceptions;
using StardewModdingAPI.Framework.Logging;
-using StardewModdingAPI.Framework.ModData;
using StardewModdingAPI.Framework.Models;
using StardewModdingAPI.Framework.ModHelpers;
using StardewModdingAPI.Framework.ModLoading;
@@ -29,7 +28,9 @@ using StardewModdingAPI.Framework.Patching;
using StardewModdingAPI.Framework.Reflection;
using StardewModdingAPI.Framework.Serialisation;
using StardewModdingAPI.Internal;
+using StardewModdingAPI.Toolkit;
using StardewModdingAPI.Toolkit.Framework.Clients.WebApi;
+using StardewModdingAPI.Toolkit.Framework.ModData;
using StardewModdingAPI.Toolkit.Serialisation;
using StardewModdingAPI.Toolkit.Serialisation.Converters;
using StardewModdingAPI.Toolkit.Utilities;
@@ -413,8 +414,8 @@ namespace StardewModdingAPI
this.Monitor.Log("SMAPI found problems in your game's content files which are likely to cause errors or crashes. Consider uninstalling XNB mods or reinstalling the game.", LogLevel.Error);
// load mod data
- SMetadata metadata = JsonConvert.DeserializeObject<SMetadata>(File.ReadAllText(Constants.ApiMetadataPath));
- ModDatabase modDatabase = new ModDatabase(metadata.ModData, Constants.GetUpdateUrl);
+ ModToolkit toolkit = new ModToolkit();
+ ModDatabase modDatabase = toolkit.GetModDatabase(Constants.ApiMetadataPath, toolkit.GetUpdateUrl);
// load mods
{
@@ -423,7 +424,7 @@ namespace StardewModdingAPI
// load manifests
IModMetadata[] mods = resolver.ReadManifests(Constants.ModPath, this.JsonHelper, modDatabase).ToArray();
- resolver.ValidateManifests(mods, Constants.ApiVersion, Constants.GetUpdateUrl);
+ resolver.ValidateManifests(mods, Constants.ApiVersion, toolkit.GetUpdateUrl);
// process dependencies
mods = resolver.ProcessDependencies(mods, modDatabase).ToArray();
diff --git a/src/SMAPI/StardewModdingAPI.csproj b/src/SMAPI/StardewModdingAPI.csproj
index 4852f70c..f849ee53 100644
--- a/src/SMAPI/StardewModdingAPI.csproj
+++ b/src/SMAPI/StardewModdingAPI.csproj
@@ -132,11 +132,6 @@
<Compile Include="IInputHelper.cs" />
<Compile Include="Framework\Input\SInputState.cs" />
<Compile Include="Framework\Input\InputStatus.cs" />
- <Compile Include="Framework\ModData\ModDatabase.cs" />
- <Compile Include="Framework\ModData\ModDataField.cs" />
- <Compile Include="Framework\ModData\ModDataFieldKey.cs" />
- <Compile Include="Framework\ModData\ParsedModDataRecord.cs" />
- <Compile Include="Framework\Models\SMetadata.cs" />
<Compile Include="Framework\ModHelpers\MultiplayerHelper.cs" />
<Compile Include="Framework\ModLoading\Finders\EventFinder.cs" />
<Compile Include="Framework\ModLoading\Finders\FieldFinder.cs" />
@@ -239,7 +234,6 @@
<Compile Include="Context.cs" />
<Compile Include="Framework\Logging\ConsoleInterceptionManager.cs" />
<Compile Include="Framework\Logging\InterceptingTextWriter.cs" />
- <Compile Include="Framework\ModData\ModStatus.cs" />
<Compile Include="Framework\Models\SConfig.cs" />
<Compile Include="Framework\ModLoading\ModMetadata.cs" />
<Compile Include="Framework\Reflection\ReflectedProperty.cs" />
@@ -263,7 +257,6 @@
<Compile Include="Framework\DeprecationLevel.cs" />
<Compile Include="Framework\DeprecationManager.cs" />
<Compile Include="Framework\InternalExtensions.cs" />
- <Compile Include="Framework\ModData\ModDataRecord.cs" />
<Compile Include="Framework\ModLoading\AssemblyLoader.cs" />
<Compile Include="Framework\Reflection\CacheEntry.cs" />
<Compile Include="Framework\Reflection\ReflectedField.cs" />
diff --git a/src/SMAPI/Framework/ModData/ModDataField.cs b/src/StardewModdingAPI.Toolkit/Framework/ModData/ModDataField.cs
index df906103..b3954693 100644
--- a/src/SMAPI/Framework/ModData/ModDataField.cs
+++ b/src/StardewModdingAPI.Toolkit/Framework/ModData/ModDataField.cs
@@ -1,9 +1,9 @@
using System.Linq;
-namespace StardewModdingAPI.Framework.ModData
+namespace StardewModdingAPI.Toolkit.Framework.ModData
{
/// <summary>A versioned mod metadata field.</summary>
- internal class ModDataField
+ public class ModDataField
{
/*********
** Accessors
diff --git a/src/SMAPI/Framework/ModData/ModDataFieldKey.cs b/src/StardewModdingAPI.Toolkit/Framework/ModData/ModDataFieldKey.cs
index f68f575c..09dd0cc5 100644
--- a/src/SMAPI/Framework/ModData/ModDataFieldKey.cs
+++ b/src/StardewModdingAPI.Toolkit/Framework/ModData/ModDataFieldKey.cs
@@ -1,4 +1,4 @@
-namespace StardewModdingAPI.Framework.ModData
+namespace StardewModdingAPI.Toolkit.Framework.ModData
{
/// <summary>The valid field keys.</summary>
public enum ModDataFieldKey
diff --git a/src/SMAPI/Framework/ModData/ModDataRecord.cs b/src/StardewModdingAPI.Toolkit/Framework/ModData/ModDataRecord.cs
index 56275f53..97ad0ca4 100644
--- a/src/SMAPI/Framework/ModData/ModDataRecord.cs
+++ b/src/StardewModdingAPI.Toolkit/Framework/ModData/ModDataRecord.cs
@@ -5,10 +5,10 @@ using System.Runtime.Serialization;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
-namespace StardewModdingAPI.Framework.ModData
+namespace StardewModdingAPI.Toolkit.Framework.ModData
{
/// <summary>Raw mod metadata from SMAPI's internal mod list.</summary>
- internal class ModDataRecord
+ public class ModDataRecord
{
/*********
** Properties
diff --git a/src/SMAPI/Framework/ModData/ModDatabase.cs b/src/StardewModdingAPI.Toolkit/Framework/ModData/ModDatabase.cs
index 62f37d9b..c60d2bcb 100644
--- a/src/SMAPI/Framework/ModData/ModDatabase.cs
+++ b/src/StardewModdingAPI.Toolkit/Framework/ModData/ModDatabase.cs
@@ -2,10 +2,10 @@ using System;
using System.Collections.Generic;
using System.Linq;
-namespace StardewModdingAPI.Framework.ModData
+namespace StardewModdingAPI.Toolkit.Framework.ModData
{
/// <summary>Handles access to SMAPI's internal mod metadata list.</summary>
- internal class ModDatabase
+ public class ModDatabase
{
/*********
** Properties
diff --git a/src/SMAPI/Framework/ModData/ModStatus.cs b/src/StardewModdingAPI.Toolkit/Framework/ModData/ModStatus.cs
index 0e1d94d4..09da74bf 100644
--- a/src/SMAPI/Framework/ModData/ModStatus.cs
+++ b/src/StardewModdingAPI.Toolkit/Framework/ModData/ModStatus.cs
@@ -1,7 +1,7 @@
-namespace StardewModdingAPI.Framework.ModData
+namespace StardewModdingAPI.Toolkit.Framework.ModData
{
/// <summary>Indicates how SMAPI should treat a mod.</summary>
- internal enum ModStatus
+ public enum ModStatus
{
/// <summary>Don't override the status.</summary>
None,
diff --git a/src/SMAPI/Framework/ModData/ParsedModDataRecord.cs b/src/StardewModdingAPI.Toolkit/Framework/ModData/ParsedModDataRecord.cs
index 3801fac3..74f11ea5 100644
--- a/src/SMAPI/Framework/ModData/ParsedModDataRecord.cs
+++ b/src/StardewModdingAPI.Toolkit/Framework/ModData/ParsedModDataRecord.cs
@@ -1,7 +1,7 @@
-namespace StardewModdingAPI.Framework.ModData
+namespace StardewModdingAPI.Toolkit.Framework.ModData
{
/// <summary>A parsed representation of the fields from a <see cref="ModDataRecord"/> for a specific manifest.</summary>
- internal class ParsedModDataRecord
+ public class ParsedModDataRecord
{
/*********
** Accessors
diff --git a/src/SMAPI/Framework/Models/SMetadata.cs b/src/StardewModdingAPI.Toolkit/Framework/ModData/SMetadata.cs
index 9ff495e9..9553cca9 100644
--- a/src/SMAPI/Framework/Models/SMetadata.cs
+++ b/src/StardewModdingAPI.Toolkit/Framework/ModData/SMetadata.cs
@@ -1,7 +1,6 @@
using System.Collections.Generic;
-using StardewModdingAPI.Framework.ModData;
-namespace StardewModdingAPI.Framework.Models
+namespace StardewModdingAPI.Toolkit.Framework.ModData
{
/// <summary>The SMAPI predefined metadata.</summary>
internal class SMetadata
diff --git a/src/StardewModdingAPI.Toolkit/ModToolkit.cs b/src/StardewModdingAPI.Toolkit/ModToolkit.cs
index 6136186e..1723991e 100644
--- a/src/StardewModdingAPI.Toolkit/ModToolkit.cs
+++ b/src/StardewModdingAPI.Toolkit/ModToolkit.cs
@@ -1,5 +1,10 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
using System.Threading.Tasks;
+using Newtonsoft.Json;
using StardewModdingAPI.Toolkit.Framework.Clients.Wiki;
+using StardewModdingAPI.Toolkit.Framework.ModData;
namespace StardewModdingAPI.Toolkit
{
@@ -12,6 +17,14 @@ namespace StardewModdingAPI.Toolkit
/// <summary>The default HTTP user agent for the toolkit.</summary>
private readonly string UserAgent;
+ /// <summary>Maps vendor keys (like <c>Nexus</c>) to their mod URL template (where <c>{0}</c> is the mod ID). This doesn't affect update checks, which defer to the remote web API.</summary>
+ private readonly IDictionary<string, string> VendorModUrls = new Dictionary<string, string>(StringComparer.InvariantCultureIgnoreCase)
+ {
+ ["Chucklefish"] = "https://community.playstarbound.com/resources/{0}",
+ ["GitHub"] = "https://github.com/{0}/releases",
+ ["Nexus"] = "https://www.nexusmods.com/stardewvalley/mods/{0}"
+ };
+
/*********
** Public methods
@@ -29,5 +42,31 @@ namespace StardewModdingAPI.Toolkit
var client = new WikiCompatibilityClient(this.UserAgent);
return await client.FetchAsync();
}
+
+ /// <summary>Get SMAPI's internal mod database.</summary>
+ /// <param name="metadataPath">The file path for the SMAPI metadata file.</param>
+ /// <param name="getUpdateUrl">Get an update URL for an update key (if valid).</param>
+ public ModDatabase GetModDatabase(string metadataPath, Func<string, string> getUpdateUrl)
+ {
+ SMetadata metadata = JsonConvert.DeserializeObject<SMetadata>(File.ReadAllText(metadataPath));
+ return new ModDatabase(metadata.ModData, getUpdateUrl);
+ }
+
+ /// <summary>Get an update URL for an update key (if valid).</summary>
+ /// <param name="updateKey">The update key.</param>
+ internal string GetUpdateUrl(string updateKey)
+ {
+ string[] parts = updateKey.Split(new[] { ':' }, 2);
+ if (parts.Length != 2)
+ return null;
+
+ string vendorKey = parts[0].Trim();
+ string modID = parts[1].Trim();
+
+ if (this.VendorModUrls.TryGetValue(vendorKey, out string urlTemplate))
+ return string.Format(urlTemplate, modID);
+
+ return null;
+ }
}
}