From 23d6c366acc34ee9f92a116ce2cace40008f3b04 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Thu, 10 Jun 2021 15:36:53 +0300 Subject: [PATCH] Add method for assigning arbitrary skins to player in test scenes --- osu.Game/Tests/Visual/PlayerTestScene.cs | 8 +++++++ osu.Game/Tests/Visual/TestPlayer.cs | 28 ++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/osu.Game/Tests/Visual/PlayerTestScene.cs b/osu.Game/Tests/Visual/PlayerTestScene.cs index 088e997de9..e42a043eec 100644 --- a/osu.Game/Tests/Visual/PlayerTestScene.cs +++ b/osu.Game/Tests/Visual/PlayerTestScene.cs @@ -10,6 +10,7 @@ using osu.Framework.Testing; using osu.Game.Configuration; using osu.Game.Rulesets; using osu.Game.Rulesets.Mods; +using osu.Game.Skinning; namespace osu.Game.Tests.Visual { @@ -78,6 +79,8 @@ namespace osu.Game.Tests.Visual } Player = CreatePlayer(ruleset); + Player.Skin = GetPlayerSkin(); + LoadScreen(Player); } @@ -93,6 +96,11 @@ namespace osu.Game.Tests.Visual [NotNull] protected abstract Ruleset CreatePlayerRuleset(); + /// + /// Creates an to be put inside the 's ruleset skin providing container. + /// + protected virtual ISkin GetPlayerSkin() => null; + protected sealed override Ruleset CreateRuleset() => CreatePlayerRuleset(); protected virtual TestPlayer CreatePlayer(Ruleset ruleset) => new TestPlayer(false, false); diff --git a/osu.Game/Tests/Visual/TestPlayer.cs b/osu.Game/Tests/Visual/TestPlayer.cs index 09da4db952..eecf8a2f6e 100644 --- a/osu.Game/Tests/Visual/TestPlayer.cs +++ b/osu.Game/Tests/Visual/TestPlayer.cs @@ -3,13 +3,17 @@ using System.Collections.Generic; using System.Linq; +using JetBrains.Annotations; using osu.Framework.Allocation; using osu.Framework.Bindables; +using osu.Game.Beatmaps; +using osu.Game.Rulesets; using osu.Game.Rulesets.Judgements; using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Scoring; using osu.Game.Rulesets.UI; using osu.Game.Screens.Play; +using osu.Game.Skinning; namespace osu.Game.Tests.Visual { @@ -18,6 +22,8 @@ namespace osu.Game.Tests.Visual /// public class TestPlayer : Player { + public ISkin Skin { get; set; } + protected override bool PauseOnFocusLost { get; } public new DrawableRuleset DrawableRuleset => base.DrawableRuleset; @@ -74,5 +80,27 @@ namespace osu.Game.Tests.Visual { ScoreProcessor.NewJudgement += r => Results.Add(r); } + + protected override RulesetSkinProvidingContainer CreateRulesetSkinProvider(Ruleset ruleset, IBeatmap beatmap, ISkin beatmapSkin) + => new TestSkinProvidingContainer(Skin, ruleset, beatmap, beatmapSkin); + + private class TestSkinProvidingContainer : RulesetSkinProvidingContainer + { + private readonly ISkin skin; + + public TestSkinProvidingContainer(ISkin skin, Ruleset ruleset, IBeatmap beatmap, [CanBeNull] ISkin beatmapSkin) + : base(ruleset, beatmap, beatmapSkin) + { + this.skin = skin; + } + + protected override void UpdateSkins() + { + base.UpdateSkins(); + + if (skin != null) + SkinSources.Insert(0, Ruleset.CreateLegacySkinProvider(skin, Beatmap)); + } + } } }