Fix regressions and test cases.

This commit is contained in:
Dean Herbert
2017-04-17 19:44:03 +09:00
parent db6556a0f9
commit af13f97435
15 changed files with 63 additions and 59 deletions

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,6 +1,7 @@
// 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.Linq;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Game.Overlays.Mods; using osu.Game.Overlays.Mods;

View File

@ -22,19 +22,17 @@ namespace osu.Desktop.VisualTests.Tests
private RulesetDatabase rulesets; private RulesetDatabase rulesets;
[BackgroundDependencyLoader]
private void load(RulesetDatabase rulesets)
{
this.rulesets = 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, storage.GetDatabase(@"client"));
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>();

View File

@ -22,12 +22,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;
} }
@ -65,6 +67,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,7 +7,6 @@ using OpenTK;
using OpenTK.Graphics; using OpenTK.Graphics;
using osu.Game.Beatmaps.Formats; using osu.Game.Beatmaps.Formats;
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;
@ -56,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.IsTrue(beatmapInfo.Ruleset.CreateInstance() is OsuRuleset); 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,7 +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.Osu;
namespace osu.Game.Tests.Beatmaps.IO namespace osu.Game.Tests.Beatmaps.IO
{ {
@ -106,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;
@ -122,7 +122,7 @@ namespace osu.Game.Tests.Beatmaps.IO
Thread.Sleep(50); Thread.Sleep(50);
}; };
Assert.IsTrue(waitAction.BeginInvoke(null, null).AsyncWaitHandle.WaitOne(timeout), Assert.IsTrue(waitAction.BeginInvoke(null, null).AsyncWaitHandle.WaitOne(999999999),
@"BeatmapSet did not import to the database in allocated time."); @"BeatmapSet did not import to the database in allocated time.");
//ensure we were stored to beatmap database backing... //ensure we were stored to beatmap database backing...
@ -153,7 +153,7 @@ 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.Ruleset.CreateInstance() is OsuRuleset))?.Beatmap; var beatmap = osu.Dependencies.Get<BeatmapDatabase>().GetWorkingBeatmap(set.Beatmaps.First(b => b.RulesetID == 0))?.Beatmap;
Assert.IsTrue(beatmap?.HitObjects.Count > 0); Assert.IsTrue(beatmap?.HitObjects.Count > 0);
} }

View File

@ -49,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() => BeatmapInfo.Ruleset.CreateInstance().CreateDifficultyCalculator(this).Calculate();
/// <summary> /// <summary>
/// Constructs a new beatmap. /// Constructs a new beatmap.
/// </summary> /// </summary>

View File

