Skip to content

Commit

Permalink
Use MaxBy in all locations that can and update inspection level to …
Browse files Browse the repository at this point in the history
…match `dotnet-build`
  • Loading branch information
peppy committed Dec 19, 2022
1 parent d5b2ffa commit b9908d7
Show file tree
Hide file tree
Showing 14 changed files with 17 additions and 28 deletions.
4 changes: 1 addition & 3 deletions osu.Game.Rulesets.Catch/Edit/CatchDistanceSnapGrid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,7 @@ public SnapResult GetSnappedPosition(Vector2 screenSpacePosition)
return new SnapResult(originPosition, StartTime);
}

return enumerateSnappingCandidates(time)
.OrderBy(pos => Vector2.DistanceSquared(screenSpacePosition, pos.ScreenSpacePosition))
.FirstOrDefault();
return enumerateSnappingCandidates(time).MinBy(pos => Vector2.DistanceSquared(screenSpacePosition, pos.ScreenSpacePosition));
}

private IEnumerable<SnapResult> enumerateSnappingCandidates(double time)
Expand Down
4 changes: 2 additions & 2 deletions osu.Game.Tournament/Screens/Ladder/LadderScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ protected virtual void UpdateLayout()

foreach (var round in LadderInfo.Rounds)
{
var topMatch = MatchesContainer.Where(p => !p.Match.Losers.Value && p.Match.Round.Value == round).OrderBy(p => p.Y).FirstOrDefault();
var topMatch = MatchesContainer.Where(p => !p.Match.Losers.Value && p.Match.Round.Value == round).MinBy(p => p.Y);

if (topMatch == null) continue;

Expand All @@ -172,7 +172,7 @@ protected virtual void UpdateLayout()

foreach (var round in LadderInfo.Rounds)
{
var topMatch = MatchesContainer.Where(p => p.Match.Losers.Value && p.Match.Round.Value == round).OrderBy(p => p.Y).FirstOrDefault();
var topMatch = MatchesContainer.Where(p => p.Match.Losers.Value && p.Match.Round.Value == round).MinBy(p => p.Y);

if (topMatch == null) continue;

Expand Down
4 changes: 2 additions & 2 deletions osu.Game/Beatmaps/ControlPoints/ControlPointInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@ public class ControlPointInfo : IDeepCloneable<ControlPointInfo>
/// </summary>
[JsonIgnore]
public double BPMMaximum =>
60000 / (TimingPoints.OrderBy(c => c.BeatLength).FirstOrDefault() ?? TimingControlPoint.DEFAULT).BeatLength;
60000 / (TimingPoints.MinBy(c => c.BeatLength) ?? TimingControlPoint.DEFAULT).BeatLength;

/// <summary>
/// Finds the minimum BPM represented by any timing control point.
/// </summary>
[JsonIgnore]
public double BPMMinimum =>
60000 / (TimingPoints.OrderByDescending(c => c.BeatLength).FirstOrDefault() ?? TimingControlPoint.DEFAULT).BeatLength;
60000 / (TimingPoints.MaxBy(c => c.BeatLength) ?? TimingControlPoint.DEFAULT).BeatLength;

/// <summary>
/// Remove all <see cref="ControlPointGroup"/>s and return to a pristine state.
Expand Down
5 changes: 1 addition & 4 deletions osu.Game/Rulesets/RulesetStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,7 @@ protected RulesetStore(Storage? storage = null)
return false;
return args.Name.Contains(name, StringComparison.Ordinal);
})
// Pick the greatest assembly version.
.OrderByDescending(a => a.GetName().Version)
.FirstOrDefault();
}).MaxBy(a => a.GetName().Version);

if (domainAssembly != null)
return domainAssembly;
Expand Down
2 changes: 1 addition & 1 deletion osu.Game/Rulesets/Scoring/ScoreProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ private void extractScoringValues(IReadOnlyDictionary<HitResult, int> statistics
break;

default:
maxResult = maxBasicResult ??= ruleset.GetHitResults().OrderByDescending(kvp => Judgement.ToNumericResult(kvp.result)).First().result;
maxResult = maxBasicResult ??= ruleset.GetHitResults().MaxBy(kvp => Judgement.ToNumericResult(kvp.result)).result;
break;
}

Expand Down
4 changes: 1 addition & 3 deletions osu.Game/Rulesets/UI/GameplaySampleTriggerSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,7 @@ protected HitObject GetMostValidObject()
// We need to use lifetime entries to find the next object (we can't just use `hitObjectContainer.Objects` due to pooling - it may even be empty).
// If required, we can make this lookup more efficient by adding support to get next-future-entry in LifetimeEntryManager.
fallbackObject = hitObjectContainer.Entries
.Where(e => e.Result?.HasResult != true)
.OrderBy(e => e.HitObject.StartTime)
.FirstOrDefault();
.Where(e => e.Result?.HasResult != true).MinBy(e => e.HitObject.StartTime);

// In the case there are no unjudged objects, the last hit object should be used instead.
fallbackObject ??= hitObjectContainer.Entries.LastOrDefault();
Expand Down
3 changes: 1 addition & 2 deletions osu.Game/Scoring/ScoreImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ public void PopulateMaximumStatistics(ScoreInfo score)
// Populate the maximum statistics.
HitResult maxBasicResult = rulesetInstance.GetHitResults()
.Select(h => h.result)
.Where(h => h.IsBasic())
.OrderByDescending(Judgement.ToNumericResult).First();
.Where(h => h.IsBasic()).MaxBy(Judgement.ToNumericResult);

