diff options
Diffstat (limited to 'src/SMAPI.Web/ViewModels')
-rw-r--r-- | src/SMAPI.Web/ViewModels/IndexModel.cs | 7 | ||||
-rw-r--r-- | src/SMAPI.Web/ViewModels/ModCompatibilityModel.cs | 40 | ||||
-rw-r--r-- | src/SMAPI.Web/ViewModels/ModLinkModel.cs | 28 | ||||
-rw-r--r-- | src/SMAPI.Web/ViewModels/ModListModel.cs | 36 | ||||
-rw-r--r-- | src/SMAPI.Web/ViewModels/ModModel.cs | 110 |
5 files changed, 220 insertions, 1 deletions
diff --git a/src/SMAPI.Web/ViewModels/IndexModel.cs b/src/SMAPI.Web/ViewModels/IndexModel.cs index 4268c878..82c4e06f 100644 --- a/src/SMAPI.Web/ViewModels/IndexModel.cs +++ b/src/SMAPI.Web/ViewModels/IndexModel.cs @@ -12,6 +12,9 @@ namespace StardewModdingAPI.Web.ViewModels /// <summary>The latest prerelease SMAPI version (if newer than <see cref="StableVersion"/>).</summary> public IndexVersionModel BetaVersion { get; set; } + /// <summary>A short sentence shown under the beta download button, if any.</summary> + public string BetaBlurb { get; set; } + /********* ** Public methods @@ -22,10 +25,12 @@ namespace StardewModdingAPI.Web.ViewModels /// <summary>Construct an instance.</summary> /// <param name="stableVersion">The latest stable SMAPI version.</param> /// <param name="betaVersion">The latest prerelease SMAPI version (if newer than <paramref name="stableVersion"/>).</param> - internal IndexModel(IndexVersionModel stableVersion, IndexVersionModel betaVersion) + /// <param name="betaBlurb">A short sentence shown under the beta download button, if any.</param> + internal IndexModel(IndexVersionModel stableVersion, IndexVersionModel betaVersion, string betaBlurb) { this.StableVersion = stableVersion; this.BetaVersion = betaVersion; + this.BetaBlurb = betaBlurb; } } } diff --git a/src/SMAPI.Web/ViewModels/ModCompatibilityModel.cs b/src/SMAPI.Web/ViewModels/ModCompatibilityModel.cs new file mode 100644 index 00000000..85bf1e46 --- /dev/null +++ b/src/SMAPI.Web/ViewModels/ModCompatibilityModel.cs @@ -0,0 +1,40 @@ +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; set; } + + /// <summary>The human-readable summary, as an HTML block.</summary> + public string Summary { get; set; } + + /// <summary>The game or SMAPI version which broke this mod (if applicable).</summary> + public string BrokeIn { get; set; } + + /// <summary>A link to the unofficial version which fixes compatibility, if any.</summary> + public ModLinkModel UnofficialVersion { get; set; } + + + /********* + ** Public methods + *********/ + /// <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()); + } + } +} diff --git a/src/SMAPI.Web/ViewModels/ModLinkModel.cs b/src/SMAPI.Web/ViewModels/ModLinkModel.cs new file mode 100644 index 00000000..97dd215c --- /dev/null +++ b/src/SMAPI.Web/ViewModels/ModLinkModel.cs @@ -0,0 +1,28 @@ +namespace StardewModdingAPI.Web.ViewModels +{ + /// <summary>Metadata about a link.</summary> + public class ModLinkModel + { + /********* + ** Accessors + *********/ + /// <summary>The URL of the linked page.</summary> + public string Url { get; set; } + + /// <summary>The suggested link text.</summary> + public string Text { get; set; } + + + /********* + ** Public methods + *********/ + /// <summary>Construct an instance.</summary> + /// <param name="url">The URL of the linked page.</param> + /// <param name="text">The suggested link text.</param> + public ModLinkModel(string url, string text) + { + this.Url = url; + this.Text = text; + } + } +} diff --git a/src/SMAPI.Web/ViewModels/ModListModel.cs b/src/SMAPI.Web/ViewModels/ModListModel.cs new file mode 100644 index 00000000..3b87d393 --- /dev/null +++ b/src/SMAPI.Web/ViewModels/ModListModel.cs @@ -0,0 +1,36 @@ +using System.Collections.Generic; +using System.Linq; + +namespace StardewModdingAPI.Web.ViewModels +{ + /// <summary>Metadata for the mod list page.</summary> + public class ModListModel + { + /********* + ** Accessors + *********/ + /// <summary>The current stable version of the game.</summary> + public string StableVersion { get; set; } + + /// <summary>The current beta version of the game (if any).</summary> + public string BetaVersion { get; set; } + + /// <summary>The mods to display.</summary> + public ModModel[] Mods { get; set; } + + + /********* + ** Public methods + *********/ + /// <summary>Construct an instance.</summary> + /// <param name="stableVersion">The current stable version of the game.</param> + /// <param name="betaVersion">The current beta version of the game (if any).</param> + /// <param name="mods">The mods to display.</param> + public ModListModel(string stableVersion, string betaVersion, IEnumerable<ModModel> mods) + { + this.StableVersion = stableVersion; + this.BetaVersion = betaVersion; + this.Mods = mods.ToArray(); + } + } +} diff --git a/src/SMAPI.Web/ViewModels/ModModel.cs b/src/SMAPI.Web/ViewModels/ModModel.cs new file mode 100644 index 00000000..0e7d2076 --- /dev/null +++ b/src/SMAPI.Web/ViewModels/ModModel.cs @@ -0,0 +1,110 @@ +using System.Collections.Generic; +using System.Linq; +using StardewModdingAPI.Toolkit.Framework.Clients.Wiki; + +namespace StardewModdingAPI.Web.ViewModels +{ + /// <summary>Metadata about a mod.</summary> + public class ModModel + { + /********* + ** Accessors + *********/ + /// <summary>The mod name.</summary> + public string Name { get; set; } + + /// <summary>The mod's alternative names, if any.</summary> + public string AlternateNames { get; set; } + + /// <summary>The mod author's name.</summary> + public string Author { get; set; } + + /// <summary>The mod author's alternative names, if any.</summary> + public string AlternateAuthors { get; set; } + + /// <summary>The URL to the mod's source code, if any.</summary> + public string SourceUrl { get; set; } + + /// <summary>The compatibility status for the stable version of the game.</summary> + public ModCompatibilityModel Compatibility { get; set; } + + /// <summary>The compatibility status for the beta version of the game.</summary> + public ModCompatibilityModel BetaCompatibility { get; set; } + + /// <summary>Links to the available mod pages.</summary> + public ModLinkModel[] ModPages { get; set; } + + /// <summary>The human-readable warnings for players about this mod.</summary> + public string[] Warnings { get; set; } + + /// <summary>A unique identifier for the mod that can be used in an anchor URL.</summary> + public string Slug { get; set; } + + /// <summary>The sites where the mod can be downloaded.</summary> + public string[] ModPageSites => this.ModPages.Select(p => p.Text).ToArray(); + + + /********* + ** Public methods + *********/ + /// <summary>Construct an instance.</summary> + /// <param name="entry">The mod metadata.</param> + public ModModel(WikiModEntry entry) + { + // basic info + this.Name = entry.Name.FirstOrDefault(); + this.AlternateNames = string.Join(", ", entry.Name.Skip(1).ToArray()); + this.Author = entry.Author.FirstOrDefault(); + this.AlternateAuthors = string.Join(", ", entry.Author.Skip(1).ToArray()); + this.SourceUrl = this.GetSourceUrl(entry); + this.Compatibility = new ModCompatibilityModel(entry.Compatibility); + this.BetaCompatibility = entry.BetaCompatibility != null ? new ModCompatibilityModel(entry.BetaCompatibility) : null; + this.ModPages = this.GetModPageUrls(entry).ToArray(); + this.Warnings = entry.Warnings; + this.Slug = entry.Anchor; + } + + + /********* + ** Private methods + *********/ + /// <summary>Get the web URL for the mod's source code repository, if any.</summary> + /// <param name="entry">The mod metadata.</param> + private string GetSourceUrl(WikiModEntry entry) + { + if (!string.IsNullOrWhiteSpace(entry.GitHubRepo)) + return $"https://github.com/{entry.GitHubRepo}"; + if (!string.IsNullOrWhiteSpace(entry.CustomSourceUrl)) + return entry.CustomSourceUrl; + return null; + } + + /// <summary>Get the web URLs for the mod pages, if any.</summary> + /// <param name="entry">The mod metadata.</param> + private IEnumerable<ModLinkModel> GetModPageUrls(WikiModEntry entry) + { + bool anyFound = false; + + // normal mod pages + if (entry.NexusID.HasValue) + { + anyFound = true; + yield return new ModLinkModel($"https://www.nexusmods.com/stardewvalley/mods/{entry.NexusID}", "Nexus"); + } + if (entry.ChucklefishID.HasValue) + { + anyFound = true; + yield return new ModLinkModel($"https://community.playstarbound.com/resources/{entry.ChucklefishID}", "Chucklefish"); + } + + // fallback + if (!anyFound && !string.IsNullOrWhiteSpace(entry.CustomUrl)) + { + anyFound = true; + yield return new ModLinkModel(entry.CustomUrl, "custom"); + } + if (!anyFound && !string.IsNullOrWhiteSpace(entry.GitHubRepo)) + yield return new ModLinkModel($"https://github.com/{entry.GitHubRepo}/releases", "GitHub"); + } + } +} |