mirror of
https://github.com/ppy/osu.git
synced 2025-01-28 18:12:56 +08:00
Centralise access to WorkingBeatmaps.
They can now only be instantiated from BeatmapDatabase and are abstract (to avoid misuse).
This commit is contained in:
parent
355bbb6324
commit
3a89348413
@ -8,6 +8,7 @@ using osu.Game.Beatmaps;
|
|||||||
using osu.Game.Beatmaps.Formats;
|
using osu.Game.Beatmaps.Formats;
|
||||||
using OpenTK;
|
using OpenTK;
|
||||||
using osu.Framework.Graphics.Sprites;
|
using osu.Framework.Graphics.Sprites;
|
||||||
|
using osu.Game.Beatmaps.IO;
|
||||||
using osu.Game.Database;
|
using osu.Game.Database;
|
||||||
using osu.Game.Modes;
|
using osu.Game.Modes;
|
||||||
using osu.Game.Modes.Objects;
|
using osu.Game.Modes.Objects;
|
||||||
@ -72,7 +73,7 @@ namespace osu.Desktop.VisualTests.Tests
|
|||||||
|
|
||||||
decoder.Process(b);
|
decoder.Process(b);
|
||||||
|
|
||||||
beatmap = new WorkingBeatmap(b);
|
beatmap = new TestWorkingBeatmap(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
Add(new Box
|
Add(new Box
|
||||||
@ -90,5 +91,16 @@ namespace osu.Desktop.VisualTests.Tests
|
|||||||
Beatmap = beatmap
|
Beatmap = beatmap
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class TestWorkingBeatmap : WorkingBeatmap
|
||||||
|
{
|
||||||
|
public TestWorkingBeatmap(Beatmap beatmap)
|
||||||
|
: base(beatmap.BeatmapInfo, beatmap.BeatmapInfo.BeatmapSet)
|
||||||
|
{
|
||||||
|
Beatmap = beatmap;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override ArchiveReader GetReader() => null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -118,7 +118,7 @@ namespace osu.Game.Tests.Beatmaps.IO
|
|||||||
|
|
||||||
Assert.IsTrue(set.Beatmaps.Count > 0);
|
Assert.IsTrue(set.Beatmaps.Count > 0);
|
||||||
|
|
||||||
var beatmap = osu.Dependencies.Get<BeatmapDatabase>().GetBeatmap(set.Beatmaps.First(b => b.Mode == PlayMode.Osu));
|
var beatmap = osu.Dependencies.Get<BeatmapDatabase>().GetWorkingBeatmap(set.Beatmaps.First(b => b.Mode == PlayMode.Osu))?.Beatmap;
|
||||||
|
|
||||||
Assert.IsTrue(beatmap.HitObjects.Count > 0);
|
Assert.IsTrue(beatmap.HitObjects.Count > 0);
|
||||||
}
|
}
|
||||||
|
@ -11,16 +11,22 @@ using osu.Game.Database;
|
|||||||
|
|
||||||
namespace osu.Game.Beatmaps
|
namespace osu.Game.Beatmaps
|
||||||
{
|
{
|
||||||
public class WorkingBeatmap : IDisposable
|
public abstract class WorkingBeatmap : IDisposable
|
||||||
{
|
{
|
||||||
public readonly BeatmapInfo BeatmapInfo;
|
public readonly BeatmapInfo BeatmapInfo;
|
||||||
|
|
||||||
public readonly BeatmapSetInfo BeatmapSetInfo;
|
public readonly BeatmapSetInfo BeatmapSetInfo;
|
||||||
private readonly BeatmapDatabase database;
|
|
||||||
|
|
||||||
public readonly bool WithStoryboard;
|
public readonly bool WithStoryboard;
|
||||||
|
|
||||||
private ArchiveReader getReader() => database?.GetReader(BeatmapSetInfo);
|
protected abstract ArchiveReader GetReader();
|
||||||
|
|
||||||
|
protected WorkingBeatmap(BeatmapInfo beatmapInfo, BeatmapSetInfo beatmapSetInfo, bool withStoryboard = false)
|
||||||
|
{
|
||||||
|
BeatmapInfo = beatmapInfo;
|
||||||
|
BeatmapSetInfo = beatmapSetInfo;
|
||||||
|
WithStoryboard = withStoryboard;
|
||||||
|
}
|
||||||
|
|
||||||
private Texture background;
|
private Texture background;
|
||||||
private object backgroundLock = new object();
|
private object backgroundLock = new object();
|
||||||
@ -36,7 +42,7 @@ namespace osu.Game.Beatmaps
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using (var reader = getReader())
|
using (var reader = GetReader())
|
||||||
background = new TextureStore(new RawTextureLoaderStore(reader), false).Get(BeatmapInfo.Metadata.BackgroundFile);
|
background = new TextureStore(new RawTextureLoaderStore(reader), false).Get(BeatmapInfo.Metadata.BackgroundFile);
|
||||||
}
|
}
|
||||||
catch { }
|
catch { }
|
||||||
@ -59,7 +65,7 @@ namespace osu.Game.Beatmaps
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using (var reader = getReader())
|
using (var reader = GetReader())
|
||||||
{
|
{
|
||||||
BeatmapDecoder decoder;
|
BeatmapDecoder decoder;
|
||||||
using (var stream = new StreamReader(reader.GetStream(BeatmapInfo.Path)))
|
using (var stream = new StreamReader(reader.GetStream(BeatmapInfo.Path)))
|
||||||
@ -95,7 +101,7 @@ namespace osu.Game.Beatmaps
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
//store a reference to the reader as we may continue accessing the stream in the background.
|
//store a reference to the reader as we may continue accessing the stream in the background.
|
||||||
trackReader = getReader();
|
trackReader = GetReader();
|
||||||
var trackData = trackReader?.GetStream(BeatmapInfo.Metadata.AudioFile);
|
var trackData = trackReader?.GetStream(BeatmapInfo.Metadata.AudioFile);
|
||||||
if (trackData != null)
|
if (trackData != null)
|
||||||
track = new TrackBass(trackData);
|
track = new TrackBass(trackData);
|
||||||
@ -110,21 +116,6 @@ namespace osu.Game.Beatmaps
|
|||||||
|
|
||||||
public bool TrackLoaded => track != null;
|
public bool TrackLoaded => track != null;
|
||||||
|
|
||||||
public WorkingBeatmap(Beatmap beatmap)
|
|
||||||
{
|
|
||||||
this.beatmap = beatmap;
|
|
||||||
BeatmapInfo = beatmap.BeatmapInfo;
|
|
||||||
BeatmapSetInfo = beatmap.BeatmapInfo.BeatmapSet;
|
|
||||||
}
|
|
||||||
|
|
||||||
public WorkingBeatmap(BeatmapInfo beatmapInfo, BeatmapSetInfo beatmapSetInfo, BeatmapDatabase database, bool withStoryboard = false)
|
|
||||||
{
|
|
||||||
BeatmapInfo = beatmapInfo;
|
|
||||||
BeatmapSetInfo = beatmapSetInfo;
|
|
||||||
this.database = database;
|
|
||||||
this.WithStoryboard = withStoryboard;
|
|
||||||
}
|
|
||||||
|
|
||||||
private bool isDisposed;
|
private bool isDisposed;
|
||||||
|
|
||||||
protected virtual void Dispose(bool disposing)
|
protected virtual void Dispose(bool disposing)
|
||||||
|
@ -183,19 +183,13 @@ namespace osu.Game.Database
|
|||||||
if (beatmapInfo.Metadata == null)
|
if (beatmapInfo.Metadata == null)
|
||||||
beatmapInfo.Metadata = beatmapSetInfo.Metadata;
|
beatmapInfo.Metadata = beatmapSetInfo.Metadata;
|
||||||
|
|
||||||
var working = new WorkingBeatmap(beatmapInfo, beatmapSetInfo, this, withStoryboard);
|
WorkingBeatmap working = new DatabaseWorkingBeatmap(this, beatmapInfo, beatmapSetInfo, withStoryboard);
|
||||||
|
|
||||||
previous?.TransferTo(working);
|
previous?.TransferTo(working);
|
||||||
|
|
||||||
return working;
|
return working;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Beatmap GetBeatmap(BeatmapInfo beatmapInfo)
|
|
||||||
{
|
|
||||||
using (WorkingBeatmap data = GetWorkingBeatmap(beatmapInfo))
|
|
||||||
return data.Beatmap;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TableQuery<T> Query<T>() where T : class
|
public TableQuery<T> Query<T>() where T : class
|
||||||
{
|
{
|
||||||
return connection.Table<T>();
|
return connection.Table<T>();
|
||||||
@ -237,5 +231,20 @@ namespace osu.Game.Database
|
|||||||
else
|
else
|
||||||
connection.Update(record);
|
connection.Update(record);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool Exists(BeatmapSetInfo beatmapSet) => storage.Exists(beatmapSet.Path);
|
||||||
|
|
||||||
|
private class DatabaseWorkingBeatmap : WorkingBeatmap
|
||||||
|
{
|
||||||
|
private readonly BeatmapDatabase database;
|
||||||
|
|
||||||
|
public DatabaseWorkingBeatmap(BeatmapDatabase database, BeatmapInfo beatmapInfo, BeatmapSetInfo beatmapSetInfo, bool withStoryboard = false)
|
||||||
|
: base(beatmapInfo, beatmapSetInfo, withStoryboard)
|
||||||
|
{
|
||||||
|
this.database = database;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override ArchiveReader GetReader() => database?.GetReader(BeatmapSetInfo);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -87,8 +87,7 @@ namespace osu.Game.Database
|
|||||||
|
|
||||||
internal void ComputeDifficulty(BeatmapDatabase database)
|
internal void ComputeDifficulty(BeatmapDatabase database)
|
||||||
{
|
{
|
||||||
WorkingBeatmap wb = new WorkingBeatmap(this, BeatmapSet, database);
|
StarDifficulty = (float)Ruleset.GetRuleset(Mode).CreateDifficultyCalculator(database.GetWorkingBeatmap(this).Beatmap).GetDifficulty();
|
||||||
StarDifficulty = (float)Ruleset.GetRuleset(Mode).CreateDifficultyCalculator(wb.Beatmap).GetDifficulty();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Equals(BeatmapInfo other)
|
public bool Equals(BeatmapInfo other)
|
||||||
|
@ -328,9 +328,7 @@ namespace osu.Game.Screens.Select
|
|||||||
b.ComputeDifficulty(database);
|
b.ComputeDifficulty(database);
|
||||||
beatmapSet.Beatmaps = beatmapSet.Beatmaps.OrderBy(b => b.StarDifficulty).ToList();
|
beatmapSet.Beatmaps = beatmapSet.Beatmaps.OrderBy(b => b.StarDifficulty).ToList();
|
||||||
|
|
||||||
var beatmap = new WorkingBeatmap(beatmapSet.Beatmaps.FirstOrDefault(), beatmapSet, database);
|
var group = new BeatmapGroup(database.GetWorkingBeatmap(beatmapSet.Beatmaps.FirstOrDefault()))
|
||||||
|
|
||||||
var group = new BeatmapGroup(beatmap)
|
|
||||||
{
|
{
|
||||||
SelectionChanged = selectionChanged,
|
SelectionChanged = selectionChanged,
|
||||||
StartRequested = b => footer.StartButton.TriggerClick()
|
StartRequested = b => footer.StartButton.TriggerClick()
|
||||||
|
Loading…
Reference in New Issue
Block a user