1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-15 01:43:15 +08:00

Make BeatmapOnlineInfo and BeatmapSetOnlineInfo separate classes, -OnlineWorkingBeatmap

This commit is contained in:
DrabWeb 2017-05-28 00:37:55 -03:00
parent e67a00f1f6
commit ab32e962ca
10 changed files with 102 additions and 88 deletions

View File

@ -48,6 +48,13 @@ namespace osu.Desktop.VisualTests.Tests
Author = @"RLC",
Source = @"",
},
OnlineInfo = new BeatmapSetOnlineInfo
{
Covers = new[] { @"https://assets.ppy.sh//beatmaps/578332/covers/cover.jpg?1494591390" },
Preview = @"https://b.ppy.sh/preview/578332.mp3",
PlayCount = 97,
FavouriteCount = 72,
},
Beatmaps = new List<BeatmapInfo>
{
new BeatmapInfo
@ -55,13 +62,6 @@ namespace osu.Desktop.VisualTests.Tests
Ruleset = ruleset,
StarDifficulty = 5.35f,
Metadata = new BeatmapMetadata(),
OnlineInfo = new BeatmapOnlineInfo
{
Covers = new[] { @"https://assets.ppy.sh//beatmaps/578332/covers/cover.jpg?1494591390" },
Preview = @"https://b.ppy.sh/preview/578332.mp3",
PlayCount = 97,
FavouriteCount = 72,
},
},
},
},
@ -74,6 +74,13 @@ namespace osu.Desktop.VisualTests.Tests
Author = @"Sotarks",
Source = @"ぎんぎつね",
},
OnlineInfo = new BeatmapSetOnlineInfo
{
Covers = new[] { @"https://assets.ppy.sh//beatmaps/599627/covers/cover.jpg?1494539318" },
Preview = @"https//b.ppy.sh/preview/599627.mp3",
PlayCount = 3082,
FavouriteCount = 14,
},
Beatmaps = new List<BeatmapInfo>
{
new BeatmapInfo
@ -81,13 +88,6 @@ namespace osu.Desktop.VisualTests.Tests
Ruleset = ruleset,
StarDifficulty = 5.81f,
Metadata = new BeatmapMetadata(),
OnlineInfo = new BeatmapOnlineInfo
{
Covers = new[] { @"https://assets.ppy.sh//beatmaps/599627/covers/cover.jpg?1494539318" },
Preview = @"https//b.ppy.sh/preview/599627.mp3",
PlayCount = 3082,
FavouriteCount = 14,
},
},
},
},
@ -100,6 +100,13 @@ namespace osu.Desktop.VisualTests.Tests
Author = @"Cerulean Veyron",
Source = @"",
},
OnlineInfo = new BeatmapSetOnlineInfo
{
Covers = new[] { @"https://assets.ppy.sh//beatmaps/513268/covers/cover.jpg?1494502863" },
Preview = @"https//b.ppy.sh/preview/513268.mp3",
PlayCount = 2762,
FavouriteCount = 15,
},
Beatmaps = new List<BeatmapInfo>
{
new BeatmapInfo
@ -107,13 +114,6 @@ namespace osu.Desktop.VisualTests.Tests
Ruleset = ruleset,
StarDifficulty = 0.9f,
Metadata = new BeatmapMetadata(),
OnlineInfo = new BeatmapOnlineInfo
{
Covers = new[] { @"https://assets.ppy.sh//beatmaps/513268/covers/cover.jpg?1494502863" },
Preview = @"https//b.ppy.sh/preview/513268.mp3",
PlayCount = 2762,
FavouriteCount = 15,
},
},
new BeatmapInfo
{
@ -141,6 +141,13 @@ namespace osu.Desktop.VisualTests.Tests
Author = @"[Kamiya]",
Source = @"小林さんちのメイドラゴン",
},
OnlineInfo = new BeatmapSetOnlineInfo
{
Covers = new[] { @"https://assets.ppy.sh//beatmaps/586841/covers/cover.jpg?1494052741" },
Preview = @"https//b.ppy.sh/preview/586841.mp3",
PlayCount = 62317,
FavouriteCount = 161,
},
Beatmaps = new List<BeatmapInfo>
{
new BeatmapInfo
@ -148,13 +155,6 @@ namespace osu.Desktop.VisualTests.Tests
Ruleset = ruleset,
StarDifficulty = 1.26f,
Metadata = new BeatmapMetadata(),
OnlineInfo = new BeatmapOnlineInfo
{
Covers = new[] { @"https://assets.ppy.sh//beatmaps/586841/covers/cover.jpg?1494052741" },
Preview = @"https//b.ppy.sh/preview/586841.mp3",
PlayCount = 62317,
FavouriteCount = 161,
},
},
new BeatmapInfo
{

View File

@ -2,6 +2,7 @@
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System.Linq;
using Newtonsoft.Json;
using SQLite.Net.Attributes;
namespace osu.Game.Database
@ -17,7 +18,10 @@ namespace osu.Game.Database
public string TitleUnicode { get; set; }
public string Artist { get; set; }
public string ArtistUnicode { get; set; }
[JsonProperty(@"creator")]
public string Author { get; set; }
public string Source { get; set; }
public string Tags { get; set; }
public int PreviewTime { get; set; }
@ -35,4 +39,4 @@ namespace osu.Game.Database
Tags
}.Where(s => !string.IsNullOrEmpty(s)).ToArray();
}
}
}

