From 4c2d7bf343999b55213b8d8900b62aee79d56276 Mon Sep 17 00:00:00 2001 From: MrTheMake Date: Sun, 13 Aug 2017 17:41:13 +0200 Subject: [PATCH 01/22] Parse the mods of a leaderboard's score --- osu.Game.Rulesets.Catch/CatchRuleset.cs | 18 +++++++++ osu.Game.Rulesets.Mania/ManiaRuleset.cs | 30 +++++++++++++++ osu.Game.Rulesets.Mania/Mods/ManiaMod.cs | 4 ++ .../Mods/ManiaModGravity.cs | 1 + osu.Game.Rulesets.Osu/Mods/OsuMod.cs | 3 ++ osu.Game.Rulesets.Osu/OsuRuleset.cs | 21 ++++++++++ osu.Game.Rulesets.Taiko/TaikoRuleset.cs | 18 +++++++++ osu.Game/Beatmaps/DummyWorkingBeatmap.cs | 2 + osu.Game/Rulesets/Mods/Mod.cs | 5 +++ osu.Game/Rulesets/Mods/ModAutoplay.cs | 1 + osu.Game/Rulesets/Mods/ModCinema.cs | 1 + osu.Game/Rulesets/Mods/ModDaycore.cs | 1 + osu.Game/Rulesets/Mods/ModDoubleTime.cs | 1 + osu.Game/Rulesets/Mods/ModEasy.cs | 1 + osu.Game/Rulesets/Mods/ModFlashlight.cs | 1 + osu.Game/Rulesets/Mods/ModHalfTime.cs | 1 + osu.Game/Rulesets/Mods/ModHardRock.cs | 1 + osu.Game/Rulesets/Mods/ModHidden.cs | 1 + osu.Game/Rulesets/Mods/ModNightcore.cs | 1 + osu.Game/Rulesets/Mods/ModNoFail.cs | 1 + osu.Game/Rulesets/Mods/ModPerfect.cs | 1 + osu.Game/Rulesets/Mods/ModRelax.cs | 1 + osu.Game/Rulesets/Mods/ModSuddenDeath.cs | 1 + osu.Game/Rulesets/Mods/MultiMod.cs | 1 + osu.Game/Rulesets/Ruleset.cs | 15 +++++++- osu.Game/Rulesets/Scoring/Score.cs | 38 ++++++++++++++++++- .../Select/Leaderboards/Leaderboard.cs | 6 ++- .../Select/Leaderboards/LeaderboardScore.cs | 19 +++++++++- 28 files changed, 188 insertions(+), 7 deletions(-) diff --git a/osu.Game.Rulesets.Catch/CatchRuleset.cs b/osu.Game.Rulesets.Catch/CatchRuleset.cs index 8d45ea8fa2..69f22f7121 100644 --- a/osu.Game.Rulesets.Catch/CatchRuleset.cs +++ b/osu.Game.Rulesets.Catch/CatchRuleset.cs @@ -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 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 GetModsFor(ModType type) { switch (type) diff --git a/osu.Game.Rulesets.Mania/ManiaRuleset.cs b/osu.Game.Rulesets.Mania/ManiaRuleset.cs index 50ad6960ae..3a7c072604 100644 --- a/osu.Game.Rulesets.Mania/ManiaRuleset.cs +++ b/osu.Game.Rulesets.Mania/ManiaRuleset.cs @@ -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 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 GetModsFor(ModType type) { switch (type) diff --git a/osu.Game.Rulesets.Mania/Mods/ManiaMod.cs b/osu.Game.Rulesets.Mania/Mods/ManiaMod.cs index f44ad6fd60..12aa9b0886 100644 --- a/osu.Game.Rulesets.Mania/Mods/ManiaMod.cs +++ b/osu.Game.Rulesets.Mania/Mods/ManiaMod.cs @@ -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; diff --git a/osu.Game.Rulesets.Mania/Mods/ManiaModGravity.cs b/osu.Game.Rulesets.Mania/Mods/ManiaModGravity.cs index a054e0db56..132c49ab31 100644 --- a/osu.Game.Rulesets.Mania/Mods/ManiaModGravity.cs +++ b/osu.Game.Rulesets.Mania/Mods/ManiaModGravity.cs @@ -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; diff --git a/osu.Game.Rulesets.Osu/Mods/OsuMod.cs b/osu.Game.Rulesets.Osu/Mods/OsuMod.cs index 3b0cfc1ef1..649e6cfb3c 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuMod.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuMod.cs @@ -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; diff --git a/osu.Game.Rulesets.Osu/OsuRuleset.cs b/osu.Game.Rulesets.Osu/OsuRuleset.cs index 212c634aaf..fbcb5e3abf 100644 --- a/osu.Game.Rulesets.Osu/OsuRuleset.cs +++ b/osu.Game.Rulesets.Osu/OsuRuleset.cs @@ -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 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 GetBeatmapStatistics(WorkingBeatmap beatmap) => new[] { new BeatmapStatistic diff --git a/osu.Game.Rulesets.Taiko/TaikoRuleset.cs b/osu.Game.Rulesets.Taiko/TaikoRuleset.cs index 4d4bbb7bc5..3e126cec4e 100644 --- a/osu.Game.Rulesets.Taiko/TaikoRuleset.cs +++ b/osu.Game.Rulesets.Taiko/TaikoRuleset.cs @@ -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 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 GetModsFor(ModType type) { switch (type) diff --git a/osu.Game/Beatmaps/DummyWorkingBeatmap.cs b/osu.Game/Beatmaps/DummyWorkingBeatmap.cs index 2fb9a568f8..f807b5828f 100644 --- a/osu.Game/Beatmaps/DummyWorkingBeatmap.cs +++ b/osu.Game/Beatmaps/DummyWorkingBeatmap.cs @@ -58,6 +58,8 @@ namespace osu.Game.Beatmaps private class DummyRuleset : Ruleset { + public override IEnumerable GetAllMods() => new Mod[] { }; + public override IEnumerable GetModsFor(ModType type) => new Mod[] { }; public override Mod GetAutoplayMod() => new ModAutoplay(); diff --git a/osu.Game/Rulesets/Mods/Mod.cs b/osu.Game/Rulesets/Mods/Mod.cs index f54267af29..7b0034863e 100644 --- a/osu.Game/Rulesets/Mods/Mod.cs +++ b/osu.Game/Rulesets/Mods/Mod.cs @@ -16,6 +16,11 @@ namespace osu.Game.Rulesets.Mods /// public abstract string Name { get; } + /// + /// The shortened name of this mod. + /// + public abstract string ShortenedName { get; } + /// /// The icon of this mod. /// diff --git a/osu.Game/Rulesets/Mods/ModAutoplay.cs b/osu.Game/Rulesets/Mods/ModAutoplay.cs index ca120e446e..2b10d098f3 100644 --- a/osu.Game/Rulesets/Mods/ModAutoplay.cs +++ b/osu.Game/Rulesets/Mods/ModAutoplay.cs @@ -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; diff --git a/osu.Game/Rulesets/Mods/ModCinema.cs b/osu.Game/Rulesets/Mods/ModCinema.cs index 332bd2c5ac..581fbc5e3a 100644 --- a/osu.Game/Rulesets/Mods/ModCinema.cs +++ b/osu.Game/Rulesets/Mods/ModCinema.cs @@ -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; } } \ No newline at end of file diff --git a/osu.Game/Rulesets/Mods/ModDaycore.cs b/osu.Game/Rulesets/Mods/ModDaycore.cs index 3e878d7104..cbad224316 100644 --- a/osu.Game/Rulesets/Mods/ModDaycore.cs +++ b/osu.Game/Rulesets/Mods/ModDaycore.cs @@ -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"; diff --git a/osu.Game/Rulesets/Mods/ModDoubleTime.cs b/osu.Game/Rulesets/Mods/ModDoubleTime.cs index 1aab56a9fc..d8aa5ea1d2 100644 --- a/osu.Game/Rulesets/Mods/ModDoubleTime.cs +++ b/osu.Game/Rulesets/Mods/ModDoubleTime.cs @@ -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"; diff --git a/osu.Game/Rulesets/Mods/ModEasy.cs b/osu.Game/Rulesets/Mods/ModEasy.cs index 075a62b0d7..aaf083fd9e 100644 --- a/osu.Game/Rulesets/Mods/ModEasy.cs +++ b/osu.Game/Rulesets/Mods/ModEasy.cs @@ -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."; diff --git a/osu.Game/Rulesets/Mods/ModFlashlight.cs b/osu.Game/Rulesets/Mods/ModFlashlight.cs index b5ad859172..b7499e624a 100644 --- a/osu.Game/Rulesets/Mods/ModFlashlight.cs +++ b/osu.Game/Rulesets/Mods/ModFlashlight.cs @@ -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."; diff --git a/osu.Game/Rulesets/Mods/ModHalfTime.cs b/osu.Game/Rulesets/Mods/ModHalfTime.cs index 14aede0809..a9e49bb4b0 100644 --- a/osu.Game/Rulesets/Mods/ModHalfTime.cs +++ b/osu.Game/Rulesets/Mods/ModHalfTime.cs @@ -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"; diff --git a/osu.Game/Rulesets/Mods/ModHardRock.cs b/osu.Game/Rulesets/Mods/ModHardRock.cs index f33f46a207..36d82362e3 100644 --- a/osu.Game/Rulesets/Mods/ModHardRock.cs +++ b/osu.Game/Rulesets/Mods/ModHardRock.cs @@ -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..."; diff --git a/osu.Game/Rulesets/Mods/ModHidden.cs b/osu.Game/Rulesets/Mods/ModHidden.cs index 89b9b3b62d..25f6ad024d 100644 --- a/osu.Game/Rulesets/Mods/ModHidden.cs +++ b/osu.Game/Rulesets/Mods/ModHidden.cs @@ -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; diff --git a/osu.Game/Rulesets/Mods/ModNightcore.cs b/osu.Game/Rulesets/Mods/ModNightcore.cs index d04643fb8b..5cefd89023 100644 --- a/osu.Game/Rulesets/Mods/ModNightcore.cs +++ b/osu.Game/Rulesets/Mods/ModNightcore.cs @@ -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"; diff --git a/osu.Game/Rulesets/Mods/ModNoFail.cs b/osu.Game/Rulesets/Mods/ModNoFail.cs index d41c4e3956..3a3878d77e 100644 --- a/osu.Game/Rulesets/Mods/ModNoFail.cs +++ b/osu.Game/Rulesets/Mods/ModNoFail.cs @@ -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."; diff --git a/osu.Game/Rulesets/Mods/ModPerfect.cs b/osu.Game/Rulesets/Mods/ModPerfect.cs index 35217c8305..082370ea5d 100644 --- a/osu.Game/Rulesets/Mods/ModPerfect.cs +++ b/osu.Game/Rulesets/Mods/ModPerfect.cs @@ -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."; } } \ No newline at end of file diff --git a/osu.Game/Rulesets/Mods/ModRelax.cs b/osu.Game/Rulesets/Mods/ModRelax.cs index 5491f8fc58..a3f38e4ff6 100644 --- a/osu.Game/Rulesets/Mods/ModRelax.cs +++ b/osu.Game/Rulesets/Mods/ModRelax.cs @@ -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) }; diff --git a/osu.Game/Rulesets/Mods/ModSuddenDeath.cs b/osu.Game/Rulesets/Mods/ModSuddenDeath.cs index 2bf0278046..999cb40f89 100644 --- a/osu.Game/Rulesets/Mods/ModSuddenDeath.cs +++ b/osu.Game/Rulesets/Mods/ModSuddenDeath.cs @@ -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."; diff --git a/osu.Game/Rulesets/Mods/MultiMod.cs b/osu.Game/Rulesets/Mods/MultiMod.cs index c5fac250d0..c40d107bda 100644 --- a/osu.Game/Rulesets/Mods/MultiMod.cs +++ b/osu.Game/Rulesets/Mods/MultiMod.cs @@ -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; diff --git a/osu.Game/Rulesets/Ruleset.cs b/osu.Game/Rulesets/Ruleset.cs index ba040403ba..b6bcd48562 100644 --- a/osu.Game/Rulesets/Ruleset.cs +++ b/osu.Game/Rulesets/Ruleset.cs @@ -1,12 +1,12 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // 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 GetBeatmapStatistics(WorkingBeatmap beatmap) => new BeatmapStatistic[] { }; + public abstract IEnumerable GetAllMods(); + public abstract IEnumerable 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) diff --git a/osu.Game/Rulesets/Scoring/Score.cs b/osu.Game/Rulesets/Scoring/Score.cs index 6169bb7380..8377b95cb2 100644 --- a/osu.Game/Rulesets/Scoring/Score.cs +++ b/osu.Game/Rulesets/Scoring/Score.cs @@ -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 Statistics = new Dictionary(); + + private void handleModString() + { + List modList = new List(); + + Ruleset rulesetInstance = Ruleset.CreateInstance(); + + foreach (string modShortenedName in modStrings) + modList.Add(rulesetInstance.GetModByShortenedName(modShortenedName)); + + Mods = modList.ToArray(); + } } } diff --git a/osu.Game/Screens/Select/Leaderboards/Leaderboard.cs b/osu.Game/Screens/Select/Leaderboards/Leaderboard.cs index 5a375e55d4..341e24baf0 100644 --- a/osu.Game/Screens/Select/Leaderboards/Leaderboard.cs +++ b/osu.Game/Screens/Select/Leaderboards/Leaderboard.cs @@ -1,15 +1,15 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // 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, diff --git a/osu.Game/Screens/Select/Leaderboards/LeaderboardScore.cs b/osu.Game/Screens/Select/Leaderboards/LeaderboardScore.cs index ac3b0b5c3b..993186ffdf 100644 --- a/osu.Game/Screens/Select/Leaderboards/LeaderboardScore.cs +++ b/osu.Game/Screens/Select/Leaderboards/LeaderboardScore.cs @@ -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)); } } } From 997d0c9053c0b7cd641fa7047c0508203dac3744 Mon Sep 17 00:00:00 2001 From: MrTheMake Date: Sun, 13 Aug 2017 17:45:46 +0200 Subject: [PATCH 02/22] CI fix --- osu.Game/Rulesets/Scoring/Score.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/osu.Game/Rulesets/Scoring/Score.cs b/osu.Game/Rulesets/Scoring/Score.cs index 8377b95cb2..0200e883ba 100644 --- a/osu.Game/Rulesets/Scoring/Score.cs +++ b/osu.Game/Rulesets/Scoring/Score.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; -using System.Reflection; using Newtonsoft.Json; using osu.Game.Beatmaps; using osu.Game.Rulesets.Mods; From e1e4eb78e324b972241d3ae57161f3da631f23aa Mon Sep 17 00:00:00 2001 From: MrTheMake Date: Sun, 13 Aug 2017 18:00:53 +0200 Subject: [PATCH 03/22] Fix nullref in the leaderboard's test case --- osu.Game/Screens/Select/Leaderboards/Leaderboard.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Screens/Select/Leaderboards/Leaderboard.cs b/osu.Game/Screens/Select/Leaderboards/Leaderboard.cs index 341e24baf0..740dc90586 100644 --- a/osu.Game/Screens/Select/Leaderboards/Leaderboard.cs +++ b/osu.Game/Screens/Select/Leaderboards/Leaderboard.cs @@ -55,7 +55,7 @@ namespace osu.Game.Screens.Select.Leaderboards i = 0; foreach (var s in scores) { - s.Ruleset = beatmap.Ruleset; + s.Ruleset = beatmap?.Ruleset; var ls = new LeaderboardScore(s, 1 + i) { From d9c26f98c7d132a8109f37174cfcbc791b7ac9ab Mon Sep 17 00:00:00 2001 From: MrTheMake Date: Sun, 13 Aug 2017 19:54:07 +0200 Subject: [PATCH 04/22] Suggested changes --- osu.Game.Rulesets.Catch/CatchRuleset.cs | 18 ----- osu.Game.Rulesets.Mania/ManiaRuleset.cs | 30 --------- osu.Game.Rulesets.Osu/OsuRuleset.cs | 21 ------ osu.Game.Rulesets.Taiko/TaikoRuleset.cs | 18 ----- osu.Game/Beatmaps/DummyWorkingBeatmap.cs | 2 - osu.Game/Rulesets/Ruleset.cs | 28 +++++--- osu.Game/Rulesets/Scoring/Score.cs | 10 +-- osu.Game/Rulesets/UI/ModIcon.cs | 6 +- .../Select/Leaderboards/LeaderboardScore.cs | 67 ++++--------------- 9 files changed, 38 insertions(+), 162 deletions(-) diff --git a/osu.Game.Rulesets.Catch/CatchRuleset.cs b/osu.Game.Rulesets.Catch/CatchRuleset.cs index 69f22f7121..8d45ea8fa2 100644 --- a/osu.Game.Rulesets.Catch/CatchRuleset.cs +++ b/osu.Game.Rulesets.Catch/CatchRuleset.cs @@ -20,24 +20,6 @@ namespace osu.Game.Rulesets.Catch { public override RulesetContainer CreateRulesetContainerWith(WorkingBeatmap beatmap, bool isForCurrentRuleset) => new CatchRulesetContainer(this, beatmap, isForCurrentRuleset); - public override IEnumerable 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 GetModsFor(ModType type) { switch (type) diff --git a/osu.Game.Rulesets.Mania/ManiaRuleset.cs b/osu.Game.Rulesets.Mania/ManiaRuleset.cs index 3a7c072604..50ad6960ae 100644 --- a/osu.Game.Rulesets.Mania/ManiaRuleset.cs +++ b/osu.Game.Rulesets.Mania/ManiaRuleset.cs @@ -19,36 +19,6 @@ namespace osu.Game.Rulesets.Mania { public override RulesetContainer CreateRulesetContainerWith(WorkingBeatmap beatmap, bool isForCurrentRuleset) => new ManiaRulesetContainer(this, beatmap, isForCurrentRuleset); - public override IEnumerable 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 GetModsFor(ModType type) { switch (type) diff --git a/osu.Game.Rulesets.Osu/OsuRuleset.cs b/osu.Game.Rulesets.Osu/OsuRuleset.cs index fbcb5e3abf..212c634aaf 100644 --- a/osu.Game.Rulesets.Osu/OsuRuleset.cs +++ b/osu.Game.Rulesets.Osu/OsuRuleset.cs @@ -24,27 +24,6 @@ namespace osu.Game.Rulesets.Osu { public override RulesetContainer CreateRulesetContainerWith(WorkingBeatmap beatmap, bool isForCurrentRuleset) => new OsuRulesetContainer(this, beatmap, isForCurrentRuleset); - public override IEnumerable 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 GetBeatmapStatistics(WorkingBeatmap beatmap) => new[] { new BeatmapStatistic diff --git a/osu.Game.Rulesets.Taiko/TaikoRuleset.cs b/osu.Game.Rulesets.Taiko/TaikoRuleset.cs index 3e126cec4e..4d4bbb7bc5 100644 --- a/osu.Game.Rulesets.Taiko/TaikoRuleset.cs +++ b/osu.Game.Rulesets.Taiko/TaikoRuleset.cs @@ -20,24 +20,6 @@ namespace osu.Game.Rulesets.Taiko { public override RulesetContainer CreateRulesetContainerWith(WorkingBeatmap beatmap, bool isForCurrentRuleset) => new TaikoRulesetContainer(this, beatmap, isForCurrentRuleset); - public override IEnumerable 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 GetModsFor(ModType type) { switch (type) diff --git a/osu.Game/Beatmaps/DummyWorkingBeatmap.cs b/osu.Game/Beatmaps/DummyWorkingBeatmap.cs index f807b5828f..2fb9a568f8 100644 --- a/osu.Game/Beatmaps/DummyWorkingBeatmap.cs +++ b/osu.Game/Beatmaps/DummyWorkingBeatmap.cs @@ -58,8 +58,6 @@ namespace osu.Game.Beatmaps private class DummyRuleset : Ruleset { - public override IEnumerable GetAllMods() => new Mod[] { }; - public override IEnumerable GetModsFor(ModType type) => new Mod[] { }; public override Mod GetAutoplayMod() => new ModAutoplay(); diff --git a/osu.Game/Rulesets/Ruleset.cs b/osu.Game/Rulesets/Ruleset.cs index b6bcd48562..56a255eda5 100644 --- a/osu.Game/Rulesets/Ruleset.cs +++ b/osu.Game/Rulesets/Ruleset.cs @@ -1,6 +1,8 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using System; +using System.Linq; using System.Collections.Generic; using osu.Game.Beatmaps; using osu.Game.Graphics; @@ -19,19 +21,29 @@ namespace osu.Game.Rulesets public virtual IEnumerable GetBeatmapStatistics(WorkingBeatmap beatmap) => new BeatmapStatistic[] { }; - public abstract IEnumerable GetAllMods(); + public IEnumerable GetAllMods() + { + List modList = new List(); + + foreach (ModType type in Enum.GetValues(typeof(ModType))) + modList.AddRange(GetModsFor(type).SelectMany(mod => + { + var multiMod = mod as MultiMod; + + if (multiMod != null) + return multiMod.Mods; + + return new Mod[] { mod }; + })); + + return modList.ToArray(); + } public abstract IEnumerable GetModsFor(ModType type); public Mod GetModByShortenedName(string shortenedName) { - foreach(Mod mod in GetAllMods()) - { - if (string.Equals(mod.ShortenedName, shortenedName)) - return mod; - } - - return null; + return GetAllMods().First(mod => mod.ShortenedName == shortenedName); } public abstract Mod GetAutoplayMod(); diff --git a/osu.Game/Rulesets/Scoring/Score.cs b/osu.Game/Rulesets/Scoring/Score.cs index 0200e883ba..b9fe54677d 100644 --- a/osu.Game/Rulesets/Scoring/Score.cs +++ b/osu.Game/Rulesets/Scoring/Score.cs @@ -2,6 +2,7 @@ // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using System; +using System.Linq; using System.Collections.Generic; using Newtonsoft.Json; using osu.Game.Beatmaps; @@ -104,14 +105,7 @@ namespace osu.Game.Rulesets.Scoring private void handleModString() { - List modList = new List(); - - Ruleset rulesetInstance = Ruleset.CreateInstance(); - - foreach (string modShortenedName in modStrings) - modList.Add(rulesetInstance.GetModByShortenedName(modShortenedName)); - - Mods = modList.ToArray(); + Mods = Ruleset.CreateInstance().GetAllMods().Where(mod => modStrings.Contains(mod.ShortenedName)).ToArray(); } } } diff --git a/osu.Game/Rulesets/UI/ModIcon.cs b/osu.Game/Rulesets/UI/ModIcon.cs index 986d8c92dc..47a39d4644 100644 --- a/osu.Game/Rulesets/UI/ModIcon.cs +++ b/osu.Game/Rulesets/UI/ModIcon.cs @@ -17,7 +17,7 @@ namespace osu.Game.Rulesets.UI private readonly SpriteIcon modIcon; private readonly SpriteIcon background; - private const float icon_size = 80; + private const float background_size = 80; public FontAwesome Icon { @@ -39,7 +39,7 @@ namespace osu.Game.Rulesets.UI { Origin = Anchor.Centre, Anchor = Anchor.Centre, - Size = new Vector2(icon_size), + Size = new Vector2(background_size), Icon = FontAwesome.fa_osu_mod_bg, Shadow = true, }, @@ -48,7 +48,7 @@ namespace osu.Game.Rulesets.UI Origin = Anchor.TopCentre, Anchor = Anchor.TopCentre, Colour = OsuColour.Gray(84), - Size = new Vector2(icon_size - 35), + Size = new Vector2(background_size - 35), Y = 25, Icon = mod.Icon }, diff --git a/osu.Game/Screens/Select/Leaderboards/LeaderboardScore.cs b/osu.Game/Screens/Select/Leaderboards/LeaderboardScore.cs index 993186ffdf..fcd87363d6 100644 --- a/osu.Game/Screens/Select/Leaderboards/LeaderboardScore.cs +++ b/osu.Game/Screens/Select/Leaderboards/LeaderboardScore.cs @@ -3,17 +3,18 @@ using OpenTK; using OpenTK.Graphics; +using osu.Framework; +using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; using osu.Game.Graphics; -using osu.Game.Graphics.Sprites; -using osu.Framework.Extensions.Color4Extensions; -using osu.Game.Rulesets.Mods; -using osu.Game.Users; -using osu.Framework; -using osu.Game.Rulesets.Scoring; using osu.Game.Graphics.Containers; +using osu.Game.Graphics.Sprites; +using osu.Game.Rulesets.Mods; +using osu.Game.Rulesets.Scoring; +using osu.Game.Rulesets.UI; +using osu.Game.Users; namespace osu.Game.Screens.Select.Leaderboards { @@ -38,7 +39,7 @@ namespace osu.Game.Screens.Select.Leaderboards private readonly ScoreComponentLabel maxCombo; private readonly ScoreComponentLabel accuracy; private readonly Container flagBadgeContainer; - private readonly FillFlowContainer modsContainer; + private readonly FillFlowContainer modsContainer; private Visibility state; public Visibility State @@ -239,7 +240,7 @@ namespace osu.Game.Screens.Select.Leaderboards }, }, }, - modsContainer = new FillFlowContainer + modsContainer = new FillFlowContainer { Anchor = Anchor.BottomRight, Origin = Anchor.BottomRight, @@ -256,23 +257,11 @@ namespace osu.Game.Screens.Select.Leaderboards { foreach (Mod mod in Score.Mods) { - Color4 modColor; - - switch (mod.Type) + modsContainer.Add(new ModIcon(mod) { - 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)); + AutoSizeAxes = Axes.Both, + Scale = new Vector2(0.375f) + }); } } } @@ -341,36 +330,6 @@ namespace osu.Game.Screens.Select.Leaderboards } } - private class ScoreModIcon : Container - { - public ScoreModIcon(FontAwesome icon, Color4 colour) - { - AutoSizeAxes = Axes.Both; - - Children = new[] - { - new SpriteIcon - { - Origin = Anchor.Centre, - Anchor = Anchor.Centre, - Icon = FontAwesome.fa_osu_mod_bg, - Colour = colour, - Shadow = true, - Size = new Vector2(30), - }, - new SpriteIcon - { - Origin = Anchor.Centre, - Anchor = Anchor.Centre, - Icon = icon, - Colour = OsuColour.Gray(84), - Size = new Vector2(18), - Position = new Vector2(0f, 2f), - }, - }; - } - } - private class ScoreComponentLabel : Container { public ScoreComponentLabel(FontAwesome icon, string value) From 81289db33b3a9f9d219ce930359e78222cdc234d Mon Sep 17 00:00:00 2001 From: MrTheMake Date: Sun, 13 Aug 2017 20:12:01 +0200 Subject: [PATCH 05/22] CI fix, fixed nullref and removed abstraction of GetAutoplayMod --- osu.Game.Rulesets.Catch/CatchRuleset.cs | 2 -- osu.Game.Rulesets.Mania/ManiaRuleset.cs | 2 -- osu.Game.Rulesets.Osu/OsuRuleset.cs | 2 -- osu.Game.Rulesets.Taiko/TaikoRuleset.cs | 2 -- osu.Game/Beatmaps/DummyWorkingBeatmap.cs | 2 -- osu.Game/Rulesets/Ruleset.cs | 6 +++--- 6 files changed, 3 insertions(+), 13 deletions(-) diff --git a/osu.Game.Rulesets.Catch/CatchRuleset.cs b/osu.Game.Rulesets.Catch/CatchRuleset.cs index 8d45ea8fa2..a5c9cf67b3 100644 --- a/osu.Game.Rulesets.Catch/CatchRuleset.cs +++ b/osu.Game.Rulesets.Catch/CatchRuleset.cs @@ -84,8 +84,6 @@ namespace osu.Game.Rulesets.Catch } } - public override Mod GetAutoplayMod() => new ModAutoplay(); - public override string Description => "osu!catch"; public override Drawable CreateIcon() => new SpriteIcon { Icon = FontAwesome.fa_osu_fruits_o }; diff --git a/osu.Game.Rulesets.Mania/ManiaRuleset.cs b/osu.Game.Rulesets.Mania/ManiaRuleset.cs index 50ad6960ae..90732df1f2 100644 --- a/osu.Game.Rulesets.Mania/ManiaRuleset.cs +++ b/osu.Game.Rulesets.Mania/ManiaRuleset.cs @@ -105,8 +105,6 @@ namespace osu.Game.Rulesets.Mania } } - public override Mod GetAutoplayMod() => new ModAutoplay(); - public override string Description => "osu!mania"; public override Drawable CreateIcon() => new SpriteIcon { Icon = FontAwesome.fa_osu_mania_o }; diff --git a/osu.Game.Rulesets.Osu/OsuRuleset.cs b/osu.Game.Rulesets.Osu/OsuRuleset.cs index 212c634aaf..92cfbf8afa 100644 --- a/osu.Game.Rulesets.Osu/OsuRuleset.cs +++ b/osu.Game.Rulesets.Osu/OsuRuleset.cs @@ -105,8 +105,6 @@ namespace osu.Game.Rulesets.Osu } } - public override Mod GetAutoplayMod() => new OsuModAutoplay(); - public override Drawable CreateIcon() => new SpriteIcon { Icon = FontAwesome.fa_osu_osu_o }; public override DifficultyCalculator CreateDifficultyCalculator(Beatmap beatmap) => new OsuDifficultyCalculator(beatmap); diff --git a/osu.Game.Rulesets.Taiko/TaikoRuleset.cs b/osu.Game.Rulesets.Taiko/TaikoRuleset.cs index 4d4bbb7bc5..7fa053161d 100644 --- a/osu.Game.Rulesets.Taiko/TaikoRuleset.cs +++ b/osu.Game.Rulesets.Taiko/TaikoRuleset.cs @@ -84,8 +84,6 @@ namespace osu.Game.Rulesets.Taiko } } - public override Mod GetAutoplayMod() => new TaikoModAutoplay(); - public override string Description => "osu!taiko"; public override Drawable CreateIcon() => new SpriteIcon { Icon = FontAwesome.fa_osu_taiko_o }; diff --git a/osu.Game/Beatmaps/DummyWorkingBeatmap.cs b/osu.Game/Beatmaps/DummyWorkingBeatmap.cs index 2fb9a568f8..22ad4f38ff 100644 --- a/osu.Game/Beatmaps/DummyWorkingBeatmap.cs +++ b/osu.Game/Beatmaps/DummyWorkingBeatmap.cs @@ -60,8 +60,6 @@ namespace osu.Game.Beatmaps { public override IEnumerable GetModsFor(ModType type) => new Mod[] { }; - public override Mod GetAutoplayMod() => new ModAutoplay(); - public override RulesetContainer CreateRulesetContainerWith(WorkingBeatmap beatmap, bool isForCurrentRuleset) { throw new NotImplementedException(); diff --git a/osu.Game/Rulesets/Ruleset.cs b/osu.Game/Rulesets/Ruleset.cs index 56a255eda5..46ab53a7d2 100644 --- a/osu.Game/Rulesets/Ruleset.cs +++ b/osu.Game/Rulesets/Ruleset.cs @@ -26,14 +26,14 @@ namespace osu.Game.Rulesets List modList = new List(); foreach (ModType type in Enum.GetValues(typeof(ModType))) - modList.AddRange(GetModsFor(type).SelectMany(mod => + modList.AddRange(GetModsFor(type).Where(mod => mod != null).SelectMany(mod => { var multiMod = mod as MultiMod; if (multiMod != null) return multiMod.Mods; - return new Mod[] { mod }; + return new[] { mod }; })); return modList.ToArray(); @@ -46,7 +46,7 @@ namespace osu.Game.Rulesets return GetAllMods().First(mod => mod.ShortenedName == shortenedName); } - public abstract Mod GetAutoplayMod(); + public Mod GetAutoplayMod() => GetAllMods().First(mod => mod is ModAutoplay); protected Ruleset(RulesetInfo rulesetInfo) { From 2f89fc432b3ed495a239170b2261aac6b3470a10 Mon Sep 17 00:00:00 2001 From: MrTheMake Date: Sun, 13 Aug 2017 20:28:30 +0200 Subject: [PATCH 06/22] Removed unused function --- osu.Game/Rulesets/Ruleset.cs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/osu.Game/Rulesets/Ruleset.cs b/osu.Game/Rulesets/Ruleset.cs index 46ab53a7d2..cd4480bbb9 100644 --- a/osu.Game/Rulesets/Ruleset.cs +++ b/osu.Game/Rulesets/Ruleset.cs @@ -41,11 +41,6 @@ namespace osu.Game.Rulesets public abstract IEnumerable GetModsFor(ModType type); - public Mod GetModByShortenedName(string shortenedName) - { - return GetAllMods().First(mod => mod.ShortenedName == shortenedName); - } - public Mod GetAutoplayMod() => GetAllMods().First(mod => mod is ModAutoplay); protected Ruleset(RulesetInfo rulesetInfo) From e54f659916c4a897fb2ca5e51f13805923a1bb9e Mon Sep 17 00:00:00 2001 From: MrTheMake Date: Sun, 13 Aug 2017 22:37:39 +0200 Subject: [PATCH 07/22] Suggested changes --- osu.Game.Rulesets.Mania/Mods/ManiaMod.cs | 2 +- osu.Game/Rulesets/Ruleset.cs | 2 +- osu.Game/Rulesets/Scoring/Score.cs | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/osu.Game.Rulesets.Mania/Mods/ManiaMod.cs b/osu.Game.Rulesets.Mania/Mods/ManiaMod.cs index 12aa9b0886..bb11a05fc8 100644 --- a/osu.Game.Rulesets.Mania/Mods/ManiaMod.cs +++ b/osu.Game.Rulesets.Mania/Mods/ManiaMod.cs @@ -149,7 +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 ShortenedName => "2P"; public override string Description => @"Double the key amount, double the fun!"; public override double ScoreMultiplier => 1; public override bool Ranked => true; diff --git a/osu.Game/Rulesets/Ruleset.cs b/osu.Game/Rulesets/Ruleset.cs index cd4480bbb9..bb08850af9 100644 --- a/osu.Game/Rulesets/Ruleset.cs +++ b/osu.Game/Rulesets/Ruleset.cs @@ -36,7 +36,7 @@ namespace osu.Game.Rulesets return new[] { mod }; })); - return modList.ToArray(); + return modList; } public abstract IEnumerable GetModsFor(ModType type); diff --git a/osu.Game/Rulesets/Scoring/Score.cs b/osu.Game/Rulesets/Scoring/Score.cs index b9fe54677d..399a805bcc 100644 --- a/osu.Game/Rulesets/Scoring/Score.cs +++ b/osu.Game/Rulesets/Scoring/Score.cs @@ -30,7 +30,8 @@ namespace osu.Game.Rulesets.Scoring private string[] modStrings; [JsonProperty(@"mods")] - protected string[] ModStrings { + protected string[] ModStrings + { get { return modStrings; } set { From 6b1184e8aff6f4de5fabe58a430595e0e1e19b02 Mon Sep 17 00:00:00 2001 From: MrTheMake Date: Mon, 14 Aug 2017 00:27:54 +0200 Subject: [PATCH 08/22] General formatting --- .../Select/Leaderboards/LeaderboardScore.cs | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/osu.Game/Screens/Select/Leaderboards/LeaderboardScore.cs b/osu.Game/Screens/Select/Leaderboards/LeaderboardScore.cs index fcd87363d6..2971600a74 100644 --- a/osu.Game/Screens/Select/Leaderboards/LeaderboardScore.cs +++ b/osu.Game/Screens/Select/Leaderboards/LeaderboardScore.cs @@ -8,6 +8,7 @@ using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; +using osu.Framework.Input; using osu.Game.Graphics; using osu.Game.Graphics.Containers; using osu.Game.Graphics.Sprites; @@ -253,16 +254,13 @@ namespace osu.Game.Screens.Select.Leaderboards }, }; - if (Score.Mods != null) + foreach (Mod mod in Score.Mods) { - foreach (Mod mod in Score.Mods) + modsContainer.Add(new ModIcon(mod) { - modsContainer.Add(new ModIcon(mod) - { - AutoSizeAxes = Axes.Both, - Scale = new Vector2(0.375f) - }); - } + AutoSizeAxes = Axes.Both, + Scale = new Vector2(0.375f) + }); } } @@ -271,13 +269,13 @@ namespace osu.Game.Screens.Select.Leaderboards public override void Hide() => State = Visibility.Hidden; public override void Show() => State = Visibility.Visible; - protected override bool OnHover(Framework.Input.InputState state) + protected override bool OnHover(InputState state) { background.FadeTo(0.5f, 300, Easing.OutQuint); return base.OnHover(state); } - protected override void OnHoverLost(Framework.Input.InputState state) + protected override void OnHoverLost(InputState state) { background.FadeTo(background_alpha, 200, Easing.OutQuint); base.OnHoverLost(state); @@ -307,8 +305,8 @@ namespace osu.Game.Screens.Select.Leaderboards Anchor = Anchor.Centre, Origin = Anchor.Centre, Font = font, - TextSize = textSize, FixedWidth = true, + TextSize = textSize, Text = text, Colour = glowColour, Shadow = false, From 718eefa362e326efdb07331d2a6a2e7c52d53e1f Mon Sep 17 00:00:00 2001 From: MrTheMake Date: Mon, 14 Aug 2017 01:16:19 +0200 Subject: [PATCH 09/22] Fixed wrong test case accuracy format --- .../Visual/TestCaseLeaderboard.cs | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/osu.Desktop.Tests/Visual/TestCaseLeaderboard.cs b/osu.Desktop.Tests/Visual/TestCaseLeaderboard.cs index 5f8ee8795c..2386881d24 100644 --- a/osu.Desktop.Tests/Visual/TestCaseLeaderboard.cs +++ b/osu.Desktop.Tests/Visual/TestCaseLeaderboard.cs @@ -24,7 +24,7 @@ namespace osu.Desktop.Tests.Visual new Score { Rank = ScoreRank.XH, - Accuracy = 100, + Accuracy = 1, MaxCombo = 244, TotalScore = 1707827, Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), }, @@ -42,7 +42,7 @@ namespace osu.Desktop.Tests.Visual new Score { Rank = ScoreRank.X, - Accuracy = 100, + Accuracy = 1, MaxCombo = 244, TotalScore = 1707827, Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), }, @@ -60,7 +60,7 @@ namespace osu.Desktop.Tests.Visual new Score { Rank = ScoreRank.SH, - Accuracy = 100, + Accuracy = 1, MaxCombo = 244, TotalScore = 1707827, Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), }, @@ -78,7 +78,7 @@ namespace osu.Desktop.Tests.Visual new Score { Rank = ScoreRank.S, - Accuracy = 100, + Accuracy = 1, MaxCombo = 244, TotalScore = 1707827, Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), }, @@ -96,7 +96,7 @@ namespace osu.Desktop.Tests.Visual new Score { Rank = ScoreRank.A, - Accuracy = 100, + Accuracy = 1, MaxCombo = 244, TotalScore = 1707827, Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), }, @@ -114,7 +114,7 @@ namespace osu.Desktop.Tests.Visual new Score { Rank = ScoreRank.B, - Accuracy = 98.26, + Accuracy = 0.9826, MaxCombo = 244, TotalScore = 1707827, Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), }, @@ -132,7 +132,7 @@ namespace osu.Desktop.Tests.Visual new Score { Rank = ScoreRank.C, - Accuracy = 96.54, + Accuracy = 0.9654, MaxCombo = 244, TotalScore = 1707827, Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), }, @@ -150,7 +150,7 @@ namespace osu.Desktop.Tests.Visual new Score { Rank = ScoreRank.F, - Accuracy = 60.25, + Accuracy = 0.6025, MaxCombo = 244, TotalScore = 1707827, Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), }, @@ -168,7 +168,7 @@ namespace osu.Desktop.Tests.Visual new Score { Rank = ScoreRank.F, - Accuracy = 51.40, + Accuracy = 0.5140, MaxCombo = 244, TotalScore = 1707827, Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), }, @@ -186,7 +186,7 @@ namespace osu.Desktop.Tests.Visual new Score { Rank = ScoreRank.F, - Accuracy = 42.22, + Accuracy = 0.4222, MaxCombo = 244, TotalScore = 1707827, Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), }, From 920710e7d0b3e37f027becbe059394f8e1345eb2 Mon Sep 17 00:00:00 2001 From: MrTheMake Date: Mon, 14 Aug 2017 13:30:54 +0200 Subject: [PATCH 10/22] Assign a score's beatmap and cleanup to the Score class --- osu.Game/Rulesets/Scoring/Score.cs | 23 ++++--------------- .../Select/Leaderboards/Leaderboard.cs | 1 + 2 files changed, 5 insertions(+), 19 deletions(-) diff --git a/osu.Game/Rulesets/Scoring/Score.cs b/osu.Game/Rulesets/Scoring/Score.cs index 399a805bcc..15217352d0 100644 --- a/osu.Game/Rulesets/Scoring/Score.cs +++ b/osu.Game/Rulesets/Scoring/Score.cs @@ -28,19 +28,8 @@ namespace osu.Game.Rulesets.Scoring public int Combo { get; set; } - private string[] modStrings; [JsonProperty(@"mods")] - protected string[] ModStrings - { - get { return modStrings; } - set - { - modStrings = value; - - if (ruleset != null) - handleModString(); - } - } + protected string[] ModStrings { get; set; } private RulesetInfo ruleset; public RulesetInfo Ruleset @@ -50,8 +39,9 @@ namespace osu.Game.Rulesets.Scoring { ruleset = value; - if (modStrings != null) - handleModString(); + // Handle the mod strings if they are assigned + if (ModStrings != null) + Mods = Ruleset.CreateInstance().GetAllMods().Where(mod => ModStrings.Contains(mod.ShortenedName)).ToArray(); } } @@ -103,10 +93,5 @@ namespace osu.Game.Rulesets.Scoring } public Dictionary Statistics = new Dictionary(); - - private void handleModString() - { - Mods = Ruleset.CreateInstance().GetAllMods().Where(mod => modStrings.Contains(mod.ShortenedName)).ToArray(); - } } } diff --git a/osu.Game/Screens/Select/Leaderboards/Leaderboard.cs b/osu.Game/Screens/Select/Leaderboards/Leaderboard.cs index 740dc90586..5ec76a59ac 100644 --- a/osu.Game/Screens/Select/Leaderboards/Leaderboard.cs +++ b/osu.Game/Screens/Select/Leaderboards/Leaderboard.cs @@ -55,6 +55,7 @@ namespace osu.Game.Screens.Select.Leaderboards i = 0; foreach (var s in scores) { + s.Beatmap = beatmap; s.Ruleset = beatmap?.Ruleset; var ls = new LeaderboardScore(s, 1 + i) From 5ed717ef861d15e02a7319127dcc060fd0cad1a3 Mon Sep 17 00:00:00 2001 From: MrTheMake Date: Mon, 14 Aug 2017 15:16:22 +0200 Subject: [PATCH 11/22] Shortened GetAllMods() using LINQ --- osu.Game/Rulesets/Ruleset.cs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/osu.Game/Rulesets/Ruleset.cs b/osu.Game/Rulesets/Ruleset.cs index bb08850af9..af51a2cd3f 100644 --- a/osu.Game/Rulesets/Ruleset.cs +++ b/osu.Game/Rulesets/Ruleset.cs @@ -4,14 +4,14 @@ using System; using System.Linq; using System.Collections.Generic; +using osu.Framework.Graphics; using osu.Game.Beatmaps; using osu.Game.Graphics; +using osu.Game.Overlays.Settings; using osu.Game.Rulesets.Mods; +using osu.Game.Rulesets.Scoring; using osu.Game.Rulesets.UI; using osu.Game.Screens.Play; -using osu.Framework.Graphics; -using osu.Game.Rulesets.Scoring; -using osu.Game.Overlays.Settings; namespace osu.Game.Rulesets { @@ -23,10 +23,9 @@ namespace osu.Game.Rulesets public IEnumerable GetAllMods() { - List modList = new List(); - - foreach (ModType type in Enum.GetValues(typeof(ModType))) - modList.AddRange(GetModsFor(type).Where(mod => mod != null).SelectMany(mod => + return Enum.GetValues(typeof(ModType)).Cast().SelectMany(type => + { + return GetModsFor(type).Where(mod => mod != null).SelectMany(mod => { var multiMod = mod as MultiMod; @@ -34,9 +33,8 @@ namespace osu.Game.Rulesets return multiMod.Mods; return new[] { mod }; - })); - - return modList; + }); + }); } public abstract IEnumerable GetModsFor(ModType type); From e908a3675ee2ac024abce62243a1261539a1956d Mon Sep 17 00:00:00 2001 From: MrTheMake Date: Mon, 14 Aug 2017 18:24:54 +0200 Subject: [PATCH 12/22] Formatted the GetAllMods() function --- osu.Game/Rulesets/Ruleset.cs | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/osu.Game/Rulesets/Ruleset.cs b/osu.Game/Rulesets/Ruleset.cs index af51a2cd3f..b875dff44f 100644 --- a/osu.Game/Rulesets/Ruleset.cs +++ b/osu.Game/Rulesets/Ruleset.cs @@ -21,21 +21,7 @@ namespace osu.Game.Rulesets public virtual IEnumerable GetBeatmapStatistics(WorkingBeatmap beatmap) => new BeatmapStatistic[] { }; - public IEnumerable GetAllMods() - { - return Enum.GetValues(typeof(ModType)).Cast().SelectMany(type => - { - return GetModsFor(type).Where(mod => mod != null).SelectMany(mod => - { - var multiMod = mod as MultiMod; - - if (multiMod != null) - return multiMod.Mods; - - return new[] { mod }; - }); - }); - } + public IEnumerable GetAllMods() => Enum.GetValues(typeof(ModType)).Cast().SelectMany(type => GetModsFor(type).Where(mod => mod != null).SelectMany(mod => (mod as MultiMod)?.Mods ?? new[] { mod })); public abstract IEnumerable GetModsFor(ModType type); From 21ced322976ddf9d0892f2d939858fe782d82d97 Mon Sep 17 00:00:00 2001 From: MrTheMake Date: Tue, 15 Aug 2017 12:03:43 +0200 Subject: [PATCH 13/22] Formatted and commented the GetAllMods() function --- osu.Game/Rulesets/Ruleset.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/osu.Game/Rulesets/Ruleset.cs b/osu.Game/Rulesets/Ruleset.cs index b875dff44f..65cc6199f0 100644 --- a/osu.Game/Rulesets/Ruleset.cs +++ b/osu.Game/Rulesets/Ruleset.cs @@ -21,7 +21,14 @@ namespace osu.Game.Rulesets public virtual IEnumerable GetBeatmapStatistics(WorkingBeatmap beatmap) => new BeatmapStatistic[] { }; - public IEnumerable GetAllMods() => Enum.GetValues(typeof(ModType)).Cast().SelectMany(type => GetModsFor(type).Where(mod => mod != null).SelectMany(mod => (mod as MultiMod)?.Mods ?? new[] { mod })); + public IEnumerable GetAllMods() => Enum.GetValues(typeof(ModType)).Cast() + //Get all mod types as an IEnumerable + .SelectMany(type => GetModsFor(type)) + // Confine all mods of each mod type into a single IEnumerable + .Where(mod => mod != null) + // Filter out all null mods + .SelectMany(mod => (mod as MultiMod)?.Mods ?? new[] { mod }); + // Resolve MultiMods as their .Mods property public abstract IEnumerable GetModsFor(ModType type); From 2c287e13486419e771572fadd682d73d870c2261 Mon Sep 17 00:00:00 2001 From: MrTheMake Date: Tue, 15 Aug 2017 12:27:51 +0200 Subject: [PATCH 14/22] CI and comment fix --- osu.Game/Rulesets/Ruleset.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Game/Rulesets/Ruleset.cs b/osu.Game/Rulesets/Ruleset.cs index 65cc6199f0..fa12199a58 100644 --- a/osu.Game/Rulesets/Ruleset.cs +++ b/osu.Game/Rulesets/Ruleset.cs @@ -22,8 +22,8 @@ namespace osu.Game.Rulesets public virtual IEnumerable GetBeatmapStatistics(WorkingBeatmap beatmap) => new BeatmapStatistic[] { }; public IEnumerable GetAllMods() => Enum.GetValues(typeof(ModType)).Cast() - //Get all mod types as an IEnumerable - .SelectMany(type => GetModsFor(type)) + // Get all mod types as an IEnumerable + .SelectMany(GetModsFor) // Confine all mods of each mod type into a single IEnumerable .Where(mod => mod != null) // Filter out all null mods From 105048500ad9a30f173d04892c5dd56ec28e5cdc Mon Sep 17 00:00:00 2001 From: MrTheMake Date: Tue, 15 Aug 2017 15:30:53 +0200 Subject: [PATCH 15/22] Made modString private and moved the beatmap assignment inside GetScoresRequest --- osu.Game/Online/API/Requests/GetScoresRequest.cs | 11 +++++++++++ osu.Game/Rulesets/Scoring/Score.cs | 6 +++--- osu.Game/Screens/Select/Leaderboards/Leaderboard.cs | 3 --- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/osu.Game/Online/API/Requests/GetScoresRequest.cs b/osu.Game/Online/API/Requests/GetScoresRequest.cs index 966049429e..a902c8c807 100644 --- a/osu.Game/Online/API/Requests/GetScoresRequest.cs +++ b/osu.Game/Online/API/Requests/GetScoresRequest.cs @@ -16,6 +16,17 @@ namespace osu.Game.Online.API.Requests public GetScoresRequest(BeatmapInfo beatmap) { this.beatmap = beatmap; + + Success += onSuccess; + } + + private void onSuccess(GetScoresResponse r) + { + foreach (Score score in r.Scores) + { + score.Beatmap = beatmap; + score.Ruleset = beatmap.Ruleset; + } } protected override WebRequest CreateWebRequest() diff --git a/osu.Game/Rulesets/Scoring/Score.cs b/osu.Game/Rulesets/Scoring/Score.cs index 15217352d0..e42c3b2df0 100644 --- a/osu.Game/Rulesets/Scoring/Score.cs +++ b/osu.Game/Rulesets/Scoring/Score.cs @@ -29,7 +29,7 @@ namespace osu.Game.Rulesets.Scoring public int Combo { get; set; } [JsonProperty(@"mods")] - protected string[] ModStrings { get; set; } + private string[] modStrings { get; set; } private RulesetInfo ruleset; public RulesetInfo Ruleset @@ -40,8 +40,8 @@ namespace osu.Game.Rulesets.Scoring ruleset = value; // Handle the mod strings if they are assigned - if (ModStrings != null) - Mods = Ruleset.CreateInstance().GetAllMods().Where(mod => ModStrings.Contains(mod.ShortenedName)).ToArray(); + if (modStrings != null) + Mods = ruleset.CreateInstance().GetAllMods().Where(mod => modStrings.Contains(mod.ShortenedName)).ToArray(); } } diff --git a/osu.Game/Screens/Select/Leaderboards/Leaderboard.cs b/osu.Game/Screens/Select/Leaderboards/Leaderboard.cs index 5ec76a59ac..0506784614 100644 --- a/osu.Game/Screens/Select/Leaderboards/Leaderboard.cs +++ b/osu.Game/Screens/Select/Leaderboards/Leaderboard.cs @@ -55,9 +55,6 @@ namespace osu.Game.Screens.Select.Leaderboards i = 0; foreach (var s in scores) { - s.Beatmap = beatmap; - s.Ruleset = beatmap?.Ruleset; - var ls = new LeaderboardScore(s, 1 + i) { AlwaysPresent = true, From 586a652b08ea3591a7c237f193afebafb9f6d268 Mon Sep 17 00:00:00 2001 From: MrTheMake Date: Thu, 17 Aug 2017 12:24:22 +0200 Subject: [PATCH 16/22] Changed Mods to be a property --- .../Visual/TestCaseLeaderboard.cs | 2 +- osu.Game/Rulesets/Scoring/Score.cs | 24 ++++++++++++------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/osu.Desktop.Tests/Visual/TestCaseLeaderboard.cs b/osu.Desktop.Tests/Visual/TestCaseLeaderboard.cs index 2386881d24..f67db2f41a 100644 --- a/osu.Desktop.Tests/Visual/TestCaseLeaderboard.cs +++ b/osu.Desktop.Tests/Visual/TestCaseLeaderboard.cs @@ -1,13 +1,13 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using OpenTK; using osu.Framework.Graphics; using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Osu.Mods; using osu.Game.Rulesets.Scoring; using osu.Game.Screens.Select.Leaderboards; using osu.Game.Users; -using OpenTK; namespace osu.Desktop.Tests.Visual { diff --git a/osu.Game/Rulesets/Scoring/Score.cs b/osu.Game/Rulesets/Scoring/Score.cs index e42c3b2df0..e83cb916bb 100644 --- a/osu.Game/Rulesets/Scoring/Score.cs +++ b/osu.Game/Rulesets/Scoring/Score.cs @@ -31,22 +31,28 @@ namespace osu.Game.Rulesets.Scoring [JsonProperty(@"mods")] private string[] modStrings { get; set; } - private RulesetInfo ruleset; - public RulesetInfo Ruleset + public RulesetInfo Ruleset; + + private Mod[] mods; + public Mod[] Mods { - get { return ruleset; } + get + { + // Evaluate the mod strings + if (mods == null) + mods = Ruleset.CreateInstance().GetAllMods().Where(mod => modStrings.Contains(mod.ShortenedName)).ToArray(); + + return mods; + } set { - ruleset = value; + mods = value; - // Handle the mod strings if they are assigned - if (modStrings != null) - Mods = ruleset.CreateInstance().GetAllMods().Where(mod => modStrings.Contains(mod.ShortenedName)).ToArray(); + // Assign the mod strings + modStrings = mods.Select(mod => mod.ShortenedName).ToArray(); } } - public Mod[] Mods { get; set; } - [JsonProperty(@"user")] public User User; From f831832c59b0b015abd22fe2e5d529f962b4196c Mon Sep 17 00:00:00 2001 From: MrTheMake Date: Sat, 19 Aug 2017 00:13:06 +0200 Subject: [PATCH 17/22] CI fix --- osu.Game/Rulesets/Scoring/Score.cs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/osu.Game/Rulesets/Scoring/Score.cs b/osu.Game/Rulesets/Scoring/Score.cs index e83cb916bb..154188a2fa 100644 --- a/osu.Game/Rulesets/Scoring/Score.cs +++ b/osu.Game/Rulesets/Scoring/Score.cs @@ -38,11 +38,8 @@ namespace osu.Game.Rulesets.Scoring { get { - // Evaluate the mod strings - if (mods == null) - mods = Ruleset.CreateInstance().GetAllMods().Where(mod => modStrings.Contains(mod.ShortenedName)).ToArray(); - - return mods; + // Evaluate the mod strings if necessary + return mods ?? (mods = Ruleset.CreateInstance().GetAllMods().Where(mod => modStrings.Contains(mod.ShortenedName)).ToArray()); } set { From 709aa1ed3dc315e6b751784e06e509e3a83bde77 Mon Sep 17 00:00:00 2001 From: MrTheMake Date: Thu, 7 Sep 2017 18:20:14 +0200 Subject: [PATCH 18/22] Moved all online score related parsing to its own class --- .../Online/API/Requests/GetScoresRequest.cs | 11 ++++------ osu.Game/Rulesets/Scoring/OnlineScore.cs | 19 +++++++++++++++++ osu.Game/Rulesets/Scoring/Score.cs | 21 +------------------ osu.Game/osu.Game.csproj | 1 + 4 files changed, 25 insertions(+), 27 deletions(-) create mode 100644 osu.Game/Rulesets/Scoring/OnlineScore.cs diff --git a/osu.Game/Online/API/Requests/GetScoresRequest.cs b/osu.Game/Online/API/Requests/GetScoresRequest.cs index a902c8c807..72b8649ae0 100644 --- a/osu.Game/Online/API/Requests/GetScoresRequest.cs +++ b/osu.Game/Online/API/Requests/GetScoresRequest.cs @@ -22,11 +22,8 @@ namespace osu.Game.Online.API.Requests private void onSuccess(GetScoresResponse r) { - foreach (Score score in r.Scores) - { - score.Beatmap = beatmap; - score.Ruleset = beatmap.Ruleset; - } + foreach (OnlineScore score in r.Scores) + score.GetModsFor(beatmap.Ruleset); } protected override WebRequest CreateWebRequest() @@ -43,6 +40,6 @@ namespace osu.Game.Online.API.Requests public class GetScoresResponse { [JsonProperty(@"scores")] - public IEnumerable Scores; + public IEnumerable Scores; } -} \ No newline at end of file +} diff --git a/osu.Game/Rulesets/Scoring/OnlineScore.cs b/osu.Game/Rulesets/Scoring/OnlineScore.cs new file mode 100644 index 0000000000..1f652e3d6c --- /dev/null +++ b/osu.Game/Rulesets/Scoring/OnlineScore.cs @@ -0,0 +1,19 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using System.Linq; +using Newtonsoft.Json; + +namespace osu.Game.Rulesets.Scoring +{ + public class OnlineScore : Score + { + [JsonProperty(@"mods")] + private string[] modStrings { get; set; } + + public void GetModsFor(RulesetInfo ruleset) + { + Mods = ruleset.CreateInstance().GetAllMods().Where(mod => modStrings.Contains(mod.ShortenedName)).ToArray(); + } + } +} diff --git a/osu.Game/Rulesets/Scoring/Score.cs b/osu.Game/Rulesets/Scoring/Score.cs index 154188a2fa..ecc7b60986 100644 --- a/osu.Game/Rulesets/Scoring/Score.cs +++ b/osu.Game/Rulesets/Scoring/Score.cs @@ -2,7 +2,6 @@ // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using System; -using System.Linq; using System.Collections.Generic; using Newtonsoft.Json; using osu.Game.Beatmaps; @@ -28,27 +27,9 @@ namespace osu.Game.Rulesets.Scoring public int Combo { get; set; } - [JsonProperty(@"mods")] - private string[] modStrings { get; set; } - public RulesetInfo Ruleset; - private Mod[] mods; - public Mod[] Mods - { - get - { - // Evaluate the mod strings if necessary - return mods ?? (mods = Ruleset.CreateInstance().GetAllMods().Where(mod => modStrings.Contains(mod.ShortenedName)).ToArray()); - } - set - { - mods = value; - - // Assign the mod strings - modStrings = mods.Select(mod => mod.ShortenedName).ToArray(); - } - } + public Mod[] Mods; [JsonProperty(@"user")] public User User; diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 07ab58bffc..16812c3467 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -128,6 +128,7 @@ + From e71f907f899352f656d8a55236834e4c266385f1 Mon Sep 17 00:00:00 2001 From: MrTheMake Date: Thu, 7 Sep 2017 18:36:16 +0200 Subject: [PATCH 19/22] CI fix --- osu.Game/Rulesets/Ruleset.cs | 1 - osu.Game/Rulesets/Scoring/Score.cs | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/osu.Game/Rulesets/Ruleset.cs b/osu.Game/Rulesets/Ruleset.cs index 3d89afb7ff..33621662af 100644 --- a/osu.Game/Rulesets/Ruleset.cs +++ b/osu.Game/Rulesets/Ruleset.cs @@ -12,7 +12,6 @@ using osu.Game.Overlays.Settings; using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Scoring; using osu.Game.Rulesets.UI; -using osu.Game.Screens.Play; namespace osu.Game.Rulesets { diff --git a/osu.Game/Rulesets/Scoring/Score.cs b/osu.Game/Rulesets/Scoring/Score.cs index ecc7b60986..c09df06633 100644 --- a/osu.Game/Rulesets/Scoring/Score.cs +++ b/osu.Game/Rulesets/Scoring/Score.cs @@ -27,9 +27,9 @@ namespace osu.Game.Rulesets.Scoring public int Combo { get; set; } - public RulesetInfo Ruleset; + public RulesetInfo Ruleset { get; set; } - public Mod[] Mods; + public Mod[] Mods { get; set; } [JsonProperty(@"user")] public User User; From 01553fc9ef9d6bdddfac28f68986f5db169fbd69 Mon Sep 17 00:00:00 2001 From: MrTheMake Date: Fri, 8 Sep 2017 02:46:54 +0200 Subject: [PATCH 20/22] Moved all online related score parsing to its class --- .../Online/API/Requests/GetScoresRequest.cs | 7 +- osu.Game/Rulesets/Scoring/OnlineScore.cs | 75 ++++++++++++++++++- osu.Game/Rulesets/Scoring/Score.cs | 38 ---------- 3 files changed, 79 insertions(+), 41 deletions(-) diff --git a/osu.Game/Online/API/Requests/GetScoresRequest.cs b/osu.Game/Online/API/Requests/GetScoresRequest.cs index 72b8649ae0..6e22bd6989 100644 --- a/osu.Game/Online/API/Requests/GetScoresRequest.cs +++ b/osu.Game/Online/API/Requests/GetScoresRequest.cs @@ -23,7 +23,12 @@ namespace osu.Game.Online.API.Requests private void onSuccess(GetScoresResponse r) { foreach (OnlineScore score in r.Scores) - score.GetModsFor(beatmap.Ruleset); + { + score.Beatmap = beatmap; + score.Ruleset = beatmap.Ruleset; + + score.ResolveModString(); + } } protected override WebRequest CreateWebRequest() diff --git a/osu.Game/Rulesets/Scoring/OnlineScore.cs b/osu.Game/Rulesets/Scoring/OnlineScore.cs index 1f652e3d6c..694ce023d1 100644 --- a/osu.Game/Rulesets/Scoring/OnlineScore.cs +++ b/osu.Game/Rulesets/Scoring/OnlineScore.cs @@ -1,19 +1,90 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using System; +using System.Collections.Generic; using System.Linq; using Newtonsoft.Json; +using osu.Game.Users; +using osu.Game.Rulesets.Replays; namespace osu.Game.Rulesets.Scoring { public class OnlineScore : Score { + [JsonProperty(@"score")] + private double totalScore + { + set { TotalScore = value; } + } + + [JsonProperty(@"max_combo")] + private int maxCombo + { + set { MaxCombo = value; } + } + + [JsonProperty(@"user")] + private User user + { + set { User = value; } + } + + [JsonProperty(@"replay_data")] + private Replay replay + { + set { Replay = value; } + } + + [JsonProperty(@"score_id")] + private long onlineScoreID + { + set { OnlineScoreID = value; } + } + + [JsonProperty(@"created_at")] + private DateTimeOffset date + { + set { Date = value; } + } + + [JsonProperty(@"statistics")] + private Dictionary jsonStats + { + set + { + foreach (var kvp in value) + { + string key = kvp.Key; + switch (key) + { + case @"count_300": + key = @"300"; + break; + case @"count_100": + key = @"100"; + break; + case @"count_50": + key = @"50"; + break; + case @"count_miss": + key = @"x"; + break; + default: + continue; + } + + Statistics.Add(key, kvp.Value); + } + } + } + [JsonProperty(@"mods")] private string[] modStrings { get; set; } - public void GetModsFor(RulesetInfo ruleset) + public void ResolveModString() { - Mods = ruleset.CreateInstance().GetAllMods().Where(mod => modStrings.Contains(mod.ShortenedName)).ToArray(); + Mods = Ruleset.CreateInstance().GetAllMods().Where(mod => modStrings.Contains(mod.ShortenedName)).ToArray(); } } } diff --git a/osu.Game/Rulesets/Scoring/Score.cs b/osu.Game/Rulesets/Scoring/Score.cs index c09df06633..ff4632a9c2 100644 --- a/osu.Game/Rulesets/Scoring/Score.cs +++ b/osu.Game/Rulesets/Scoring/Score.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; -using Newtonsoft.Json; using osu.Game.Beatmaps; using osu.Game.Rulesets.Mods; using osu.Game.Users; @@ -15,14 +14,12 @@ namespace osu.Game.Rulesets.Scoring { public ScoreRank Rank { get; set; } - [JsonProperty(@"score")] public double TotalScore { get; set; } public double Accuracy { get; set; } public double Health { get; set; } = 1; - [JsonProperty(@"max_combo")] public int MaxCombo { get; set; } public int Combo { get; set; } @@ -31,51 +28,16 @@ namespace osu.Game.Rulesets.Scoring public Mod[] Mods { get; set; } - [JsonProperty(@"user")] public User User; - [JsonProperty(@"replay_data")] public Replay Replay; public BeatmapInfo Beatmap; - [JsonProperty(@"score_id")] public long OnlineScoreID; - [JsonProperty(@"created_at")] public DateTimeOffset Date; - [JsonProperty(@"statistics")] - private Dictionary jsonStats - { - set - { - foreach (var kvp in value) - { - string key = kvp.Key; - switch (key) - { - case @"count_300": - key = @"300"; - break; - case @"count_100": - key = @"100"; - break; - case @"count_50": - key = @"50"; - break; - case @"count_miss": - key = @"x"; - break; - default: - continue; - } - - Statistics.Add(key, kvp.Value); - } - } - } - public Dictionary Statistics = new Dictionary(); } } From 526ee107b8102ad0dd815e59e8d543f00cc52436 Mon Sep 17 00:00:00 2001 From: MrTheMake Date: Fri, 8 Sep 2017 12:17:16 +0200 Subject: [PATCH 21/22] Use a method to apply a beatmap, its ruleset and the mods. --- osu.Game/Online/API/Requests/GetScoresRequest.cs | 7 +------ osu.Game/Rulesets/Scoring/OnlineScore.cs | 7 ++++++- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/osu.Game/Online/API/Requests/GetScoresRequest.cs b/osu.Game/Online/API/Requests/GetScoresRequest.cs index 6e22bd6989..d5ba22b9ac 100644 --- a/osu.Game/Online/API/Requests/GetScoresRequest.cs +++ b/osu.Game/Online/API/Requests/GetScoresRequest.cs @@ -23,12 +23,7 @@ namespace osu.Game.Online.API.Requests private void onSuccess(GetScoresResponse r) { foreach (OnlineScore score in r.Scores) - { - score.Beatmap = beatmap; - score.Ruleset = beatmap.Ruleset; - - score.ResolveModString(); - } + score.ApplyBeatmap(beatmap); } protected override WebRequest CreateWebRequest() diff --git a/osu.Game/Rulesets/Scoring/OnlineScore.cs b/osu.Game/Rulesets/Scoring/OnlineScore.cs index 694ce023d1..a58d682d05 100644 --- a/osu.Game/Rulesets/Scoring/OnlineScore.cs +++ b/osu.Game/Rulesets/Scoring/OnlineScore.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.Linq; using Newtonsoft.Json; +using osu.Game.Beatmaps; using osu.Game.Users; using osu.Game.Rulesets.Replays; @@ -82,8 +83,12 @@ namespace osu.Game.Rulesets.Scoring [JsonProperty(@"mods")] private string[] modStrings { get; set; } - public void ResolveModString() + public void ApplyBeatmap(BeatmapInfo beatmap) { + Beatmap = beatmap; + Ruleset = beatmap.Ruleset; + + // Evaluate the mod string Mods = Ruleset.CreateInstance().GetAllMods().Where(mod => modStrings.Contains(mod.ShortenedName)).ToArray(); } } From 0b1403683bc9a806a152067707eaba56052e273e Mon Sep 17 00:00:00 2001 From: MrTheMake Date: Fri, 8 Sep 2017 12:21:35 +0200 Subject: [PATCH 22/22] Moved OnlineScore inside GetScoresRequest.cs --- .../Online/API/Requests/GetScoresRequest.cs | 86 +++++++++++++++++ osu.Game/Rulesets/Scoring/OnlineScore.cs | 95 ------------------- osu.Game/osu.Game.csproj | 1 - 3 files changed, 86 insertions(+), 96 deletions(-) delete mode 100644 osu.Game/Rulesets/Scoring/OnlineScore.cs diff --git a/osu.Game/Online/API/Requests/GetScoresRequest.cs b/osu.Game/Online/API/Requests/GetScoresRequest.cs index d5ba22b9ac..ef9ee85d25 100644 --- a/osu.Game/Online/API/Requests/GetScoresRequest.cs +++ b/osu.Game/Online/API/Requests/GetScoresRequest.cs @@ -1,10 +1,14 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using System; using System.Collections.Generic; +using System.Linq; using Newtonsoft.Json; using osu.Framework.IO.Network; using osu.Game.Beatmaps; +using osu.Game.Users; +using osu.Game.Rulesets.Replays; using osu.Game.Rulesets.Scoring; namespace osu.Game.Online.API.Requests @@ -42,4 +46,86 @@ namespace osu.Game.Online.API.Requests [JsonProperty(@"scores")] public IEnumerable Scores; } + + public class OnlineScore : Score + { + [JsonProperty(@"score")] + private double totalScore + { + set { TotalScore = value; } + } + + [JsonProperty(@"max_combo")] + private int maxCombo + { + set { MaxCombo = value; } + } + + [JsonProperty(@"user")] + private User user + { + set { User = value; } + } + + [JsonProperty(@"replay_data")] + private Replay replay + { + set { Replay = value; } + } + + [JsonProperty(@"score_id")] + private long onlineScoreID + { + set { OnlineScoreID = value; } + } + + [JsonProperty(@"created_at")] + private DateTimeOffset date + { + set { Date = value; } + } + + [JsonProperty(@"statistics")] + private Dictionary jsonStats + { + set + { + foreach (var kvp in value) + { + string key = kvp.Key; + switch (key) + { + case @"count_300": + key = @"300"; + break; + case @"count_100": + key = @"100"; + break; + case @"count_50": + key = @"50"; + break; + case @"count_miss": + key = @"x"; + break; + default: + continue; + } + + Statistics.Add(key, kvp.Value); + } + } + } + + [JsonProperty(@"mods")] + private string[] modStrings { get; set; } + + public void ApplyBeatmap(BeatmapInfo beatmap) + { + Beatmap = beatmap; + Ruleset = beatmap.Ruleset; + + // Evaluate the mod string + Mods = Ruleset.CreateInstance().GetAllMods().Where(mod => modStrings.Contains(mod.ShortenedName)).ToArray(); + } + } } diff --git a/osu.Game/Rulesets/Scoring/OnlineScore.cs b/osu.Game/Rulesets/Scoring/OnlineScore.cs deleted file mode 100644 index a58d682d05..0000000000 --- a/osu.Game/Rulesets/Scoring/OnlineScore.cs +++ /dev/null @@ -1,95 +0,0 @@ -// Copyright (c) 2007-2017 ppy Pty Ltd . -// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE - -using System; -using System.Collections.Generic; -using System.Linq; -using Newtonsoft.Json; -using osu.Game.Beatmaps; -using osu.Game.Users; -using osu.Game.Rulesets.Replays; - -namespace osu.Game.Rulesets.Scoring -{ - public class OnlineScore : Score - { - [JsonProperty(@"score")] - private double totalScore - { - set { TotalScore = value; } - } - - [JsonProperty(@"max_combo")] - private int maxCombo - { - set { MaxCombo = value; } - } - - [JsonProperty(@"user")] - private User user - { - set { User = value; } - } - - [JsonProperty(@"replay_data")] - private Replay replay - { - set { Replay = value; } - } - - [JsonProperty(@"score_id")] - private long onlineScoreID - { - set { OnlineScoreID = value; } - } - - [JsonProperty(@"created_at")] - private DateTimeOffset date - { - set { Date = value; } - } - - [JsonProperty(@"statistics")] - private Dictionary jsonStats - { - set - { - foreach (var kvp in value) - { - string key = kvp.Key; - switch (key) - { - case @"count_300": - key = @"300"; - break; - case @"count_100": - key = @"100"; - break; - case @"count_50": - key = @"50"; - break; - case @"count_miss": - key = @"x"; - break; - default: - continue; - } - - Statistics.Add(key, kvp.Value); - } - } - } - - [JsonProperty(@"mods")] - private string[] modStrings { get; set; } - - public void ApplyBeatmap(BeatmapInfo beatmap) - { - Beatmap = beatmap; - Ruleset = beatmap.Ruleset; - - // Evaluate the mod string - Mods = Ruleset.CreateInstance().GetAllMods().Where(mod => modStrings.Contains(mod.ShortenedName)).ToArray(); - } - } -} diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 66a892406f..05ba3e25ab 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -244,7 +244,6 @@ -