mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 10:07:52 +08:00
Merge pull request #4614 from smoogipoo/player-mod-reinstantiation
Reinstantiate mods for each player instance Co-authored-by: Dean Herbert <pe@ppy.sh>
This commit is contained in:
commit
f6cbae578b
@ -1,11 +1,16 @@
|
||||
// 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.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Screens;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Rulesets.Mods;
|
||||
using osu.Game.Rulesets.Scoring;
|
||||
using osu.Game.Screens;
|
||||
using osu.Game.Screens.Play;
|
||||
|
||||
@ -21,23 +26,15 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
InputManager.Add(stack = new OsuScreenStack { RelativeSizeAxes = Axes.Both });
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuGameBase game)
|
||||
[Test]
|
||||
public void TestLoadContinuation()
|
||||
{
|
||||
Beatmap.Value = new DummyWorkingBeatmap(game);
|
||||
|
||||
AddStep("load dummy beatmap", () => stack.Push(loader = new PlayerLoader(() => new Player(false, false))));
|
||||
|
||||
AddUntilStep("wait for current", () => loader.IsCurrentScreen());
|
||||
|
||||
AddStep("mouse in centre", () => InputManager.MoveMouseTo(loader.ScreenSpaceDrawQuad.Centre));
|
||||
|
||||
AddUntilStep("wait for no longer current", () => !loader.IsCurrentScreen());
|
||||
|
||||
AddStep("exit loader", () => loader.Exit());
|
||||
|
||||
AddUntilStep("wait for no longer alive", () => !loader.IsAlive);
|
||||
|
||||
AddStep("load slow dummy beatmap", () =>
|
||||
{
|
||||
SlowLoadPlayer slow = null;
|
||||
@ -50,6 +47,81 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
AddUntilStep("wait for no longer current", () => !loader.IsCurrentScreen());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestModReinstantiation()
|
||||
{
|
||||
TestPlayer player = null;
|
||||
TestMod gameMod = null;
|
||||
TestMod playerMod1 = null;
|
||||
TestMod playerMod2 = null;
|
||||
|
||||
AddStep("load player", () =>
|
||||
{
|
||||
Mods.Value = new[] { gameMod = new TestMod() };
|
||||
InputManager.MoveMouseTo(loader.ScreenSpaceDrawQuad.Centre);
|
||||
stack.Push(new PlayerLoader(() => player = new TestPlayer()));
|
||||
});
|
||||
|
||||
AddUntilStep("wait for player to become current", () =>
|
||||
{
|
||||
if (player.IsCurrentScreen())
|
||||
{
|
||||
playerMod1 = (TestMod)player.Mods.Value.Single();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
AddAssert("game mods not applied", () => gameMod.Applied == false);
|
||||
AddAssert("player mods applied", () => playerMod1.Applied);
|
||||
|
||||
AddStep("restart player", () =>
|
||||
{
|
||||
player = null;
|
||||
player.Restart();
|
||||
});
|
||||
|
||||
AddUntilStep("wait for player to become current", () =>
|
||||
{
|
||||
if (player.IsCurrentScreen())
|
||||
{
|
||||
playerMod2 = (TestMod)player.Mods.Value.Single();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
AddAssert("game mods not applied", () => gameMod.Applied == false);
|
||||
AddAssert("player has different mods", () => playerMod1 != playerMod2);
|
||||
AddAssert("player mods applied", () => playerMod2.Applied);
|
||||
}
|
||||
|
||||
private class TestMod : Mod, IApplicableToScoreProcessor
|
||||
{
|
||||
public override string Name => string.Empty;
|
||||
public override string Acronym => string.Empty;
|
||||
public override double ScoreMultiplier => 1;
|
||||
|
||||
public bool Applied { get; private set; }
|
||||
|
||||
public void ApplyToScoreProcessor(ScoreProcessor scoreProcessor)
|
||||
{
|
||||
Applied = true;
|
||||
}
|
||||
}
|
||||
|
||||
private class TestPlayer : Player
|
||||
{
|
||||
public new Bindable<IReadOnlyList<Mod>> Mods => base.Mods;
|
||||
|
||||
public TestPlayer()
|
||||
: base(false, false)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
protected class SlowLoadPlayer : Player
|
||||
{
|
||||
public bool Ready;
|
||||
|
@ -2,6 +2,7 @@
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Audio;
|
||||
@ -69,6 +70,10 @@ namespace osu.Game.Screens.Play
|
||||
|
||||
protected GameplayClockContainer GameplayClockContainer { get; private set; }
|
||||
|
||||
[Cached]
|
||||
[Cached(Type = typeof(IBindable<IReadOnlyList<Mod>>))]
|
||||
protected readonly Bindable<IReadOnlyList<Mod>> Mods = new Bindable<IReadOnlyList<Mod>>(Array.Empty<Mod>());
|
||||
|
||||
private readonly bool allowPause;
|
||||
private readonly bool showResults;
|
||||
|
||||
@ -88,6 +93,8 @@ namespace osu.Game.Screens.Play
|
||||
{
|
||||
this.api = api;
|
||||
|
||||
Mods.Value = base.Mods.Value.Select(m => m.CreateCopy()).ToArray();
|
||||
|
||||
WorkingBeatmap working = loadBeatmap();
|
||||
|
||||
if (working == null)
|
||||
|
Loading…
Reference in New Issue
Block a user