Add beatmap sample override support

This commit is contained in:
Dean Herbert 2018-03-16 00:14:29 +09:00
parent 9a0fc9e29a
commit d1c2aa71d0
6 changed files with 19 additions and 13 deletions

View File

@ -68,7 +68,7 @@ namespace osu.Game.Tests.Visual
IDatabaseContextFactory factory = new SingletonContextFactory(new OsuDbContext()); IDatabaseContextFactory factory = new SingletonContextFactory(new OsuDbContext());
dependencies.Cache(rulesets = new RulesetStore(factory)); dependencies.Cache(rulesets = new RulesetStore(factory));
dependencies.Cache(manager = new BeatmapManager(storage, factory, rulesets, null) dependencies.Cache(manager = new BeatmapManager(storage, factory, rulesets, null, null)
{ {
DefaultBeatmap = defaultBeatmap = game.Beatmap.Default DefaultBeatmap = defaultBeatmap = game.Beatmap.Default
}); });

View File

@ -8,6 +8,7 @@ using System.Linq;
using System.Linq.Expressions; using System.Linq.Expressions;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using osu.Framework.Audio;
using osu.Framework.Extensions; using osu.Framework.Extensions;
using osu.Framework.Logging; using osu.Framework.Logging;
using osu.Framework.Platform; using osu.Framework.Platform;
@ -55,6 +56,8 @@ namespace osu.Game.Beatmaps
private readonly APIAccess api; private readonly APIAccess api;
private readonly AudioManager audioManager;
private readonly List<DownloadBeatmapSetRequest> currentDownloads = new List<DownloadBeatmapSetRequest>(); private readonly List<DownloadBeatmapSetRequest> currentDownloads = new List<DownloadBeatmapSetRequest>();
/// <summary> /// <summary>
@ -62,7 +65,7 @@ namespace osu.Game.Beatmaps
/// </summary> /// </summary>
public Func<Storage> GetStableStorage { private get; set; } public Func<Storage> GetStableStorage { private get; set; }
public BeatmapManager(Storage storage, IDatabaseContextFactory contextFactory, RulesetStore rulesets, APIAccess api, IIpcHost importHost = null) public BeatmapManager(Storage storage, IDatabaseContextFactory contextFactory, RulesetStore rulesets, APIAccess api, AudioManager audioManager, IIpcHost importHost = null)
: base(storage, contextFactory, new BeatmapStore(contextFactory), importHost) : base(storage, contextFactory, new BeatmapStore(contextFactory), importHost)
{ {
beatmaps = (BeatmapStore)ModelStore; beatmaps = (BeatmapStore)ModelStore;
@ -71,6 +74,7 @@ namespace osu.Game.Beatmaps
this.rulesets = rulesets; this.rulesets = rulesets;
this.api = api; this.api = api;
this.audioManager = audioManager;
} }
protected override void Populate(BeatmapSetInfo model, ArchiveReader archive) protected override void Populate(BeatmapSetInfo model, ArchiveReader archive)
@ -217,7 +221,7 @@ namespace osu.Game.Beatmaps
if (beatmapInfo.Metadata == null) if (beatmapInfo.Metadata == null)
beatmapInfo.Metadata = beatmapInfo.BeatmapSet.Metadata; beatmapInfo.Metadata = beatmapInfo.BeatmapSet.Metadata;
WorkingBeatmap working = new BeatmapManagerWorkingBeatmap(Files.Store, beatmapInfo); WorkingBeatmap working = new BeatmapManagerWorkingBeatmap(Files.Store, beatmapInfo, audioManager);
previous?.TransferTo(working); previous?.TransferTo(working);

View File

