mirror of
https://github.com/ppy/osu.git
synced 2024-12-16 06:33:32 +08:00
Make BeatmapSetInfo.Files
non-nullable
This commit is contained in:
parent
fdbd421040
commit
c24712642c
@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Linq.Expressions;
|
using System.Linq.Expressions;
|
||||||
@ -245,8 +244,6 @@ namespace osu.Game.Beatmaps
|
|||||||
{
|
{
|
||||||
var setInfo = info.BeatmapSet;
|
var setInfo = info.BeatmapSet;
|
||||||
|
|
||||||
Debug.Assert(setInfo.Files != null);
|
|
||||||
|
|
||||||
using (var stream = new MemoryStream())
|
using (var stream = new MemoryStream())
|
||||||
{
|
{
|
||||||
using (var sw = new StreamWriter(stream, Encoding.UTF8, 1024, true))
|
using (var sw = new StreamWriter(stream, Encoding.UTF8, 1024, true))
|
||||||
@ -287,20 +284,21 @@ namespace osu.Game.Beatmaps
|
|||||||
/// <returns>A <see cref="WorkingBeatmap"/> instance correlating to the provided <see cref="BeatmapInfo"/>.</returns>
|
/// <returns>A <see cref="WorkingBeatmap"/> instance correlating to the provided <see cref="BeatmapInfo"/>.</returns>
|
||||||
public virtual WorkingBeatmap GetWorkingBeatmap(BeatmapInfo beatmapInfo, WorkingBeatmap previous = null)
|
public virtual WorkingBeatmap GetWorkingBeatmap(BeatmapInfo beatmapInfo, WorkingBeatmap previous = null)
|
||||||
{
|
{
|
||||||
if (beatmapInfo?.ID > 0 && previous != null && previous.BeatmapInfo?.ID == beatmapInfo.ID)
|
if (beatmapInfo?.BeatmapSet == null)
|
||||||
return previous;
|
|
||||||
|
|
||||||
if (beatmapInfo?.BeatmapSet == null || beatmapInfo == DefaultBeatmap?.BeatmapInfo)
|
|
||||||
return DefaultBeatmap;
|
return DefaultBeatmap;
|
||||||
|
|
||||||
if (beatmapInfo.BeatmapSet.Files == null)
|
if (beatmapInfo == DefaultBeatmap?.BeatmapInfo)
|
||||||
|
return DefaultBeatmap;
|
||||||
|
|
||||||
|
// if there are no files, presume the full beatmap info has not yet been fetched from the database.
|
||||||
|
if (beatmapInfo.BeatmapSet.Files.Count == 0)
|
||||||
{
|
{
|
||||||
var info = beatmapInfo;
|
int lookupId = beatmapInfo.ID;
|
||||||
beatmapInfo = QueryBeatmap(b => b.ID == info.ID);
|
beatmapInfo = QueryBeatmap(b => b.ID == lookupId);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (beatmapInfo == null)
|
if (beatmapInfo.ID > 0 && previous != null && previous.BeatmapInfo?.ID == beatmapInfo.ID)
|
||||||
return DefaultBeatmap;
|
return previous;
|
||||||
|
|
||||||
lock (workingCache)
|
lock (workingCache)
|
||||||
{
|
{
|
||||||
|
@ -5,6 +5,7 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using JetBrains.Annotations;
|
||||||
using osu.Framework.Testing;
|
using osu.Framework.Testing;
|
||||||
using osu.Game.Database;
|
using osu.Game.Database;
|
||||||
|
|
||||||
@ -31,6 +32,9 @@ namespace osu.Game.Beatmaps
|
|||||||
|
|
||||||
public List<BeatmapInfo> Beatmaps { get; set; }
|
public List<BeatmapInfo> Beatmaps { get; set; }
|
||||||
|
|
||||||
|
[NotNull]
|
||||||
|
public List<BeatmapSetFileInfo> Files { get; set; } = new List<BeatmapSetFileInfo>();
|
||||||
|
|
||||||
[NotMapped]
|
[NotMapped]
|
||||||
public BeatmapSetOnlineInfo OnlineInfo { get; set; }
|
public BeatmapSetOnlineInfo OnlineInfo { get; set; }
|
||||||
|
|
||||||
@ -57,16 +61,14 @@ namespace osu.Game.Beatmaps
|
|||||||
|
|
||||||
public string Hash { get; set; }
|
public string Hash { get; set; }
|
||||||
|
|
||||||
public string StoryboardFile => Files?.Find(f => f.Filename.EndsWith(".osb", StringComparison.OrdinalIgnoreCase))?.Filename;
|
public string StoryboardFile => Files.Find(f => f.Filename.EndsWith(".osb", StringComparison.OrdinalIgnoreCase))?.Filename;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns the storage path for the file in this beatmapset with the given filename, if any exists, otherwise null.
|
/// Returns the storage path for the file in this beatmapset with the given filename, if any exists, otherwise null.
|
||||||
/// The path returned is relative to the user file storage.
|
/// The path returned is relative to the user file storage.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="filename">The name of the file to get the storage path of.</param>
|
/// <param name="filename">The name of the file to get the storage path of.</param>
|
||||||
public string GetPathForFile(string filename) => Files?.SingleOrDefault(f => string.Equals(f.Filename, filename, StringComparison.OrdinalIgnoreCase))?.FileInfo.StoragePath;
|
public string GetPathForFile(string filename) => Files.SingleOrDefault(f => string.Equals(f.Filename, filename, StringComparison.OrdinalIgnoreCase))?.FileInfo.StoragePath;
|
||||||
|
|
||||||
public List<BeatmapSetFileInfo> Files { get; set; }
|
|
||||||
|
|
||||||
public override string ToString() => Metadata?.ToString() ?? base.ToString();
|
public override string ToString() => Metadata?.ToString() ?? base.ToString();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user