mirror of
https://github.com/ppy/osu.git
synced 2025-01-28 00:02:56 +08:00
Expose resources to beatmaps in a saner way
This commit is contained in:
parent
7c804be4d3
commit
0ffbe12fcc
@ -16,6 +16,7 @@ using osu.Framework.Audio.Track;
|
|||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Extensions;
|
using osu.Framework.Extensions;
|
||||||
using osu.Framework.Graphics.Textures;
|
using osu.Framework.Graphics.Textures;
|
||||||
|
using osu.Framework.IO.Stores;
|
||||||
using osu.Framework.Lists;
|
using osu.Framework.Lists;
|
||||||
using osu.Framework.Logging;
|
using osu.Framework.Logging;
|
||||||
using osu.Framework.Platform;
|
using osu.Framework.Platform;
|
||||||
@ -28,8 +29,8 @@ using osu.Game.Online.API;
|
|||||||
using osu.Game.Online.API.Requests;
|
using osu.Game.Online.API.Requests;
|
||||||
using osu.Game.Rulesets;
|
using osu.Game.Rulesets;
|
||||||
using osu.Game.Rulesets.Objects;
|
using osu.Game.Rulesets.Objects;
|
||||||
using osu.Game.Users;
|
|
||||||
using osu.Game.Skinning;
|
using osu.Game.Skinning;
|
||||||
|
using osu.Game.Users;
|
||||||
using Decoder = osu.Game.Beatmaps.Formats.Decoder;
|
using Decoder = osu.Game.Beatmaps.Formats.Decoder;
|
||||||
|
|
||||||
namespace osu.Game.Beatmaps
|
namespace osu.Game.Beatmaps
|
||||||
@ -38,7 +39,7 @@ namespace osu.Game.Beatmaps
|
|||||||
/// Handles the storage and retrieval of Beatmaps/WorkingBeatmaps.
|
/// Handles the storage and retrieval of Beatmaps/WorkingBeatmaps.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[ExcludeFromDynamicCompile]
|
[ExcludeFromDynamicCompile]
|
||||||
public partial class BeatmapManager : DownloadableArchiveModelManager<BeatmapSetInfo, BeatmapSetFileInfo>, IDisposable
|
public partial class BeatmapManager : DownloadableArchiveModelManager<BeatmapSetInfo, BeatmapSetFileInfo>, IDisposable, IBeatmapResourceProvider
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Fired when a single difficulty has been hidden.
|
/// Fired when a single difficulty has been hidden.
|
||||||
@ -71,6 +72,8 @@ namespace osu.Game.Beatmaps
|
|||||||
private readonly LargeTextureStore largeTextureStore;
|
private readonly LargeTextureStore largeTextureStore;
|
||||||
private readonly ITrackStore trackStore;
|
private readonly ITrackStore trackStore;
|
||||||
|
|
||||||
|
private readonly GameHost host;
|
||||||
|
|
||||||
[CanBeNull]
|
[CanBeNull]
|
||||||
private readonly BeatmapOnlineLookupQueue onlineLookupQueue;
|
private readonly BeatmapOnlineLookupQueue onlineLookupQueue;
|
||||||
|
|
||||||
@ -80,6 +83,7 @@ namespace osu.Game.Beatmaps
|
|||||||
{
|
{
|
||||||
this.rulesets = rulesets;
|
this.rulesets = rulesets;
|
||||||
this.audioManager = audioManager;
|
this.audioManager = audioManager;
|
||||||
|
this.host = host;
|
||||||
|
|
||||||
DefaultBeatmap = defaultBeatmap;
|
DefaultBeatmap = defaultBeatmap;
|
||||||
|
|
||||||
@ -302,7 +306,7 @@ namespace osu.Game.Beatmaps
|
|||||||
|
|
||||||
beatmapInfo.Metadata ??= beatmapInfo.BeatmapSet.Metadata;
|
beatmapInfo.Metadata ??= beatmapInfo.BeatmapSet.Metadata;
|
||||||
|
|
||||||
workingCache.Add(working = new BeatmapManagerWorkingBeatmap(Files.Store, largeTextureStore, trackStore, beatmapInfo, audioManager));
|
workingCache.Add(working = new BeatmapManagerWorkingBeatmap(beatmapInfo, this));
|
||||||
|
|
||||||
return working;
|
return working;
|
||||||
}
|
}
|
||||||
@ -492,6 +496,12 @@ namespace osu.Game.Beatmaps
|
|||||||
onlineLookupQueue?.Dispose();
|
onlineLookupQueue?.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TextureStore IBeatmapResourceProvider.LargeTextureStore => largeTextureStore;
|
||||||
|
ITrackStore IBeatmapResourceProvider.Tracks => trackStore;
|
||||||
|
AudioManager IBeatmapResourceProvider.AudioManager => audioManager;
|
||||||
|
IResourceStore<byte[]> IBeatmapResourceProvider.Files => Files.Store;
|
||||||
|
IResourceStore<TextureUpload> IBeatmapResourceProvider.CreateTextureLoaderStore(IResourceStore<byte[]> underlyingStore) => host.CreateTextureLoaderStore(underlyingStore);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A dummy WorkingBeatmap for the purpose of retrieving a beatmap for star difficulty calculation.
|
/// A dummy WorkingBeatmap for the purpose of retrieving a beatmap for star difficulty calculation.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -3,10 +3,8 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using osu.Framework.Audio;
|
|
||||||
using osu.Framework.Audio.Track;
|
using osu.Framework.Audio.Track;
|
||||||
using osu.Framework.Graphics.Textures;
|
using osu.Framework.Graphics.Textures;
|
||||||
using osu.Framework.IO.Stores;
|
|
||||||
using osu.Framework.Logging;
|
using osu.Framework.Logging;
|
||||||
using osu.Framework.Testing;
|
using osu.Framework.Testing;
|
||||||
using osu.Game.Beatmaps.Formats;
|
using osu.Game.Beatmaps.Formats;
|
||||||
@ -21,16 +19,12 @@ namespace osu.Game.Beatmaps
|
|||||||
[ExcludeFromDynamicCompile]
|
[ExcludeFromDynamicCompile]
|
||||||
private class BeatmapManagerWorkingBeatmap : WorkingBeatmap
|
private class BeatmapManagerWorkingBeatmap : WorkingBeatmap
|
||||||
{
|
{
|
||||||
private readonly IResourceStore<byte[]> store;
|
private readonly IBeatmapResourceProvider resources;
|
||||||
private readonly TextureStore textureStore;
|
|
||||||
private readonly ITrackStore trackStore;
|
|
||||||
|
|
||||||
public BeatmapManagerWorkingBeatmap(IResourceStore<byte[]> store, TextureStore textureStore, ITrackStore trackStore, BeatmapInfo beatmapInfo, AudioManager audioManager)
|
public BeatmapManagerWorkingBeatmap(BeatmapInfo beatmapInfo, IBeatmapResourceProvider resources)
|
||||||
: base(beatmapInfo, audioManager)
|
: base(beatmapInfo, resources?.AudioManager)
|
||||||
{
|
{
|
||||||
this.store = store;
|
this.resources = resources;
|
||||||
this.textureStore = textureStore;
|
|
||||||
this.trackStore = trackStore;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override IBeatmap GetBeatmap()
|
protected override IBeatmap GetBeatmap()
|
||||||
@ -40,7 +34,7 @@ namespace osu.Game.Beatmaps
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using (var stream = new LineBufferedReader(store.GetStream(getPathForFile(BeatmapInfo.Path))))
|
using (var stream = new LineBufferedReader(resources.Files.GetStream(getPathForFile(BeatmapInfo.Path))))
|
||||||
return Decoder.GetDecoder<Beatmap>(stream).Decode(stream);
|
return Decoder.GetDecoder<Beatmap>(stream).Decode(stream);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
@ -61,7 +55,7 @@ namespace osu.Game.Beatmaps
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return textureStore.Get(getPathForFile(Metadata.BackgroundFile));
|
return resources.LargeTextureStore.Get(getPathForFile(Metadata.BackgroundFile));
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
@ -77,7 +71,7 @@ namespace osu.Game.Beatmaps
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return trackStore.Get(getPathForFile(Metadata.AudioFile));
|
return resources.Tracks.Get(getPathForFile(Metadata.AudioFile));
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
@ -93,7 +87,7 @@ namespace osu.Game.Beatmaps
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var trackData = store.GetStream(getPathForFile(Metadata.AudioFile));
|
var trackData = resources.Files.GetStream(getPathForFile(Metadata.AudioFile));
|
||||||
return trackData == null ? null : new Waveform(trackData);
|
return trackData == null ? null : new Waveform(trackData);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
@ -109,7 +103,7 @@ namespace osu.Game.Beatmaps
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using (var stream = new LineBufferedReader(store.GetStream(getPathForFile(BeatmapInfo.Path))))
|
using (var stream = new LineBufferedReader(resources.Files.GetStream(getPathForFile(BeatmapInfo.Path))))
|
||||||
{
|
{
|
||||||
var decoder = Decoder.GetDecoder<Storyboard>(stream);
|
var decoder = Decoder.GetDecoder<Storyboard>(stream);
|
||||||
|
|
||||||
@ -118,7 +112,7 @@ namespace osu.Game.Beatmaps
|
|||||||
storyboard = decoder.Decode(stream);
|
storyboard = decoder.Decode(stream);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
using (var secondaryStream = new LineBufferedReader(store.GetStream(getPathForFile(BeatmapSetInfo.StoryboardFile))))
|
using (var secondaryStream = new LineBufferedReader(resources.Files.GetStream(getPathForFile(BeatmapSetInfo.StoryboardFile))))
|
||||||
storyboard = decoder.Decode(stream, secondaryStream);
|
storyboard = decoder.Decode(stream, secondaryStream);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -138,7 +132,7 @@ namespace osu.Game.Beatmaps
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return new LegacyBeatmapSkin(BeatmapInfo, store, AudioManager);
|
return new LegacyBeatmapSkin(BeatmapInfo, resources.Files, AudioManager);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
40
osu.Game/Beatmaps/IBeatmapResourceProvider.cs
Normal file
40
osu.Game/Beatmaps/IBeatmapResourceProvider.cs
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||||
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using osu.Framework.Audio;
|
||||||
|
using osu.Framework.Audio.Track;
|
||||||
|
using osu.Framework.Graphics.Textures;
|
||||||
|
using osu.Framework.IO.Stores;
|
||||||
|
|
||||||
|
namespace osu.Game.Beatmaps
|
||||||
|
{
|
||||||
|
public interface IBeatmapResourceProvider
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Retrieve a global large texture store, used for loading beatmap backgrounds.
|
||||||
|
/// </summary>
|
||||||
|
TextureStore LargeTextureStore { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Access a global track store for retrieving beatmap tracks from.
|
||||||
|
/// </summary>
|
||||||
|
ITrackStore Tracks { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Retrieve the game-wide audio manager.
|
||||||
|
/// </summary>
|
||||||
|
AudioManager AudioManager { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Access game-wide user files.
|
||||||
|
/// </summary>
|
||||||
|
IResourceStore<byte[]> Files { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Create a texture loader store based on an underlying data store.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="underlyingStore">The underlying provider of texture data (in arbitrary image formats).</param>
|
||||||
|
/// <returns>A texture loader store.</returns>
|
||||||
|
IResourceStore<TextureUpload> CreateTextureLoaderStore(IResourceStore<byte[]> underlyingStore);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user