Apply Ruleset to Scores. Reduce complexity of score creation.

This commit is contained in:
Dean Herbert 2017-04-20 11:16:08 +09:00
parent 6cf026e5c1
commit a47870b376
No known key found for this signature in database
GPG Key ID: 46D71BF4958ABB49
5 changed files with 22 additions and 23 deletions

View File

@ -37,16 +37,14 @@ namespace osu.Game.Rulesets.Osu.Scoring
private readonly Dictionary<OsuScoreResult, int> scoreResultCounts = new Dictionary<OsuScoreResult, int>();
private readonly Dictionary<ComboResult, int> comboResultCounts = new Dictionary<ComboResult, int>();
public override Score GetPopulatedScore()
public override void PopulateScore(Score score)
{
var score = base.GetPopulatedScore();
base.PopulateScore(score);
score.Statistics[@"300"] = scoreResultCounts.GetOrDefault(OsuScoreResult.Hit300);
score.Statistics[@"100"] = scoreResultCounts.GetOrDefault(OsuScoreResult.Hit100);
score.Statistics[@"50"] = scoreResultCounts.GetOrDefault(OsuScoreResult.Hit50);
score.Statistics[@"x"] = scoreResultCounts.GetOrDefault(OsuScoreResult.Miss);
return score;
}
protected override void OnNewJudgement(OsuJudgement judgement)

View File

@ -45,7 +45,7 @@ namespace osu.Game.Database
using (SerializationReader sr = new SerializationReader(s))
{
var ruleset = rulesets.GetRuleset(sr.ReadByte()).CreateInstance();
score = ruleset.CreateScoreProcessor().CreateEmptyScore();
score = new Score();
/* score.Pass = true;*/
var version = sr.ReadInt32();

View File

@ -32,6 +32,8 @@ namespace osu.Game.Rulesets.Scoring
[JsonProperty(@"mods")]
protected string[] ModStrings { get; set; } //todo: parse to Mod objects
public RulesetInfo Ruleset { get; set; }
public Mod[] Mods { get; set; }
[JsonProperty(@"user")]

View File

@ -61,12 +61,6 @@ namespace osu.Game.Rulesets.Scoring
Reset();
}
/// <summary>
/// Creates a Score applicable to the ruleset in which this ScoreProcessor resides.
/// </summary>
/// <returns>The Score.</returns>
public virtual Score CreateEmptyScore() => new Score();
private ScoreRank rankFrom(double acc)
{
if (acc == 1)
@ -114,10 +108,8 @@ namespace osu.Game.Rulesets.Scoring
/// <summary>
/// Retrieve a score populated with data for the current play this processor is responsible for.
/// </summary>
public virtual Score GetPopulatedScore()
public virtual void PopulateScore(Score score)
{
var score = CreateEmptyScore();
score.TotalScore = TotalScore;
score.Combo = Combo;
score.MaxCombo = HighestCombo;
@ -125,8 +117,6 @@ namespace osu.Game.Rulesets.Scoring
score.Rank = rankFrom(Accuracy);
score.Date = DateTime.Now;
score.Health = Health;
return score;
}
}

View File

@ -51,7 +51,7 @@ namespace osu.Game.Screens.Play
private IAdjustableClock sourceClock;
private IFrameBasedClock interpolatedSourceClock;
private Ruleset ruleset;
private RulesetInfo ruleset;
private ScoreProcessor scoreProcessor;
protected HitRenderer HitRenderer;
@ -68,6 +68,8 @@ namespace osu.Game.Screens.Play
dimLevel = config.GetBindable<int>(OsuConfig.DimLevel);
mouseWheelDisabled = config.GetBindable<bool>(OsuConfig.MouseDisableWheel);
Ruleset rulesetInstance;
try
{
if (Beatmap == null)
@ -82,15 +84,17 @@ namespace osu.Game.Screens.Play
try
{
// Try using the preferred user ruleset
ruleset = osu == null ? Beatmap.BeatmapInfo.Ruleset.CreateInstance() : osu.Ruleset.Value.CreateInstance();
HitRenderer = ruleset.CreateHitRendererWith(Beatmap);
ruleset = osu == null ? Beatmap.BeatmapInfo.Ruleset : osu.Ruleset.Value;
}
catch (BeatmapInvalidForModeException)
{
// Default to the beatmap ruleset
ruleset = Beatmap.BeatmapInfo.Ruleset.CreateInstance();
HitRenderer = ruleset.CreateHitRendererWith(Beatmap);
ruleset = Beatmap.BeatmapInfo.Ruleset;
}
rulesetInstance = ruleset.CreateInstance();
HitRenderer = rulesetInstance.CreateHitRendererWith(Beatmap);
}
catch (Exception e)
{
@ -125,7 +129,7 @@ namespace osu.Game.Screens.Play
Origin = Anchor.Centre
};
hudOverlay.KeyCounter.Add(ruleset.CreateGameplayKeys());
hudOverlay.KeyCounter.Add(rulesetInstance.CreateGameplayKeys());
hudOverlay.BindProcessor(scoreProcessor);
hudOverlay.BindHitRenderer(HitRenderer);
@ -266,7 +270,12 @@ namespace osu.Game.Screens.Play
Delay(1000);
onCompletionEvent = Schedule(delegate
{
var score = scoreProcessor.GetPopulatedScore();
var score = new Score
{
Beatmap = Beatmap.BeatmapInfo,
Ruleset = ruleset
};
scoreProcessor.PopulateScore(score);
score.User = HitRenderer.Replay?.User ?? (Game as OsuGame)?.API?.LocalUser?.Value;
Push(new Results(score));
});