1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-27 13:23:05 +08:00

Start introducing ILive

This commit is contained in:
Dean Herbert 2021-12-15 15:03:06 +09:00
parent 3152d2d8a0
commit 1d536fd0bc
6 changed files with 34 additions and 30 deletions

View File

@ -173,14 +173,14 @@ namespace osu.Game.Beatmaps
/// </summary> /// </summary>
/// <param name="query">The query.</param> /// <param name="query">The query.</param>
/// <returns>Results from the provided query.</returns> /// <returns>Results from the provided query.</returns>
public ILive<IEnumerable<BeatmapSetInfo>> QueryBeatmapSets(Expression<Func<BeatmapSetInfo, bool>> query) => beatmapModelManager.QueryBeatmapSets(query).ToLive(contextFactory); public List<ILive<BeatmapSetInfo>> QueryBeatmapSets(Expression<Func<BeatmapSetInfo, bool>> query) => beatmapModelManager.QueryBeatmapSets(query).ToLive();
/// <summary> /// <summary>
/// Perform a lookup query on available <see cref="BeatmapSetInfo"/>s. /// Perform a lookup query on available <see cref="BeatmapSetInfo"/>s.
/// </summary> /// </summary>
/// <param name="query">The query.</param> /// <param name="query">The query.</param>
/// <returns>The first result for the provided query, or null if no results were found.</returns> /// <returns>The first result for the provided query, or null if no results were found.</returns>
public BeatmapSetInfo? QueryBeatmapSet(Expression<Func<BeatmapSetInfo, bool>> query) => beatmapModelManager.QueryBeatmapSet(query); public ILive<BeatmapSetInfo>? QueryBeatmapSet(Expression<Func<BeatmapSetInfo, bool>> query) => beatmapModelManager.QueryBeatmapSet(query);
/// <summary> /// <summary>
/// Perform a lookup query on available <see cref="BeatmapInfo"/>s. /// Perform a lookup query on available <see cref="BeatmapInfo"/>s.

View File

@ -104,10 +104,10 @@ namespace osu.Game.Beatmaps
/// </summary> /// </summary>
/// <param name="query">The query.</param> /// <param name="query">The query.</param>
/// <returns>The first result for the provided query, or null if no results were found.</returns> /// <returns>The first result for the provided query, or null if no results were found.</returns>
public BeatmapSetInfo? QueryBeatmapSet(Expression<Func<BeatmapSetInfo, bool>> query) public ILive<BeatmapSetInfo>? QueryBeatmapSet(Expression<Func<BeatmapSetInfo, bool>> query)
{ {
using (var context = ContextFactory.CreateContext()) using (var context = ContextFactory.CreateContext())
return context.All<BeatmapSetInfo>().FirstOrDefault(query); // TODO: ?.ToLive(); return context.All<BeatmapSetInfo>().FirstOrDefault(query)?.ToLive();
} }
/// <summary> /// <summary>

View File

@ -437,7 +437,7 @@ namespace osu.Game
/// </remarks> /// </remarks>
public void PresentBeatmap(IBeatmapSetInfo beatmap, Predicate<BeatmapInfo> difficultyCriteria = null) public void PresentBeatmap(IBeatmapSetInfo beatmap, Predicate<BeatmapInfo> difficultyCriteria = null)
{ {
BeatmapSetInfo databasedSet = null; ILive<BeatmapSetInfo> databasedSet = null;
if (beatmap.OnlineID > 0) if (beatmap.OnlineID > 0)
databasedSet = BeatmapManager.QueryBeatmapSet(s => s.OnlineID == beatmap.OnlineID); databasedSet = BeatmapManager.QueryBeatmapSet(s => s.OnlineID == beatmap.OnlineID);
@ -453,27 +453,30 @@ namespace osu.Game
PerformFromScreen(screen => PerformFromScreen(screen =>
{ {
// Find beatmaps that match our predicate. databasedSet.PerformRead(set =>
var beatmaps = databasedSet.Beatmaps.Where(b => difficultyCriteria?.Invoke(b) ?? true).ToList();
// Use all beatmaps if predicate matched nothing
if (beatmaps.Count == 0)
beatmaps = databasedSet.Beatmaps.ToList();
// Prefer recommended beatmap if recommendations are available, else fallback to a sane selection.
var selection = difficultyRecommender.GetRecommendedBeatmap(beatmaps)
?? beatmaps.FirstOrDefault(b => b.Ruleset.Equals(Ruleset.Value))
?? beatmaps.First();
if (screen is IHandlePresentBeatmap presentableScreen)
{ {
presentableScreen.PresentBeatmap(BeatmapManager.GetWorkingBeatmap(selection), selection.Ruleset); // Find beatmaps that match our predicate.
} var beatmaps = set.Beatmaps.Where(b => difficultyCriteria?.Invoke(b) ?? true).ToList();
else
{ // Use all beatmaps if predicate matched nothing
Ruleset.Value = selection.Ruleset; if (beatmaps.Count == 0)
Beatmap.Value = BeatmapManager.GetWorkingBeatmap(selection); beatmaps = set.Beatmaps.ToList();
}
// Prefer recommended beatmap if recommendations are available, else fallback to a sane selection.
var selection = difficultyRecommender.GetRecommendedBeatmap(beatmaps)
?? beatmaps.FirstOrDefault(b => b.Ruleset.Equals(Ruleset.Value))
?? beatmaps.First();
if (screen is IHandlePresentBeatmap presentableScreen)
{
presentableScreen.PresentBeatmap(BeatmapManager.GetWorkingBeatmap(selection), selection.Ruleset);
}
else
{
Ruleset.Value = selection.Ruleset;
Beatmap.Value = BeatmapManager.GetWorkingBeatmap(selection);
}
});
}, validScreens: new[] { typeof(SongSelect), typeof(IHandlePresentBeatmap) }); }, validScreens: new[] { typeof(SongSelect), typeof(IHandlePresentBeatmap) });
} }

