1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-12 17:43:05 +08:00

Move checking logic inside ModUtils and somewhat optimise

This commit is contained in:
Salman Ahmed 2024-01-15 14:57:17 +03:00
parent 494c1be655
commit 1d7b63e204
2 changed files with 34 additions and 1 deletions

View File

@ -38,6 +38,7 @@ using osu.Game.Screens.Play.HUD;
using osu.Game.Screens.Ranking;
using osu.Game.Skinning;
using osu.Game.Users;
using osu.Game.Utils;
using osuTK.Graphics;
namespace osu.Game.Screens.Play
@ -213,7 +214,7 @@ namespace osu.Game.Screens.Play
if (playableBeatmap == null)
return;
if (gameplayMods.Any(m => ruleset.AllMods.All(rulesetMod => m.GetType() != rulesetMod.GetType())))
if (!ModUtils.CheckModsBelongToRuleset(ruleset, gameplayMods))
{
Logger.Log($@"Gameplay was started with a mod belonging to a ruleset different than '{ruleset.Description}'.", level: LogLevel.Important);
return;

View File

@ -229,6 +229,38 @@ namespace osu.Game.Utils
return proposedWereValid;
}
/// <summary>
/// Verifies all mods provided belong to the given ruleset.
/// </summary>
/// <param name="ruleset">The ruleset to check the proposed mods against.</param>
/// <param name="proposedMods">The mods proposed for checking.</param>
/// <returns>Whether all <paramref name="proposedMods"/> belong to the given <paramref name="ruleset"/>.</returns>
public static bool CheckModsBelongToRuleset(Ruleset ruleset, IEnumerable<Mod> proposedMods)
{
var rulesetModsTypes = ruleset.AllMods.Select(m => m.GetType()).ToList();
foreach (var proposedMod in proposedMods)
{
bool found = false;
var proposedModType = proposedMod.GetType();
foreach (var rulesetModType in rulesetModsTypes)
{
if (rulesetModType == proposedModType)
{
found = true;
break;
}
}
if (!found)
return true;
}
return true;
}
/// <summary>
/// Given a value of a score multiplier, returns a string version with special handling for a value near 1.00x.
/// </summary>