summaryrefslogtreecommitdiff
path: root/src/SMAPI/Framework/Models
diff options
context:
space:
mode:
Diffstat (limited to 'src/SMAPI/Framework/Models')
-rw-r--r--src/SMAPI/Framework/Models/Manifest.cs8
-rw-r--r--src/SMAPI/Framework/Models/ManifestContentPackFor.cs15
-rw-r--r--src/SMAPI/Framework/Models/ModCompatibility.cs55
-rw-r--r--src/SMAPI/Framework/Models/ModDataID.cs85
-rw-r--r--src/SMAPI/Framework/Models/ModDataRecord.cs63
-rw-r--r--src/SMAPI/Framework/Models/ModStatus.cs18
-rw-r--r--src/SMAPI/Framework/Models/SConfig.cs5
7 files changed, 24 insertions, 225 deletions
diff --git a/src/SMAPI/Framework/Models/Manifest.cs b/src/SMAPI/Framework/Models/Manifest.cs
index f9762406..f5867cf3 100644
--- a/src/SMAPI/Framework/Models/Manifest.cs
+++ b/src/SMAPI/Framework/Models/Manifest.cs
@@ -20,16 +20,18 @@ namespace StardewModdingAPI.Framework.Models
public string Author { get; set; }
/// <summary>The mod version.</summary>
- [JsonConverter(typeof(SemanticVersionConverter))]
public ISemanticVersion Version { get; set; }
/// <summary>The minimum SMAPI version required by this mod, if any.</summary>
- [JsonConverter(typeof(SemanticVersionConverter))]
public ISemanticVersion MinimumApiVersion { get; set; }
- /// <summary>The name of the DLL in the directory that has the <see cref="IMod.Entry"/> method.</summary>
+ /// <summary>The name of the DLL in the directory that has the <see cref="IMod.Entry"/> method. Mutually exclusive with <see cref="ContentPackFor"/>.</summary>
public string EntryDll { get; set; }
+ /// <summary>The mod which will read this as a content pack. Mutually exclusive with <see cref="IManifest.EntryDll"/>.</summary>
+ [JsonConverter(typeof(ManifestContentPackForConverter))]
+ public IManifestContentPackFor ContentPackFor { get; set; }
+
/// <summary>The other mods that must be loaded before this mod.</summary>
[JsonConverter(typeof(ManifestDependencyArrayConverter))]
public IManifestDependency[] Dependencies { get; set; }
diff --git a/src/SMAPI/Framework/Models/ManifestContentPackFor.cs b/src/SMAPI/Framework/Models/ManifestContentPackFor.cs
new file mode 100644
index 00000000..7836bbcc
--- /dev/null
+++ b/src/SMAPI/Framework/Models/ManifestContentPackFor.cs
@@ -0,0 +1,15 @@
+namespace StardewModdingAPI.Framework.Models
+{
+ /// <summary>Indicates which mod can read the content pack represented by the containing manifest.</summary>
+ internal class ManifestContentPackFor : IManifestContentPackFor
+ {
+ /*********
+ ** Accessors
+ *********/
+ /// <summary>The unique ID of the mod which can read this content pack.</summary>
+ public string UniqueID { get; set; }
+
+ /// <summary>The minimum required version (if any).</summary>
+ public ISemanticVersion MinimumVersion { get; set; }
+ }
+}
diff --git a/src/SMAPI/Framework/Models/ModCompatibility.cs b/src/SMAPI/Framework/Models/ModCompatibility.cs
deleted file mode 100644
index 54737e6c..00000000
--- a/src/SMAPI/Framework/Models/ModCompatibility.cs
+++ /dev/null
@@ -1,55 +0,0 @@
-using System;
-
-namespace StardewModdingAPI.Framework.Models
-{
- /// <summary>Specifies the compatibility of a given mod version range.</summary>
- internal class ModCompatibility
- {
- /*********
- ** Accessors
- *********/
- /// <summary>The lowest version in the range, or <c>null</c> for all past versions.</summary>
- public ISemanticVersion LowerVersion { get; }
-
- /// <summary>The highest version in the range, or <c>null</c> for all future versions.</summary>
- public ISemanticVersion UpperVersion { get; }
-
- /// <summary>The mod compatibility.</summary>
- public ModStatus Status { get; }
-
- /// <summary>The reason phrase to show in log output, or <c>null</c> to use the default value.</summary>
- /// <example>For example, "this version is incompatible with the latest version of the game".</example>
- public string ReasonPhrase { get; }
-
-
- /*********
- ** Public methods
- *********/
- /// <summary>Construct an instance.</summary>
- /// <param name="versionRange">A version range, which consists of two version strings separated by a '~' character. Either side can be left blank for an unbounded range.</param>
- /// <param name="status">The mod compatibility.</param>
- /// <param name="reasonPhrase">The reason phrase to show in log output, or <c>null</c> to use the default value.</param>
- public ModCompatibility(string versionRange, ModStatus status, string reasonPhrase)
- {
- // extract version strings
- string[] versions = versionRange.Split('~');
- if (versions.Length != 2)
- throw new FormatException($"Could not parse '{versionRange}' as a version range. It must have two version strings separated by a '~' character (either side can be left blank for an unbounded range).");
-
- // initialise
- this.LowerVersion = !string.IsNullOrWhiteSpace(versions[0]) ? new SemanticVersion(versions[0]) : null;
- this.UpperVersion = !string.IsNullOrWhiteSpace(versions[1]) ? new SemanticVersion(versions[1]) : null;
- this.Status = status;
- this.ReasonPhrase = reasonPhrase;
- }
-
- /// <summary>Get whether a given version is contained within this compatibility range.</summary>
- /// <param name="version">The version to check.</param>
- public bool MatchesVersion(ISemanticVersion version)
- {
- return
- (this.LowerVersion == null || !version.IsOlderThan(this.LowerVersion))
- && (this.UpperVersion == null || !version.IsNewerThan(this.UpperVersion));
- }
- }
-}
diff --git a/src/SMAPI/Framework/Models/ModDataID.cs b/src/SMAPI/Framework/Models/ModDataID.cs
deleted file mode 100644
index d19434fa..00000000
--- a/src/SMAPI/Framework/Models/ModDataID.cs
+++ /dev/null
@@ -1,85 +0,0 @@
-using System;
-using System.Linq;
-using Newtonsoft.Json;
-
-namespace StardewModdingAPI.Framework.Models
-{
- /// <summary>Uniquely identifies a mod in SMAPI's internal data.</summary>
- /// <remarks>
- /// This represents a custom format which uniquely identifies a mod across all versions, even
- /// if its field values change or it doesn't specify a unique ID. This is mapped to a string
- /// with the following format:
- ///
- /// 1. If the mod's identifier changed over time, multiple variants can be separated by the <c>|</c>
- /// character.
- /// 2. Each variant can take one of two forms:
- /// - A simple string matching the mod's UniqueID value.
- /// - A JSON structure containing any of three manifest fields (ID, Name, and Author) to match.
- /// </remarks>
- internal class ModDataID
- {
- /*********
- ** Properties
- *********/
- /// <summary>The unique sets of field values which identify this mod.</summary>
- private readonly FieldSnapshot[] Snapshots;
-
-
- /*********
- ** Public methods
- *********/
- /// <summary>Construct an instance.</summary>
- public ModDataID() { }
-
- /// <summary>Construct an instance.</summary>
- /// <param name="data">The mod identifier string (see remarks on <see cref="ModDataID"/>).</param>
- public ModDataID(string data)
- {
- this.Snapshots =
- (
- from string part in data.Split('|')
- let str = part.Trim()
- select str.StartsWith("{")
- ? JsonConvert.DeserializeObject<FieldSnapshot>(str)
- : new FieldSnapshot { ID = str }
- )
- .ToArray();
- }
-
- /// <summary>Get whether this ID matches a given mod manifest.</summary>
- /// <param name="id">The mod's unique ID, or a substitute ID if it isn't set in the manifest.</param>
- /// <param name="manifest">The manifest to check.</param>
- public bool Matches(string id, IManifest manifest)
- {
- return this.Snapshots.Any(snapshot =>
- snapshot.ID.Equals(id, StringComparison.InvariantCultureIgnoreCase)
- && (
- snapshot.Author == null
- || snapshot.Author.Equals(manifest.Author, StringComparison.InvariantCultureIgnoreCase)
- || (manifest.ExtraFields.ContainsKey("Authour") && snapshot.Author.Equals(manifest.ExtraFields["Authour"].ToString(), StringComparison.InvariantCultureIgnoreCase))
- )
- && (snapshot.Name == null || snapshot.Name.Equals(manifest.Name, StringComparison.InvariantCultureIgnoreCase))
- );
- }
-
-
- /*********
- ** Private models
- *********/
- /// <summary>A unique set of fields which identifies the mod.</summary>
- private class FieldSnapshot
- {
- /*********
- ** Accessors
- *********/
- /// <summary>The unique mod ID.</summary>
- public string ID { get; set; }
-
- /// <summary>The mod name, or <c>null</c> to ignore the mod name.</summary>
- public string Name { get; set; }
-
- /// <summary>The author name, or <c>null</c> to ignore the author.</summary>
- public string Author { get; set; }
- }
- }
-}
diff --git a/src/SMAPI/Framework/Models/ModDataRecord.cs b/src/SMAPI/Framework/Models/ModDataRecord.cs
deleted file mode 100644
index 580acb70..00000000
--- a/src/SMAPI/Framework/Models/ModDataRecord.cs
+++ /dev/null
@@ -1,63 +0,0 @@
-using System.Collections.Generic;
-using System.Linq;
-using Newtonsoft.Json;
-using StardewModdingAPI.Framework.Serialisation.SmapiConverters;
-
-namespace StardewModdingAPI.Framework.Models
-{
- /// <summary>Metadata about a mod from SMAPI's internal data.</summary>
- internal class ModDataRecord
- {
- /*********
- ** Accessors
- *********/
- /// <summary>The unique mod identifier.</summary>
- [JsonConverter(typeof(ModDataIdConverter))]
- public ModDataID ID { get; set; }
-
- /// <summary>A value to inject into <see cref="IManifest.UpdateKeys"/> field if it's not already set.</summary>
- public string[] UpdateKeys { get; set; }
-
- /// <summary>The URL where the player can get an unofficial or alternative version of the mod if the official version isn't compatible.</summary>
- public string AlternativeUrl { get; set; }
-
- /// <summary>The compatibility of given mod versions (if any).</summary>
- [JsonConverter(typeof(ModCompatibilityArrayConverter))]
- public ModCompatibility[] Compatibility { get; set; } = new ModCompatibility[0];
-
- /// <summary>Map local versions to a semantic version for update checks.</summary>
- public IDictionary<string, string> MapLocalVersions { get; set; } = new Dictionary<string, string>();
-
- /// <summary>Map remote versions to a semantic version for update checks.</summary>
- public IDictionary<string, string> MapRemoteVersions { get; set; } = new Dictionary<string, string>();
-
-
- /*********
- ** Public methods
- *********/
- /// <summary>Get the compatibility record for a given version, if any.</summary>
- /// <param name="version">The mod version to check.</param>
- public ModCompatibility GetCompatibility(ISemanticVersion version)
- {
- return this.Compatibility.FirstOrDefault(p => p.MatchesVersion(version));
- }
-
- /// <summary>Get a semantic local version for update checks.</summary>
- /// <param name="version">The local version to normalise.</param>
- public string GetLocalVersionForUpdateChecks(string version)
- {
- return this.MapLocalVersions != null && this.MapLocalVersions.TryGetValue(version, out string newVersion)
- ? newVersion
- : version;
- }
-
- /// <summary>Get a semantic remote version for update checks.</summary>
- /// <param name="version">The remote version to normalise.</param>
- public string GetRemoteVersionForUpdateChecks(string version)
- {
- return this.MapRemoteVersions != null && this.MapRemoteVersions.TryGetValue(version, out string newVersion)
- ? newVersion
- : version;
- }
- }
-}
diff --git a/src/SMAPI/Framework/Models/ModStatus.cs b/src/SMAPI/Framework/Models/ModStatus.cs
deleted file mode 100644
index 343ccb7e..00000000
--- a/src/SMAPI/Framework/Models/ModStatus.cs
+++ /dev/null
@@ -1,18 +0,0 @@
-namespace StardewModdingAPI.Framework.Models
-{
- /// <summary>Indicates how SMAPI should treat a mod.</summary>
- internal enum ModStatus
- {
- /// <summary>Don't override the status.</summary>
- None,
-
- /// <summary>The mod is obsolete and shouldn't be used, regardless of version.</summary>
- Obsolete,
-
- /// <summary>Assume the mod is not compatible, even if SMAPI doesn't detect any incompatible code.</summary>
- AssumeBroken,
-
- /// <summary>Assume the mod is compatible, even if SMAPI detects incompatible code.</summary>
- AssumeCompatible
- }
-}
diff --git a/src/SMAPI/Framework/Models/SConfig.cs b/src/SMAPI/Framework/Models/SConfig.cs
index 401e1a3a..17169714 100644
--- a/src/SMAPI/Framework/Models/SConfig.cs
+++ b/src/SMAPI/Framework/Models/SConfig.cs
@@ -1,3 +1,6 @@
+using System.Collections.Generic;
+using StardewModdingAPI.Framework.ModData;
+
namespace StardewModdingAPI.Framework.Models
{
/// <summary>The SMAPI configuration settings.</summary>
@@ -22,6 +25,6 @@ namespace StardewModdingAPI.Framework.Models
public bool VerboseLogging { get; set; }
/// <summary>Extra metadata about mods.</summary>
- public ModDataRecord[] ModData { get; set; }
+ public IDictionary<string, ModDataRecord> ModData { get; set; }
}
}