View File

@ -11,28 +11,16 @@ namespace osu.Game.Database
/// </summary>
public class BeatmapOnlineInfo
{
/// <summary>
/// The different sizes of cover art for this beatmap: cover, cover@2x, card, card@2x, list, list@2x.
/// </summary>
[JsonProperty(@"covers")]
public IEnumerable<string> Covers { get; set; }
/// <summary>
/// A small sample clip of this beatmap's song.
/// </summary>
[JsonProperty(@"previewUrl")]
public string Preview { get; set; }
/// <summary>
/// The amount of plays this beatmap has.
/// </summary>
[JsonProperty(@"play_count")]
[JsonProperty(@"playcount")]
public int PlayCount { get; set; }
/// <summary>
/// The amount of people who have favourited this map.
/// The amount of passes this beatmap has.
/// </summary>
[JsonProperty(@"favourite_count")]
public int FavouriteCount { get; set; }
[JsonProperty(@"passcount")]
public int PassCount { get; set; }
}
}

View File

@ -24,6 +24,9 @@ namespace osu.Game.Database
[OneToMany(CascadeOperations = CascadeOperation.All)]
public List<BeatmapInfo> Beatmaps { get; set; }
[Ignore]
public BeatmapSetOnlineInfo OnlineInfo { get; set; }
public double MaxStarDifficulty => Beatmaps.Max(b => b.StarDifficulty);
[Indexed]

View File

@ -0,0 +1,38 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using Newtonsoft.Json;
using System.Collections.Generic;
namespace osu.Game.Database
{
/// <summary>
/// Beatmap set info retrieved for previewing locally without having the set downloaded.
/// </summary>
public class BeatmapSetOnlineInfo
{
/// <summary>
/// The different sizes of cover art for this beatmap: cover, cover@2x, card, card@2x, list, list@2x.
/// </summary>
[JsonProperty(@"covers")]
public IEnumerable<string> Covers { get; set; }
/// <summary>
/// A small sample clip of this beatmap's song.
/// </summary>
[JsonProperty(@"previewUrl")]
public string Preview { get; set; }
/// <summary>
/// The amount of plays this set has.
/// </summary>
[JsonProperty(@"play_count")]
public int PlayCount { get; set; }
/// <summary>
/// The amount of people who have favourited this map.
/// </summary>
[JsonProperty(@"favourite_count")]
public int FavouriteCount { get; set; }
}
}

View File

@ -1,37 +0,0 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System.Linq;
using osu.Framework.Audio.Track;
using osu.Framework.Graphics.Textures;
using osu.Game.Beatmaps;
namespace osu.Game.Database
{
internal class OnlineWorkingBeatmap : WorkingBeatmap
{
private readonly TextureStore textures;
private readonly TrackManager tracks;
public OnlineWorkingBeatmap(BeatmapInfo beatmapInfo, TextureStore textures, TrackManager tracks) : base(beatmapInfo)
{
this.textures = textures;
this.tracks = tracks;
}
protected override Beatmap GetBeatmap()
{
return new Beatmap();
}
protected override Texture GetBackground()
{
return textures.Get(BeatmapInfo.OnlineInfo.Covers.FirstOrDefault());
}
protected override Track GetTrack()
{
return tracks.Get(BeatmapInfo.OnlineInfo.Preview);
}
}
}

