diff --git a/osu.Desktop.Tests/VisualTests.cs b/osu.Desktop.Tests/VisualTests.cs index 6519dbe917..6ef924e873 100644 --- a/osu.Desktop.Tests/VisualTests.cs +++ b/osu.Desktop.Tests/VisualTests.cs @@ -4,11 +4,6 @@ using NUnit.Framework; using osu.Desktop.VisualTests; using osu.Framework.Desktop.Platform; -using osu.Game.Modes; -using osu.Game.Modes.Catch; -using osu.Game.Modes.Mania; -using osu.Game.Modes.Osu; -using osu.Game.Modes.Taiko; namespace osu.Desktop.Tests { @@ -20,11 +15,6 @@ namespace osu.Desktop.Tests { using (var host = new HeadlessGameHost()) { - Ruleset.Register(new OsuRuleset()); - Ruleset.Register(new TaikoRuleset()); - Ruleset.Register(new ManiaRuleset()); - Ruleset.Register(new CatchRuleset()); - host.Run(new AutomatedVisualTestGame()); } } diff --git a/osu.Desktop.VisualTests/Program.cs b/osu.Desktop.VisualTests/Program.cs index fe1cdfd7f0..03d1588b78 100644 --- a/osu.Desktop.VisualTests/Program.cs +++ b/osu.Desktop.VisualTests/Program.cs @@ -4,11 +4,6 @@ using System; using osu.Framework.Desktop; using osu.Framework.Platform; -using osu.Game.Modes; -using osu.Game.Modes.Catch; -using osu.Game.Modes.Mania; -using osu.Game.Modes.Osu; -using osu.Game.Modes.Taiko; namespace osu.Desktop.VisualTests { @@ -21,11 +16,6 @@ namespace osu.Desktop.VisualTests using (GameHost host = Host.GetSuitableHost(@"osu")) { - Ruleset.Register(new OsuRuleset()); - Ruleset.Register(new TaikoRuleset()); - Ruleset.Register(new ManiaRuleset()); - Ruleset.Register(new CatchRuleset()); - if (benchmark) host.Run(new AutomatedVisualTestGame()); else diff --git a/osu.Desktop.VisualTests/Tests/TestCaseGamefield.cs b/osu.Desktop.VisualTests/Tests/TestCaseGamefield.cs index 3129cade63..d1519d0404 100644 --- a/osu.Desktop.VisualTests/Tests/TestCaseGamefield.cs +++ b/osu.Desktop.VisualTests/Tests/TestCaseGamefield.cs @@ -17,13 +17,22 @@ using osu.Game.Modes.Osu.UI; using osu.Game.Modes.Taiko.UI; using System.Collections.Generic; using osu.Desktop.VisualTests.Beatmaps; +using osu.Framework.Allocation; namespace osu.Desktop.VisualTests.Tests { internal class TestCaseGamefield : TestCase { + private RulesetDatabase rulesets; + public override string Description => @"Showing hitobjects and what not."; + [BackgroundDependencyLoader] + private void load(RulesetDatabase rulesets) + { + this.rulesets = rulesets; + } + public override void Reset() { base.Reset(); @@ -49,6 +58,7 @@ namespace osu.Desktop.VisualTests.Tests BeatmapInfo = new BeatmapInfo { Difficulty = new BeatmapDifficulty(), + Ruleset = rulesets.Query().First(), Metadata = new BeatmapMetadata { Artist = @"Unknown", diff --git a/osu.Desktop.VisualTests/Tests/TestCaseModSelectOverlay.cs b/osu.Desktop.VisualTests/Tests/TestCaseModSelectOverlay.cs index 7677682ac8..d1c137191f 100644 --- a/osu.Desktop.VisualTests/Tests/TestCaseModSelectOverlay.cs +++ b/osu.Desktop.VisualTests/Tests/TestCaseModSelectOverlay.cs @@ -1,10 +1,11 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Game.Overlays.Mods; using osu.Framework.Testing; -using osu.Game.Modes; +using osu.Game.Database; namespace osu.Desktop.VisualTests.Tests { @@ -13,6 +14,13 @@ namespace osu.Desktop.VisualTests.Tests public override string Description => @"Tests the mod select overlay"; private ModSelectOverlay modSelect; + private RulesetDatabase rulesets; + + [BackgroundDependencyLoader] + private void load(RulesetDatabase rulesets) + { + this.rulesets = rulesets; + } public override void Reset() { @@ -26,10 +34,9 @@ namespace osu.Desktop.VisualTests.Tests }); AddStep("Toggle", modSelect.ToggleVisibility); - AddStep("osu!", () => modSelect.PlayMode.Value = PlayMode.Osu); - AddStep("osu!taiko", () => modSelect.PlayMode.Value = PlayMode.Taiko); - AddStep("osu!catch", () => modSelect.PlayMode.Value = PlayMode.Catch); - AddStep("osu!mania", () => modSelect.PlayMode.Value = PlayMode.Mania); + + foreach (var ruleset in rulesets.AllRulesets) + AddStep(ruleset.CreateInstance().Description, () => modSelect.Ruleset.Value = ruleset); } } } diff --git a/osu.Desktop.VisualTests/Tests/TestCasePlaySongSelect.cs b/osu.Desktop.VisualTests/Tests/TestCasePlaySongSelect.cs index 1a43425dda..35eb6d0ff9 100644 --- a/osu.Desktop.VisualTests/Tests/TestCasePlaySongSelect.cs +++ b/osu.Desktop.VisualTests/Tests/TestCasePlaySongSelect.cs @@ -6,7 +6,6 @@ using osu.Desktop.VisualTests.Platform; using osu.Framework.Testing; using osu.Framework.MathUtils; using osu.Game.Database; -using osu.Game.Modes; using osu.Game.Screens.Select; using osu.Game.Screens.Select.Filter; @@ -20,13 +19,19 @@ namespace osu.Desktop.VisualTests.Tests public override string Description => @"with fake data"; + private RulesetDatabase rulesets; + public override void Reset() { base.Reset(); if (db == null) { storage = new TestStorage(@"TestCasePlaySongSelect"); - db = new BeatmapDatabase(storage); + + var backingDatabase = storage.GetDatabase(@"client"); + + rulesets = new RulesetDatabase(storage, backingDatabase); + db = new BeatmapDatabase(storage, backingDatabase, rulesets); var sets = new List(); @@ -72,7 +77,7 @@ namespace osu.Desktop.VisualTests.Tests new BeatmapInfo { OnlineBeatmapID = 1234 + i, - Mode = PlayMode.Osu, + Ruleset = rulesets.Query().First(), Path = "normal.osu", Version = "Normal", Difficulty = new BeatmapDifficulty @@ -83,7 +88,7 @@ namespace osu.Desktop.VisualTests.Tests new BeatmapInfo { OnlineBeatmapID = 1235 + i, - Mode = PlayMode.Osu, + Ruleset = rulesets.Query().First(), Path = "hard.osu", Version = "Hard", Difficulty = new BeatmapDifficulty @@ -94,7 +99,7 @@ namespace osu.Desktop.VisualTests.Tests new BeatmapInfo { OnlineBeatmapID = 1236 + i, - Mode = PlayMode.Osu, + Ruleset = rulesets.Query().First(), Path = "insane.osu", Version = "Insane", Difficulty = new BeatmapDifficulty diff --git a/osu.Desktop.VisualTests/Tests/TestCasePlayer.cs b/osu.Desktop.VisualTests/Tests/TestCasePlayer.cs index 624723ed35..8e19419dbb 100644 --- a/osu.Desktop.VisualTests/Tests/TestCasePlayer.cs +++ b/osu.Desktop.VisualTests/Tests/TestCasePlayer.cs @@ -9,7 +9,6 @@ using osu.Game.Beatmaps; using OpenTK; using osu.Framework.Graphics.Sprites; using osu.Game.Database; -using osu.Game.Modes; using osu.Game.Modes.Objects; using osu.Game.Modes.Osu.Objects; using osu.Game.Screens.Play; @@ -22,12 +21,14 @@ namespace osu.Desktop.VisualTests.Tests { protected Player Player; private BeatmapDatabase db; + private RulesetDatabase rulesets; public override string Description => @"Showing everything to play the game."; [BackgroundDependencyLoader] - private void load(BeatmapDatabase db) + private void load(BeatmapDatabase db, RulesetDatabase rulesets) { + this.rulesets = rulesets; this.db = db; } @@ -37,7 +38,7 @@ namespace osu.Desktop.VisualTests.Tests WorkingBeatmap beatmap = null; - var beatmapInfo = db.Query().FirstOrDefault(b => b.Mode == PlayMode.Osu); + var beatmapInfo = db.Query().FirstOrDefault(b => b.RulesetID == 0); if (beatmapInfo != null) beatmap = db.GetWorkingBeatmap(beatmapInfo); @@ -65,6 +66,7 @@ namespace osu.Desktop.VisualTests.Tests BeatmapInfo = new BeatmapInfo { Difficulty = new BeatmapDifficulty(), + Ruleset = rulesets.Query().First(), Metadata = new BeatmapMetadata { Artist = @"Unknown", diff --git a/osu.Desktop/Program.cs b/osu.Desktop/Program.cs index ddf58ac363..210f780078 100644 --- a/osu.Desktop/Program.cs +++ b/osu.Desktop/Program.cs @@ -7,11 +7,6 @@ using osu.Desktop.Beatmaps.IO; using osu.Framework.Desktop; using osu.Framework.Desktop.Platform; using osu.Game.IPC; -using osu.Game.Modes; -using osu.Game.Modes.Catch; -using osu.Game.Modes.Mania; -using osu.Game.Modes.Osu; -using osu.Game.Modes.Taiko; namespace osu.Desktop { @@ -41,11 +36,6 @@ namespace osu.Desktop } else { - Ruleset.Register(new OsuRuleset()); - Ruleset.Register(new TaikoRuleset()); - Ruleset.Register(new ManiaRuleset()); - Ruleset.Register(new CatchRuleset()); - host.Run(new OsuGameDesktop(args)); } return 0; diff --git a/osu.Game.Modes.Catch/CatchRuleset.cs b/osu.Game.Modes.Catch/CatchRuleset.cs index 09d8bdb9e5..6aafb2a3c6 100644 --- a/osu.Game.Modes.Catch/CatchRuleset.cs +++ b/osu.Game.Modes.Catch/CatchRuleset.cs @@ -76,8 +76,6 @@ namespace osu.Game.Modes.Catch } } - protected override PlayMode PlayMode => PlayMode.Catch; - public override string Description => "osu!catch"; public override FontAwesome Icon => FontAwesome.fa_osu_fruits_o; @@ -92,5 +90,7 @@ namespace osu.Game.Modes.Catch public override DifficultyCalculator CreateDifficultyCalculator(Beatmap beatmap) => new CatchDifficultyCalculator(beatmap); public override ScoreProcessor CreateScoreProcessor() => new CatchScoreProcessor(); + + public override int LegacyID => 2; } } diff --git a/osu.Game.Modes.Mania/ManiaRuleset.cs b/osu.Game.Modes.Mania/ManiaRuleset.cs index bd995d87d6..030cea7344 100644 --- a/osu.Game.Modes.Mania/ManiaRuleset.cs +++ b/osu.Game.Modes.Mania/ManiaRuleset.cs @@ -96,8 +96,6 @@ namespace osu.Game.Modes.Mania } } - protected override PlayMode PlayMode => PlayMode.Mania; - public override string Description => "osu!mania"; public override FontAwesome Icon => FontAwesome.fa_osu_mania_o; @@ -107,5 +105,7 @@ namespace osu.Game.Modes.Mania public override DifficultyCalculator CreateDifficultyCalculator(Beatmap beatmap) => new ManiaDifficultyCalculator(beatmap); public override ScoreProcessor CreateScoreProcessor() => new ManiaScoreProcessor(); + + public override int LegacyID => 3; } } diff --git a/osu.Game.Modes.Osu/OsuRuleset.cs b/osu.Game.Modes.Osu/OsuRuleset.cs index 12df7d3f3c..4de890ac5f 100644 --- a/osu.Game.Modes.Osu/OsuRuleset.cs +++ b/osu.Game.Modes.Osu/OsuRuleset.cs @@ -99,8 +99,6 @@ namespace osu.Game.Modes.Osu public override DifficultyCalculator CreateDifficultyCalculator(Beatmap beatmap) => new OsuDifficultyCalculator(beatmap); - protected override PlayMode PlayMode => PlayMode.Osu; - public override string Description => "osu!"; public override IEnumerable CreateGameplayKeys() => new KeyCounter[] @@ -112,5 +110,7 @@ namespace osu.Game.Modes.Osu }; public override ScoreProcessor CreateScoreProcessor() => new OsuScoreProcessor(); + + public override int LegacyID => 0; } } diff --git a/osu.Game.Modes.Taiko/TaikoRuleset.cs b/osu.Game.Modes.Taiko/TaikoRuleset.cs index 1b3c3fc0eb..b93c25c55d 100644 --- a/osu.Game.Modes.Taiko/TaikoRuleset.cs +++ b/osu.Game.Modes.Taiko/TaikoRuleset.cs @@ -76,8 +76,6 @@ namespace osu.Game.Modes.Taiko } } - protected override PlayMode PlayMode => PlayMode.Taiko; - public override string Description => "osu!taiko"; public override FontAwesome Icon => FontAwesome.fa_osu_taiko_o; @@ -93,5 +91,7 @@ namespace osu.Game.Modes.Taiko public override DifficultyCalculator CreateDifficultyCalculator(Beatmap beatmap) => new TaikoDifficultyCalculator(beatmap); public override ScoreProcessor CreateScoreProcessor() => new TaikoScoreProcessor(); + + public override int LegacyID => 1; } } diff --git a/osu.Game.Tests/Beatmaps/Formats/OsuLegacyDecoderTest.cs b/osu.Game.Tests/Beatmaps/Formats/OsuLegacyDecoderTest.cs index 8183bc952e..5e94a4dd77 100644 --- a/osu.Game.Tests/Beatmaps/Formats/OsuLegacyDecoderTest.cs +++ b/osu.Game.Tests/Beatmaps/Formats/OsuLegacyDecoderTest.cs @@ -6,9 +6,7 @@ using NUnit.Framework; using OpenTK; using OpenTK.Graphics; using osu.Game.Beatmaps.Formats; -using osu.Game.Modes; using osu.Game.Tests.Resources; -using osu.Game.Modes.Osu; using osu.Game.Modes.Objects.Legacy; using System.Linq; using osu.Game.Audio; @@ -22,7 +20,6 @@ namespace osu.Game.Tests.Beatmaps.Formats public void SetUp() { OsuLegacyDecoder.Register(); - Ruleset.Register(new OsuRuleset()); } [Test] @@ -58,7 +55,7 @@ namespace osu.Game.Tests.Beatmaps.Formats Assert.AreEqual(false, beatmapInfo.Countdown); Assert.AreEqual(0.7f, beatmapInfo.StackLeniency); Assert.AreEqual(false, beatmapInfo.SpecialStyle); - Assert.AreEqual(PlayMode.Osu, beatmapInfo.Mode); + Assert.IsTrue(beatmapInfo.RulesetID == 0); Assert.AreEqual(false, beatmapInfo.LetterboxInBreaks); Assert.AreEqual(false, beatmapInfo.WidescreenStoryboard); } diff --git a/osu.Game.Tests/Beatmaps/IO/ImportBeatmapTest.cs b/osu.Game.Tests/Beatmaps/IO/ImportBeatmapTest.cs index 5d15b43761..b35f5901be 100644 --- a/osu.Game.Tests/Beatmaps/IO/ImportBeatmapTest.cs +++ b/osu.Game.Tests/Beatmaps/IO/ImportBeatmapTest.cs @@ -12,11 +12,6 @@ using osu.Framework.Desktop.Platform; using osu.Framework.Platform; using osu.Game.Database; using osu.Game.IPC; -using osu.Game.Modes; -using osu.Game.Modes.Catch; -using osu.Game.Modes.Mania; -using osu.Game.Modes.Osu; -using osu.Game.Modes.Taiko; namespace osu.Game.Tests.Beatmaps.IO { @@ -25,15 +20,6 @@ namespace osu.Game.Tests.Beatmaps.IO { private const string osz_path = @"../../../osu-resources/osu.Game.Resources/Beatmaps/241526 Soleily - Renatus.osz"; - [OneTimeSetUp] - public void SetUp() - { - Ruleset.Register(new OsuRuleset()); - Ruleset.Register(new TaikoRuleset()); - Ruleset.Register(new ManiaRuleset()); - Ruleset.Register(new CatchRuleset()); - } - [Test] public void TestImportWhenClosed() { @@ -119,6 +105,7 @@ namespace osu.Game.Tests.Beatmaps.IO Thread.Sleep(1); //reset beatmap database (sqlite and storage backing) + osu.Dependencies.Get().Reset(); osu.Dependencies.Get().Reset(); return osu; @@ -166,8 +153,16 @@ namespace osu.Game.Tests.Beatmaps.IO Assert.IsTrue(set.Beatmaps.Count > 0); - var beatmap = osu.Dependencies.Get().GetWorkingBeatmap(set.Beatmaps.First(b => b.Mode == PlayMode.Osu))?.Beatmap; + var beatmap = osu.Dependencies.Get().GetWorkingBeatmap(set.Beatmaps.First(b => b.RulesetID == 0))?.Beatmap; + Assert.IsTrue(beatmap?.HitObjects.Count > 0); + beatmap = osu.Dependencies.Get().GetWorkingBeatmap(set.Beatmaps.First(b => b.RulesetID == 1))?.Beatmap; + Assert.IsTrue(beatmap?.HitObjects.Count > 0); + + beatmap = osu.Dependencies.Get().GetWorkingBeatmap(set.Beatmaps.First(b => b.RulesetID == 2))?.Beatmap; + Assert.IsTrue(beatmap?.HitObjects.Count > 0); + + beatmap = osu.Dependencies.Get().GetWorkingBeatmap(set.Beatmaps.First(b => b.RulesetID == 3))?.Beatmap; Assert.IsTrue(beatmap?.HitObjects.Count > 0); } } diff --git a/osu.Game.Tests/Beatmaps/IO/OszArchiveReaderTest.cs b/osu.Game.Tests/Beatmaps/IO/OszArchiveReaderTest.cs index b9c4cf780a..03d09e24e0 100644 --- a/osu.Game.Tests/Beatmaps/IO/OszArchiveReaderTest.cs +++ b/osu.Game.Tests/Beatmaps/IO/OszArchiveReaderTest.cs @@ -4,8 +4,6 @@ using System.IO; using NUnit.Framework; using osu.Game.Beatmaps.IO; -using osu.Game.Modes; -using osu.Game.Modes.Osu; using osu.Game.Tests.Resources; using osu.Game.Beatmaps.Formats; using osu.Game.Database; @@ -19,7 +17,6 @@ namespace osu.Game.Tests.Beatmaps.IO public void SetUp() { OszArchiveReader.Register(); - Ruleset.Register(new OsuRuleset()); } [Test] diff --git a/osu.Game/Beatmaps/Beatmap.cs b/osu.Game/Beatmaps/Beatmap.cs index 5709bdc8c5..e3a7a81d0d 100644 --- a/osu.Game/Beatmaps/Beatmap.cs +++ b/osu.Game/Beatmaps/Beatmap.cs @@ -4,7 +4,6 @@ using OpenTK.Graphics; using osu.Game.Beatmaps.Timing; using osu.Game.Database; -using osu.Game.Modes; using osu.Game.Modes.Objects; using System.Collections.Generic; @@ -50,12 +49,6 @@ namespace osu.Game.Beatmaps /// public class Beatmap : Beatmap { - /// - /// Calculates the star difficulty for this Beatmap. - /// - /// The star difficulty. - public double CalculateStarDifficulty() => Ruleset.GetRuleset(BeatmapInfo.Mode).CreateDifficultyCalculator(this).Calculate(); - /// /// Constructs a new beatmap. /// diff --git a/osu.Game/Beatmaps/Drawables/DifficultyIcon.cs b/osu.Game/Beatmaps/Drawables/DifficultyIcon.cs index 47ae4d7985..8a9183819c 100644 --- a/osu.Game/Beatmaps/Drawables/DifficultyIcon.cs +++ b/osu.Game/Beatmaps/Drawables/DifficultyIcon.cs @@ -6,7 +6,6 @@ using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Game.Database; using osu.Game.Graphics; -using osu.Game.Modes; using OpenTK; using OpenTK.Graphics; @@ -45,7 +44,7 @@ namespace osu.Game.Beatmaps.Drawables Origin = Anchor.Centre, TextSize = Size.X, Colour = Color4.White, - Icon = Ruleset.GetRuleset(beatmap.Mode).Icon + Icon = beatmap.Ruleset.CreateInstance().Icon } }; } diff --git a/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs b/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs index 35d81311d2..8ad5f8e7c0 100644 --- a/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs +++ b/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs @@ -7,7 +7,6 @@ using System.IO; using OpenTK.Graphics; using osu.Game.Beatmaps.Events; using osu.Game.Beatmaps.Timing; -using osu.Game.Modes; using osu.Game.Modes.Objects; using osu.Game.Beatmaps.Legacy; @@ -84,7 +83,7 @@ namespace osu.Game.Beatmaps.Formats beatmap.BeatmapInfo.StackLeniency = float.Parse(val, NumberFormatInfo.InvariantInfo); break; case @"Mode": - beatmap.BeatmapInfo.Mode = (PlayMode)int.Parse(val); + beatmap.BeatmapInfo.RulesetID = int.Parse(val); break; case @"LetterboxInBreaks": beatmap.BeatmapInfo.LetterboxInBreaks = int.Parse(val) == 1; diff --git a/osu.Game/Beatmaps/WorkingBeatmap.cs b/osu.Game/Beatmaps/WorkingBeatmap.cs index 5bea1d0986..8ffec25882 100644 --- a/osu.Game/Beatmaps/WorkingBeatmap.cs +++ b/osu.Game/Beatmaps/WorkingBeatmap.cs @@ -5,7 +5,6 @@ using osu.Framework.Audio.Track; using osu.Framework.Configuration; using osu.Framework.Graphics.Textures; using osu.Game.Database; -using osu.Game.Modes; using osu.Game.Modes.Mods; using System; using System.Collections.Generic; @@ -18,14 +17,6 @@ namespace osu.Game.Beatmaps public readonly BeatmapSetInfo BeatmapSetInfo; - /// - /// A play mode that is preferred for this beatmap. PlayMode will become this mode where conversion is feasible, - /// or otherwise to the beatmap's default. - /// - public PlayMode? PreferredPlayMode; - - public PlayMode PlayMode => Beatmap?.BeatmapInfo?.Mode > PlayMode.Osu ? Beatmap.BeatmapInfo.Mode : PreferredPlayMode ?? PlayMode.Osu; - public readonly Bindable> Mods = new Bindable>(); public readonly bool WithStoryboard; diff --git a/osu.Game/Configuration/OsuConfigManager.cs b/osu.Game/Configuration/OsuConfigManager.cs index e2f33479c0..a31c1f882d 100644 --- a/osu.Game/Configuration/OsuConfigManager.cs +++ b/osu.Game/Configuration/OsuConfigManager.cs @@ -4,7 +4,6 @@ using System; using osu.Framework.Configuration; using osu.Framework.Platform; -using osu.Game.Modes; namespace osu.Game.Configuration { @@ -17,7 +16,7 @@ namespace osu.Game.Configuration Set(OsuConfig.Username, string.Empty); Set(OsuConfig.Token, string.Empty); - Set(OsuConfig.PlayMode, PlayMode.Osu); + Set(OsuConfig.Ruleset, 0, 0, int.MaxValue); Set(OsuConfig.AudioDevice, string.Empty); Set(OsuConfig.SavePassword, false); @@ -196,7 +195,7 @@ namespace osu.Game.Configuration public enum OsuConfig { // New osu: - PlayMode, + Ruleset, Token, // Imported from old osu: BeatmapDirectory, diff --git a/osu.Game/Database/BeatmapDatabase.cs b/osu.Game/Database/BeatmapDatabase.cs index 41ddd8df39..0e814dea82 100644 --- a/osu.Game/Database/BeatmapDatabase.cs +++ b/osu.Game/Database/BeatmapDatabase.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; -using System.Linq.Expressions; using osu.Framework.Extensions; using osu.Framework.Logging; using osu.Framework.Platform; @@ -18,37 +17,21 @@ using SQLiteNetExtensions.Extensions; namespace osu.Game.Database { - public class BeatmapDatabase + public class BeatmapDatabase : Database { - private SQLiteConnection connection { get; } - private readonly Storage storage; + private readonly RulesetDatabase rulesets; + public event Action BeatmapSetAdded; public event Action BeatmapSetRemoved; // ReSharper disable once NotAccessedField.Local (we should keep a reference to this so it is not finalised) private BeatmapIPCChannel ipc; - public BeatmapDatabase(Storage storage, IIpcHost importHost = null) + public BeatmapDatabase(Storage storage, SQLiteConnection connection, RulesetDatabase rulesets, IIpcHost importHost = null) : base(storage, connection) { - this.storage = storage; - + this.rulesets = rulesets; if (importHost != null) ipc = new BeatmapIPCChannel(importHost, this); - - if (connection == null) - { - try - { - connection = prepareConnection(); - deletePending(); - } - catch (Exception e) - { - Logger.Error(e, @"Failed to initialise the beatmap database! Trying again with a clean database..."); - storage.DeleteDatabase(@"beatmaps"); - connection = prepareConnection(); - } - } } private void deletePending() @@ -57,20 +40,20 @@ namespace osu.Game.Database { try { - storage.Delete(b.Path); + Storage.Delete(b.Path); GetChildren(b, true); foreach (var i in b.Beatmaps) { - if (i.Metadata != null) connection.Delete(i.Metadata); - if (i.Difficulty != null) connection.Delete(i.Difficulty); + if (i.Metadata != null) Connection.Delete(i.Metadata); + if (i.Difficulty != null) Connection.Delete(i.Difficulty); - connection.Delete(i); + Connection.Delete(i); } - if (b.Metadata != null) connection.Delete(b.Metadata); - connection.Delete(b); + if (b.Metadata != null) Connection.Delete(b.Metadata); + Connection.Delete(b); } catch (Exception e) { @@ -80,42 +63,41 @@ namespace osu.Game.Database //this is required because sqlite migrations don't work, initially inserting nulls into this field. //see https://github.com/praeclarum/sqlite-net/issues/326 - connection.Query("UPDATE BeatmapSetInfo SET DeletePending = 0 WHERE DeletePending IS NULL"); + Connection.Query("UPDATE BeatmapSetInfo SET DeletePending = 0 WHERE DeletePending IS NULL"); } - private SQLiteConnection prepareConnection() + protected override void Prepare(bool reset = false) { - var conn = storage.GetDatabase(@"beatmaps"); + Connection.CreateTable(); + Connection.CreateTable(); + Connection.CreateTable(); + Connection.CreateTable(); - try + if (reset) { - conn.CreateTable(); - conn.CreateTable(); - conn.CreateTable(); - conn.CreateTable(); - } - catch - { - conn.Close(); - throw; + Storage.DeleteDatabase(@"beatmaps"); + + foreach (var setInfo in Query()) + { + if (Storage.Exists(setInfo.Path)) + Storage.Delete(setInfo.Path); + } + + Connection.DeleteAll(); + Connection.DeleteAll(); + Connection.DeleteAll(); + Connection.DeleteAll(); } - return conn; + deletePending(); } - public void Reset() - { - foreach (var setInfo in Query()) - { - if (storage.Exists(setInfo.Path)) - storage.Delete(setInfo.Path); - } - - connection.DeleteAll(); - connection.DeleteAll(); - connection.DeleteAll(); - connection.DeleteAll(); - } + protected override Type[] ValidTypes => new[] { + typeof(BeatmapSetInfo), + typeof(BeatmapInfo), + typeof(BeatmapMetadata), + typeof(BeatmapDifficulty), + }; /// /// Import multiple from . @@ -174,7 +156,7 @@ namespace osu.Game.Database BeatmapMetadata metadata; - using (var reader = ArchiveReader.GetReader(storage, path)) + using (var reader = ArchiveReader.GetReader(Storage, path)) { using (var stream = new StreamReader(reader.GetStream(reader.BeatmapFilenames[0]))) metadata = BeatmapDecoder.GetDecoder(stream).Decode(stream).Metadata; @@ -182,18 +164,18 @@ namespace osu.Game.Database if (File.Exists(path)) // Not always the case, i.e. for LegacyFilesystemReader { - using (var input = storage.GetStream(path)) + using (var input = Storage.GetStream(path)) { hash = input.GetMd5Hash(); input.Seek(0, SeekOrigin.Begin); path = Path.Combine(@"beatmaps", hash.Remove(1), hash.Remove(2), hash); - if (!storage.Exists(path)) - using (var output = storage.GetStream(path, FileAccess.Write)) + if (!Storage.Exists(path)) + using (var output = Storage.GetStream(path, FileAccess.Write)) input.CopyTo(output); } } - var existing = connection.Table().FirstOrDefault(b => b.Hash == hash); + var existing = Connection.Table().FirstOrDefault(b => b.Hash == hash); if (existing != null) { @@ -216,7 +198,7 @@ namespace osu.Game.Database Metadata = metadata }; - using (var archive = ArchiveReader.GetReader(storage, path)) + using (var archive = ArchiveReader.GetReader(Storage, path)) { string[] mapNames = archive.BeatmapFilenames; foreach (var name in mapNames) @@ -236,7 +218,9 @@ namespace osu.Game.Database // TODO: Diff beatmap metadata with set metadata and leave it here if necessary beatmap.BeatmapInfo.Metadata = null; - beatmap.BeatmapInfo.StarDifficulty = beatmap.CalculateStarDifficulty(); + // TODO: this should be done in a better place once we actually need to dynamically update it. + beatmap.BeatmapInfo.Ruleset = rulesets.Query().FirstOrDefault(r => r.ID == beatmap.BeatmapInfo.RulesetID); + beatmap.BeatmapInfo.StarDifficulty = rulesets.Query().FirstOrDefault(r => r.ID == beatmap.BeatmapInfo.RulesetID)?.CreateInstance()?.CreateDifficultyCalculator(beatmap).Calculate() ?? 0; beatmapSet.Beatmaps.Add(beatmap.BeatmapInfo); } @@ -248,17 +232,17 @@ namespace osu.Game.Database public void Import(IEnumerable beatmapSets) { - lock (connection) + lock (Connection) { - connection.BeginTransaction(); + Connection.BeginTransaction(); foreach (var s in beatmapSets) { - connection.InsertWithChildren(s, true); + Connection.InsertOrReplaceWithChildren(s, true); BeatmapSetAdded?.Invoke(s); } - connection.Commit(); + Connection.Commit(); } } @@ -275,7 +259,7 @@ namespace osu.Game.Database if (string.IsNullOrEmpty(beatmapSet.Path)) return null; - return ArchiveReader.GetReader(storage, beatmapSet.Path); + return ArchiveReader.GetReader(Storage, beatmapSet.Path); } public BeatmapSetInfo GetBeatmapSet(int id) @@ -287,12 +271,14 @@ namespace osu.Game.Database { var beatmapSetInfo = Query().FirstOrDefault(s => s.ID == beatmapInfo.BeatmapSetInfoID); - //we need metadata - GetChildren(beatmapSetInfo); - if (beatmapSetInfo == null) throw new InvalidOperationException($@"Beatmap set {beatmapInfo.BeatmapSetInfoID} is not in the local database."); + //we need metadata + GetChildren(beatmapSetInfo); + //we also need a ruleset + GetChildren(beatmapInfo); + if (beatmapInfo.Metadata == null) beatmapInfo.Metadata = beatmapSetInfo.Metadata; @@ -303,47 +289,6 @@ namespace osu.Game.Database return working; } - public TableQuery Query() where T : class - { - return connection.Table(); - } - - public T GetWithChildren(object id) where T : class - { - return connection.GetWithChildren(id); - } - - public List GetAllWithChildren(Expression> filter = null, bool recursive = true) - where T : class - { - return connection.GetAllWithChildren(filter, recursive); - } - - public T GetChildren(T item, bool recursive = false) - { - if (item == null) return default(T); - - connection.GetChildren(item, recursive); - return item; - } - - private readonly Type[] validTypes = { - typeof(BeatmapSetInfo), - typeof(BeatmapInfo), - typeof(BeatmapMetadata), - typeof(BeatmapDifficulty), - }; - - public void Update(T record, bool cascade = true) where T : class - { - if (validTypes.All(t => t != typeof(T))) - throw new ArgumentException("Must be a type managed by BeatmapDatabase", nameof(T)); - if (cascade) - connection.UpdateWithChildren(record); - else - connection.Update(record); - } - - public bool Exists(BeatmapSetInfo beatmapSet) => storage.Exists(beatmapSet.Path); + public bool Exists(BeatmapSetInfo beatmapSet) => Storage.Exists(beatmapSet.Path); } } diff --git a/osu.Game/Database/BeatmapInfo.cs b/osu.Game/Database/BeatmapInfo.cs index 3e84825919..5097622deb 100644 --- a/osu.Game/Database/BeatmapInfo.cs +++ b/osu.Game/Database/BeatmapInfo.cs @@ -3,7 +3,6 @@ using Newtonsoft.Json; using osu.Game.IO.Serialization; -using osu.Game.Modes; using SQLite.Net.Attributes; using SQLiteNetExtensions.Attributes; using System; @@ -54,7 +53,13 @@ namespace osu.Game.Database public bool Countdown { get; set; } public float StackLeniency { get; set; } public bool SpecialStyle { get; set; } - public PlayMode Mode { get; set; } + + [ForeignKey(typeof(RulesetInfo))] + public int RulesetID { get; set; } + + [OneToOne(CascadeOperations = CascadeOperation.All)] + public RulesetInfo Ruleset { get; set; } + public bool LetterboxInBreaks { get; set; } public bool WidescreenStoryboard { get; set; } diff --git a/osu.Game/Database/BeatmapSetInfo.cs b/osu.Game/Database/BeatmapSetInfo.cs index 0ef0ba4c63..0875d3c01f 100644 --- a/osu.Game/Database/BeatmapSetInfo.cs +++ b/osu.Game/Database/BeatmapSetInfo.cs @@ -26,6 +26,7 @@ namespace osu.Game.Database public double MaxStarDifficulty => Beatmaps.Max(b => b.StarDifficulty); + [Indexed] public bool DeletePending { get; set; } public string Hash { get; set; } diff --git a/osu.Game/Database/Database.cs b/osu.Game/Database/Database.cs new file mode 100644 index 0000000000..23851b3b2e --- /dev/null +++ b/osu.Game/Database/Database.cs @@ -0,0 +1,82 @@ +// 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 System.Linq.Expressions; +using osu.Framework.Logging; +using osu.Framework.Platform; +using SQLite.Net; +using SQLiteNetExtensions.Extensions; + +namespace osu.Game.Database +{ + public abstract class Database + { + protected SQLiteConnection Connection { get; } + protected Storage Storage { get; } + + protected Database(Storage storage, SQLiteConnection connection) + { + Storage = storage; + Connection = connection; + + try + { + Prepare(); + } + catch (Exception e) + { + Logger.Error(e, $@"Failed to initialise the {GetType()}! Trying again with a clean database..."); + Prepare(true); + } + } + + /// + /// Prepare this database for use. + /// + protected abstract void Prepare(bool reset = false); + + /// + /// Reset this database to a default state. Undo all changes to database and storage backings. + /// + public void Reset() => Prepare(true); + + public TableQuery Query() where T : class + { + return Connection.Table(); + } + + public T GetWithChildren(object id) where T : class + { + return Connection.GetWithChildren(id); + } + + public List GetAllWithChildren(Expression> filter = null, bool recursive = true) + where T : class + { + return Connection.GetAllWithChildren(filter, recursive); + } + + public T GetChildren(T item, bool recursive = false) + { + if (item == null) return default(T); + + Connection.GetChildren(item, recursive); + return item; + } + + protected abstract Type[] ValidTypes { get; } + + public void Update(T record, bool cascade = true) where T : class + { + if (ValidTypes.All(t => t != typeof(T))) + throw new ArgumentException("Must be a type managed by BeatmapDatabase", nameof(T)); + if (cascade) + Connection.UpdateWithChildren(record); + else + Connection.Update(record); + } + } +} \ No newline at end of file diff --git a/osu.Game/Database/RulesetDatabase.cs b/osu.Game/Database/RulesetDatabase.cs new file mode 100644 index 0000000000..d19fe56345 --- /dev/null +++ b/osu.Game/Database/RulesetDatabase.cs @@ -0,0 +1,103 @@ +// 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.IO; +using System.Linq; +using System.Reflection; +using osu.Framework.Platform; +using osu.Game.Modes; +using SQLite.Net; + +namespace osu.Game.Database +{ + /// + /// Todo: All of this needs to be moved to a RulesetDatabase. + /// + public class RulesetDatabase : Database + { + public IEnumerable AllRulesets => Query().Where(r => r.Available); + + public RulesetDatabase(Storage storage, SQLiteConnection connection) + : base(storage, connection) + { + } + + protected override void Prepare(bool reset = false) + { + Connection.CreateTable(); + + if (reset) + { + Connection.DeleteAll(); + } + + List instances = new List(); + + foreach (string file in Directory.GetFiles(Environment.CurrentDirectory, @"osu.Game.Modes.*.dll")) + { + try + { + var assembly = Assembly.LoadFile(file); + var rulesets = assembly.GetTypes().Where(t => t.IsSubclassOf(typeof(Ruleset))); + + if (rulesets.Count() != 1) + continue; + + foreach (Type rulesetType in rulesets) + instances.Add((Ruleset)Activator.CreateInstance(rulesetType)); + } + catch (Exception) { } + } + + Connection.BeginTransaction(); + + //add all legacy modes in correct order + foreach (var r in instances.Where(r => r.LegacyID >= 0).OrderBy(r => r.LegacyID)) + { + Connection.InsertOrReplace(createRulesetInfo(r)); + } + + //add any other modes + foreach (var r in instances.Where(r => r.LegacyID < 0)) + { + var us = createRulesetInfo(r); + + var existing = Query().FirstOrDefault(ri => ri.InstantiationInfo == us.InstantiationInfo); + + if (existing == null) + Connection.Insert(us); + } + + //perform a consistency check + foreach (var r in Query()) + { + try + { + r.CreateInstance(); + r.Available = true; + } + catch + { + r.Available = false; + } + + Connection.Update(r); + } + + Connection.Commit(); + } + + private RulesetInfo createRulesetInfo(Ruleset ruleset) => new RulesetInfo + { + Name = ruleset.Description, + InstantiationInfo = ruleset.GetType().AssemblyQualifiedName, + ID = ruleset.LegacyID + }; + + protected override Type[] ValidTypes => new[] { typeof(RulesetInfo) }; + + public RulesetInfo GetRuleset(int id) => Query().First(r => r.ID == id); + } +} diff --git a/osu.Game/Database/RulesetInfo.cs b/osu.Game/Database/RulesetInfo.cs new file mode 100644 index 0000000000..c3c0d4343d --- /dev/null +++ b/osu.Game/Database/RulesetInfo.cs @@ -0,0 +1,26 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using System; +using osu.Game.Modes; +using SQLite.Net.Attributes; + +namespace osu.Game.Database +{ + public class RulesetInfo + { + [PrimaryKey, AutoIncrement] + public int? ID { get; set; } + + [Indexed(Unique = true)] + public string Name { get; set; } + + [Indexed(Unique = true)] + public string InstantiationInfo { get; set; } + + [Indexed] + public bool Available { get; set; } + + public Ruleset CreateInstance() => (Ruleset)Activator.CreateInstance(Type.GetType(InstantiationInfo)); + } +} \ No newline at end of file diff --git a/osu.Game/Database/ScoreDatabase.cs b/osu.Game/Database/ScoreDatabase.cs index 642bb4aff6..a2fff7f795 100644 --- a/osu.Game/Database/ScoreDatabase.cs +++ b/osu.Game/Database/ScoreDatabase.cs @@ -7,26 +7,29 @@ using System.Linq; using osu.Framework.Platform; using osu.Game.IO.Legacy; using osu.Game.IPC; -using osu.Game.Modes; using osu.Game.Modes.Scoring; using SharpCompress.Compressors.LZMA; +using SQLite.Net; namespace osu.Game.Database { - public class ScoreDatabase + public class ScoreDatabase : Database { private readonly Storage storage; + private readonly BeatmapDatabase beatmaps; + private readonly RulesetDatabase rulesets; private const string replay_folder = @"replays"; // ReSharper disable once NotAccessedField.Local (we should keep a reference to this so it is not finalised) private ScoreIPCChannel ipc; - public ScoreDatabase(Storage storage, IIpcHost importHost = null, BeatmapDatabase beatmaps = null) + public ScoreDatabase(Storage storage, SQLiteConnection connection, IIpcHost importHost = null, BeatmapDatabase beatmaps = null, RulesetDatabase rulesets = null) : base(storage, connection) { this.storage = storage; this.beatmaps = beatmaps; + this.rulesets = rulesets; if (importHost != null) ipc = new ScoreIPCChannel(importHost, this); @@ -39,7 +42,7 @@ namespace osu.Game.Database using (Stream s = storage.GetStream(Path.Combine(replay_folder, replayFilename))) using (SerializationReader sr = new SerializationReader(s)) { - var ruleset = Ruleset.GetRuleset((PlayMode)sr.ReadByte()); + var ruleset = rulesets.GetRuleset(sr.ReadByte()).CreateInstance(); score = ruleset.CreateScoreProcessor().CreateScore(); /* score.Pass = true;*/ @@ -107,5 +110,11 @@ namespace osu.Game.Database return score; } + + protected override void Prepare(bool reset = false) + { + } + + protected override Type[] ValidTypes => new[] { typeof(Score) }; } } diff --git a/osu.Game/Modes/PlayMode.cs b/osu.Game/Modes/BeatmapStatistic.cs similarity index 53% rename from osu.Game/Modes/PlayMode.cs rename to osu.Game/Modes/BeatmapStatistic.cs index fa6d94a650..d598b81ff4 100644 --- a/osu.Game/Modes/PlayMode.cs +++ b/osu.Game/Modes/BeatmapStatistic.cs @@ -1,13 +1,14 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using osu.Game.Graphics; + namespace osu.Game.Modes { - public enum PlayMode + public class BeatmapStatistic { - Osu = 0, - Taiko = 1, - Catch = 2, - Mania = 3 + public FontAwesome Icon; + public string Content; + public string Name; } -} +} \ No newline at end of file diff --git a/osu.Game/Modes/Ruleset.cs b/osu.Game/Modes/Ruleset.cs index c97420fbe3..cf0fbe5b6a 100644 --- a/osu.Game/Modes/Ruleset.cs +++ b/osu.Game/Modes/Ruleset.cs @@ -6,26 +6,13 @@ using osu.Game.Graphics; using osu.Game.Modes.Mods; using osu.Game.Modes.UI; using osu.Game.Screens.Play; -using System; -using System.Collections.Concurrent; using System.Collections.Generic; using osu.Game.Modes.Scoring; namespace osu.Game.Modes { - public class BeatmapStatistic - { - public FontAwesome Icon; - public string Content; - public string Name; - } - public abstract class Ruleset { - private static readonly ConcurrentDictionary available_rulesets = new ConcurrentDictionary(); - - public static IEnumerable PlayModes => available_rulesets.Keys; - public virtual IEnumerable GetBeatmapStatistics(WorkingBeatmap beatmap) => new BeatmapStatistic[] { }; public abstract IEnumerable GetModsFor(ModType type); @@ -36,25 +23,15 @@ namespace osu.Game.Modes public abstract ScoreProcessor CreateScoreProcessor(); - public static void Register(Ruleset ruleset) => available_rulesets.TryAdd(ruleset.PlayMode, ruleset.GetType()); - - protected abstract PlayMode PlayMode { get; } - public virtual FontAwesome Icon => FontAwesome.fa_question_circle; public abstract string Description { get; } public abstract IEnumerable CreateGameplayKeys(); - public static Ruleset GetRuleset(PlayMode mode) - { - Type type; - - if (!available_rulesets.TryGetValue(mode, out type)) - return null; - - return Activator.CreateInstance(type) as Ruleset; - } - + /// + /// Do not override this unless you are a legacy mode. + /// + public virtual int LegacyID => -1; } } diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index ccea6ef458..1006008afc 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -15,7 +15,6 @@ using osu.Framework.Logging; using osu.Game.Graphics.UserInterface.Volume; using osu.Framework.Allocation; using osu.Framework.Timing; -using osu.Game.Modes; using osu.Game.Overlays.Toolbar; using osu.Game.Screens; using osu.Game.Screens.Menu; @@ -24,6 +23,7 @@ using System.Linq; using osu.Framework.Graphics.Primitives; using System.Threading.Tasks; using osu.Framework.Threading; +using osu.Game.Database; using osu.Game.Graphics; using osu.Game.Modes.Scoring; using osu.Game.Overlays.Notifications; @@ -58,7 +58,8 @@ namespace osu.Game private VolumeControl volume; - public Bindable PlayMode; + private Bindable configRuleset; + public Bindable Ruleset = new Bindable(); private readonly string[] args; @@ -88,7 +89,9 @@ namespace osu.Game Dependencies.Cache(this); - PlayMode = LocalConfig.GetBindable(OsuConfig.PlayMode); + configRuleset = LocalConfig.GetBindable(OsuConfig.Ruleset); + Ruleset.Value = RulesetDatabase.GetRuleset(configRuleset.Value); + Ruleset.ValueChanged += r => configRuleset.Value = r.ID ?? 0; } private ScheduledDelegate scoreLoad; @@ -199,11 +202,11 @@ namespace osu.Game { Depth = -3, OnHome = delegate { intro?.ChildScreen?.MakeCurrent(); }, - OnPlayModeChange = m => PlayMode.Value = m, + OnRulesetChange = r => Ruleset.Value = r, }, t => { - PlayMode.ValueChanged += delegate { Toolbar.SetGameMode(PlayMode.Value); }; - PlayMode.TriggerChange(); + Ruleset.ValueChanged += delegate { Toolbar.SetGameMode(Ruleset.Value); }; + Ruleset.TriggerChange(); overlayContent.Add(Toolbar); }); diff --git a/osu.Game/OsuGameBase.cs b/osu.Game/OsuGameBase.cs index f95e8c3ac6..371699eab3 100644 --- a/osu.Game/OsuGameBase.cs +++ b/osu.Game/OsuGameBase.cs @@ -18,6 +18,7 @@ using osu.Game.Graphics; using osu.Game.Graphics.Cursor; using osu.Game.Graphics.Processing; using osu.Game.Online.API; +using SQLite.Net; namespace osu.Game { @@ -27,6 +28,8 @@ namespace osu.Game protected BeatmapDatabase BeatmapDatabase; + protected RulesetDatabase RulesetDatabase; + protected ScoreDatabase ScoreDatabase; protected override string MainResourceFile => @"osu.Game.Resources.dll"; @@ -80,8 +83,12 @@ namespace osu.Game { Dependencies.Cache(this); Dependencies.Cache(LocalConfig); - Dependencies.Cache(BeatmapDatabase = new BeatmapDatabase(Host.Storage, Host)); - Dependencies.Cache(ScoreDatabase = new ScoreDatabase(Host.Storage, Host, BeatmapDatabase)); + + SQLiteConnection connection = Host.Storage.GetDatabase(@"client"); + + Dependencies.Cache(RulesetDatabase = new RulesetDatabase(Host.Storage, connection)); + Dependencies.Cache(BeatmapDatabase = new BeatmapDatabase(Host.Storage, connection, RulesetDatabase, Host)); + Dependencies.Cache(ScoreDatabase = new ScoreDatabase(Host.Storage, connection, Host, BeatmapDatabase)); Dependencies.Cache(new OsuColour()); //this completely overrides the framework default. will need to change once we make a proper FontStore. diff --git a/osu.Game/Overlays/Mods/ModSelectOverlay.cs b/osu.Game/Overlays/Mods/ModSelectOverlay.cs index 2b9f8e86a9..bf7117edf1 100644 --- a/osu.Game/Overlays/Mods/ModSelectOverlay.cs +++ b/osu.Game/Overlays/Mods/ModSelectOverlay.cs @@ -13,11 +13,11 @@ using osu.Framework.Graphics.Sprites; using osu.Game.Graphics; using osu.Game.Graphics.Backgrounds; using osu.Game.Graphics.Sprites; -using osu.Game.Modes; using osu.Game.Modes.Mods; using System; using System.Collections.Generic; using System.Linq; +using osu.Game.Database; namespace osu.Game.Overlays.Mods { @@ -37,26 +37,30 @@ namespace osu.Game.Overlays.Mods public readonly Bindable> SelectedMods = new Bindable>(); - public readonly Bindable PlayMode = new Bindable(); + public readonly Bindable Ruleset = new Bindable(); - private void modeChanged(PlayMode newMode) + private void rulesetChanged(RulesetInfo newRuleset) { - var ruleset = Ruleset.GetRuleset(newMode); + var instance = newRuleset.CreateInstance(); + foreach (ModSection section in modSectionsContainer.Children) - section.Buttons = ruleset.GetModsFor(section.ModType).Select(m => new ModButton(m)).ToArray(); + section.Buttons = instance.GetModsFor(section.ModType).Select(m => new ModButton(m)).ToArray(); refreshSelectedMods(); } [BackgroundDependencyLoader(permitNulls: true)] - private void load(OsuColour colours, OsuGame osu) + private void load(OsuColour colours, OsuGame osu, RulesetDatabase rulesets) { lowMultiplierColour = colours.Red; highMultiplierColour = colours.Green; if (osu != null) - PlayMode.BindTo(osu.PlayMode); - PlayMode.ValueChanged += modeChanged; - PlayMode.TriggerChange(); + Ruleset.BindTo(osu.Ruleset); + else + Ruleset.Value = rulesets.AllRulesets.First(); + + Ruleset.ValueChanged += rulesetChanged; + Ruleset.TriggerChange(); } protected override void PopOut() diff --git a/osu.Game/Overlays/Options/OptionsFooter.cs b/osu.Game/Overlays/Options/OptionsFooter.cs index c42fe42428..c785f2d0c0 100644 --- a/osu.Game/Overlays/Options/OptionsFooter.cs +++ b/osu.Game/Overlays/Options/OptionsFooter.cs @@ -1,15 +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 osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Primitives; +using osu.Game.Database; using osu.Game.Graphics; using osu.Game.Graphics.Sprites; -using osu.Game.Modes; using OpenTK; using OpenTK.Graphics; @@ -18,7 +17,7 @@ namespace osu.Game.Overlays.Options public class OptionsFooter : FillFlowContainer { [BackgroundDependencyLoader] - private void load(OsuGameBase game, OsuColour colours) + private void load(OsuGameBase game, OsuColour colours, RulesetDatabase rulesets) { RelativeSizeAxes = Axes.X; AutoSizeAxes = Axes.Y; @@ -27,13 +26,15 @@ namespace osu.Game.Overlays.Options var modes = new List(); - foreach (PlayMode m in Enum.GetValues(typeof(PlayMode))) + foreach (var ruleset in rulesets.AllRulesets) + { modes.Add(new TextAwesome { - Icon = Ruleset.GetRuleset(m).Icon, + Icon = ruleset.CreateInstance().Icon, Colour = Color4.Gray, TextSize = 20 }); + } Children = new Drawable[] { diff --git a/osu.Game/Overlays/Toolbar/Toolbar.cs b/osu.Game/Overlays/Toolbar/Toolbar.cs index 9e7b4f1519..4632b55775 100644 --- a/osu.Game/Overlays/Toolbar/Toolbar.cs +++ b/osu.Game/Overlays/Toolbar/Toolbar.cs @@ -8,8 +8,8 @@ using osu.Framework.Graphics.Colour; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Sprites; using osu.Framework.Input; +using osu.Game.Database; using osu.Game.Graphics; -using osu.Game.Modes; using OpenTK; namespace osu.Game.Overlays.Toolbar @@ -20,7 +20,7 @@ namespace osu.Game.Overlays.Toolbar public const float TOOLTIP_HEIGHT = 30; public Action OnHome; - public Action OnPlayModeChange; + public Action OnRulesetChange; private readonly ToolbarModeSelector modeSelector; private readonly ToolbarUserArea userArea; @@ -55,9 +55,9 @@ namespace osu.Game.Overlays.Toolbar }, modeSelector = new ToolbarModeSelector { - OnPlayModeChange = mode => + OnRulesetChange = mode => { - OnPlayModeChange?.Invoke(mode); + OnRulesetChange?.Invoke(mode); } } } @@ -129,7 +129,7 @@ namespace osu.Game.Overlays.Toolbar } } - public void SetGameMode(PlayMode mode) => modeSelector.SetGameMode(mode); + public void SetGameMode(RulesetInfo ruleset) => modeSelector.SetGameMode(ruleset); protected override void PopIn() { diff --git a/osu.Game/Overlays/Toolbar/ToolbarModeButton.cs b/osu.Game/Overlays/Toolbar/ToolbarModeButton.cs index 62359b05ae..dd70289f7d 100644 --- a/osu.Game/Overlays/Toolbar/ToolbarModeButton.cs +++ b/osu.Game/Overlays/Toolbar/ToolbarModeButton.cs @@ -2,23 +2,26 @@ // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using osu.Framework.Graphics.Containers; -using osu.Game.Modes; +using osu.Game.Database; using OpenTK.Graphics; namespace osu.Game.Overlays.Toolbar { public class ToolbarModeButton : ToolbarButton { - private PlayMode mode; - public PlayMode Mode + private RulesetInfo ruleset; + public RulesetInfo Ruleset { - get { return mode; } + get { return ruleset; } set { - mode = value; - TooltipMain = Ruleset.GetRuleset(mode).Description; - TooltipSub = $"Play some {Ruleset.GetRuleset(mode).Description}"; - Icon = Ruleset.GetRuleset(mode).Icon; + ruleset = value; + + var rInstance = ruleset.CreateInstance(); + + TooltipMain = rInstance.Description; + TooltipSub = $"Play some {rInstance.Description}"; + Icon = rInstance.Icon; } } diff --git a/osu.Game/Overlays/Toolbar/ToolbarModeSelector.cs b/osu.Game/Overlays/Toolbar/ToolbarModeSelector.cs index e117089166..e4c9db7c5d 100644 --- a/osu.Game/Overlays/Toolbar/ToolbarModeSelector.cs +++ b/osu.Game/Overlays/Toolbar/ToolbarModeSelector.cs @@ -3,12 +3,13 @@ using System; using System.Linq; +using osu.Framework.Allocation; using osu.Framework.Caching; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Primitives; using osu.Framework.Graphics.Sprites; -using osu.Game.Modes; +using osu.Game.Database; using OpenTK; using OpenTK.Graphics; @@ -22,7 +23,7 @@ namespace osu.Game.Overlays.Toolbar private readonly Drawable modeButtonLine; private ToolbarModeButton activeButton; - public Action OnPlayModeChange; + public Action OnRulesetChange; public ToolbarModeSelector() { @@ -62,16 +63,20 @@ namespace osu.Game.Overlays.Toolbar } } }; + } - foreach (PlayMode m in Ruleset.PlayModes) + [BackgroundDependencyLoader] + private void load(RulesetDatabase rulesets) + { + foreach (var ruleset in rulesets.AllRulesets) { modeButtons.Add(new ToolbarModeButton { - Mode = m, + Ruleset = ruleset, Action = delegate { - SetGameMode(m); - OnPlayModeChange?.Invoke(m); + SetGameMode(ruleset); + OnRulesetChange?.Invoke(ruleset); } }); } @@ -84,11 +89,11 @@ namespace osu.Game.Overlays.Toolbar Size = new Vector2(modeButtons.DrawSize.X, 1); } - public void SetGameMode(PlayMode mode) + public void SetGameMode(RulesetInfo ruleset) { foreach (ToolbarModeButton m in modeButtons.Children.Cast()) { - bool isActive = m.Mode == mode; + bool isActive = m.Ruleset.ID == ruleset.ID; m.Active = isActive; if (isActive) activeButton = m; diff --git a/osu.Game/Screens/Play/Player.cs b/osu.Game/Screens/Play/Player.cs index fa564cdd61..b32548c31a 100644 --- a/osu.Game/Screens/Play/Player.cs +++ b/osu.Game/Screens/Play/Player.cs @@ -63,13 +63,6 @@ namespace osu.Game.Screens.Play [BackgroundDependencyLoader] private void load(AudioManager audio, BeatmapDatabase beatmaps, OsuConfigManager config) { - if (Beatmap.Beatmap.BeatmapInfo?.Mode > PlayMode.Taiko) - { - //we only support osu! mode for now because the hitobject parsing is crappy and needs a refactor. - Exit(); - return; - } - dimLevel = config.GetBindable(OsuConfig.DimLevel); mouseWheelDisabled = config.GetBindable(OsuConfig.MouseDisableWheel); @@ -109,7 +102,10 @@ namespace osu.Game.Screens.Play sourceClock.Reset(); }); - ruleset = Ruleset.GetRuleset(Beatmap.PlayMode); + ruleset = Beatmap.BeatmapInfo.Ruleset.CreateInstance(); + + // Todo: This should be done as early as possible, and should check if the hit renderer + // can actually convert the hit objects... Somehow... HitRenderer = ruleset.CreateHitRendererWith(Beatmap); scoreProcessor = HitRenderer.CreateScoreProcessor(); diff --git a/osu.Game/Screens/Select/BeatmapCarousel.cs b/osu.Game/Screens/Select/BeatmapCarousel.cs index f104bf9a37..06aaea041a 100644 --- a/osu.Game/Screens/Select/BeatmapCarousel.cs +++ b/osu.Game/Screens/Select/BeatmapCarousel.cs @@ -145,7 +145,7 @@ namespace osu.Game.Screens.Select } } - int startIndex = groups.IndexOf(selectedGroup); + int startIndex = Math.Max(0, groups.IndexOf(selectedGroup)); int index = startIndex; do @@ -221,7 +221,12 @@ namespace osu.Game.Screens.Select private BeatmapGroup createGroup(BeatmapSetInfo beatmapSet) { database.GetChildren(beatmapSet); - beatmapSet.Beatmaps.ForEach(b => { if (b.Metadata == null) b.Metadata = beatmapSet.Metadata; }); + beatmapSet.Beatmaps.ForEach(b => + { + database.GetChildren(b); + if (b.Metadata == null) + b.Metadata = beatmapSet.Metadata; + }); return new BeatmapGroup(beatmapSet, database) { diff --git a/osu.Game/Screens/Select/BeatmapInfoWedge.cs b/osu.Game/Screens/Select/BeatmapInfoWedge.cs index ac1f1837b7..d15e5a9bb8 100644 --- a/osu.Game/Screens/Select/BeatmapInfoWedge.cs +++ b/osu.Game/Screens/Select/BeatmapInfoWedge.cs @@ -102,7 +102,7 @@ namespace osu.Game.Screens.Select })); //get statistics fromt he current ruleset. - labels.AddRange(Ruleset.GetRuleset(beatmap.BeatmapInfo.Mode).GetBeatmapStatistics(beatmap).Select(s => new InfoLabel(s))); + labels.AddRange(beatmap.BeatmapInfo.Ruleset.CreateInstance().GetBeatmapStatistics(beatmap).Select(s => new InfoLabel(s))); } AlwaysPresent = true; diff --git a/osu.Game/Screens/Select/FilterControl.cs b/osu.Game/Screens/Select/FilterControl.cs index 7596af1484..e0b197e9ca 100644 --- a/osu.Game/Screens/Select/FilterControl.cs +++ b/osu.Game/Screens/Select/FilterControl.cs @@ -16,7 +16,7 @@ using osu.Game.Graphics.UserInterface; using osu.Game.Screens.Select.Filter; using Container = osu.Framework.Graphics.Containers.Container; using osu.Framework.Input; -using osu.Game.Modes; +using osu.Game.Database; namespace osu.Game.Screens.Select { @@ -61,7 +61,7 @@ namespace osu.Game.Screens.Select Group = group, Sort = sort, SearchText = searchTextBox.Text, - Mode = playMode + Ruleset = ruleset }; public Action Exit; @@ -163,16 +163,17 @@ namespace osu.Game.Screens.Select searchTextBox.HoldFocus = true; } - private readonly Bindable playMode = new Bindable(); + private readonly Bindable ruleset = new Bindable(); [BackgroundDependencyLoader(permitNulls:true)] private void load(OsuColour colours, OsuGame osu) { sortTabs.AccentColour = colours.GreenLight; - if (osu != null) playMode.BindTo(osu.PlayMode); - playMode.ValueChanged += val => FilterChanged?.Invoke(CreateCriteria()); - playMode.TriggerChange(); + if (osu != null) + ruleset.BindTo(osu.Ruleset); + ruleset.ValueChanged += val => FilterChanged?.Invoke(CreateCriteria()); + ruleset.TriggerChange(); } protected override bool OnMouseDown(InputState state, MouseDownEventArgs args) => true; diff --git a/osu.Game/Screens/Select/FilterCriteria.cs b/osu.Game/Screens/Select/FilterCriteria.cs index 2654129a44..d49c7296ba 100644 --- a/osu.Game/Screens/Select/FilterCriteria.cs +++ b/osu.Game/Screens/Select/FilterCriteria.cs @@ -5,7 +5,7 @@ using System; using System.Collections.Generic; using System.Linq; using osu.Game.Beatmaps.Drawables; -using osu.Game.Modes; +using osu.Game.Database; using osu.Game.Screens.Select.Filter; namespace osu.Game.Screens.Select @@ -15,7 +15,7 @@ namespace osu.Game.Screens.Select public GroupMode Group; public SortMode Sort; public string SearchText; - public PlayMode Mode; + public RulesetInfo Ruleset; public void Filter(List groups) { @@ -23,7 +23,7 @@ namespace osu.Game.Screens.Select { var set = g.BeatmapSet; - bool hasCurrentMode = set.Beatmaps.Any(bm => bm.Mode == Mode); + bool hasCurrentMode = set.Beatmaps.Any(bm => bm.RulesetID == (Ruleset?.ID ?? 0)); bool match = hasCurrentMode; diff --git a/osu.Game/Screens/Select/SongSelect.cs b/osu.Game/Screens/Select/SongSelect.cs index 3e8ddc0f64..182158fa5d 100644 --- a/osu.Game/Screens/Select/SongSelect.cs +++ b/osu.Game/Screens/Select/SongSelect.cs @@ -20,7 +20,6 @@ using osu.Game.Beatmaps.Drawables; using osu.Game.Database; using osu.Game.Graphics; using osu.Game.Graphics.Containers; -using osu.Game.Modes; using osu.Game.Overlays; using osu.Game.Screens.Backgrounds; using osu.Game.Screens.Select.Options; @@ -29,7 +28,7 @@ namespace osu.Game.Screens.Select { public abstract class SongSelect : OsuScreen { - private readonly Bindable playMode = new Bindable(); + private readonly Bindable ruleset = new Bindable(); private BeatmapDatabase database; protected override BackgroundScreen CreateBackground() => new BackgroundScreenBeatmap(Beatmap); @@ -170,8 +169,8 @@ namespace osu.Game.Screens.Select if (database == null) database = beatmaps; - playMode.ValueChanged += val => { if (Beatmap != null) Beatmap.PreferredPlayMode = val; }; - if (osu != null) playMode.BindTo(osu.PlayMode); + if (osu != null) + ruleset.BindTo(osu.Ruleset); database.BeatmapSetAdded += onBeatmapSetAdded; database.BeatmapSetRemoved += onBeatmapSetRemoved; @@ -200,7 +199,6 @@ namespace osu.Game.Screens.Select { if (Beatmap == null) return; - Beatmap.PreferredPlayMode = playMode.Value; OnSelected(); } diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index d73e6d0b61..193c2c1179 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -78,6 +78,8 @@ + + @@ -101,6 +103,7 @@ + @@ -132,6 +135,7 @@ + @@ -217,7 +221,6 @@ -