1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-12 16:42:55 +08:00

Merge pull request #640 from smoogipooo/remove-playmode

Remove PlayMode enum and make Rulesets modular
This commit is contained in:
Dan Balasescu 2017-04-18 11:21:02 +09:00 committed by GitHub
commit 1df3189e5d
42 changed files with 455 additions and 316 deletions

View File

@ -4,11 +4,6 @@
using NUnit.Framework; using NUnit.Framework;
using osu.Desktop.VisualTests; using osu.Desktop.VisualTests;
using osu.Framework.Desktop.Platform; 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 namespace osu.Desktop.Tests
{ {
@ -20,11 +15,6 @@ namespace osu.Desktop.Tests
{ {
using (var host = new HeadlessGameHost()) 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()); host.Run(new AutomatedVisualTestGame());
} }
} }

View File

@ -4,11 +4,6 @@
using System; using System;
using osu.Framework.Desktop; using osu.Framework.Desktop;
using osu.Framework.Platform; 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 namespace osu.Desktop.VisualTests
{ {
@ -21,11 +16,6 @@ namespace osu.Desktop.VisualTests
using (GameHost host = Host.GetSuitableHost(@"osu")) using (GameHost host = Host.GetSuitableHost(@"osu"))
{ {
Ruleset.Register(new OsuRuleset());
Ruleset.Register(new TaikoRuleset());
Ruleset.Register(new ManiaRuleset());
Ruleset.Register(new CatchRuleset());
if (benchmark) if (benchmark)
host.Run(new AutomatedVisualTestGame()); host.Run(new AutomatedVisualTestGame());
else else

View File

@ -17,13 +17,22 @@ using osu.Game.Modes.Osu.UI;
using osu.Game.Modes.Taiko.UI; using osu.Game.Modes.Taiko.UI;
using System.Collections.Generic; using System.Collections.Generic;
using osu.Desktop.VisualTests.Beatmaps; using osu.Desktop.VisualTests.Beatmaps;
using osu.Framework.Allocation;
namespace osu.Desktop.VisualTests.Tests namespace osu.Desktop.VisualTests.Tests
{ {
internal class TestCaseGamefield : TestCase internal class TestCaseGamefield : TestCase
{ {
private RulesetDatabase rulesets;
public override string Description => @"Showing hitobjects and what not."; public override string Description => @"Showing hitobjects and what not.";
[BackgroundDependencyLoader]
private void load(RulesetDatabase rulesets)
{
this.rulesets = rulesets;
}
public override void Reset() public override void Reset()
{ {
base.Reset(); base.Reset();
@ -49,6 +58,7 @@ namespace osu.Desktop.VisualTests.Tests
BeatmapInfo = new BeatmapInfo BeatmapInfo = new BeatmapInfo
{ {
Difficulty = new BeatmapDifficulty(), Difficulty = new BeatmapDifficulty(),
Ruleset = rulesets.Query<RulesetInfo>().First(),
Metadata = new BeatmapMetadata Metadata = new BeatmapMetadata
{ {
Artist = @"Unknown", Artist = @"Unknown",

View File

@ -1,10 +1,11 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>. // Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Allocation;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Game.Overlays.Mods; using osu.Game.Overlays.Mods;
using osu.Framework.Testing; using osu.Framework.Testing;
using osu.Game.Modes; using osu.Game.Database;
namespace osu.Desktop.VisualTests.Tests namespace osu.Desktop.VisualTests.Tests
{ {
@ -13,6 +14,13 @@ namespace osu.Desktop.VisualTests.Tests
public override string Description => @"Tests the mod select overlay"; public override string Description => @"Tests the mod select overlay";
private ModSelectOverlay modSelect; private ModSelectOverlay modSelect;
private RulesetDatabase rulesets;
[BackgroundDependencyLoader]
private void load(RulesetDatabase rulesets)
{
this.rulesets = rulesets;
}
public override void Reset() public override void Reset()
{ {
@ -26,10 +34,9 @@ namespace osu.Desktop.VisualTests.Tests
}); });
AddStep("Toggle", modSelect.ToggleVisibility); AddStep("Toggle", modSelect.ToggleVisibility);
AddStep("osu!", () => modSelect.PlayMode.Value = PlayMode.Osu);
AddStep("osu!taiko", () => modSelect.PlayMode.Value = PlayMode.Taiko); foreach (var ruleset in rulesets.AllRulesets)
AddStep("osu!catch", () => modSelect.PlayMode.Value = PlayMode.Catch); AddStep(ruleset.CreateInstance().Description, () => modSelect.Ruleset.Value = ruleset);
AddStep("osu!mania", () => modSelect.PlayMode.Value = PlayMode.Mania);
} }
} }
} }

View File

@ -6,7 +6,6 @@ using osu.Desktop.VisualTests.Platform;
using osu.Framework.Testing; using osu.Framework.Testing;
using osu.Framework.MathUtils; using osu.Framework.MathUtils;
using osu.Game.Database; using osu.Game.Database;
using osu.Game.Modes;
using osu.Game.Screens.Select; using osu.Game.Screens.Select;
using osu.Game.Screens.Select.Filter; using osu.Game.Screens.Select.Filter;
@ -20,13 +19,19 @@ namespace osu.Desktop.VisualTests.Tests
public override string Description => @"with fake data"; public override string Description => @"with fake data";
private RulesetDatabase rulesets;
public override void Reset() public override void Reset()
{ {
base.Reset(); base.Reset();
if (db == null) if (db == null)
{ {
storage = new TestStorage(@"TestCasePlaySongSelect"); 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<BeatmapSetInfo>(); var sets = new List<BeatmapSetInfo>();
@ -72,7 +77,7 @@ namespace osu.Desktop.VisualTests.Tests
new BeatmapInfo new BeatmapInfo
{ {
OnlineBeatmapID = 1234 + i, OnlineBeatmapID = 1234 + i,
Mode = PlayMode.Osu, Ruleset = rulesets.Query<RulesetInfo>().First(),
Path = "normal.osu", Path = "normal.osu",
Version = "Normal", Version = "Normal",
Difficulty = new BeatmapDifficulty Difficulty = new BeatmapDifficulty
@ -83,7 +88,7 @@ namespace osu.Desktop.VisualTests.Tests
new BeatmapInfo new BeatmapInfo
{ {
OnlineBeatmapID = 1235 + i, OnlineBeatmapID = 1235 + i,
Mode = PlayMode.Osu, Ruleset = rulesets.Query<RulesetInfo>().First(),
Path = "hard.osu", Path = "hard.osu",
Version = "Hard", Version = "Hard",
Difficulty = new BeatmapDifficulty Difficulty = new BeatmapDifficulty
@ -94,7 +99,7 @@ namespace osu.Desktop.VisualTests.Tests
new BeatmapInfo new BeatmapInfo
{ {
OnlineBeatmapID = 1236 + i, OnlineBeatmapID = 1236 + i,
Mode = PlayMode.Osu, Ruleset = rulesets.Query<RulesetInfo>().First(),
Path = "insane.osu", Path = "insane.osu",
Version = "Insane", Version = "Insane",
Difficulty = new BeatmapDifficulty Difficulty = new BeatmapDifficulty

View File

@ -9,7 +9,6 @@ using osu.Game.Beatmaps;
using OpenTK; using OpenTK;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
using osu.Game.Database; using osu.Game.Database;
using osu.Game.Modes;
using osu.Game.Modes.Objects; using osu.Game.Modes.Objects;
using osu.Game.Modes.Osu.Objects; using osu.Game.Modes.Osu.Objects;
using osu.Game.Screens.Play; using osu.Game.Screens.Play;
@ -22,12 +21,14 @@ namespace osu.Desktop.VisualTests.Tests
{ {
protected Player Player; protected Player Player;
private BeatmapDatabase db; private BeatmapDatabase db;
private RulesetDatabase rulesets;
public override string Description => @"Showing everything to play the game."; public override string Description => @"Showing everything to play the game.";
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(BeatmapDatabase db) private void load(BeatmapDatabase db, RulesetDatabase rulesets)
{ {
this.rulesets = rulesets;
this.db = db; this.db = db;
} }
@ -37,7 +38,7 @@ namespace osu.Desktop.VisualTests.Tests
WorkingBeatmap beatmap = null; WorkingBeatmap beatmap = null;
var beatmapInfo = db.Query<BeatmapInfo>().FirstOrDefault(b => b.Mode == PlayMode.Osu); var beatmapInfo = db.Query<BeatmapInfo>().FirstOrDefault(b => b.RulesetID == 0);
if (beatmapInfo != null) if (beatmapInfo != null)
beatmap = db.GetWorkingBeatmap(beatmapInfo); beatmap = db.GetWorkingBeatmap(beatmapInfo);
@ -65,6 +66,7 @@ namespace osu.Desktop.VisualTests.Tests
BeatmapInfo = new BeatmapInfo BeatmapInfo = new BeatmapInfo
{ {
Difficulty = new BeatmapDifficulty(), Difficulty = new BeatmapDifficulty(),
Ruleset = rulesets.Query<RulesetInfo>().First(),
Metadata = new BeatmapMetadata Metadata = new BeatmapMetadata
{ {
Artist = @"Unknown", Artist = @"Unknown",

View File

@ -7,11 +7,6 @@ using osu.Desktop.Beatmaps.IO;
using osu.Framework.Desktop; using osu.Framework.Desktop;
using osu.Framework.Desktop.Platform; using osu.Framework.Desktop.Platform;
using osu.Game.IPC; 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 namespace osu.Desktop
{ {
@ -41,11 +36,6 @@ namespace osu.Desktop
} }
else else
{ {
Ruleset.Register(new OsuRuleset());
Ruleset.Register(new TaikoRuleset());
Ruleset.Register(new ManiaRuleset());
Ruleset.Register(new CatchRuleset());
host.Run(new OsuGameDesktop(args)); host.Run(new OsuGameDesktop(args));
} }
return 0; return 0;

View File

@ -76,8 +76,6 @@ namespace osu.Game.Modes.Catch
} }
} }
protected override PlayMode PlayMode => PlayMode.Catch;
public override string Description => "osu!catch"; public override string Description => "osu!catch";
public override FontAwesome Icon => FontAwesome.fa_osu_fruits_o; 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 DifficultyCalculator CreateDifficultyCalculator(Beatmap beatmap) => new CatchDifficultyCalculator(beatmap);
public override ScoreProcessor CreateScoreProcessor() => new CatchScoreProcessor(); public override ScoreProcessor CreateScoreProcessor() => new CatchScoreProcessor();
public override int LegacyID => 2;
} }
} }

View File

@ -96,8 +96,6 @@ namespace osu.Game.Modes.Mania
} }
} }
protected override PlayMode PlayMode => PlayMode.Mania;
public override string Description => "osu!mania"; public override string Description => "osu!mania";
public override FontAwesome Icon => FontAwesome.fa_osu_mania_o; 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 DifficultyCalculator CreateDifficultyCalculator(Beatmap beatmap) => new ManiaDifficultyCalculator(beatmap);
public override ScoreProcessor CreateScoreProcessor() => new ManiaScoreProcessor(); public override ScoreProcessor CreateScoreProcessor() => new ManiaScoreProcessor();
public override int LegacyID => 3;
} }
} }

View File

@ -99,8 +99,6 @@ namespace osu.Game.Modes.Osu
public override DifficultyCalculator CreateDifficultyCalculator(Beatmap beatmap) => new OsuDifficultyCalculator(beatmap); public override DifficultyCalculator CreateDifficultyCalculator(Beatmap beatmap) => new OsuDifficultyCalculator(beatmap);
protected override PlayMode PlayMode => PlayMode.Osu;
public override string Description => "osu!"; public override string Description => "osu!";
public override IEnumerable<KeyCounter> CreateGameplayKeys() => new KeyCounter[] public override IEnumerable<KeyCounter> CreateGameplayKeys() => new KeyCounter[]
@ -112,5 +110,7 @@ namespace osu.Game.Modes.Osu
}; };
public override ScoreProcessor CreateScoreProcessor() => new OsuScoreProcessor(); public override ScoreProcessor CreateScoreProcessor() => new OsuScoreProcessor();
public override int LegacyID => 0;
} }
} }

View File

@ -76,8 +76,6 @@ namespace osu.Game.Modes.Taiko
} }
} }
protected override PlayMode PlayMode => PlayMode.Taiko;
public override string Description => "osu!taiko"; public override string Description => "osu!taiko";
public override FontAwesome Icon => FontAwesome.fa_osu_taiko_o; 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 DifficultyCalculator CreateDifficultyCalculator(Beatmap beatmap) => new TaikoDifficultyCalculator(beatmap);
public override ScoreProcessor CreateScoreProcessor() => new TaikoScoreProcessor(); public override ScoreProcessor CreateScoreProcessor() => new TaikoScoreProcessor();
public override int LegacyID => 1;
} }
} }