View File

@ -180,11 +180,11 @@ namespace osu.Game.Overlays.Direct
Margin = new MarginPadding { Top = vertical_padding, Right = vertical_padding },
Children = new[]
{
new Statistic(FontAwesome.fa_play_circle, SetInfo.Beatmaps.FirstOrDefault()?.OnlineInfo.PlayCount ?? 0)
new Statistic(FontAwesome.fa_play_circle, SetInfo.OnlineInfo?.PlayCount ?? 0)
{
Margin = new MarginPadding { Right = 1 },
},
new Statistic(FontAwesome.fa_heart, SetInfo.Beatmaps.FirstOrDefault()?.OnlineInfo.FavouriteCount ?? 0),
new Statistic(FontAwesome.fa_heart, SetInfo.OnlineInfo?.FavouriteCount ?? 0),
},
},
};

View File

@ -104,11 +104,11 @@ namespace osu.Game.Overlays.Direct
Margin = new MarginPadding { Right = height - vertical_padding * 2 + vertical_padding },
Children = new Drawable[]
{
new Statistic(FontAwesome.fa_play_circle, SetInfo.Beatmaps.FirstOrDefault()?.OnlineInfo.PlayCount ?? 0)
new Statistic(FontAwesome.fa_play_circle, SetInfo.OnlineInfo?.PlayCount ?? 0)
{
Margin = new MarginPadding { Right = 1 },
},
new Statistic(FontAwesome.fa_heart, SetInfo.Beatmaps.FirstOrDefault()?.OnlineInfo.FavouriteCount ?? 0),
new Statistic(FontAwesome.fa_heart, SetInfo.OnlineInfo?.FavouriteCount ?? 0),
new FillFlowContainer
{
Anchor = Anchor.TopRight,

View File

@ -4,6 +4,7 @@
using System.Collections.Generic;
using System.Linq;
using OpenTK;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
@ -36,7 +37,7 @@ namespace osu.Game.Overlays.Direct
protected Drawable GetBackground(TextureStore textures)
{
return new AsyncLoadWrapper(new BeatmapBackgroundSprite(new OnlineWorkingBeatmap(SetInfo.Beatmaps.FirstOrDefault(), textures, null))
return new AsyncLoadWrapper(new BeatmapSetBackgroundSprite(SetInfo)
{
FillMode = FillMode.Fill,
OnLoadComplete = d => d.FadeInFromZero(400, EasingTypes.Out),
@ -84,5 +85,22 @@ namespace osu.Game.Overlays.Direct
Value = value;
}
}
private class BeatmapSetBackgroundSprite : Sprite
{
private readonly BeatmapSetInfo set;
public BeatmapSetBackgroundSprite(BeatmapSetInfo set)
{
this.set = set;
}
[BackgroundDependencyLoader]
private void load(TextureStore textures)
{
if (set.OnlineInfo?.Covers.FirstOrDefault() != null)
Texture = textures.Get(set.OnlineInfo.Covers.First());
}
}
}
}

View File

@ -445,11 +445,11 @@
<Compile Include="Overlays\Direct\DirectPanel.cs" />
<Compile Include="Overlays\Direct\DirectGridPanel.cs" />
<Compile Include="Overlays\Direct\DirectListPanel.cs" />
<Compile Include="Database\OnlineWorkingBeatmap.cs" />
<Compile Include="Database\BeatmapOnlineInfo.cs" />
<Compile Include="Overlays\Direct\SlimEnumDropdown.cs" />
<Compile Include="Graphics\Containers\ReverseDepthFillFlowContainer.cs" />
<Compile Include="Database\RankStatus.cs" />
<Compile Include="Database\BeatmapSetOnlineInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\osu-framework\osu.Framework\osu.Framework.csproj">