@ -19,6 +19,7 @@ namespace osu.Game.Database
{ {
public class BeatmapDatabase : Database public class BeatmapDatabase : Database
{ {
private readonly RulesetDatabase rulesets;
public event Action<BeatmapSetInfo> BeatmapSetAdded; public event Action<BeatmapSetInfo> BeatmapSetAdded;
public event Action<BeatmapSetInfo> BeatmapSetRemoved; public event Action<BeatmapSetInfo> BeatmapSetRemoved;
@ -26,8 +27,9 @@ namespace osu.Game.Database
// 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, SQLiteConnection connection, IIpcHost importHost = null) : base(storage, connection) public BeatmapDatabase(Storage storage, SQLiteConnection connection, RulesetDatabase rulesets, IIpcHost importHost = null) : base(storage, connection)
{ {
this.rulesets = rulesets;
if (importHost != null) if (importHost != null)
ipc = new BeatmapIPCChannel(importHost, this); ipc = new BeatmapIPCChannel(importHost, this);
} }
@ -64,17 +66,14 @@ namespace osu.Game.Database
Connection.Query<BeatmapSetInfo>("UPDATE BeatmapSetInfo SET DeletePending = 0 WHERE DeletePending IS NULL"); Connection.Query<BeatmapSetInfo>("UPDATE BeatmapSetInfo SET DeletePending = 0 WHERE DeletePending IS NULL");
} }
protected override void Prepare() protected override void Prepare(bool reset = false)
{ {
Connection.CreateTable<BeatmapMetadata>(); Connection.CreateTable<BeatmapMetadata>();
Connection.CreateTable<BeatmapDifficulty>(); Connection.CreateTable<BeatmapDifficulty>();
Connection.CreateTable<BeatmapSetInfo>(); Connection.CreateTable<BeatmapSetInfo>();
Connection.CreateTable<BeatmapInfo>(); Connection.CreateTable<BeatmapInfo>();
deletePending(); if (reset)
}
public override void Reset()
{ {
Storage.DeleteDatabase(@"beatmaps"); Storage.DeleteDatabase(@"beatmaps");
@ -90,6 +89,9 @@ namespace osu.Game.Database
Connection.DeleteAll<BeatmapInfo>(); Connection.DeleteAll<BeatmapInfo>();
} }
deletePending();
}
protected override Type[] ValidTypes => new[] { protected override Type[] ValidTypes => new[] {
typeof(BeatmapSetInfo), typeof(BeatmapSetInfo),
typeof(BeatmapInfo), typeof(BeatmapInfo),
@ -216,7 +218,10 @@ 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.StarDifficulty = rulesets.Query<RulesetInfo>().FirstOrDefault(r => r.ID == beatmap.BeatmapInfo.RulesetID)?.CreateInstance()?.CreateDifficultyCalculator(beatmap).Calculate() ?? 0;
beatmap.BeatmapInfo.Ruleset = null;
beatmapSet.Beatmaps.Add(beatmap.BeatmapInfo); beatmapSet.Beatmaps.Add(beatmap.BeatmapInfo);
} }

View File

@ -29,20 +29,19 @@ namespace osu.Game.Database
catch (Exception e) catch (Exception e)
{ {
Logger.Error(e, $@"Failed to initialise the {GetType()}! Trying again with a clean database..."); Logger.Error(e, $@"Failed to initialise the {GetType()}! Trying again with a clean database...");
Reset(); Prepare(true);
Prepare();
} }
} }
/// <summary> /// <summary>
/// Prepare this database for use. /// Prepare this database for use.
/// </summary> /// </summary>
protected abstract void Prepare(); protected abstract void Prepare(bool reset = false);
/// <summary> /// <summary>
/// Reset this database to a default state. Undo all changes to database and storage backings. /// Reset this database to a default state. Undo all changes to database and storage backings.
/// </summary> /// </summary>
public abstract void Reset(); public void Reset() => Prepare(true);
public TableQuery<T> Query<T>() where T : class public TableQuery<T> Query<T>() where T : class
{ {

View File

@ -24,10 +24,15 @@ namespace osu.Game.Database
{ {
} }
protected override void Prepare() protected override void Prepare(bool reset = false)
{ {
Connection.CreateTable<RulesetInfo>(); Connection.CreateTable<RulesetInfo>();
if (reset)
{
Connection.DeleteAll<RulesetInfo>();
}
List<Ruleset> instances = new List<Ruleset>(); List<Ruleset> instances = new List<Ruleset>();
foreach (string file in Directory.GetFiles(Environment.CurrentDirectory, @"osu.Game.Modes.*.dll")) foreach (string file in Directory.GetFiles(Environment.CurrentDirectory, @"osu.Game.Modes.*.dll"))
@ -40,8 +45,6 @@ namespace osu.Game.Database
if (rulesets.Count() != 1) if (rulesets.Count() != 1)
continue; continue;
Assembly.LoadFile(file);
foreach (Type rulesetType in rulesets) foreach (Type rulesetType in rulesets)
instances.Add((Ruleset)Activator.CreateInstance(rulesetType)); instances.Add((Ruleset)Activator.CreateInstance(rulesetType));
} }
@ -84,8 +87,6 @@ namespace osu.Game.Database
} }
Connection.Commit(); Connection.Commit();
} }
private RulesetInfo createRulesetInfo(Ruleset ruleset) => new RulesetInfo private RulesetInfo createRulesetInfo(Ruleset ruleset) => new RulesetInfo
@ -95,11 +96,6 @@ namespace osu.Game.Database
ID = ruleset.LegacyID ID = ruleset.LegacyID
}; };
public override void Reset()
{
Connection.DeleteAll<RulesetInfo>();
}
protected override Type[] ValidTypes => new[] { typeof(RulesetInfo) }; protected override Type[] ValidTypes => new[] { typeof(RulesetInfo) };
public RulesetInfo GetRuleset(int id) => Query<RulesetInfo>().First(r => r.ID == id); public RulesetInfo GetRuleset(int id) => Query<RulesetInfo>().First(r => r.ID == id);

View File

@ -10,7 +10,7 @@ namespace osu.Game.Database
public class RulesetInfo public class RulesetInfo
{ {
[PrimaryKey, AutoIncrement] [PrimaryKey, AutoIncrement]
public int ID { get; set; } public int? ID { get; set; }
public string Name { get; set; } public string Name { get; set; }

View File

@ -111,11 +111,7 @@ namespace osu.Game.Database
return score; return score;
} }
protected override void Prepare() protected override void Prepare(bool reset = false)
{
}
public override void Reset()
{ {
} }

View File

@ -91,7 +91,7 @@ namespace osu.Game
configRuleset = LocalConfig.GetBindable<int>(OsuConfig.Ruleset); configRuleset = LocalConfig.GetBindable<int>(OsuConfig.Ruleset);
Ruleset.Value = RulesetDatabase.GetRuleset(configRuleset.Value); Ruleset.Value = RulesetDatabase.GetRuleset(configRuleset.Value);
Ruleset.ValueChanged += r => configRuleset.Value = r.ID; Ruleset.ValueChanged += r => configRuleset.Value = r.ID ?? 0;
} }
private ScheduledDelegate scoreLoad; private ScheduledDelegate scoreLoad;

View File

@ -86,8 +86,8 @@ namespace osu.Game
SQLiteConnection connection = Host.Storage.GetDatabase(@"client"); SQLiteConnection connection = Host.Storage.GetDatabase(@"client");
Dependencies.Cache(BeatmapDatabase = new BeatmapDatabase(Host.Storage, connection, Host));
Dependencies.Cache(RulesetDatabase = new RulesetDatabase(Host.Storage, connection)); 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(ScoreDatabase = new ScoreDatabase(Host.Storage, connection, Host, BeatmapDatabase));
Dependencies.Cache(new OsuColour()); Dependencies.Cache(new OsuColour());

View File

@ -49,13 +49,16 @@ namespace osu.Game.Overlays.Mods
} }
[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)
Ruleset.BindTo(osu.Ruleset); Ruleset.BindTo(osu.Ruleset);
else
Ruleset.Value = rulesets.AllRulesets.First();
Ruleset.ValueChanged += rulesetChanged; Ruleset.ValueChanged += rulesetChanged;
Ruleset.TriggerChange(); Ruleset.TriggerChange();
} }