|
2 | 2 | // See the LICENCE file in the repository root for full licence text.
|
3 | 3 |
|
4 | 4 | using System.Collections.Generic;
|
| 5 | +using System.Linq; |
5 | 6 | using NUnit.Framework;
|
6 | 7 | using osu.Framework.Bindables;
|
7 | 8 | using osu.Game.Beatmaps;
|
@@ -99,6 +100,59 @@ public void TestCriteriaMatchingConvertedBeatmapsForCustomRulesets()
|
99 | 100 | Assert.IsFalse(carouselItem.Filtered.Value);
|
100 | 101 | }
|
101 | 102 |
|
| 103 | + [Test] |
| 104 | + [TestCase(true)] |
| 105 | + [TestCase(false)] |
| 106 | + public void TestCriteriaMatchingCustomConvertRules(bool convertsStd) |
| 107 | + { |
| 108 | + var exampleBeatmapInfo = getExampleBeatmap(); |
| 109 | + var criteria = new FilterCriteria |
| 110 | + { |
| 111 | + Ruleset = new RulesetInfo { OnlineID = -1, ShortName = "custom" }, |
| 112 | + AllowConvertedBeatmaps = true, |
| 113 | + RulesetConvertSupport = new CustomConvertSupport(["custom"], convertsStd ? ["osu"] : []) |
| 114 | + }; |
| 115 | + var carouselItem = new CarouselBeatmap(exampleBeatmapInfo); |
| 116 | + carouselItem.Filter(criteria); |
| 117 | + Assert.AreEqual(!convertsStd, carouselItem.Filtered.Value); |
| 118 | + } |
| 119 | + |
| 120 | + [Test] |
| 121 | + [TestCase(true)] |
| 122 | + [TestCase(false)] |
| 123 | + public void TestCriteriaMatchingCustomNativeConvertRules(bool allowConverts) |
| 124 | + { |
| 125 | + var exampleBeatmapInfo = getExampleBeatmap(); |
| 126 | + var criteria = new FilterCriteria |
| 127 | + { |
| 128 | + Ruleset = new RulesetInfo { OnlineID = -1, ShortName = "custom" }, |
| 129 | + AllowConvertedBeatmaps = allowConverts, |
| 130 | + RulesetConvertSupport = new CustomConvertSupport(["custom", "osu"], []) |
| 131 | + }; |
| 132 | + var carouselItem = new CarouselBeatmap(exampleBeatmapInfo); |
| 133 | + carouselItem.Filter(criteria); |
| 134 | + Assert.IsFalse(carouselItem.Filtered.Value); |
| 135 | + } |
| 136 | + |
| 137 | + private class CustomConvertSupport : IRulesetConvertSupport |
| 138 | + { |
| 139 | + private readonly string[] nativeFormats, convertFormats; |
| 140 | + |
| 141 | + public CustomConvertSupport(string[] nativeFormats, string[] convertFormats) |
| 142 | + { |
| 143 | + this.nativeFormats = nativeFormats; |
| 144 | + this.convertFormats = convertFormats; |
| 145 | + } |
| 146 | + |
| 147 | + public bool CanBePlayed(RulesetInfo ruleset, bool conversionEnabled) |
| 148 | + { |
| 149 | + if (conversionEnabled && convertFormats.Contains(ruleset.ShortName)) |
| 150 | + return true; |
| 151 | + |
| 152 | + return nativeFormats.Contains(ruleset.ShortName); |
| 153 | + } |
| 154 | + } |
| 155 | + |
102 | 156 | [Test]
|
103 | 157 | [TestCase(true)]
|
104 | 158 | [TestCase(false)]
|
|
0 commit comments