View File

@ -6,9 +6,7 @@ using NUnit.Framework;
using OpenTK; using OpenTK;
using OpenTK.Graphics; using OpenTK.Graphics;
using osu.Game.Beatmaps.Formats; using osu.Game.Beatmaps.Formats;
using osu.Game.Modes;
using osu.Game.Tests.Resources; using osu.Game.Tests.Resources;
using osu.Game.Modes.Osu;
using osu.Game.Modes.Objects.Legacy; using osu.Game.Modes.Objects.Legacy;
using System.Linq; using System.Linq;
using osu.Game.Audio; using osu.Game.Audio;
@ -22,7 +20,6 @@ namespace osu.Game.Tests.Beatmaps.Formats
public void SetUp() public void SetUp()
{ {
OsuLegacyDecoder.Register(); OsuLegacyDecoder.Register();
Ruleset.Register(new OsuRuleset());
} }
[Test] [Test]
@ -58,7 +55,7 @@ namespace osu.Game.Tests.Beatmaps.Formats
Assert.AreEqual(false, beatmapInfo.Countdown); Assert.AreEqual(false, beatmapInfo.Countdown);
Assert.AreEqual(0.7f, beatmapInfo.StackLeniency); Assert.AreEqual(0.7f, beatmapInfo.StackLeniency);
Assert.AreEqual(false, beatmapInfo.SpecialStyle); 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.LetterboxInBreaks);
Assert.AreEqual(false, beatmapInfo.WidescreenStoryboard); Assert.AreEqual(false, beatmapInfo.WidescreenStoryboard);
} }

View File

