1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-13 08:32:57 +08:00

Move replays to an wrapping Score class

This commit is contained in:
smoogipoo 2018-11-28 18:45:17 +09:00
parent 219929eb47
commit b8e60afa69
12 changed files with 88 additions and 70 deletions

View File

@ -12,13 +12,10 @@ namespace osu.Game.Rulesets.Catch.Mods
{
public class CatchModAutoplay : ModAutoplay<CatchHitObject>
{
protected override ScoreInfo CreateReplayScore(Beatmap<CatchHitObject> beatmap)
protected override Score CreateReplayScore(Beatmap<CatchHitObject> 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(),
};
}
}

View File

@ -13,13 +13,10 @@ namespace osu.Game.Rulesets.Mania.Mods
{
public class ManiaModAutoplay : ModAutoplay<ManiaHitObject>
{
protected override ScoreInfo CreateReplayScore(Beatmap<ManiaHitObject> beatmap)
protected override Score CreateReplayScore(Beatmap<ManiaHitObject> 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(),
};
}
}

View File

@ -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<OsuHitObject> beatmap)
protected override Score CreateReplayScore(Beatmap<OsuHitObject> beatmap) => new Score
{
return new ScoreInfo
{
Replay = new OsuAutoGenerator(beatmap).Generate()
};
}
Replay = new OsuAutoGenerator(beatmap).Generate()
};
}
}

View File

@ -12,13 +12,10 @@ namespace osu.Game.Rulesets.Taiko.Mods
{
public class TaikoModAutoplay : ModAutoplay<TaikoHitObject>
{
protected override ScoreInfo CreateReplayScore(Beatmap<TaikoHitObject> beatmap)
protected override Score CreateReplayScore(Beatmap<TaikoHitObject> 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(),
};
}
}

View File

@ -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; }

View File

@ -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)

View File

@ -14,7 +14,7 @@ namespace osu.Game.Rulesets.Mods
public abstract class ModAutoplay<T> : ModAutoplay, IApplicableToRulesetContainer<T>
where T : HitObject
{
protected virtual ScoreInfo CreateReplayScore(Beatmap<T> beatmap) => new ScoreInfo { Replay = new Replay() };
protected virtual Score CreateReplayScore(Beatmap<T> beatmap) => new Score { Replay = new Replay() };
public override bool HasImplementation => GetType().GenericTypeArguments.Length == 0;

View File

@ -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)

View File

@ -0,0 +1,25 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// 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<byte[]> 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;
}
}
}

13
osu.Game/Scoring/Score.cs Normal file
View File

@ -0,0 +1,13 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// 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();
}
}

View File

@ -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;

View File

@ -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<ScoreInfo> GetAllScores() => ModelStore.ConsumableItems.Where(s => !s.DeletePending).ToList();
public Score GetScore(ScoreInfo scoreInfo) => new LegacyDatabasedScore(scoreInfo, rulesets, beatmaps, Files.Store);
public List<ScoreInfo> GetAllUsableScores() => ModelStore.ConsumableItems.Where(s => !s.DeletePending).ToList();
public ScoreInfo Query(Expression<Func<ScoreInfo, bool>> query) => ModelStore.ConsumableItems.AsNoTracking().FirstOrDefault(query);
}