1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-15 03:47:26 +08:00
osu-lazer/osu.Game/Modes/ScoreProcessor.cs

100 lines
3.3 KiB
C#
Raw Normal View History

// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
2016-11-29 19:30:16 +08:00
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;
2016-11-29 19:30:16 +08:00
namespace osu.Game.Modes
{
public abstract class ScoreProcessor
2016-11-29 19:30:16 +08:00
{
2017-03-07 09:59:19 +08:00
public virtual Score GetScore() => new Score
2016-11-29 22:59:56 +08:00
{
TotalScore = TotalScore,
Combo = Combo,
MaxCombo = HighestCombo,
2017-01-10 16:01:53 +08:00
Accuracy = Accuracy,
Health = Health,
2016-11-29 22:59:56 +08:00
};
public readonly BindableDouble TotalScore = new BindableDouble { MinValue = 0 };
public readonly BindableDouble Accuracy = new BindableDouble { MinValue = 0, MaxValue = 1 };
2017-01-10 16:01:53 +08:00
public readonly BindableDouble Health = new BindableDouble { MinValue = 0, MaxValue = 1 };
2017-03-10 15:05:05 +08:00
public readonly BindableInt Combo = new BindableInt();
2017-01-20 15:51:43 +08:00
/// <summary>
/// Keeps track of the highest combo ever achieved in this play.
/// This is handled automatically by ScoreProcessor.
2017-01-20 15:51:43 +08:00
/// </summary>
public readonly BindableInt HighestCombo = new BindableInt();
2017-01-20 15:51:43 +08:00
/// <summary>
/// Called when we reach a failing health of zero.
/// </summary>
public event Action Failed;
2017-03-16 11:57:50 +08:00
/// <summary>
/// Notifies subscribers that the score is in a failed state.
/// </summary>
protected void TriggerFailed()
{
Failed?.Invoke();
}
}
public abstract class ScoreProcessor<TObject, TJudgement> : ScoreProcessor
where TObject : HitObject
where TJudgement : JudgementInfo
{
2017-01-20 15:51:43 +08:00
/// <summary>
/// All judgements held by this ScoreProcessor.
2017-01-20 15:51:43 +08:00
/// </summary>
protected List<TJudgement> Judgements;
2016-11-29 20:57:53 +08:00
/// <summary>
/// Are we allowed to fail?
/// </summary>
protected bool CanFail => true;
2017-01-18 23:51:38 +08:00
/// <summary>
/// Whether this ScoreProcessor has already triggered the failed event.
2017-01-18 23:51:38 +08:00
/// </summary>
protected bool HasFailed { get; private set; }
protected ScoreProcessor(HitRenderer<TObject, TJudgement> hitRenderer)
{
2016-11-29 21:05:21 +08:00
Combo.ValueChanged += delegate { HighestCombo.Value = Math.Max(HighestCombo.Value, Combo.Value); };
Judgements = new List<TJudgement>(hitRenderer.Beatmap.HitObjects.Count);
hitRenderer.OnJudgement += addJudgement;
}
private void addJudgement(TJudgement judgement)
{
Judgements.Add(judgement);
2016-11-29 20:46:30 +08:00
UpdateCalculations(judgement);
2016-11-29 20:57:53 +08:00
judgement.ComboAtHit = (ulong)Combo.Value;
2017-01-20 15:51:43 +08:00
if (Health.Value == Health.MinValue && !HasFailed)
{
HasFailed = true;
TriggerFailed();
2017-01-20 15:51:43 +08:00
}
}
/// <summary>
/// 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(TJudgement newJudgement);
2016-11-29 19:30:16 +08:00
}
}