@ -12,11 +12,6 @@ using osu.Framework.Desktop.Platform;
using osu.Framework.Platform; using osu.Framework.Platform;
using osu.Game.Database; using osu.Game.Database;
using osu.Game.IPC; 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 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"; 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] [Test]
public void TestImportWhenClosed() public void TestImportWhenClosed()
{ {
@ -119,6 +105,7 @@ namespace osu.Game.Tests.Beatmaps.IO
Thread.Sleep(1); Thread.Sleep(1);
//reset beatmap database (sqlite and storage backing) //reset beatmap database (sqlite and storage backing)
osu.Dependencies.Get<RulesetDatabase>().Reset();
osu.Dependencies.Get<BeatmapDatabase>().Reset(); osu.Dependencies.Get<BeatmapDatabase>().Reset();
return osu; return osu;
@ -166,8 +153,16 @@ namespace osu.Game.Tests.Beatmaps.IO
Assert.IsTrue(set.Beatmaps.Count > 0); Assert.IsTrue(set.Beatmaps.Count > 0);
var beatmap = osu.Dependencies.Get<BeatmapDatabase>().GetWorkingBeatmap(set.Beatmaps.First(b => b.Mode == PlayMode.Osu))?.Beatmap; var beatmap = osu.Dependencies.Get<BeatmapDatabase>().GetWorkingBeatmap(set.Beatmaps.First(b => b.RulesetID == 0))?.Beatmap;
Assert.IsTrue(beatmap?.HitObjects.Count > 0);
beatmap = osu.Dependencies.Get<BeatmapDatabase>().GetWorkingBeatmap(set.Beatmaps.First(b => b.RulesetID == 1))?.Beatmap;
Assert.IsTrue(beatmap?.HitObjects.Count > 0);
beatmap = osu.Dependencies.Get<BeatmapDatabase>().GetWorkingBeatmap(set.Beatmaps.First(b => b.RulesetID == 2))?.Beatmap;
Assert.IsTrue(beatmap?.HitObjects.Count > 0);
beatmap = osu.Dependencies.Get<BeatmapDatabase>().GetWorkingBeatmap(set.Beatmaps.First(b => b.RulesetID == 3))?.Beatmap;
Assert.IsTrue(beatmap?.HitObjects.Count > 0); Assert.IsTrue(beatmap?.HitObjects.Count > 0);
} }
} }

View File

@ -4,8 +4,6 @@
using System.IO; using System.IO;
using NUnit.Framework; using NUnit.Framework;
using osu.Game.Beatmaps.IO; using osu.Game.Beatmaps.IO;
using osu.Game.Modes;
using osu.Game.Modes.Osu;
using osu.Game.Tests.Resources; using osu.Game.Tests.Resources;
using osu.Game.Beatmaps.Formats; using osu.Game.Beatmaps.Formats;
using osu.Game.Database; using osu.Game.Database;
@ -19,7 +17,6 @@ namespace osu.Game.Tests.Beatmaps.IO
public void SetUp() public void SetUp()
{ {
OszArchiveReader.Register(); OszArchiveReader.Register();
Ruleset.Register(new OsuRuleset());
} }
[Test] [Test]

View File

@ -4,7 +4,6 @@
using OpenTK.Graphics; using OpenTK.Graphics;
using osu.Game.Beatmaps.Timing; using osu.Game.Beatmaps.Timing;
using osu.Game.Database; using osu.Game.Database;
using osu.Game.Modes;
using osu.Game.Modes.Objects; using osu.Game.Modes.Objects;
using System.Collections.Generic; using System.Collections.Generic;
@ -50,12 +49,6 @@ namespace osu.Game.Beatmaps
/// </summary> /// </summary>
public class Beatmap : Beatmap<HitObject> public class Beatmap : Beatmap<HitObject>
{ {
/// <summary>
/// Calculates the star difficulty for this Beatmap.
/// </summary>
/// <returns>The star difficulty.</returns>
public double CalculateStarDifficulty() => Ruleset.GetRuleset(BeatmapInfo.Mode).CreateDifficultyCalculator(this).Calculate();
/// <summary> /// <summary>
/// Constructs a new beatmap. /// Constructs a new beatmap.
/// </summary> /// </summary>

View File

@ -6,7 +6,6 @@ using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Game.Database; using osu.Game.Database;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Modes;
using OpenTK; using OpenTK;
using OpenTK.Graphics; using OpenTK.Graphics;
@ -45,7 +44,7 @@ namespace osu.Game.Beatmaps.Drawables
Origin = Anchor.Centre, Origin = Anchor.Centre,
TextSize = Size.X, TextSize = Size.X,
Colour = Color4.White, Colour = Color4.White,
Icon = Ruleset.GetRuleset(beatmap.Mode).Icon Icon = beatmap.Ruleset.CreateInstance().Icon
} }
}; };
} }

View File

@ -7,7 +7,6 @@ using System.IO;
using OpenTK.Graphics; using OpenTK.Graphics;
using osu.Game.Beatmaps.Events; using osu.Game.Beatmaps.Events;
using osu.Game.Beatmaps.Timing; using osu.Game.Beatmaps.Timing;
using osu.Game.Modes;
using osu.Game.Modes.Objects; using osu.Game.Modes.Objects;
using osu.Game.Beatmaps.Legacy; using osu.Game.Beatmaps.Legacy;
@ -84,7 +83,7 @@ namespace osu.Game.Beatmaps.Formats
beatmap.BeatmapInfo.StackLeniency = float.Parse(val, NumberFormatInfo.InvariantInfo); beatmap.BeatmapInfo.StackLeniency = float.Parse(val, NumberFormatInfo.InvariantInfo);
break; break;
case @"Mode": case @"Mode":
beatmap.BeatmapInfo.Mode = (PlayMode)int.Parse(val); beatmap.BeatmapInfo.RulesetID = int.Parse(val);
break; break;
case @"LetterboxInBreaks": case @"LetterboxInBreaks":
beatmap.BeatmapInfo.LetterboxInBreaks = int.Parse(val) == 1; beatmap.BeatmapInfo.LetterboxInBreaks = int.Parse(val) == 1;

View File

@ -5,7 +5,6 @@ using osu.Framework.Audio.Track;
using osu.Framework.Configuration; using osu.Framework.Configuration;
using osu.Framework.Graphics.Textures; using osu.Framework.Graphics.Textures;
using osu.Game.Database; using osu.Game.Database;
using osu.Game.Modes;
using osu.Game.Modes.Mods; using osu.Game.Modes.Mods;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -18,14 +17,6 @@ namespace osu.Game.Beatmaps
public readonly BeatmapSetInfo BeatmapSetInfo; public readonly BeatmapSetInfo BeatmapSetInfo;
/// <summary>
/// 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.
/// </summary>
public PlayMode? PreferredPlayMode;
public PlayMode PlayMode => Beatmap?.BeatmapInfo?.Mode > PlayMode.Osu ? Beatmap.BeatmapInfo.Mode : PreferredPlayMode ?? PlayMode.Osu;
public readonly Bindable<IEnumerable<Mod>> Mods = new Bindable<IEnumerable<Mod>>(); public readonly Bindable<IEnumerable<Mod>> Mods = new Bindable<IEnumerable<Mod>>();
public readonly bool WithStoryboard; public readonly bool WithStoryboard;

View File

