1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-12 08:33:04 +08:00

Added maintainability patch by bdach

This commit is contained in:
OliBomby 2023-03-06 16:20:36 +01:00
parent b0cd801405
commit 1fcf41379d
2 changed files with 33 additions and 24 deletions

View File

@ -1,7 +1,7 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Collections.Generic;
using osu.Framework.Localisation;
namespace osu.Game.Beatmaps
@ -29,25 +29,19 @@ namespace osu.Game.Beatmaps
return new RomanisableString($"{metadata.GetPreferred(true)}".Trim(), $"{metadata.GetPreferred(false)}".Trim());
}
public static ReadOnlySpan<string> GetSearchableTerms(this IBeatmapInfo beatmapInfo)
public static List<string> GetSearchableTerms(this IBeatmapInfo beatmapInfo)
{
string[] terms = new string[8];
int i = 0;
var metadata = beatmapInfo.Metadata;
var termsList = new List<string>(BeatmapMetadataInfoExtensions.MAX_SEARCHABLE_TERM_COUNT + 1);
addIfNotNull(beatmapInfo.DifficultyName);
addIfNotNull(metadata.Author.Username);
addIfNotNull(metadata.Artist);
addIfNotNull(metadata.ArtistUnicode);
addIfNotNull(metadata.Title);
addIfNotNull(metadata.TitleUnicode);
addIfNotNull(metadata.Source);
addIfNotNull(metadata.Tags);
return terms.AsSpan(0, i);
BeatmapMetadataInfoExtensions.CollectSearchableTerms(beatmapInfo.Metadata, termsList);
return termsList;
void addIfNotNull(string? s)
{
if (!string.IsNullOrEmpty(s))
terms[i++] = s;
termsList.Add(s);
}
}

View File

@ -3,7 +3,7 @@
#nullable disable
using System.Linq;
using System.Collections.Generic;
using osu.Framework.Localisation;
namespace osu.Game.Beatmaps
@ -13,16 +13,31 @@ namespace osu.Game.Beatmaps
/// <summary>
/// An array of all searchable terms provided in contained metadata.
/// </summary>
public static string[] GetSearchableTerms(this IBeatmapMetadataInfo metadataInfo) => new[]
public static string[] GetSearchableTerms(this IBeatmapMetadataInfo metadataInfo)
{
metadataInfo.Author.Username,
metadataInfo.Artist,
metadataInfo.ArtistUnicode,
metadataInfo.Title,
metadataInfo.TitleUnicode,
metadataInfo.Source,
metadataInfo.Tags
}.Where(s => !string.IsNullOrEmpty(s)).ToArray();
var termsList = new List<string>(MAX_SEARCHABLE_TERM_COUNT);
CollectSearchableTerms(metadataInfo, termsList);
return termsList.ToArray();
}
internal const int MAX_SEARCHABLE_TERM_COUNT = 7;
internal static void CollectSearchableTerms(IBeatmapMetadataInfo metadataInfo, IList<string> termsList)
{
addIfNotNull(metadataInfo.Author.Username);
addIfNotNull(metadataInfo.Artist);
addIfNotNull(metadataInfo.ArtistUnicode);
addIfNotNull(metadataInfo.Title);
addIfNotNull(metadataInfo.TitleUnicode);
addIfNotNull(metadataInfo.Source);
addIfNotNull(metadataInfo.Tags);
void addIfNotNull(string s)
{
if (!string.IsNullOrEmpty(s))
termsList.Add(s);
}
}
/// <summary>
/// A user-presentable display title representing this metadata.