2020-06-21 16:02:09 +00:00
|
|
|
// 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 System;
|
|
|
|
using System.Collections.Generic;
|
2021-11-24 03:16:08 +00:00
|
|
|
using System.Diagnostics;
|
2020-06-21 16:02:09 +00:00
|
|
|
using System.IO;
|
|
|
|
using System.Linq;
|
2021-12-23 09:33:17 +00:00
|
|
|
using System.Threading;
|
2020-06-21 16:02:09 +00:00
|
|
|
using System.Threading.Tasks;
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Audio;
|
2020-12-21 06:14:32 +00:00
|
|
|
using osu.Framework.Graphics.Textures;
|
2020-06-21 16:02:09 +00:00
|
|
|
using osu.Framework.IO.Stores;
|
2020-11-13 09:19:07 +00:00
|
|
|
using osu.Framework.Testing;
|
2020-06-21 16:02:09 +00:00
|
|
|
using osu.Framework.Timing;
|
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
using osu.Game.Beatmaps.Formats;
|
2021-12-14 05:19:43 +00:00
|
|
|
using osu.Game.Database;
|
2020-06-21 16:02:09 +00:00
|
|
|
using osu.Game.IO;
|
2021-11-23 07:05:28 +00:00
|
|
|
using osu.Game.Models;
|
2020-06-21 16:02:09 +00:00
|
|
|
using osu.Game.Rulesets;
|
2020-11-13 09:19:07 +00:00
|
|
|
using osu.Game.Rulesets.Objects;
|
|
|
|
using osu.Game.Screens.Ranking;
|
2020-06-21 16:02:09 +00:00
|
|
|
using osu.Game.Skinning;
|
|
|
|
using osu.Game.Storyboards;
|
|
|
|
using osu.Game.Tests.Visual;
|
|
|
|
|
2020-06-21 16:20:36 +00:00
|
|
|
namespace osu.Game.Tests.Beatmaps
|
2020-06-21 16:02:09 +00:00
|
|
|
{
|
2020-11-13 09:19:07 +00:00
|
|
|
[HeadlessTest]
|
2020-12-21 06:14:32 +00:00
|
|
|
public abstract class HitObjectSampleTest : PlayerTestScene, IStorageResourceProvider
|
2020-06-21 16:02:09 +00:00
|
|
|
{
|
2021-05-31 09:37:32 +00:00
|
|
|
protected abstract IResourceStore<byte[]> RulesetResources { get; }
|
2020-06-21 16:52:15 +00:00
|
|
|
protected LegacySkin Skin { get; private set; }
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
private RulesetStore rulesetStore { get; set; }
|
2020-06-21 16:19:33 +00:00
|
|
|
|
2020-06-21 16:02:09 +00:00
|
|
|
private readonly SkinInfo userSkinInfo = new SkinInfo();
|
|
|
|
|
|
|
|
private readonly BeatmapInfo beatmapInfo = new BeatmapInfo
|
|
|
|
{
|
|
|
|
BeatmapSet = new BeatmapSetInfo(),
|
2021-11-22 16:22:19 +00:00
|
|
|
Metadata = new BeatmapMetadata(),
|
2020-06-21 16:02:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
private readonly TestResourceStore userSkinResourceStore = new TestResourceStore();
|
|
|
|
private readonly TestResourceStore beatmapSkinResourceStore = new TestResourceStore();
|
|
|
|
private SkinSourceDependencyContainer dependencies;
|
|
|
|
private IBeatmap currentTestBeatmap;
|
2020-11-13 09:19:07 +00:00
|
|
|
|
2020-06-21 21:04:59 +00:00
|
|
|
protected sealed override bool HasCustomSteps => true;
|
2020-11-13 09:19:07 +00:00
|
|
|
protected override bool Autoplay => true;
|
2020-06-21 16:02:09 +00:00
|
|
|
|
2020-06-21 21:04:59 +00:00
|
|
|
protected sealed override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
|
2020-06-21 16:02:09 +00:00
|
|
|
=> new DependencyContainer(dependencies = new SkinSourceDependencyContainer(base.CreateChildDependencies(parent)));
|
|
|
|
|
2020-06-21 21:04:59 +00:00
|
|
|
protected sealed override IBeatmap CreateBeatmap(RulesetInfo ruleset) => currentTestBeatmap;
|
2020-06-21 16:02:09 +00:00
|
|
|
|
2020-06-21 21:04:59 +00:00
|
|
|
protected sealed override WorkingBeatmap CreateWorkingBeatmap(IBeatmap beatmap, Storyboard storyboard = null)
|
2020-12-21 06:14:32 +00:00
|
|
|
=> new TestWorkingBeatmap(beatmapInfo, beatmapSkinResourceStore, beatmap, storyboard, Clock, this);
|
2020-06-21 16:02:09 +00:00
|
|
|
|
2020-11-13 09:19:07 +00:00
|
|
|
protected override TestPlayer CreatePlayer(Ruleset ruleset) => new TestPlayer(false);
|
|
|
|
|
2020-06-21 16:02:09 +00:00
|
|
|
protected void CreateTestWithBeatmap(string filename)
|
|
|
|
{
|
|
|
|
CreateTest(() =>
|
|
|
|
{
|
|
|
|
AddStep("clear performed lookups", () =>
|
|
|
|
{
|
|
|
|
userSkinResourceStore.PerformedLookups.Clear();
|
|
|
|
beatmapSkinResourceStore.PerformedLookups.Clear();
|
|
|
|
});
|
|
|
|
|
|
|
|
AddStep($"load {filename}", () =>
|
|
|
|
{
|
2021-05-31 09:55:47 +00:00
|
|
|
using (var reader = new LineBufferedReader(RulesetResources.GetStream($"Resources/SampleLookups/{filename}")))
|
2020-06-21 16:02:09 +00:00
|
|
|
currentTestBeatmap = Decoder.GetDecoder<Beatmap>(reader).Decode(reader);
|
2020-06-21 16:52:15 +00:00
|
|
|
|
|
|
|
// populate ruleset for beatmap converters that require it to be present.
|
2022-01-27 06:19:48 +00:00
|
|
|
var ruleset = rulesetStore.GetRuleset(currentTestBeatmap.BeatmapInfo.Ruleset.OnlineID);
|
2021-11-24 03:16:08 +00:00
|
|
|
|
|
|
|
Debug.Assert(ruleset != null);
|
|
|
|
|
|
|
|
currentTestBeatmap.BeatmapInfo.Ruleset = ruleset;
|
2020-06-21 16:02:09 +00:00
|
|
|
});
|
|
|
|
});
|
2020-11-13 09:19:07 +00:00
|
|
|
|
|
|
|
AddStep("seek to completion", () => Player.GameplayClockContainer.Seek(Player.DrawableRuleset.Objects.Last().GetEndTime()));
|
|
|
|
AddUntilStep("results displayed", () => Stack.CurrentScreen is ResultsScreen);
|
2020-06-21 16:02:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected void SetupSkins(string beatmapFile, string userFile)
|
|
|
|
{
|
|
|
|
AddStep("setup skins", () =>
|
|
|
|
{
|
2021-11-24 04:49:38 +00:00
|
|
|
userSkinInfo.Files.Clear();
|
2022-03-23 05:14:55 +00:00
|
|
|
if (!string.IsNullOrEmpty(userFile))
|
|
|
|
userSkinInfo.Files.Add(new RealmNamedFileUsage(new RealmFile { Hash = userFile }, userFile));
|
2021-11-24 04:49:38 +00:00
|
|
|
|
2022-01-12 13:34:07 +00:00
|
|
|
Debug.Assert(beatmapInfo.BeatmapSet != null);
|
|
|
|
|
2021-11-24 04:49:38 +00:00
|
|
|
beatmapInfo.BeatmapSet.Files.Clear();
|
2022-03-23 05:14:55 +00:00
|
|
|
if (!string.IsNullOrEmpty(beatmapFile))
|
|
|
|
beatmapInfo.BeatmapSet.Files.Add(new RealmNamedFileUsage(new RealmFile { Hash = beatmapFile }, beatmapFile));
|
2020-06-21 16:02:09 +00:00
|
|
|
|
|
|
|
// Need to refresh the cached skin source to refresh the skin resource store.
|
2020-12-21 06:14:32 +00:00
|
|
|
dependencies.SkinSource = new SkinProvidingContainer(Skin = new LegacySkin(userSkinInfo, this));
|
2020-06-21 16:02:09 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void AssertBeatmapLookup(string name) => AddAssert($"\"{name}\" looked up from beatmap skin",
|
|
|
|
() => !userSkinResourceStore.PerformedLookups.Contains(name) && beatmapSkinResourceStore.PerformedLookups.Contains(name));
|
|
|
|
|
|
|
|
protected void AssertUserLookup(string name) => AddAssert($"\"{name}\" looked up from user skin",
|
|
|
|
() => !beatmapSkinResourceStore.PerformedLookups.Contains(name) && userSkinResourceStore.PerformedLookups.Contains(name));
|
|
|
|
|
2020-06-21 16:52:15 +00:00
|
|
|
protected void AssertNoLookup(string name) => AddAssert($"\"{name}\" not looked up",
|
|
|
|
() => !beatmapSkinResourceStore.PerformedLookups.Contains(name) && !userSkinResourceStore.PerformedLookups.Contains(name));
|
|
|
|
|
2020-12-22 03:01:09 +00:00
|
|
|
#region IResourceStorageProvider
|
|
|
|
|
2020-12-21 06:14:32 +00:00
|
|
|
public AudioManager AudioManager => Audio;
|
|
|
|
public IResourceStore<byte[]> Files => userSkinResourceStore;
|
2021-05-31 09:37:32 +00:00
|
|
|
public new IResourceStore<byte[]> Resources => base.Resources;
|
2020-12-21 06:14:32 +00:00
|
|
|
public IResourceStore<TextureUpload> CreateTextureLoaderStore(IResourceStore<byte[]> underlyingStore) => null;
|
2022-01-24 10:59:58 +00:00
|
|
|
RealmAccess IStorageResourceProvider.RealmAccess => null;
|
2020-12-21 06:14:32 +00:00
|
|
|
|
2020-12-22 03:01:09 +00:00
|
|
|
#endregion
|
|
|
|
|
2020-06-21 21:04:59 +00:00
|
|
|
private class SkinSourceDependencyContainer : IReadOnlyDependencyContainer
|
2020-06-21 16:02:09 +00:00
|
|
|
{
|
|
|
|
public ISkinSource SkinSource;
|
|
|
|
|
|
|
|
private readonly IReadOnlyDependencyContainer fallback;
|
|
|
|
|
|
|
|
public SkinSourceDependencyContainer(IReadOnlyDependencyContainer fallback)
|
|
|
|
{
|
|
|
|
this.fallback = fallback;
|
|
|
|
}
|
|
|
|
|
|
|
|
public object Get(Type type)
|
|
|
|
{
|
|
|
|
if (type == typeof(ISkinSource))
|
|
|
|
return SkinSource;
|
|
|
|
|
|
|
|
return fallback.Get(type);
|
|
|
|
}
|
|
|
|
|
|
|
|
public object Get(Type type, CacheInfo info)
|
|
|
|
{
|
|
|
|
if (type == typeof(ISkinSource))
|
|
|
|
return SkinSource;
|
|
|
|
|
|
|
|
return fallback.Get(type, info);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Inject<T>(T instance) where T : class
|
|
|
|
{
|
|
|
|
// Never used directly
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-21 21:04:59 +00:00
|
|
|
private class TestResourceStore : IResourceStore<byte[]>
|
2020-06-21 16:02:09 +00:00
|
|
|
{
|
|
|
|
public readonly List<string> PerformedLookups = new List<string>();
|
|
|
|
|
|
|
|
public byte[] Get(string name)
|
|
|
|
{
|
|
|
|
markLookup(name);
|
|
|
|
return Array.Empty<byte>();
|
|
|
|
}
|
|
|
|
|
2021-12-23 09:33:17 +00:00
|
|
|
public Task<byte[]> GetAsync(string name, CancellationToken cancellationToken = default)
|
2020-06-21 16:02:09 +00:00
|
|
|
{
|
|
|
|
markLookup(name);
|
|
|
|
return Task.FromResult(Array.Empty<byte>());
|
|
|
|
}
|
|
|
|
|
|
|
|
public Stream GetStream(string name)
|
|
|
|
{
|
|
|
|
markLookup(name);
|
|
|
|
return new MemoryStream();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void markLookup(string name) => PerformedLookups.Add(name.Substring(name.LastIndexOf(Path.DirectorySeparatorChar) + 1));
|
|
|
|
|
|
|
|
public IEnumerable<string> GetAvailableResources() => Enumerable.Empty<string>();
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-23 05:23:07 +00:00
|
|
|
private class TestWorkingBeatmap : ClockBackedTestWorkingBeatmap, IStorageResourceProvider
|
2020-06-21 16:02:09 +00:00
|
|
|
{
|
|
|
|
private readonly BeatmapInfo skinBeatmapInfo;
|
|
|
|
|
2020-12-21 06:14:32 +00:00
|
|
|
private readonly IStorageResourceProvider resources;
|
|
|
|
|
2022-03-23 05:23:07 +00:00
|
|
|
public TestWorkingBeatmap(BeatmapInfo skinBeatmapInfo, IResourceStore<byte[]> accessMarkingResourceStore, IBeatmap beatmap, Storyboard storyboard, IFrameBasedClock referenceClock,
|
|
|
|
IStorageResourceProvider resources)
|
2020-12-21 06:14:32 +00:00
|
|
|
: base(beatmap, storyboard, referenceClock, resources.AudioManager)
|
2020-06-21 16:02:09 +00:00
|
|
|
{
|
|
|
|
this.skinBeatmapInfo = skinBeatmapInfo;
|
2022-03-23 05:23:07 +00:00
|
|
|
Files = accessMarkingResourceStore;
|
2020-12-21 06:14:32 +00:00
|
|
|
this.resources = resources;
|
2020-06-21 16:02:09 +00:00
|
|
|
}
|
|
|
|
|
2022-03-23 05:23:07 +00:00
|
|
|
protected internal override ISkin GetSkin() => new LegacyBeatmapSkin(skinBeatmapInfo, this);
|
|
|
|
|
|
|
|
public AudioManager AudioManager => resources.AudioManager;
|
|
|
|
|
|
|
|
public IResourceStore<byte[]> Files { get; }
|
|
|
|
|
|
|
|
public IResourceStore<byte[]> Resources => resources.Resources;
|
|
|
|
|
|
|
|
public RealmAccess RealmAccess => resources.RealmAccess;
|
|
|
|
|
|
|
|
public IResourceStore<TextureUpload> CreateTextureLoaderStore(IResourceStore<byte[]> underlyingStore) => resources.CreateTextureLoaderStore(underlyingStore);
|
2020-06-21 16:02:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|