@ -4,7 +4,6 @@
using System; using System;
using osu.Framework.Configuration; using osu.Framework.Configuration;
using osu.Framework.Platform; using osu.Framework.Platform;
using osu.Game.Modes;
namespace osu.Game.Configuration namespace osu.Game.Configuration
{ {
@ -17,7 +16,7 @@ namespace osu.Game.Configuration
Set(OsuConfig.Username, string.Empty); Set(OsuConfig.Username, string.Empty);
Set(OsuConfig.Token, 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.AudioDevice, string.Empty);
Set(OsuConfig.SavePassword, false); Set(OsuConfig.SavePassword, false);
@ -196,7 +195,7 @@ namespace osu.Game.Configuration
public enum OsuConfig public enum OsuConfig
{ {
// New osu: // New osu:
PlayMode, Ruleset,
Token, Token,
// Imported from old osu: // Imported from old osu:
BeatmapDirectory, BeatmapDirectory,

View File

@ -5,7 +5,6 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Linq.Expressions;
using osu.Framework.Extensions; using osu.Framework.Extensions;
using osu.Framework.Logging; using osu.Framework.Logging;
using osu.Framework.Platform; using osu.Framework.Platform;
@ -18,37 +17,21 @@ using SQLiteNetExtensions.Extensions;
namespace osu.Game.Database namespace osu.Game.Database
{ {
public class BeatmapDatabase public class BeatmapDatabase : Database
{ {
private SQLiteConnection connection { get; } private readonly RulesetDatabase rulesets;
private readonly Storage storage;
public event Action<BeatmapSetInfo> BeatmapSetAdded; public event Action<BeatmapSetInfo> BeatmapSetAdded;
public event Action<BeatmapSetInfo> BeatmapSetRemoved; public event Action<BeatmapSetInfo> BeatmapSetRemoved;
// ReSharper disable once NotAccessedField.Local (we should keep a reference to this so it is not finalised) // ReSharper disable once NotAccessedField.Local (we should keep a reference to this so it is not finalised)
private BeatmapIPCChannel ipc; 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) if (importHost != null)
ipc = new BeatmapIPCChannel(importHost, this); 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() private void deletePending()
@ -57,20 +40,20 @@ namespace osu.Game.Database
{ {
try try
{ {
storage.Delete(b.Path); Storage.Delete(b.Path);
GetChildren(b, true); GetChildren(b, true);
foreach (var i in b.Beatmaps) foreach (var i in b.Beatmaps)
{ {
if (i.Metadata != null) connection.Delete(i.Metadata); if (i.Metadata != null) Connection.Delete(i.Metadata);
if (i.Difficulty != null) connection.Delete(i.Difficulty); if (i.Difficulty != null) Connection.Delete(i.Difficulty);
connection.Delete(i); Connection.Delete(i);
} }
if (b.Metadata != null) connection.Delete(b.Metadata); if (b.Metadata != null) Connection.Delete(b.Metadata);
connection.Delete(b); Connection.Delete(b);
} }
catch (Exception e) catch (Exception e)
{ {
@ -80,43 +63,42 @@ namespace osu.Game.Database
//this is required because sqlite migrations don't work, initially inserting nulls into this field. //this is required because sqlite migrations don't work, initially inserting nulls into this field.
//see https://github.com/praeclarum/sqlite-net/issues/326 //see https://github.com/praeclarum/sqlite-net/issues/326
connection.Query<BeatmapSetInfo>("UPDATE BeatmapSetInfo SET DeletePending = 0 WHERE DeletePending IS NULL"); Connection.Query<BeatmapSetInfo>("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<BeatmapMetadata>();
Connection.CreateTable<BeatmapDifficulty>();
Connection.CreateTable<BeatmapSetInfo>();
Connection.CreateTable<BeatmapInfo>();
try if (reset)
{ {
conn.CreateTable<BeatmapMetadata>(); Storage.DeleteDatabase(@"beatmaps");
conn.CreateTable<BeatmapDifficulty>();
conn.CreateTable<BeatmapSetInfo>();
conn.CreateTable<BeatmapInfo>();
}
catch
{
conn.Close();
throw;
}
return conn;
}
public void Reset()
{
foreach (var setInfo in Query<BeatmapSetInfo>()) foreach (var setInfo in Query<BeatmapSetInfo>())
{ {
if (storage.Exists(setInfo.Path)) if (Storage.Exists(setInfo.Path))
storage.Delete(setInfo.Path); Storage.Delete(setInfo.Path);
} }
connection.DeleteAll<BeatmapMetadata>(); Connection.DeleteAll<BeatmapMetadata>();
connection.DeleteAll<BeatmapDifficulty>(); Connection.DeleteAll<BeatmapDifficulty>();
connection.DeleteAll<BeatmapSetInfo>(); Connection.DeleteAll<BeatmapSetInfo>();
connection.DeleteAll<BeatmapInfo>(); Connection.DeleteAll<BeatmapInfo>();
} }
deletePending();
}
protected override Type[] ValidTypes => new[] {
typeof(BeatmapSetInfo),
typeof(BeatmapInfo),
typeof(BeatmapMetadata),
typeof(BeatmapDifficulty),
};
/// <summary> /// <summary>
/// Import multiple <see cref="BeatmapSetInfo"/> from <paramref name="paths"/>. /// Import multiple <see cref="BeatmapSetInfo"/> from <paramref name="paths"/>.
/// </summary> /// </summary>
@ -174,7 +156,7 @@ namespace osu.Game.Database
BeatmapMetadata metadata; 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]))) using (var stream = new StreamReader(reader.GetStream(reader.BeatmapFilenames[0])))
metadata = BeatmapDecoder.GetDecoder(stream).Decode(stream).Metadata; 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 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(); hash = input.GetMd5Hash();
input.Seek(0, SeekOrigin.Begin); input.Seek(0, SeekOrigin.Begin);
path = Path.Combine(@"beatmaps", hash.Remove(1), hash.Remove(2), hash); path = Path.Combine(@"beatmaps", hash.Remove(1), hash.Remove(2), hash);
if (!storage.Exists(path)) if (!Storage.Exists(path))
using (var output = storage.GetStream(path, FileAccess.Write)) using (var output = Storage.GetStream(path, FileAccess.Write))
input.CopyTo(output); input.CopyTo(output);
} }
} }
var existing = connection.Table<BeatmapSetInfo>().FirstOrDefault(b => b.Hash == hash); var existing = Connection.Table<BeatmapSetInfo>().FirstOrDefault(b => b.Hash == hash);
if (existing != null) if (existing != null)
{ {
@ -216,7 +198,7 @@ namespace osu.Game.Database
Metadata = metadata Metadata = metadata
}; };
using (var archive = ArchiveReader.GetReader(storage, path)) using (var archive = ArchiveReader.GetReader(Storage, path))
{ {
string[] mapNames = archive.BeatmapFilenames; string[] mapNames = archive.BeatmapFilenames;
foreach (var name in mapNames) 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 // TODO: Diff beatmap metadata with set metadata and leave it here if necessary
beatmap.BeatmapInfo.Metadata = null; 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<RulesetInfo>().FirstOrDefault(r => r.ID == beatmap.BeatmapInfo.RulesetID);
beatmap.BeatmapInfo.StarDifficulty = rulesets.Query<RulesetInfo>().FirstOrDefault(r => r.ID == beatmap.BeatmapInfo.RulesetID)?.CreateInstance()?.CreateDifficultyCalculator(beatmap).Calculate() ?? 0;
beatmapSet.Beatmaps.Add(beatmap.BeatmapInfo); beatmapSet.Beatmaps.Add(beatmap.BeatmapInfo);
} }
@ -248,17 +232,17 @@ namespace osu.Game.Database
public void Import(IEnumerable<BeatmapSetInfo> beatmapSets) public void Import(IEnumerable<BeatmapSetInfo> beatmapSets)
{ {
lock (connection) lock (Connection)
{ {
connection.BeginTransaction(); Connection.BeginTransaction();
foreach (var s in beatmapSets) foreach (var s in beatmapSets)
{ {
connection.InsertWithChildren(s, true); Connection.InsertOrReplaceWithChildren(s, true);
BeatmapSetAdded?.Invoke(s); BeatmapSetAdded?.Invoke(s);
} }
connection.Commit(); Connection.Commit();
} }
} }
@ -275,7 +259,7 @@ namespace osu.Game.Database
if (string.IsNullOrEmpty(beatmapSet.Path)) if (string.IsNullOrEmpty(beatmapSet.Path))
return null; return null;
return ArchiveReader.GetReader(storage, beatmapSet.Path); return ArchiveReader.GetReader(Storage, beatmapSet.Path);
} }
public BeatmapSetInfo GetBeatmapSet(int id) public BeatmapSetInfo GetBeatmapSet(int id)
@ -287,12 +271,14 @@ namespace osu.Game.Database
{ {
var beatmapSetInfo = Query<BeatmapSetInfo>().FirstOrDefault(s => s.ID == beatmapInfo.BeatmapSetInfoID); var beatmapSetInfo = Query<BeatmapSetInfo>().FirstOrDefault(s => s.ID == beatmapInfo.BeatmapSetInfoID);
//we need metadata
GetChildren(beatmapSetInfo);
if (beatmapSetInfo == null) if (beatmapSetInfo == null)
throw new InvalidOperationException($@"Beatmap set {beatmapInfo.BeatmapSetInfoID} is not in the local database."); 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) if (beatmapInfo.Metadata == null)
beatmapInfo.Metadata = beatmapSetInfo.Metadata; beatmapInfo.Metadata = beatmapSetInfo.Metadata;
@ -303,47 +289,6 @@ namespace osu.Game.Database
return working; return working;
} }
public TableQuery<T> Query<T>() where T : class public bool Exists(BeatmapSetInfo beatmapSet) => Storage.Exists(beatmapSet.Path);
{
return connection.Table<T>();
}
public T GetWithChildren<T>(object id) where T : class
{
return connection.GetWithChildren<T>(id);
}
public List<T> GetAllWithChildren<T>(Expression<Func<T, bool>> filter = null, bool recursive = true)
where T : class
{
return connection.GetAllWithChildren(filter, recursive);
}
public T GetChildren<T>(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>(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);
} }
} }

