mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 12:33:01 +08:00
Merge pull request #14988 from peppy/remove-gameplay-mod-bindable-storage
Remove local overridden storage of `Mods` in `Player`
This commit is contained in:
commit
0e0779e45b
@ -120,7 +120,7 @@ namespace osu.Game.Rulesets.Osu.Tests.Mods
|
|||||||
private bool checkSomeHit() => Player.ScoreProcessor.JudgedHits >= 4;
|
private bool checkSomeHit() => Player.ScoreProcessor.JudgedHits >= 4;
|
||||||
|
|
||||||
private bool objectWithIncreasedVisibilityHasIndex(int index)
|
private bool objectWithIncreasedVisibilityHasIndex(int index)
|
||||||
=> Player.Mods.Value.OfType<TestOsuModHidden>().Single().FirstObject == Player.GameplayState.Beatmap.HitObjects[index];
|
=> Player.GameplayState.Mods.OfType<TestOsuModHidden>().Single().FirstObject == Player.GameplayState.Beatmap.HitObjects[index];
|
||||||
|
|
||||||
private class TestOsuModHidden : OsuModHidden
|
private class TestOsuModHidden : OsuModHidden
|
||||||
{
|
{
|
||||||
|
@ -205,7 +205,7 @@ namespace osu.Game.Tests.Visual.Gameplay
|
|||||||
AddUntilStep("wait for loader to become current", () => loader.IsCurrentScreen());
|
AddUntilStep("wait for loader to become current", () => loader.IsCurrentScreen());
|
||||||
AddStep("mouse in centre", () => InputManager.MoveMouseTo(loader.ScreenSpaceDrawQuad.Centre));
|
AddStep("mouse in centre", () => InputManager.MoveMouseTo(loader.ScreenSpaceDrawQuad.Centre));
|
||||||
AddUntilStep("wait for player to be current", () => player.IsCurrentScreen());
|
AddUntilStep("wait for player to be current", () => player.IsCurrentScreen());
|
||||||
AddStep("retrieve mods", () => playerMod1 = (TestMod)player.Mods.Value.Single());
|
AddStep("retrieve mods", () => playerMod1 = (TestMod)player.GameplayState.Mods.Single());
|
||||||
AddAssert("game mods not applied", () => gameMod.Applied == false);
|
AddAssert("game mods not applied", () => gameMod.Applied == false);
|
||||||
AddAssert("player mods applied", () => playerMod1.Applied);
|
AddAssert("player mods applied", () => playerMod1.Applied);
|
||||||
|
|
||||||
@ -217,7 +217,7 @@ namespace osu.Game.Tests.Visual.Gameplay
|
|||||||
});
|
});
|
||||||
|
|
||||||
AddUntilStep("wait for player to be current", () => player.IsCurrentScreen());
|
AddUntilStep("wait for player to be current", () => player.IsCurrentScreen());
|
||||||
AddStep("retrieve mods", () => playerMod2 = (TestMod)player.Mods.Value.Single());
|
AddStep("retrieve mods", () => playerMod2 = (TestMod)player.GameplayState.Mods.Single());
|
||||||
AddAssert("game mods not applied", () => gameMod.Applied == false);
|
AddAssert("game mods not applied", () => gameMod.Applied == false);
|
||||||
AddAssert("player has different mods", () => playerMod1 != playerMod2);
|
AddAssert("player has different mods", () => playerMod1 != playerMod2);
|
||||||
AddAssert("player mods applied", () => playerMod2.Applied);
|
AddAssert("player mods applied", () => playerMod2.Applied);
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@ -125,15 +124,11 @@ namespace osu.Game.Screens.Play
|
|||||||
|
|
||||||
public DimmableStoryboard DimmableStoryboard { get; private set; }
|
public DimmableStoryboard DimmableStoryboard { get; private set; }
|
||||||
|
|
||||||
[Cached]
|
|
||||||
[Cached(Type = typeof(IBindable<IReadOnlyList<Mod>>))]
|
|
||||||
protected new readonly Bindable<IReadOnlyList<Mod>> Mods = new Bindable<IReadOnlyList<Mod>>(Array.Empty<Mod>());
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Whether failing should be allowed.
|
/// Whether failing should be allowed.
|
||||||
/// By default, this checks whether all selected mods allow failing.
|
/// By default, this checks whether all selected mods allow failing.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected virtual bool CheckModsAllowFailure() => Mods.Value.OfType<IApplicableFailOverride>().All(m => m.PerformFail());
|
protected virtual bool CheckModsAllowFailure() => GameplayState.Mods.OfType<IApplicableFailOverride>().All(m => m.PerformFail());
|
||||||
|
|
||||||
public readonly PlayerConfiguration Configuration;
|
public readonly PlayerConfiguration Configuration;
|
||||||
|
|
||||||
@ -179,12 +174,12 @@ namespace osu.Game.Screens.Play
|
|||||||
[BackgroundDependencyLoader(true)]
|
[BackgroundDependencyLoader(true)]
|
||||||
private void load(AudioManager audio, OsuConfigManager config, OsuGameBase game)
|
private void load(AudioManager audio, OsuConfigManager config, OsuGameBase game)
|
||||||
{
|
{
|
||||||
Mods.Value = base.Mods.Value.Select(m => m.DeepClone()).ToArray();
|
var gameplayMods = Mods.Value.Select(m => m.DeepClone()).ToArray();
|
||||||
|
|
||||||
if (Beatmap.Value is DummyWorkingBeatmap)
|
if (Beatmap.Value is DummyWorkingBeatmap)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
IBeatmap playableBeatmap = loadPlayableBeatmap();
|
IBeatmap playableBeatmap = loadPlayableBeatmap(gameplayMods);
|
||||||
|
|
||||||
if (playableBeatmap == null)
|
if (playableBeatmap == null)
|
||||||
return;
|
return;
|
||||||
@ -199,12 +194,12 @@ namespace osu.Game.Screens.Play
|
|||||||
if (game is OsuGame osuGame)
|
if (game is OsuGame osuGame)
|
||||||
LocalUserPlaying.BindTo(osuGame.LocalUserPlaying);
|
LocalUserPlaying.BindTo(osuGame.LocalUserPlaying);
|
||||||
|
|
||||||
DrawableRuleset = ruleset.CreateDrawableRulesetWith(playableBeatmap, Mods.Value);
|
DrawableRuleset = ruleset.CreateDrawableRulesetWith(playableBeatmap, gameplayMods);
|
||||||
dependencies.CacheAs(DrawableRuleset);
|
dependencies.CacheAs(DrawableRuleset);
|
||||||
|
|
||||||
ScoreProcessor = ruleset.CreateScoreProcessor();
|
ScoreProcessor = ruleset.CreateScoreProcessor();
|
||||||
ScoreProcessor.ApplyBeatmap(playableBeatmap);
|
ScoreProcessor.ApplyBeatmap(playableBeatmap);
|
||||||
ScoreProcessor.Mods.BindTo(Mods);
|
ScoreProcessor.Mods.Value = gameplayMods;
|
||||||
|
|
||||||
dependencies.CacheAs(ScoreProcessor);
|
dependencies.CacheAs(ScoreProcessor);
|
||||||
|
|
||||||
@ -223,9 +218,9 @@ namespace osu.Game.Screens.Play
|
|||||||
// ensure the score is in a consistent state with the current player.
|
// ensure the score is in a consistent state with the current player.
|
||||||
Score.ScoreInfo.BeatmapInfo = Beatmap.Value.BeatmapInfo;
|
Score.ScoreInfo.BeatmapInfo = Beatmap.Value.BeatmapInfo;
|
||||||
Score.ScoreInfo.Ruleset = ruleset.RulesetInfo;
|
Score.ScoreInfo.Ruleset = ruleset.RulesetInfo;
|
||||||
Score.ScoreInfo.Mods = Mods.Value.ToArray();
|
Score.ScoreInfo.Mods = gameplayMods;
|
||||||
|
|
||||||
dependencies.CacheAs(GameplayState = new GameplayState(playableBeatmap, ruleset, Mods.Value, Score));
|
dependencies.CacheAs(GameplayState = new GameplayState(playableBeatmap, ruleset, gameplayMods, Score));
|
||||||
|
|
||||||
AddInternal(screenSuspension = new ScreenSuspensionHandler(GameplayClockContainer));
|
AddInternal(screenSuspension = new ScreenSuspensionHandler(GameplayClockContainer));
|
||||||
|
|
||||||
@ -302,13 +297,13 @@ namespace osu.Game.Screens.Play
|
|||||||
// this is required for mods that apply transforms to these processors.
|
// this is required for mods that apply transforms to these processors.
|
||||||
ScoreProcessor.OnLoadComplete += _ =>
|
ScoreProcessor.OnLoadComplete += _ =>
|
||||||
{
|
{
|
||||||
foreach (var mod in Mods.Value.OfType<IApplicableToScoreProcessor>())
|
foreach (var mod in gameplayMods.OfType<IApplicableToScoreProcessor>())
|
||||||
mod.ApplyToScoreProcessor(ScoreProcessor);
|
mod.ApplyToScoreProcessor(ScoreProcessor);
|
||||||
};
|
};
|
||||||
|
|
||||||
HealthProcessor.OnLoadComplete += _ =>
|
HealthProcessor.OnLoadComplete += _ =>
|
||||||
{
|
{
|
||||||
foreach (var mod in Mods.Value.OfType<IApplicableToHealthProcessor>())
|
foreach (var mod in gameplayMods.OfType<IApplicableToHealthProcessor>())
|
||||||
mod.ApplyToHealthProcessor(HealthProcessor);
|
mod.ApplyToHealthProcessor(HealthProcessor);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -356,7 +351,7 @@ namespace osu.Game.Screens.Play
|
|||||||
// display the cursor above some HUD elements.
|
// display the cursor above some HUD elements.
|
||||||
DrawableRuleset.Cursor?.CreateProxy() ?? new Container(),
|
DrawableRuleset.Cursor?.CreateProxy() ?? new Container(),
|
||||||
DrawableRuleset.ResumeOverlay?.CreateProxy() ?? new Container(),
|
DrawableRuleset.ResumeOverlay?.CreateProxy() ?? new Container(),
|
||||||
HUDOverlay = new HUDOverlay(DrawableRuleset, Mods.Value)
|
HUDOverlay = new HUDOverlay(DrawableRuleset, GameplayState.Mods)
|
||||||
{
|
{
|
||||||
HoldToQuit =
|
HoldToQuit =
|
||||||
{
|
{
|
||||||
@ -467,7 +462,7 @@ namespace osu.Game.Screens.Play
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private IBeatmap loadPlayableBeatmap()
|
private IBeatmap loadPlayableBeatmap(Mod[] gameplayMods)
|
||||||
{
|
{
|
||||||
IBeatmap playable;
|
IBeatmap playable;
|
||||||
|
|
||||||
@ -481,7 +476,7 @@ namespace osu.Game.Screens.Play
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
playable = Beatmap.Value.GetPlayableBeatmap(ruleset.RulesetInfo, Mods.Value);
|
playable = Beatmap.Value.GetPlayableBeatmap(ruleset.RulesetInfo, gameplayMods);
|
||||||
}
|
}
|
||||||
catch (BeatmapInvalidForRulesetException)
|
catch (BeatmapInvalidForRulesetException)
|
||||||
{
|
{
|
||||||
@ -489,7 +484,7 @@ namespace osu.Game.Screens.Play
|
|||||||
rulesetInfo = Beatmap.Value.BeatmapInfo.Ruleset;
|
rulesetInfo = Beatmap.Value.BeatmapInfo.Ruleset;
|
||||||
ruleset = rulesetInfo.CreateInstance();
|
ruleset = rulesetInfo.CreateInstance();
|
||||||
|
|
||||||
playable = Beatmap.Value.GetPlayableBeatmap(rulesetInfo, Mods.Value);
|
playable = Beatmap.Value.GetPlayableBeatmap(rulesetInfo, gameplayMods);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (playable.HitObjects.Count == 0)
|
if (playable.HitObjects.Count == 0)
|
||||||
@ -789,7 +784,7 @@ namespace osu.Game.Screens.Play
|
|||||||
|
|
||||||
failAnimation.Start();
|
failAnimation.Start();
|
||||||
|
|
||||||
if (Mods.Value.OfType<IApplicableFailOverride>().Any(m => m.RestartOnFail))
|
if (GameplayState.Mods.OfType<IApplicableFailOverride>().Any(m => m.RestartOnFail))
|
||||||
Restart();
|
Restart();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -919,17 +914,17 @@ namespace osu.Game.Screens.Play
|
|||||||
|
|
||||||
storyboardReplacesBackground.Value = Beatmap.Value.Storyboard.ReplacesBackground && Beatmap.Value.Storyboard.HasDrawable;
|
storyboardReplacesBackground.Value = Beatmap.Value.Storyboard.ReplacesBackground && Beatmap.Value.Storyboard.HasDrawable;
|
||||||
|
|
||||||
foreach (var mod in Mods.Value.OfType<IApplicableToPlayer>())
|
foreach (var mod in GameplayState.Mods.OfType<IApplicableToPlayer>())
|
||||||
mod.ApplyToPlayer(this);
|
mod.ApplyToPlayer(this);
|
||||||
|
|
||||||
foreach (var mod in Mods.Value.OfType<IApplicableToHUD>())
|
foreach (var mod in GameplayState.Mods.OfType<IApplicableToHUD>())
|
||||||
mod.ApplyToHUD(HUDOverlay);
|
mod.ApplyToHUD(HUDOverlay);
|
||||||
|
|
||||||
// Our mods are local copies of the global mods so they need to be re-applied to the track.
|
// Our mods are local copies of the global mods so they need to be re-applied to the track.
|
||||||
// This is done through the music controller (for now), because resetting speed adjustments on the beatmap track also removes adjustments provided by DrawableTrack.
|
// This is done through the music controller (for now), because resetting speed adjustments on the beatmap track also removes adjustments provided by DrawableTrack.
|
||||||
// Todo: In the future, player will receive in a track and will probably not have to worry about this...
|
// Todo: In the future, player will receive in a track and will probably not have to worry about this...
|
||||||
musicController.ResetTrackAdjustments();
|
musicController.ResetTrackAdjustments();
|
||||||
foreach (var mod in Mods.Value.OfType<IApplicableToTrack>())
|
foreach (var mod in GameplayState.Mods.OfType<IApplicableToTrack>())
|
||||||
mod.ApplyToTrack(musicController.CurrentTrack);
|
mod.ApplyToTrack(musicController.CurrentTrack);
|
||||||
|
|
||||||
updateGameplayState();
|
updateGameplayState();
|
||||||
|
Loading…
Reference in New Issue
Block a user