From 2d810f72fa930194fea586363bc7ed4fd474130a Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Tue, 4 Oct 2016 11:31:10 -0400 Subject: [PATCH 01/38] 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/38] 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/38] 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/38] 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/38] 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/38] 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/38] 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/38] 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/38] 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 8707c7f746ace3c93d0bf19958a56a6ea5069854 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 13 Oct 2016 03:06:06 +0900 Subject: [PATCH 11/38] Fix regression causing multi-line (wrapped) chat messages to overlap. --- osu.Game/Online/Chat/Display/ChatLine.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Online/Chat/Display/ChatLine.cs b/osu.Game/Online/Chat/Display/ChatLine.cs index a827f411bf..5032ff0b9f 100644 --- a/osu.Game/Online/Chat/Display/ChatLine.cs +++ b/osu.Game/Online/Chat/Display/ChatLine.cs @@ -56,7 +56,7 @@ namespace osu.Game.Online.Chat.Display } } }, - new Container + new AutoSizeContainer { RelativeSizeAxes = Axes.X, Padding = new MarginPadding { Left = padding + 10 }, From 2566d6bfe019e7dda928e5975c931a6d2f010638 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 13 Oct 2016 10:10:15 +0900 Subject: [PATCH 12/38] Fix regressions with HitRenderers, while also cleaning them up. --- .../Tests/TestCaseGamefield.cs | 6 +- .../Beatmaps/Objects/Catch/CatchConverter.cs | 43 +++++++++++ .../Objects/Catch/Drawable/DrawableFruit.cs | 42 +++++++++++ .../Beatmaps/Objects/HitObjectConverter.cs | 13 ++++ .../Objects/Mania/Drawable/DrawableNote.cs | 33 ++++++++ .../Beatmaps/Objects/Mania/ManiaConverter.cs | 46 ++++++++++++ .../Objects/Osu/Drawable/DrawableCircle.cs | 42 +++++++++++ osu.Game/Beatmaps/Objects/Osu/OsuConverter.cs | 21 ++++++ .../Taiko/Drawable/DrawableTaikoHit.cs | 37 +++++++++ .../Beatmaps/Objects/Taiko/TaikoBaseHit.cs | 2 +- .../Beatmaps/Objects/Taiko/TaikoConverter.cs | 38 ++++++++++ .../GameModes/Play/Catch/CatchHitRenderer.cs | 72 ++---------------- osu.Game/GameModes/Play/HitRenderer.cs | 44 +++++++---- .../GameModes/Play/Mania/ManiaHitRenderer.cs | 75 ++++--------------- osu.Game/GameModes/Play/Osu/OsuHitRenderer.cs | 53 ++----------- .../GameModes/Play/Taiko/TaikoHitRenderer.cs | 73 ++---------------- osu.Game/Online/API/APIAccess.cs | 5 +- osu.Game/osu.Game.csproj | 9 +++ 18 files changed, 391 insertions(+), 263 deletions(-) create mode 100644 osu.Game/Beatmaps/Objects/Catch/CatchConverter.cs create mode 100644 osu.Game/Beatmaps/Objects/Catch/Drawable/DrawableFruit.cs create mode 100644 osu.Game/Beatmaps/Objects/HitObjectConverter.cs create mode 100644 osu.Game/Beatmaps/Objects/Mania/Drawable/DrawableNote.cs create mode 100644 osu.Game/Beatmaps/Objects/Mania/ManiaConverter.cs create mode 100644 osu.Game/Beatmaps/Objects/Osu/Drawable/DrawableCircle.cs create mode 100644 osu.Game/Beatmaps/Objects/Osu/OsuConverter.cs create mode 100644 osu.Game/Beatmaps/Objects/Taiko/Drawable/DrawableTaikoHit.cs create mode 100644 osu.Game/Beatmaps/Objects/Taiko/TaikoConverter.cs diff --git a/osu.Desktop.VisualTests/Tests/TestCaseGamefield.cs b/osu.Desktop.VisualTests/Tests/TestCaseGamefield.cs index 085100acf9..316a099e38 100644 --- a/osu.Desktop.VisualTests/Tests/TestCaseGamefield.cs +++ b/osu.Desktop.VisualTests/Tests/TestCaseGamefield.cs @@ -23,7 +23,7 @@ namespace osu.Desktop.Tests public override string Description => @"Showing hitobjects and what not."; - FramedOffsetClock localClock; + FramedClock localClock; protected override IFrameBasedClock Clock => localClock; @@ -32,9 +32,7 @@ namespace osu.Desktop.Tests base.Reset(); //ensure we are at offset 0 - if (localClock == null) - localClock = new FramedOffsetClock(base.Clock); - localClock.Offset = -base.Clock.CurrentTime; + localClock = new FramedClock(); List objects = new List(); diff --git a/osu.Game/Beatmaps/Objects/Catch/CatchConverter.cs b/osu.Game/Beatmaps/Objects/Catch/CatchConverter.cs new file mode 100644 index 0000000000..dbd97e90bc --- /dev/null +++ b/osu.Game/Beatmaps/Objects/Catch/CatchConverter.cs @@ -0,0 +1,43 @@ +//Copyright (c) 2007-2016 ppy Pty Ltd . +//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using osu.Game.Beatmaps.Objects.Catch; +using osu.Game.Beatmaps.Objects.Osu; + +namespace osu.Game.Beatmaps.Objects.Catch +{ + class CatchConverter : HitObjectConverter + { + public override List Convert(List input) + { + List output = new List(); + + foreach (HitObject i in input) + { + CatchBaseHit h = i as CatchBaseHit; + + if (h == null) + { + OsuBaseHit o = i as OsuBaseHit; + + if (o == null) throw new Exception(@"Can't convert!"); + + h = new Fruit + { + StartTime = o.StartTime, + Position = o.Position.X, + }; + } + + output.Add(h); + } + + return output; + } + } +} diff --git a/osu.Game/Beatmaps/Objects/Catch/Drawable/DrawableFruit.cs b/osu.Game/Beatmaps/Objects/Catch/Drawable/DrawableFruit.cs new file mode 100644 index 0000000000..028afff5cc --- /dev/null +++ b/osu.Game/Beatmaps/Objects/Catch/Drawable/DrawableFruit.cs @@ -0,0 +1,42 @@ +//Copyright (c) 2007-2016 ppy Pty Ltd . +//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using osu.Framework; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Sprites; +using osu.Framework.Graphics.Transformations; +using OpenTK; + +namespace osu.Game.Beatmaps.Objects.Catch.Drawable +{ + class DrawableFruit : Sprite + { + private CatchBaseHit h; + + public DrawableFruit(CatchBaseHit h) + { + this.h = h; + + Origin = Anchor.Centre; + Scale = new Vector2(0.1f); + RelativePositionAxes = Axes.Y; + Position = new Vector2(h.Position, -0.1f); + } + + public override void Load(BaseGame game) + { + base.Load(game); + + Texture = game.Textures.Get(@"Menu/logo"); + + Transforms.Add(new TransformPosition(Clock) { StartTime = h.StartTime - 200, EndTime = h.StartTime, StartValue = new Vector2(h.Position, -0.1f), EndValue = new Vector2(h.Position, 0.9f) }); + Transforms.Add(new TransformAlpha(Clock) { StartTime = h.StartTime + h.Duration + 200, EndTime = h.StartTime + h.Duration + 400, StartValue = 1, EndValue = 0 }); + Expire(true); + } + } +} diff --git a/osu.Game/Beatmaps/Objects/HitObjectConverter.cs b/osu.Game/Beatmaps/Objects/HitObjectConverter.cs new file mode 100644 index 0000000000..a70526e85a --- /dev/null +++ b/osu.Game/Beatmaps/Objects/HitObjectConverter.cs @@ -0,0 +1,13 @@ +//Copyright (c) 2007-2016 ppy Pty Ltd . +//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using System.Collections.Generic; + +namespace osu.Game.Beatmaps.Objects +{ + public abstract class HitObjectConverter + where T : HitObject + { + public abstract List Convert(List input); + } +} diff --git a/osu.Game/Beatmaps/Objects/Mania/Drawable/DrawableNote.cs b/osu.Game/Beatmaps/Objects/Mania/Drawable/DrawableNote.cs new file mode 100644 index 0000000000..132fb6ce36 --- /dev/null +++ b/osu.Game/Beatmaps/Objects/Mania/Drawable/DrawableNote.cs @@ -0,0 +1,33 @@ +//Copyright (c) 2007-2016 ppy Pty Ltd . +//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Framework; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Sprites; +using osu.Framework.Graphics.Transformations; +using OpenTK; + +namespace osu.Game.Beatmaps.Objects.Mania.Drawable +{ + public class DrawableNote : Sprite + { + private readonly ManiaBaseHit note; + + public DrawableNote(ManiaBaseHit note) + { + this.note = note; + Origin = Anchor.Centre; + Scale = new Vector2(0.1f); + } + + public override void Load(BaseGame game) + { + base.Load(game); + Texture = game.Textures.Get(@"Menu/logo"); + + Transforms.Add(new TransformPositionY(Clock) { StartTime = note.StartTime - 200, EndTime = note.StartTime, StartValue = -0.1f, EndValue = 0.9f }); + Transforms.Add(new TransformAlpha(Clock) { StartTime = note.StartTime + note.Duration + 200, EndTime = note.StartTime + note.Duration + 400, StartValue = 1, EndValue = 0 }); + Expire(true); + } + } +} diff --git a/osu.Game/Beatmaps/Objects/Mania/ManiaConverter.cs b/osu.Game/Beatmaps/Objects/Mania/ManiaConverter.cs new file mode 100644 index 0000000000..22d8f9ae9c --- /dev/null +++ b/osu.Game/Beatmaps/Objects/Mania/ManiaConverter.cs @@ -0,0 +1,46 @@ +//Copyright (c) 2007-2016 ppy Pty Ltd . +//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using System; +using System.Collections.Generic; +using osu.Game.Beatmaps.Objects.Osu; + +namespace osu.Game.Beatmaps.Objects.Mania +{ + class ManiaConverter : HitObjectConverter + { + private readonly int columns; + + public ManiaConverter(int columns) + { + this.columns = columns; + } + + public override List Convert(List input) + { + List output = new List(); + + foreach (HitObject i in input) + { + ManiaBaseHit h = i as ManiaBaseHit; + + if (h == null) + { + OsuBaseHit o = i as OsuBaseHit; + + if (o == null) throw new Exception(@"Can't convert!"); + + h = new Note + { + StartTime = o.StartTime, + Column = (int)Math.Round(o.Position.X / 512 * columns) + }; + } + + output.Add(h); + } + + return output; + } + } +} diff --git a/osu.Game/Beatmaps/Objects/Osu/Drawable/DrawableCircle.cs b/osu.Game/Beatmaps/Objects/Osu/Drawable/DrawableCircle.cs new file mode 100644 index 0000000000..f4297970e8 --- /dev/null +++ b/osu.Game/Beatmaps/Objects/Osu/Drawable/DrawableCircle.cs @@ -0,0 +1,42 @@ +//Copyright (c) 2007-2016 ppy Pty Ltd . +//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using osu.Framework; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Sprites; +using osu.Framework.Graphics.Transformations; +using OpenTK; + +namespace osu.Game.Beatmaps.Objects.Osu.Drawable +{ + class DrawableCircle : Sprite + { + private OsuBaseHit h; + + public DrawableCircle(OsuBaseHit h) + { + this.h = h; + + Origin = Anchor.Centre; + Scale = new Vector2(0.1f); + Alpha = 0; + Position = h.Position; + } + + public override void Load(BaseGame game) + { + base.Load(game); + + Texture = game.Textures.Get(@"Menu/logo"); + + Transforms.Add(new TransformAlpha(Clock) { StartTime = h.StartTime - 200, EndTime = h.StartTime, StartValue = 0, EndValue = 1 }); + Transforms.Add(new TransformAlpha(Clock) { StartTime = h.StartTime + h.Duration + 200, EndTime = h.StartTime + h.Duration + 400, StartValue = 1, EndValue = 0 }); + Expire(true); + } + } +} diff --git a/osu.Game/Beatmaps/Objects/Osu/OsuConverter.cs b/osu.Game/Beatmaps/Objects/Osu/OsuConverter.cs new file mode 100644 index 0000000000..5629fccd5c --- /dev/null +++ b/osu.Game/Beatmaps/Objects/Osu/OsuConverter.cs @@ -0,0 +1,21 @@ +//Copyright (c) 2007-2016 ppy Pty Ltd . +//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using System; +using System.Collections.Generic; + +namespace osu.Game.Beatmaps.Objects.Osu +{ + class OsuConverter : HitObjectConverter + { + public override List Convert(List input) + { + List output = new List(); + + foreach (HitObject h in input) + output.Add(h as OsuBaseHit); + + return output; + } + } +} diff --git a/osu.Game/Beatmaps/Objects/Taiko/Drawable/DrawableTaikoHit.cs b/osu.Game/Beatmaps/Objects/Taiko/Drawable/DrawableTaikoHit.cs new file mode 100644 index 0000000000..dafbe33415 --- /dev/null +++ b/osu.Game/Beatmaps/Objects/Taiko/Drawable/DrawableTaikoHit.cs @@ -0,0 +1,37 @@ +//Copyright (c) 2007-2016 ppy Pty Ltd . +//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Framework; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Sprites; +using osu.Framework.Graphics.Transformations; +using OpenTK; + +namespace osu.Game.Beatmaps.Objects.Taiko.Drawable +{ + class DrawableTaikoHit : Sprite + { + private TaikoBaseHit h; + + public DrawableTaikoHit(TaikoBaseHit h) + { + this.h = h; + + Origin = Anchor.Centre; + Scale = new Vector2(0.2f); + RelativePositionAxes = Axes.Both; + Position = new Vector2(1.1f, 0.5f); + } + + public override void Load(BaseGame game) + { + base.Load(game); + + Texture = game.Textures.Get(@"Menu/logo"); + + Transforms.Add(new TransformPositionX(Clock) { StartTime = h.StartTime - 200, EndTime = h.StartTime, StartValue = 1.1f, EndValue = 0.1f }); + Transforms.Add(new TransformAlpha(Clock) { StartTime = h.StartTime + h.Duration + 200, EndTime = h.StartTime + h.Duration + 400, StartValue = 1, EndValue = 0 }); + Expire(true); + } + } +} diff --git a/osu.Game/Beatmaps/Objects/Taiko/TaikoBaseHit.cs b/osu.Game/Beatmaps/Objects/Taiko/TaikoBaseHit.cs index ddd8375204..6b8f241306 100644 --- a/osu.Game/Beatmaps/Objects/Taiko/TaikoBaseHit.cs +++ b/osu.Game/Beatmaps/Objects/Taiko/TaikoBaseHit.cs @@ -3,7 +3,7 @@ namespace osu.Game.Beatmaps.Objects.Taiko { - class TaikoBaseHit : HitObject + public class TaikoBaseHit : HitObject { public float Scale = 1; diff --git a/osu.Game/Beatmaps/Objects/Taiko/TaikoConverter.cs b/osu.Game/Beatmaps/Objects/Taiko/TaikoConverter.cs new file mode 100644 index 0000000000..3189a0dec7 --- /dev/null +++ b/osu.Game/Beatmaps/Objects/Taiko/TaikoConverter.cs @@ -0,0 +1,38 @@ +//Copyright (c) 2007-2016 ppy Pty Ltd . +//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using System; +using System.Collections.Generic; +using osu.Game.Beatmaps.Objects.Osu; + +namespace osu.Game.Beatmaps.Objects.Taiko +{ + class TaikoConverter : HitObjectConverter + { + public override List Convert(List input) + { + List output = new List(); + + foreach (HitObject i in input) + { + TaikoBaseHit h = i as TaikoBaseHit; + + if (h == null) + { + OsuBaseHit o = i as OsuBaseHit; + + if (o == null) throw new Exception(@"Can't convert!"); + + h = new TaikoBaseHit + { + StartTime = o.StartTime, + }; + } + + output.Add(h); + } + + return output; + } + } +} diff --git a/osu.Game/GameModes/Play/Catch/CatchHitRenderer.cs b/osu.Game/GameModes/Play/Catch/CatchHitRenderer.cs index d6543360fc..d8e5aaaa35 100644 --- a/osu.Game/GameModes/Play/Catch/CatchHitRenderer.cs +++ b/osu.Game/GameModes/Play/Catch/CatchHitRenderer.cs @@ -1,82 +1,20 @@ //Copyright (c) 2007-2016 ppy Pty Ltd . //Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE -using System; using System.Collections.Generic; -using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics; -using osu.Framework.Graphics.Transformations; using osu.Game.Beatmaps.Objects; -using osu.Game.Beatmaps.Objects.Osu; using osu.Game.Beatmaps.Objects.Catch; -using OpenTK; -using osu.Framework; +using osu.Game.Beatmaps.Objects.Catch.Drawable; namespace osu.Game.GameModes.Play.Catch { - public class CatchHitRenderer : HitRenderer + public class CatchHitRenderer : HitRenderer { - List objects; - private CatchPlayfield playfield; + protected override Playfield CreatePlayfield() => new CatchPlayfield(); - public override List Objects - { - set - { - //osu! mode requires all objects to be of CatchBaseHit type. - objects = value.ConvertAll(convertForCatch); - } - } + protected override List Convert(List objects) => new CatchConverter().Convert(objects); - private CatchBaseHit convertForCatch(HitObject input) - { - CatchBaseHit h = input as CatchBaseHit; - - if (h == null) - { - OsuBaseHit o = input as OsuBaseHit; - - if (o == null) throw new Exception(@"Can't convert!"); - - h = new Fruit() - { - StartTime = o.StartTime, - Position = o.Position.X - }; - } - - return h; - } - - public override void Load(BaseGame game) - { - base.Load(game); - - if (playfield == null) - Add(playfield = new CatchPlayfield()); - else - playfield.Clear(); - - if (objects == null) return; - - foreach (CatchBaseHit h in objects) - { - //render stuff! - Sprite s = new Sprite - { - Texture = game.Textures.Get(@"Menu/logo"), - Origin = Anchor.Centre, - Scale = new Vector2(0.1f), - RelativePositionAxes = Axes.Y, - Position = new Vector2(h.Position, -0.1f) - }; - - s.Transforms.Add(new TransformPosition(Clock) { StartTime = h.StartTime - 200, EndTime = h.StartTime, StartValue = new Vector2(h.Position, -0.1f), EndValue = new Vector2(h.Position, 0.9f) }); - s.Transforms.Add(new TransformAlpha(Clock) { StartTime = h.StartTime + h.Duration + 200, EndTime = h.StartTime + h.Duration + 400, StartValue = 1, EndValue = 0 }); - s.Expire(true); - - playfield.Add(s); - } - } + protected override Drawable GetVisualRepresentation(CatchBaseHit h) => new DrawableFruit(h); } } diff --git a/osu.Game/GameModes/Play/HitRenderer.cs b/osu.Game/GameModes/Play/HitRenderer.cs index 06d98da836..b18d9ebb6d 100644 --- a/osu.Game/GameModes/Play/HitRenderer.cs +++ b/osu.Game/GameModes/Play/HitRenderer.cs @@ -3,35 +3,53 @@ using System.Collections.Generic; using osu.Framework.Graphics; -using osu.Framework.Graphics.Batches; using osu.Framework.Graphics.Containers; -using osu.Framework.Graphics.Drawables; using osu.Game.Beatmaps.Objects; -using OpenTK; -using OpenTK.Graphics; using osu.Framework; namespace osu.Game.GameModes.Play { - public abstract class HitRenderer : Container + public abstract class HitRenderer : Container { - public abstract List Objects { set; } + private List objects; - public HitRenderer() + public List Objects { - RelativeSizeAxes = Axes.Both; + set + { + objects = Convert(value); + if (IsLoaded) + loadObjects(); + } } + private Playfield playfield; + + protected abstract Playfield CreatePlayfield(); + + protected abstract List Convert(List objects); + public override void Load(BaseGame game) { base.Load(game); - Add(new Box() + RelativeSizeAxes = Axes.Both; + + Children = new Drawable[] { - RelativeSizeAxes = Axes.Both, - Alpha = 0.8f, - Colour = new Color4(5, 5, 5, 255), - }); + playfield = CreatePlayfield() + }; + + loadObjects(); } + + private void loadObjects() + { + if (objects == null) return; + foreach (T h in objects) + playfield.Add(GetVisualRepresentation(h)); + } + + protected abstract Drawable GetVisualRepresentation(T h); } } diff --git a/osu.Game/GameModes/Play/Mania/ManiaHitRenderer.cs b/osu.Game/GameModes/Play/Mania/ManiaHitRenderer.cs index 1e55e552d3..302f40878b 100644 --- a/osu.Game/GameModes/Play/Mania/ManiaHitRenderer.cs +++ b/osu.Game/GameModes/Play/Mania/ManiaHitRenderer.cs @@ -1,88 +1,39 @@ //Copyright (c) 2007-2016 ppy Pty Ltd . //Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE -using System; -using System.Collections.Generic; -using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics; -using osu.Framework.Graphics.Transformations; using osu.Game.Beatmaps.Objects; -using osu.Game.Beatmaps.Objects.Osu; using osu.Game.Beatmaps.Objects.Mania; using OpenTK; -using osu.Framework; +using osu.Game.Beatmaps.Objects.Mania.Drawable; +using System.Collections.Generic; namespace osu.Game.GameModes.Play.Mania { - public class ManiaHitRenderer : HitRenderer + public class ManiaHitRenderer : HitRenderer { private readonly int columns; - List objects; - private ManiaPlayfield playfield; public ManiaHitRenderer(int columns = 5) { this.columns = columns; } - public override List Objects + protected override List Convert(List objects) { - set - { - //osu! mode requires all objects to be of ManiaBaseHit type. - objects = value.ConvertAll(convertForMania); - } + ManiaConverter converter = new ManiaConverter(columns); + return converter.Convert(objects); } - private ManiaBaseHit convertForMania(HitObject input) + protected override Playfield CreatePlayfield() => new ManiaPlayfield(columns); + + protected override Drawable GetVisualRepresentation(ManiaBaseHit h) { - ManiaBaseHit h = input as ManiaBaseHit; - - if (h == null) + return new DrawableNote(h) { - OsuBaseHit o = input as OsuBaseHit; - - if (o == null) throw new Exception(@"Can't convert!"); - - h = new Note() - { - StartTime = o.StartTime, - Column = (int)Math.Round(o.Position.X / 512 * columns) - }; - } - - return h; - } - - public override void Load(BaseGame game) - { - base.Load(game); - - if (playfield == null) - Add(playfield = new ManiaPlayfield(columns)); - else - playfield.Clear(); - - if (objects == null) return; - - foreach (ManiaBaseHit h in objects) - { - //render stuff! - Sprite s = new Sprite - { - Texture = game.Textures.Get(@"Menu/logo"), - Origin = Anchor.Centre, - Scale = new Vector2(0.1f), - RelativePositionAxes = Axes.Both, - Position = new Vector2((float)(h.Column + 0.5) / columns, -0.1f) - }; - - s.Transforms.Add(new TransformPositionY(Clock) { StartTime = h.StartTime - 200, EndTime = h.StartTime, StartValue = -0.1f, EndValue = 0.9f }); - s.Transforms.Add(new TransformAlpha(Clock) { StartTime = h.StartTime + h.Duration + 200, EndTime = h.StartTime + h.Duration + 400, StartValue = 1, EndValue = 0 }); - s.Expire(true); - - playfield.Add(s); - } + Position = new Vector2((float)(h.Column + 0.5) / columns, -0.1f), + RelativePositionAxes = Axes.Both + }; } } } diff --git a/osu.Game/GameModes/Play/Osu/OsuHitRenderer.cs b/osu.Game/GameModes/Play/Osu/OsuHitRenderer.cs index c95eca8077..130d6d212f 100644 --- a/osu.Game/GameModes/Play/Osu/OsuHitRenderer.cs +++ b/osu.Game/GameModes/Play/Osu/OsuHitRenderer.cs @@ -2,62 +2,19 @@ //Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using System.Collections.Generic; -using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics; -using osu.Framework.Graphics.Transformations; using osu.Game.Beatmaps.Objects; using osu.Game.Beatmaps.Objects.Osu; -using OpenTK; -using System.Diagnostics; -using osu.Framework; +using osu.Game.Beatmaps.Objects.Osu.Drawable; namespace osu.Game.GameModes.Play.Osu { - public class OsuHitRenderer : HitRenderer + public class OsuHitRenderer : HitRenderer { - List objects; - private OsuPlayfield playfield; + protected override Playfield CreatePlayfield() => new OsuPlayfield(); - public override List Objects - { - set - { - Debug.Assert(objects == null); + protected override List Convert(List objects) => new OsuConverter().Convert(objects); - //osu! mode requires all objects to be of OsuBaseHit type. - objects = value.ConvertAll(o => (OsuBaseHit)o); - } - } - - public override void Load(BaseGame game) - { - base.Load(game); - - if (playfield == null) - Add(playfield = new OsuPlayfield()); - else - playfield.Clear(); - - if (objects == null) return; - - foreach (OsuBaseHit h in objects) - { - //render stuff! - Sprite s = new Sprite - { - Texture = game.Textures.Get(@"Menu/logo"), - Origin = Anchor.Centre, - Scale = new Vector2(0.1f), - Alpha = 0, - Position = h.Position - }; - - s.Transforms.Add(new TransformAlpha(Clock) { StartTime = h.StartTime - 200, EndTime = h.StartTime, StartValue = 0, EndValue = 1 }); - s.Transforms.Add(new TransformAlpha(Clock) { StartTime = h.StartTime + h.Duration + 200, EndTime = h.StartTime + h.Duration + 400, StartValue = 1, EndValue = 0 }); - s.Expire(true); - - playfield.Add(s); - } - } + protected override Drawable GetVisualRepresentation(OsuBaseHit h) => new DrawableCircle(h); } } diff --git a/osu.Game/GameModes/Play/Taiko/TaikoHitRenderer.cs b/osu.Game/GameModes/Play/Taiko/TaikoHitRenderer.cs index 2874c62fca..9fab5998f5 100644 --- a/osu.Game/GameModes/Play/Taiko/TaikoHitRenderer.cs +++ b/osu.Game/GameModes/Play/Taiko/TaikoHitRenderer.cs @@ -1,81 +1,20 @@ //Copyright (c) 2007-2016 ppy Pty Ltd . //Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE -using System; using System.Collections.Generic; -using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics; -using osu.Framework.Graphics.Transformations; using osu.Game.Beatmaps.Objects; -using osu.Game.Beatmaps.Objects.Osu; using osu.Game.Beatmaps.Objects.Taiko; -using OpenTK; -using osu.Framework; +using osu.Game.Beatmaps.Objects.Taiko.Drawable; namespace osu.Game.GameModes.Play.Taiko { - public class TaikoHitRenderer : HitRenderer + public class TaikoHitRenderer : HitRenderer { - List objects; - private TaikoPlayfield playfield; + protected override List Convert(List objects) => new TaikoConverter().Convert(objects); - public override List Objects - { - set - { - //osu! mode requires all objects to be of TaikoBaseHit type. - objects = value.ConvertAll(convertForTaiko); - } - } + protected override Playfield CreatePlayfield() => new TaikoPlayfield(); - private TaikoBaseHit convertForTaiko(HitObject input) - { - TaikoBaseHit h = input as TaikoBaseHit; - - if (h == null) - { - OsuBaseHit o = input as OsuBaseHit; - - if (o == null) throw new Exception(@"Can't convert!"); - - h = new TaikoBaseHit() - { - StartTime = o.StartTime - }; - } - - return h; - } - - public override void Load(BaseGame game) - { - base.Load(game); - - if (playfield == null) - Add(playfield = new TaikoPlayfield()); - else - playfield.Clear(); - - if (objects == null) return; - - foreach (TaikoBaseHit h in objects) - { - //render stuff! - Sprite s = new Sprite - { - Texture = game.Textures.Get(@"Menu/logo"), - Origin = Anchor.Centre, - Scale = new Vector2(0.2f), - RelativePositionAxes = Axes.Both, - Position = new Vector2(1.1f, 0.5f) - }; - - s.Transforms.Add(new TransformPositionX(Clock) { StartTime = h.StartTime - 200, EndTime = h.StartTime, StartValue = 1.1f, EndValue = 0.1f }); - s.Transforms.Add(new TransformAlpha(Clock) { StartTime = h.StartTime + h.Duration + 200, EndTime = h.StartTime + h.Duration + 400, StartValue = 1, EndValue = 0 }); - s.Expire(true); - - playfield.Add(s); - } - } + protected override Drawable GetVisualRepresentation(TaikoBaseHit h) => new DrawableTaikoHit(h); } -} +} \ No newline at end of file diff --git a/osu.Game/Online/API/APIAccess.cs b/osu.Game/Online/API/APIAccess.cs index bb72bdf02e..a7b2239355 100644 --- a/osu.Game/Online/API/APIAccess.cs +++ b/osu.Game/Online/API/APIAccess.cs @@ -219,7 +219,10 @@ namespace osu.Game.Online.API { //NotificationManager.ShowMessage($@"We just went {newState}!", newState == APIState.Online ? Color4.YellowGreen : Color4.OrangeRed, 5000); log.Add($@"We just went {newState}!"); - OnStateChange?.Invoke(oldState, newState); + Scheduler.Add(delegate + { + OnStateChange?.Invoke(oldState, newState); + }); } } } diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index bdb852c33f..ca38e48f8b 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -48,18 +48,27 @@ + + + + + + + + + From 2a3f04789568334fd3912592119f3390f7466143 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Fri, 7 Oct 2016 15:09:52 -0400 Subject: [PATCH 13/38] 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 14/38] 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 22/38] 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 23/38] 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 24/38] 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 25/38] 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 26/38] 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 27/38] 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 28/38] 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 29/38] 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 30/38] 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 31/38] 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 32/38] 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 33/38] 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 34/38] 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 35/38] 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: From 1a9dede98ce8e6314dbba6f28a6af975e6b203ae Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 13 Oct 2016 14:27:31 +0900 Subject: [PATCH 36/38] Remove unused Deploy build configuration. --- osu.sln | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/osu.sln b/osu.sln index 8fba171a2f..3d79d4444f 100644 --- a/osu.sln +++ b/osu.sln @@ -24,45 +24,35 @@ EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution 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 {2A66DD92-ADB1-4994-89E2-C94E04ACDA0D}.Debug|Any CPU.Build.0 = Debug|Any CPU - {2A66DD92-ADB1-4994-89E2-C94E04ACDA0D}.Deploy|Any CPU.ActiveCfg = Debug|Any CPU {2A66DD92-ADB1-4994-89E2-C94E04ACDA0D}.Release|Any CPU.ActiveCfg = Release|Any CPU {2A66DD92-ADB1-4994-89E2-C94E04ACDA0D}.Release|Any CPU.Build.0 = Release|Any CPU {C76BF5B3-985E-4D39-95FE-97C9C879B83A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {C76BF5B3-985E-4D39-95FE-97C9C879B83A}.Debug|Any CPU.Build.0 = Debug|Any CPU - {C76BF5B3-985E-4D39-95FE-97C9C879B83A}.Deploy|Any CPU.ActiveCfg = Debug|Any CPU {C76BF5B3-985E-4D39-95FE-97C9C879B83A}.Release|Any CPU.ActiveCfg = Release|Any CPU {C76BF5B3-985E-4D39-95FE-97C9C879B83A}.Release|Any CPU.Build.0 = Release|Any CPU {0D3FBF8A-7464-4CF7-8C90-3E7886DF2D4D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {0D3FBF8A-7464-4CF7-8C90-3E7886DF2D4D}.Debug|Any CPU.Build.0 = Debug|Any CPU - {0D3FBF8A-7464-4CF7-8C90-3E7886DF2D4D}.Deploy|Any CPU.ActiveCfg = Debug|Any CPU {0D3FBF8A-7464-4CF7-8C90-3E7886DF2D4D}.Release|Any CPU.ActiveCfg = Release|Any CPU {0D3FBF8A-7464-4CF7-8C90-3E7886DF2D4D}.Release|Any CPU.Build.0 = Release|Any CPU {D9A367C9-4C1A-489F-9B05-A0CEA2B53B58}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {D9A367C9-4C1A-489F-9B05-A0CEA2B53B58}.Debug|Any CPU.Build.0 = Debug|Any CPU - {D9A367C9-4C1A-489F-9B05-A0CEA2B53B58}.Deploy|Any CPU.ActiveCfg = Debug|Any CPU {D9A367C9-4C1A-489F-9B05-A0CEA2B53B58}.Release|Any CPU.ActiveCfg = Release|Any CPU {D9A367C9-4C1A-489F-9B05-A0CEA2B53B58}.Release|Any CPU.Build.0 = Release|Any CPU {65DC628F-A640-4111-AB35-3A5652BC1E17}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {65DC628F-A640-4111-AB35-3A5652BC1E17}.Debug|Any CPU.Build.0 = Debug|Any CPU - {65DC628F-A640-4111-AB35-3A5652BC1E17}.Deploy|Any CPU.ActiveCfg = Debug|Any CPU {65DC628F-A640-4111-AB35-3A5652BC1E17}.Release|Any CPU.ActiveCfg = Release|Any CPU {65DC628F-A640-4111-AB35-3A5652BC1E17}.Release|Any CPU.Build.0 = Release|Any CPU {69051C69-12AE-4E7D-A3E6-460D2E282312}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {69051C69-12AE-4E7D-A3E6-460D2E282312}.Debug|Any CPU.Build.0 = Debug|Any CPU - {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 From 5e3e949fd6571ea671d8efe84bcaaa1851a9c55f Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 13 Oct 2016 14:45:41 +0900 Subject: [PATCH 37/38] Revert all counter commits. Requires much further review. --- .../Tests/TestCaseScoreCounter.cs | 159 ------------ .../osu.Desktop.VisualTests.csproj | 1 - .../Graphics/UserInterface/AccuracyCounter.cs | 102 -------- .../UserInterface/AlternativeComboCounter.cs | 91 ------- .../UserInterface/CatchComboCounter.cs | 60 ----- .../UserInterface/NumericRollingCounter.cs | 65 ----- .../Graphics/UserInterface/RollingCounter.cs | 241 ------------------ .../Graphics/UserInterface/ScoreCounter.cs | 32 --- .../UserInterface/StandardComboCounter.cs | 110 -------- .../Graphics/UserInterface/StarCounter.cs | 205 --------------- .../Graphics/UserInterface/ULongCounter.cs | 59 ----- osu.Game/osu.Game.csproj | 18 +- 12 files changed, 2 insertions(+), 1141 deletions(-) delete mode 100644 osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs delete mode 100644 osu.Game/Graphics/UserInterface/AccuracyCounter.cs delete mode 100644 osu.Game/Graphics/UserInterface/AlternativeComboCounter.cs delete mode 100644 osu.Game/Graphics/UserInterface/CatchComboCounter.cs delete mode 100644 osu.Game/Graphics/UserInterface/NumericRollingCounter.cs delete mode 100644 osu.Game/Graphics/UserInterface/RollingCounter.cs delete mode 100644 osu.Game/Graphics/UserInterface/ScoreCounter.cs delete mode 100644 osu.Game/Graphics/UserInterface/StandardComboCounter.cs delete mode 100644 osu.Game/Graphics/UserInterface/StarCounter.cs delete mode 100644 osu.Game/Graphics/UserInterface/ULongCounter.cs diff --git a/osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs b/osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs deleted file mode 100644 index 144adf9098..0000000000 --- a/osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs +++ /dev/null @@ -1,159 +0,0 @@ -//Copyright (c) 2007-2016 ppy Pty Ltd . -//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE - -using System; -using OpenTK.Input; -using osu.Framework.GameModes.Testing; -using osu.Framework.Graphics; -using osu.Game.Graphics.UserInterface; -using osu.Framework.Graphics.UserInterface; -using osu.Framework.Graphics.Transformations; -using OpenTK; -using OpenTK.Graphics; -using osu.Framework.MathUtils; -using osu.Framework.Graphics.Sprites; - -namespace osu.Desktop.Tests -{ - class TestCaseScoreCounter : TestCase - { - public override string Name => @"ScoreCounter"; - - public override string Description => @"Tests multiple counters"; - - public override void Reset() - { - base.Reset(); - - ScoreCounter uc = new ScoreCounter - { - Origin = Anchor.TopRight, - Anchor = Anchor.TopRight, - TextSize = 40, - RollingDuration = 1000, - RollingEasing = EasingTypes.Out, - Count = 0, - Position = new Vector2(20, 20), - LeadingZeroes = 7, - }; - Add(uc); - - StandardComboCounter sc = new StandardComboCounter - { - Origin = Anchor.BottomLeft, - Anchor = Anchor.BottomLeft, - Position = new Vector2(20, 20), - IsRollingProportional = true, - RollingDuration = 20, - PopOutDuration = 250, - Count = 0, - TextSize = 40, - }; - Add(sc); - - CatchComboCounter cc = new CatchComboCounter - { - Origin = Anchor.Centre, - Anchor = Anchor.Centre, - IsRollingProportional = true, - RollingDuration = 20, - PopOutDuration = 250, - Count = 0, - TextSize = 40, - }; - Add(cc); - - AlternativeComboCounter ac = new AlternativeComboCounter - { - Origin = Anchor.BottomLeft, - Anchor = Anchor.BottomLeft, - Position = new Vector2(20, 80), - IsRollingProportional = true, - RollingDuration = 20, - ScaleFactor = 2, - Count = 0, - TextSize = 40, - }; - Add(ac); - - - AccuracyCounter pc = new AccuracyCounter - { - Origin = Anchor.TopRight, - Anchor = Anchor.TopRight, - RollingDuration = 1000, - RollingEasing = EasingTypes.Out, - Count = 100.0f, - Position = new Vector2(20, 60), - }; - Add(pc); - - SpriteText text = new SpriteText - { - Origin = Anchor.BottomLeft, - Anchor = Anchor.BottomLeft, - Position = new Vector2(20, 190), - Text = @"- unset -", - }; - Add(text); - - StarCounter tc = new StarCounter - { - Origin = Anchor.BottomLeft, - Anchor = Anchor.BottomLeft, - Position = new Vector2(20, 160), - }; - Add(tc); - - AddButton(@"Reset all", delegate - { - uc.Count = 0; - sc.Count = 0; - ac.Count = 0; - cc.Count = 0; - pc.SetCount(0, 0); - tc.Count = 0; - text.Text = tc.Count.ToString("0.00"); - }); - - AddButton(@"Hit! :D", delegate - { - uc.Count += 300 + (ulong)(300.0 * (sc.Count > 0 ? sc.Count - 1 : 0) / 25.0); - sc.Count++; - ac.Count++; - cc.CatchFruit(new Color4( - Math.Max(0.5f, RNG.NextSingle()), - Math.Max(0.5f, RNG.NextSingle()), - Math.Max(0.5f, RNG.NextSingle()), - 1) - ); - pc.Numerator++; - pc.Denominator++; - }); - - AddButton(@"miss...", delegate - { - sc.Count = 0; - ac.Count = 0; - cc.Count = 0; - pc.Denominator++; - }); - - AddButton(@"Alter stars", delegate - { - tc.Count = RNG.NextSingle() * (tc.MaxStars + 1); - text.Text = tc.Count.ToString("0.00"); - }); - - AddButton(@"Stop counters", delegate - { - uc.StopRolling(); - sc.StopRolling(); - cc.StopRolling(); - ac.StopRolling(); - pc.StopRolling(); - tc.StopRolling(); - }); - } - } -} diff --git a/osu.Desktop.VisualTests/osu.Desktop.VisualTests.csproj b/osu.Desktop.VisualTests/osu.Desktop.VisualTests.csproj index 44a1aef6de..c54140b267 100644 --- a/osu.Desktop.VisualTests/osu.Desktop.VisualTests.csproj +++ b/osu.Desktop.VisualTests/osu.Desktop.VisualTests.csproj @@ -140,7 +140,6 @@ - diff --git a/osu.Game/Graphics/UserInterface/AccuracyCounter.cs b/osu.Game/Graphics/UserInterface/AccuracyCounter.cs deleted file mode 100644 index d13cd20107..0000000000 --- a/osu.Game/Graphics/UserInterface/AccuracyCounter.cs +++ /dev/null @@ -1,102 +0,0 @@ -//Copyright (c) 2007-2016 ppy Pty Ltd . -//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE - -using osu.Framework.Graphics; -using osu.Framework.Graphics.Transformations; -using osu.Framework.MathUtils; -using osu.Framework.Timing; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace osu.Game.Graphics.UserInterface -{ - /// - /// Used as an accuracy counter. Represented visually as a percentage, internally as a fraction. - /// - public class AccuracyCounter : NumericRollingCounter - { - protected override Type transformType => typeof(TransformAccuracy); - - private long numerator = 0; - public long Numerator - { - get - { - return numerator; - } - set - { - numerator = value; - updateCount(); - } - } - - private ulong denominator = 0; - public ulong Denominator - { - get - { - return denominator; - } - set - { - denominator = value; - updateCount(); - } - } - - public void SetCount(long num, ulong den) - { - numerator = num; - denominator = den; - updateCount(); - } - - private void updateCount() - { - Count = Denominator == 0 ? 100.0f : (Numerator * 100.0f) / Denominator; - } - - public override void ResetCount() - { - numerator = 0; - denominator = 0; - updateCount(); - StopRolling(); - } - - protected override string formatCount(float count) - { - return count.ToString("0.00") + "%"; - } - - protected class TransformAccuracy : Transform - { - public override float CurrentValue - { - get - { - double time = Time; - if (time < StartTime) return StartValue; - if (time >= EndTime) return EndValue; - - return Interpolation.ValueAt(time, StartValue, EndValue, StartTime, EndTime, Easing); - } - } - - public override void Apply(Drawable d) - { - base.Apply(d); - (d as AccuracyCounter).VisibleCount = CurrentValue; - } - - public TransformAccuracy(IClock clock) - : base(clock) - { - } - } - } -} diff --git a/osu.Game/Graphics/UserInterface/AlternativeComboCounter.cs b/osu.Game/Graphics/UserInterface/AlternativeComboCounter.cs deleted file mode 100644 index 9b710174ea..0000000000 --- a/osu.Game/Graphics/UserInterface/AlternativeComboCounter.cs +++ /dev/null @@ -1,91 +0,0 @@ -//Copyright (c) 2007-2016 ppy Pty Ltd . -//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE - -using OpenTK; -using OpenTK.Graphics; -using osu.Framework; -using osu.Framework.Graphics.Transformations; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace osu.Game.Graphics.UserInterface -{ - /// - /// Allows tint and vertical scaling animation. Used in osu!taiko and osu!mania. - /// - public class AlternativeComboCounter : ULongCounter // btw, I'm terribly bad with names... OUENDAN! - { - public Color4 OriginalColour; - public Color4 TintColour = Color4.OrangeRed; - public int TintDuration = 250; - public float ScaleFactor = 2; - public EasingTypes TintEasing = EasingTypes.None; - public bool CanAnimateWhenBackwards = false; - - public AlternativeComboCounter() : base() - { - IsRollingContinuous = false; - } - - public override void Load(BaseGame game) - { - base.Load(game); - - countSpriteText.Hide(); - OriginalColour = Colour; - } - - public override void ResetCount() - { - SetCountWithoutRolling(0); - } - - protected override void transformCount(ulong currentValue, ulong newValue) - { - // Animate rollover only when going backwards - if (newValue > currentValue) - { - updateTransforms(typeof(TransformULongCounter)); - removeTransforms(typeof(TransformULongCounter)); - VisibleCount = newValue; - } - else - transformCount(new TransformULongCounter(Clock), currentValue, newValue); - } - - protected override ulong getProportionalDuration(ulong currentValue, ulong newValue) - { - ulong difference = currentValue > newValue ? currentValue - newValue : currentValue - newValue; - return difference * RollingDuration; - } - - protected virtual void transformAnimate() - { - countSpriteText.FadeColour(TintColour, 0); - countSpriteText.ScaleTo(new Vector2(1, ScaleFactor)); - countSpriteText.FadeColour(OriginalColour, TintDuration, TintEasing); - countSpriteText.ScaleTo(new Vector2(1, 1), TintDuration, TintEasing); - } - - protected override void transformVisibleCount(ulong currentValue, ulong newValue) - { - if (countSpriteText != null) - { - countSpriteText.Text = newValue.ToString("#,0"); - if (newValue == 0) - { - countSpriteText.FadeOut(TintDuration); - return; - } - countSpriteText.Show(); - if (newValue > currentValue || CanAnimateWhenBackwards) - { - transformAnimate(); - } - } - } - } -} diff --git a/osu.Game/Graphics/UserInterface/CatchComboCounter.cs b/osu.Game/Graphics/UserInterface/CatchComboCounter.cs deleted file mode 100644 index 9fb8caa07a..0000000000 --- a/osu.Game/Graphics/UserInterface/CatchComboCounter.cs +++ /dev/null @@ -1,60 +0,0 @@ -//Copyright (c) 2007-2016 ppy Pty Ltd . -//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE - -using OpenTK.Graphics; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace osu.Game.Graphics.UserInterface -{ - /// - /// Similar to Standard, but without the 'x' and has tinted pop-ups. Used in osu!catch. - /// - public class CatchComboCounter : StandardComboCounter - { - public CatchComboCounter() : base() - { - CanPopOutWhenBackwards = true; - } - - protected override string formatCount(ulong count) - { - return count.ToString("#,0"); - } - - protected override void transformCount(ulong currentValue, ulong newValue) - { - // Animate rollover only when going backwards - if (newValue > currentValue) - { - updateTransforms(typeof(TransformULongCounter)); - removeTransforms(typeof(TransformULongCounter)); - VisibleCount = newValue; - } - else - { - // Backwards pop-up animation has no tint colour - popOutSpriteText.Colour = countSpriteText.Colour; - transformCount(new TransformULongCounter(Clock), currentValue, newValue); - } - } - - /// - /// Increaces counter and tints pop-out before animation. - /// - /// Last grabbed fruit colour. - public void CatchFruit(Color4 colour) - { - popOutSpriteText.Colour = colour; - Count++; - } - - public override void ResetCount() - { - base.ResetCount(); - } - } -} diff --git a/osu.Game/Graphics/UserInterface/NumericRollingCounter.cs b/osu.Game/Graphics/UserInterface/NumericRollingCounter.cs deleted file mode 100644 index e1cb9ddbb4..0000000000 --- a/osu.Game/Graphics/UserInterface/NumericRollingCounter.cs +++ /dev/null @@ -1,65 +0,0 @@ -//Copyright (c) 2007-2016 ppy Pty Ltd . -//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE - -using osu.Framework; -using osu.Framework.Graphics; -using osu.Framework.Graphics.Sprites; -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace osu.Game.Graphics.UserInterface -{ - /// - /// Skeleton for a numeric counter with a simple roll-up animation. - /// - /// Type of the actual counter. - public abstract class NumericRollingCounter : RollingCounter - { - protected SpriteText countSpriteText; - - protected float textSize = 20.0f; - public float TextSize - { - get { return textSize; } - set - { - textSize = value; - updateTextSize(); - } - } - - public override void Load(BaseGame game) - { - base.Load(game); - - Children = new Drawable[] - { - countSpriteText = new SpriteText - { - Text = formatCount(Count), - TextSize = this.TextSize, - Anchor = this.Anchor, - Origin = this.Origin, - }, - }; - } - - protected override void transformVisibleCount(T currentValue, T newValue) - { - if (countSpriteText != null) - { - countSpriteText.Text = formatCount(newValue); - } - } - - protected virtual void updateTextSize() - { - if (countSpriteText != null) - countSpriteText.TextSize = TextSize; - } - } -} diff --git a/osu.Game/Graphics/UserInterface/RollingCounter.cs b/osu.Game/Graphics/UserInterface/RollingCounter.cs deleted file mode 100644 index b0686ca0cb..0000000000 --- a/osu.Game/Graphics/UserInterface/RollingCounter.cs +++ /dev/null @@ -1,241 +0,0 @@ -using osu.Framework; -using osu.Framework.Graphics; -using osu.Framework.Graphics.Containers; -using osu.Framework.Graphics.Transformations; -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace osu.Game.Graphics.UserInterface -{ - /// - /// Skeleton for a counter which value rolls-up in a lapse of time. - /// - /// - /// This class only abstracts the basics to roll-up a value in a lapse of time by using Transforms. - /// In order to show a value, you must implement a way to display it, i.e., as a numeric counter or a bar. - /// - /// Type of the actual counter. - public abstract class RollingCounter : Container - { - /// - /// Type of the Transform to use. - /// - /// - /// Must be a subclass of Transform - /// - protected virtual Type transformType => typeof(Transform); - - protected ulong RollingTotalDuration = 0; - - /// - /// If true, each time the Count is updated, it will roll over from the current visible value. - /// Else, it will roll up from the current count value. - /// - public bool IsRollingContinuous = true; - - /// - /// If true, the roll-up duration will be proportional to the counter. - /// - public bool IsRollingProportional = false; - - /// - /// If IsRollingProportional = false, duration in milliseconds for the counter roll-up animation for each - /// element; else duration in milliseconds for the counter roll-up animation in total. - /// - public ulong RollingDuration = 0; - - /// - /// Easing for the counter rollover animation. - /// - public EasingTypes RollingEasing = EasingTypes.None; - - protected T prevVisibleCount; - protected T visibleCount; - - /// - /// Value shown at the current moment. - /// - public virtual T VisibleCount - { - get - { - return visibleCount; - } - protected set - { - prevVisibleCount = visibleCount; - if (visibleCount.Equals(value)) - return; - visibleCount = value; - transformVisibleCount(prevVisibleCount, value); - } - } - - protected T prevCount; - protected T count; - - /// - /// Actual value of counter. - /// - public virtual T Count - { - get - { - return count; - } - set - { - prevCount = count; - count = value; - if (Clock != null) - { - RollingTotalDuration = - IsRollingProportional - ? getProportionalDuration(VisibleCount, value) - : RollingDuration; - transformCount(IsRollingContinuous ? VisibleCount : prevCount, value); - } - } - } - - protected RollingCounter() - { - Debug.Assert( - transformType.IsSubclassOf(typeof(Transform)) || transformType == typeof(Transform), - @"transformType should be a subclass of Transform." - ); - } - - public override void Load(BaseGame game) - { - base.Load(game); - removeTransforms(transformType); - if (Count == null) - ResetCount(); - VisibleCount = Count; - } - - /// - /// Sets count value, bypassing rollover animation. - /// - /// New count value. - public virtual void SetCountWithoutRolling(T count) - { - Count = count; - StopRolling(); - } - - /// - /// Stops rollover animation, forcing the visible count to be the actual count. - /// - public virtual void StopRolling() - { - removeTransforms(transformType); - VisibleCount = Count; - } - - /// - /// Resets count to default value. - /// - public abstract void ResetCount(); - - /// - /// Calculates the duration of the roll-up animation by using the difference between the current visible value - /// and the new final value. - /// - /// - /// To be used in conjunction with IsRollingProportional = true. - /// Unless a derived class needs to have a proportional rolling, it is not necessary to override this function. - /// - /// Current visible value. - /// New final value. - /// Calculated rollover duration in milliseconds. - protected virtual ulong getProportionalDuration(T currentValue, T newValue) - { - return RollingDuration; - } - - /// - /// Used to format counts. - /// - /// Count to format. - /// Count formatted as a string. - protected virtual string formatCount(T count) - { - return count.ToString(); - } - - protected void updateTransforms(Type type) - { - foreach (ITransform t in Transforms.AliveItems) - if (t.GetType() == type) - t.Apply(this); - } - - protected void removeTransforms(Type type) - { - Transforms.RemoveAll(t => t.GetType() == type); - } - - /// - /// Called when the count is updated to add a transformer that changes the value of the visible count (i.e. - /// implement the rollover animation). - /// - /// Count value before modification. - /// Expected count value after modification- - /// - /// Unless you need to set a custom animation according to the current or new value of the count, the - /// recommended approach is to call transformCount(CustomTransformer(Clock), currentValue, newValue), where - /// CustomTransformer is of type transformerType. - /// By using this approach, there is no need to check if the Clock is not null; this validation is done before - /// adding the transformer. - /// - /// - protected virtual void transformCount(T currentValue, T newValue) - { - object[] parameters = { Clock }; - transformCount((Transform)Activator.CreateInstance(transformType, parameters), currentValue, newValue); - } - - /// - /// Intended to be used by transformCount(). - /// - /// - protected void transformCount(Transform transform, T currentValue, T newValue) - { - Type type = transform.GetType(); - - updateTransforms(type); - removeTransforms(type); - - if (Clock == null) - return; - - if (RollingDuration == 0) - { - VisibleCount = Count; - return; - } - - transform.StartTime = Time; - transform.EndTime = Time + RollingTotalDuration; - transform.StartValue = currentValue; - transform.EndValue = newValue; - transform.Easing = RollingEasing; - - Transforms.Add(transform); - } - - /// - /// This procedure is called each time the visible count value is updated. - /// Override to create custom animations. - /// - /// Visible count value before modification. - /// Expected visible count value after modification- - protected abstract void transformVisibleCount(T currentValue, T newValue); - } -} diff --git a/osu.Game/Graphics/UserInterface/ScoreCounter.cs b/osu.Game/Graphics/UserInterface/ScoreCounter.cs deleted file mode 100644 index d5b9edf73d..0000000000 --- a/osu.Game/Graphics/UserInterface/ScoreCounter.cs +++ /dev/null @@ -1,32 +0,0 @@ -//Copyright (c) 2007-2016 ppy Pty Ltd . -//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE - -using osu.Framework; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace osu.Game.Graphics.UserInterface -{ - public class ScoreCounter : ULongCounter - { - /// - /// How many leading zeroes the counter will have. - /// - public uint LeadingZeroes = 0; - - public override void Load(BaseGame game) - { - base.Load(game); - - countSpriteText.FixedWidth = true; - } - - protected override string formatCount(ulong count) - { - return count.ToString("D" + LeadingZeroes); - } - } -} diff --git a/osu.Game/Graphics/UserInterface/StandardComboCounter.cs b/osu.Game/Graphics/UserInterface/StandardComboCounter.cs deleted file mode 100644 index 676e3672d2..0000000000 --- a/osu.Game/Graphics/UserInterface/StandardComboCounter.cs +++ /dev/null @@ -1,110 +0,0 @@ -//Copyright (c) 2007-2016 ppy Pty Ltd . -//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE - -using osu.Framework; -using osu.Framework.Graphics.Sprites; -using osu.Framework.Graphics.Transformations; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace osu.Game.Graphics.UserInterface -{ - /// - /// Uses the 'x' symbol and has a pop-out effect while rolling over. Used in osu! standard. - /// - public class StandardComboCounter : ULongCounter - { - public SpriteText popOutSpriteText; - - public ulong PopOutDuration = 0; - public float PopOutBigScale = 2.0f; - public float PopOutSmallScale = 1.2f; - public EasingTypes PopOutEasing = EasingTypes.None; - public bool CanPopOutWhenBackwards = false; - public float PopOutInitialAlpha = 0.75f; - - public StandardComboCounter() : base() - { - IsRollingContinuous = false; - } - - public override void Load(BaseGame game) - { - base.Load(game); - - countSpriteText.Alpha = 0; - Add(popOutSpriteText = new SpriteText - { - Text = formatCount(Count), - Origin = this.Origin, - Anchor = this.Anchor, - TextSize = this.TextSize, - Alpha = 0, - }); - } - - protected override void updateTextSize() - { - base.updateTextSize(); - if (popOutSpriteText != null) - popOutSpriteText.TextSize = this.TextSize; - } - - - protected override void transformCount(ulong currentValue, ulong newValue) - { - // Animate rollover only when going backwards - if (newValue > currentValue) - { - updateTransforms(typeof(TransformULongCounter)); - removeTransforms(typeof(TransformULongCounter)); - VisibleCount = newValue; - } - else - transformCount(new TransformULongCounter(Clock), currentValue, newValue); - } - - protected override ulong getProportionalDuration(ulong currentValue, ulong newValue) - { - ulong difference = currentValue > newValue ? currentValue - newValue : currentValue - newValue; - return difference * RollingDuration; - } - - protected override string formatCount(ulong count) - { - return count.ToString("#,0") + "x"; - } - - protected virtual void transformPopOut() - { - countSpriteText.ScaleTo(PopOutSmallScale); - countSpriteText.ScaleTo(1, PopOutDuration, PopOutEasing); - - popOutSpriteText.ScaleTo(PopOutBigScale); - popOutSpriteText.FadeTo(PopOutInitialAlpha); - popOutSpriteText.ScaleTo(1, PopOutDuration, PopOutEasing); - popOutSpriteText.FadeOut(PopOutDuration, PopOutEasing); - } - - protected override void transformVisibleCount(ulong currentValue, ulong newValue) - { - if (countSpriteText != null && popOutSpriteText != null) - { - countSpriteText.Text = popOutSpriteText.Text = formatCount(newValue); - if (newValue == 0) - { - countSpriteText.FadeOut(PopOutDuration); - } - else - { - countSpriteText.Show(); - if (newValue > currentValue || CanPopOutWhenBackwards) - transformPopOut(); - } - } - } - } -} diff --git a/osu.Game/Graphics/UserInterface/StarCounter.cs b/osu.Game/Graphics/UserInterface/StarCounter.cs deleted file mode 100644 index 790e0ddcc8..0000000000 --- a/osu.Game/Graphics/UserInterface/StarCounter.cs +++ /dev/null @@ -1,205 +0,0 @@ -//Copyright (c) 2007-2016 ppy Pty Ltd . -//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE - -using OpenTK; -using osu.Framework; -using osu.Framework.Graphics; -using osu.Framework.Graphics.Containers; -using osu.Framework.Graphics.Transformations; -using osu.Framework.MathUtils; -using osu.Framework.Timing; -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace osu.Game.Graphics.UserInterface -{ - /// - /// Shows a float count as stars. Used as star difficulty display. - /// - public class StarCounter : RollingCounter - { - protected override Type transformType => typeof(TransformStarCounter); - - protected Container starContainer; - protected List stars = new List(); - - public ulong StarAnimationDuration = 500; - public EasingTypes StarAnimationEasing = EasingTypes.OutElasticHalf; - public ulong FadeDuration = 100; - public float MinStarSize = 0.3f; - public float MinStarAlpha = 0.5f; - public int MaxStars = 10; - public int StarSize = 20; - public int StarSpacing = 4; - - public StarCounter() : base() - { - IsRollingProportional = true; - RollingDuration = 150; - } - - protected override ulong getProportionalDuration(float currentValue, float newValue) - { - return (ulong)(Math.Abs(currentValue - newValue) * RollingDuration); - } - - public override void ResetCount() - { - Count = 0; - StopRolling(); - } - - public override void Load(BaseGame game) - { - base.Load(game); - - Children = new Drawable[] - { - starContainer = new Container - { - Anchor = Anchor.CentreLeft, - Origin = Anchor.CentreLeft, - Width = MaxStars * StarSize + Math.Max(MaxStars - 1, 0) * StarSpacing, - Height = StarSize, - } - }; - - for (int i = 0; i < MaxStars; i++) - { - TextAwesome star = new TextAwesome - { - Icon = FontAwesome.star, - Anchor = Anchor.CentreLeft, - Origin = Anchor.Centre, - TextSize = StarSize, - Scale = new Vector2(MinStarSize), - Alpha = (i == 0) ? 1.0f : MinStarAlpha, - Position = new Vector2((StarSize + StarSpacing) * i + (StarSize + StarSpacing) / 2, 0), - }; - - //todo: user Container once we have it. - stars.Add(star); - starContainer.Add(star); - } - - ResetCount(); - } - - protected override void transformCount(float currentValue, float newValue) - { - transformStar((int)Math.Floor(currentValue), currentValue, currentValue < newValue); - transformCount(new TransformStarCounter(Clock), currentValue, newValue); - } - - protected void updateTransformStar(int i) - { - foreach (ITransform t in stars[i].Transforms.AliveItems) - if (t.GetType() == typeof(TransformAlpha) || t.GetType() == typeof(TransformScaleVector)) - t.Apply(stars[i]); - - stars[i].Transforms.RemoveAll(t => - t.GetType() == typeof(TransformScaleVector) || t.GetType() == typeof(TransformAlpha) - ); - } - - protected void transformStarScale(int i, TransformScaleVector transform, bool isIncrement, double startTime) - { - transform.StartTime = startTime; - transform.EndTime = transform.StartTime + StarAnimationDuration; - transform.StartValue = stars[i].Scale; - transform.EndValue = new Vector2( - Interpolation.ValueAt( - Math.Min(Math.Max(i, Count), i + 1), - MinStarSize, - 1.0f, - i, - i + 1 - ) - ); - transform.Easing = StarAnimationEasing; - - stars[i].Transforms.Add(transform); - } - - protected void transformStarAlpha(int i, TransformAlpha transform, bool isIncrement, double startTime) - { - transform.StartTime = startTime; - //if (!isIncrement) - //transform.StartTime += StarAnimationDuration - FadeDuration; - transform.EndTime = transform.StartTime + FadeDuration; - transform.StartValue = stars[i].Alpha; - transform.EndValue = i < Count ? 1.0f : MinStarAlpha; - - stars[i].Transforms.Add(transform); - } - - - protected void transformStar(int i, float value, bool isIncrement) - { - if (i >= MaxStars) - return; - - if (Clock == null) - return; - - // Calculate time where animation should had started - double startTime = Time; - // If incrementing, animation should had started when VisibleCount crossed start of star (i) - if (isIncrement) - startTime -= i == (int)Math.Floor(prevCount) ? - getProportionalDuration(prevCount, value) : getProportionalDuration(i, value); - // If decrementing, animation should had started when VisibleCount crossed end of star (i + 1) - else - startTime -= i == (int)Math.Floor(prevCount) ? - getProportionalDuration(prevCount, value) : getProportionalDuration(i + 1, value); - - updateTransformStar(i); - - transformStarScale(i, new TransformScaleVector(Clock), isIncrement, startTime); - transformStarAlpha(i, new TransformAlpha(Clock), isIncrement, startTime); - } - - protected override void transformVisibleCount(float currentValue, float newValue) - { - // Detect increment that passes over an integer value - if (Math.Ceiling(currentValue) <= Math.Floor(newValue)) - for (int i = (int)Math.Ceiling(currentValue); i <= Math.Floor(newValue); i++) - transformStar(i, newValue, true); - - // Detect decrement that passes over an integer value - if (Math.Floor(currentValue) >= Math.Ceiling(newValue)) - for (int i = (int)Math.Floor(newValue); i < Math.Floor(currentValue); i++) - transformStar(i, newValue, false); - } - - protected class TransformStarCounter : Transform - { - public override float CurrentValue - { - get - { - double time = Time; - if (time < StartTime) return StartValue; - if (time >= EndTime) return EndValue; - - return Interpolation.ValueAt(time, StartValue, EndValue, StartTime, EndTime, Easing); - } - } - - public override void Apply(Drawable d) - { - base.Apply(d); - (d as StarCounter).VisibleCount = CurrentValue; - } - - public TransformStarCounter(IClock clock) - : base(clock) - { - } - } - } -} diff --git a/osu.Game/Graphics/UserInterface/ULongCounter.cs b/osu.Game/Graphics/UserInterface/ULongCounter.cs deleted file mode 100644 index 35df8f5cc8..0000000000 --- a/osu.Game/Graphics/UserInterface/ULongCounter.cs +++ /dev/null @@ -1,59 +0,0 @@ -//Copyright (c) 2007-2016 ppy Pty Ltd . -//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE - -using osu.Framework.Graphics; -using osu.Framework.Graphics.Transformations; -using osu.Framework.MathUtils; -using osu.Framework.Timing; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace osu.Game.Graphics.UserInterface -{ - /// - /// A simple rolling counter that accepts unsigned long values. - /// - public class ULongCounter : NumericRollingCounter - { - protected override Type transformType => typeof(TransformULongCounter); - - public override void ResetCount() - { - SetCountWithoutRolling(0); - } - - protected override string formatCount(ulong count) - { - return count.ToString("#,0"); - } - - protected class TransformULongCounter : Transform - { - public override ulong CurrentValue - { - get - { - double time = Time; - if (time < StartTime) return StartValue; - if (time >= EndTime) return EndValue; - - return (ulong)Interpolation.ValueAt(time, StartValue, EndValue, StartTime, EndTime, Easing); - } - } - - public override void Apply(Drawable d) - { - base.Apply(d); - (d as ULongCounter).VisibleCount = CurrentValue; - } - - public TransformULongCounter(IClock clock) - : base(clock) - { - } - } - } -} diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 982798f24b..068c1e1fd8 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -136,19 +136,10 @@ - - - - - - - - - @@ -197,12 +188,7 @@ - - - - - - +