foreach ((HitResult result, int count) in score.Statistics)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ private void handleMouseInput(Vector2 screenSpaceMousePosition)
// copied from SliderBar so we can do custom spacing logic.
float xPosition = (ToLocalSpace(screenSpaceMousePosition).X - RangePadding) / UsableWidth;

CurrentNumber.Value = beatDivisor.ValidDivisors.Value.Presets.OrderBy(d => Math.Abs(getMappedPosition(d) - xPosition)).First();
CurrentNumber.Value = beatDivisor.ValidDivisors.Value.Presets.MinBy(d => Math.Abs(getMappedPosition(d) - xPosition));
OnUserChange(Current.Value);
}

Expand Down
2 changes: 1 addition & 1 deletion osu.Game/Screens/Edit/Compose/ComposeScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ private string formatSelectionAsString()
if (composer == null)
return string.Empty;

double displayTime = EditorBeatmap.SelectedHitObjects.OrderBy(h => h.StartTime).FirstOrDefault()?.StartTime ?? clock.CurrentTime;
double displayTime = EditorBeatmap.SelectedHitObjects.MinBy(h => h.StartTime)?.StartTime ?? clock.CurrentTime;
string selectionAsString = composer.ConvertSelectionToString();

return !string.IsNullOrEmpty(selectionAsString)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,7 @@ protected override void Update()

if (!isCandidateAudioSource(currentAudioSource?.SpectatorPlayerClock))
{
currentAudioSource = instances.Where(i => isCandidateAudioSource(i.SpectatorPlayerClock))
.OrderBy(i => Math.Abs(i.SpectatorPlayerClock.CurrentTime - syncManager.CurrentMasterTime))
.FirstOrDefault();
currentAudioSource = instances.Where(i => isCandidateAudioSource(i.SpectatorPlayerClock)).MinBy(i => Math.Abs(i.SpectatorPlayerClock.CurrentTime - syncManager.CurrentMasterTime));

// Only bind adjustments if there's actually a valid source, else just use the previous ones to ensure no sudden changes to audio.
if (currentAudioSource != null)
Expand Down
4 changes: 2 additions & 2 deletions osu.Game/Storyboards/Storyboard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class Storyboard
/// <remarks>
/// This iterates all elements and as such should be used sparingly or stored locally.
/// </remarks>
public double? EarliestEventTime => Layers.SelectMany(l => l.Elements).OrderBy(e => e.StartTime).FirstOrDefault()?.StartTime;
public double? EarliestEventTime => Layers.SelectMany(l => l.Elements).MinBy(e => e.StartTime)?.StartTime;

/// <summary>
/// Across all layers, find the latest point in time that a storyboard element ends at.
Expand All @@ -42,7 +42,7 @@ public class Storyboard
/// This iterates all elements and as such should be used sparingly or stored locally.
/// Videos and samples return StartTime as their EndTIme.
/// </remarks>
public double? LatestEventTime => Layers.SelectMany(l => l.Elements).OrderBy(e => e.GetEndTime()).LastOrDefault()?.GetEndTime();
public double? LatestEventTime => Layers.SelectMany(l => l.Elements).MaxBy(e => e.GetEndTime())?.GetEndTime();

/// <summary>
/// Depth of the currently front-most storyboard layer, excluding the overlay layer.
Expand Down
2 changes: 1 addition & 1 deletion osu.Game/Storyboards/StoryboardSprite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public double StartTime

if (alphaCommands.Count > 0)
{
var firstAlpha = alphaCommands.OrderBy(t => t.startTime).First();
var firstAlpha = alphaCommands.MinBy(t => t.startTime);

if (firstAlpha.isZeroStartValue)
return firstAlpha.startTime;
Expand Down
4 changes: 1 addition & 3 deletions osu.Game/Tests/Visual/Multiplayer/TestMultiplayerClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,7 @@ private void addUser(MultiplayerRoomUser user)
// simulate the server's automatic assignment of users to teams on join.
// the "best" team is the one with the least users on it.
int bestTeam = teamVersus.Teams
.Select(team => (teamID: team.ID, userCount: ServerRoom.Users.Count(u => (u.MatchState as TeamVersusUserState)?.TeamID == team.ID)))
.OrderBy(pair => pair.userCount)
.First().teamID;
.Select(team => (teamID: team.ID, userCount: ServerRoom.Users.Count(u => (u.MatchState as TeamVersusUserState)?.TeamID == team.ID))).MinBy(pair => pair.userCount).teamID;

user.MatchState = new TeamVersusUserState { TeamID = bestTeam };
((IMultiplayerClient)this).MatchUserStateChanged(clone(user.UserID), clone(user.MatchState)).WaitSafely();
Expand Down
1 change: 1 addition & 0 deletions osu.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ReplaceWithSingleOrDefault_002E3/@EntryIndexedValue">WARNING</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ReplaceWithSingleOrDefault_002E4/@EntryIndexedValue">WARNING</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=SeparateControlTransferStatement/@EntryIndexedValue">WARNING</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=SimplifyLinqExpressionUseMinByAndMaxBy/@EntryIndexedValue">WARNING</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=StringEndsWithIsCultureSpecific/@EntryIndexedValue">WARNING</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=StringLiteralTypo/@EntryIndexedValue">HINT</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=StringStartsWithIsCultureSpecific/@EntryIndexedValue">WARNING</s:String>
Expand Down

0 comments on commit b9908d7

Please sign in to comment.