Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow subclasses of LegacyScoreParser to specify beatmap/ruleset retrieval #2551

Merged
merged 4 commits into from May 15, 2018
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 11 additions & 5 deletions osu.Game/Rulesets/Scoring/Legacy/LegacyScoreParser.cs
Expand Up @@ -25,6 +25,10 @@ public LegacyScoreParser(RulesetStore rulesets, BeatmapManager beatmaps)
this.beatmaps = beatmaps;
}

protected LegacyScoreParser()

This comment was marked as off-topic.

{
}

private IBeatmap currentBeatmap;
private Ruleset currentRuleset;

Expand All @@ -34,16 +38,15 @@ public Score Parse(Stream stream)

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() };
Expand Down Expand Up @@ -181,5 +184,8 @@ private ReplayFrame convertFrame(LegacyReplayFrame legacyFrame)

return frame;
}

protected virtual Ruleset GetRuleset(int rulesetId) => rulesets.GetRuleset(rulesetId).CreateInstance();
protected virtual WorkingBeatmap GetBeatmap(string md5Hash) => beatmaps.GetWorkingBeatmap(beatmaps.QueryBeatmap(b => b.MD5Hash == md5Hash));
}
}