From 2d810f72fa930194fea586363bc7ed4fd474130a Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Tue, 4 Oct 2016 11:31:10 -0400 Subject: [PATCH 01/33] Add initial DB schema and support code --- osu.Desktop/Program.cs | 2 +- osu.Game/Beatmaps/GameMode.cs | 11 +++++++++++ osu.Game/Database/Beatmap.cs | 21 +++++++++++++++++++++ osu.Game/Database/BeatmapDatabase.cs | 21 +++++++++++++++++++++ osu.Game/Database/BeatmapMetadata.cs | 23 +++++++++++++++++++++++ osu.Game/Database/BeatmapSet.cs | 14 ++++++++++++++ osu.Game/OsuGameBase.cs | 2 ++ osu.Game/osu.Game.csproj | 25 ++++++++++++++++++++++++- osu.Game/packages.config | 25 ++++++++++++++++--------- 9 files changed, 133 insertions(+), 11 deletions(-) create mode 100644 osu.Game/Beatmaps/GameMode.cs create mode 100644 osu.Game/Database/Beatmap.cs create mode 100644 osu.Game/Database/BeatmapDatabase.cs create mode 100644 osu.Game/Database/BeatmapMetadata.cs create mode 100644 osu.Game/Database/BeatmapSet.cs diff --git a/osu.Desktop/Program.cs b/osu.Desktop/Program.cs index 1421086054..0af085dce0 100644 --- a/osu.Desktop/Program.cs +++ b/osu.Desktop/Program.cs @@ -11,7 +11,7 @@ namespace osu.Desktop public static class Program { [STAThread] - public static void Main() + public static void Main(string[] args) { BasicGameHost host = Host.GetSuitableHost(@"osu"); host.Add(new OsuGame()); diff --git a/osu.Game/Beatmaps/GameMode.cs b/osu.Game/Beatmaps/GameMode.cs new file mode 100644 index 0000000000..a555d3b320 --- /dev/null +++ b/osu.Game/Beatmaps/GameMode.cs @@ -0,0 +1,11 @@ +using System; +namespace osu.Game.Beatmaps +{ + public enum GameMode + { + Osu = 0, + Taiko = 1, + CatchTheBeat = 2, + OsuMania = 3, + } +} \ No newline at end of file diff --git a/osu.Game/Database/Beatmap.cs b/osu.Game/Database/Beatmap.cs new file mode 100644 index 0000000000..e60d455a16 --- /dev/null +++ b/osu.Game/Database/Beatmap.cs @@ -0,0 +1,21 @@ +using System; +using SQLite; + +namespace osu.Game.Database +{ + public class Beatmap + { + [PrimaryKey] + public int ID { get; set; } + [NotNull, Indexed] + public int BeatmapSetID { get; set; } + [Indexed] + public int BeatmapMetadataID { get; set; } + public float DrainRate { get; set; } + public float CircleSize { get; set; } + public float OverallDifficulty { get; set; } + public float ApproachRate { get; set; } + public float SliderMultiplier { get; set; } + public float SliderTickRate { get; set; } + } +} \ No newline at end of file diff --git a/osu.Game/Database/BeatmapDatabase.cs b/osu.Game/Database/BeatmapDatabase.cs new file mode 100644 index 0000000000..2c318c5997 --- /dev/null +++ b/osu.Game/Database/BeatmapDatabase.cs @@ -0,0 +1,21 @@ +using System; +using SQLite; + +namespace osu.Game.Database +{ + public class BeatmapDatabase + { + private static SQLiteConnection Connection { get; set; } + + public BeatmapDatabase() + { + if (Connection == null) + { + Connection = new SQLiteConnection("beatmap.db"); + Connection.CreateTable(); + Connection.CreateTable(); + Connection.CreateTable(); + } + } + } +} \ No newline at end of file diff --git a/osu.Game/Database/BeatmapMetadata.cs b/osu.Game/Database/BeatmapMetadata.cs new file mode 100644 index 0000000000..b29ed0f593 --- /dev/null +++ b/osu.Game/Database/BeatmapMetadata.cs @@ -0,0 +1,23 @@ +using System; +using osu.Game.Beatmaps; +using SQLite; + +namespace osu.Game.Database +{ + public class BeatmapMetadata + { + [PrimaryKey] + public int ID { get; set; } + public string Title { get; set; } + public string TitleUnicode { get; set; } + public string Artist { get; set; } + public string ArtistUnicode { get; set; } + public string Author { get; set; } + public string Source { get; set; } + public string Tags { get; set; } + public GameMode Mode { get; set; } + public int PreviewTime { get; set; } + public string AudioFile { get; set; } + public string BackgroundFile { get; set; } + } +} \ No newline at end of file diff --git a/osu.Game/Database/BeatmapSet.cs b/osu.Game/Database/BeatmapSet.cs new file mode 100644 index 0000000000..fd0e161d93 --- /dev/null +++ b/osu.Game/Database/BeatmapSet.cs @@ -0,0 +1,14 @@ +using System; +using SQLite; + +namespace osu.Game.Database +{ + public class BeatmapSet + { + [PrimaryKey] + public int BeatmapSetID { get; set; } + [NotNull, Indexed] + public int MetadataID { get; set; } + } +} + diff --git a/osu.Game/OsuGameBase.cs b/osu.Game/OsuGameBase.cs index 229b306d14..98a5c254bb 100644 --- a/osu.Game/OsuGameBase.cs +++ b/osu.Game/OsuGameBase.cs @@ -6,6 +6,7 @@ using osu.Framework.Graphics.Cursor; using osu.Framework.Graphics.Textures; using osu.Framework.IO.Stores; using osu.Game.Configuration; +using osu.Game.Database; using osu.Game.Graphics.Cursor; using osu.Game.Graphics.Processing; using osu.Game.Online.API; @@ -16,6 +17,7 @@ namespace osu.Game public class OsuGameBase : BaseGame { internal OsuConfigManager Config = new OsuConfigManager(); + internal BeatmapDatabase Beatmaps = new BeatmapDatabase(); protected override string MainResourceFile => @"osu.Game.Resources.dll"; diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index bdb852c33f..b5e4ea1adf 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -43,6 +43,18 @@ + + ..\packages\SQLitePCLRaw.core.1.0.1\lib\net45\SQLitePCLRaw.core.dll + + + ..\packages\SQLitePCLRaw.provider.e_sqlite3.net45.1.0.1\lib\net45\SQLitePCLRaw.provider.e_sqlite3.dll + + + ..\packages\SQLitePCLRaw.bundle_green.1.0.1\lib\net45\SQLitePCLRaw.batteries_green.dll + + + ..\packages\sqlite-net-pcl.1.2.0\lib\portable-net45+wp8+wpa81+win8+MonoAndroid10+MonoTouch10+Xamarin.iOS10\SQLite-net.dll + @@ -148,6 +160,11 @@ + + + + + @@ -166,6 +183,9 @@ + + + - \ No newline at end of file + + + + diff --git a/osu.Game/packages.config b/osu.Game/packages.config index 8c9d8076cf..d40da68750 100644 --- a/osu.Game/packages.config +++ b/osu.Game/packages.config @@ -1,9 +1,16 @@ - - - - - - \ No newline at end of file + + + + + + + + + + + + + From 72c4a26aeadcc78e4c7a4dd66415e292581d1121 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Tue, 4 Oct 2016 13:35:40 -0400 Subject: [PATCH 02/33] Move control of databases into osu-framework --- osu.Game/Database/BeatmapDatabase.cs | 5 +++-- osu.Game/OsuGameBase.cs | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/osu.Game/Database/BeatmapDatabase.cs b/osu.Game/Database/BeatmapDatabase.cs index 2c318c5997..86c352c81c 100644 --- a/osu.Game/Database/BeatmapDatabase.cs +++ b/osu.Game/Database/BeatmapDatabase.cs @@ -1,4 +1,5 @@ using System; +using osu.Framework.OS; using SQLite; namespace osu.Game.Database @@ -7,11 +8,11 @@ namespace osu.Game.Database { private static SQLiteConnection Connection { get; set; } - public BeatmapDatabase() + public BeatmapDatabase(BasicStorage storage) { if (Connection == null) { - Connection = new SQLiteConnection("beatmap.db"); + Connection = storage.GetDb("beatmaps"); Connection.CreateTable(); Connection.CreateTable(); Connection.CreateTable(); diff --git a/osu.Game/OsuGameBase.cs b/osu.Game/OsuGameBase.cs index 98a5c254bb..89b5229ad9 100644 --- a/osu.Game/OsuGameBase.cs +++ b/osu.Game/OsuGameBase.cs @@ -17,7 +17,7 @@ namespace osu.Game public class OsuGameBase : BaseGame { internal OsuConfigManager Config = new OsuConfigManager(); - internal BeatmapDatabase Beatmaps = new BeatmapDatabase(); + internal BeatmapDatabase Beatmaps { get; private set; } protected override string MainResourceFile => @"osu.Game.Resources.dll"; @@ -34,6 +34,8 @@ namespace osu.Game { base.Load(game); + Beatmaps = new BeatmapDatabase(Host.Storage); + //this completely overrides the framework default. will need to change once we make a proper FontStore. Fonts = new TextureStore() { ScaleAdjust = 0.01f }; Fonts.AddStore(new GlyphStore(Resources, @"Fonts/Exo2.0-Regular")); From f6b6446a9cc352c65025ccc9637f26791454791d Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Tue, 4 Oct 2016 14:04:10 -0400 Subject: [PATCH 03/33] MetadataID -> BeatmapMetadataID --- osu.Game/Database/BeatmapSet.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Database/BeatmapSet.cs b/osu.Game/Database/BeatmapSet.cs index fd0e161d93..9222be7107 100644 --- a/osu.Game/Database/BeatmapSet.cs +++ b/osu.Game/Database/BeatmapSet.cs @@ -8,7 +8,7 @@ namespace osu.Game.Database [PrimaryKey] public int BeatmapSetID { get; set; } [NotNull, Indexed] - public int MetadataID { get; set; } + public int BeatmapMetadataID { get; set; } } } From e8de2450328ae3df4fd8565de93e060602c94bbf Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Tue, 4 Oct 2016 14:23:34 -0400 Subject: [PATCH 04/33] Use @strings --- osu.Game/Database/BeatmapDatabase.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Database/BeatmapDatabase.cs b/osu.Game/Database/BeatmapDatabase.cs index 86c352c81c..17779a8299 100644 --- a/osu.Game/Database/BeatmapDatabase.cs +++ b/osu.Game/Database/BeatmapDatabase.cs @@ -12,7 +12,7 @@ namespace osu.Game.Database { if (Connection == null) { - Connection = storage.GetDb("beatmaps"); + Connection = storage.GetDatabase(@"beatmaps"); Connection.CreateTable(); Connection.CreateTable(); Connection.CreateTable(); From 005dc9e8cbc45542e002017b699298c513ce9dce Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Tue, 4 Oct 2016 14:24:50 -0400 Subject: [PATCH 05/33] Drop GameMode --- osu.Game/Beatmaps/GameMode.cs | 11 ----------- osu.Game/osu.Game.csproj | 1 - 2 files changed, 12 deletions(-) delete mode 100644 osu.Game/Beatmaps/GameMode.cs diff --git a/osu.Game/Beatmaps/GameMode.cs b/osu.Game/Beatmaps/GameMode.cs deleted file mode 100644 index a555d3b320..0000000000 --- a/osu.Game/Beatmaps/GameMode.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System; -namespace osu.Game.Beatmaps -{ - public enum GameMode - { - Osu = 0, - Taiko = 1, - CatchTheBeat = 2, - OsuMania = 3, - } -} \ No newline at end of file diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index b5e4ea1adf..87e1f30823 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -164,7 +164,6 @@ - From 768c3bc31e70272332fde096be6dfb093de0a972 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Tue, 4 Oct 2016 14:34:42 -0400 Subject: [PATCH 06/33] Use PlayMode instead of GameMode --- osu.Game/Database/BeatmapMetadata.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Game/Database/BeatmapMetadata.cs b/osu.Game/Database/BeatmapMetadata.cs index b29ed0f593..4073bb7d57 100644 --- a/osu.Game/Database/BeatmapMetadata.cs +++ b/osu.Game/Database/BeatmapMetadata.cs @@ -1,5 +1,5 @@ using System; -using osu.Game.Beatmaps; +using osu.Game.GameModes.Play; using SQLite; namespace osu.Game.Database @@ -15,7 +15,7 @@ namespace osu.Game.Database public string Author { get; set; } public string Source { get; set; } public string Tags { get; set; } - public GameMode Mode { get; set; } + public PlayMode Mode { get; set; } public int PreviewTime { get; set; } public string AudioFile { get; set; } public string BackgroundFile { get; set; } From bc69aa1455825591943f20459895701c9ae0e155 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Tue, 4 Oct 2016 16:29:08 -0400 Subject: [PATCH 07/33] Initial support code for beatmap loading --- .../Beatmaps/IO/LegacyFilesystemReader.cs | 51 +++++++++++++++++++ osu.Desktop/osu.Desktop.csproj | 5 ++ osu.Game/Beatmaps/Beatmap.cs | 9 ++-- osu.Game/Beatmaps/BeatmapSet.cs | 2 + osu.Game/Beatmaps/Formats/BeatmapDecoder.cs | 25 +++++++++ osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs | 34 +++++++++++++ osu.Game/Beatmaps/IO/ArchiveReader.cs | 46 +++++++++++++++++ osu.Game/Beatmaps/IO/OszArchiveReader.cs | 42 +++++++++++++++ osu.Game/Beatmaps/Metadata.cs | 16 +++++- osu.Game/Database/BeatmapDatabase.cs | 44 ++++++++++++++++ osu.Game/osu.Game.csproj | 6 +++ 11 files changed, 274 insertions(+), 6 deletions(-) create mode 100644 osu.Desktop/Beatmaps/IO/LegacyFilesystemReader.cs create mode 100644 osu.Game/Beatmaps/Formats/BeatmapDecoder.cs create mode 100644 osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs create mode 100644 osu.Game/Beatmaps/IO/ArchiveReader.cs create mode 100644 osu.Game/Beatmaps/IO/OszArchiveReader.cs diff --git a/osu.Desktop/Beatmaps/IO/LegacyFilesystemReader.cs b/osu.Desktop/Beatmaps/IO/LegacyFilesystemReader.cs new file mode 100644 index 0000000000..711607b9df --- /dev/null +++ b/osu.Desktop/Beatmaps/IO/LegacyFilesystemReader.cs @@ -0,0 +1,51 @@ +using System; +using System.IO; +using System.Collections.Generic; +using System.Linq; +using osu.Game.Beatmaps.Formats; +using osu.Game.Beatmaps.IO; +using osu.Game.Beatmaps; + +namespace osu.Desktop.Beatmaps.IO +{ + /// + /// Reads an extracted legacy beatmap from disk. + /// + public class LegacyFilesystemReader : ArchiveReader + { + static LegacyFilesystemReader() + { + AddReader((storage, path) => Directory.Exists(path)); + } + + private string BasePath { get; set; } + private Beatmap FirstMap { get; set; } + + public LegacyFilesystemReader(string path) + { + BasePath = path; + var maps = ReadBeatmaps(); + if (maps.Length == 0) + throw new FileNotFoundException("This directory contains no beatmaps"); + using (var stream = new StreamReader(ReadFile(maps[0]))) + { + var decoder = BeatmapDecoder.GetDecoder(stream); + FirstMap = decoder.Decode(stream); + } + } + + public override string[] ReadBeatmaps() + { + return Directory.GetFiles(BasePath, "*.osu").Select(f => Path.GetFileName(f)).ToArray(); + } + + public override Stream ReadFile(string name) + { + return File.OpenRead(Path.Combine(BasePath, name)); + } + + public override Metadata ReadMetadata() + { + return FirstMap.Metadata; + } } +} \ No newline at end of file diff --git a/osu.Desktop/osu.Desktop.csproj b/osu.Desktop/osu.Desktop.csproj index 5553f12019..d8463dbc35 100644 --- a/osu.Desktop/osu.Desktop.csproj +++ b/osu.Desktop/osu.Desktop.csproj @@ -135,8 +135,13 @@ + + + + + + From e9a45de51f87346d61e168230c9cf7cf61045b09 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Fri, 7 Oct 2016 13:50:34 -0400 Subject: [PATCH 09/33] Refactor database to reuse existing types --- .../Beatmaps/IO/LegacyFilesystemReader.cs | 2 +- .../Beatmap.cs => Beatmaps/BaseDifficulty.cs} | 13 ++++------ osu.Game/Beatmaps/Beatmap.cs | 24 +++++++++++++------ .../{Metadata.cs => BeatmapMetadata.cs} | 6 ++++- osu.Game/Beatmaps/BeatmapSet.cs | 16 ++++++++----- osu.Game/Beatmaps/IO/ArchiveReader.cs | 2 +- osu.Game/Beatmaps/IO/OszArchiveReader.cs | 2 +- osu.Game/Database/BeatmapDatabase.cs | 3 ++- osu.Game/Database/BeatmapMetadata.cs | 23 ------------------ osu.Game/Database/BeatmapSet.cs | 14 ----------- osu.Game/osu.Game.csproj | 6 ++--- 11 files changed, 44 insertions(+), 67 deletions(-) rename osu.Game/{Database/Beatmap.cs => Beatmaps/BaseDifficulty.cs} (63%) rename osu.Game/Beatmaps/{Metadata.cs => BeatmapMetadata.cs} (84%) delete mode 100644 osu.Game/Database/BeatmapMetadata.cs delete mode 100644 osu.Game/Database/BeatmapSet.cs diff --git a/osu.Desktop/Beatmaps/IO/LegacyFilesystemReader.cs b/osu.Desktop/Beatmaps/IO/LegacyFilesystemReader.cs index 31c7b4c365..fa960b876c 100644 --- a/osu.Desktop/Beatmaps/IO/LegacyFilesystemReader.cs +++ b/osu.Desktop/Beatmaps/IO/LegacyFilesystemReader.cs @@ -45,7 +45,7 @@ namespace osu.Desktop.Beatmaps.IO return File.OpenRead(Path.Combine(BasePath, name)); } - public override Metadata ReadMetadata() + public override BeatmapMetadata ReadMetadata() { return FirstMap.Metadata; } } diff --git a/osu.Game/Database/Beatmap.cs b/osu.Game/Beatmaps/BaseDifficulty.cs similarity index 63% rename from osu.Game/Database/Beatmap.cs rename to osu.Game/Beatmaps/BaseDifficulty.cs index e60d455a16..62acf07695 100644 --- a/osu.Game/Database/Beatmap.cs +++ b/osu.Game/Beatmaps/BaseDifficulty.cs @@ -1,16 +1,12 @@ using System; using SQLite; -namespace osu.Game.Database +namespace osu.Game.Beatmaps { - public class Beatmap + public class BaseDifficulty { - [PrimaryKey] + [PrimaryKey, AutoIncrement] public int ID { get; set; } - [NotNull, Indexed] - public int BeatmapSetID { get; set; } - [Indexed] - public int BeatmapMetadataID { get; set; } public float DrainRate { get; set; } public float CircleSize { get; set; } public float OverallDifficulty { get; set; } @@ -18,4 +14,5 @@ namespace osu.Game.Database public float SliderMultiplier { get; set; } public float SliderTickRate { get; set; } } -} \ No newline at end of file +} + diff --git a/osu.Game/Beatmaps/Beatmap.cs b/osu.Game/Beatmaps/Beatmap.cs index 762d06eb17..b6ec2855ba 100644 --- a/osu.Game/Beatmaps/Beatmap.cs +++ b/osu.Game/Beatmaps/Beatmap.cs @@ -5,17 +5,27 @@ using System.Collections.Generic; using osu.Game.Beatmaps.Objects; using osu.Game.Beatmaps.Timing; using osu.Game.Users; +using SQLite; namespace osu.Game.Beatmaps { public class Beatmap { - public int BeatmapID; - - public List HitObjects; - public List ControlPoints; - - public string Version; - public Metadata Metadata; + [PrimaryKey] + public int BeatmapID { get; set; } + [NotNull, Indexed] + public int BeatmapSetID { get; set; } + [Indexed] + public int BeatmapMetadataID { get; set; } + public int BaseDifficultyID { get; set; } + [Ignore] + public List HitObjects { get; set; } + [Ignore] + public List ControlPoints { get; set; } + [Ignore] + public BeatmapMetadata Metadata { get; set; } + [Ignore] + public BaseDifficulty BaseDifficulty { get; set; } + public string Version { get; set; } } } \ No newline at end of file diff --git a/osu.Game/Beatmaps/Metadata.cs b/osu.Game/Beatmaps/BeatmapMetadata.cs similarity index 84% rename from osu.Game/Beatmaps/Metadata.cs rename to osu.Game/Beatmaps/BeatmapMetadata.cs index c23573e232..a1808a80e6 100644 --- a/osu.Game/Beatmaps/Metadata.cs +++ b/osu.Game/Beatmaps/BeatmapMetadata.cs @@ -2,11 +2,15 @@ //Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using osu.Game.GameModes.Play; +using SQLite; namespace osu.Game.Beatmaps { - public class Metadata + public class BeatmapMetadata { + [PrimaryKey] + public int ID { get; set; } + public int BeatmapSetID { get; set; } public string Title { get; set; } public string TitleUnicode { get; set; } diff --git a/osu.Game/Beatmaps/BeatmapSet.cs b/osu.Game/Beatmaps/BeatmapSet.cs index a110f094ea..5f1be7f9b0 100644 --- a/osu.Game/Beatmaps/BeatmapSet.cs +++ b/osu.Game/Beatmaps/BeatmapSet.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using osu.Game.Users; +using SQLite; namespace osu.Game.Beatmaps { @@ -11,12 +12,15 @@ namespace osu.Game.Beatmaps /// public class BeatmapSet { - public int BeatmapSetID; - + [PrimaryKey] + public int BeatmapSetID { get; set; } + [NotNull, Indexed] + public int BeatmapMetadataID { get; set; } + [Ignore] public List Beatmaps { get; protected set; } - - public Metadata Metadata; - - public User Creator; + [Ignore] + public BeatmapMetadata Metadata { get; set; } + [Ignore] + public User Creator { get; set; } } } diff --git a/osu.Game/Beatmaps/IO/ArchiveReader.cs b/osu.Game/Beatmaps/IO/ArchiveReader.cs index a009f89b1f..0731b35bb0 100644 --- a/osu.Game/Beatmaps/IO/ArchiveReader.cs +++ b/osu.Game/Beatmaps/IO/ArchiveReader.cs @@ -33,7 +33,7 @@ namespace osu.Game.Beatmaps.IO /// /// Reads the beatmap metadata from this archive. /// - public abstract Metadata ReadMetadata(); + public abstract BeatmapMetadata ReadMetadata(); /// /// Gets a list of beatmap file names. /// diff --git a/osu.Game/Beatmaps/IO/OszArchiveReader.cs b/osu.Game/Beatmaps/IO/OszArchiveReader.cs index 036ce07128..c7213cbedc 100644 --- a/osu.Game/Beatmaps/IO/OszArchiveReader.cs +++ b/osu.Game/Beatmaps/IO/OszArchiveReader.cs @@ -53,7 +53,7 @@ namespace osu.Game.Beatmaps.IO return entry.OpenReader(); } - public override Metadata ReadMetadata() + public override BeatmapMetadata ReadMetadata() { return FirstMap.Metadata; } diff --git a/osu.Game/Database/BeatmapDatabase.cs b/osu.Game/Database/BeatmapDatabase.cs index df3eba7b1f..5b087388a7 100644 --- a/osu.Game/Database/BeatmapDatabase.cs +++ b/osu.Game/Database/BeatmapDatabase.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.IO; using osu.Framework.OS; +using osu.Game.Beatmaps; using osu.Game.Beatmaps.Formats; using osu.Game.Beatmaps.IO; using SQLite; @@ -52,7 +53,7 @@ namespace osu.Game.Database var beatmap = decoder.Decode(stream); maps.Add(new Beatmap { - ID = beatmap.BeatmapID, + BeatmapID = beatmap.BeatmapID, BeatmapSetID = metadata.BeatmapSetID, // TODO: Import more things }); diff --git a/osu.Game/Database/BeatmapMetadata.cs b/osu.Game/Database/BeatmapMetadata.cs deleted file mode 100644 index 4073bb7d57..0000000000 --- a/osu.Game/Database/BeatmapMetadata.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System; -using osu.Game.GameModes.Play; -using SQLite; - -namespace osu.Game.Database -{ - public class BeatmapMetadata - { - [PrimaryKey] - public int ID { get; set; } - public string Title { get; set; } - public string TitleUnicode { get; set; } - public string Artist { get; set; } - public string ArtistUnicode { get; set; } - public string Author { get; set; } - public string Source { get; set; } - public string Tags { get; set; } - public PlayMode Mode { get; set; } - public int PreviewTime { get; set; } - public string AudioFile { get; set; } - public string BackgroundFile { get; set; } - } -} \ No newline at end of file diff --git a/osu.Game/Database/BeatmapSet.cs b/osu.Game/Database/BeatmapSet.cs deleted file mode 100644 index 9222be7107..0000000000 --- a/osu.Game/Database/BeatmapSet.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using SQLite; - -namespace osu.Game.Database -{ - public class BeatmapSet - { - [PrimaryKey] - public int BeatmapSetID { get; set; } - [NotNull, Indexed] - public int BeatmapMetadataID { get; set; } - } -} - diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index d11283b00c..fced014b07 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -62,7 +62,7 @@ - + @@ -164,13 +164,11 @@ - - - + From c9a057b510d7c34c84c5fd2f521b1684c36184d9 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Fri, 7 Oct 2016 13:57:06 -0400 Subject: [PATCH 10/33] Update AddBeatmap accordingly --- osu.Game/Database/BeatmapDatabase.cs | 25 ++++--------------------- 1 file changed, 4 insertions(+), 21 deletions(-) diff --git a/osu.Game/Database/BeatmapDatabase.cs b/osu.Game/Database/BeatmapDatabase.cs index 5b087388a7..de40dc2dee 100644 --- a/osu.Game/Database/BeatmapDatabase.cs +++ b/osu.Game/Database/BeatmapDatabase.cs @@ -19,6 +19,7 @@ namespace osu.Game.Database { Connection = storage.GetDatabase(@"beatmaps"); Connection.CreateTable(); + Connection.CreateTable(); Connection.CreateTable(); Connection.CreateTable(); } @@ -30,20 +31,6 @@ namespace osu.Game.Database return; string[] mapNames = input.ReadBeatmaps(); var beatmapSet = new BeatmapSet { BeatmapSetID = metadata.BeatmapSetID }; - var beatmapMetadata = new BeatmapMetadata - { - Title = metadata.Title, - TitleUnicode = metadata.TitleUnicode, - Artist = metadata.Artist, - ArtistUnicode = metadata.ArtistUnicode, - Author = metadata.Author, - Source = metadata.Source, - Tags = metadata.Tags, - Mode = metadata.Mode, - PreviewTime = metadata.PreviewTime, - AudioFile = metadata.AudioFile, - BackgroundFile = metadata.BackgroundFile, - }; var maps = new List(); foreach (var name in mapNames) { @@ -51,15 +38,11 @@ namespace osu.Game.Database { var decoder = BeatmapDecoder.GetDecoder(stream); var beatmap = decoder.Decode(stream); - maps.Add(new Beatmap - { - BeatmapID = beatmap.BeatmapID, - BeatmapSetID = metadata.BeatmapSetID, - // TODO: Import more things - }); + maps.Add(beatmap); + beatmap.BaseDifficultyID = Connection.Insert(beatmap.BaseDifficulty); } } - beatmapSet.BeatmapMetadataID = Connection.Insert(beatmapMetadata); + beatmapSet.BeatmapMetadataID = Connection.Insert(metadata); Connection.Insert(beatmapSet); Connection.InsertAll(maps); } From 2a3f04789568334fd3912592119f3390f7466143 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Fri, 7 Oct 2016 15:09:52 -0400 Subject: [PATCH 11/33] Start implementing legacy decoder --- .../Beatmaps/IO/OszArchiveReaderTest.cs | 46 ++++++++ osu.Game.Tests/Resources/Resource.cs | 15 +++ osu.Game.Tests/osu.Game.Tests.csproj | 57 ++++++++++ osu.Game.Tests/packages.config | 4 + osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs | 103 +++++++++++++++++- osu.Game/Beatmaps/IO/OszArchiveReader.cs | 5 +- osu.Game/OsuGameBase.cs | 2 + osu.sln | 9 ++ 8 files changed, 236 insertions(+), 5 deletions(-) create mode 100644 osu.Game.Tests/Beatmaps/IO/OszArchiveReaderTest.cs create mode 100644 osu.Game.Tests/Resources/Resource.cs create mode 100644 osu.Game.Tests/osu.Game.Tests.csproj create mode 100644 osu.Game.Tests/packages.config diff --git a/osu.Game.Tests/Beatmaps/IO/OszArchiveReaderTest.cs b/osu.Game.Tests/Beatmaps/IO/OszArchiveReaderTest.cs new file mode 100644 index 0000000000..275de8121f --- /dev/null +++ b/osu.Game.Tests/Beatmaps/IO/OszArchiveReaderTest.cs @@ -0,0 +1,46 @@ +using System; +using System.IO; +using NUnit.Framework; +using osu.Game.Beatmaps.IO; +using osu.Game.Tests.Resources; + +namespace osu.Game.Tests.Beatmaps.IO +{ + [TestFixture] + public class OszArchiveReaderTest + { + [TestFixtureSetUp] + public void SetUp() + { + OszArchiveReader.Register(); + } + + [Test] + public void TestReadBeatmaps() + { + using (var osz = File.OpenRead(Resource.GetPath("241526 Soleily - Renatus.osz"))) + { + var reader = new OszArchiveReader(osz); + string[] expected = + { + "Soleily - Renatus (Deif) [Platter].osu", + "Soleily - Renatus (Deif) [Rain].osu", + "Soleily - Renatus (Deif) [Salad].osu", + "Soleily - Renatus (ExPew) [Another].osu", + "Soleily - Renatus (ExPew) [Hyper].osu", + "Soleily - Renatus (ExPew) [Normal].osu", + "Soleily - Renatus (Gamu) [Hard].osu", + "Soleily - Renatus (Gamu) [Insane].osu", + "Soleily - Renatus (Gamu) [Normal].osu", + "Soleily - Renatus (MMzz) [Futsuu].osu", + "Soleily - Renatus (MMzz) [Muzukashii].osu", + "Soleily - Renatus (MMzz) [Oni].osu" + }; + var maps = reader.ReadBeatmaps(); + foreach (var map in expected) + Assert.Contains(map, maps); + } + } + } +} + diff --git a/osu.Game.Tests/Resources/Resource.cs b/osu.Game.Tests/Resources/Resource.cs new file mode 100644 index 0000000000..ccc136f2b3 --- /dev/null +++ b/osu.Game.Tests/Resources/Resource.cs @@ -0,0 +1,15 @@ +using System; +using System.IO; +using System.Reflection; + +namespace osu.Game.Tests.Resources +{ + public static class Resource + { + public static string GetPath(string path) + { + var assemblyDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); + return Path.Combine(assemblyDir, "Resources", path); + } + } +} \ No newline at end of file diff --git a/osu.Game.Tests/osu.Game.Tests.csproj b/osu.Game.Tests/osu.Game.Tests.csproj new file mode 100644 index 0000000000..82f06ad84d --- /dev/null +++ b/osu.Game.Tests/osu.Game.Tests.csproj @@ -0,0 +1,57 @@ + + + + Debug + AnyCPU + {54377672-20B1-40AF-8087-5CF73BF3953A} + Library + osu.Game.Tests + osu.Game.Tests + v4.5 + + + true + full + false + bin\Debug + DEBUG; + prompt + 4 + false + + + true + bin\Release + prompt + 4 + false + + + + + ..\packages\NUnit.2.6.4\lib\nunit.framework.dll + + + + + + PreserveNewest + + + + + {0D3FBF8A-7464-4CF7-8C90-3E7886DF2D4D} + osu.Game + + + + + + + + + + + + + \ No newline at end of file diff --git a/osu.Game.Tests/packages.config b/osu.Game.Tests/packages.config new file mode 100644 index 0000000000..c714ef3a23 --- /dev/null +++ b/osu.Game.Tests/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs b/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs index e5ca017f9f..879a6b0c34 100644 --- a/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs +++ b/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs @@ -1,11 +1,15 @@ using System; +using System.Collections.Generic; using System.IO; +using osu.Game.Beatmaps.Objects; +using osu.Game.Beatmaps.Timing; +using osu.Game.GameModes.Play; namespace osu.Game.Beatmaps.Formats { public class OsuLegacyDecoder : BeatmapDecoder { - static OsuLegacyDecoder() + public static void Register() { AddDecoder("osu file format v14"); AddDecoder("osu file format v13"); @@ -16,6 +20,7 @@ namespace osu.Game.Beatmaps.Formats } private enum Section { + None, General, Editor, Metadata, @@ -25,10 +30,102 @@ namespace osu.Game.Beatmaps.Formats Colours, HitObjects, } + private void HandleGeneral(Beatmap beatmap, string key, string val) + { + switch (key) + { + case "AudioFilename": + beatmap.Metadata.AudioFile = val; + break; + case "AudioLeadIn": + // TODO + break; + case "PreviewTime": + beatmap.Metadata.PreviewTime = int.Parse(val); + break; + case "Countdown": + // TODO + break; + case "SampleSet": + // TODO + break; + case "StackLeniency": + // TODO + break; + case "Mode": + beatmap.Metadata.Mode = (PlayMode)int.Parse(val); + break; + case "LetterboxInBreaks": + // TODO + break; + case "SpecialStyle": + // TODO + break; + case "WidescreenStoryboard": + // TODO + break; + } + } public override Beatmap Decode(TextReader stream) - { - throw new NotImplementedException(); + { + var beatmap = new Beatmap + { + Metadata = new BeatmapMetadata(), + HitObjects = new List(), + ControlPoints = new List(), + }; + var section = Section.None; + string line; + while (true) + { + line = stream.ReadLine(); + if (line == null) + break; + line = line.Trim(); + if (string.IsNullOrEmpty(line)) + continue; + + if (line.StartsWith("[") && line.EndsWith("]")) + { + if (!Enum.TryParse(line.Substring(1, line.Length - 2), out section)) + throw new InvalidOperationException($@"Unknown osu section {line}"); + continue; + } + + string val = line, key = null; + if (section != Section.Events && section != Section.TimingPoints + && section != Section.HitObjects) + { + key = val.Remove(val.IndexOf(':')).Trim(); + val = val.Substring(val.IndexOf(':') + 1).Trim(); + } + switch (section) + { + case Section.General: + HandleGeneral(beatmap, key, val); + break; + case Section.Editor: + // TODO + break; + case Section.Metadata: + // TODO + break; + case Section.Difficulty: + // TODO + break; + case Section.Events: + // TODO + break; + case Section.TimingPoints: + // TODO + break; + case Section.HitObjects: + // TODO + break; + } + } + return beatmap; } } } \ No newline at end of file diff --git a/osu.Game/Beatmaps/IO/OszArchiveReader.cs b/osu.Game/Beatmaps/IO/OszArchiveReader.cs index c7213cbedc..a63468c16e 100644 --- a/osu.Game/Beatmaps/IO/OszArchiveReader.cs +++ b/osu.Game/Beatmaps/IO/OszArchiveReader.cs @@ -6,9 +6,9 @@ using osu.Game.Beatmaps.Formats; namespace osu.Game.Beatmaps.IO { - public class OszArchiveReader : ArchiveReader + public sealed class OszArchiveReader : ArchiveReader { - static OszArchiveReader() + public static void Register() { AddReader((storage, path) => { @@ -20,6 +20,7 @@ namespace osu.Game.Beatmaps.IO return zip.Entries.Any(e => e.FileName.EndsWith(".osu")); } }); + OsuLegacyDecoder.Register(); } private ZipFile Archive { get; set; } diff --git a/osu.Game/OsuGameBase.cs b/osu.Game/OsuGameBase.cs index 89b5229ad9..ea2fecf7c2 100644 --- a/osu.Game/OsuGameBase.cs +++ b/osu.Game/OsuGameBase.cs @@ -5,6 +5,7 @@ using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Cursor; using osu.Framework.Graphics.Textures; using osu.Framework.IO.Stores; +using osu.Game.Beatmaps.IO; using osu.Game.Configuration; using osu.Game.Database; using osu.Game.Graphics.Cursor; @@ -34,6 +35,7 @@ namespace osu.Game { base.Load(game); + OszArchiveReader.Register(); Beatmaps = new BeatmapDatabase(Host.Storage); //this completely overrides the framework default. will need to change once we make a proper FontStore. diff --git a/osu.sln b/osu.sln index 1454c14c82..d9f58def79 100644 --- a/osu.sln +++ b/osu.sln @@ -19,6 +19,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "osu.Framework.Desktop", "os EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "osu.Desktop.VisualTests", "osu.Desktop.VisualTests\osu.Desktop.VisualTests.csproj", "{69051C69-12AE-4E7D-A3E6-460D2E282312}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "osu.Game.Tests", "osu.Game.Tests\osu.Game.Tests.csproj", "{54377672-20B1-40AF-8087-5CF73BF3953A}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -56,6 +58,12 @@ Global {69051C69-12AE-4E7D-A3E6-460D2E282312}.Deploy|Any CPU.ActiveCfg = Debug|Any CPU {69051C69-12AE-4E7D-A3E6-460D2E282312}.Release|Any CPU.ActiveCfg = Release|Any CPU {69051C69-12AE-4E7D-A3E6-460D2E282312}.Release|Any CPU.Build.0 = Release|Any CPU + {54377672-20B1-40AF-8087-5CF73BF3953A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {54377672-20B1-40AF-8087-5CF73BF3953A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {54377672-20B1-40AF-8087-5CF73BF3953A}.Deploy|Any CPU.ActiveCfg = Release|Any CPU + {54377672-20B1-40AF-8087-5CF73BF3953A}.Deploy|Any CPU.Build.0 = Release|Any CPU + {54377672-20B1-40AF-8087-5CF73BF3953A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {54377672-20B1-40AF-8087-5CF73BF3953A}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -67,6 +75,7 @@ Global {D9A367C9-4C1A-489F-9B05-A0CEA2B53B58} = {0D37A2AD-80A4-464F-A1DE-1560B70F1CE3} {65DC628F-A640-4111-AB35-3A5652BC1E17} = {7A75DFA2-DE65-4458-98AF-26AF96FFD6DC} {69051C69-12AE-4E7D-A3E6-460D2E282312} = {0D37A2AD-80A4-464F-A1DE-1560B70F1CE3} + {54377672-20B1-40AF-8087-5CF73BF3953A} = {0D37A2AD-80A4-464F-A1DE-1560B70F1CE3} EndGlobalSection GlobalSection(MonoDevelopProperties) = preSolution Policies = $0 From 32ab8f97bb58a612a1628e0fb67a583c80a2c331 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Fri, 7 Oct 2016 15:36:20 -0400 Subject: [PATCH 12/33] Add more decoding (including full BeatmapMetadata) --- .../Beatmaps/IO/OszArchiveReaderTest.cs | 22 ++ osu.Game/Beatmaps/Beatmap.cs | 2 + osu.Game/Beatmaps/BeatmapMetadata.cs | 1 - osu.Game/Beatmaps/Events/EventType.cs | 14 + osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs | 271 +++++++++++------- osu.Game/osu.Game.csproj | 2 + 6 files changed, 206 insertions(+), 106 deletions(-) create mode 100644 osu.Game/Beatmaps/Events/EventType.cs diff --git a/osu.Game.Tests/Beatmaps/IO/OszArchiveReaderTest.cs b/osu.Game.Tests/Beatmaps/IO/OszArchiveReaderTest.cs index 275de8121f..502f410951 100644 --- a/osu.Game.Tests/Beatmaps/IO/OszArchiveReaderTest.cs +++ b/osu.Game.Tests/Beatmaps/IO/OszArchiveReaderTest.cs @@ -2,6 +2,7 @@ using System.IO; using NUnit.Framework; using osu.Game.Beatmaps.IO; +using osu.Game.GameModes.Play; using osu.Game.Tests.Resources; namespace osu.Game.Tests.Beatmaps.IO @@ -40,6 +41,27 @@ namespace osu.Game.Tests.Beatmaps.IO foreach (var map in expected) Assert.Contains(map, maps); } + } + + [Test] + public void TestReadMetadata() + { + using (var osz = File.OpenRead(Resource.GetPath("241526 Soleily - Renatus.osz"))) + { + var reader = new OszArchiveReader(osz); + var meta = reader.ReadMetadata(); + Assert.AreEqual(241526, meta.BeatmapSetID); + Assert.AreEqual("Soleily", meta.Artist); + Assert.AreEqual("Soleily", meta.ArtistUnicode); + Assert.AreEqual("03. Renatus - Soleily 192kbps.mp3", meta.AudioFile); + Assert.AreEqual("Deif", meta.Author); + Assert.AreEqual("machinetop_background.jpg", meta.BackgroundFile); + Assert.AreEqual(164471, meta.PreviewTime); + Assert.AreEqual(string.Empty, meta.Source); + Assert.AreEqual("MBC7 Unisphere 地球ヤバイEP Chikyu Yabai", meta.Tags); + Assert.AreEqual("Renatus", meta.Title); + Assert.AreEqual("Renatus", meta.TitleUnicode); + } } } } diff --git a/osu.Game/Beatmaps/Beatmap.cs b/osu.Game/Beatmaps/Beatmap.cs index b6ec2855ba..2c96f62988 100644 --- a/osu.Game/Beatmaps/Beatmap.cs +++ b/osu.Game/Beatmaps/Beatmap.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using osu.Game.Beatmaps.Objects; using osu.Game.Beatmaps.Timing; +using osu.Game.GameModes.Play; using osu.Game.Users; using SQLite; @@ -26,6 +27,7 @@ namespace osu.Game.Beatmaps public BeatmapMetadata Metadata { get; set; } [Ignore] public BaseDifficulty BaseDifficulty { get; set; } + public PlayMode Mode { get; set; } public string Version { get; set; } } } \ No newline at end of file diff --git a/osu.Game/Beatmaps/BeatmapMetadata.cs b/osu.Game/Beatmaps/BeatmapMetadata.cs index a1808a80e6..1499dde323 100644 --- a/osu.Game/Beatmaps/BeatmapMetadata.cs +++ b/osu.Game/Beatmaps/BeatmapMetadata.cs @@ -19,7 +19,6 @@ namespace osu.Game.Beatmaps public string Author { get; set; } public string Source { get; set; } public string Tags { get; set; } - public PlayMode Mode { get; set; } public int PreviewTime { get; set; } public string AudioFile { get; set; } public string BackgroundFile { get; set; } diff --git a/osu.Game/Beatmaps/Events/EventType.cs b/osu.Game/Beatmaps/Events/EventType.cs new file mode 100644 index 0000000000..cb66a42f2d --- /dev/null +++ b/osu.Game/Beatmaps/Events/EventType.cs @@ -0,0 +1,14 @@ +using System; +namespace osu.Game.Beatmaps.Events +{ + public enum EventType + { + Background = 0, + Video = 1, + Break = 2, + Colour = 3, + Sprite = 4, + Sample = 5, + Animation = 6 + } +} \ No newline at end of file diff --git a/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs b/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs index 879a6b0c34..cf01b751a9 100644 --- a/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs +++ b/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs @@ -1,131 +1,192 @@ -using System; +using System; using System.Collections.Generic; using System.IO; +using osu.Game.Beatmaps.Events; using osu.Game.Beatmaps.Objects; using osu.Game.Beatmaps.Timing; using osu.Game.GameModes.Play; -namespace osu.Game.Beatmaps.Formats -{ - public class OsuLegacyDecoder : BeatmapDecoder - { - public static void Register() - { - AddDecoder("osu file format v14"); - AddDecoder("osu file format v13"); - AddDecoder("osu file format v12"); - AddDecoder("osu file format v11"); - AddDecoder("osu file format v10"); - // TODO: Not sure how far back to go, or differences between versions +namespace osu.Game.Beatmaps.Formats +{ + public class OsuLegacyDecoder : BeatmapDecoder + { + public static void Register() + { + AddDecoder("osu file format v14"); + AddDecoder("osu file format v13"); + AddDecoder("osu file format v12"); + AddDecoder("osu file format v11"); + AddDecoder("osu file format v10"); + // TODO: Not sure how far back to go, or differences between versions } - private enum Section - { - None, - General, - Editor, - Metadata, - Difficulty, - Events, - TimingPoints, - Colours, - HitObjects, + + private enum Section + { + None, + General, + Editor, + Metadata, + Difficulty, + Events, + TimingPoints, + Colours, + HitObjects, } - private void HandleGeneral(Beatmap beatmap, string key, string val) - { - switch (key) - { - case "AudioFilename": + + private void HandleGeneral(Beatmap beatmap, string key, string val) + { + switch (key) + { + case "AudioFilename": beatmap.Metadata.AudioFile = val; - break; - case "AudioLeadIn": + break; + case "AudioLeadIn": // TODO - break; - case "PreviewTime": - beatmap.Metadata.PreviewTime = int.Parse(val); - break; - case "Countdown": - // TODO - break; - case "SampleSet": + break; + case "PreviewTime": + beatmap.Metadata.PreviewTime = int.Parse(val); + break; + case "Countdown": // TODO - break; - case "StackLeniency": + break; + case "SampleSet": // TODO - break; - case "Mode": - beatmap.Metadata.Mode = (PlayMode)int.Parse(val); - break; - case "LetterboxInBreaks": + break; + case "StackLeniency": // TODO - break; - case "SpecialStyle": + break; + case "Mode": + beatmap.Mode = (PlayMode)int.Parse(val); + break; + case "LetterboxInBreaks": // TODO - break; - case "WidescreenStoryboard": - // TODO - break; - } + break; + case "SpecialStyle": + // TODO + break; + case "WidescreenStoryboard": + // TODO + break; + } + } + + private void HandleMetadata(Beatmap beatmap, string key, string val) + { + switch (key) + { + case "Title": + beatmap.Metadata.Title = val; + break; + case "TitleUnicode": + beatmap.Metadata.TitleUnicode = val; + break; + case "Artist": + beatmap.Metadata.Artist = val; + break; + case "ArtistUnicode": + beatmap.Metadata.ArtistUnicode = val; + break; + case "Creator": + beatmap.Metadata.Author = val; + break; + case "Version": + beatmap.Version = val; + break; + case "Source": + beatmap.Metadata.Source = val; + break; + case "Tags": + beatmap.Metadata.Tags = val; + break; + case "BeatmapID": + beatmap.BeatmapID = int.Parse(val); + break; + case "BeatmapSetID": + beatmap.BeatmapSetID = int.Parse(val); + beatmap.Metadata.BeatmapSetID = int.Parse(val); + break; + } + } + + private void HandleEvents(Beatmap beatmap, string val) + { + if (val.StartsWith("//")) + return; + string[] split = val.Split(','); + EventType type; + int _type; + if (!int.TryParse(split[0], out _type)) + { + if (!Enum.TryParse(split[0], out type)) + throw new InvalidDataException($@"Unknown event type {split[0]}"); + } + else + type = (EventType)_type; + // TODO: Parse and store the rest of the event + if (type == EventType.Background) + beatmap.Metadata.BackgroundFile = split[2].Trim('"'); } public override Beatmap Decode(TextReader stream) - { - var beatmap = new Beatmap - { - Metadata = new BeatmapMetadata(), - HitObjects = new List(), - ControlPoints = new List(), - }; - var section = Section.None; - string line; + { + var beatmap = new Beatmap + { + Metadata = new BeatmapMetadata(), + BaseDifficulty = new BaseDifficulty(), + HitObjects = new List(), + ControlPoints = new List(), + }; + var section = Section.None; + string line; while (true) - { - line = stream.ReadLine(); + { + line = stream.ReadLine(); if (line == null) - break; - line = line.Trim(); - if (string.IsNullOrEmpty(line)) - continue; - - if (line.StartsWith("[") && line.EndsWith("]")) - { - if (!Enum.TryParse(line.Substring(1, line.Length - 2), out section)) - throw new InvalidOperationException($@"Unknown osu section {line}"); - continue; - } - - string val = line, key = null; - if (section != Section.Events && section != Section.TimingPoints + break; + line = line.Trim(); + if (string.IsNullOrEmpty(line)) + continue; + + if (line.StartsWith("[") && line.EndsWith("]")) + { + if (!Enum.TryParse(line.Substring(1, line.Length - 2), out section)) + throw new InvalidDataException($@"Unknown osu section {line}"); + continue; + } + + string val = line, key = null; + if (section != Section.Events && section != Section.TimingPoints && section != Section.HitObjects) - { - key = val.Remove(val.IndexOf(':')).Trim(); + { + key = val.Remove(val.IndexOf(':')).Trim(); val = val.Substring(val.IndexOf(':') + 1).Trim(); - } - switch (section) - { - case Section.General: - HandleGeneral(beatmap, key, val); - break; - case Section.Editor: - // TODO - break; - case Section.Metadata: + } + switch (section) + { + case Section.General: + HandleGeneral(beatmap, key, val); + break; + case Section.Editor: // TODO - break; - case Section.Difficulty: - // TODO - break; - case Section.Events: + break; + case Section.Metadata: + HandleMetadata(beatmap, key, val); + break; + case Section.Difficulty: // TODO - break; - case Section.TimingPoints: + break; + case Section.Events: + HandleEvents(beatmap, val); + break; + case Section.TimingPoints: // TODO - break; - case Section.HitObjects: + break; + case Section.HitObjects: // TODO - break; - } - } - return beatmap; - } - } + break; + } + } + return beatmap; + } + } } \ No newline at end of file diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index fced014b07..285e635012 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -169,6 +169,7 @@ + @@ -191,6 +192,7 @@ + + + + + + + + diff --git a/osu.Game.Tests/osu.Game.Tests.csproj b/osu.Game.Tests/osu.Game.Tests.csproj index d61d98434a..36044b4bbf 100644 --- a/osu.Game.Tests/osu.Game.Tests.csproj +++ b/osu.Game.Tests/osu.Game.Tests.csproj @@ -31,9 +31,15 @@ ..\packages\NUnit.2.6.4\lib\nunit.framework.dll + + ..\packages\ppy.OpenTK.1.1.2225.3\lib\net20\OpenTK.dll + + + + diff --git a/osu.Game.Tests/packages.config b/osu.Game.Tests/packages.config index c714ef3a23..46387efcc6 100644 --- a/osu.Game.Tests/packages.config +++ b/osu.Game.Tests/packages.config @@ -1,4 +1,5 @@  + \ No newline at end of file diff --git a/osu.Game/Beatmaps/Beatmap.cs b/osu.Game/Beatmaps/Beatmap.cs index c1f3d7f744..99199e421c 100644 --- a/osu.Game/Beatmaps/Beatmap.cs +++ b/osu.Game/Beatmaps/Beatmap.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; +using OpenTK.Graphics; using osu.Game.Beatmaps.Objects; using osu.Game.Beatmaps.Samples; using osu.Game.Beatmaps.Timing; @@ -29,6 +30,8 @@ namespace osu.Game.Beatmaps public BeatmapMetadata Metadata { get; set; } [Ignore] public BaseDifficulty BaseDifficulty { get; set; } + [Ignore] + public List ComboColors { get; set; } // General public int AudioLeadIn { get; set; } diff --git a/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs b/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs index 1a3ea5a53e..e900038120 100644 --- a/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs +++ b/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.IO; +using OpenTK.Graphics; using osu.Game.Beatmaps.Events; using osu.Game.Beatmaps.Objects; using osu.Game.Beatmaps.Samples; @@ -180,6 +181,24 @@ namespace osu.Game.Beatmaps.Formats // TODO } + private void HandleColours(Beatmap beatmap, string key, string val) + { + string[] split = val.Split(','); + if (split.Length != 3) + throw new InvalidOperationException($@"Color specified in incorrect format (should be R,G,B): {val}"); + byte r, g, b; + if (!byte.TryParse(split[0], out r) || !byte.TryParse(split[1], out g) || !byte.TryParse(split[2], out b)) + throw new InvalidOperationException($@"Color must be specified with 8-bit integer components"); + // Note: the combo index specified in the beatmap is discarded + beatmap.ComboColors.Add(new Color4 + { + R = r / 255f, + G = g / 255f, + B = b / 255f, + A = 1f, + }); + } + public override Beatmap Decode(TextReader stream) { var beatmap = new Beatmap @@ -188,6 +207,7 @@ namespace osu.Game.Beatmaps.Formats BaseDifficulty = new BaseDifficulty(), HitObjects = new List(), ControlPoints = new List(), + ComboColors = new List(), }; var section = Section.None; string line; @@ -210,8 +230,7 @@ namespace osu.Game.Beatmaps.Formats } string val = line, key = null; - if (section != Section.Events && section != Section.TimingPoints - && section != Section.HitObjects) + if (section != Section.Events && section != Section.TimingPoints && section != Section.HitObjects) { key = val.Remove(val.IndexOf(':')).Trim(); val = val.Substring(val.IndexOf(':') + 1).Trim(); @@ -236,6 +255,9 @@ namespace osu.Game.Beatmaps.Formats case Section.TimingPoints: HandleTimingPoints(beatmap, val); break; + case Section.Colours: + HandleColours(beatmap, key, val); + break; case Section.HitObjects: beatmap.HitObjects.Add(HitObject.Parse(beatmap.Mode, val)); break; From c39179d299dd98ec15127a36a9713c6677f663f6 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Mon, 10 Oct 2016 13:08:07 -0400 Subject: [PATCH 20/33] Add test for hit objects --- .../Beatmaps/Formats/OsuLegacyDecoderTest.cs | 37 +++++++++++++++---- osu.Game/Beatmaps/Objects/Osu/OsuBaseHit.cs | 2 +- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/osu.Game.Tests/Beatmaps/Formats/OsuLegacyDecoderTest.cs b/osu.Game.Tests/Beatmaps/Formats/OsuLegacyDecoderTest.cs index d5b9e46183..7eddb2a7dc 100644 --- a/osu.Game.Tests/Beatmaps/Formats/OsuLegacyDecoderTest.cs +++ b/osu.Game.Tests/Beatmaps/Formats/OsuLegacyDecoderTest.cs @@ -1,8 +1,10 @@ using System; using System.IO; using NUnit.Framework; +using OpenTK; using OpenTK.Graphics; using osu.Game.Beatmaps.Formats; +using osu.Game.Beatmaps.Objects.Osu; using osu.Game.Beatmaps.Samples; using osu.Game.GameModes.Play; using osu.Game.Tests.Resources; @@ -37,8 +39,8 @@ namespace osu.Game.Tests.Beatmaps.Formats Assert.AreEqual("Renatus", meta.Title); Assert.AreEqual("Renatus", meta.TitleUnicode); } - } - + } + [Test] public void TestDecodeGeneral() { @@ -55,8 +57,8 @@ namespace osu.Game.Tests.Beatmaps.Formats Assert.AreEqual(false, beatmap.LetterboxInBreaks); Assert.AreEqual(false, beatmap.WidescreenStoryboard); } - } - + } + [Test] public void TestDecodeEditor() { @@ -78,8 +80,8 @@ namespace osu.Game.Tests.Beatmaps.Formats Assert.AreEqual(4, beatmap.GridSize); Assert.AreEqual(2, beatmap.TimelineZoom); } - } - + } + [Test] public void TestDecodeDifficulty() { @@ -95,8 +97,8 @@ namespace osu.Game.Tests.Beatmaps.Formats Assert.AreEqual(1.8f, difficulty.SliderMultiplier); Assert.AreEqual(2, difficulty.SliderTickRate); } - } - + } + [Test] public void TestDecodeColors() { @@ -117,6 +119,25 @@ namespace osu.Game.Tests.Beatmaps.Formats for (int i = 0; i < expected.Length; i++) Assert.AreEqual(expected[i], beatmap.ComboColors[i]); } + } + + [Test] public void TestDecodeHitObjects() + { + var decoder = new OsuLegacyDecoder(); + using (var stream = Resource.OpenResource("Soleily - Renatus (Gamu) [Insane].osu")) + { + var beatmap = decoder.Decode(new StreamReader(stream)); + var slider = beatmap.HitObjects[0] as Slider; + Assert.IsNotNull(slider); + Assert.AreEqual(new Vector2(192, 168), slider.Position); + Assert.AreEqual(956, slider.StartTime); + Assert.AreEqual(SampleType.None, slider.Sample.Type); + var circle = beatmap.HitObjects[1] as Circle; + Assert.IsNotNull(circle); + Assert.AreEqual(new Vector2(304, 56), circle.Position); + Assert.AreEqual(1285, circle.StartTime); + Assert.AreEqual(SampleType.Clap, circle.Sample.Type); + } } } } \ No newline at end of file diff --git a/osu.Game/Beatmaps/Objects/Osu/OsuBaseHit.cs b/osu.Game/Beatmaps/Objects/Osu/OsuBaseHit.cs index 1f069677c9..7db848eeaf 100644 --- a/osu.Game/Beatmaps/Objects/Osu/OsuBaseHit.cs +++ b/osu.Game/Beatmaps/Objects/Osu/OsuBaseHit.cs @@ -44,7 +44,7 @@ namespace osu.Game.Beatmaps.Objects.Osu } result.Position = new Vector2(int.Parse(split[0]), int.Parse(split[1])); result.StartTime = double.Parse(split[2]); - result.Sample = new HitSampleInfo { Type = (SampleType)int.Parse(split[3]) }; + result.Sample = new HitSampleInfo { Type = (SampleType)int.Parse(split[4]) }; result.NewCombo = combo; // TODO: "addition" field return result; From dc4bd48f29b612486285e166a267b67fd3108ab7 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Mon, 10 Oct 2016 13:55:58 -0400 Subject: [PATCH 21/33] Fix casing issues Cheers @RemieRichards --- osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs b/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs index e900038120..982b1f8bbc 100644 --- a/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs +++ b/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs @@ -35,7 +35,7 @@ namespace osu.Game.Beatmaps.Formats HitObjects, } - private void HandleGeneral(Beatmap beatmap, string key, string val) + private void handleGeneral(Beatmap beatmap, string key, string val) { switch (key) { @@ -72,7 +72,7 @@ namespace osu.Game.Beatmaps.Formats } } - private void HandleEditor(Beatmap beatmap, string key, string val) + private void handleEditor(Beatmap beatmap, string key, string val) { switch (key) { @@ -94,7 +94,7 @@ namespace osu.Game.Beatmaps.Formats } } - private void HandleMetadata(Beatmap beatmap, string key, string val) + private void handleMetadata(Beatmap beatmap, string key, string val) { switch (key) { @@ -132,7 +132,7 @@ namespace osu.Game.Beatmaps.Formats } } - private void HandleDifficulty(Beatmap beatmap, string key, string val) + private void handleDifficulty(Beatmap beatmap, string key, string val) { switch (key) { @@ -157,7 +157,7 @@ namespace osu.Game.Beatmaps.Formats } } - private void HandleEvents(Beatmap beatmap, string val) + private void handleEvents(Beatmap beatmap, string val) { if (val.StartsWith("//")) return; @@ -176,12 +176,12 @@ namespace osu.Game.Beatmaps.Formats beatmap.Metadata.BackgroundFile = split[2].Trim('"'); } - private void HandleTimingPoints(Beatmap beatmap, string val) + private void handleTimingPoints(Beatmap beatmap, string val) { // TODO } - private void HandleColours(Beatmap beatmap, string key, string val) + private void handleColours(Beatmap beatmap, string key, string val) { string[] split = val.Split(','); if (split.Length != 3) @@ -238,25 +238,25 @@ namespace osu.Game.Beatmaps.Formats switch (section) { case Section.General: - HandleGeneral(beatmap, key, val); + handleGeneral(beatmap, key, val); break; case Section.Editor: - HandleEditor(beatmap, key, val); + handleEditor(beatmap, key, val); break; case Section.Metadata: - HandleMetadata(beatmap, key, val); + handleMetadata(beatmap, key, val); break; case Section.Difficulty: - HandleDifficulty(beatmap, key, val); + handleDifficulty(beatmap, key, val); break; case Section.Events: - HandleEvents(beatmap, val); + handleEvents(beatmap, val); break; case Section.TimingPoints: - HandleTimingPoints(beatmap, val); + handleTimingPoints(beatmap, val); break; case Section.Colours: - HandleColours(beatmap, key, val); + handleColours(beatmap, key, val); break; case Section.HitObjects: beatmap.HitObjects.Add(HitObject.Parse(beatmap.Mode, val)); From 880399f5a5b89a6520692779d35d90b75e14d4d9 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Mon, 10 Oct 2016 14:00:33 -0400 Subject: [PATCH 22/33] Fix casing on private properties --- .../Beatmaps/IO/LegacyFilesystemReader.cs | 22 ++++++++-------- osu.Game/Beatmaps/Formats/BeatmapDecoder.cs | 8 +++--- osu.Game/Beatmaps/IO/ArchiveReader.cs | 6 ++--- osu.Game/Beatmaps/IO/OszArchiveReader.cs | 26 +++++++++---------- osu.Game/Database/BeatmapDatabase.cs | 24 ++++++++--------- 5 files changed, 43 insertions(+), 43 deletions(-) diff --git a/osu.Desktop/Beatmaps/IO/LegacyFilesystemReader.cs b/osu.Desktop/Beatmaps/IO/LegacyFilesystemReader.cs index e899673fef..bb26d2d63b 100644 --- a/osu.Desktop/Beatmaps/IO/LegacyFilesystemReader.cs +++ b/osu.Desktop/Beatmaps/IO/LegacyFilesystemReader.cs @@ -18,36 +18,36 @@ namespace osu.Desktop.Beatmaps.IO AddReader((storage, path) => Directory.Exists(path)); } - private string BasePath { get; set; } - private string[] Beatmaps { get; set; } - private Beatmap FirstMap { get; set; } + private string basePath { get; set; } + private string[] beatmaps { get; set; } + private Beatmap firstMap { get; set; } public LegacyFilesystemReader(string path) { - BasePath = path; - Beatmaps = Directory.GetFiles(BasePath, "*.osu").Select(f => Path.GetFileName(f)).ToArray(); - if (Beatmaps.Length == 0) + basePath = path; + beatmaps = Directory.GetFiles(basePath, "*.osu").Select(f => Path.GetFileName(f)).ToArray(); + if (beatmaps.Length == 0) throw new FileNotFoundException("This directory contains no beatmaps"); - using (var stream = new StreamReader(ReadFile(Beatmaps[0]))) + using (var stream = new StreamReader(ReadFile(beatmaps[0]))) { var decoder = BeatmapDecoder.GetDecoder(stream); - FirstMap = decoder.Decode(stream); + firstMap = decoder.Decode(stream); } } public override string[] ReadBeatmaps() { - return Beatmaps; + return beatmaps; } public override Stream ReadFile(string name) { - return File.OpenRead(Path.Combine(BasePath, name)); + return File.OpenRead(Path.Combine(basePath, name)); } public override BeatmapMetadata ReadMetadata() { - return FirstMap.Metadata; + return firstMap.Metadata; } public override void Dispose() diff --git a/osu.Game/Beatmaps/Formats/BeatmapDecoder.cs b/osu.Game/Beatmaps/Formats/BeatmapDecoder.cs index 2fb653a767..d6c792e06c 100644 --- a/osu.Game/Beatmaps/Formats/BeatmapDecoder.cs +++ b/osu.Game/Beatmaps/Formats/BeatmapDecoder.cs @@ -6,18 +6,18 @@ namespace osu.Game.Beatmaps.Formats { public abstract class BeatmapDecoder { - private static Dictionary Decoders { get; set; } = new Dictionary(); + private static Dictionary decoders { get; set; } = new Dictionary(); public static BeatmapDecoder GetDecoder(TextReader stream) { var line = stream.ReadLine().Trim(); - if (!Decoders.ContainsKey(line)) + if (!decoders.ContainsKey(line)) throw new IOException("Unknown file format"); - return (BeatmapDecoder)Activator.CreateInstance(Decoders[line]); + return (BeatmapDecoder)Activator.CreateInstance(decoders[line]); } protected static void AddDecoder(string magic) where T : BeatmapDecoder { - Decoders[magic] = typeof(T); + decoders[magic] = typeof(T); } public abstract Beatmap Decode(TextReader stream); diff --git a/osu.Game/Beatmaps/IO/ArchiveReader.cs b/osu.Game/Beatmaps/IO/ArchiveReader.cs index 2324236ba1..292973a275 100644 --- a/osu.Game/Beatmaps/IO/ArchiveReader.cs +++ b/osu.Game/Beatmaps/IO/ArchiveReader.cs @@ -13,11 +13,11 @@ namespace osu.Game.Beatmaps.IO public Type Type { get; set; } } - private static List Readers { get; set; } = new List(); + private static List readers { get; set; } = new List(); public static ArchiveReader GetReader(BasicStorage storage, string path) { - foreach (var reader in Readers) + foreach (var reader in readers) { if (reader.Test(storage, path)) return (ArchiveReader)Activator.CreateInstance(reader.Type); @@ -27,7 +27,7 @@ namespace osu.Game.Beatmaps.IO protected static void AddReader(Func test) where T : ArchiveReader { - Readers.Add(new Reader { Test = test, Type = typeof(T) }); + readers.Add(new Reader { Test = test, Type = typeof(T) }); } /// diff --git a/osu.Game/Beatmaps/IO/OszArchiveReader.cs b/osu.Game/Beatmaps/IO/OszArchiveReader.cs index e75215949f..c61a49cb03 100644 --- a/osu.Game/Beatmaps/IO/OszArchiveReader.cs +++ b/osu.Game/Beatmaps/IO/OszArchiveReader.cs @@ -23,32 +23,32 @@ namespace osu.Game.Beatmaps.IO OsuLegacyDecoder.Register(); } - private ZipFile Archive { get; set; } - private string[] Beatmaps { get; set; } - private Beatmap FirstMap { get; set; } + private ZipFile archive { get; set; } + private string[] beatmaps { get; set; } + private Beatmap firstMap { get; set; } - public OszArchiveReader(Stream archive) + public OszArchiveReader(Stream archiveStream) { - Archive = ZipFile.Read(archive); - Beatmaps = Archive.Entries.Where(e => e.FileName.EndsWith(".osu")) + archive = ZipFile.Read(archiveStream); + beatmaps = archive.Entries.Where(e => e.FileName.EndsWith(".osu")) .Select(e => e.FileName).ToArray(); - if (Beatmaps.Length == 0) + if (beatmaps.Length == 0) throw new FileNotFoundException("This directory contains no beatmaps"); - using (var stream = new StreamReader(ReadFile(Beatmaps[0]))) + using (var stream = new StreamReader(ReadFile(beatmaps[0]))) { var decoder = BeatmapDecoder.GetDecoder(stream); - FirstMap = decoder.Decode(stream); + firstMap = decoder.Decode(stream); } } public override string[] ReadBeatmaps() { - return Beatmaps; + return beatmaps; } public override Stream ReadFile(string name) { - ZipEntry entry = Archive.Entries.SingleOrDefault(e => e.FileName == name); + ZipEntry entry = archive.Entries.SingleOrDefault(e => e.FileName == name); if (entry == null) throw new FileNotFoundException(); return entry.OpenReader(); @@ -56,11 +56,11 @@ namespace osu.Game.Beatmaps.IO public override BeatmapMetadata ReadMetadata() { - return FirstMap.Metadata; + return firstMap.Metadata; } public override void Dispose() { - Archive.Dispose(); + archive.Dispose(); } } } \ No newline at end of file diff --git a/osu.Game/Database/BeatmapDatabase.cs b/osu.Game/Database/BeatmapDatabase.cs index c7f09ebadb..36f8776eb0 100644 --- a/osu.Game/Database/BeatmapDatabase.cs +++ b/osu.Game/Database/BeatmapDatabase.cs @@ -11,23 +11,23 @@ namespace osu.Game.Database { public class BeatmapDatabase { - private static SQLiteConnection Connection { get; set; } + private static SQLiteConnection connection { get; set; } public BeatmapDatabase(BasicStorage storage) { - if (Connection == null) + if (connection == null) { - Connection = storage.GetDatabase(@"beatmaps"); - Connection.CreateTable(); - Connection.CreateTable(); - Connection.CreateTable(); - Connection.CreateTable(); + connection = storage.GetDatabase(@"beatmaps"); + connection.CreateTable(); + connection.CreateTable(); + connection.CreateTable(); + connection.CreateTable(); } } public void AddBeatmap(ArchiveReader input) { var metadata = input.ReadMetadata(); - if (Connection.Table().Count(b => b.BeatmapSetID == metadata.BeatmapSetID) != 0) + if (connection.Table().Count(b => b.BeatmapSetID == metadata.BeatmapSetID) != 0) return; string[] mapNames = input.ReadBeatmaps(); var beatmapSet = new BeatmapSet { BeatmapSetID = metadata.BeatmapSetID }; @@ -39,12 +39,12 @@ namespace osu.Game.Database var decoder = BeatmapDecoder.GetDecoder(stream); var beatmap = decoder.Decode(stream); maps.Add(beatmap); - beatmap.BaseDifficultyID = Connection.Insert(beatmap.BaseDifficulty); + beatmap.BaseDifficultyID = connection.Insert(beatmap.BaseDifficulty); } } - beatmapSet.BeatmapMetadataID = Connection.Insert(metadata); - Connection.Insert(beatmapSet); - Connection.InsertAll(maps); + beatmapSet.BeatmapMetadataID = connection.Insert(metadata); + connection.Insert(beatmapSet); + connection.InsertAll(maps); } } } \ No newline at end of file From c7d12bc07217a01066a3ac17ba646bd8142bd656 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Mon, 10 Oct 2016 14:35:44 -0400 Subject: [PATCH 23/33] Remove unnecessary setters --- osu.Game/Beatmaps/Formats/BeatmapDecoder.cs | 2 +- osu.Game/Beatmaps/IO/ArchiveReader.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Game/Beatmaps/Formats/BeatmapDecoder.cs b/osu.Game/Beatmaps/Formats/BeatmapDecoder.cs index d6c792e06c..91e647964a 100644 --- a/osu.Game/Beatmaps/Formats/BeatmapDecoder.cs +++ b/osu.Game/Beatmaps/Formats/BeatmapDecoder.cs @@ -6,7 +6,7 @@ namespace osu.Game.Beatmaps.Formats { public abstract class BeatmapDecoder { - private static Dictionary decoders { get; set; } = new Dictionary(); + private static Dictionary decoders { get; } = new Dictionary(); public static BeatmapDecoder GetDecoder(TextReader stream) { diff --git a/osu.Game/Beatmaps/IO/ArchiveReader.cs b/osu.Game/Beatmaps/IO/ArchiveReader.cs index 292973a275..8fe3df0685 100644 --- a/osu.Game/Beatmaps/IO/ArchiveReader.cs +++ b/osu.Game/Beatmaps/IO/ArchiveReader.cs @@ -13,7 +13,7 @@ namespace osu.Game.Beatmaps.IO public Type Type { get; set; } } - private static List readers { get; set; } = new List(); + private static List readers { get; } = new List(); public static ArchiveReader GetReader(BasicStorage storage, string path) { From 94f2898f52a60a8bde8e9136facce05fa2c79281 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Mon, 10 Oct 2016 16:56:01 -0400 Subject: [PATCH 24/33] Implement beatmap sending/receiving over IPC --- osu-framework | 2 +- osu.Desktop/Program.cs | 2 +- osu.Desktop/osu.Desktop.csproj | 1 + osu.Game/OsuGame.cs | 33 +++++++++++++++++++++++++++++++++ osu.sln | 1 + 5 files changed, 37 insertions(+), 2 deletions(-) diff --git a/osu-framework b/osu-framework index 7439250a63..aa96aeec4a 160000 --- a/osu-framework +++ b/osu-framework @@ -1 +1 @@ -Subproject commit 7439250a63dd451f34dbc08ecf68a196cf8e479f +Subproject commit aa96aeec4a1da743b5b997844b9107ea94b9b8de diff --git a/osu.Desktop/Program.cs b/osu.Desktop/Program.cs index 0af085dce0..a1a29b918f 100644 --- a/osu.Desktop/Program.cs +++ b/osu.Desktop/Program.cs @@ -14,7 +14,7 @@ namespace osu.Desktop public static void Main(string[] args) { BasicGameHost host = Host.GetSuitableHost(@"osu"); - host.Add(new OsuGame()); + host.Add(new OsuGame(args)); host.Run(); } } diff --git a/osu.Desktop/osu.Desktop.csproj b/osu.Desktop/osu.Desktop.csproj index d8463dbc35..86ca44e381 100644 --- a/osu.Desktop/osu.Desktop.csproj +++ b/osu.Desktop/osu.Desktop.csproj @@ -59,6 +59,7 @@ AllRules.ruleset false false + none diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index fa4d5f3a9c..26607e0bf8 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -20,17 +20,30 @@ using osu.Framework; using osu.Framework.Input; using osu.Game.Input; using OpenTK.Input; +using System.IO; namespace osu.Game { public class OsuGame : OsuGameBase { + private class ImportBeatmapIPC + { + public string Path; + } + public Toolbar Toolbar; public ChatConsole Chat; public MainMenu MainMenu => intro?.ChildGameMode as MainMenu; private Intro intro; + private string[] args; + private IPCHost BeatmapIPC; public Bindable PlayMode; + + public OsuGame(string[] args) + { + this.args = args; + } public override void SetHost(BasicGameHost host) { @@ -41,7 +54,27 @@ namespace osu.Game public override void Load(BaseGame game) { +<<<<<<< HEAD base.Load(game); +======= + BeatmapIPC = new IPCHost(Host); + + if (!Host.IsPrimaryInstance) + { + if (args.Length == 1 && File.Exists(args[0])) + { + BeatmapIPC.SendMessage(new ImportBeatmapIPC { Path = args[0] }).Wait(); + Console.WriteLine(@"Sent file to running instance"); + } + else + Console.WriteLine(@"osu! does not support multiple running instances."); + Environment.Exit(0); + } + + BeatmapIPC.MessageReceived += (message) => Console.WriteLine($@"Got beatmap: {message.Path}"); + + base.Load(); +>>>>>>> Implement beatmap sending/receiving over IPC //attach our bindables to the audio subsystem. Audio.Volume.Weld(Config.GetBindable(OsuConfig.VolumeGlobal)); diff --git a/osu.sln b/osu.sln index d9f58def79..8fba171a2f 100644 --- a/osu.sln +++ b/osu.sln @@ -26,6 +26,7 @@ Global Debug|Any CPU = Debug|Any CPU Deploy|Any CPU = Deploy|Any CPU Release|Any CPU = Release|Any CPU + Deploy|Any CPU = Deploy|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {2A66DD92-ADB1-4994-89E2-C94E04ACDA0D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU From 3a163de0f72763450aaaa413b7f90b16ca817893 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Tue, 11 Oct 2016 09:47:50 -0400 Subject: [PATCH 25/33] Follow changes to osu-framework --- osu.Game/OsuGame.cs | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index 26607e0bf8..4a82316849 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -26,7 +26,7 @@ namespace osu.Game { public class OsuGame : OsuGameBase { - private class ImportBeatmapIPC + private class ImportBeatmap { public string Path; } @@ -36,7 +36,7 @@ namespace osu.Game public MainMenu MainMenu => intro?.ChildGameMode as MainMenu; private Intro intro; private string[] args; - private IPCHost BeatmapIPC; + private IPCChannel BeatmapIPC; public Bindable PlayMode; @@ -54,16 +54,13 @@ namespace osu.Game public override void Load(BaseGame game) { -<<<<<<< HEAD - base.Load(game); -======= - BeatmapIPC = new IPCHost(Host); + BeatmapIPC = new IPCChannel(Host); if (!Host.IsPrimaryInstance) { if (args.Length == 1 && File.Exists(args[0])) { - BeatmapIPC.SendMessage(new ImportBeatmapIPC { Path = args[0] }).Wait(); + BeatmapIPC.SendMessage(new ImportBeatmap { Path = args[0] }).Wait(); Console.WriteLine(@"Sent file to running instance"); } else @@ -72,9 +69,8 @@ namespace osu.Game } BeatmapIPC.MessageReceived += (message) => Console.WriteLine($@"Got beatmap: {message.Path}"); - - base.Load(); ->>>>>>> Implement beatmap sending/receiving over IPC + + base.Load(game); //attach our bindables to the audio subsystem. Audio.Volume.Weld(Config.GetBindable(OsuConfig.VolumeGlobal)); From 45c0bc54282cf140cd043855a165d9f872e61448 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Tue, 11 Oct 2016 10:53:16 -0400 Subject: [PATCH 26/33] Import beatmaps into the database via IPC --- osu.Game/Beatmaps/IO/ArchiveReader.cs | 2 +- osu.Game/Beatmaps/IO/OszArchiveReader.cs | 7 +------ osu.Game/Beatmaps/Objects/Osu/OsuBaseHit.cs | 6 ++++++ osu.Game/OsuGame.cs | 18 ++++++++++++++++-- 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/osu.Game/Beatmaps/IO/ArchiveReader.cs b/osu.Game/Beatmaps/IO/ArchiveReader.cs index 8fe3df0685..d9b4295704 100644 --- a/osu.Game/Beatmaps/IO/ArchiveReader.cs +++ b/osu.Game/Beatmaps/IO/ArchiveReader.cs @@ -20,7 +20,7 @@ namespace osu.Game.Beatmaps.IO foreach (var reader in readers) { if (reader.Test(storage, path)) - return (ArchiveReader)Activator.CreateInstance(reader.Type); + return (ArchiveReader)Activator.CreateInstance(reader.Type, storage.GetStream(path)); } throw new IOException("Unknown file format"); } diff --git a/osu.Game/Beatmaps/IO/OszArchiveReader.cs b/osu.Game/Beatmaps/IO/OszArchiveReader.cs index c61a49cb03..d7241d17a1 100644 --- a/osu.Game/Beatmaps/IO/OszArchiveReader.cs +++ b/osu.Game/Beatmaps/IO/OszArchiveReader.cs @@ -13,12 +13,7 @@ namespace osu.Game.Beatmaps.IO AddReader((storage, path) => { using (var stream = storage.GetStream(path)) - { - if (!ZipFile.IsZipFile(stream, false)) - return false; - using (ZipFile zip = ZipFile.Read(stream)) - return zip.Entries.Any(e => e.FileName.EndsWith(".osu")); - } + return ZipFile.IsZipFile(stream, false); }); OsuLegacyDecoder.Register(); } diff --git a/osu.Game/Beatmaps/Objects/Osu/OsuBaseHit.cs b/osu.Game/Beatmaps/Objects/Osu/OsuBaseHit.cs index 7db848eeaf..2f94c70a0e 100644 --- a/osu.Game/Beatmaps/Objects/Osu/OsuBaseHit.cs +++ b/osu.Game/Beatmaps/Objects/Osu/OsuBaseHit.cs @@ -18,7 +18,12 @@ namespace osu.Game.Beatmaps.Objects.Osu Circle = 1, Slider = 2, NewCombo = 4, + CircleNewCombo = 5, + SliderNewCombo = 6, Spinner = 8, + ColourHax = 122, + Hold = 128, + ManiaLong = 128, } public static OsuBaseHit Parse(string val) @@ -26,6 +31,7 @@ namespace osu.Game.Beatmaps.Objects.Osu string[] split = val.Split(','); var type = (HitObjectType)int.Parse(split[3]); bool combo = type.HasFlag(HitObjectType.NewCombo); + type &= (HitObjectType)0xF; type &= ~HitObjectType.NewCombo; OsuBaseHit result; switch (type) diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index 4a82316849..42b5535072 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -21,6 +21,7 @@ using osu.Framework.Input; using osu.Game.Input; using OpenTK.Input; using System.IO; +using osu.Game.Beatmaps.IO; namespace osu.Game { @@ -68,8 +69,21 @@ namespace osu.Game Environment.Exit(0); } - BeatmapIPC.MessageReceived += (message) => Console.WriteLine($@"Got beatmap: {message.Path}"); - + BeatmapIPC.MessageReceived += message => + { + try + { + var reader = ArchiveReader.GetReader(Host.Storage, message.Path); + Beatmaps.AddBeatmap(reader); + // TODO: Switch to beatmap list and select the new song + } + catch (Exception ex) + { + // TODO: Show the user some info? + Console.WriteLine($@"Failed to import beatmap: {ex}"); + } + }; + base.Load(game); //attach our bindables to the audio subsystem. From ddac0e8c8f26a2a9f23c0e4dca73772bb011c9c2 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Wed, 12 Oct 2016 11:31:44 -0400 Subject: [PATCH 27/33] Update osu-framework --- osu-framework | 2 +- osu.Game/OsuGame.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/osu-framework b/osu-framework index aa96aeec4a..6115acdeff 160000 --- a/osu-framework +++ b/osu-framework @@ -1 +1 @@ -Subproject commit aa96aeec4a1da743b5b997844b9107ea94b9b8de +Subproject commit 6115acdeffbba5f35aa2ef20d4ec69b06a4116c0 diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index 42b5535072..9eb32117c5 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -37,7 +37,7 @@ namespace osu.Game public MainMenu MainMenu => intro?.ChildGameMode as MainMenu; private Intro intro; private string[] args; - private IPCChannel BeatmapIPC; + private IpcChannel BeatmapIPC; public Bindable PlayMode; @@ -55,7 +55,7 @@ namespace osu.Game public override void Load(BaseGame game) { - BeatmapIPC = new IPCChannel(Host); + BeatmapIPC = new IpcChannel(Host); if (!Host.IsPrimaryInstance) { From 2f8fbee36403c3c6f9be6ae60d6b5aacdf2b5106 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Wed, 12 Oct 2016 11:38:43 -0400 Subject: [PATCH 28/33] Moved test osz file into osu-resources --- osu-resources | 2 +- osu.Game.Tests/Beatmaps/IO/OszArchiveReaderTest.cs | 6 +++--- osu.Game.Tests/Resources/Resource.cs | 4 +++- osu.Game.Tests/osu.Game.Tests.csproj | 5 ++++- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/osu-resources b/osu-resources index 6d9bbe6c83..0505cf0d3b 160000 --- a/osu-resources +++ b/osu-resources @@ -1 +1 @@ -Subproject commit 6d9bbe6c838e4b89b69d5ad49b37b434aa62281e +Subproject commit 0505cf0d3b317667dbc95346f57b67fdbcdb4dee diff --git a/osu.Game.Tests/Beatmaps/IO/OszArchiveReaderTest.cs b/osu.Game.Tests/Beatmaps/IO/OszArchiveReaderTest.cs index 8de6a39e84..e224bf3db4 100644 --- a/osu.Game.Tests/Beatmaps/IO/OszArchiveReaderTest.cs +++ b/osu.Game.Tests/Beatmaps/IO/OszArchiveReaderTest.cs @@ -19,7 +19,7 @@ namespace osu.Game.Tests.Beatmaps.IO [Test] public void TestReadBeatmaps() { - using (var osz = Resource.OpenResource("241526 Soleily - Renatus.osz")) + using (var osz = Resource.OpenResource("Beatmaps.241526 Soleily - Renatus.osz")) { var reader = new OszArchiveReader(osz); string[] expected = @@ -46,7 +46,7 @@ namespace osu.Game.Tests.Beatmaps.IO [Test] public void TestReadMetadata() { - using (var osz = Resource.OpenResource("241526 Soleily - Renatus.osz")) + using (var osz = Resource.OpenResource("Beatmaps.241526 Soleily - Renatus.osz")) { var reader = new OszArchiveReader(osz); var meta = reader.ReadMetadata(); @@ -66,7 +66,7 @@ namespace osu.Game.Tests.Beatmaps.IO [Test] public void TestReadFile() { - using (var osz = Resource.OpenResource("241526 Soleily - Renatus.osz")) + using (var osz = Resource.OpenResource("Beatmaps.241526 Soleily - Renatus.osz")) { var reader = new OszArchiveReader(osz); using (var stream = new StreamReader( diff --git a/osu.Game.Tests/Resources/Resource.cs b/osu.Game.Tests/Resources/Resource.cs index 72858e449e..46c51da5ef 100644 --- a/osu.Game.Tests/Resources/Resource.cs +++ b/osu.Game.Tests/Resources/Resource.cs @@ -9,7 +9,9 @@ namespace osu.Game.Tests.Resources public static Stream OpenResource(string name) { return Assembly.GetExecutingAssembly().GetManifestResourceStream( - $@"osu.Game.Tests.Resources.{name}"); + $@"osu.Game.Tests.Resources.{name}") ?? + Assembly.LoadFrom("osu.Game.Resources.dll").GetManifestResourceStream( + $@"osu.Game.Resources.{name}"); } } } \ No newline at end of file diff --git a/osu.Game.Tests/osu.Game.Tests.csproj b/osu.Game.Tests/osu.Game.Tests.csproj index 36044b4bbf..915f91829b 100644 --- a/osu.Game.Tests/osu.Game.Tests.csproj +++ b/osu.Game.Tests/osu.Game.Tests.csproj @@ -46,6 +46,10 @@ {0D3FBF8A-7464-4CF7-8C90-3E7886DF2D4D} osu.Game + + {D9A367C9-4C1A-489F-9B05-A0CEA2B53B58} + osu.Game.Resources + @@ -59,7 +63,6 @@ - From 10b5e2a89d54e35ffe9e5a6f47bd93eab7b43f16 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Wed, 12 Oct 2016 12:45:49 -0400 Subject: [PATCH 29/33] Update osu-framework --- osu-framework | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu-framework b/osu-framework index 6115acdeff..03730d016d 160000 --- a/osu-framework +++ b/osu-framework @@ -1 +1 @@ -Subproject commit 6115acdeffbba5f35aa2ef20d4ec69b06a4116c0 +Subproject commit 03730d016d5d5ebd8ebda003dcae3ca3c35536c4 From dd86e75ea7770ad2c091e8fd35c985b5b53e0996 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Wed, 12 Oct 2016 13:26:09 -0400 Subject: [PATCH 30/33] Minor fixes --- osu.Game.Tests/osu.Game.Tests.csproj | 6 +++--- osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs | 21 +++++++++++-------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/osu.Game.Tests/osu.Game.Tests.csproj b/osu.Game.Tests/osu.Game.Tests.csproj index 915f91829b..531e89230b 100644 --- a/osu.Game.Tests/osu.Game.Tests.csproj +++ b/osu.Game.Tests/osu.Game.Tests.csproj @@ -29,10 +29,10 @@ - ..\packages\NUnit.2.6.4\lib\nunit.framework.dll + $(SolutionDir)\packages\NUnit.2.6.4\lib\nunit.framework.dll - ..\packages\ppy.OpenTK.1.1.2225.3\lib\net20\OpenTK.dll + $(SolutionDir)\packages\ppy.OpenTK.1.1.2225.3\lib\net20\OpenTK.dll @@ -66,4 +66,4 @@ - \ No newline at end of file + diff --git a/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs b/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs index 982b1f8bbc..eeda4e46f8 100644 --- a/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs +++ b/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Globalization; using System.IO; using OpenTK.Graphics; using osu.Game.Beatmaps.Events; @@ -55,7 +56,7 @@ namespace osu.Game.Beatmaps.Formats beatmap.SampleSet = (SampleSet)Enum.Parse(typeof(SampleSet), val); break; case "StackLeniency": - beatmap.StackLeniency = float.Parse(val); + beatmap.StackLeniency = float.Parse(val, NumberFormatInfo.InvariantInfo); break; case "Mode": beatmap.Mode = (PlayMode)int.Parse(val); @@ -80,7 +81,7 @@ namespace osu.Game.Beatmaps.Formats beatmap.StoredBookmarks = val; break; case "DistanceSpacing": - beatmap.DistanceSpacing = double.Parse(val); + beatmap.DistanceSpacing = double.Parse(val, NumberFormatInfo.InvariantInfo); break; case "BeatDivisor": beatmap.BeatDivisor = int.Parse(val); @@ -89,7 +90,7 @@ namespace osu.Game.Beatmaps.Formats beatmap.GridSize = int.Parse(val); break; case "TimelineZoom": - beatmap.TimelineZoom = double.Parse(val); + beatmap.TimelineZoom = double.Parse(val, NumberFormatInfo.InvariantInfo); break; } } @@ -137,22 +138,22 @@ namespace osu.Game.Beatmaps.Formats switch (key) { case "HPDrainRate": - beatmap.BaseDifficulty.DrainRate = float.Parse(val); + beatmap.BaseDifficulty.DrainRate = float.Parse(val, NumberFormatInfo.InvariantInfo); break; case "CircleSize": - beatmap.BaseDifficulty.CircleSize = float.Parse(val); + beatmap.BaseDifficulty.CircleSize = float.Parse(val, NumberFormatInfo.InvariantInfo); break; case "OverallDifficulty": - beatmap.BaseDifficulty.OverallDifficulty = float.Parse(val); + beatmap.BaseDifficulty.OverallDifficulty = float.Parse(val, NumberFormatInfo.InvariantInfo); break; case "ApproachRate": - beatmap.BaseDifficulty.ApproachRate = float.Parse(val); + beatmap.BaseDifficulty.ApproachRate = float.Parse(val, NumberFormatInfo.InvariantInfo); break; case "SliderMultiplier": - beatmap.BaseDifficulty.SliderMultiplier = float.Parse(val); + beatmap.BaseDifficulty.SliderMultiplier = float.Parse(val, NumberFormatInfo.InvariantInfo); break; case "SliderTickRate": - beatmap.BaseDifficulty.SliderTickRate = float.Parse(val); + beatmap.BaseDifficulty.SliderTickRate = float.Parse(val, NumberFormatInfo.InvariantInfo); break; } } @@ -161,6 +162,8 @@ namespace osu.Game.Beatmaps.Formats { if (val.StartsWith("//")) return; + if (val.StartsWith(" ")) + return; // TODO string[] split = val.Split(','); EventType type; int _type; From deff5ad61e30d44f9fa3c823db1092fbb94c9589 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Wed, 12 Oct 2016 13:36:10 -0400 Subject: [PATCH 31/33] Use @strings where appropriate --- .../Beatmaps/IO/LegacyFilesystemReader.cs | 4 +- osu.Game/Beatmaps/Formats/BeatmapDecoder.cs | 2 +- osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs | 80 +++++++++---------- osu.Game/Beatmaps/IO/ArchiveReader.cs | 2 +- osu.Game/Beatmaps/IO/OszArchiveReader.cs | 4 +- 5 files changed, 46 insertions(+), 46 deletions(-) diff --git a/osu.Desktop/Beatmaps/IO/LegacyFilesystemReader.cs b/osu.Desktop/Beatmaps/IO/LegacyFilesystemReader.cs index bb26d2d63b..a6367ebfab 100644 --- a/osu.Desktop/Beatmaps/IO/LegacyFilesystemReader.cs +++ b/osu.Desktop/Beatmaps/IO/LegacyFilesystemReader.cs @@ -25,9 +25,9 @@ namespace osu.Desktop.Beatmaps.IO public LegacyFilesystemReader(string path) { basePath = path; - beatmaps = Directory.GetFiles(basePath, "*.osu").Select(f => Path.GetFileName(f)).ToArray(); + beatmaps = Directory.GetFiles(basePath, @"*.osu").Select(f => Path.GetFileName(f)).ToArray(); if (beatmaps.Length == 0) - throw new FileNotFoundException("This directory contains no beatmaps"); + throw new FileNotFoundException(@"This directory contains no beatmaps"); using (var stream = new StreamReader(ReadFile(beatmaps[0]))) { var decoder = BeatmapDecoder.GetDecoder(stream); diff --git a/osu.Game/Beatmaps/Formats/BeatmapDecoder.cs b/osu.Game/Beatmaps/Formats/BeatmapDecoder.cs index 91e647964a..7302e2a4c5 100644 --- a/osu.Game/Beatmaps/Formats/BeatmapDecoder.cs +++ b/osu.Game/Beatmaps/Formats/BeatmapDecoder.cs @@ -12,7 +12,7 @@ namespace osu.Game.Beatmaps.Formats { var line = stream.ReadLine().Trim(); if (!decoders.ContainsKey(line)) - throw new IOException("Unknown file format"); + throw new IOException(@"Unknown file format"); return (BeatmapDecoder)Activator.CreateInstance(decoders[line]); } protected static void AddDecoder(string magic) where T : BeatmapDecoder diff --git a/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs b/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs index eeda4e46f8..89451c1233 100644 --- a/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs +++ b/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs @@ -15,11 +15,11 @@ namespace osu.Game.Beatmaps.Formats { public static void Register() { - AddDecoder("osu file format v14"); - AddDecoder("osu file format v13"); - AddDecoder("osu file format v12"); - AddDecoder("osu file format v11"); - AddDecoder("osu file format v10"); + AddDecoder(@"osu file format v14"); + AddDecoder(@"osu file format v13"); + AddDecoder(@"osu file format v12"); + AddDecoder(@"osu file format v11"); + AddDecoder(@"osu file format v10"); // TODO: Not sure how far back to go, or differences between versions } @@ -40,34 +40,34 @@ namespace osu.Game.Beatmaps.Formats { switch (key) { - case "AudioFilename": + case @"AudioFilename": beatmap.Metadata.AudioFile = val; break; - case "AudioLeadIn": + case @"AudioLeadIn": beatmap.AudioLeadIn = int.Parse(val); break; - case "PreviewTime": + case @"PreviewTime": beatmap.Metadata.PreviewTime = int.Parse(val); break; - case "Countdown": + case @"Countdown": beatmap.Countdown = int.Parse(val) == 1; break; - case "SampleSet": + case @"SampleSet": beatmap.SampleSet = (SampleSet)Enum.Parse(typeof(SampleSet), val); break; - case "StackLeniency": + case @"StackLeniency": beatmap.StackLeniency = float.Parse(val, NumberFormatInfo.InvariantInfo); break; - case "Mode": + case @"Mode": beatmap.Mode = (PlayMode)int.Parse(val); break; - case "LetterboxInBreaks": + case @"LetterboxInBreaks": beatmap.LetterboxInBreaks = int.Parse(val) == 1; break; - case "SpecialStyle": + case @"SpecialStyle": beatmap.SpecialStyle = int.Parse(val) == 1; break; - case "WidescreenStoryboard": + case @"WidescreenStoryboard": beatmap.WidescreenStoryboard = int.Parse(val) == 1; break; } @@ -77,19 +77,19 @@ namespace osu.Game.Beatmaps.Formats { switch (key) { - case "Bookmarks": + case @"Bookmarks": beatmap.StoredBookmarks = val; break; - case "DistanceSpacing": + case @"DistanceSpacing": beatmap.DistanceSpacing = double.Parse(val, NumberFormatInfo.InvariantInfo); break; - case "BeatDivisor": + case @"BeatDivisor": beatmap.BeatDivisor = int.Parse(val); break; - case "GridSize": + case @"GridSize": beatmap.GridSize = int.Parse(val); break; - case "TimelineZoom": + case @"TimelineZoom": beatmap.TimelineZoom = double.Parse(val, NumberFormatInfo.InvariantInfo); break; } @@ -99,34 +99,34 @@ namespace osu.Game.Beatmaps.Formats { switch (key) { - case "Title": + case @"Title": beatmap.Metadata.Title = val; break; - case "TitleUnicode": + case @"TitleUnicode": beatmap.Metadata.TitleUnicode = val; break; - case "Artist": + case @"Artist": beatmap.Metadata.Artist = val; break; - case "ArtistUnicode": + case @"ArtistUnicode": beatmap.Metadata.ArtistUnicode = val; break; - case "Creator": + case @"Creator": beatmap.Metadata.Author = val; break; - case "Version": + case @"Version": beatmap.Version = val; break; - case "Source": + case @"Source": beatmap.Metadata.Source = val; break; - case "Tags": + case @"Tags": beatmap.Metadata.Tags = val; break; - case "BeatmapID": + case @"BeatmapID": beatmap.BeatmapID = int.Parse(val); break; - case "BeatmapSetID": + case @"BeatmapSetID": beatmap.BeatmapSetID = int.Parse(val); beatmap.Metadata.BeatmapSetID = int.Parse(val); break; @@ -137,22 +137,22 @@ namespace osu.Game.Beatmaps.Formats { switch (key) { - case "HPDrainRate": + case @"HPDrainRate": beatmap.BaseDifficulty.DrainRate = float.Parse(val, NumberFormatInfo.InvariantInfo); break; - case "CircleSize": + case @"CircleSize": beatmap.BaseDifficulty.CircleSize = float.Parse(val, NumberFormatInfo.InvariantInfo); break; - case "OverallDifficulty": + case @"OverallDifficulty": beatmap.BaseDifficulty.OverallDifficulty = float.Parse(val, NumberFormatInfo.InvariantInfo); break; - case "ApproachRate": + case @"ApproachRate": beatmap.BaseDifficulty.ApproachRate = float.Parse(val, NumberFormatInfo.InvariantInfo); break; - case "SliderMultiplier": + case @"SliderMultiplier": beatmap.BaseDifficulty.SliderMultiplier = float.Parse(val, NumberFormatInfo.InvariantInfo); break; - case "SliderTickRate": + case @"SliderTickRate": beatmap.BaseDifficulty.SliderTickRate = float.Parse(val, NumberFormatInfo.InvariantInfo); break; } @@ -160,9 +160,9 @@ namespace osu.Game.Beatmaps.Formats private void handleEvents(Beatmap beatmap, string val) { - if (val.StartsWith("//")) + if (val.StartsWith(@"//")) return; - if (val.StartsWith(" ")) + if (val.StartsWith(@" ")) return; // TODO string[] split = val.Split(','); EventType type; @@ -222,10 +222,10 @@ namespace osu.Game.Beatmaps.Formats line = line.Trim(); if (string.IsNullOrEmpty(line)) continue; - if (line.StartsWith("osu file format v")) + if (line.StartsWith(@"osu file format v")) continue; - if (line.StartsWith("[") && line.EndsWith("]")) + if (line.StartsWith(@"[") && line.EndsWith(@"]")) { if (!Enum.TryParse(line.Substring(1, line.Length - 2), out section)) throw new InvalidDataException($@"Unknown osu section {line}"); diff --git a/osu.Game/Beatmaps/IO/ArchiveReader.cs b/osu.Game/Beatmaps/IO/ArchiveReader.cs index d9b4295704..77315d4a21 100644 --- a/osu.Game/Beatmaps/IO/ArchiveReader.cs +++ b/osu.Game/Beatmaps/IO/ArchiveReader.cs @@ -22,7 +22,7 @@ namespace osu.Game.Beatmaps.IO if (reader.Test(storage, path)) return (ArchiveReader)Activator.CreateInstance(reader.Type, storage.GetStream(path)); } - throw new IOException("Unknown file format"); + throw new IOException(@"Unknown file format"); } protected static void AddReader(Func test) where T : ArchiveReader diff --git a/osu.Game/Beatmaps/IO/OszArchiveReader.cs b/osu.Game/Beatmaps/IO/OszArchiveReader.cs index d7241d17a1..b70bee076c 100644 --- a/osu.Game/Beatmaps/IO/OszArchiveReader.cs +++ b/osu.Game/Beatmaps/IO/OszArchiveReader.cs @@ -25,10 +25,10 @@ namespace osu.Game.Beatmaps.IO public OszArchiveReader(Stream archiveStream) { archive = ZipFile.Read(archiveStream); - beatmaps = archive.Entries.Where(e => e.FileName.EndsWith(".osu")) + beatmaps = archive.Entries.Where(e => e.FileName.EndsWith(@".osu")) .Select(e => e.FileName).ToArray(); if (beatmaps.Length == 0) - throw new FileNotFoundException("This directory contains no beatmaps"); + throw new FileNotFoundException(@"This directory contains no beatmaps"); using (var stream = new StreamReader(ReadFile(beatmaps[0]))) { var decoder = BeatmapDecoder.GetDecoder(stream); From 65e3e13aa2fe95cfae77fd6bfc97060a25ffc3d5 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Wed, 12 Oct 2016 13:49:30 -0400 Subject: [PATCH 32/33] Fix reference paths in osu.Game.csproj --- osu.Game/osu.Game.csproj | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 285e635012..0839891dd8 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -34,29 +34,29 @@ - ..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll + $(SolutionDir)\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll True - ..\packages\ppy.OpenTK.1.1.2225.3\lib\net20\OpenTK.dll + $(SolutionDir)\packages\ppy.OpenTK.1.1.2225.3\lib\net20\OpenTK.dll True - ..\packages\SQLitePCLRaw.core.1.0.1\lib\net45\SQLitePCLRaw.core.dll + $(SolutionDir)\packages\SQLitePCLRaw.core.1.0.1\lib\net45\SQLitePCLRaw.core.dll - ..\packages\SQLitePCLRaw.provider.e_sqlite3.net45.1.0.1\lib\net45\SQLitePCLRaw.provider.e_sqlite3.dll + $(SolutionDir)\packages\SQLitePCLRaw.provider.e_sqlite3.net45.1.0.1\lib\net45\SQLitePCLRaw.provider.e_sqlite3.dll - ..\packages\SQLitePCLRaw.bundle_green.1.0.1\lib\net45\SQLitePCLRaw.batteries_green.dll + $(SolutionDir)\packages\SQLitePCLRaw.bundle_green.1.0.1\lib\net45\SQLitePCLRaw.batteries_green.dll - ..\packages\sqlite-net-pcl.1.2.0\lib\portable-net45+wp8+wpa81+win8+MonoAndroid10+MonoTouch10+Xamarin.iOS10\SQLite-net.dll + $(SolutionDir)\packages\sqlite-net-pcl.1.2.0\lib\portable-net45+wp8+wpa81+win8+MonoAndroid10+MonoTouch10+Xamarin.iOS10\SQLite-net.dll - ..\packages\DotNetZip.1.10.1\lib\net20\DotNetZip.dll + $(SolutionDir)\packages\DotNetZip.1.10.1\lib\net20\DotNetZip.dll @@ -172,11 +172,11 @@ - + {c76bf5b3-985e-4d39-95fe-97c9c879b83a} osu.Framework - + {d9a367c9-4c1a-489f-9b05-a0cea2b53b58} osu.Game.Resources @@ -202,7 +202,7 @@ --> - - - + + + From edd8f3871e3e00e8b93f315526524d292ed32dc7 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 13 Oct 2016 11:41:11 +0900 Subject: [PATCH 33/33] Add TODO regarding parsing. --- osu.Game/Beatmaps/Objects/HitObject.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/osu.Game/Beatmaps/Objects/HitObject.cs b/osu.Game/Beatmaps/Objects/HitObject.cs index ffa5e8e6ff..16f0bb8a43 100644 --- a/osu.Game/Beatmaps/Objects/HitObject.cs +++ b/osu.Game/Beatmaps/Objects/HitObject.cs @@ -21,6 +21,7 @@ namespace osu.Game.Beatmaps.Objects public static HitObject Parse(PlayMode mode, string val) { + //TODO: move to modular HitObjectParser system rather than static parsing. (https://github.com/ppy/osu/pull/60/files#r83135780) switch (mode) { case PlayMode.Osu: