using System.Diagnostics.CodeAnalysis;
using Newtonsoft.Json;
namespace StardewModdingAPI.Toolkit.Serialization.Models
{
/// A mod dependency listed in a mod manifest.
public class ManifestDependency : IManifestDependency
{
/*********
** Accessors
*********/
/// The unique mod ID to require.
public string UniqueID { get; }
/// The minimum required version (if any).
public ISemanticVersion? MinimumVersion { get; }
/// Whether the dependency must be installed to use the mod.
public bool IsRequired { get; }
/*********
** Public methods
*********/
/// Construct an instance.
/// The unique mod ID to require.
/// The minimum required version (if any).
/// Whether the dependency must be installed to use the mod.
public ManifestDependency(string uniqueID, string? minimumVersion, bool required = true)
: this(
uniqueID: uniqueID,
minimumVersion: !string.IsNullOrWhiteSpace(minimumVersion)
? new SemanticVersion(minimumVersion)
: null,
required: required
)
{ }
/// Construct an instance.
/// The unique mod ID to require.
/// The minimum required version (if any).
/// Whether the dependency must be installed to use the mod.
[JsonConstructor]
public ManifestDependency(string uniqueID, ISemanticVersion? minimumVersion, bool required = true)
{
this.UniqueID = this.NormalizeWhitespace(uniqueID);
this.MinimumVersion = minimumVersion;
this.IsRequired = required;
}
/*********
** Private methods
*********/
/// Normalize whitespace in a raw string.
/// The input to strip.
[return: NotNullIfNotNull("input")]
private string? NormalizeWhitespace(string? input)
{
return input?.Trim();
}
}
}