blob: 5d1b73b1c44feebedbe4dbdde224c3ddfa510a04 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
using System.Diagnostics.CodeAnalysis;
using Newtonsoft.Json;
namespace StardewModdingAPI.Toolkit.Serialization.Models
{
/// <summary>A mod dependency listed in a mod manifest.</summary>
public class ManifestDependency : IManifestDependency
{
/*********
** Accessors
*********/
/// <summary>The unique mod ID to require.</summary>
public string UniqueID { get; }
/// <summary>The minimum required version (if any).</summary>
public ISemanticVersion? MinimumVersion { get; }
/// <summary>Whether the dependency must be installed to use the mod.</summary>
public bool IsRequired { get; }
/*********
** Public methods
*********/
/// <summary>Construct an instance.</summary>
/// <param name="uniqueID">The unique mod ID to require.</param>
/// <param name="minimumVersion">The minimum required version (if any).</param>
/// <param name="required">Whether the dependency must be installed to use the mod.</param>
public ManifestDependency(string uniqueID, string? minimumVersion, bool required = true)
: this(
uniqueID: uniqueID,
minimumVersion: !string.IsNullOrWhiteSpace(minimumVersion)
? new SemanticVersion(minimumVersion)
: null,
required: required
)
{ }
/// <summary>Construct an instance.</summary>
/// <param name="uniqueID">The unique mod ID to require.</param>
/// <param name="minimumVersion">The minimum required version (if any).</param>
/// <param name="required">Whether the dependency must be installed to use the mod.</param>
[JsonConstructor]
public ManifestDependency(string uniqueID, ISemanticVersion? minimumVersion, bool required = true)
{
this.UniqueID = this.NormalizeWhitespace(uniqueID);
this.MinimumVersion = minimumVersion;
this.IsRequired = required;
}
/*********
** Private methods
*********/
/// <summary>Normalize whitespace in a raw string.</summary>
/// <param name="input">The input to strip.</param>
[return: NotNullIfNotNull("input")]
private string? NormalizeWhitespace(string? input)
{
return input?.Trim();
}
}
}
|