mirror of
https://github.com/osukey/osukey.git
synced 2025-08-04 23:24:04 +09:00
Implement PerformanceCalculator testcase
This commit is contained in:
@ -49,6 +49,8 @@ namespace osu.Game.Rulesets
|
||||
|
||||
public abstract DifficultyCalculator CreateDifficultyCalculator(Beatmap beatmap, Mod[] mods = null);
|
||||
|
||||
public virtual PerformanceCalculator CreatePerformanceCalculator(Beatmap beatmap, Score score) => null;
|
||||
|
||||
public virtual Drawable CreateIcon() => new SpriteIcon { Icon = FontAwesome.fa_question_circle };
|
||||
|
||||
public abstract string Description { get; }
|
||||
|
35
osu.Game/Rulesets/Scoring/PerformanceCalculator.cs
Normal file
35
osu.Game/Rulesets/Scoring/PerformanceCalculator.cs
Normal file
@ -0,0 +1,35 @@
|
||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using System.Collections.Generic;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Rulesets.Objects;
|
||||
|
||||
namespace osu.Game.Rulesets.Scoring
|
||||
{
|
||||
public abstract class PerformanceCalculator
|
||||
{
|
||||
public abstract double Calculate(Dictionary<string, string> categoryDifficulty = null);
|
||||
}
|
||||
|
||||
public abstract class PerformanceCalculator<TObject> : PerformanceCalculator
|
||||
where TObject : HitObject
|
||||
{
|
||||
private readonly Dictionary<string, string> attributes = new Dictionary<string, string>();
|
||||
protected IDictionary<string, string> Attributes => attributes;
|
||||
|
||||
protected readonly Beatmap<TObject> Beatmap;
|
||||
protected readonly Score Score;
|
||||
|
||||
public PerformanceCalculator(Ruleset ruleset, Beatmap beatmap, Score score)
|
||||
{
|
||||
Beatmap = CreateBeatmapConverter().Convert(beatmap);
|
||||
Score = score;
|
||||
|
||||
var diffCalc = ruleset.CreateDifficultyCalculator(beatmap);
|
||||
diffCalc.Calculate(attributes);
|
||||
}
|
||||
|
||||
protected abstract BeatmapConverter<TObject> CreateBeatmapConverter();
|
||||
}
|
||||
}
|
@ -14,9 +14,12 @@ using osu.Framework.Graphics.Sprites;
|
||||
using osu.Framework.Input;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using osu.Game.Online.API;
|
||||
using osu.Game.Online.API.Requests;
|
||||
using osu.Game.Overlays;
|
||||
using osu.Game.Overlays.Music;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Rulesets.Scoring;
|
||||
|
||||
namespace osu.Game.Tests.Visual
|
||||
{
|
||||
@ -24,30 +27,51 @@ namespace osu.Game.Tests.Visual
|
||||
{
|
||||
public TestCasePerformancePoints(Ruleset ruleset)
|
||||
{
|
||||
Children = new Drawable[]
|
||||
Child = new FillFlowContainer
|
||||
{
|
||||
new Container
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Direction = FillDirection.Horizontal,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
Anchor = Anchor.TopRight,
|
||||
Origin = Anchor.TopRight,
|
||||
RelativeSizeAxes = Axes.Y,
|
||||
Width = 300,
|
||||
Children = new Drawable[]
|
||||
new Container
|
||||
{
|
||||
new Box
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Width = 0.25f,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Colour = Color4.Black,
|
||||
Alpha = 0.5f,
|
||||
},
|
||||
new ScrollContainer(Direction.Vertical)
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Child = new BeatmapList(ruleset)
|
||||
new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Colour = Color4.Black,
|
||||
Alpha = 0.5f,
|
||||
},
|
||||
new ScrollContainer(Direction.Vertical)
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Child = new BeatmapList(ruleset)
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
new PpDisplay(ruleset)
|
||||
},
|
||||
new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Width = 0.75f,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Colour = Color4.Black,
|
||||
Alpha = 0.5f,
|
||||
},
|
||||
new ScrollContainer(Direction.Vertical)
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Child = new ScoreList { RelativeSizeAxes = Axes.Both }
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@ -144,70 +168,84 @@ namespace osu.Game.Tests.Visual
|
||||
}
|
||||
}
|
||||
|
||||
private class PpDisplay : CompositeDrawable
|
||||
private class ScoreList : CompositeDrawable
|
||||
{
|
||||
private readonly Container<OsuSpriteText> strainsContainer;
|
||||
private readonly OsuSpriteText totalPp;
|
||||
private readonly FillFlowContainer<ScoreDisplay> scores;
|
||||
private APIAccess api;
|
||||
|
||||
private readonly Ruleset ruleset;
|
||||
|
||||
public PpDisplay(Ruleset ruleset)
|
||||
public ScoreList()
|
||||
{
|
||||
this.ruleset = ruleset;
|
||||
|
||||
RelativeSizeAxes = Axes.Y;
|
||||
Width = 400;
|
||||
|
||||
InternalChildren = new Drawable[]
|
||||
InternalChild = scores = new FillFlowContainer<ScoreDisplay>
|
||||
{
|
||||
new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Colour = Color4.Black,
|
||||
Alpha = 0.2f
|
||||
},
|
||||
totalPp = new OsuSpriteText { TextSize = 18 },
|
||||
new Container
|
||||
{
|
||||
AutoSizeAxes = Axes.Both,
|
||||
Y = 26,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Colour = Color4.Black,
|
||||
Alpha = 0.2f,
|
||||
},
|
||||
strainsContainer = new FillFlowContainer<OsuSpriteText>
|
||||
{
|
||||
AutoSizeAxes = Axes.Both,
|
||||
Direction = FillDirection.Vertical,
|
||||
Spacing = new Vector2(0, 5)
|
||||
}
|
||||
}
|
||||
}
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Direction = FillDirection.Vertical,
|
||||
Spacing = new Vector2(0, 4)
|
||||
};
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuGameBase osuGame)
|
||||
private void load(OsuGameBase osuGame, APIAccess api)
|
||||
{
|
||||
this.api = api;
|
||||
osuGame.Beatmap.ValueChanged += beatmapChanged;
|
||||
}
|
||||
|
||||
private void beatmapChanged(WorkingBeatmap beatmap)
|
||||
private GetScoresRequest lastRequest;
|
||||
private void beatmapChanged(WorkingBeatmap newBeatmap)
|
||||
{
|
||||
var diffCalculator = ruleset.CreateDifficultyCalculator(beatmap.Beatmap);
|
||||
lastRequest?.Cancel();
|
||||
scores.Clear();
|
||||
|
||||
var strains = new Dictionary<string, string>();
|
||||
double pp = diffCalculator.Calculate(strains);
|
||||
lastRequest = new GetScoresRequest(newBeatmap.BeatmapInfo);
|
||||
lastRequest.Success += res => res.Scores.ForEach(s => scores.Add(new ScoreDisplay(s, newBeatmap.Beatmap)));
|
||||
api.Queue(lastRequest);
|
||||
}
|
||||
|
||||
totalPp.Text = $"Total PP: {pp.ToString("n2")}";
|
||||
private class ScoreDisplay : CompositeDrawable
|
||||
{
|
||||
private readonly OsuSpriteText playerName;
|
||||
private readonly GridContainer attributeGrid;
|
||||
|
||||
strainsContainer.Clear();
|
||||
foreach (var kvp in strains)
|
||||
strainsContainer.Add(new OsuSpriteText { Text = $"{kvp.Key} : {kvp.Value}" });
|
||||
private readonly Score score;
|
||||
private readonly Beatmap beatmap;
|
||||
|
||||
public ScoreDisplay(Score score, Beatmap beatmap)
|
||||
{
|
||||
this.score = score;
|
||||
this.beatmap = beatmap;
|
||||
|
||||
RelativeSizeAxes = Axes.X;
|
||||
Height = 16;
|
||||
InternalChild = new GridContainer
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Content = new[]
|
||||
{
|
||||
new Drawable[] { playerName = new OsuSpriteText() },
|
||||
new Drawable[] { attributeGrid = new GridContainer { RelativeSizeAxes = Axes.Both } }
|
||||
},
|
||||
RowDimensions = new[]
|
||||
{
|
||||
new Dimension(GridSizeMode.Relative, 0.75f),
|
||||
new Dimension(GridSizeMode.Relative, 0.25f)
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
var ruleset = beatmap.BeatmapInfo.Ruleset.CreateInstance();
|
||||
var calculator = ruleset.CreatePerformanceCalculator(beatmap, score);
|
||||
if (calculator == null)
|
||||
return;
|
||||
|
||||
var attributes = new Dictionary<string, string>();
|
||||
double performance = calculator.Calculate(attributes);
|
||||
|
||||
playerName.Text = $"{score.PP} | {performance.ToString("0.00")} | {score.PP / performance}";
|
||||
// var attributeRow =
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -620,6 +620,7 @@
|
||||
<Compile Include="Rulesets\Ruleset.cs" />
|
||||
<Compile Include="Rulesets\RulesetInfo.cs" />
|
||||
<Compile Include="Rulesets\RulesetStore.cs" />
|
||||
<Compile Include="Rulesets\Scoring\PerformanceCalculator.cs" />
|
||||
<Compile Include="Rulesets\Scoring\Score.cs" />
|
||||
<Compile Include="Rulesets\Scoring\ScoreProcessor.cs" />
|
||||
<Compile Include="Rulesets\Scoring\ScoreRank.cs" />
|
||||
|
Reference in New Issue
Block a user