mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 01:42:55 +08:00
Add helper method to convert to legacy mods enums
This commit is contained in:
parent
e5f4d8686e
commit
546772192c
@ -48,7 +48,7 @@ namespace osu.Game.Rulesets.Catch
|
||||
new KeyBinding(InputKey.Shift, CatchAction.Dash),
|
||||
};
|
||||
|
||||
public override IEnumerable<Mod> ConvertLegacyMods(LegacyMods mods)
|
||||
public override IEnumerable<Mod> ConvertFromLegacyMods(LegacyMods mods)
|
||||
{
|
||||
if (mods.HasFlag(LegacyMods.Nightcore))
|
||||
yield return new CatchModNightcore();
|
||||
|
@ -49,7 +49,7 @@ namespace osu.Game.Rulesets.Mania
|
||||
|
||||
public override ISkin CreateLegacySkinProvider(ISkinSource source) => new ManiaLegacySkinTransformer(source);
|
||||
|
||||
public override IEnumerable<Mod> ConvertLegacyMods(LegacyMods mods)
|
||||
public override IEnumerable<Mod> ConvertFromLegacyMods(LegacyMods mods)
|
||||
{
|
||||
if (mods.HasFlag(LegacyMods.Nightcore))
|
||||
yield return new ManiaModNightcore();
|
||||
@ -118,6 +118,59 @@ namespace osu.Game.Rulesets.Mania
|
||||
yield return new ManiaModRandom();
|
||||
}
|
||||
|
||||
public override LegacyMods ConvertToLegacyMods(Mod[] mods)
|
||||
{
|
||||
var value = base.ConvertToLegacyMods(mods);
|
||||
|
||||
foreach (var mod in mods)
|
||||
{
|
||||
switch (mod)
|
||||
{
|
||||
case ManiaModKey1 _:
|
||||
value |= LegacyMods.Key1;
|
||||
break;
|
||||
|
||||
case ManiaModKey2 _:
|
||||
value |= LegacyMods.Key2;
|
||||
break;
|
||||
|
||||
case ManiaModKey3 _:
|
||||
value |= LegacyMods.Key3;
|
||||
break;
|
||||
|
||||
case ManiaModKey4 _:
|
||||
value |= LegacyMods.Key4;
|
||||
break;
|
||||
|
||||
case ManiaModKey5 _:
|
||||
value |= LegacyMods.Key5;
|
||||
break;
|
||||
|
||||
case ManiaModKey6 _:
|
||||
value |= LegacyMods.Key6;
|
||||
break;
|
||||
|
||||
case ManiaModKey7 _:
|
||||
value |= LegacyMods.Key7;
|
||||
break;
|
||||
|
||||
case ManiaModKey8 _:
|
||||
value |= LegacyMods.Key8;
|
||||
break;
|
||||
|
||||
case ManiaModKey9 _:
|
||||
value |= LegacyMods.Key9;
|
||||
break;
|
||||
|
||||
case ManiaModFadeIn _:
|
||||
value |= LegacyMods.FadeIn;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
public override IEnumerable<Mod> GetModsFor(ModType type)
|
||||
{
|
||||
switch (type)
|
||||
|
@ -52,7 +52,7 @@ namespace osu.Game.Rulesets.Osu
|
||||
new KeyBinding(InputKey.MouseRight, OsuAction.RightButton),
|
||||
};
|
||||
|
||||
public override IEnumerable<Mod> ConvertLegacyMods(LegacyMods mods)
|
||||
public override IEnumerable<Mod> ConvertFromLegacyMods(LegacyMods mods)
|
||||
{
|
||||
if (mods.HasFlag(LegacyMods.Nightcore))
|
||||
yield return new OsuModNightcore();
|
||||
|
@ -50,7 +50,7 @@ namespace osu.Game.Rulesets.Taiko
|
||||
new KeyBinding(InputKey.K, TaikoAction.RightRim),
|
||||
};
|
||||
|
||||
public override IEnumerable<Mod> ConvertLegacyMods(LegacyMods mods)
|
||||
public override IEnumerable<Mod> ConvertFromLegacyMods(LegacyMods mods)
|
||||
{
|
||||
if (mods.HasFlag(LegacyMods.Nightcore))
|
||||
yield return new TaikoModNightcore();
|
||||
|
@ -42,9 +42,63 @@ namespace osu.Game.Rulesets
|
||||
/// <summary>
|
||||
/// Converts mods from legacy enum values. Do not override if you're not a legacy ruleset.
|
||||
/// </summary>
|
||||
/// <param name="mods">The legacy enum which will be converted</param>
|
||||
/// <returns>An enumerable of constructed <see cref="Mod"/>s</returns>
|
||||
public virtual IEnumerable<Mod> ConvertLegacyMods(LegacyMods mods) => Array.Empty<Mod>();
|
||||
/// <param name="mods">The legacy enum which will be converted.</param>
|
||||
/// <returns>An enumerable of constructed <see cref="Mod"/>s.</returns>
|
||||
public virtual IEnumerable<Mod> ConvertFromLegacyMods(LegacyMods mods) => Array.Empty<Mod>();
|
||||
|
||||
/// <summary>
|
||||
/// Converts mods to legacy enum values. Do not override if you're not a legacy ruleset.
|
||||
/// </summary>
|
||||
/// <param name="mods">The mods which will be converted.</param>
|
||||
/// <returns>A single bitwise enumerable value representing (to the best of our ability) the mods.</returns>
|
||||
public virtual LegacyMods ConvertToLegacyMods(Mod[] mods)
|
||||
{
|
||||
var value = LegacyMods.None;
|
||||
|
||||
foreach (var mod in mods)
|
||||
{
|
||||
switch (mod)
|
||||
{
|
||||
case ModNoFail _:
|
||||
value |= LegacyMods.NoFail;
|
||||
break;
|
||||
|
||||
case ModEasy _:
|
||||
value |= LegacyMods.Easy;
|
||||
break;
|
||||
|
||||
case ModHidden _:
|
||||
value |= LegacyMods.Hidden;
|
||||
break;
|
||||
|
||||
case ModHardRock _:
|
||||
value |= LegacyMods.HardRock;
|
||||
break;
|
||||
|
||||
case ModSuddenDeath _:
|
||||
value |= LegacyMods.SuddenDeath;
|
||||
break;
|
||||
|
||||
case ModDoubleTime _:
|
||||
value |= LegacyMods.DoubleTime;
|
||||
break;
|
||||
|
||||
case ModRelax _:
|
||||
value |= LegacyMods.Relax;
|
||||
break;
|
||||
|
||||
case ModHalfTime _:
|
||||
value |= LegacyMods.HalfTime;
|
||||
break;
|
||||
|
||||
case ModFlashlight _:
|
||||
value |= LegacyMods.Flashlight;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
public ModAutoplay GetAutoplayMod() => GetAllMods().OfType<ModAutoplay>().First();
|
||||
|
||||
|
@ -66,7 +66,7 @@ namespace osu.Game.Scoring.Legacy
|
||||
/* score.Perfect = */
|
||||
sr.ReadBoolean();
|
||||
|
||||
scoreInfo.Mods = currentRuleset.ConvertLegacyMods((LegacyMods)sr.ReadInt32()).ToArray();
|
||||
scoreInfo.Mods = currentRuleset.ConvertFromLegacyMods((LegacyMods)sr.ReadInt32()).ToArray();
|
||||
|
||||
/* score.HpGraphString = */
|
||||
sr.ReadString();
|
||||
|
35
osu.Game/Scoring/Legacy/LegacyScoreEncoder.cs
Normal file
35
osu.Game/Scoring/Legacy/LegacyScoreEncoder.cs
Normal file
@ -0,0 +1,35 @@
|
||||
// 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.IO;
|
||||
|
||||
namespace osu.Game.Scoring.Legacy
|
||||
{
|
||||
public class LegacyScoreEncoder
|
||||
{
|
||||
public const int LATEST_VERSION = 128;
|
||||
|
||||
private readonly Score score;
|
||||
|
||||
public LegacyScoreEncoder(Score score)
|
||||
{
|
||||
this.score = score;
|
||||
|
||||
if (score.ScoreInfo.Beatmap.RulesetID < 0 || score.ScoreInfo.Beatmap.RulesetID > 3)
|
||||
throw new ArgumentException("Only scores in the osu, taiko, catch, or mania rulesets can be encoded to the legacy score format.", nameof(score));
|
||||
}
|
||||
|
||||
public void Encode(TextWriter writer)
|
||||
{
|
||||
writer.WriteLine($"osu file format v{LATEST_VERSION}");
|
||||
|
||||
writer.WriteLine();
|
||||
handleGeneral(writer);
|
||||
}
|
||||
|
||||
private void handleGeneral(TextWriter writer)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
@ -23,7 +23,7 @@ namespace osu.Game.Tests.Beatmaps
|
||||
protected void Test(LegacyMods legacyMods, Type[] expectedMods)
|
||||
{
|
||||
var ruleset = CreateRuleset();
|
||||
var mods = ruleset.ConvertLegacyMods(legacyMods).ToList();
|
||||
var mods = ruleset.ConvertFromLegacyMods(legacyMods).ToList();
|
||||
Assert.AreEqual(expectedMods.Length, mods.Count);
|
||||
|
||||
foreach (var modType in expectedMods)
|
||||
|
Loading…
Reference in New Issue
Block a user