From b8e60afa6961b0851b557dbab77808468a65d2a7 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Wed, 28 Nov 2018 18:45:17 +0900 Subject: [PATCH] Move replays to an wrapping Score class --- .../Mods/CatchModAutoplay.cs | 11 ++-- .../Mods/ManiaModAutoplay.cs | 11 ++-- osu.Game.Rulesets.Osu/Mods/OsuModAutoplay.cs | 9 +-- .../Mods/TaikoModAutoplay.cs | 11 ++-- .../API/Requests/Responses/APIScoreInfo.cs | 7 --- osu.Game/OsuGame.cs | 2 +- osu.Game/Rulesets/Mods/ModAutoplay.cs | 2 +- osu.Game/Scoring/Legacy/LegacyScoreParser.cs | 57 ++++++++++--------- osu.Game/Scoring/LegacyDatabasedScore.cs | 25 ++++++++ osu.Game/Scoring/Score.cs | 13 +++++ osu.Game/Scoring/ScoreInfo.cs | 4 -- osu.Game/Scoring/ScoreManager.cs | 6 +- 12 files changed, 88 insertions(+), 70 deletions(-) create mode 100644 osu.Game/Scoring/LegacyDatabasedScore.cs create mode 100644 osu.Game/Scoring/Score.cs diff --git a/osu.Game.Rulesets.Catch/Mods/CatchModAutoplay.cs b/osu.Game.Rulesets.Catch/Mods/CatchModAutoplay.cs index 2b8324d327..8bba73ed64 100644 --- a/osu.Game.Rulesets.Catch/Mods/CatchModAutoplay.cs +++ b/osu.Game.Rulesets.Catch/Mods/CatchModAutoplay.cs @@ -12,13 +12,10 @@ namespace osu.Game.Rulesets.Catch.Mods { public class CatchModAutoplay : ModAutoplay { - protected override ScoreInfo CreateReplayScore(Beatmap beatmap) + protected override Score CreateReplayScore(Beatmap beatmap) => new Score { - return new ScoreInfo - { - User = new User { Username = "osu!salad!" }, - Replay = new CatchAutoGenerator(beatmap).Generate(), - }; - } + ScoreInfo = new ScoreInfo { User = new User { Username = "osu!salad!" } }, + Replay = new CatchAutoGenerator(beatmap).Generate(), + }; } } diff --git a/osu.Game.Rulesets.Mania/Mods/ManiaModAutoplay.cs b/osu.Game.Rulesets.Mania/Mods/ManiaModAutoplay.cs index 1629a3916d..f53943ec85 100644 --- a/osu.Game.Rulesets.Mania/Mods/ManiaModAutoplay.cs +++ b/osu.Game.Rulesets.Mania/Mods/ManiaModAutoplay.cs @@ -13,13 +13,10 @@ namespace osu.Game.Rulesets.Mania.Mods { public class ManiaModAutoplay : ModAutoplay { - protected override ScoreInfo CreateReplayScore(Beatmap beatmap) + protected override Score CreateReplayScore(Beatmap beatmap) => new Score { - return new ScoreInfo - { - User = new User { Username = "osu!topus!" }, - Replay = new ManiaAutoGenerator((ManiaBeatmap)beatmap).Generate(), - }; - } + ScoreInfo = new ScoreInfo { User = new User { Username = "osu!topus!" } }, + Replay = new ManiaAutoGenerator((ManiaBeatmap)beatmap).Generate(), + }; } } diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModAutoplay.cs b/osu.Game.Rulesets.Osu/Mods/OsuModAutoplay.cs index c998f36792..ce5d3dae44 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModAutoplay.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModAutoplay.cs @@ -15,12 +15,9 @@ namespace osu.Game.Rulesets.Osu.Mods { public override Type[] IncompatibleMods => base.IncompatibleMods.Append(typeof(OsuModAutopilot)).Append(typeof(OsuModSpunOut)).ToArray(); - protected override ScoreInfo CreateReplayScore(Beatmap beatmap) + protected override Score CreateReplayScore(Beatmap beatmap) => new Score { - return new ScoreInfo - { - Replay = new OsuAutoGenerator(beatmap).Generate() - }; - } + Replay = new OsuAutoGenerator(beatmap).Generate() + }; } } diff --git a/osu.Game.Rulesets.Taiko/Mods/TaikoModAutoplay.cs b/osu.Game.Rulesets.Taiko/Mods/TaikoModAutoplay.cs index ff64ecf1bd..62111ae74a 100644 --- a/osu.Game.Rulesets.Taiko/Mods/TaikoModAutoplay.cs +++ b/osu.Game.Rulesets.Taiko/Mods/TaikoModAutoplay.cs @@ -12,13 +12,10 @@ namespace osu.Game.Rulesets.Taiko.Mods { public class TaikoModAutoplay : ModAutoplay { - protected override ScoreInfo CreateReplayScore(Beatmap beatmap) + protected override Score CreateReplayScore(Beatmap beatmap) => new Score { - return new ScoreInfo - { - User = new User { Username = "mekkadosu!" }, - Replay = new TaikoAutoGenerator(beatmap).Generate(), - }; - } + ScoreInfo = new ScoreInfo { User = new User { Username = "mekkadosu!" } }, + Replay = new TaikoAutoGenerator(beatmap).Generate(), + }; } } diff --git a/osu.Game/Online/API/Requests/Responses/APIScoreInfo.cs b/osu.Game/Online/API/Requests/Responses/APIScoreInfo.cs index bea0c94920..19f8206667 100644 --- a/osu.Game/Online/API/Requests/Responses/APIScoreInfo.cs +++ b/osu.Game/Online/API/Requests/Responses/APIScoreInfo.cs @@ -6,7 +6,6 @@ using System.Collections.Generic; using System.Linq; using Newtonsoft.Json; using osu.Game.Beatmaps; -using osu.Game.Replays; using osu.Game.Rulesets; using osu.Game.Rulesets.Scoring; using osu.Game.Scoring; @@ -34,12 +33,6 @@ namespace osu.Game.Online.API.Requests.Responses set => User = value; } - [JsonProperty(@"replay_data")] - private Replay replay - { - set => Replay = value; - } - [JsonProperty(@"mode_int")] public int OnlineRulesetID { get; set; } diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index 2600d4f814..9d22ecc220 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -282,7 +282,7 @@ namespace osu.Game Beatmap.Value = BeatmapManager.GetWorkingBeatmap(scoreInfo.BeatmapInfo); Beatmap.Value.Mods.Value = scoreInfo.Mods; - menu.Push(new PlayerLoader(new ReplayPlayer(scoreInfo.Replay))); + menu.Push(new PlayerLoader(new ReplayPlayer(ScoreManager.GetScore(scoreInfo).Replay))); } protected override void Dispose(bool isDisposing) diff --git a/osu.Game/Rulesets/Mods/ModAutoplay.cs b/osu.Game/Rulesets/Mods/ModAutoplay.cs index 70d31c8480..3f3cab5854 100644 --- a/osu.Game/Rulesets/Mods/ModAutoplay.cs +++ b/osu.Game/Rulesets/Mods/ModAutoplay.cs @@ -14,7 +14,7 @@ namespace osu.Game.Rulesets.Mods public abstract class ModAutoplay : ModAutoplay, IApplicableToRulesetContainer where T : HitObject { - protected virtual ScoreInfo CreateReplayScore(Beatmap beatmap) => new ScoreInfo { Replay = new Replay() }; + protected virtual Score CreateReplayScore(Beatmap beatmap) => new Score { Replay = new Replay() }; public override bool HasImplementation => GetType().GenericTypeArguments.Length == 0; diff --git a/osu.Game/Scoring/Legacy/LegacyScoreParser.cs b/osu.Game/Scoring/Legacy/LegacyScoreParser.cs index 1e65218af3..f17873df89 100644 --- a/osu.Game/Scoring/Legacy/LegacyScoreParser.cs +++ b/osu.Game/Scoring/Legacy/LegacyScoreParser.cs @@ -22,22 +22,26 @@ namespace osu.Game.Scoring.Legacy private IBeatmap currentBeatmap; private Ruleset currentRuleset; - public ScoreInfo Parse(Stream stream) + public Score Parse(Stream stream) { - ScoreInfo scoreInfo; + var score = new Score + { + ScoreInfo = new ScoreInfo(), + Replay = new Replay() + }; using (SerializationReader sr = new SerializationReader(stream)) { currentRuleset = GetRuleset(sr.ReadByte()); - scoreInfo = new ScoreInfo { Ruleset = currentRuleset.RulesetInfo }; + score.ScoreInfo = new ScoreInfo { Ruleset = currentRuleset.RulesetInfo }; var version = sr.ReadInt32(); currentBeatmap = GetBeatmap(sr.ReadString()).Beatmap; - scoreInfo.BeatmapInfo = currentBeatmap.BeatmapInfo; + score.ScoreInfo.BeatmapInfo = currentBeatmap.BeatmapInfo; - scoreInfo.User = new User { Username = sr.ReadString() }; - scoreInfo.MD5Hash = sr.ReadString(); + score.ScoreInfo.User = score.Replay.User = new User { Username = sr.ReadString() }; + score.ScoreInfo.MD5Hash = sr.ReadString(); var count300 = sr.ReadUInt16(); var count100 = sr.ReadUInt16(); @@ -46,57 +50,57 @@ namespace osu.Game.Scoring.Legacy var countKatu = sr.ReadUInt16(); var countMiss = sr.ReadUInt16(); - scoreInfo.Statistics[HitResult.Great] = count300; - scoreInfo.Statistics[HitResult.Good] = count100; - scoreInfo.Statistics[HitResult.Meh] = count50; - scoreInfo.Statistics[HitResult.Perfect] = countGeki; - scoreInfo.Statistics[HitResult.Ok] = countKatu; - scoreInfo.Statistics[HitResult.Miss] = countMiss; + score.ScoreInfo.Statistics[HitResult.Great] = count300; + score.ScoreInfo.Statistics[HitResult.Good] = count100; + score.ScoreInfo.Statistics[HitResult.Meh] = count50; + score.ScoreInfo.Statistics[HitResult.Perfect] = countGeki; + score.ScoreInfo.Statistics[HitResult.Ok] = countKatu; + score.ScoreInfo.Statistics[HitResult.Miss] = countMiss; - scoreInfo.TotalScore = sr.ReadInt32(); - scoreInfo.MaxCombo = sr.ReadUInt16(); + score.ScoreInfo.TotalScore = sr.ReadInt32(); + score.ScoreInfo.MaxCombo = sr.ReadUInt16(); /* score.Perfect = */ sr.ReadBoolean(); - scoreInfo.Mods = currentRuleset.ConvertLegacyMods((LegacyMods)sr.ReadInt32()).ToArray(); + score.ScoreInfo.Mods = currentRuleset.ConvertLegacyMods((LegacyMods)sr.ReadInt32()).ToArray(); /* score.HpGraphString = */ sr.ReadString(); - scoreInfo.Date = sr.ReadDateTime(); + score.ScoreInfo.Date = sr.ReadDateTime(); var compressedReplay = sr.ReadByteArray(); if (version >= 20140721) - scoreInfo.OnlineScoreID = sr.ReadInt64(); + score.ScoreInfo.OnlineScoreID = sr.ReadInt64(); else if (version >= 20121008) - scoreInfo.OnlineScoreID = sr.ReadInt32(); + score.ScoreInfo.OnlineScoreID = sr.ReadInt32(); - switch (scoreInfo.Ruleset.ID) + switch (score.ScoreInfo.Ruleset.ID) { case 0: { int totalHits = count50 + count100 + count300 + countMiss; - scoreInfo.Accuracy = totalHits > 0 ? (double)(count50 * 50 + count100 * 100 + count300 * 300) / (totalHits * 300) : 1; + score.ScoreInfo.Accuracy = totalHits > 0 ? (double)(count50 * 50 + count100 * 100 + count300 * 300) / (totalHits * 300) : 1; break; } case 1: { int totalHits = count50 + count100 + count300 + countMiss; - scoreInfo.Accuracy = totalHits > 0 ? (double)(count100 * 150 + count300 * 300) / (totalHits * 300) : 1; + score.ScoreInfo.Accuracy = totalHits > 0 ? (double)(count100 * 150 + count300 * 300) / (totalHits * 300) : 1; break; } case 2: { int totalHits = count50 + count100 + count300 + countMiss + countKatu; - scoreInfo.Accuracy = totalHits > 0 ? (double)(count50 + count100 + count300 ) / totalHits : 1; + score.ScoreInfo.Accuracy = totalHits > 0 ? (double)(count50 + count100 + count300 ) / totalHits : 1; break; } case 3: { int totalHits = count50 + count100 + count300 + countMiss + countGeki + countKatu; - scoreInfo.Accuracy = totalHits > 0 ? (double)(count50 * 50 + count100 * 100 + countKatu * 200 + (count300 + countGeki) * 300) / (totalHits * 300) : 1; + score.ScoreInfo.Accuracy = totalHits > 0 ? (double)(count50 * 50 + count100 * 100 + countKatu * 200 + (count300 + countGeki) * 300) / (totalHits * 300) : 1; break; } } @@ -119,14 +123,11 @@ namespace osu.Game.Scoring.Legacy using (var lzma = new LzmaStream(properties, replayInStream, compressedSize, outSize)) using (var reader = new StreamReader(lzma)) - { - scoreInfo.Replay = new Replay { User = scoreInfo.User }; - readLegacyReplay(scoreInfo.Replay, reader); - } + readLegacyReplay(score.Replay, reader); } } - return scoreInfo; + return score; } private void readLegacyReplay(Replay replay, StreamReader reader) diff --git a/osu.Game/Scoring/LegacyDatabasedScore.cs b/osu.Game/Scoring/LegacyDatabasedScore.cs new file mode 100644 index 0000000000..29996d5c01 --- /dev/null +++ b/osu.Game/Scoring/LegacyDatabasedScore.cs @@ -0,0 +1,25 @@ +// Copyright (c) 2007-2018 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using System; +using System.Linq; +using osu.Framework.IO.Stores; +using osu.Game.Beatmaps; +using osu.Game.Rulesets; +using osu.Game.Scoring.Legacy; + +namespace osu.Game.Scoring +{ + public class LegacyDatabasedScore : Score + { + public LegacyDatabasedScore(ScoreInfo scoreInfo, RulesetStore rulesets, BeatmapManager beatmaps, IResourceStore store) + { + ScoreInfo = scoreInfo; + + var replayFilename = scoreInfo.Files.First(f => f.Filename.EndsWith(".osr", StringComparison.InvariantCultureIgnoreCase)).FileInfo.StoragePath; + + using (var stream = store.GetStream(replayFilename)) + Replay = new DatabasedLegacyScoreParser(rulesets, beatmaps).Parse(stream).Replay; + } + } +} diff --git a/osu.Game/Scoring/Score.cs b/osu.Game/Scoring/Score.cs new file mode 100644 index 0000000000..ffbee920cb --- /dev/null +++ b/osu.Game/Scoring/Score.cs @@ -0,0 +1,13 @@ +// Copyright (c) 2007-2018 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Game.Replays; + +namespace osu.Game.Scoring +{ + public class Score + { + public ScoreInfo ScoreInfo = new ScoreInfo(); + public Replay Replay = new Replay(); + } +} diff --git a/osu.Game/Scoring/ScoreInfo.cs b/osu.Game/Scoring/ScoreInfo.cs index 84657a729d..9c4d196a04 100644 --- a/osu.Game/Scoring/ScoreInfo.cs +++ b/osu.Game/Scoring/ScoreInfo.cs @@ -9,7 +9,6 @@ using JetBrains.Annotations; using Newtonsoft.Json; using osu.Game.Beatmaps; using osu.Game.Database; -using osu.Game.Replays; using osu.Game.Rulesets; using osu.Game.Rulesets.Mods; using osu.Game.Users; @@ -64,9 +63,6 @@ namespace osu.Game.Scoring set => User = new User { Username = value }; } - [JsonIgnore] - public Replay Replay; - public int BeatmapInfoID { get; set; } public BeatmapInfo BeatmapInfo; diff --git a/osu.Game/Scoring/ScoreManager.cs b/osu.Game/Scoring/ScoreManager.cs index b9c77288ff..eec23ba48c 100644 --- a/osu.Game/Scoring/ScoreManager.cs +++ b/osu.Game/Scoring/ScoreManager.cs @@ -41,7 +41,7 @@ namespace osu.Game.Scoring return null; using (var stream = archive.GetStream(archive.Filenames.First(f => f.EndsWith(".osr")))) - return new DatabasedLegacyScoreParser(rulesets, beatmaps).Parse(stream); + return new DatabasedLegacyScoreParser(rulesets, beatmaps).Parse(stream).ScoreInfo; } protected override ScoreInfo CheckForExisting(ScoreInfo model) @@ -56,7 +56,9 @@ namespace osu.Game.Scoring return null; } - public List GetAllScores() => ModelStore.ConsumableItems.Where(s => !s.DeletePending).ToList(); + public Score GetScore(ScoreInfo scoreInfo) => new LegacyDatabasedScore(scoreInfo, rulesets, beatmaps, Files.Store); + + public List GetAllUsableScores() => ModelStore.ConsumableItems.Where(s => !s.DeletePending).ToList(); public ScoreInfo Query(Expression> query) => ModelStore.ConsumableItems.AsNoTracking().FirstOrDefault(query); }