2020-04-14 20:05:54 +08: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 NUnit.Framework ;
2020-06-22 00:19:33 +08:00
using osu.Framework.IO.Stores ;
2020-04-14 21:39:51 +08:00
using osu.Framework.Testing ;
2020-04-14 20:05:54 +08:00
using osu.Game.Rulesets ;
2020-06-22 00:02:09 +08:00
using osu.Game.Rulesets.Osu ;
2020-06-22 00:52:15 +08:00
using osu.Game.Skinning ;
2020-06-22 00:20:36 +08:00
using osu.Game.Tests.Beatmaps ;
2020-06-22 00:19:33 +08:00
using osu.Game.Tests.Resources ;
2020-04-14 20:05:54 +08:00
namespace osu.Game.Tests.Gameplay
{
2020-04-14 21:39:51 +08:00
[HeadlessTest]
2020-06-22 00:02:09 +08:00
public class TestSceneHitObjectSamples : HitObjectSampleTest
2020-04-14 20:05:54 +08:00
{
2020-06-22 00:02:09 +08:00
protected override Ruleset CreatePlayerRuleset ( ) = > new OsuRuleset ( ) ;
2020-06-22 00:19:33 +08:00
protected override IResourceStore < byte [ ] > Resources = > TestResources . GetStore ( ) ;
2020-04-14 20:05:54 +08:00
/// <summary>
/// Tests that a hitobject which provides no custom sample set retrieves samples from the user skin.
/// </summary>
[Test]
public void TestDefaultSampleFromUserSkin ( )
{
const string expected_sample = "normal-hitnormal" ;
2020-06-22 00:02:09 +08:00
SetupSkins ( expected_sample , expected_sample ) ;
2020-04-14 20:05:54 +08:00
2020-06-22 00:02:09 +08:00
CreateTestWithBeatmap ( "hitobject-skin-sample.osu" ) ;
2020-04-14 20:05:54 +08:00
2020-06-22 00:02:09 +08:00
AssertUserLookup ( expected_sample ) ;
2020-04-14 20:05:54 +08:00
}
/// <summary>
/// Tests that a hitobject which provides a sample set of 1 retrieves samples from the beatmap skin.
/// </summary>
[Test]
public void TestDefaultSampleFromBeatmap ( )
{
const string expected_sample = "normal-hitnormal" ;
2020-06-22 00:02:09 +08:00
SetupSkins ( expected_sample , expected_sample ) ;
2020-04-14 20:05:54 +08:00
2020-06-22 00:02:09 +08:00
CreateTestWithBeatmap ( "hitobject-beatmap-sample.osu" ) ;
2020-04-14 20:05:54 +08:00
2020-06-22 00:02:09 +08:00
AssertBeatmapLookup ( expected_sample ) ;
2020-04-14 20:05:54 +08:00
}
/// <summary>
/// Tests that a hitobject which provides a sample set of 1 retrieves samples from the user skin when the beatmap does not contain the sample.
/// </summary>
[Test]
public void TestDefaultSampleFromUserSkinFallback ( )
{
const string expected_sample = "normal-hitnormal" ;
2020-06-22 00:02:09 +08:00
SetupSkins ( null , expected_sample ) ;
2020-04-14 20:05:54 +08:00
2020-06-22 00:02:09 +08:00
CreateTestWithBeatmap ( "hitobject-beatmap-sample.osu" ) ;
2020-04-14 20:05:54 +08:00
2020-06-22 00:02:09 +08:00
AssertUserLookup ( expected_sample ) ;
2020-04-14 20:05:54 +08:00
}
/// <summary>
/// Tests that a hitobject which provides a custom sample set of 2 retrieves the following samples from the beatmap skin:
/// normal-hitnormal2
/// normal-hitnormal
/// </summary>
[TestCase("normal-hitnormal2")]
[TestCase("normal-hitnormal")]
public void TestDefaultCustomSampleFromBeatmap ( string expectedSample )
{
2020-06-22 00:02:09 +08:00
SetupSkins ( expectedSample , expectedSample ) ;
2020-04-14 20:05:54 +08:00
2020-06-22 00:02:09 +08:00
CreateTestWithBeatmap ( "hitobject-beatmap-custom-sample.osu" ) ;
2020-04-14 20:05:54 +08:00
2020-06-22 00:02:09 +08:00
AssertBeatmapLookup ( expectedSample ) ;
2020-04-14 20:05:54 +08:00
}
/// <summary>
/// Tests that a hitobject which provides a custom sample set of 2 retrieves the following samples from the user skin when the beatmap does not contain the sample:
/// normal-hitnormal2
/// normal-hitnormal
/// </summary>
[TestCase("normal-hitnormal2")]
[TestCase("normal-hitnormal")]
public void TestDefaultCustomSampleFromUserSkinFallback ( string expectedSample )
{
2020-06-22 00:02:09 +08:00
SetupSkins ( string . Empty , expectedSample ) ;
2020-04-14 20:05:54 +08:00
2020-06-22 00:02:09 +08:00
CreateTestWithBeatmap ( "hitobject-beatmap-custom-sample.osu" ) ;
2020-04-14 20:05:54 +08:00
2020-06-22 00:02:09 +08:00
AssertUserLookup ( expectedSample ) ;
2020-04-14 20:05:54 +08:00
}
/// <summary>
/// Tests that a hitobject which provides a sample file retrieves the sample file from the beatmap skin.
/// </summary>
[Test]
public void TestFileSampleFromBeatmap ( )
{
const string expected_sample = "hit_1.wav" ;
2020-06-22 00:02:09 +08:00
SetupSkins ( expected_sample , expected_sample ) ;
2020-04-14 20:05:54 +08:00
2020-06-22 00:02:09 +08:00
CreateTestWithBeatmap ( "file-beatmap-sample.osu" ) ;
2020-04-14 20:05:54 +08:00
2020-06-22 00:02:09 +08:00
AssertBeatmapLookup ( expected_sample ) ;
2020-04-14 20:05:54 +08:00
}
/// <summary>
/// Tests that a default hitobject and control point causes <see cref="TestDefaultSampleFromUserSkin"/>.
/// </summary>
[Test]
public void TestControlPointSampleFromSkin ( )
{
const string expected_sample = "normal-hitnormal" ;
2020-06-22 00:02:09 +08:00
SetupSkins ( expected_sample , expected_sample ) ;
2020-04-14 20:05:54 +08:00
2020-06-22 00:02:09 +08:00
CreateTestWithBeatmap ( "controlpoint-skin-sample.osu" ) ;
2020-04-14 20:05:54 +08:00
2020-06-22 00:02:09 +08:00
AssertUserLookup ( expected_sample ) ;
2020-04-14 20:05:54 +08:00
}
/// <summary>
/// Tests that a control point that provides a custom sample set of 1 causes <see cref="TestDefaultSampleFromBeatmap"/>.
/// </summary>
[Test]
public void TestControlPointSampleFromBeatmap ( )
{
const string expected_sample = "normal-hitnormal" ;
2020-06-22 00:02:09 +08:00
SetupSkins ( expected_sample , expected_sample ) ;
2020-04-14 20:05:54 +08:00
2020-06-22 00:02:09 +08:00
CreateTestWithBeatmap ( "controlpoint-beatmap-sample.osu" ) ;
2020-04-14 20:05:54 +08:00
2020-06-22 00:02:09 +08:00
AssertBeatmapLookup ( expected_sample ) ;
2020-04-14 20:05:54 +08:00
}
/// <summary>
/// Tests that a control point that provides a custom sample of 2 causes <see cref="TestDefaultCustomSampleFromBeatmap"/>.
/// </summary>
[TestCase("normal-hitnormal2")]
[TestCase("normal-hitnormal")]
public void TestControlPointCustomSampleFromBeatmap ( string sampleName )
{
2020-06-22 00:02:09 +08:00
SetupSkins ( sampleName , sampleName ) ;
2020-04-14 20:05:54 +08:00
2020-06-22 00:02:09 +08:00
CreateTestWithBeatmap ( "controlpoint-beatmap-custom-sample.osu" ) ;
2020-04-14 20:05:54 +08:00
2020-06-22 00:02:09 +08:00
AssertBeatmapLookup ( sampleName ) ;
2020-04-14 20:05:54 +08:00
}
/// <summary>
/// Tests that a hitobject's custom sample overrides the control point's.
/// </summary>
[Test]
public void TestHitObjectCustomSampleOverride ( )
{
const string expected_sample = "normal-hitnormal3" ;
2020-06-22 00:02:09 +08:00
SetupSkins ( expected_sample , expected_sample ) ;
2020-04-14 20:05:54 +08:00
2020-06-22 00:02:09 +08:00
CreateTestWithBeatmap ( "hitobject-beatmap-custom-sample-override.osu" ) ;
2020-04-14 20:05:54 +08:00
2020-06-22 00:02:09 +08:00
AssertBeatmapLookup ( expected_sample ) ;
2020-04-14 20:05:54 +08:00
}
2020-06-22 00:52:15 +08:00
/// <summary>
/// Tests that when a custom sample bank is used, both the normal and additional sounds will be looked up.
/// </summary>
[Test]
public void TestHitObjectCustomSampleBank ( )
{
string [ ] expectedSamples =
{
"normal-hitnormal2" ,
"normal-hitwhistle2"
} ;
SetupSkins ( expectedSamples [ 0 ] , expectedSamples [ 1 ] ) ;
CreateTestWithBeatmap ( "hitobject-beatmap-custom-sample-bank.osu" ) ;
AssertBeatmapLookup ( expectedSamples [ 0 ] ) ;
AssertUserLookup ( expectedSamples [ 1 ] ) ;
}
/// <summary>
/// Tests that when a custom sample bank is used, but <see cref="GlobalSkinConfiguration.LayeredHitSounds"/> is disabled,
/// only the additional sound will be looked up.
/// </summary>
[Test]
public void TestHitObjectCustomSampleBankWithoutLayered ( )
{
const string expected_sample = "normal-hitwhistle2" ;
const string unwanted_sample = "normal-hitnormal2" ;
SetupSkins ( expected_sample , unwanted_sample ) ;
disableLayeredHitSounds ( ) ;
CreateTestWithBeatmap ( "hitobject-beatmap-custom-sample-bank.osu" ) ;
AssertBeatmapLookup ( expected_sample ) ;
AssertNoLookup ( unwanted_sample ) ;
}
/// <summary>
/// Tests that when a normal sample bank is used and <see cref="GlobalSkinConfiguration.LayeredHitSounds"/> is disabled,
/// the normal sound will be looked up anyway.
/// </summary>
[Test]
public void TestHitObjectNormalSampleBankWithoutLayered ( )
{
const string expected_sample = "normal-hitnormal" ;
SetupSkins ( expected_sample , expected_sample ) ;
disableLayeredHitSounds ( ) ;
CreateTestWithBeatmap ( "hitobject-beatmap-sample.osu" ) ;
AssertBeatmapLookup ( expected_sample ) ;
}
private void disableLayeredHitSounds ( )
= > AddStep ( "set LayeredHitSounds to false" , ( ) = > Skin . Configuration . ConfigDictionary [ GlobalSkinConfiguration . LayeredHitSounds . ToString ( ) ] = "0" ) ;
2020-04-14 20:05:54 +08:00
}
}