1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-21 21:27:24 +08:00

Parse the mods of a leaderboard's score

This commit is contained in:
MrTheMake 2017-08-13 17:41:13 +02:00
parent 07487b5ca9
commit 4c2d7bf343
28 changed files with 188 additions and 7 deletions

View File

@ -20,6 +20,24 @@ namespace osu.Game.Rulesets.Catch
{
public override RulesetContainer CreateRulesetContainerWith(WorkingBeatmap beatmap, bool isForCurrentRuleset) => new CatchRulesetContainer(this, beatmap, isForCurrentRuleset);
public override IEnumerable<Mod> GetAllMods() => new Mod[]
{
new CatchModEasy(),
new CatchModNoFail(),
new CatchModHalfTime(),
new CatchModDaycore(),
new CatchModHardRock(),
new CatchModSuddenDeath(),
new CatchModPerfect(),
new CatchModDoubleTime(),
new CatchModNightcore(),
new CatchModHidden(),
new CatchModFlashlight(),
new CatchModRelax(),
new ModAutoplay(),
new ModCinema()
};
public override IEnumerable<Mod> GetModsFor(ModType type)
{
switch (type)

View File

@ -19,6 +19,36 @@ namespace osu.Game.Rulesets.Mania
{
public override RulesetContainer CreateRulesetContainerWith(WorkingBeatmap beatmap, bool isForCurrentRuleset) => new ManiaRulesetContainer(this, beatmap, isForCurrentRuleset);
public override IEnumerable<Mod> GetAllMods() => new Mod[]
{
new ManiaModEasy(),
new ManiaModNoFail(),
new ManiaModHalfTime(),
new ManiaModDaycore(),
new ManiaModHardRock(),
new ManiaModSuddenDeath(),
new ManiaModPerfect(),
new ManiaModDoubleTime(),
new ManiaModNightcore(),
new ManiaModFadeIn(),
new ManiaModHidden(),
new ManiaModFlashlight(),
new ManiaModKey4(),
new ManiaModKey5(),
new ManiaModKey6(),
new ManiaModKey7(),
new ManiaModKey8(),
new ManiaModKey9(),
new ManiaModKey1(),
new ManiaModKey2(),
new ManiaModKey3(),
new ManiaModRandom(),
new ManiaModKeyCoop(),
new ModAutoplay(),
new ModCinema(),
new ManiaModGravity()
};
public override IEnumerable<Mod> GetModsFor(ModType type)
{
switch (type)

View File

@ -68,6 +68,7 @@ namespace osu.Game.Rulesets.Mania.Mods
public class ManiaModFadeIn : Mod
{
public override string Name => "FadeIn";
public override string ShortenedName => "FI";
public override FontAwesome Icon => FontAwesome.fa_osu_mod_hidden;
public override ModType Type => ModType.DifficultyIncrease;
public override double ScoreMultiplier => 1;
@ -78,12 +79,14 @@ namespace osu.Game.Rulesets.Mania.Mods
public class ManiaModRandom : Mod
{
public override string Name => "Random";
public override string ShortenedName => "RD";
public override string Description => @"Shuffle around the notes!";
public override double ScoreMultiplier => 1;
}
public abstract class ManiaKeyMod : Mod
{
public override string ShortenedName => Name;
public abstract int KeyCount { get; }
public override double ScoreMultiplier => 1; // TODO: Implement the mania key mod score multiplier
public override bool Ranked => true;
@ -146,6 +149,7 @@ namespace osu.Game.Rulesets.Mania.Mods
public class ManiaModKeyCoop : Mod
{
public override string Name => "KeyCoop";
public override string ShortenedName => "CO";
public override string Description => @"Double the key amount, double the fun!";
public override double ScoreMultiplier => 1;
public override bool Ranked => true;

View File

@ -15,6 +15,7 @@ namespace osu.Game.Rulesets.Mania.Mods
public class ManiaModGravity : Mod, IGenerateSpeedAdjustments
{
public override string Name => "Gravity";
public override string ShortenedName => "GR";
public override double ScoreMultiplier => 0;

View File

@ -78,6 +78,7 @@ namespace osu.Game.Rulesets.Osu.Mods
public class OsuModSpunOut : Mod
{
public override string Name => "Spun Out";
public override string ShortenedName => "SO";
public override FontAwesome Icon => FontAwesome.fa_osu_mod_spunout;
public override string Description => @"Spinners will be automatically completed";
public override double ScoreMultiplier => 0.9;
@ -88,6 +89,7 @@ namespace osu.Game.Rulesets.Osu.Mods
public class OsuModAutopilot : Mod
{
public override string Name => "Autopilot";
public override string ShortenedName => "AP";
public override FontAwesome Icon => FontAwesome.fa_osu_mod_autopilot;
public override string Description => @"Automatic cursor movement - just follow the rhythm.";
public override double ScoreMultiplier => 0;
@ -108,6 +110,7 @@ namespace osu.Game.Rulesets.Osu.Mods
public class OsuModTarget : Mod
{
public override string Name => "Target";
public override string ShortenedName => "TP";
public override FontAwesome Icon => FontAwesome.fa_osu_mod_target;
public override string Description => @"";
public override double ScoreMultiplier => 1;

View File

@ -24,6 +24,27 @@ namespace osu.Game.Rulesets.Osu
{
public override RulesetContainer CreateRulesetContainerWith(WorkingBeatmap beatmap, bool isForCurrentRuleset) => new OsuRulesetContainer(this, beatmap, isForCurrentRuleset);
public override IEnumerable<Mod> GetAllMods() => new Mod[]
{
new OsuModEasy(),
new OsuModNoFail(),
new OsuModHalfTime(),
new OsuModDaycore(),
new OsuModHardRock(),
new OsuModSuddenDeath(),
new OsuModPerfect(),
new OsuModDoubleTime(),
new OsuModNightcore(),
new OsuModHidden(),
new OsuModFlashlight(),
new OsuModRelax(),
new OsuModAutopilot(),
new OsuModSpunOut(),
new OsuModAutoplay(),
new ModCinema(),
new OsuModTarget(),
};
public override IEnumerable<BeatmapStatistic> GetBeatmapStatistics(WorkingBeatmap beatmap) => new[]
{
new BeatmapStatistic

View File

@ -20,6 +20,24 @@ namespace osu.Game.Rulesets.Taiko
{
public override RulesetContainer CreateRulesetContainerWith(WorkingBeatmap beatmap, bool isForCurrentRuleset) => new TaikoRulesetContainer(this, beatmap, isForCurrentRuleset);
public override IEnumerable<Mod> GetAllMods() => new Mod[]
{
new TaikoModEasy(),
new TaikoModNoFail(),
new TaikoModHalfTime(),
new TaikoModDaycore(),
new TaikoModHardRock(),
new TaikoModSuddenDeath(),
new TaikoModPerfect(),
new TaikoModDoubleTime(),
new TaikoModNightcore(),
new TaikoModHidden(),
new TaikoModFlashlight(),
new TaikoModRelax(),
new TaikoModAutoplay(),
new ModCinema()
};
public override IEnumerable<Mod> GetModsFor(ModType type)
{
switch (type)

View File

@ -58,6 +58,8 @@ namespace osu.Game.Beatmaps
private class DummyRuleset : Ruleset
{
public override IEnumerable<Mod> GetAllMods() => new Mod[] { };
public override IEnumerable<Mod> GetModsFor(ModType type) => new Mod[] { };
public override Mod GetAutoplayMod() => new ModAutoplay();

View File

@ -16,6 +16,11 @@ namespace osu.Game.Rulesets.Mods
/// </summary>
public abstract string Name { get; }
/// <summary>
/// The shortened name of this mod.
/// </summary>
public abstract string ShortenedName { get; }
/// <summary>
/// The icon of this mod.
/// </summary>

View File

@ -24,6 +24,7 @@ namespace osu.Game.Rulesets.Mods
public class ModAutoplay : Mod
{
public override string Name => "Autoplay";
public override string ShortenedName => "AT";
public override FontAwesome Icon => FontAwesome.fa_osu_mod_auto;
public override string Description => "Watch a perfect automated play through the song";
public override double ScoreMultiplier => 0;

View File

@ -8,6 +8,7 @@ namespace osu.Game.Rulesets.Mods
public class ModCinema : ModAutoplay
{
public override string Name => "Cinema";
public override string ShortenedName => "CN";
public override FontAwesome Icon => FontAwesome.fa_osu_mod_cinema;
}
}

View File

@ -10,6 +10,7 @@ namespace osu.Game.Rulesets.Mods
public abstract class ModDaycore : ModHalfTime
{
public override string Name => "Daycore";
public override string ShortenedName => "DC";
public override FontAwesome Icon => FontAwesome.fa_question;
public override string Description => "whoaaaaa";

View File

@ -10,6 +10,7 @@ namespace osu.Game.Rulesets.Mods
public class ModDoubleTime : Mod, IApplicableToClock
{
public override string Name => "Double Time";
public override string ShortenedName => "DT";
public override FontAwesome Icon => FontAwesome.fa_osu_mod_doubletime;
public override ModType Type => ModType.DifficultyIncrease;
public override string Description => "Zoooooooooom";

View File

@ -10,6 +10,7 @@ namespace osu.Game.Rulesets.Mods
public abstract class ModEasy : Mod, IApplicableToDifficulty
{
public override string Name => "Easy";
public override string ShortenedName => "EZ";
public override FontAwesome Icon => FontAwesome.fa_osu_mod_easy;
public override ModType Type => ModType.DifficultyReduction;
public override string Description => "Reduces overall difficulty - larger circles, more forgiving HP drain, less accuracy required.";

View File

@ -8,6 +8,7 @@ namespace osu.Game.Rulesets.Mods
public abstract class ModFlashlight : Mod
{
public override string Name => "Flashlight";
public override string ShortenedName => "FL";
public override FontAwesome Icon => FontAwesome.fa_osu_mod_flashlight;
public override ModType Type => ModType.DifficultyIncrease;
public override string Description => "Restricted view area.";

View File

@ -10,6 +10,7 @@ namespace osu.Game.Rulesets.Mods
public abstract class ModHalfTime : Mod, IApplicableToClock
{
public override string Name => "Half Time";
public override string ShortenedName => "HT";
public override FontAwesome Icon => FontAwesome.fa_osu_mod_halftime;
public override ModType Type => ModType.DifficultyReduction;
public override string Description => "Less zoom";

View File

@ -10,6 +10,7 @@ namespace osu.Game.Rulesets.Mods
public abstract class ModHardRock : Mod, IApplicableToDifficulty
{
public override string Name => "Hard Rock";
public override string ShortenedName => "HR";
public override FontAwesome Icon => FontAwesome.fa_osu_mod_hardrock;
public override ModType Type => ModType.DifficultyIncrease;
public override string Description => "Everything just got a bit harder...";

View File

@ -8,6 +8,7 @@ namespace osu.Game.Rulesets.Mods
public abstract class ModHidden : Mod
{
public override string Name => "Hidden";
public override string ShortenedName => "HD";
public override FontAwesome Icon => FontAwesome.fa_osu_mod_hidden;
public override ModType Type => ModType.DifficultyIncrease;
public override bool Ranked => true;

View File

@ -10,6 +10,7 @@ namespace osu.Game.Rulesets.Mods
public abstract class ModNightcore : ModDoubleTime
{
public override string Name => "Nightcore";
public override string ShortenedName => "NC";
public override FontAwesome Icon => FontAwesome.fa_osu_mod_nightcore;
public override string Description => "uguuuuuuuu";

View File

@ -9,6 +9,7 @@ namespace osu.Game.Rulesets.Mods
public abstract class ModNoFail : Mod
{
public override string Name => "NoFail";
public override string ShortenedName => "NF";
public override FontAwesome Icon => FontAwesome.fa_osu_mod_nofail;
public override ModType Type => ModType.DifficultyReduction;
public override string Description => "You can't fail, no matter what.";

View File

@ -6,6 +6,7 @@ namespace osu.Game.Rulesets.Mods
public abstract class ModPerfect : ModSuddenDeath
{
public override string Name => "Perfect";
public override string ShortenedName => "PF";
public override string Description => "SS or quit.";
}
}

View File

@ -9,6 +9,7 @@ namespace osu.Game.Rulesets.Mods
public abstract class ModRelax : Mod
{
public override string Name => "Relax";
public override string ShortenedName => "RX";
public override FontAwesome Icon => FontAwesome.fa_osu_mod_relax;
public override double ScoreMultiplier => 0;
public override Type[] IncompatibleMods => new[] { typeof(ModAutoplay), typeof(ModNoFail), typeof(ModSuddenDeath) };

View File

@ -9,6 +9,7 @@ namespace osu.Game.Rulesets.Mods
public abstract class ModSuddenDeath : Mod
{
public override string Name => "Sudden Death";
public override string ShortenedName => "SD";
public override FontAwesome Icon => FontAwesome.fa_osu_mod_suddendeath;
public override ModType Type => ModType.DifficultyIncrease;
public override string Description => "Miss a note and fail.";

View File

@ -6,6 +6,7 @@ namespace osu.Game.Rulesets.Mods
public class MultiMod : Mod
{
public override string Name => string.Empty;
public override string ShortenedName => string.Empty;
public override string Description => string.Empty;
public override double ScoreMultiplier => 0.0;

View File

@ -1,12 +1,12 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System.Collections.Generic;
using osu.Game.Beatmaps;
using osu.Game.Graphics;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.UI;
using osu.Game.Screens.Play;
using System.Collections.Generic;
using osu.Framework.Graphics;
using osu.Game.Rulesets.Scoring;
using osu.Game.Overlays.Settings;
@ -19,8 +19,21 @@ namespace osu.Game.Rulesets
public virtual IEnumerable<BeatmapStatistic> GetBeatmapStatistics(WorkingBeatmap beatmap) => new BeatmapStatistic[] { };
public abstract IEnumerable<Mod> GetAllMods();
public abstract IEnumerable<Mod> GetModsFor(ModType type);
public Mod GetModByShortenedName(string shortenedName)
{
foreach(Mod mod in GetAllMods())
{
if (string.Equals(mod.ShortenedName, shortenedName))
return mod;
}
return null;
}
public abstract Mod GetAutoplayMod();
protected Ruleset(RulesetInfo rulesetInfo)

View File

@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using Newtonsoft.Json;
using osu.Game.Beatmaps;
using osu.Game.Rulesets.Mods;
@ -27,10 +28,31 @@ namespace osu.Game.Rulesets.Scoring
public int Combo { get; set; }
private string[] modStrings;
[JsonProperty(@"mods")]
protected string[] ModStrings { get; set; } //todo: parse to Mod objects
protected string[] ModStrings {
get { return modStrings; }
set
{
modStrings = value;
public RulesetInfo Ruleset { get; set; }
if (ruleset != null)
handleModString();
}
}
private RulesetInfo ruleset;
public RulesetInfo Ruleset
{
get { return ruleset; }
set
{
ruleset = value;
if (modStrings != null)
handleModString();
}
}
public Mod[] Mods { get; set; }
@ -80,5 +102,17 @@ namespace osu.Game.Rulesets.Scoring
}
public Dictionary<string, dynamic> Statistics = new Dictionary<string, dynamic>();
private void handleModString()
{
List<Mod> modList = new List<Mod>();
Ruleset rulesetInstance = Ruleset.CreateInstance();
foreach (string modShortenedName in modStrings)
modList.Add(rulesetInstance.GetModByShortenedName(modShortenedName));
Mods = modList.ToArray();
}
}
}

View File

@ -1,15 +1,15 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using System.Collections.Generic;
using OpenTK;
using OpenTK.Graphics;
using osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Colour;
using osu.Framework.Graphics.Containers;
using System;
using osu.Framework.Allocation;
using osu.Framework.Threading;
using osu.Game.Beatmaps;
using osu.Game.Graphics.Containers;
@ -55,6 +55,8 @@ namespace osu.Game.Screens.Select.Leaderboards
i = 0;
foreach (var s in scores)
{
s.Ruleset = beatmap.Ruleset;
var ls = new LeaderboardScore(s, 1 + i)
{
AlwaysPresent = true,

View File

@ -256,8 +256,23 @@ namespace osu.Game.Screens.Select.Leaderboards
{
foreach (Mod mod in Score.Mods)
{
// TODO: Get actual mod colours
modsContainer.Add(new ScoreModIcon(mod.Icon, OsuColour.FromHex(@"ffcc22")));
Color4 modColor;
switch (mod.Type)
{
default:
case ModType.DifficultyIncrease:
modColor = OsuColour.FromHex(@"ffcc22");
break;
case ModType.DifficultyReduction:
modColor = OsuColour.FromHex(@"88b300");
break;
case ModType.Special:
modColor = OsuColour.FromHex(@"66ccff");
break;
}
modsContainer.Add(new ScoreModIcon(mod.Icon, modColor));
}
}
}