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
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<OsuScoreResult, int> scoreResultCounts = new Dictionary<OsuScoreResult, int>();
private readonly Dictionary<ComboResult, int> comboResultCounts = new Dictionary<ComboResult, 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[@"300"] = scoreResultCounts.GetOrDefault(OsuScoreResult.Hit300);
score.Statistics[@"100"] = scoreResultCounts.GetOrDefault(OsuScoreResult.Hit100); score.Statistics[@"100"] = scoreResultCounts.GetOrDefault(OsuScoreResult.Hit100);
score.Statistics[@"50"] = scoreResultCounts.GetOrDefault(OsuScoreResult.Hit50); score.Statistics[@"50"] = scoreResultCounts.GetOrDefault(OsuScoreResult.Hit50);
score.Statistics[@"x"] = scoreResultCounts.GetOrDefault(OsuScoreResult.Miss); score.Statistics[@"x"] = scoreResultCounts.GetOrDefault(OsuScoreResult.Miss);
return score;
} }
protected override void OnNewJudgement(OsuJudgement judgement) protected override void OnNewJudgement(OsuJudgement judgement)

View File

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

View File

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

View File

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

View File

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