1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 12:33:01 +08:00

Merge branch 'reinstantiate-mods' into sorcerer-diffcalc-changes

This commit is contained in:
smoogipoo 2019-03-14 23:42:11 +09:00
commit 2bf01e876e
6 changed files with 46 additions and 42 deletions

View File

@ -90,12 +90,12 @@ namespace osu.Game.Rulesets.Catch.Difficulty
new Movement(),
};
protected override Mod[] DifficultyAdjustmentMods => new Mod[]
protected override Type[] DifficultyAdjustmentMods => new[]
{
new CatchModDoubleTime(),
new CatchModHalfTime(),
new CatchModHardRock(),
new CatchModEasy(),
typeof(CatchModDoubleTime),
typeof(CatchModHalfTime),
typeof(CatchModHardRock),
typeof(CatchModEasy),
};
}
}

View File

@ -1,6 +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 System.Linq;
using osu.Game.Beatmaps;
@ -91,33 +92,33 @@ namespace osu.Game.Rulesets.Mania.Difficulty
return skills.ToArray();
}
protected override Mod[] DifficultyAdjustmentMods
protected override Type[] DifficultyAdjustmentMods
{
get
{
var mods = new Mod[]
var mods = new[]
{
new ManiaModDoubleTime(),
new ManiaModHalfTime(),
new ManiaModEasy(),
new ManiaModHardRock(),
typeof(ManiaModDoubleTime),
typeof(ManiaModHalfTime),
typeof(ManiaModEasy),
typeof(ManiaModHardRock)
};
if (isForCurrentRuleset)
return mods;
// if we are a convert, we can be played in any key mod.
return mods.Concat(new Mod[]
return mods.Concat(new[]
{
new ManiaModKey1(),
new ManiaModKey2(),
new ManiaModKey3(),
new ManiaModKey4(),
new ManiaModKey5(),
new ManiaModKey6(),
new ManiaModKey7(),
new ManiaModKey8(),
new ManiaModKey9(),
typeof(ManiaModKey1),
typeof(ManiaModKey2),
typeof(ManiaModKey3),
typeof(ManiaModKey4),
typeof(ManiaModKey5),
typeof(ManiaModKey6),
typeof(ManiaModKey7),
typeof(ManiaModKey8),
typeof(ManiaModKey9),
}).ToArray();
}
}

View File

@ -74,12 +74,12 @@ namespace osu.Game.Rulesets.Osu.Difficulty
new Speed()
};
protected override Mod[] DifficultyAdjustmentMods => new Mod[]
protected override Type[] DifficultyAdjustmentMods => new[]
{
new OsuModDoubleTime(),
new OsuModHalfTime(),
new OsuModEasy(),
new OsuModHardRock(),
typeof(OsuModDoubleTime),
typeof(OsuModHalfTime),
typeof(OsuModEasy),
typeof(OsuModHardRock),
};
}
}

View File

@ -1,6 +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 System.Linq;
using osu.Game.Beatmaps;
@ -47,12 +48,12 @@ namespace osu.Game.Rulesets.Taiko.Difficulty
protected override Skill[] CreateSkills(IBeatmap beatmap) => new Skill[] { new Strain() };
protected override Mod[] DifficultyAdjustmentMods => new Mod[]
protected override Type[] DifficultyAdjustmentMods => new[]
{
new TaikoModDoubleTime(),
new TaikoModHalfTime(),
new TaikoModEasy(),
new TaikoModHardRock(),
typeof(TaikoModDoubleTime),
typeof(TaikoModHalfTime),
typeof(TaikoModEasy),
typeof(TaikoModHardRock),
};
}
}

View File

