summaryrefslogtreecommitdiff
path: root/src/SMAPI.Web/Framework/Caching/Wiki/CachedWikiMod.cs
blob: f4331f8dd063e8764dff1c7e8c0e76743e86bcfd (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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
using System;
using System.Diagnostics.CodeAnalysis;
using MongoDB.Bson;
using StardewModdingAPI.Toolkit;
using StardewModdingAPI.Toolkit.Framework.Clients.Wiki;

namespace StardewModdingAPI.Web.Framework.Caching.Wiki
{
    /// <summary>The model for cached wiki mods.</summary>
    public class CachedWikiMod
    {
        /*********
        ** Accessors
        *********/
        /****
        ** Tracking
        ****/
        /// <summary>The internal MongoDB ID.</summary>
        [SuppressMessage("ReSharper", "InconsistentNaming", Justification = "Named per MongoDB conventions.")]
        public ObjectId _id { get; set; }

        /// <summary>When the data was last updated.</summary>
        public DateTimeOffset LastUpdated { get; set; }

        /****
        ** Mod info
        ****/
        /// <summary>The mod's unique ID. If the mod has alternate/old IDs, they're listed in latest to newest order.</summary>
        public string[] ID { get; set; }

        /// <summary>The mod's display name. If the mod has multiple names, the first one is the most canonical name.</summary>
        public string[] Name { get; set; }

        /// <summary>The mod's author name.  If the author has multiple names, the first one is the most canonical name.</summary>
        public string[] Author { get; set; }

        /// <summary>The mod ID on Nexus.</summary>
        public int? NexusID { get; set; }

        /// <summary>The mod ID in the Chucklefish mod repo.</summary>
        public int? ChucklefishID { get; set; }

        /// <summary>The mod ID in the ModDrop mod repo.</summary>
        public int? ModDropID { get; set; }

        /// <summary>The GitHub repository in the form 'owner/repo'.</summary>
        public string GitHubRepo { get; set; }

        /// <summary>The URL to a non-GitHub source repo.</summary>
        public string CustomSourceUrl { get; set; }

        /// <summary>The custom mod page URL (if applicable).</summary>
        public string CustomUrl { get; set; }

        /// <summary>The name of the mod which loads this content pack, if applicable.</summary>
        public string ContentPackFor { get; set; }

        /// <summary>The human-readable warnings for players about this mod.</summary>
        public string[] Warnings { get; set; }

        /// <summary>The link anchor for the mod entry in the wiki compatibility list.</summary>
        public string Anchor { get; set; }

        /****
        ** Stable compatibility
        ****/
        /// <summary>The compatibility status.</summary>
        public WikiCompatibilityStatus MainStatus { get; set; }

        /// <summary>The human-readable summary of the compatibility status or workaround, without HTML formatting.</summary>
        public string MainSummary { get; set; }

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

        /// <summary>The version of the latest unofficial update, if applicable.</summary>
        public string MainUnofficialVersion { get; set; }

        /// <summary>The URL to the latest unofficial update, if applicable.</summary>
        public string MainUnofficialUrl { get; set; }

        /****
        ** Beta compatibility
        ****/
        /// <summary>The compatibility status.</summary>
        public WikiCompatibilityStatus? BetaStatus { get; set; }

        /// <summary>The human-readable summary of the compatibility status or workaround, without HTML formatting.</summary>
        public string BetaSummary { get; set; }

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

        /// <summary>The version of the latest unofficial update, if applicable.</summary>
        public string BetaUnofficialVersion { get; set; }

        /// <summary>The URL to the latest unofficial update, if applicable.</summary>
        public string BetaUnofficialUrl { get; set; }


        /*********
        ** Accessors
        *********/
        /// <summary>Construct an instance.</summary>
        public CachedWikiMod() { }

        /// <summary>Construct an instance.</summary>
        /// <param name="mod">The mod data.</param>
        public CachedWikiMod(WikiModEntry mod)
        {
            // tracking
            this.LastUpdated = DateTimeOffset.UtcNow;

            // mod info
            this.ID = mod.ID;
            this.Name = mod.Name;
            this.Author = mod.Author;
            this.NexusID = mod.NexusID;
            this.ChucklefishID = mod.ChucklefishID;
            this.ModDropID = mod.ModDropID;
            this.GitHubRepo = mod.GitHubRepo;
            this.CustomSourceUrl = mod.CustomSourceUrl;
            this.CustomUrl = mod.CustomUrl;
            this.ContentPackFor = mod.ContentPackFor;
            this.Warnings = mod.Warnings;
            this.Anchor = mod.Anchor;

            // stable compatibility
            this.MainStatus = mod.Compatibility.Status;
            this.MainSummary = mod.Compatibility.Summary;
            this.MainBrokeIn = mod.Compatibility.BrokeIn;
            this.MainUnofficialVersion = mod.Compatibility.UnofficialVersion?.ToString();
            this.MainUnofficialUrl = mod.Compatibility.UnofficialUrl;

            // beta compatibility
            this.BetaStatus = mod.BetaCompatibility?.Status;
            this.BetaSummary = mod.BetaCompatibility?.Summary;
            this.BetaBrokeIn = mod.BetaCompatibility?.BrokeIn;
            this.BetaUnofficialVersion = mod.BetaCompatibility?.UnofficialVersion?.ToString();
            this.BetaUnofficialUrl = mod.BetaCompatibility?.UnofficialUrl;
        }

        /// <summary>Reconstruct the original model.</summary>
        public WikiModEntry GetModel()
        {
            var mod = new WikiModEntry
            {
                ID = this.ID,
                Name = this.Name,
                Author = this.Author,
                NexusID = this.NexusID,
                ChucklefishID = this.ChucklefishID,
                ModDropID = this.ModDropID,
                GitHubRepo = this.GitHubRepo,
                CustomSourceUrl = this.CustomSourceUrl,
                CustomUrl = this.CustomUrl,
                ContentPackFor = this.ContentPackFor,
                Warnings = this.Warnings,
                Anchor = this.Anchor,

                // stable compatibility
                Compatibility = new WikiCompatibilityInfo
                {
                    Status = this.MainStatus,
                    Summary = this.MainSummary,
                    BrokeIn = this.MainBrokeIn,
                    UnofficialVersion = this.MainUnofficialVersion != null ? new SemanticVersion(this.MainUnofficialVersion) : null,
                    UnofficialUrl = this.MainUnofficialUrl
                }
            };

            // beta compatibility
            if (this.BetaStatus != null)
            {
                mod.BetaCompatibility = new WikiCompatibilityInfo
                {
                    Status = this.BetaStatus.Value,
                    Summary = this.BetaSummary,
                    BrokeIn = this.BetaBrokeIn,
                    UnofficialVersion = this.BetaUnofficialVersion != null ? new SemanticVersion(this.BetaUnofficialVersion) : null,
                    UnofficialUrl = this.BetaUnofficialUrl
                };
            }

            return mod;
        }
    }
}