From a3fdab34d5b39840ca60b79cf80bebfe4bfbb780 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 24 Nov 2021 13:34:52 +0900 Subject: [PATCH] Avoid json serialisation of aggregate helper properties Also avoids `throw`ing when there are no beatmaps available. Until now this wasn't an issue due to the `Beatmaps` list being null instead of empty. --- osu.Game/Beatmaps/BeatmapSetInfo.cs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/osu.Game/Beatmaps/BeatmapSetInfo.cs b/osu.Game/Beatmaps/BeatmapSetInfo.cs index 818a6dd48f..998bc6f16c 100644 --- a/osu.Game/Beatmaps/BeatmapSetInfo.cs +++ b/osu.Game/Beatmaps/BeatmapSetInfo.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.ComponentModel.DataAnnotations.Schema; using System.Linq; using JetBrains.Annotations; +using Newtonsoft.Json; using osu.Framework.Testing; using osu.Game.Database; using osu.Game.Extensions; @@ -30,6 +31,7 @@ namespace osu.Game.Beatmaps public BeatmapMetadata Metadata { get; set; } + [NotNull] public List Beatmaps { get; } = new List(); public BeatmapSetOnlineStatus Status { get; set; } = BeatmapSetOnlineStatus.None; @@ -40,17 +42,20 @@ namespace osu.Game.Beatmaps /// /// The maximum star difficulty of all beatmaps in this set. /// - public double MaxStarDifficulty => Beatmaps?.Max(b => b.StarRating) ?? 0; + [JsonIgnore] + public double MaxStarDifficulty => Beatmaps.Count == 0 ? 0 : Beatmaps.Max(b => b.StarRating); /// /// The maximum playable length in milliseconds of all beatmaps in this set. /// - public double MaxLength => Beatmaps?.Max(b => b.Length) ?? 0; + [JsonIgnore] + public double MaxLength => Beatmaps.Count == 0 ? 0 : Beatmaps.Max(b => b.Length); /// /// The maximum BPM of all beatmaps in this set. /// - public double MaxBPM => Beatmaps?.Max(b => b.BPM) ?? 0; + [JsonIgnore] + public double MaxBPM => Beatmaps.Count == 0 ? 0 : Beatmaps.Max(b => b.BPM); [NotMapped] public bool DeletePending { get; set; }