1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-28 05:22:54 +08:00

the power of linq

This commit is contained in:
Jorolf 2017-04-11 18:43:48 +02:00
parent 9026880495
commit d4e5f55091
4 changed files with 28 additions and 50 deletions

View File

@ -42,9 +42,9 @@ namespace osu.Desktop.VisualTests.Tests
StarDifficulty = 5.3f,
Metric = new BeatmapMetric
{
Ratings = Enumerable.Range(0,10).ToList(),
Fails = Enumerable.Range(lastRange, 100).Select(i => i % 12 - 6).ToList(),
Retries = Enumerable.Range(lastRange - 3, 100).Select(i => i % 12 - 6).ToList(),
Ratings = Enumerable.Range(0,10),
Fails = Enumerable.Range(lastRange, 100).Select(i => i % 12 - 6),
Retries = Enumerable.Range(lastRange - 3, 100).Select(i => i % 12 - 6),
},
},
});
@ -56,29 +56,9 @@ namespace osu.Desktop.VisualTests.Tests
private void newRetryAndFailValues()
{
details.Beatmap = new BeatmapInfo
{
Version = "VisualTest",
Metadata = new BeatmapMetadata
{
Source = "Some guy",
Tags = "beatmap metadata example with a very very long list of tags and not much creativity",
},
Difficulty = new BeatmapDifficulty
{
CircleSize = 7,
ApproachRate = 3.5f,
OverallDifficulty = 5.7f,
DrainRate = 1,
},
StarDifficulty = 5.3f,
Metric = new BeatmapMetric
{
Ratings = Enumerable.Range(0, 10).ToList(),
Fails = Enumerable.Range(lastRange, 100).Select(i => i % 12 - 6).ToList(),
Retries = Enumerable.Range(lastRange - 3, 100).Select(i => i % 12 - 6).ToList(),
},
};
details.Beatmap.Metric.Fails = Enumerable.Range(lastRange, 100).Select(i => i % 12 - 6);
details.Beatmap.Metric.Retries = Enumerable.Range(lastRange - 3, 100).Select(i => i % 12 - 6);
details.Beatmap = details.Beatmap;
lastRange += 100;
}
}

View File

@ -10,16 +10,16 @@ namespace osu.Game.Database
/// <summary>
/// Ratings for a beatmap, length should be 10
/// </summary>
public List<int> Ratings { get; set; }
public IEnumerable<int> Ratings { get; set; }
/// <summary>
/// Fails for a beatmap, length should be 100
/// </summary>
public List<int> Fails { get; set; }
public IEnumerable<int> Fails { get; set; }
/// <summary>
/// Retries for a beatmap, length should be 100
/// </summary>
public List<int> Retries { get; set; }
public IEnumerable<int> Retries { get; set; }
}
}

View File

@ -42,23 +42,22 @@ namespace osu.Game.Graphics.UserInterface
{
set
{
List<float> values = value?.ToList() ?? new List<float>();
List<Bar> graphBars = Children.ToList();
for (int i = 0; i < values.Count; i++)
if (graphBars.Count > i)
List<Bar> bars = Children.ToList();
foreach (var bar in value.Select((length, index) => new { Value = length, Bar = bars.Count > index ? bars[index] : null }))
if (bar.Bar != null)
{
graphBars[i].Length = values[i] / (MaxValue ?? values.Max());
graphBars[i].Size = (direction & BarDirection.Horizontal) > 0 ? new Vector2(1, 1.0f / values.Count) : new Vector2(1.0f / values.Count, 1);
bar.Bar.Length = bar.Value / (MaxValue ?? value.Max());
bar.Bar.Size = (direction & BarDirection.Horizontal) > 0 ? new Vector2(1, 1.0f / value.Count()) : new Vector2(1.0f / value.Count(), 1);
}
else
Add(new Bar
{
RelativeSizeAxes = Axes.Both,
Size = (direction & BarDirection.Horizontal) > 0 ? new Vector2(1, 1.0f / values.Count) : new Vector2(1.0f / values.Count, 1),
Length = values[i] / (MaxValue ?? values.Max()),
Size = (direction & BarDirection.Horizontal) > 0 ? new Vector2(1, 1.0f / value.Count()) : new Vector2(1.0f / value.Count(), 1),
Length = bar.Value / (MaxValue ?? value.Max()),
Direction = Direction,
});
Remove(Children.Where((bar, index) => index >= values.Count).ToList());
Remove(Children.Where((bar, index) => index >= value.Count()).ToList());
}
}
}

View File

@ -49,7 +49,6 @@ namespace osu.Game.Screens.Select
}
set
{
if (beatmap == value) return;
beatmap = value;
description.Text = beatmap.Version;
@ -62,11 +61,9 @@ namespace osu.Game.Screens.Select
approachRate.Value = beatmap.Difficulty.ApproachRate;
stars.Value = (float)beatmap.StarDifficulty;
if (beatmap.Metric?.Ratings == null)
ratingsContainer.Hide();
else
if (beatmap.Metric?.Ratings.Count() > 0)
{
List<int> ratings = beatmap.Metric.Ratings;
List<int> ratings = beatmap.Metric.Ratings.ToList();
ratingsContainer.Show();
negativeRatings.Text = ratings.GetRange(0, 5).Sum().ToString();
@ -75,22 +72,24 @@ namespace osu.Game.Screens.Select
ratingsGraph.Values = ratings.Select(rating => (float)rating);
}
if (beatmap.Metric?.Retries == null || beatmap.Metric?.Fails == null)
retryFailContainer.Hide();
else
ratingsContainer.Hide();
if (beatmap.Metric?.Retries.Count() > 0 && beatmap.Metric?.Retries.Count() > 0)
{
List<int> retries = beatmap.Metric.Retries;
List<int> fails = beatmap.Metric.Fails;
IEnumerable<int> retries = beatmap.Metric.Retries;
IEnumerable<int> fails = beatmap.Metric.Fails;
retryFailContainer.Show();
float maxValue = fails.Select((fail, index) => fail + retries[index]).Max();
float maxValue = fails.Zip(retries, (fail, retry) => fail + retry).Max();
failGraph.MaxValue = maxValue;
retryGraph.MaxValue = maxValue;
failGraph.Values = fails.Select(fail => (float)fail);
retryGraph.Values = retries.Select((retry, index) => retry + MathHelper.Clamp(fails[index], 0, maxValue));
retryGraph.Values = retries.Zip(fails, (retry, fail) => retry + MathHelper.Clamp(fail, 0, maxValue));
}
else
retryFailContainer.Hide();
}
}