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:
parent
494c1be655
commit
1d7b63e204
@ -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;
|
||||
|
@ -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>
|
||||
|
Loading…
Reference in New Issue
Block a user