View File

@ -3,7 +3,6 @@
using Newtonsoft.Json; using Newtonsoft.Json;
using osu.Game.IO.Serialization; using osu.Game.IO.Serialization;
using osu.Game.Modes;
using SQLite.Net.Attributes; using SQLite.Net.Attributes;
using SQLiteNetExtensions.Attributes; using SQLiteNetExtensions.Attributes;
using System; using System;
@ -54,7 +53,13 @@ namespace osu.Game.Database
public bool Countdown { get; set; } public bool Countdown { get; set; }
public float StackLeniency { get; set; } public float StackLeniency { get; set; }
public bool SpecialStyle { 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 LetterboxInBreaks { get; set; }
public bool WidescreenStoryboard { get; set; } public bool WidescreenStoryboard { get; set; }

View File

@ -26,6 +26,7 @@ namespace osu.Game.Database
public double MaxStarDifficulty => Beatmaps.Max(b => b.StarDifficulty); public double MaxStarDifficulty => Beatmaps.Max(b => b.StarDifficulty);
[Indexed]
public bool DeletePending { get; set; } public bool DeletePending { get; set; }
public string Hash { get; set; } public string Hash { get; set; }

View File

@ -0,0 +1,82 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using System.Collections.Generic;
using 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);
}
}
/// <summary>
/// Prepare this database for use.
/// </summary>
protected abstract void Prepare(bool reset = false);
/// <summary>
/// Reset this database to a default state. Undo all changes to database and storage backings.
/// </summary>
public void Reset() => Prepare(true);
public TableQuery<T> Query<T>() where T : class
{
return Connection.Table<T>();
}
public T GetWithChildren<T>(object id) where T : class
{
return Connection.GetWithChildren<T>(id);
}
public List<T> GetAllWithChildren<T>(Expression<Func<T, bool>> filter = null, bool recursive = true)
where T : class
{
return Connection.GetAllWithChildren(filter, recursive);
}
public T GetChildren<T>(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>(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);
}
}
}

View File

@ -0,0 +1,103 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using osu.Framework.Platform;
using osu.Game.Modes;
using SQLite.Net;
namespace osu.Game.Database
{
/// <summary>
/// Todo: All of this needs to be moved to a RulesetDatabase.
/// </summary>
public class RulesetDatabase : Database
{
public IEnumerable<RulesetInfo> AllRulesets => Query<RulesetInfo>().Where(r => r.Available);
public RulesetDatabase(Storage storage, SQLiteConnection connection)
: base(storage, connection)
{
}
protected override void Prepare(bool reset = false)
{
Connection.CreateTable<RulesetInfo>();
if (reset)
{
Connection.DeleteAll<RulesetInfo>();
}
List<Ruleset> instances = new List<Ruleset>();
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<RulesetInfo>().FirstOrDefault(ri => ri.InstantiationInfo == us.InstantiationInfo);
if (existing == null)
Connection.Insert(us);
}
//perform a consistency check
foreach (var r in Query<RulesetInfo>())
{
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<RulesetInfo>().First(r => r.ID == id);
}
}

View File

@ -0,0 +1,26 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using 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));
}
}

View File

@ -7,26 +7,29 @@ using System.Linq;
using osu.Framework.Platform; using osu.Framework.Platform;
using osu.Game.IO.Legacy; using osu.Game.IO.Legacy;
using osu.Game.IPC; using osu.Game.IPC;
using osu.Game.Modes;
using osu.Game.Modes.Scoring; using osu.Game.Modes.Scoring;
using SharpCompress.Compressors.LZMA; using SharpCompress.Compressors.LZMA;
using SQLite.Net;
namespace osu.Game.Database namespace osu.Game.Database
{ {
public class ScoreDatabase public class ScoreDatabase : Database
{ {
private readonly Storage storage; private readonly Storage storage;
private readonly BeatmapDatabase beatmaps; private readonly BeatmapDatabase beatmaps;
private readonly RulesetDatabase rulesets;
private const string replay_folder = @"replays"; private const string replay_folder = @"replays";
// ReSharper disable once NotAccessedField.Local (we should keep a reference to this so it is not finalised) // ReSharper disable once NotAccessedField.Local (we should keep a reference to this so it is not finalised)
private ScoreIPCChannel ipc; 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.storage = storage;
this.beatmaps = beatmaps; this.beatmaps = beatmaps;
this.rulesets = rulesets;
if (importHost != null) if (importHost != null)
ipc = new ScoreIPCChannel(importHost, this); ipc = new ScoreIPCChannel(importHost, this);
@ -39,7 +42,7 @@ namespace osu.Game.Database
using (Stream s = storage.GetStream(Path.Combine(replay_folder, replayFilename))) using (Stream s = storage.GetStream(Path.Combine(replay_folder, replayFilename)))
using (SerializationReader sr = new SerializationReader(s)) 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 = ruleset.CreateScoreProcessor().CreateScore();
/* score.Pass = true;*/ /* score.Pass = true;*/
@ -107,5 +110,11 @@ namespace osu.Game.Database
return score; return score;
} }
protected override void Prepare(bool reset = false)
{
}
protected override Type[] ValidTypes => new[] { typeof(Score) };
} }
} }

View File

@ -1,13 +1,14 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>. // Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Game.Graphics;
namespace osu.Game.Modes namespace osu.Game.Modes
{ {
public enum PlayMode public class BeatmapStatistic
{ {
Osu = 0, public FontAwesome Icon;
Taiko = 1, public string Content;
Catch = 2, public string Name;
Mania = 3
} }
} }

View File

