mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 10:12:54 +08:00
Merge pull request #2551 from smoogipoo/score-parser-deriving
Allow subclasses of LegacyScoreParser to specify beatmap/ruleset retrieval
This commit is contained in:
commit
b40c55868e
@ -0,0 +1,26 @@
|
||||
// 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.Beatmaps;
|
||||
|
||||
namespace osu.Game.Rulesets.Scoring.Legacy
|
||||
{
|
||||
/// <summary>
|
||||
/// A <see cref="LegacyScoreParser"/> which retrieves the applicable <see cref="Beatmap"/> and <see cref="Ruleset"/>
|
||||
/// for the score from the database.
|
||||
/// </summary>
|
||||
public class DatabasedLegacyScoreParser : LegacyScoreParser
|
||||
{
|
||||
private readonly RulesetStore rulesets;
|
||||
private readonly BeatmapManager beatmaps;
|
||||
|
||||
public DatabasedLegacyScoreParser(RulesetStore rulesets, BeatmapManager beatmaps)
|
||||
{
|
||||
this.rulesets = rulesets;
|
||||
this.beatmaps = beatmaps;
|
||||
}
|
||||
|
||||
protected override Ruleset GetRuleset(int rulesetId) => rulesets.GetRuleset(rulesetId).CreateInstance();
|
||||
protected override WorkingBeatmap GetBeatmap(string md5Hash) => beatmaps.GetWorkingBeatmap(beatmaps.QueryBeatmap(b => b.MD5Hash == md5Hash));
|
||||
}
|
||||
}
|
@ -14,17 +14,8 @@ using System.Linq;
|
||||
|
||||
namespace osu.Game.Rulesets.Scoring.Legacy
|
||||
{
|
||||
public class LegacyScoreParser
|
||||
public abstract class LegacyScoreParser
|
||||
{
|
||||
private readonly RulesetStore rulesets;
|
||||
private readonly BeatmapManager beatmaps;
|
||||
|
||||
public LegacyScoreParser(RulesetStore rulesets, BeatmapManager beatmaps)
|
||||
{
|
||||
this.rulesets = rulesets;
|
||||
this.beatmaps = beatmaps;
|
||||
}
|
||||
|
||||
private IBeatmap currentBeatmap;
|
||||
private Ruleset currentRuleset;
|
||||
|
||||
@ -34,16 +25,15 @@ namespace osu.Game.Rulesets.Scoring.Legacy
|
||||
|
||||
using (SerializationReader sr = new SerializationReader(stream))
|
||||
{
|
||||
score = new Score { Ruleset = rulesets.GetRuleset(sr.ReadByte()) };
|
||||
currentRuleset = score.Ruleset.CreateInstance();
|
||||
currentRuleset = GetRuleset(sr.ReadByte());
|
||||
score = new Score { Ruleset = currentRuleset.RulesetInfo };
|
||||
|
||||
/* score.Pass = true;*/
|
||||
var version = sr.ReadInt32();
|
||||
|
||||
/* score.FileChecksum = */
|
||||
var beatmapHash = sr.ReadString();
|
||||
score.Beatmap = beatmaps.QueryBeatmap(b => b.MD5Hash == beatmapHash);
|
||||
currentBeatmap = beatmaps.GetWorkingBeatmap(score.Beatmap).Beatmap;
|
||||
currentBeatmap = GetBeatmap(sr.ReadString()).Beatmap;
|
||||
score.Beatmap = currentBeatmap.BeatmapInfo;
|
||||
|
||||
/* score.PlayerName = */
|
||||
score.User = new User { Username = sr.ReadString() };
|
||||
@ -181,5 +171,19 @@ namespace osu.Game.Rulesets.Scoring.Legacy
|
||||
|
||||
return frame;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the <see cref="Ruleset"/> for a specific id.
|
||||
/// </summary>
|
||||
/// <param name="rulesetId">The id.</param>
|
||||
/// <returns>The <see cref="Ruleset"/>.</returns>
|
||||
protected abstract Ruleset GetRuleset(int rulesetId);
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the <see cref="WorkingBeatmap"/> corresponding to an MD5 hash.
|
||||
/// </summary>
|
||||
/// <param name="md5Hash">The MD5 hash.</param>
|
||||
/// <returns>The <see cref="WorkingBeatmap"/>.</returns>
|
||||
protected abstract WorkingBeatmap GetBeatmap(string md5Hash);
|
||||
}
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ namespace osu.Game.Rulesets.Scoring
|
||||
public Score ReadReplayFile(string replayFilename)
|
||||
{
|
||||
using (Stream s = storage.GetStream(Path.Combine(replay_folder, replayFilename)))
|
||||
return new LegacyScoreParser(rulesets, beatmaps).Parse(s);
|
||||
return new DatabasedLegacyScoreParser(rulesets, beatmaps).Parse(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user