summaryrefslogtreecommitdiff
path: root/src/SMAPI.Web/ViewModels/ModCompatibilityModel.cs
blob: 36ea891d11259319e0bd93ec1c81d6d8a03d7ca5 (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
using Newtonsoft.Json;
using StardewModdingAPI.Toolkit.Framework.Clients.Wiki;

namespace StardewModdingAPI.Web.ViewModels
{
    /// <summary>Metadata about a mod's compatibility with the latest versions of SMAPI and Stardew Valley.</summary>
    public class ModCompatibilityModel
    {
        /*********
        ** Accessors
        *********/
        /// <summary>The compatibility status, as a string like <c>"Broken"</c>.</summary>
        public string Status { get; }

        /// <summary>The human-readable summary, as an HTML block.</summary>
        public string? Summary { get; }

        /// <summary>The game or SMAPI version which broke this mod (if applicable).</summary>
        public string? BrokeIn { get; }

        /// <summary>A link to the unofficial version which fixes compatibility, if any.</summary>
        public ModLinkModel? UnofficialVersion { get; }


        /*********
        ** Public methods
        *********/
        /// <summary>Construct an instance.</summary>
        /// <param name="status">The compatibility status, as a string like <c>"Broken"</c>.</param>
        /// <param name="summary">The human-readable summary, as an HTML block.</param>
        /// <param name="brokeIn">The game or SMAPI version which broke this mod (if applicable).</param>
        /// <param name="unofficialVersion">A link to the unofficial version which fixes compatibility, if any.</param>
        [JsonConstructor]
        public ModCompatibilityModel(string status, string? summary, string? brokeIn, ModLinkModel? unofficialVersion)
        {
            this.Status = status;
            this.Summary = summary;
            this.BrokeIn = brokeIn;
            this.UnofficialVersion = unofficialVersion;
        }

        /// <summary>Construct an instance.</summary>
        /// <param name="info">The mod metadata.</param>
        public ModCompatibilityModel(WikiCompatibilityInfo info)
        {
            this.Status = info.Status.ToString();
            this.Status = this.Status.Substring(0, 1).ToLower() + this.Status.Substring(1);

            this.Summary = info.Summary;
            this.BrokeIn = info.BrokeIn;
            if (info.UnofficialVersion != null)
                this.UnofficialVersion = new ModLinkModel(info.UnofficialUrl!, info.UnofficialVersion.ToString());
        }
    }
}