1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-14 17:52:56 +08:00

Refactor player score creation and submission process

This commit is contained in:
smoogipoo 2020-12-18 16:51:59 +09:00
parent c80ecec0b4
commit 2db7433c0b
4 changed files with 65 additions and 47 deletions

View File

@ -10,6 +10,7 @@ using osu.Framework.Timing;
using osu.Game.Beatmaps;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Scoring;
using osu.Game.Storyboards;
using osuTK;
@ -117,7 +118,7 @@ namespace osu.Game.Tests.Visual.Gameplay
{
}
protected override void GotoRanking()
protected override void GotoRanking(ScoreInfo score)
{
GotoRankingInvoked = true;
}

View File

@ -5,6 +5,7 @@ using System;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Logging;
@ -95,19 +96,25 @@ namespace osu.Game.Screens.Multi.Play
return new TimeshiftResultsScreen(score, roomId.Value.Value, playlistItem, true);
}
protected override ScoreInfo CreateScore()
protected override Score CreateScore()
{
var score = base.CreateScore();
score.TotalScore = (int)Math.Round(ScoreProcessor.GetStandardisedScore());
score.ScoreInfo.TotalScore = (int)Math.Round(ScoreProcessor.GetStandardisedScore());
return score;
}
protected override async Task<ScoreInfo> SubmitScore(Score score)
{
await base.SubmitScore(score);
Debug.Assert(token != null);
var request = new SubmitRoomScoreRequest(token.Value, roomId.Value ?? 0, playlistItem.ID, score);
request.Success += s => score.OnlineScoreID = s.ID;
var request = new SubmitRoomScoreRequest(token.Value, roomId.Value ?? 0, playlistItem.ID, score.ScoreInfo);
request.Success += s => score.ScoreInfo.OnlineScoreID = s.ID;
request.Failure += e => Logger.Error(e, "Failed to submit score");
api.Queue(request);
return score;
return score.ScoreInfo;
}
protected override void Dispose(bool isDisposing)

View File

@ -5,6 +5,7 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using JetBrains.Annotations;
using osu.Framework.Allocation;
using osu.Framework.Audio;
@ -527,8 +528,18 @@ namespace osu.Game.Screens.Play
if (!showResults) return;
using (BeginDelayedSequence(RESULTS_DISPLAY_DELAY))
completionProgressDelegate = Schedule(GotoRanking);
SubmitScore(CreateScore()).ContinueWith(t => Schedule(() =>
{
using (BeginDelayedSequence(RESULTS_DISPLAY_DELAY))
{
completionProgressDelegate = Schedule(() =>
{
// screen may be in the exiting transition phase.
if (this.IsCurrentScreen())
GotoRanking(t.Result);
});
}
}));
}
protected override bool OnScroll(ScrollEvent e) => mouseWheelDisabled.Value && !GameplayClockContainer.IsPaused.Value;
@ -727,60 +738,56 @@ namespace osu.Game.Screens.Play
return base.OnExiting(next);
}
protected virtual ScoreInfo CreateScore()
protected virtual Score CreateScore()
{
var score = new ScoreInfo
var score = new Score
{
Beatmap = Beatmap.Value.BeatmapInfo,
Ruleset = rulesetInfo,
Mods = Mods.Value.ToArray(),
ScoreInfo = new ScoreInfo
{
Beatmap = Beatmap.Value.BeatmapInfo,
Ruleset = rulesetInfo,
Mods = Mods.Value.ToArray(),
}
};
if (DrawableRuleset.ReplayScore != null)
score.User = DrawableRuleset.ReplayScore.ScoreInfo?.User ?? new GuestUser();
{
score.ScoreInfo.User = DrawableRuleset.ReplayScore.ScoreInfo?.User ?? new GuestUser();
score.Replay = DrawableRuleset.ReplayScore.Replay;
}
else
score.User = api.LocalUser.Value;
{
score.ScoreInfo.User = api.LocalUser.Value;
if (recordingScore?.Replay.Frames.Count > 0)
score.Replay = recordingScore.Replay;
}
ScoreProcessor.PopulateScore(score);
ScoreProcessor.PopulateScore(score.ScoreInfo);
return score;
}
protected virtual void GotoRanking()
protected virtual async Task<ScoreInfo> SubmitScore(Score score)
{
// Replays are already populated and present in the game's database, so should not be re-imported.
if (DrawableRuleset.ReplayScore != null)
return score.ScoreInfo;
LegacyByteArrayReader replayReader;
using (var stream = new MemoryStream())
{
// if a replay is present, we likely don't want to import into the local database.
this.Push(CreateResults(CreateScore()));
return;
new LegacyScoreEncoder(score, gameplayBeatmap.PlayableBeatmap).Encode(stream);
replayReader = new LegacyByteArrayReader(stream.ToArray(), "replay.osr");
}
LegacyByteArrayReader replayReader = null;
var score = new Score { ScoreInfo = CreateScore() };
if (recordingScore?.Replay.Frames.Count > 0)
{
score.Replay = recordingScore.Replay;
using (var stream = new MemoryStream())
{
new LegacyScoreEncoder(score, gameplayBeatmap.PlayableBeatmap).Encode(stream);
replayReader = new LegacyByteArrayReader(stream.ToArray(), "replay.osr");
}
}
scoreManager.Import(score.ScoreInfo, replayReader)
.ContinueWith(imported => Schedule(() =>
{
// screen may be in the exiting transition phase.
if (this.IsCurrentScreen())
this.Push(CreateResults(imported.Result));
}));
return await scoreManager.Import(score.ScoreInfo, replayReader);
}
protected virtual ResultsScreen CreateResults(ScoreInfo score) => new SoloResultsScreen(score, true);
protected virtual void GotoRanking(ScoreInfo score) => this.Push(CreateResults(score));
private void fadeOut(bool instant = false)
{
float fadeOutDuration = instant ? 0 : 250;

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.Threading.Tasks;
using osu.Framework.Input.Bindings;
using osu.Game.Input.Bindings;
using osu.Game.Scoring;
@ -26,18 +27,20 @@ namespace osu.Game.Screens.Play
DrawableRuleset?.SetReplayScore(Score);
}
protected override ResultsScreen CreateResults(ScoreInfo score) => new SoloResultsScreen(score, false);
protected override ScoreInfo CreateScore()
protected override Score CreateScore()
{
var baseScore = base.CreateScore();
// Since the replay score doesn't contain statistics, we'll pass them through here.
Score.ScoreInfo.HitEvents = baseScore.HitEvents;
Score.ScoreInfo.HitEvents = baseScore.ScoreInfo.HitEvents;
return Score.ScoreInfo;
return Score;
}
protected override Task<ScoreInfo> SubmitScore(Score score) => Task.FromResult(score.ScoreInfo);
protected override ResultsScreen CreateResults(ScoreInfo score) => new SoloResultsScreen(score, false);
public bool OnPressed(GlobalAction action)
{
switch (action)