mirror of
https://github.com/ppy/osu.git
synced 2025-02-21 06:52:55 +08:00
Move BeatmapManagerWorkingBeatmap to its own file
This commit is contained in:
parent
fb6dc922c6
commit
db654004b7
@ -9,31 +9,26 @@ using System.Linq.Expressions;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Ionic.Zip;
|
using Ionic.Zip;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using osu.Framework.Audio.Track;
|
|
||||||
using osu.Framework.Extensions;
|
using osu.Framework.Extensions;
|
||||||
using osu.Framework.Graphics.Textures;
|
|
||||||
using osu.Framework.IO.Stores;
|
|
||||||
using osu.Framework.Logging;
|
using osu.Framework.Logging;
|
||||||
using osu.Framework.Platform;
|
using osu.Framework.Platform;
|
||||||
using osu.Game.Beatmaps.Formats;
|
using osu.Game.Beatmaps.Formats;
|
||||||
using osu.Game.Beatmaps.IO;
|
using osu.Game.Beatmaps.IO;
|
||||||
using osu.Game.Database;
|
using osu.Game.Database;
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
using osu.Game.Graphics.Textures;
|
|
||||||
using osu.Game.IO;
|
using osu.Game.IO;
|
||||||
using osu.Game.IPC;
|
using osu.Game.IPC;
|
||||||
using osu.Game.Online.API;
|
using osu.Game.Online.API;
|
||||||
using osu.Game.Online.API.Requests;
|
using osu.Game.Online.API.Requests;
|
||||||
using osu.Game.Overlays.Notifications;
|
using osu.Game.Overlays.Notifications;
|
||||||
using osu.Game.Rulesets;
|
using osu.Game.Rulesets;
|
||||||
using osu.Game.Storyboards;
|
|
||||||
|
|
||||||
namespace osu.Game.Beatmaps
|
namespace osu.Game.Beatmaps
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Handles the storage and retrieval of Beatmaps/WorkingBeatmaps.
|
/// Handles the storage and retrieval of Beatmaps/WorkingBeatmaps.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class BeatmapManager
|
public partial class BeatmapManager
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Fired when a new <see cref="BeatmapSetInfo"/> becomes available in the database.
|
/// Fired when a new <see cref="BeatmapSetInfo"/> becomes available in the database.
|
||||||
@ -627,86 +622,6 @@ namespace osu.Game.Beatmaps
|
|||||||
return store;
|
return store;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected class BeatmapManagerWorkingBeatmap : WorkingBeatmap
|
|
||||||
{
|
|
||||||
private readonly IResourceStore<byte[]> store;
|
|
||||||
|
|
||||||
public BeatmapManagerWorkingBeatmap(IResourceStore<byte[]> store, BeatmapInfo beatmapInfo)
|
|
||||||
: base(beatmapInfo)
|
|
||||||
{
|
|
||||||
this.store = store;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override Beatmap GetBeatmap()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
using (var stream = new StreamReader(store.GetStream(getPathForFile(BeatmapInfo.Path))))
|
|
||||||
{
|
|
||||||
Decoder decoder = Decoder.GetDecoder(stream);
|
|
||||||
return decoder.DecodeBeatmap(stream);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private string getPathForFile(string filename) => BeatmapSetInfo.Files.First(f => string.Equals(f.Filename, filename, StringComparison.InvariantCultureIgnoreCase)).FileInfo.StoragePath;
|
|
||||||
|
|
||||||
protected override Texture GetBackground()
|
|
||||||
{
|
|
||||||
if (Metadata?.BackgroundFile == null)
|
|
||||||
return null;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
return new LargeTextureStore(new RawTextureLoaderStore(store)).Get(getPathForFile(Metadata.BackgroundFile));
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override Track GetTrack()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var trackData = store.GetStream(getPathForFile(Metadata.AudioFile));
|
|
||||||
return trackData == null ? null : new TrackBass(trackData);
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
return new TrackVirtual();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override Waveform GetWaveform() => new Waveform(store.GetStream(getPathForFile(Metadata.AudioFile)));
|
|
||||||
|
|
||||||
protected override Storyboard GetStoryboard()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
using (var beatmap = new StreamReader(store.GetStream(getPathForFile(BeatmapInfo.Path))))
|
|
||||||
{
|
|
||||||
Decoder decoder = Decoder.GetDecoder(beatmap);
|
|
||||||
|
|
||||||
if (BeatmapSetInfo?.StoryboardFile == null)
|
|
||||||
return decoder.GetStoryboardDecoder().DecodeStoryboard(beatmap);
|
|
||||||
|
|
||||||
using (var storyboard = new StreamReader(store.GetStream(getPathForFile(BeatmapSetInfo.StoryboardFile))))
|
|
||||||
return decoder.GetStoryboardDecoder().DecodeStoryboard(beatmap, storyboard);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
return new Storyboard();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool StableInstallationAvailable => GetStableStorage?.Invoke() != null;
|
public bool StableInstallationAvailable => GetStableStorage?.Invoke() != null;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
95
osu.Game/Beatmaps/BeatmapManager_WorkingBeatmap.cs
Normal file
95
osu.Game/Beatmaps/BeatmapManager_WorkingBeatmap.cs
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using osu.Framework.Audio.Track;
|
||||||
|
using osu.Framework.Graphics.Textures;
|
||||||
|
using osu.Framework.IO.Stores;
|
||||||
|
using osu.Game.Beatmaps.Formats;
|
||||||
|
using osu.Game.Graphics.Textures;
|
||||||
|
using osu.Game.Storyboards;
|
||||||
|
|
||||||
|
namespace osu.Game.Beatmaps
|
||||||
|
{
|
||||||
|
public partial class BeatmapManager
|
||||||
|
{
|
||||||
|
protected class BeatmapManagerWorkingBeatmap : WorkingBeatmap
|
||||||
|
{
|
||||||
|
private readonly IResourceStore<byte[]> store;
|
||||||
|
|
||||||
|
public BeatmapManagerWorkingBeatmap(IResourceStore<byte[]> store, BeatmapInfo beatmapInfo)
|
||||||
|
: base(beatmapInfo)
|
||||||
|
{
|
||||||
|
this.store = store;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override Beatmap GetBeatmap()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (var stream = new StreamReader(store.GetStream(getPathForFile(BeatmapInfo.Path))))
|
||||||
|
{
|
||||||
|
Decoder decoder = Decoder.GetDecoder(stream);
|
||||||
|
return decoder.DecodeBeatmap(stream);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private string getPathForFile(string filename) => BeatmapSetInfo.Files.First(f => string.Equals(f.Filename, filename, StringComparison.InvariantCultureIgnoreCase)).FileInfo.StoragePath;
|
||||||
|
|
||||||
|
protected override Texture GetBackground()
|
||||||
|
{
|
||||||
|
if (Metadata?.BackgroundFile == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return new LargeTextureStore(new RawTextureLoaderStore(store)).Get(getPathForFile(Metadata.BackgroundFile));
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override Track GetTrack()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var trackData = store.GetStream(getPathForFile(Metadata.AudioFile));
|
||||||
|
return trackData == null ? null : new TrackBass(trackData);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return new TrackVirtual();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override Waveform GetWaveform() => new Waveform(store.GetStream(getPathForFile(Metadata.AudioFile)));
|
||||||
|
|
||||||
|
protected override Storyboard GetStoryboard()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (var beatmap = new StreamReader(store.GetStream(getPathForFile(BeatmapInfo.Path))))
|
||||||
|
{
|
||||||
|
Decoder decoder = Decoder.GetDecoder(beatmap);
|
||||||
|
|
||||||
|
if (BeatmapSetInfo?.StoryboardFile == null)
|
||||||
|
return decoder.GetStoryboardDecoder().DecodeStoryboard(beatmap);
|
||||||
|
|
||||||
|
using (var storyboard = new StreamReader(store.GetStream(getPathForFile(BeatmapSetInfo.StoryboardFile))))
|
||||||
|
return decoder.GetStoryboardDecoder().DecodeStoryboard(beatmap, storyboard);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return new Storyboard();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -248,6 +248,7 @@
|
|||||||
<Compile Include="Beatmaps\BeatmapDifficulty.cs" />
|
<Compile Include="Beatmaps\BeatmapDifficulty.cs" />
|
||||||
<Compile Include="Beatmaps\BeatmapInfo.cs" />
|
<Compile Include="Beatmaps\BeatmapInfo.cs" />
|
||||||
<Compile Include="Beatmaps\BeatmapManager.cs" />
|
<Compile Include="Beatmaps\BeatmapManager.cs" />
|
||||||
|
<Compile Include="Beatmaps\BeatmapManager_WorkingBeatmap.cs" />
|
||||||
<Compile Include="Beatmaps\BeatmapMetadata.cs" />
|
<Compile Include="Beatmaps\BeatmapMetadata.cs" />
|
||||||
<Compile Include="Beatmaps\BeatmapMetrics.cs" />
|
<Compile Include="Beatmaps\BeatmapMetrics.cs" />
|
||||||
<Compile Include="Beatmaps\BeatmapOnlineInfo.cs" />
|
<Compile Include="Beatmaps\BeatmapOnlineInfo.cs" />
|
||||||
|
Loading…
Reference in New Issue
Block a user