mirror of
https://github.com/ppy/osu.git
synced 2025-01-12 11:42:54 +08:00
Consume new method rather than caching skin sources on top of Player
This commit is contained in:
parent
23d6c366ac
commit
680791301f
@ -101,15 +101,10 @@ namespace osu.Game.Rulesets.Catch.Tests
|
||||
AddAssert("is custom hyper dash fruit colours", () => ((CatchExposedPlayer)TestPlayer).UsableHyperDashFruitColour == TestSkin.HYPER_DASH_FRUIT_COLOUR);
|
||||
}
|
||||
|
||||
protected override ExposedPlayer CreateTestPlayer(bool userHasCustomColours) => new CatchExposedPlayer(userHasCustomColours);
|
||||
protected override ExposedPlayer CreateTestPlayer() => new CatchExposedPlayer();
|
||||
|
||||
private class CatchExposedPlayer : ExposedPlayer
|
||||
{
|
||||
public CatchExposedPlayer(bool userHasCustomColours)
|
||||
: base(userHasCustomColours)
|
||||
{
|
||||
}
|
||||
|
||||
public Color4 UsableHyperDashColour =>
|
||||
GameplayClockContainer.ChildrenOfType<BeatmapSkinProvidingContainer>()
|
||||
.First()
|
||||
|
@ -21,7 +21,6 @@ using osu.Game.Graphics.Sprites;
|
||||
using osu.Game.Rulesets.Osu.Objects.Drawables;
|
||||
using osu.Game.Skinning;
|
||||
using osu.Game.Storyboards;
|
||||
using osu.Game.Tests.Visual;
|
||||
|
||||
namespace osu.Game.Rulesets.Osu.Tests
|
||||
{
|
||||
@ -99,7 +98,7 @@ namespace osu.Game.Rulesets.Osu.Tests
|
||||
[Resolved]
|
||||
private AudioManager audio { get; set; }
|
||||
|
||||
protected override TestPlayer CreatePlayer(Ruleset ruleset) => new SkinProvidingPlayer(testUserSkin);
|
||||
protected override ISkin GetPlayerSkin() => testUserSkin;
|
||||
|
||||
protected override WorkingBeatmap CreateWorkingBeatmap(IBeatmap beatmap, Storyboard storyboard = null) => new CustomSkinWorkingBeatmap(beatmap, storyboard, Clock, audio, testBeatmapSkin);
|
||||
|
||||
@ -116,27 +115,6 @@ namespace osu.Game.Rulesets.Osu.Tests
|
||||
protected override ISkin GetSkin() => skin;
|
||||
}
|
||||
|
||||
public class SkinProvidingPlayer : TestPlayer
|
||||
{
|
||||
private readonly TestSource userSkin;
|
||||
|
||||
public SkinProvidingPlayer(TestSource userSkin)
|
||||
{
|
||||
this.userSkin = userSkin;
|
||||
}
|
||||
|
||||
private DependencyContainer dependencies;
|
||||
|
||||
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
|
||||
{
|
||||
dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
|
||||
|
||||
dependencies.CacheAs<ISkinSource>(userSkin);
|
||||
|
||||
return dependencies;
|
||||
}
|
||||
}
|
||||
|
||||
public class TestSource : ISkinSource
|
||||
{
|
||||
private readonly string identifier;
|
||||
@ -164,8 +142,8 @@ namespace osu.Game.Rulesets.Osu.Tests
|
||||
|
||||
public ISample GetSample(ISampleInfo sampleInfo) => null;
|
||||
|
||||
public TValue GetValue<TConfiguration, TValue>(Func<TConfiguration, TValue> query) where TConfiguration : SkinConfiguration => default;
|
||||
public IBindable<TValue> GetConfig<TLookup, TValue>(TLookup lookup) => null;
|
||||
|
||||
public ISkin FindProvider(Func<ISkin, bool> lookupFunction) => null;
|
||||
|
||||
public event Action SourceChanged;
|
||||
|
@ -47,15 +47,11 @@ namespace osu.Game.Tests.Beatmaps
|
||||
|
||||
private readonly TestResourceStore userSkinResourceStore = new TestResourceStore();
|
||||
private readonly TestResourceStore beatmapSkinResourceStore = new TestResourceStore();
|
||||
private SkinSourceDependencyContainer dependencies;
|
||||
private IBeatmap currentTestBeatmap;
|
||||
|
||||
protected sealed override bool HasCustomSteps => true;
|
||||
protected override bool Autoplay => true;
|
||||
|
||||
protected sealed override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
|
||||
=> new DependencyContainer(dependencies = new SkinSourceDependencyContainer(base.CreateChildDependencies(parent)));
|
||||
|
||||
protected sealed override IBeatmap CreateBeatmap(RulesetInfo ruleset) => currentTestBeatmap;
|
||||
|
||||
protected sealed override WorkingBeatmap CreateWorkingBeatmap(IBeatmap beatmap, Storyboard storyboard = null)
|
||||
@ -63,6 +59,8 @@ namespace osu.Game.Tests.Beatmaps
|
||||
|
||||
protected override TestPlayer CreatePlayer(Ruleset ruleset) => new TestPlayer(false);
|
||||
|
||||
protected override ISkin GetPlayerSkin() => Skin;
|
||||
|
||||
protected void CreateTestWithBeatmap(string filename)
|
||||
{
|
||||
CreateTest(() =>
|
||||
@ -109,8 +107,7 @@ namespace osu.Game.Tests.Beatmaps
|
||||
}
|
||||
};
|
||||
|
||||
// Need to refresh the cached skin source to refresh the skin resource store.
|
||||
dependencies.SkinSource = new SkinProvidingContainer(Skin = new LegacySkin(userSkinInfo, this));
|
||||
Skin = new LegacySkin(userSkinInfo, this);
|
||||
});
|
||||
}
|
||||
|
||||
@ -132,39 +129,6 @@ namespace osu.Game.Tests.Beatmaps
|
||||
|
||||
#endregion
|
||||
|
||||
private class SkinSourceDependencyContainer : IReadOnlyDependencyContainer
|
||||
{
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
private class TestResourceStore : IResourceStore<byte[]>
|
||||
{
|
||||
public readonly List<string> PerformedLookups = new List<string>();
|
||||
|
@ -4,13 +4,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Audio;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.IO.Stores;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Screens.Play;
|
||||
using osu.Game.Skinning;
|
||||
using osu.Game.Tests.Visual;
|
||||
using osuTK.Graphics;
|
||||
@ -49,36 +47,24 @@ namespace osu.Game.Tests.Beatmaps
|
||||
|
||||
protected virtual ExposedPlayer LoadBeatmap(bool userHasCustomColours)
|
||||
{
|
||||
ExposedPlayer player;
|
||||
|
||||
Beatmap.Value = testBeatmap;
|
||||
|
||||
LoadScreen(player = CreateTestPlayer(userHasCustomColours));
|
||||
ExposedPlayer player = CreateTestPlayer();
|
||||
|
||||
player.Skin = new TestSkin(userHasCustomColours);
|
||||
|
||||
LoadScreen(player);
|
||||
|
||||
return player;
|
||||
}
|
||||
|
||||
protected virtual ExposedPlayer CreateTestPlayer(bool userHasCustomColours) => new ExposedPlayer(userHasCustomColours);
|
||||
protected virtual ExposedPlayer CreateTestPlayer() => new ExposedPlayer();
|
||||
|
||||
protected class ExposedPlayer : Player
|
||||
protected class ExposedPlayer : TestPlayer
|
||||
{
|
||||
protected readonly bool UserHasCustomColours;
|
||||
|
||||
public ExposedPlayer(bool userHasCustomColours)
|
||||
: base(new PlayerConfiguration
|
||||
{
|
||||
AllowPause = false,
|
||||
ShowResults = false,
|
||||
})
|
||||
public ExposedPlayer()
|
||||
: base(false, false)
|
||||
{
|
||||
UserHasCustomColours = userHasCustomColours;
|
||||
}
|
||||
|
||||
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
|
||||
{
|
||||
var dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
|
||||
dependencies.CacheAs<ISkinSource>(new TestSkin(UserHasCustomColours));
|
||||
return dependencies;
|
||||
}
|
||||
|
||||
public IReadOnlyList<Color4> UsableComboColours =>
|
||||
|
@ -5,7 +5,6 @@ using NUnit.Framework;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Extensions.IEnumerableExtensions;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Skinning;
|
||||
|
||||
namespace osu.Game.Tests.Visual
|
||||
@ -15,15 +14,12 @@ namespace osu.Game.Tests.Visual
|
||||
{
|
||||
protected LegacySkin LegacySkin { get; private set; }
|
||||
|
||||
private ISkinSource legacySkinSource;
|
||||
|
||||
protected override TestPlayer CreatePlayer(Ruleset ruleset) => new SkinProvidingPlayer(legacySkinSource);
|
||||
protected override ISkin GetPlayerSkin() => LegacySkin;
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(SkinManager skins)
|
||||
{
|
||||
LegacySkin = new DefaultLegacySkin(skins);
|
||||
legacySkinSource = new SkinProvidingContainer(LegacySkin);
|
||||
}
|
||||
|
||||
[SetUpSteps]
|
||||
@ -48,16 +44,5 @@ namespace osu.Game.Tests.Visual
|
||||
t.Reload();
|
||||
}));
|
||||
}
|
||||
|
||||
public class SkinProvidingPlayer : TestPlayer
|
||||
{
|
||||
[Cached(typeof(ISkinSource))]
|
||||
private readonly ISkinSource skinSource;
|
||||
|
||||
public SkinProvidingPlayer(ISkinSource skinSource)
|
||||
{
|
||||
this.skinSource = skinSource;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user