Hook up ScoreProcessor to Scoreoverlay etc.

This commit is contained in:
Dean Herbert 2016-11-29 21:28:43 +09:00
parent 9b243ccc23
commit 2947121e48
7 changed files with 95 additions and 21 deletions

View File

@ -3,10 +3,60 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using osu.Game.Modes.Objects.Drawables;
using osu.Game.Modes.Osu.Objects.Drawables;
namespace osu.Game.Modes.Osu namespace osu.Game.Modes.Osu
{ {
class OsuScoreProcessor : ScoreProcessor class OsuScoreProcessor : ScoreProcessor
{ {
public override void AddJudgement(JudgementInfo judgement)
{
base.AddJudgement(judgement);
switch (judgement.Result)
{
case HitResult.Hit:
Combo.Value++;
break;
case HitResult.Miss:
Combo.Value = 0;
break;
}
}
protected override void UpdateCalculations()
{
base.UpdateCalculations();
int score = 0;
int maxScore = 0;
foreach (OsuJudgementInfo j in Judgements)
{
switch (j.Score)
{
case OsuScoreResult.Miss:
maxScore += 300;
break;
case OsuScoreResult.Hit50:
score += 50;
maxScore += 300;
break;
case OsuScoreResult.Hit100:
score += 100;
maxScore += 300;
break;
case OsuScoreResult.Hit300:
score += 300;
maxScore += 300;
break;
}
}
TotalScore.Value = score;
Accuracy.Value = (double)score / maxScore;
}
} }
} }

View File

@ -13,9 +13,7 @@ namespace osu.Game.Modes.Objects.Drawables
{ {
public abstract class DrawableHitObject : Container, IStateful<ArmedState> public abstract class DrawableHitObject : Container, IStateful<ArmedState>
{ {
//todo: move to a more central implementation. this logic should not be at a drawable level. public event Action<DrawableHitObject, JudgementInfo> OnJudgement;
public Action<DrawableHitObject, JudgementInfo> OnHit;
public Action<DrawableHitObject, JudgementInfo> OnMiss;
public Container<DrawableHitObject> ChildObjects; public Container<DrawableHitObject> ChildObjects;
@ -73,14 +71,14 @@ namespace osu.Game.Modes.Objects.Drawables
{ {
default: default:
State = ArmedState.Hit; State = ArmedState.Hit;
OnHit?.Invoke(this, Judgement);
break; break;
case HitResult.Miss: case HitResult.Miss:
State = ArmedState.Miss; State = ArmedState.Miss;
OnMiss?.Invoke(this, Judgement);
break; break;
} }
OnJudgement?.Invoke(this, Judgement);
return true; return true;
} }

View File

@ -6,11 +6,35 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using osu.Framework.Configuration;
using osu.Game.Modes.Objects.Drawables;
namespace osu.Game.Modes namespace osu.Game.Modes
{ {
public class ScoreProcessor public class ScoreProcessor
{ {
public virtual Score GetScore() => new Score(); public virtual Score GetScore() => new Score();
public BindableDouble TotalScore = new BindableDouble { MinValue = 0 };
public BindableDouble Accuracy = new BindableDouble { MinValue = 0, MaxValue = 1 };
public BindableInt Combo = new BindableInt();
public List<JudgementInfo> Judgements = new List<JudgementInfo>();
public virtual void AddJudgement(JudgementInfo judgement)
{
Judgements.Add(judgement);
UpdateCalculations();
}
/// <summary>
/// Update any values that potentially need post-processing on a judgement change.
/// </summary>
protected virtual void UpdateCalculations()
{
}
} }
} }

View File

@ -262,5 +262,13 @@ namespace osu.Game.Modes.UI
(d as ComboCounter).DisplayedCount = CurrentValue; (d as ComboCounter).DisplayedCount = CurrentValue;
} }
} }
public void Set(ulong value)
{
if (value == 0)
Roll();
else
Count = value;
}
} }
} }

View File

@ -14,8 +14,9 @@ namespace osu.Game.Modes.UI
{ {
public abstract class HitRenderer : Container public abstract class HitRenderer : Container
{ {
public Action<HitObject> OnHit; public event Action<JudgementInfo> OnJudgement;
public Action<HitObject> OnMiss;
protected void TriggerOnJudgement(JudgementInfo j) => OnJudgement?.Invoke(j);
protected Playfield Playfield; protected Playfield Playfield;
@ -68,22 +69,13 @@ namespace osu.Game.Modes.UI
if (drawableObject == null) continue; if (drawableObject == null) continue;
drawableObject.OnHit = onHit; drawableObject.OnJudgement += onJudgement;
drawableObject.OnMiss = onMiss;
Playfield.Add(drawableObject); Playfield.Add(drawableObject);
} }
} }
private void onMiss(DrawableHitObject obj, JudgementInfo judgement) private void onJudgement(DrawableHitObject o, JudgementInfo j) => TriggerOnJudgement(j);
{
OnMiss?.Invoke(obj.HitObject);
}
private void onHit(DrawableHitObject obj, JudgementInfo judgement)
{
OnHit?.Invoke(obj.HitObject);
}
protected abstract DrawableHitObject GetVisualRepresentation(T h); protected abstract DrawableHitObject GetVisualRepresentation(T h);
} }

View File

@ -49,7 +49,10 @@ namespace osu.Game.Modes.UI
public void BindProcessor(ScoreProcessor processor) public void BindProcessor(ScoreProcessor processor)
{ {
//bind processor bindables to combocounter, score display etc.
processor.TotalScore.ValueChanged += delegate { ScoreCounter?.Set((ulong)processor.TotalScore.Value); };
processor.Accuracy.ValueChanged += delegate { AccuracyCounter?.Set((float)processor.Accuracy.Value); };
processor.Combo.ValueChanged += delegate { ComboCounter?.Set((ulong)processor.Combo.Value); };
} }
} }
} }

View File

@ -91,8 +91,7 @@ namespace osu.Game.Screens.Play
var hitRenderer = ruleset.CreateHitRendererWith(beatmap.HitObjects); var hitRenderer = ruleset.CreateHitRendererWith(beatmap.HitObjects);
hitRenderer.OnHit += delegate (HitObject h) { scoreOverlay.OnHit(h); }; hitRenderer.OnJudgement += scoreProcessor.AddJudgement;
hitRenderer.OnMiss += delegate (HitObject h) { scoreOverlay.OnMiss(h); };
if (Autoplay) if (Autoplay)
hitRenderer.Schedule(() => hitRenderer.DrawableObjects.ForEach(h => h.State = ArmedState.Hit)); hitRenderer.Schedule(() => hitRenderer.DrawableObjects.ForEach(h => h.State = ArmedState.Hit));