View File

@ -88,7 +88,6 @@ namespace osu.Game.Overlays
if (changes == null) if (changes == null)
{ {
beatmapSets.AddRange(sender); beatmapSets.AddRange(sender);
return;
} }
// beatmaps.ItemUpdated += set => Schedule(() => // beatmaps.ItemUpdated += set => Schedule(() =>

View File

@ -160,7 +160,8 @@ namespace osu.Game.Overlays.Settings.Sections.Maintenance
Action = () => Action = () =>
{ {
undeleteButton.Enabled.Value = false; undeleteButton.Enabled.Value = false;
Task.Run(() => beatmaps.Undelete(beatmaps.QueryBeatmapSets(b => b.DeletePending).ToList())).ContinueWith(t => Schedule(() => undeleteButton.Enabled.Value = true)); // TODO: reimplement similar to SkinManager?
// Task.Run(() => beatmaps.Undelete(beatmaps.QueryBeatmapSets(b => b.DeletePending).ToList())).ContinueWith(t => Schedule(() => undeleteButton.Enabled.Value = true));
} }
}, },
}); });

View File

@ -15,6 +15,7 @@ using osu.Framework.Screens;
using osu.Framework.Utils; using osu.Framework.Utils;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Configuration; using osu.Game.Configuration;
using osu.Game.Database;
using osu.Game.IO.Archives; using osu.Game.IO.Archives;
using osu.Game.Overlays; using osu.Game.Overlays;
using osu.Game.Screens.Backgrounds; using osu.Game.Screens.Backgrounds;
@ -90,7 +91,7 @@ namespace osu.Game.Screens.Menu
MenuMusic = config.GetBindable<bool>(OsuSetting.MenuMusic); MenuMusic = config.GetBindable<bool>(OsuSetting.MenuMusic);
seeya = audio.Samples.Get(SeeyaSampleName); seeya = audio.Samples.Get(SeeyaSampleName);
BeatmapSetInfo setInfo = null; ILive<BeatmapSetInfo> setInfo = null;
// if the user has requested not to play theme music, we should attempt to find a random beatmap from their collection. // if the user has requested not to play theme music, we should attempt to find a random beatmap from their collection.
if (!MenuMusic.Value) if (!MenuMusic.Value)
@ -100,7 +101,7 @@ namespace osu.Game.Screens.Menu
if (sets.Count > 0) if (sets.Count > 0)
{ {
setInfo = beatmaps.QueryBeatmapSet(s => s.ID == sets[RNG.Next(0, sets.Count - 1)].ID); setInfo = beatmaps.QueryBeatmapSet(s => s.ID == sets[RNG.Next(0, sets.Count - 1)].ID);
initialBeatmap = beatmaps.GetWorkingBeatmap(setInfo?.Beatmaps[0]); initialBeatmap = beatmaps.GetWorkingBeatmap(setInfo?.PerformRead(s => s.Beatmaps[0].ToLive()));
} }
} }
@ -130,7 +131,7 @@ namespace osu.Game.Screens.Menu
if (setInfo == null) if (setInfo == null)
return false; return false;
initialBeatmap = beatmaps.GetWorkingBeatmap(setInfo.Beatmaps[0]); initialBeatmap = beatmaps.GetWorkingBeatmap(setInfo.PerformRead(s => s.Beatmaps[0].ToLive()));
return UsingThemedIntro = initialBeatmap != null; return UsingThemedIntro = initialBeatmap != null;
} }