/// <summary> /// Imports the player's <see cref="Scoring.Score"/> to the local database. /// </summary> /// <param name="score">The <see cref="Scoring.Score"/> to import.</param> /// <returns>The imported score.</returns> protected virtual async Task ImportScore(Score score) { // Replays are already populated and present in the game's database, so should not be re-imported. if (DrawableRuleset.ReplayScore != null) { return; } LegacyByteArrayReader replayReader; using (var stream = new MemoryStream()) { new LegacyScoreEncoder(score, GameplayBeatmap.PlayableBeatmap).Encode(stream); replayReader = new LegacyByteArrayReader(stream.ToArray(), "replay.osr"); } // For the time being, online ID responses are not really useful for anything. // In addition, the IDs provided via new (lazer) endpoints are based on a different autoincrement from legacy (stable) scores. // // Until we better define the server-side logic behind this, let's not store the online ID to avoid potential unique constraint // conflicts across various systems (ie. solo and multiplayer). long?onlineScoreId = score.ScoreInfo.OnlineScoreID; score.ScoreInfo.OnlineScoreID = null; await scoreManager.Import(score.ScoreInfo, replayReader).ConfigureAwait(false); // ... And restore the online ID for other processes to handle correctly (e.g. de-duplication for the results screen). score.ScoreInfo.OnlineScoreID = onlineScoreId; }
/// <summary> /// Imports the player's <see cref="Score"/> to the local database. /// </summary> /// <param name="score">The <see cref="Score"/> to import.</param> /// <returns>The imported score.</returns> protected virtual Task ImportScore(Score score) { // Replays are already populated and present in the game's database, so should not be re-imported. if (DrawableRuleset.ReplayScore != null) { return(Task.CompletedTask); } LegacyByteArrayReader replayReader; using (var stream = new MemoryStream()) { new LegacyScoreEncoder(score, gameplayBeatmap.PlayableBeatmap).Encode(stream); replayReader = new LegacyByteArrayReader(stream.ToArray(), "replay.osr"); } return(scoreManager.Import(score.ScoreInfo, replayReader)); }
private Task <ScoreInfo> saveScore() { LegacyByteArrayReader replayReader = null; var score = new Score { ScoreInfo = CreateScore() }; if (recordingReplay?.Frames.Count > 0) { score.Replay = recordingReplay; using (var stream = new MemoryStream()) { new LegacyScoreEncoder(score, gameplayBeatmap.PlayableBeatmap).Encode(stream); replayReader = new LegacyByteArrayReader(stream.ToArray(), "replay.osr"); } } return(scoreManager.Import(score.ScoreInfo, replayReader)); }
/// <summary> /// Imports the player's <see cref="Scoring.Score"/> to the local database. /// </summary> /// <param name="score">The <see cref="Scoring.Score"/> to import.</param> /// <returns>The imported score.</returns> protected virtual Task ImportScore(Score score) { // Replays are already populated and present in the game's database, so should not be re-imported. if (DrawableRuleset.ReplayScore != null) { return(Task.CompletedTask); } LegacyByteArrayReader replayReader; using (var stream = new MemoryStream()) { new LegacyScoreEncoder(score, GameplayState.Beatmap).Encode(stream); replayReader = new LegacyByteArrayReader(stream.ToArray(), "replay.osr"); } // the import process will re-attach managed beatmap/rulesets to this score. we don't want this for now, so create a temporary copy to import. var importableScore = score.ScoreInfo.DeepClone(); // For the time being, online ID responses are not really useful for anything. // In addition, the IDs provided via new (lazer) endpoints are based on a different autoincrement from legacy (stable) scores. // // Until we better define the server-side logic behind this, let's not store the online ID to avoid potential unique constraint // conflicts across various systems (ie. solo and multiplayer). importableScore.OnlineID = -1; var imported = scoreManager.Import(importableScore, replayReader); imported.PerformRead(s => { // because of the clone above, it's required that we copy back the post-import hash/ID to use for availability matching. score.ScoreInfo.Hash = s.Hash; score.ScoreInfo.ID = s.ID; }); return(Task.CompletedTask); }
protected virtual void GotoRanking() { if (DrawableRuleset.ReplayScore != null) { // if a replay is present, we likely don't want to import into the local database. this.Push(CreateResults(CreateScore())); return; } LegacyByteArrayReader replayReader = null; var score = new Score { ScoreInfo = CreateScore() }; if (recordingReplay?.Frames.Count > 0) { score.Replay = recordingReplay; 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)); } })); }