@ -27,7 +27,7 @@ namespace osu.Game.Tests.NonVisual
[Test]
public void TestSingleMod()
{
var combinations = new TestLegacyDifficultyCalculator(new ModA()).CreateDifficultyAdjustmentModCombinations();
var combinations = new TestLegacyDifficultyCalculator(typeof(ModA)).CreateDifficultyAdjustmentModCombinations();
Assert.AreEqual(2, combinations.Length);
Assert.IsTrue(combinations[0] is ModNoMod);
@ -37,7 +37,7 @@ namespace osu.Game.Tests.NonVisual
[Test]
public void TestDoubleMod()
{
var combinations = new TestLegacyDifficultyCalculator(new ModA(), new ModB()).CreateDifficultyAdjustmentModCombinations();
var combinations = new TestLegacyDifficultyCalculator(typeof(ModA), typeof(ModB)).CreateDifficultyAdjustmentModCombinations();
Assert.AreEqual(4, combinations.Length);
Assert.IsTrue(combinations[0] is ModNoMod);
@ -52,7 +52,7 @@ namespace osu.Game.Tests.NonVisual
[Test]
public void TestIncompatibleMods()
{
var combinations = new TestLegacyDifficultyCalculator(new ModA(), new ModIncompatibleWithA()).CreateDifficultyAdjustmentModCombinations();
var combinations = new TestLegacyDifficultyCalculator(typeof(ModA), typeof(ModIncompatibleWithA)).CreateDifficultyAdjustmentModCombinations();
Assert.AreEqual(3, combinations.Length);
Assert.IsTrue(combinations[0] is ModNoMod);
@ -63,7 +63,7 @@ namespace osu.Game.Tests.NonVisual
[Test]
public void TestDoubleIncompatibleMods()
{
var combinations = new TestLegacyDifficultyCalculator(new ModA(), new ModB(), new ModIncompatibleWithA(), new ModIncompatibleWithAAndB()).CreateDifficultyAdjustmentModCombinations();
var combinations = new TestLegacyDifficultyCalculator(typeof(ModA), typeof(ModB), typeof(ModIncompatibleWithA), typeof(ModIncompatibleWithAAndB)).CreateDifficultyAdjustmentModCombinations();
Assert.AreEqual(8, combinations.Length);
Assert.IsTrue(combinations[0] is ModNoMod);
@ -86,7 +86,7 @@ namespace osu.Game.Tests.NonVisual
[Test]
public void TestIncompatibleThroughBaseType()
{
var combinations = new TestLegacyDifficultyCalculator(new ModAofA(), new ModIncompatibleWithAofA()).CreateDifficultyAdjustmentModCombinations();
var combinations = new TestLegacyDifficultyCalculator(typeof(ModAofA), typeof(ModIncompatibleWithAofA)).CreateDifficultyAdjustmentModCombinations();
Assert.AreEqual(3, combinations.Length);
Assert.IsTrue(combinations[0] is ModNoMod);
@ -141,13 +141,13 @@ namespace osu.Game.Tests.NonVisual
private class TestLegacyDifficultyCalculator : DifficultyCalculator
{
public TestLegacyDifficultyCalculator(params Mod[] mods)
public TestLegacyDifficultyCalculator(params Type[] mods)
: base(null, null)
{
DifficultyAdjustmentMods = mods;
}
protected override Mod[] DifficultyAdjustmentMods { get; }
protected override Type[] DifficultyAdjustmentMods { get; }
protected override DifficultyAttributes CreateDifficultyAttributes(IBeatmap beatmap, Mod[] mods, Skill[] skills, double clockRate)
{

View File

@ -106,7 +106,7 @@ namespace osu.Game.Rulesets.Difficulty
{
return createDifficultyAdjustmentModCombinations(Enumerable.Empty<Mod>(), DifficultyAdjustmentMods).ToArray();
IEnumerable<Mod> createDifficultyAdjustmentModCombinations(IEnumerable<Mod> currentSet, Mod[] adjustmentSet, int currentSetCount = 0, int adjustmentSetStart = 0)
IEnumerable<Mod> createDifficultyAdjustmentModCombinations(IEnumerable<Mod> currentSet, Type[] adjustmentSet, int currentSetCount = 0, int adjustmentSetStart = 0)
{
switch (currentSetCount)
{
@ -129,12 +129,14 @@ namespace osu.Game.Rulesets.Difficulty
// combinations in further recursions, so a moving subset is used to eliminate this effect
for (int i = adjustmentSetStart; i < adjustmentSet.Length; i++)
{
var adjustmentMod = adjustmentSet[i];
var adjustmentMod = createMod();
if (currentSet.Any(c => c.IncompatibleMods.Any(m => m.IsInstanceOfType(adjustmentMod))))
continue;
foreach (var combo in createDifficultyAdjustmentModCombinations(currentSet.Append(adjustmentMod), adjustmentSet, currentSetCount + 1, i + 1))
foreach (var combo in createDifficultyAdjustmentModCombinations(currentSet.Append(createMod()), adjustmentSet, currentSetCount + 1, i + 1))
yield return combo;
Mod createMod() => (Mod)Activator.CreateInstance(adjustmentSet[i]);
}
}
}
@ -142,7 +144,7 @@ namespace osu.Game.Rulesets.Difficulty
/// <summary>
/// Retrieves all <see cref="Mod"/>s which adjust the <see cref="Beatmap"/> difficulty.
/// </summary>
protected virtual Mod[] DifficultyAdjustmentMods => Array.Empty<Mod>();
protected virtual Type[] DifficultyAdjustmentMods => Array.Empty<Type>();
/// <summary>
/// Creates <see cref="DifficultyAttributes"/> to describe beatmap's calculated difficulty.