1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 23:12:56 +08:00

Make GameplayState.Score immutable

This commit is contained in:
Dean Herbert 2021-10-05 14:48:10 +09:00
parent 5624dd9af6
commit e19be8ebe4
4 changed files with 18 additions and 15 deletions

View File

@ -1,6 +1,7 @@
// 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;
using System.Collections.Generic;
using osu.Framework.Bindables;
using osu.Game.Beatmaps;
@ -36,7 +37,7 @@ namespace osu.Game.Screens.Play
/// <summary>
/// The gameplay score.
/// </summary>
public Score? Score { get; set; }
public readonly Score Score;
/// <summary>
/// A bindable tracking the last judgement result applied to any hit object.
@ -45,11 +46,12 @@ namespace osu.Game.Screens.Play
private readonly Bindable<JudgementResult> lastJudgementResult = new Bindable<JudgementResult>();
public GameplayState(IBeatmap beatmap, Ruleset ruleset, IReadOnlyList<Mod> mods)
public GameplayState(IBeatmap beatmap, Ruleset ruleset, IReadOnlyList<Mod>? mods = null, Score? score = null)
{
Beatmap = beatmap;
Ruleset = ruleset;
Mods = mods;
Score = score ?? new Score();
Mods = mods ?? ArraySegment<Mod>.Empty;
}
/// <summary>

View File

@ -161,14 +161,6 @@ namespace osu.Game.Screens.Play
if (!LoadedBeatmapSuccessfully)
return;
Score = CreateScore();
GameplayState.Score = Score;
// ensure the score is in a consistent state with the current player.
Score.ScoreInfo.BeatmapInfo = Beatmap.Value.BeatmapInfo;
Score.ScoreInfo.Ruleset = ruleset.RulesetInfo;
Score.ScoreInfo.Mods = Mods.Value.ToArray();
PrepareReplay();
ScoreProcessor.NewJudgement += result => ScoreProcessor.PopulateScore(Score.ScoreInfo);
@ -226,7 +218,14 @@ namespace osu.Game.Screens.Play
InternalChild = GameplayClockContainer = CreateGameplayClockContainer(Beatmap.Value, DrawableRuleset.GameplayStartTime);
dependencies.CacheAs(GameplayState = new GameplayState(playableBeatmap, ruleset, Mods.Value));
Score = CreateScore(playableBeatmap);
// ensure the score is in a consistent state with the current player.
Score.ScoreInfo.BeatmapInfo = Beatmap.Value.BeatmapInfo;
Score.ScoreInfo.Ruleset = ruleset.RulesetInfo;
Score.ScoreInfo.Mods = Mods.Value.ToArray();
dependencies.CacheAs(GameplayState = new GameplayState(playableBeatmap, ruleset, Mods.Value, Score));
AddInternal(screenSuspension = new ScreenSuspensionHandler(GameplayClockContainer));
@ -989,8 +988,9 @@ namespace osu.Game.Screens.Play
/// <summary>
/// Creates the player's <see cref="Scoring.Score"/>.
/// </summary>
/// <param name="beatmap"></param>
/// <returns>The <see cref="Scoring.Score"/>.</returns>
protected virtual Score CreateScore() => new Score
protected virtual Score CreateScore(IBeatmap beatmap) => new Score
{
ScoreInfo = new ScoreInfo { User = api.LocalUser.Value },
};

View File

@ -41,7 +41,7 @@ namespace osu.Game.Screens.Play
DrawableRuleset?.SetReplayScore(Score);
}
protected override Score CreateScore() => createScore(GameplayState.Beatmap, Mods.Value);
protected override Score CreateScore(IBeatmap beatmap) => createScore(beatmap, Mods.Value);
// Don't re-import replay scores as they're already present in the database.
protected override Task ImportScore(Score score) => Task.CompletedTask;

View File

@ -4,6 +4,7 @@
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Screens;
using osu.Game.Beatmaps;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Online.Spectator;
@ -79,7 +80,7 @@ namespace osu.Game.Screens.Play
NonFrameStableSeek(score.Replay.Frames[0].Time);
}
protected override Score CreateScore() => score;
protected override Score CreateScore(IBeatmap beatmap) => score;
protected override ResultsScreen CreateResults(ScoreInfo score)
=> new SpectatorResultsScreen(score);