@ -6,26 +6,13 @@ using osu.Game.Graphics;
using osu.Game.Modes.Mods; using osu.Game.Modes.Mods;
using osu.Game.Modes.UI; using osu.Game.Modes.UI;
using osu.Game.Screens.Play; using osu.Game.Screens.Play;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic; using System.Collections.Generic;
using osu.Game.Modes.Scoring; using osu.Game.Modes.Scoring;
namespace osu.Game.Modes namespace osu.Game.Modes
{ {
public class BeatmapStatistic
{
public FontAwesome Icon;
public string Content;
public string Name;
}
public abstract class Ruleset public abstract class Ruleset
{ {
private static readonly ConcurrentDictionary<PlayMode, Type> available_rulesets = new ConcurrentDictionary<PlayMode, Type>();
public static IEnumerable<PlayMode> PlayModes => available_rulesets.Keys;
public virtual IEnumerable<BeatmapStatistic> GetBeatmapStatistics(WorkingBeatmap beatmap) => new BeatmapStatistic[] { }; public virtual IEnumerable<BeatmapStatistic> GetBeatmapStatistics(WorkingBeatmap beatmap) => new BeatmapStatistic[] { };
public abstract IEnumerable<Mod> GetModsFor(ModType type); public abstract IEnumerable<Mod> GetModsFor(ModType type);
@ -36,25 +23,15 @@ namespace osu.Game.Modes
public abstract ScoreProcessor CreateScoreProcessor(); 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 virtual FontAwesome Icon => FontAwesome.fa_question_circle;
public abstract string Description { get; } public abstract string Description { get; }
public abstract IEnumerable<KeyCounter> CreateGameplayKeys(); public abstract IEnumerable<KeyCounter> CreateGameplayKeys();
public static Ruleset GetRuleset(PlayMode mode) /// <summary>
{ /// Do not override this unless you are a legacy mode.
Type type; /// </summary>
public virtual int LegacyID => -1;
if (!available_rulesets.TryGetValue(mode, out type))
return null;
return Activator.CreateInstance(type) as Ruleset;
}
} }
} }

View File

@ -15,7 +15,6 @@ using osu.Framework.Logging;
using osu.Game.Graphics.UserInterface.Volume; using osu.Game.Graphics.UserInterface.Volume;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Timing; using osu.Framework.Timing;
using osu.Game.Modes;
using osu.Game.Overlays.Toolbar; using osu.Game.Overlays.Toolbar;
using osu.Game.Screens; using osu.Game.Screens;
using osu.Game.Screens.Menu; using osu.Game.Screens.Menu;
@ -24,6 +23,7 @@ using System.Linq;
using osu.Framework.Graphics.Primitives; using osu.Framework.Graphics.Primitives;
using System.Threading.Tasks; using System.Threading.Tasks;
using osu.Framework.Threading; using osu.Framework.Threading;
using osu.Game.Database;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Modes.Scoring; using osu.Game.Modes.Scoring;
using osu.Game.Overlays.Notifications; using osu.Game.Overlays.Notifications;
@ -58,7 +58,8 @@ namespace osu.Game
private VolumeControl volume; private VolumeControl volume;
public Bindable<PlayMode> PlayMode; private Bindable<int> configRuleset;
public Bindable<RulesetInfo> Ruleset = new Bindable<RulesetInfo>();
private readonly string[] args; private readonly string[] args;
@ -88,7 +89,9 @@ namespace osu.Game
Dependencies.Cache(this); Dependencies.Cache(this);
PlayMode = LocalConfig.GetBindable<PlayMode>(OsuConfig.PlayMode); configRuleset = LocalConfig.GetBindable<int>(OsuConfig.Ruleset);
Ruleset.Value = RulesetDatabase.GetRuleset(configRuleset.Value);
Ruleset.ValueChanged += r => configRuleset.Value = r.ID ?? 0;
} }
private ScheduledDelegate scoreLoad; private ScheduledDelegate scoreLoad;
@ -199,11 +202,11 @@ namespace osu.Game
{ {
Depth = -3, Depth = -3,
OnHome = delegate { intro?.ChildScreen?.MakeCurrent(); }, OnHome = delegate { intro?.ChildScreen?.MakeCurrent(); },
OnPlayModeChange = m => PlayMode.Value = m, OnRulesetChange = r => Ruleset.Value = r,
}, t => }, t =>
{ {
PlayMode.ValueChanged += delegate { Toolbar.SetGameMode(PlayMode.Value); }; Ruleset.ValueChanged += delegate { Toolbar.SetGameMode(Ruleset.Value); };
PlayMode.TriggerChange(); Ruleset.TriggerChange();
overlayContent.Add(Toolbar); overlayContent.Add(Toolbar);
}); });

View File

