2018-10-21 03:10:44 +08:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
2022-04-13 07:15:39 +08:00
|
|
|
using Newtonsoft.Json;
|
2018-10-21 03:10:44 +08:00
|
|
|
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>
|
2022-04-13 07:15:39 +08:00
|
|
|
public string? Name { get; }
|
2018-10-21 03:10:44 +08:00
|
|
|
|
|
|
|
/// <summary>The mod's alternative names, if any.</summary>
|
2022-04-13 07:15:39 +08:00
|
|
|
public string AlternateNames { get; }
|
2018-10-21 03:10:44 +08:00
|
|
|
|
|
|
|
/// <summary>The mod author's name.</summary>
|
2022-04-13 07:15:39 +08:00
|
|
|
public string? Author { get; }
|
2018-10-21 03:10:44 +08:00
|
|
|
|
|
|
|
/// <summary>The mod author's alternative names, if any.</summary>
|
2022-04-13 07:15:39 +08:00
|
|
|
public string AlternateAuthors { get; }
|
2018-10-21 03:10:44 +08:00
|
|
|
|
2020-05-10 02:06:10 +08:00
|
|
|
/// <summary>The GitHub repo, if any.</summary>
|
2022-04-13 07:15:39 +08:00
|
|
|
public string? GitHubRepo { get; }
|
2020-05-10 02:06:10 +08:00
|
|
|
|
2018-10-21 03:10:44 +08:00
|
|
|
/// <summary>The URL to the mod's source code, if any.</summary>
|
2022-04-13 07:15:39 +08:00
|
|
|
public string? SourceUrl { get; }
|
2018-10-21 03:10:44 +08:00
|
|
|
|
|
|
|
/// <summary>The compatibility status for the stable version of the game.</summary>
|
2022-04-13 07:15:39 +08:00
|
|
|
public ModCompatibilityModel Compatibility { get; }
|
2018-10-21 03:10:44 +08:00
|
|
|
|
|
|
|
/// <summary>The compatibility status for the beta version of the game.</summary>
|
2022-04-13 07:15:39 +08:00
|
|
|
public ModCompatibilityModel? BetaCompatibility { get; }
|
2018-10-21 03:10:44 +08:00
|
|
|
|
|
|
|
/// <summary>Links to the available mod pages.</summary>
|
2022-04-13 07:15:39 +08:00
|
|
|
public ModLinkModel[] ModPages { get; }
|
2018-10-21 03:10:44 +08:00
|
|
|
|
2018-10-28 09:15:53 +08:00
|
|
|
/// <summary>The human-readable warnings for players about this mod.</summary>
|
2022-04-13 07:15:39 +08:00
|
|
|
public string[] Warnings { get; }
|
2018-10-28 09:15:53 +08:00
|
|
|
|
2020-01-12 05:53:58 +08:00
|
|
|
/// <summary>The URL of the pull request which submits changes for an unofficial update to the author, if any.</summary>
|
2022-04-13 07:15:39 +08:00
|
|
|
public string? PullRequestUrl { get; }
|
2019-07-15 05:49:33 +08:00
|
|
|
|
2022-04-13 07:15:39 +08:00
|
|
|
/// <summary>Special notes intended for developers who maintain unofficial updates or submit pull requests.</summary>
|
|
|
|
public string? DevNote { get; }
|
2019-07-15 10:27:00 +08:00
|
|
|
|
2018-10-21 03:10:44 +08:00
|
|
|
/// <summary>A unique identifier for the mod that can be used in an anchor URL.</summary>
|
2022-04-13 07:15:39 +08:00
|
|
|
public string? Slug { get; }
|
2018-10-21 03:10:44 +08:00
|
|
|
|
2018-11-10 06:35:56 +08:00
|
|
|
/// <summary>The sites where the mod can be downloaded.</summary>
|
|
|
|
public string[] ModPageSites => this.ModPages.Select(p => p.Text).ToArray();
|
|
|
|
|
2018-10-21 03:10:44 +08:00
|
|
|
|
|
|
|
/*********
|
|
|
|
** Public methods
|
|
|
|
*********/
|
2022-04-13 07:15:39 +08:00
|
|
|
/// <summary>Construct an instance.</summary>
|
|
|
|
/// <param name="name">The mod name.</param>
|
|
|
|
/// <param name="alternateNames">The mod's alternative names, if any.</param>
|
|
|
|
/// <param name="author">The mod author's name.</param>
|
|
|
|
/// <param name="alternateAuthors">The mod author's alternative names, if any.</param>
|
|
|
|
/// <param name="gitHubRepo">The GitHub repo, if any.</param>
|
|
|
|
/// <param name="sourceUrl">The URL to the mod's source code, if any.</param>
|
|
|
|
/// <param name="compatibility">The compatibility status for the stable version of the game.</param>
|
|
|
|
/// <param name="betaCompatibility">The compatibility status for the beta version of the game.</param>
|
|
|
|
/// <param name="modPages">Links to the available mod pages.</param>
|
|
|
|
/// <param name="warnings">The human-readable warnings for players about this mod.</param>
|
|
|
|
/// <param name="pullRequestUrl">The URL of the pull request which submits changes for an unofficial update to the author, if any.</param>
|
|
|
|
/// <param name="devNote">Special notes intended for developers who maintain unofficial updates or submit pull requests.</param>
|
|
|
|
/// <param name="slug">A unique identifier for the mod that can be used in an anchor URL.</param>
|
|
|
|
[JsonConstructor]
|
|
|
|
public ModModel(string? name, string alternateNames, string author, string alternateAuthors, string gitHubRepo, string sourceUrl, ModCompatibilityModel compatibility, ModCompatibilityModel betaCompatibility, ModLinkModel[] modPages, string[] warnings, string pullRequestUrl, string devNote, string slug)
|
|
|
|
{
|
|
|
|
this.Name = name;
|
|
|
|
this.AlternateNames = alternateNames;
|
|
|
|
this.Author = author;
|
|
|
|
this.AlternateAuthors = alternateAuthors;
|
|
|
|
this.GitHubRepo = gitHubRepo;
|
|
|
|
this.SourceUrl = sourceUrl;
|
|
|
|
this.Compatibility = compatibility;
|
|
|
|
this.BetaCompatibility = betaCompatibility;
|
|
|
|
this.ModPages = modPages;
|
|
|
|
this.Warnings = warnings;
|
|
|
|
this.PullRequestUrl = pullRequestUrl;
|
|
|
|
this.DevNote = devNote;
|
|
|
|
this.Slug = slug;
|
|
|
|
}
|
|
|
|
|
2018-10-21 03:10:44 +08:00
|
|
|
/// <summary>Construct an instance.</summary>
|
|
|
|
/// <param name="entry">The mod metadata.</param>
|
|
|
|
public ModModel(WikiModEntry entry)
|
|
|
|
{
|
|
|
|
// basic info
|
2018-10-28 08:37:42 +08:00
|
|
|
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());
|
2020-05-10 02:06:10 +08:00
|
|
|
this.GitHubRepo = entry.GitHubRepo;
|
2018-10-21 03:10:44 +08:00
|
|
|
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();
|
2018-10-28 09:15:53 +08:00
|
|
|
this.Warnings = entry.Warnings;
|
2020-01-12 05:53:58 +08:00
|
|
|
this.PullRequestUrl = entry.PullRequestUrl;
|
2019-07-15 10:27:00 +08:00
|
|
|
this.DevNote = entry.DevNote;
|
2018-10-21 03:10:44 +08:00
|
|
|
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>
|
2022-04-13 07:15:39 +08:00
|
|
|
private string? GetSourceUrl(WikiModEntry entry)
|
2018-10-21 03:10:44 +08:00
|
|
|
{
|
|
|
|
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");
|
|
|
|
}
|
2019-11-09 02:44:49 +08:00
|
|
|
if (entry.ModDropID.HasValue)
|
2018-10-21 03:10:44 +08:00
|
|
|
{
|
|
|
|
anyFound = true;
|
2020-05-25 02:35:16 +08:00
|
|
|
yield return new ModLinkModel($"https://www.moddrop.com/stardew-valley/mod/{entry.ModDropID}", "ModDrop");
|
2018-10-21 03:10:44 +08:00
|
|
|
}
|
2019-11-09 02:44:49 +08:00
|
|
|
if (!string.IsNullOrWhiteSpace(entry.CurseForgeKey))
|
2018-12-03 04:16:24 +08:00
|
|
|
{
|
|
|
|
anyFound = true;
|
2019-11-09 02:44:49 +08:00
|
|
|
yield return new ModLinkModel($"https://www.curseforge.com/stardewvalley/mods/{entry.CurseForgeKey}", "CurseForge");
|
|
|
|
}
|
|
|
|
if (entry.ChucklefishID.HasValue)
|
|
|
|
{
|
|
|
|
anyFound = true;
|
|
|
|
yield return new ModLinkModel($"https://community.playstarbound.com/resources/{entry.ChucklefishID}", "Chucklefish");
|
2018-12-03 04:16:24 +08:00
|
|
|
}
|
2018-10-21 03:10:44 +08:00
|
|
|
|
|
|
|
// 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");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|