mirror of
https://github.com/osukey/osukey.git
synced 2025-05-05 21:57:24 +09:00
Refactor player score creation and submission process
This commit is contained in:
parent
c80ecec0b4
commit
2db7433c0b
@ -10,6 +10,7 @@ using osu.Framework.Timing;
|
|||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
using osu.Game.Rulesets;
|
using osu.Game.Rulesets;
|
||||||
using osu.Game.Rulesets.Osu.Objects;
|
using osu.Game.Rulesets.Osu.Objects;
|
||||||
|
using osu.Game.Scoring;
|
||||||
using osu.Game.Storyboards;
|
using osu.Game.Storyboards;
|
||||||
using osuTK;
|
using osuTK;
|
||||||
|
|
||||||
@ -117,7 +118,7 @@ namespace osu.Game.Tests.Visual.Gameplay
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void GotoRanking()
|
protected override void GotoRanking(ScoreInfo score)
|
||||||
{
|
{
|
||||||
GotoRankingInvoked = true;
|
GotoRankingInvoked = true;
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ using System;
|
|||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Logging;
|
using osu.Framework.Logging;
|
||||||
@ -95,19 +96,25 @@ namespace osu.Game.Screens.Multi.Play
|
|||||||
return new TimeshiftResultsScreen(score, roomId.Value.Value, playlistItem, true);
|
return new TimeshiftResultsScreen(score, roomId.Value.Value, playlistItem, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override ScoreInfo CreateScore()
|
protected override Score CreateScore()
|
||||||
{
|
{
|
||||||
var score = base.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);
|
Debug.Assert(token != null);
|
||||||
|
|
||||||
var request = new SubmitRoomScoreRequest(token.Value, roomId.Value ?? 0, playlistItem.ID, score);
|
var request = new SubmitRoomScoreRequest(token.Value, roomId.Value ?? 0, playlistItem.ID, score.ScoreInfo);
|
||||||
request.Success += s => score.OnlineScoreID = s.ID;
|
request.Success += s => score.ScoreInfo.OnlineScoreID = s.ID;
|
||||||
request.Failure += e => Logger.Error(e, "Failed to submit score");
|
request.Failure += e => Logger.Error(e, "Failed to submit score");
|
||||||
api.Queue(request);
|
api.Queue(request);
|
||||||
|
|
||||||
return score;
|
return score.ScoreInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Dispose(bool isDisposing)
|
protected override void Dispose(bool isDisposing)
|
||||||
|
@ -5,6 +5,7 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Audio;
|
using osu.Framework.Audio;
|
||||||
@ -527,8 +528,18 @@ namespace osu.Game.Screens.Play
|
|||||||
|
|
||||||
if (!showResults) return;
|
if (!showResults) return;
|
||||||
|
|
||||||
|
SubmitScore(CreateScore()).ContinueWith(t => Schedule(() =>
|
||||||
|
{
|
||||||
using (BeginDelayedSequence(RESULTS_DISPLAY_DELAY))
|
using (BeginDelayedSequence(RESULTS_DISPLAY_DELAY))
|
||||||
completionProgressDelegate = Schedule(GotoRanking);
|
{
|
||||||
|
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;
|
protected override bool OnScroll(ScrollEvent e) => mouseWheelDisabled.Value && !GameplayClockContainer.IsPaused.Value;
|
||||||
@ -727,60 +738,56 @@ namespace osu.Game.Screens.Play
|
|||||||
return base.OnExiting(next);
|
return base.OnExiting(next);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual ScoreInfo CreateScore()
|
protected virtual Score CreateScore()
|
||||||
{
|
{
|
||||||
var score = new ScoreInfo
|
var score = new Score
|
||||||
|
{
|
||||||
|
ScoreInfo = new ScoreInfo
|
||||||
{
|
{
|
||||||
Beatmap = Beatmap.Value.BeatmapInfo,
|
Beatmap = Beatmap.Value.BeatmapInfo,
|
||||||
Ruleset = rulesetInfo,
|
Ruleset = rulesetInfo,
|
||||||
Mods = Mods.Value.ToArray(),
|
Mods = Mods.Value.ToArray(),
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (DrawableRuleset.ReplayScore != null)
|
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
|
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;
|
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)
|
if (DrawableRuleset.ReplayScore != null)
|
||||||
{
|
return score.ScoreInfo;
|
||||||
// if a replay is present, we likely don't want to import into the local database.
|
|
||||||
this.Push(CreateResults(CreateScore()));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
LegacyByteArrayReader replayReader = null;
|
LegacyByteArrayReader replayReader;
|
||||||
|
|
||||||
var score = new Score { ScoreInfo = CreateScore() };
|
|
||||||
|
|
||||||
if (recordingScore?.Replay.Frames.Count > 0)
|
|
||||||
{
|
|
||||||
score.Replay = recordingScore.Replay;
|
|
||||||
|
|
||||||
using (var stream = new MemoryStream())
|
using (var stream = new MemoryStream())
|
||||||
{
|
{
|
||||||
new LegacyScoreEncoder(score, gameplayBeatmap.PlayableBeatmap).Encode(stream);
|
new LegacyScoreEncoder(score, gameplayBeatmap.PlayableBeatmap).Encode(stream);
|
||||||
replayReader = new LegacyByteArrayReader(stream.ToArray(), "replay.osr");
|
replayReader = new LegacyByteArrayReader(stream.ToArray(), "replay.osr");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
scoreManager.Import(score.ScoreInfo, replayReader)
|
return await scoreManager.Import(score.ScoreInfo, replayReader);
|
||||||
.ContinueWith(imported => Schedule(() =>
|
|
||||||
{
|
|
||||||
// screen may be in the exiting transition phase.
|
|
||||||
if (this.IsCurrentScreen())
|
|
||||||
this.Push(CreateResults(imported.Result));
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual ResultsScreen CreateResults(ScoreInfo score) => new SoloResultsScreen(score, true);
|
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)
|
private void fadeOut(bool instant = false)
|
||||||
{
|
{
|
||||||
float fadeOutDuration = instant ? 0 : 250;
|
float fadeOutDuration = instant ? 0 : 250;
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using System.Threading.Tasks;
|
||||||
using osu.Framework.Input.Bindings;
|
using osu.Framework.Input.Bindings;
|
||||||
using osu.Game.Input.Bindings;
|
using osu.Game.Input.Bindings;
|
||||||
using osu.Game.Scoring;
|
using osu.Game.Scoring;
|
||||||
@ -26,18 +27,20 @@ namespace osu.Game.Screens.Play
|
|||||||
DrawableRuleset?.SetReplayScore(Score);
|
DrawableRuleset?.SetReplayScore(Score);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override ResultsScreen CreateResults(ScoreInfo score) => new SoloResultsScreen(score, false);
|
protected override Score CreateScore()
|
||||||
|
|
||||||
protected override ScoreInfo CreateScore()
|
|
||||||
{
|
{
|
||||||
var baseScore = base.CreateScore();
|
var baseScore = base.CreateScore();
|
||||||
|
|
||||||
// Since the replay score doesn't contain statistics, we'll pass them through here.
|
// 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)
|
public bool OnPressed(GlobalAction action)
|
||||||
{
|
{
|
||||||
switch (action)
|
switch (action)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user