@ -18,6 +18,7 @@ using osu.Game.Graphics;
using osu.Game.Graphics.Cursor; using osu.Game.Graphics.Cursor;
using osu.Game.Graphics.Processing; using osu.Game.Graphics.Processing;
using osu.Game.Online.API; using osu.Game.Online.API;
using SQLite.Net;
namespace osu.Game namespace osu.Game
{ {
@ -27,6 +28,8 @@ namespace osu.Game
protected BeatmapDatabase BeatmapDatabase; protected BeatmapDatabase BeatmapDatabase;
protected RulesetDatabase RulesetDatabase;
protected ScoreDatabase ScoreDatabase; protected ScoreDatabase ScoreDatabase;
protected override string MainResourceFile => @"osu.Game.Resources.dll"; protected override string MainResourceFile => @"osu.Game.Resources.dll";
@ -80,8 +83,12 @@ namespace osu.Game
{ {
Dependencies.Cache(this); Dependencies.Cache(this);
Dependencies.Cache(LocalConfig); 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()); Dependencies.Cache(new OsuColour());
//this completely overrides the framework default. will need to change once we make a proper FontStore. //this completely overrides the framework default. will need to change once we make a proper FontStore.

View File

@ -13,11 +13,11 @@ using osu.Framework.Graphics.Sprites;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.Backgrounds; using osu.Game.Graphics.Backgrounds;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using osu.Game.Modes;
using osu.Game.Modes.Mods; using osu.Game.Modes.Mods;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using osu.Game.Database;
namespace osu.Game.Overlays.Mods namespace osu.Game.Overlays.Mods
{ {
@ -37,26 +37,30 @@ namespace osu.Game.Overlays.Mods
public readonly Bindable<IEnumerable<Mod>> SelectedMods = new Bindable<IEnumerable<Mod>>(); public readonly Bindable<IEnumerable<Mod>> SelectedMods = new Bindable<IEnumerable<Mod>>();
public readonly Bindable<PlayMode> PlayMode = new Bindable<PlayMode>(); public readonly Bindable<RulesetInfo> Ruleset = new Bindable<RulesetInfo>();
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) 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(); refreshSelectedMods();
} }
[BackgroundDependencyLoader(permitNulls: true)] [BackgroundDependencyLoader(permitNulls: true)]
private void load(OsuColour colours, OsuGame osu) private void load(OsuColour colours, OsuGame osu, RulesetDatabase rulesets)
{ {
lowMultiplierColour = colours.Red; lowMultiplierColour = colours.Red;
highMultiplierColour = colours.Green; highMultiplierColour = colours.Green;
if (osu != null) if (osu != null)
PlayMode.BindTo(osu.PlayMode); Ruleset.BindTo(osu.Ruleset);
PlayMode.ValueChanged += modeChanged; else
PlayMode.TriggerChange(); Ruleset.Value = rulesets.AllRulesets.First();
Ruleset.ValueChanged += rulesetChanged;
Ruleset.TriggerChange();
} }
protected override void PopOut() protected override void PopOut()

View File

@ -1,15 +1,14 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>. // Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using System.Collections.Generic; using System.Collections.Generic;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Primitives; using osu.Framework.Graphics.Primitives;
using osu.Game.Database;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using osu.Game.Modes;
using OpenTK; using OpenTK;
using OpenTK.Graphics; using OpenTK.Graphics;
@ -18,7 +17,7 @@ namespace osu.Game.Overlays.Options
public class OptionsFooter : FillFlowContainer public class OptionsFooter : FillFlowContainer
{ {
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuGameBase game, OsuColour colours) private void load(OsuGameBase game, OsuColour colours, RulesetDatabase rulesets)
{ {
RelativeSizeAxes = Axes.X; RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y; AutoSizeAxes = Axes.Y;
@ -27,13 +26,15 @@ namespace osu.Game.Overlays.Options
var modes = new List<Drawable>(); var modes = new List<Drawable>();
foreach (PlayMode m in Enum.GetValues(typeof(PlayMode))) foreach (var ruleset in rulesets.AllRulesets)
{
modes.Add(new TextAwesome modes.Add(new TextAwesome
{ {
Icon = Ruleset.GetRuleset(m).Icon, Icon = ruleset.CreateInstance().Icon,
Colour = Color4.Gray, Colour = Color4.Gray,
TextSize = 20 TextSize = 20
}); });
}
Children = new Drawable[] Children = new Drawable[]
{ {

View File

@ -8,8 +8,8 @@ using osu.Framework.Graphics.Colour;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
using osu.Framework.Input; using osu.Framework.Input;
using osu.Game.Database;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Modes;
using OpenTK; using OpenTK;
namespace osu.Game.Overlays.Toolbar namespace osu.Game.Overlays.Toolbar
@ -20,7 +20,7 @@ namespace osu.Game.Overlays.Toolbar
public const float TOOLTIP_HEIGHT = 30; public const float TOOLTIP_HEIGHT = 30;
public Action OnHome; public Action OnHome;
public Action<PlayMode> OnPlayModeChange; public Action<RulesetInfo> OnRulesetChange;
private readonly ToolbarModeSelector modeSelector; private readonly ToolbarModeSelector modeSelector;
private readonly ToolbarUserArea userArea; private readonly ToolbarUserArea userArea;
@ -55,9 +55,9 @@ namespace osu.Game.Overlays.Toolbar
}, },
modeSelector = new ToolbarModeSelector 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() protected override void PopIn()
{ {

View File

@ -2,23 +2,26 @@
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Game.Modes; using osu.Game.Database;
using OpenTK.Graphics; using OpenTK.Graphics;
namespace osu.Game.Overlays.Toolbar namespace osu.Game.Overlays.Toolbar
{ {
public class ToolbarModeButton : ToolbarButton public class ToolbarModeButton : ToolbarButton
{ {
private PlayMode mode; private RulesetInfo ruleset;
public PlayMode Mode public RulesetInfo Ruleset
{ {
get { return mode; } get { return ruleset; }
set set
{ {
mode = value; ruleset = value;
TooltipMain = Ruleset.GetRuleset(mode).Description;
TooltipSub = $"Play some {Ruleset.GetRuleset(mode).Description}"; var rInstance = ruleset.CreateInstance();
Icon = Ruleset.GetRuleset(mode).Icon;
TooltipMain = rInstance.Description;
TooltipSub = $"Play some {rInstance.Description}";
Icon = rInstance.Icon;
} }
} }

View File

@ -3,12 +3,13 @@
using System; using System;
using System.Linq; using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Caching; using osu.Framework.Caching;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Primitives; using osu.Framework.Graphics.Primitives;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
using osu.Game.Modes; using osu.Game.Database;
using OpenTK; using OpenTK;
using OpenTK.Graphics; using OpenTK.Graphics;
@ -22,7 +23,7 @@ namespace osu.Game.Overlays.Toolbar
private readonly Drawable modeButtonLine; private readonly Drawable modeButtonLine;
private ToolbarModeButton activeButton; private ToolbarModeButton activeButton;
public Action<PlayMode> OnPlayModeChange; public Action<RulesetInfo> OnRulesetChange;
public ToolbarModeSelector() 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 modeButtons.Add(new ToolbarModeButton
{ {
Mode = m, Ruleset = ruleset,
Action = delegate Action = delegate
{ {
SetGameMode(m); SetGameMode(ruleset);
OnPlayModeChange?.Invoke(m); OnRulesetChange?.Invoke(ruleset);
} }
}); });
} }
@ -84,11 +89,11 @@ namespace osu.Game.Overlays.Toolbar
Size = new Vector2(modeButtons.DrawSize.X, 1); Size = new Vector2(modeButtons.DrawSize.X, 1);
} }
public void SetGameMode(PlayMode mode) public void SetGameMode(RulesetInfo ruleset)
{ {
foreach (ToolbarModeButton m in modeButtons.Children.Cast<ToolbarModeButton>()) foreach (ToolbarModeButton m in modeButtons.Children.Cast<ToolbarModeButton>())
{ {
bool isActive = m.Mode == mode; bool isActive = m.Ruleset.ID == ruleset.ID;
m.Active = isActive; m.Active = isActive;
if (isActive) if (isActive)
activeButton = m; activeButton = m;

View File

@ -63,13 +63,6 @@ namespace osu.Game.Screens.Play
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(AudioManager audio, BeatmapDatabase beatmaps, OsuConfigManager config) 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<int>(OsuConfig.DimLevel); dimLevel = config.GetBindable<int>(OsuConfig.DimLevel);
mouseWheelDisabled = config.GetBindable<bool>(OsuConfig.MouseDisableWheel); mouseWheelDisabled = config.GetBindable<bool>(OsuConfig.MouseDisableWheel);
@ -109,7 +102,10 @@ namespace osu.Game.Screens.Play
sourceClock.Reset(); 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); HitRenderer = ruleset.CreateHitRendererWith(Beatmap);
scoreProcessor = HitRenderer.CreateScoreProcessor(); scoreProcessor = HitRenderer.CreateScoreProcessor();

View File

@ -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; int index = startIndex;
do do
@ -221,7 +221,12 @@ namespace osu.Game.Screens.Select
private BeatmapGroup createGroup(BeatmapSetInfo beatmapSet) private BeatmapGroup createGroup(BeatmapSetInfo beatmapSet)
{ {
database.GetChildren(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) return new BeatmapGroup(beatmapSet, database)
{ {

View File

@ -102,7 +102,7 @@ namespace osu.Game.Screens.Select
})); }));
//get statistics fromt he current ruleset. //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; AlwaysPresent = true;

View File

@ -16,7 +16,7 @@ using osu.Game.Graphics.UserInterface;
using osu.Game.Screens.Select.Filter; using osu.Game.Screens.Select.Filter;
using Container = osu.Framework.Graphics.Containers.Container; using Container = osu.Framework.Graphics.Containers.Container;
using osu.Framework.Input; using osu.Framework.Input;
using osu.Game.Modes; using osu.Game.Database;
namespace osu.Game.Screens.Select namespace osu.Game.Screens.Select
{ {
@ -61,7 +61,7 @@ namespace osu.Game.Screens.Select
Group = group, Group = group,
Sort = sort, Sort = sort,
SearchText = searchTextBox.Text, SearchText = searchTextBox.Text,
Mode = playMode Ruleset = ruleset
}; };
public Action Exit; public Action Exit;
@ -163,16 +163,17 @@ namespace osu.Game.Screens.Select
searchTextBox.HoldFocus = true; searchTextBox.HoldFocus = true;
} }
private readonly Bindable<PlayMode> playMode = new Bindable<PlayMode>(); private readonly Bindable<RulesetInfo> ruleset = new Bindable<RulesetInfo>();
[BackgroundDependencyLoader(permitNulls:true)] [BackgroundDependencyLoader(permitNulls:true)]
private void load(OsuColour colours, OsuGame osu) private void load(OsuColour colours, OsuGame osu)
{ {
sortTabs.AccentColour = colours.GreenLight; sortTabs.AccentColour = colours.GreenLight;
if (osu != null) playMode.BindTo(osu.PlayMode); if (osu != null)
playMode.ValueChanged += val => FilterChanged?.Invoke(CreateCriteria()); ruleset.BindTo(osu.Ruleset);
playMode.TriggerChange(); ruleset.ValueChanged += val => FilterChanged?.Invoke(CreateCriteria());
ruleset.TriggerChange();
} }
protected override bool OnMouseDown(InputState state, MouseDownEventArgs args) => true; protected override bool OnMouseDown(InputState state, MouseDownEventArgs args) => true;

View File

@ -5,7 +5,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using osu.Game.Beatmaps.Drawables; using osu.Game.Beatmaps.Drawables;
using osu.Game.Modes; using osu.Game.Database;
using osu.Game.Screens.Select.Filter; using osu.Game.Screens.Select.Filter;
namespace osu.Game.Screens.Select namespace osu.Game.Screens.Select
@ -15,7 +15,7 @@ namespace osu.Game.Screens.Select
public GroupMode Group; public GroupMode Group;
public SortMode Sort; public SortMode Sort;
public string SearchText; public string SearchText;
public PlayMode Mode; public RulesetInfo Ruleset;
public void Filter(List<BeatmapGroup> groups) public void Filter(List<BeatmapGroup> groups)
{ {
@ -23,7 +23,7 @@ namespace osu.Game.Screens.Select
{ {
var set = g.BeatmapSet; 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; bool match = hasCurrentMode;

View File

@ -20,7 +20,6 @@ using osu.Game.Beatmaps.Drawables;
using osu.Game.Database; using osu.Game.Database;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.Containers; using osu.Game.Graphics.Containers;
using osu.Game.Modes;
using osu.Game.Overlays; using osu.Game.Overlays;
using osu.Game.Screens.Backgrounds; using osu.Game.Screens.Backgrounds;
using osu.Game.Screens.Select.Options; using osu.Game.Screens.Select.Options;
@ -29,7 +28,7 @@ namespace osu.Game.Screens.Select
{ {
public abstract class SongSelect : OsuScreen public abstract class SongSelect : OsuScreen
{ {
private readonly Bindable<PlayMode> playMode = new Bindable<PlayMode>(); private readonly Bindable<RulesetInfo> ruleset = new Bindable<RulesetInfo>();
private BeatmapDatabase database; private BeatmapDatabase database;
protected override BackgroundScreen CreateBackground() => new BackgroundScreenBeatmap(Beatmap); protected override BackgroundScreen CreateBackground() => new BackgroundScreenBeatmap(Beatmap);
@ -170,8 +169,8 @@ namespace osu.Game.Screens.Select
if (database == null) if (database == null)
database = beatmaps; database = beatmaps;
playMode.ValueChanged += val => { if (Beatmap != null) Beatmap.PreferredPlayMode = val; }; if (osu != null)
if (osu != null) playMode.BindTo(osu.PlayMode); ruleset.BindTo(osu.Ruleset);
database.BeatmapSetAdded += onBeatmapSetAdded; database.BeatmapSetAdded += onBeatmapSetAdded;
database.BeatmapSetRemoved += onBeatmapSetRemoved; database.BeatmapSetRemoved += onBeatmapSetRemoved;
@ -200,7 +199,6 @@ namespace osu.Game.Screens.Select
{ {
if (Beatmap == null) return; if (Beatmap == null) return;
Beatmap.PreferredPlayMode = playMode.Value;
OnSelected(); OnSelected();
} }

View File

@ -78,6 +78,8 @@
<Compile Include="Beatmaps\Timing\TimeSignatures.cs" /> <Compile Include="Beatmaps\Timing\TimeSignatures.cs" />
<Compile Include="Beatmaps\Timing\TimingInfo.cs" /> <Compile Include="Beatmaps\Timing\TimingInfo.cs" />
<Compile Include="Database\BeatmapMetrics.cs" /> <Compile Include="Database\BeatmapMetrics.cs" />
<Compile Include="Database\Database.cs" />
<Compile Include="Database\RulesetInfo.cs" />
<Compile Include="Database\ScoreDatabase.cs" /> <Compile Include="Database\ScoreDatabase.cs" />
<Compile Include="Graphics\Backgrounds\Triangles.cs" /> <Compile Include="Graphics\Backgrounds\Triangles.cs" />
<Compile Include="Graphics\Cursor\CursorTrail.cs" /> <Compile Include="Graphics\Cursor\CursorTrail.cs" />
@ -101,6 +103,7 @@
<Compile Include="IO\Legacy\SerializationWriter.cs" /> <Compile Include="IO\Legacy\SerializationWriter.cs" />
<Compile Include="IO\Serialization\IJsonSerializable.cs" /> <Compile Include="IO\Serialization\IJsonSerializable.cs" />
<Compile Include="IPC\ScoreIPCChannel.cs" /> <Compile Include="IPC\ScoreIPCChannel.cs" />
<Compile Include="Modes\BeatmapStatistic.cs" />
<Compile Include="Modes\Replays\Replay.cs" /> <Compile Include="Modes\Replays\Replay.cs" />
<Compile Include="Modes\Judgements\DrawableJudgement.cs" /> <Compile Include="Modes\Judgements\DrawableJudgement.cs" />
<Compile Include="Modes\Judgements\IPartialJudgement.cs" /> <Compile Include="Modes\Judgements\IPartialJudgement.cs" />
@ -132,6 +135,7 @@
<Compile Include="Modes\Objects\Legacy\LegacyHitObjectType.cs" /> <Compile Include="Modes\Objects\Legacy\LegacyHitObjectType.cs" />
<Compile Include="Modes\Replays\ReplayButtonState.cs" /> <Compile Include="Modes\Replays\ReplayButtonState.cs" />
<Compile Include="Modes\Replays\ReplayFrame.cs" /> <Compile Include="Modes\Replays\ReplayFrame.cs" />
<Compile Include="Database\RulesetDatabase.cs" />
<Compile Include="Modes\Scoring\Score.cs" /> <Compile Include="Modes\Scoring\Score.cs" />
<Compile Include="Modes\Scoring\ScoreProcessor.cs" /> <Compile Include="Modes\Scoring\ScoreProcessor.cs" />
<Compile Include="Modes\UI\HealthDisplay.cs" /> <Compile Include="Modes\UI\HealthDisplay.cs" />
@ -217,7 +221,6 @@
<Compile Include="Beatmaps\Drawables\BeatmapPanel.cs" /> <Compile Include="Beatmaps\Drawables\BeatmapPanel.cs" />
<Compile Include="Screens\Play\Player.cs" /> <Compile Include="Screens\Play\Player.cs" />
<Compile Include="Screens\Charts\ChartListing.cs" /> <Compile Include="Screens\Charts\ChartListing.cs" />
<Compile Include="Modes\PlayMode.cs" />
<Compile Include="Modes\Ruleset.cs" /> <Compile Include="Modes\Ruleset.cs" />
<Compile Include="Screens\Ranking\Results.cs" /> <Compile Include="Screens\Ranking\Results.cs" />
<Compile Include="Screens\Direct\OnlineListing.cs" /> <Compile Include="Screens\Direct\OnlineListing.cs" />