diff options
author | Jesse Plamondon-Willard <github@jplamondonw.com> | 2018-10-20 15:10:44 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <github@jplamondonw.com> | 2018-10-20 15:10:44 -0400 |
commit | 28fdb9e4e7f5419947226171bf6d7efa273802c5 (patch) | |
tree | 26231b40f1e6c338e00f420b1856ae298dceea7c /src/SMAPI.Web/ViewModels/ModModel.cs | |
parent | f09befe24047de8187276c722557b6f0fddd6e35 (diff) | |
download | SMAPI-28fdb9e4e7f5419947226171bf6d7efa273802c5.tar.gz SMAPI-28fdb9e4e7f5419947226171bf6d7efa273802c5.tar.bz2 SMAPI-28fdb9e4e7f5419947226171bf6d7efa273802c5.zip |
add mod compatibility page (#597)
Diffstat (limited to 'src/SMAPI.Web/ViewModels/ModModel.cs')
-rw-r--r-- | src/SMAPI.Web/ViewModels/ModModel.cs | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/src/SMAPI.Web/ViewModels/ModModel.cs b/src/SMAPI.Web/ViewModels/ModModel.cs new file mode 100644 index 00000000..4fb9d5b5 --- /dev/null +++ b/src/SMAPI.Web/ViewModels/ModModel.cs @@ -0,0 +1,107 @@ +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 game or SMAPI version which broke this mod (if applicable).</summary> + public string BrokeIn { get; set; } + + /// <summary>A unique identifier for the mod that can be used in an anchor URL.</summary> + public string Slug { get; set; } + + + /********* + ** Public methods + *********/ + /// <summary>Construct an instance.</summary> + /// <param name="entry">The mod metadata.</param> + public ModModel(WikiModEntry entry) + { + // basic info + this.Name = entry.Name; + this.AlternateNames = entry.AlternateNames; + this.Author = entry.Author; + this.AlternateAuthors = entry.AlternateAuthors; + 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.BrokeIn = entry.BrokeIn; + 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"); + } + } +} |