mirror of
https://github.com/osukey/osukey.git
synced 2025-08-07 16:43:52 +09:00
Merge pull request #2551 from smoogipoo/score-parser-deriving
Allow subclasses of LegacyScoreParser to specify beatmap/ruleset retrieval
This commit is contained in:
@ -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
|
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 IBeatmap currentBeatmap;
|
||||||
private Ruleset currentRuleset;
|
private Ruleset currentRuleset;
|
||||||
|
|
||||||
@ -34,16 +25,15 @@ namespace osu.Game.Rulesets.Scoring.Legacy
|
|||||||
|
|
||||||
using (SerializationReader sr = new SerializationReader(stream))
|
using (SerializationReader sr = new SerializationReader(stream))
|
||||||
{
|
{
|
||||||
score = new Score { Ruleset = rulesets.GetRuleset(sr.ReadByte()) };
|
currentRuleset = GetRuleset(sr.ReadByte());
|
||||||
currentRuleset = score.Ruleset.CreateInstance();
|
score = new Score { Ruleset = currentRuleset.RulesetInfo };
|
||||||
|
|
||||||
/* score.Pass = true;*/
|
/* score.Pass = true;*/
|
||||||
var version = sr.ReadInt32();
|
var version = sr.ReadInt32();
|
||||||
|
|
||||||
/* score.FileChecksum = */
|
/* score.FileChecksum = */
|
||||||
var beatmapHash = sr.ReadString();
|
currentBeatmap = GetBeatmap(sr.ReadString()).Beatmap;
|
||||||
score.Beatmap = beatmaps.QueryBeatmap(b => b.MD5Hash == beatmapHash);
|
score.Beatmap = currentBeatmap.BeatmapInfo;
|
||||||
currentBeatmap = beatmaps.GetWorkingBeatmap(score.Beatmap).Beatmap;
|
|
||||||
|
|
||||||
/* score.PlayerName = */
|
/* score.PlayerName = */
|
||||||
score.User = new User { Username = sr.ReadString() };
|
score.User = new User { Username = sr.ReadString() };
|
||||||
@ -181,5 +171,19 @@ namespace osu.Game.Rulesets.Scoring.Legacy
|
|||||||
|
|
||||||
return frame;
|
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)
|
public Score ReadReplayFile(string replayFilename)
|
||||||
{
|
{
|
||||||
using (Stream s = storage.GetStream(Path.Combine(replay_folder, 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user