diff options
Diffstat (limited to 'src/StardewModdingAPI.Toolkit/Framework/Clients')
-rw-r--r-- | src/StardewModdingAPI.Toolkit/Framework/Clients/WebApi/ModEntryModel.cs | 45 | ||||
-rw-r--r-- | src/StardewModdingAPI.Toolkit/Framework/Clients/WebApi/ModEntryVersionModel.cs | 31 |
2 files changed, 70 insertions, 6 deletions
diff --git a/src/StardewModdingAPI.Toolkit/Framework/Clients/WebApi/ModEntryModel.cs b/src/StardewModdingAPI.Toolkit/Framework/Clients/WebApi/ModEntryModel.cs index e4ab168e..581a524c 100644 --- a/src/StardewModdingAPI.Toolkit/Framework/Clients/WebApi/ModEntryModel.cs +++ b/src/StardewModdingAPI.Toolkit/Framework/Clients/WebApi/ModEntryModel.cs @@ -1,3 +1,5 @@ +using System; + namespace StardewModdingAPI.Toolkit.Framework.Clients.WebApi { /// <summary>Metadata about a mod.</summary> @@ -12,19 +14,50 @@ namespace StardewModdingAPI.Toolkit.Framework.Clients.WebApi /// <summary>The mod name.</summary> public string Name { get; set; } + /// <summary>The main version.</summary> + public ModEntryVersionModel Main { get; set; } + + /// <summary>The latest optional version, if newer than <see cref="Main"/>.</summary> + public ModEntryVersionModel Optional { get; set; } + + /// <summary>The errors that occurred while fetching update data.</summary> + public string[] Errors { get; set; } = new string[0]; + + /**** + ** Backwards-compatible fields + ****/ /// <summary>The mod's latest version number.</summary> - public string Version { get; set; } + [Obsolete("Use " + nameof(ModEntryModel.Main))] + internal string Version { get; private set; } /// <summary>The mod's web URL.</summary> - public string Url { get; set; } + [Obsolete("Use " + nameof(ModEntryModel.Main))] + internal string Url { get; private set; } /// <summary>The mod's latest optional release, if newer than <see cref="Version"/>.</summary> - public string PreviewVersion { get; set; } + [Obsolete("Use " + nameof(ModEntryModel.Optional))] + internal string PreviewVersion { get; private set; } /// <summary>The web URL to the mod's latest optional release, if newer than <see cref="Version"/>.</summary> - public string PreviewUrl { get; set; } + [Obsolete("Use " + nameof(ModEntryModel.Optional))] + internal string PreviewUrl { get; private set; } - /// <summary>The errors that occurred while fetching update data.</summary> - public string[] Errors { get; set; } = new string[0]; + + /********* + ** Public methods + *********/ + /// <summary>Set backwards-compatible fields.</summary> + /// <param name="version">The requested API version.</param> + public void SetBackwardsCompatibility(ISemanticVersion version) + { + if (version.IsOlderThan("2.6-beta.19")) + { + this.Version = this.Main?.Version?.ToString(); + this.Url = this.Main?.Url; + + this.PreviewVersion = this.Optional?.Version?.ToString(); + this.PreviewUrl = this.Optional?.Url; + } + } } } diff --git a/src/StardewModdingAPI.Toolkit/Framework/Clients/WebApi/ModEntryVersionModel.cs b/src/StardewModdingAPI.Toolkit/Framework/Clients/WebApi/ModEntryVersionModel.cs new file mode 100644 index 00000000..dadb8c10 --- /dev/null +++ b/src/StardewModdingAPI.Toolkit/Framework/Clients/WebApi/ModEntryVersionModel.cs @@ -0,0 +1,31 @@ +namespace StardewModdingAPI.Toolkit.Framework.Clients.WebApi +{ + /// <summary>Metadata about a version.</summary> + public class ModEntryVersionModel + { + /********* + ** Accessors + *********/ + /// <summary>The version number.</summary> + public ISemanticVersion Version { get; set; } + + /// <summary>The mod page URL.</summary> + public string Url { get; set; } + + + /********* + ** Public methods + *********/ + /// <summary>Construct an instance.</summary> + public ModEntryVersionModel() { } + + /// <summary>Construct an instance.</summary> + /// <param name="version">The version number.</param> + /// <param name="url">The mod page URL.</param> + public ModEntryVersionModel(ISemanticVersion version, string url) + { + this.Version = version; + this.Url = url; + } + } +} |