mirror of
https://github.com/osukey/osukey.git
synced 2025-08-05 07:33:55 +09:00
Make ScoreProcessors take generic judgements.
This commit is contained in:
@ -39,9 +39,8 @@ namespace osu.Game.Database
|
||||
using (SerializationReader sr = new SerializationReader(s))
|
||||
{
|
||||
var ruleset = Ruleset.GetRuleset((PlayMode)sr.ReadByte());
|
||||
var processor = ruleset.CreateScoreProcessor();
|
||||
|
||||
score = processor.GetScore();
|
||||
score = new Score();
|
||||
|
||||
/* score.Pass = true;*/
|
||||
var version = sr.ReadInt32();
|
||||
|
@ -29,8 +29,6 @@ namespace osu.Game.Modes
|
||||
|
||||
public abstract IEnumerable<Mod> GetModsFor(ModType type);
|
||||
|
||||
public abstract ScoreProcessor CreateScoreProcessor(int hitObjectCount = 0);
|
||||
|
||||
public abstract HitRenderer CreateHitRendererWith(WorkingBeatmap beatmap);
|
||||
|
||||
public abstract DifficultyCalculator CreateDifficultyCalculator(Beatmap beatmap);
|
||||
|
@ -5,6 +5,8 @@ using osu.Framework.Configuration;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using osu.Game.Modes.Judgements;
|
||||
using osu.Game.Modes.UI;
|
||||
using osu.Game.Modes.Objects;
|
||||
|
||||
namespace osu.Game.Modes
|
||||
{
|
||||
@ -28,36 +30,50 @@ namespace osu.Game.Modes
|
||||
public readonly BindableInt Combo = new BindableInt();
|
||||
|
||||
/// <summary>
|
||||
/// Are we allowed to fail?
|
||||
/// Keeps track of the highest combo ever achieved in this play.
|
||||
/// This is handled automatically by ScoreProcessor.
|
||||
/// </summary>
|
||||
protected bool CanFail => true;
|
||||
|
||||
protected bool HasFailed { get; private set; }
|
||||
public readonly BindableInt HighestCombo = new BindableInt();
|
||||
|
||||
/// <summary>
|
||||
/// Called when we reach a failing health of zero.
|
||||
/// </summary>
|
||||
public event Action Failed;
|
||||
|
||||
/// <summary>
|
||||
/// Keeps track of the highest combo ever achieved in this play.
|
||||
/// This is handled automatically by ScoreProcessor.
|
||||
/// </summary>
|
||||
public readonly BindableInt HighestCombo = new BindableInt();
|
||||
protected void TriggerFailed()
|
||||
{
|
||||
Failed?.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
public readonly List<JudgementInfo> Judgements;
|
||||
public abstract class ScoreProcessor<TObject, TJudgement> : ScoreProcessor
|
||||
where TObject : HitObject
|
||||
where TJudgement : JudgementInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// All judgements held by this ScoreProcessor.
|
||||
/// </summary>
|
||||
protected List<TJudgement> Judgements;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ScoreProcessor"/> class.
|
||||
/// Are we allowed to fail?
|
||||
/// </summary>
|
||||
/// <param name="hitObjectCount">Number of HitObjects. It is used for specifying Judgements collection Capacity</param>
|
||||
protected ScoreProcessor(int hitObjectCount = 0)
|
||||
protected bool CanFail => true;
|
||||
|
||||
/// <summary>
|
||||
/// Whether this ScoreProcessor has already triggered the failed event.
|
||||
/// </summary>
|
||||
protected bool HasFailed { get; private set; }
|
||||
|
||||
protected ScoreProcessor(HitRenderer<TObject, TJudgement> hitRenderer)
|
||||
{
|
||||
Combo.ValueChanged += delegate { HighestCombo.Value = Math.Max(HighestCombo.Value, Combo.Value); };
|
||||
Judgements = new List<JudgementInfo>(hitObjectCount);
|
||||
Judgements = new List<TJudgement>(hitRenderer.Beatmap.HitObjects.Count);
|
||||
|
||||
hitRenderer.OnJudgement += addJudgement;
|
||||
}
|
||||
|
||||
public void AddJudgement(JudgementInfo judgement)
|
||||
private void addJudgement(TJudgement judgement)
|
||||
{
|
||||
Judgements.Add(judgement);
|
||||
|
||||
@ -67,7 +83,7 @@ namespace osu.Game.Modes
|
||||
if (Health.Value == Health.MinValue && !HasFailed)
|
||||
{
|
||||
HasFailed = true;
|
||||
Failed?.Invoke();
|
||||
TriggerFailed();
|
||||
}
|
||||
}
|
||||
|
||||
@ -75,6 +91,6 @@ namespace osu.Game.Modes
|
||||
/// Update any values that potentially need post-processing on a judgement change.
|
||||
/// </summary>
|
||||
/// <param name="newJudgement">A new JudgementInfo that triggered this calculation. May be null.</param>
|
||||
protected abstract void UpdateCalculations(JudgementInfo newJudgement);
|
||||
protected abstract void UpdateCalculations(TJudgement newJudgement);
|
||||
}
|
||||
}
|
||||
|
@ -25,14 +25,6 @@ namespace osu.Game.Modes.UI
|
||||
/// </summary>
|
||||
public abstract class HitRenderer : Container
|
||||
{
|
||||
/// <summary>
|
||||
/// The event that's fired when a hit object is judged.
|
||||
/// </summary>
|
||||
public event Action<JudgementInfo> OnJudgement;
|
||||
|
||||
/// <summary>
|
||||
/// The event that's fired when all hit objects have been judged.
|
||||
/// </summary>
|
||||
public event Action OnAllJudged;
|
||||
|
||||
/// <summary>
|
||||
@ -57,17 +49,16 @@ namespace osu.Game.Modes.UI
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Triggers a judgement for further processing.
|
||||
/// Checks whether all HitObjects have been judged, and invokes OnAllJudged.
|
||||
/// </summary>
|
||||
/// <param name="j">The judgement to trigger.</param>
|
||||
protected void TriggerOnJudgement(JudgementInfo j)
|
||||
protected void CheckAllJudged()
|
||||
{
|
||||
OnJudgement?.Invoke(j);
|
||||
|
||||
if (AllObjectsJudged)
|
||||
OnAllJudged?.Invoke();
|
||||
}
|
||||
|
||||
public abstract ScoreProcessor CreateScoreProcessor();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a key conversion input manager.
|
||||
/// </summary>
|
||||
@ -141,6 +132,8 @@ namespace osu.Game.Modes.UI
|
||||
where TObject : HitObject
|
||||
where TJudgement : JudgementInfo
|
||||
{
|
||||
public event Action<TJudgement> OnJudgement;
|
||||
|
||||
protected override Container<Drawable> Content => content;
|
||||
protected override bool AllObjectsJudged => Playfield.HitObjects.Children.All(h => h.Judgement.Result.HasValue);
|
||||
|
||||
@ -197,8 +190,10 @@ namespace osu.Game.Modes.UI
|
||||
/// <param name="judgedObject">The object that Judgement has been updated for.</param>
|
||||
private void onJudgement(DrawableHitObject<TObject, TJudgement> judgedObject)
|
||||
{
|
||||
TriggerOnJudgement(judgedObject.Judgement);
|
||||
OnJudgement?.Invoke(judgedObject.Judgement);
|
||||
Playfield.OnJudgement(judgedObject);
|
||||
|
||||
CheckAllJudged();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -108,10 +108,13 @@ namespace osu.Game.Screens.Play
|
||||
});
|
||||
|
||||
ruleset = Ruleset.GetRuleset(Beatmap.PlayMode);
|
||||
hitRenderer = ruleset.CreateHitRendererWith(Beatmap);
|
||||
|
||||
scoreProcessor = hitRenderer.CreateScoreProcessor();
|
||||
|
||||
hudOverlay = new StandardHudOverlay();
|
||||
hudOverlay.KeyCounter.Add(ruleset.CreateGameplayKeys());
|
||||
hudOverlay.BindProcessor(scoreProcessor = ruleset.CreateScoreProcessor(beatmap.HitObjects.Count));
|
||||
hudOverlay.BindProcessor(scoreProcessor);
|
||||
|
||||
pauseOverlay = new PauseOverlay
|
||||
{
|
||||
@ -125,7 +128,6 @@ namespace osu.Game.Screens.Play
|
||||
OnQuit = Exit
|
||||
};
|
||||
|
||||
hitRenderer = ruleset.CreateHitRendererWith(Beatmap);
|
||||
|
||||
if (ReplayInputHandler != null)
|
||||
hitRenderer.InputManager.ReplayInputHandler = ReplayInputHandler;
|
||||
@ -133,7 +135,6 @@ namespace osu.Game.Screens.Play
|
||||
hudOverlay.BindHitRenderer(hitRenderer);
|
||||
|
||||
//bind HitRenderer to ScoreProcessor and ourselves (for a pass situation)
|
||||
hitRenderer.OnJudgement += scoreProcessor.AddJudgement;
|
||||
hitRenderer.OnAllJudged += onPass;
|
||||
|
||||
//bind ScoreProcessor to ourselves (for a fail situation)
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<!--
|
||||
Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||
Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
Reference in New Issue
Block a user