Use GameplayState

This commit is contained in:
smoogipoo 2021-10-04 20:33:54 +09:00
parent 2e3450b3f5
commit 5aae673240
3 changed files with 18 additions and 12 deletions

View File

@ -7,6 +7,7 @@ using osu.Game.Beatmaps;
using osu.Game.Rulesets; using osu.Game.Rulesets;
using osu.Game.Rulesets.Judgements; using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Mods;
using osu.Game.Scoring;
#nullable enable #nullable enable
@ -32,6 +33,11 @@ namespace osu.Game.Screens.Play
/// </summary> /// </summary>
public readonly IReadOnlyList<Mod> Mods; public readonly IReadOnlyList<Mod> Mods;
/// <summary>
/// The gameplay score.
/// </summary>
public Score? Score { get; set; } = null;
/// <summary> /// <summary>
/// A bindable tracking the last judgement result applied to any hit object. /// A bindable tracking the last judgement result applied to any hit object.
/// </summary> /// </summary>

View File

@ -36,9 +36,9 @@ namespace osu.Game.Screens.Play.HUD
[Resolved(CanBeNull = true)] [Resolved(CanBeNull = true)]
private ScoreProcessor scoreProcessor { get; set; } private ScoreProcessor scoreProcessor { get; set; }
[Resolved]
[CanBeNull] [CanBeNull]
[Resolved(CanBeNull = true)] private GameplayState gameplayState { get; set; }
private Player player { get; set; }
private TimedDifficultyAttributes[] timedAttributes; private TimedDifficultyAttributes[] timedAttributes;
private Ruleset gameplayRuleset; private Ruleset gameplayRuleset;
@ -53,10 +53,10 @@ namespace osu.Game.Screens.Play.HUD
{ {
Colour = colours.BlueLighter; Colour = colours.BlueLighter;
if (player != null) if (gameplayState != null)
{ {
gameplayRuleset = player.GameplayRuleset; gameplayRuleset = gameplayState.Ruleset;
timedAttributes = gameplayRuleset.CreateDifficultyCalculator(new GameplayWorkingBeatmap(player.GameplayBeatmap)).CalculateTimed(player.Mods.Value.ToArray()).ToArray(); timedAttributes = gameplayRuleset.CreateDifficultyCalculator(new GameplayWorkingBeatmap(gameplayState.Beatmap)).CalculateTimed(gameplayState.Mods.ToArray()).ToArray();
} }
} }
@ -70,7 +70,7 @@ namespace osu.Game.Screens.Play.HUD
private void onNewJudgement(JudgementResult judgement) private void onNewJudgement(JudgementResult judgement)
{ {
if (player == null || timedAttributes.Length == 0) if (gameplayState?.Score == null || timedAttributes.Length == 0)
return; return;
var attribIndex = Array.BinarySearch(timedAttributes, 0, timedAttributes.Length, new TimedDifficultyAttributes(judgement.HitObject.GetEndTime(), null)); var attribIndex = Array.BinarySearch(timedAttributes, 0, timedAttributes.Length, new TimedDifficultyAttributes(judgement.HitObject.GetEndTime(), null));
@ -78,7 +78,7 @@ namespace osu.Game.Screens.Play.HUD
attribIndex = ~attribIndex - 1; attribIndex = ~attribIndex - 1;
attribIndex = Math.Clamp(attribIndex, 0, timedAttributes.Length - 1); attribIndex = Math.Clamp(attribIndex, 0, timedAttributes.Length - 1);
var ppProcessor = gameplayRuleset.CreatePerformanceCalculator(timedAttributes[attribIndex].Attributes, player.Score.ScoreInfo); var ppProcessor = gameplayRuleset.CreatePerformanceCalculator(timedAttributes[attribIndex].Attributes, gameplayState.Score.ScoreInfo);
Current.Value = (int)(ppProcessor?.Calculate() ?? 0); Current.Value = (int)(ppProcessor?.Calculate() ?? 0);
} }
@ -134,18 +134,18 @@ namespace osu.Game.Screens.Play.HUD
private class GameplayWorkingBeatmap : WorkingBeatmap private class GameplayWorkingBeatmap : WorkingBeatmap
{ {
private readonly GameplayBeatmap gameplayBeatmap; private readonly IBeatmap gameplayBeatmap;
public GameplayWorkingBeatmap(GameplayBeatmap gameplayBeatmap) public GameplayWorkingBeatmap(IBeatmap gameplayBeatmap)
: base(gameplayBeatmap.BeatmapInfo, null) : base(gameplayBeatmap.BeatmapInfo, null)
{ {
this.gameplayBeatmap = gameplayBeatmap; this.gameplayBeatmap = gameplayBeatmap;
} }
public override IBeatmap GetPlayableBeatmap(RulesetInfo ruleset, IReadOnlyList<Mod> mods = null, TimeSpan? timeout = null) public override IBeatmap GetPlayableBeatmap(RulesetInfo ruleset, IReadOnlyList<Mod> mods = null, TimeSpan? timeout = null)
=> gameplayBeatmap.PlayableBeatmap; => gameplayBeatmap;
protected override IBeatmap GetBeatmap() => gameplayBeatmap.PlayableBeatmap; protected override IBeatmap GetBeatmap() => gameplayBeatmap;
protected override Texture GetBackground() => throw new NotImplementedException(); protected override Texture GetBackground() => throw new NotImplementedException();

View File

@ -127,7 +127,7 @@ namespace osu.Game.Screens.Play
[Cached] [Cached]
[Cached(Type = typeof(IBindable<IReadOnlyList<Mod>>))] [Cached(Type = typeof(IBindable<IReadOnlyList<Mod>>))]
public new readonly Bindable<IReadOnlyList<Mod>> Mods = new Bindable<IReadOnlyList<Mod>>(Array.Empty<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.