@ -4,6 +4,7 @@
using System; using System;
using System.IO; using System.IO;
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.IO.Stores;
@ -20,11 +21,13 @@ namespace osu.Game.Beatmaps
protected class BeatmapManagerWorkingBeatmap : WorkingBeatmap protected class BeatmapManagerWorkingBeatmap : WorkingBeatmap
{ {
private readonly IResourceStore<byte[]> store; private readonly IResourceStore<byte[]> store;
private readonly AudioManager audioManager;
public BeatmapManagerWorkingBeatmap(IResourceStore<byte[]> store, BeatmapInfo beatmapInfo) public BeatmapManagerWorkingBeatmap(IResourceStore<byte[]> store, BeatmapInfo beatmapInfo, AudioManager audioManager)
: base(beatmapInfo) : base(beatmapInfo)
{ {
this.store = store; this.store = store;
this.audioManager = audioManager;
} }
protected override Beatmap GetBeatmap() protected override Beatmap GetBeatmap()
@ -107,8 +110,7 @@ namespace osu.Game.Beatmaps
Skin skin; Skin skin;
try try
{ {
// todo: this needs an AudioManager skin = new BeatmapSkin(BeatmapInfo, store, audioManager);
skin = new BeatmapSkin(BeatmapInfo, store);
} }
catch (Exception e) catch (Exception e)
{ {

View File

@ -113,7 +113,7 @@ namespace osu.Game
dependencies.Cache(RulesetStore = new RulesetStore(contextFactory)); dependencies.Cache(RulesetStore = new RulesetStore(contextFactory));
dependencies.Cache(FileStore = new FileStore(contextFactory, Host.Storage)); dependencies.Cache(FileStore = new FileStore(contextFactory, Host.Storage));
dependencies.Cache(BeatmapManager = new BeatmapManager(Host.Storage, contextFactory, RulesetStore, api, Host)); dependencies.Cache(BeatmapManager = new BeatmapManager(Host.Storage, contextFactory, RulesetStore, api, Audio, Host));
dependencies.Cache(ScoreStore = new ScoreStore(Host.Storage, contextFactory, Host, BeatmapManager, RulesetStore)); dependencies.Cache(ScoreStore = new ScoreStore(Host.Storage, contextFactory, Host, BeatmapManager, RulesetStore));
dependencies.Cache(KeyBindingStore = new KeyBindingStore(contextFactory, RulesetStore)); dependencies.Cache(KeyBindingStore = new KeyBindingStore(contextFactory, RulesetStore));
dependencies.Cache(SettingsStore = new SettingsStore(contextFactory)); dependencies.Cache(SettingsStore = new SettingsStore(contextFactory));

View File

@ -2,6 +2,7 @@
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System.IO; using System.IO;
using osu.Framework.Audio;
using osu.Framework.Graphics.Textures; using osu.Framework.Graphics.Textures;
using osu.Framework.IO.Stores; using osu.Framework.IO.Stores;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
@ -10,13 +11,12 @@ namespace osu.Game.Skinning
{ {
public class BeatmapSkin : LegacySkin public class BeatmapSkin : LegacySkin
{ {
public BeatmapSkin(BeatmapInfo beatmap, IResourceStore<byte[]> storage) public BeatmapSkin(BeatmapInfo beatmap, IResourceStore<byte[]> storage, AudioManager audioManager)
: base(new SkinInfo { Name = beatmap.ToString(), Creator = beatmap.Metadata.Author.ToString() }) : base(new SkinInfo { Name = beatmap.ToString(), Creator = beatmap.Metadata.Author.ToString() })
{ {
storage = new LegacySkinResourceStore<BeatmapSetFileInfo>(beatmap.BeatmapSet, storage); storage = new LegacySkinResourceStore<BeatmapSetFileInfo>(beatmap.BeatmapSet, storage);
// todo: sample support Samples = audioManager.GetSampleManager(storage);
// samples = audioManager.GetSampleManager(storage);
Textures = new TextureStore(new RawTextureLoaderStore(storage)); Textures = new TextureStore(new RawTextureLoaderStore(storage));

View File

@ -18,13 +18,13 @@ namespace osu.Game.Skinning
{ {
protected TextureStore Textures; protected TextureStore Textures;
private readonly SampleManager samples; protected SampleManager Samples;
public LegacySkin(SkinInfo skin, IResourceStore<byte[]> storage, AudioManager audioManager) public LegacySkin(SkinInfo skin, IResourceStore<byte[]> storage, AudioManager audioManager)
: this(skin) : this(skin)
{ {
storage = new LegacySkinResourceStore<SkinFileInfo>(skin, storage); storage = new LegacySkinResourceStore<SkinFileInfo>(skin, storage);
samples = audioManager.GetSampleManager(storage); Samples = audioManager.GetSampleManager(storage);
Textures = new TextureStore(new RawTextureLoaderStore(storage)); Textures = new TextureStore(new RawTextureLoaderStore(storage));
Stream stream = storage.GetStream("skin.ini"); Stream stream = storage.GetStream("skin.ini");
@ -63,7 +63,7 @@ namespace osu.Game.Skinning
return new Sprite { Texture = texture }; return new Sprite { Texture = texture };
} }
public override SampleChannel GetSample(string sampleName) => samples.Get(sampleName); public override SampleChannel GetSample(string sampleName) => Samples.Get(sampleName);
protected class LegacySkinResourceStore<T> : IResourceStore<byte[]> protected class LegacySkinResourceStore<T> : IResourceStore<byte[]>
where T : INamedFileInfo where T : INamedFileInfo