From fd10e6e582f44f60e9c63e5e3fe15312f61257a1 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Thu, 13 Oct 2016 10:15:08 -0400 Subject: [PATCH 1/9] Copy imported beatmaps into beatmap storage --- .../Beatmaps/IO/LegacyFilesystemReader.cs | 4 +- osu.Game/Beatmaps/BeatmapSet.cs | 2 + osu.Game/Beatmaps/IO/OszArchiveReader.cs | 3 +- osu.Game/Database/BeatmapDatabase.cs | 42 ++++++++++++++++--- osu.Game/OsuGame.cs | 3 +- 5 files changed, 44 insertions(+), 10 deletions(-) diff --git a/osu.Desktop/Beatmaps/IO/LegacyFilesystemReader.cs b/osu.Desktop/Beatmaps/IO/LegacyFilesystemReader.cs index a6367ebfab..13c881d1f8 100644 --- a/osu.Desktop/Beatmaps/IO/LegacyFilesystemReader.cs +++ b/osu.Desktop/Beatmaps/IO/LegacyFilesystemReader.cs @@ -20,8 +20,8 @@ namespace osu.Desktop.Beatmaps.IO private string basePath { get; set; } private string[] beatmaps { get; set; } - private Beatmap firstMap { get; set; } - + private Beatmap firstMap { get; set; } + public LegacyFilesystemReader(string path) { basePath = path; diff --git a/osu.Game/Beatmaps/BeatmapSet.cs b/osu.Game/Beatmaps/BeatmapSet.cs index 5f1be7f9b0..8ba8ef0d53 100644 --- a/osu.Game/Beatmaps/BeatmapSet.cs +++ b/osu.Game/Beatmaps/BeatmapSet.cs @@ -22,5 +22,7 @@ namespace osu.Game.Beatmaps public BeatmapMetadata Metadata { get; set; } [Ignore] public User Creator { get; set; } + public string Hash { get; set; } + public string Path { get; set; } } } diff --git a/osu.Game/Beatmaps/IO/OszArchiveReader.cs b/osu.Game/Beatmaps/IO/OszArchiveReader.cs index b70bee076c..b83cf8ad04 100644 --- a/osu.Game/Beatmaps/IO/OszArchiveReader.cs +++ b/osu.Game/Beatmaps/IO/OszArchiveReader.cs @@ -1,6 +1,7 @@ using System; using System.IO; using System.Linq; +using System.Security.Cryptography; using Ionic.Zip; using osu.Game.Beatmaps.Formats; @@ -20,7 +21,7 @@ namespace osu.Game.Beatmaps.IO private ZipFile archive { get; set; } private string[] beatmaps { get; set; } - private Beatmap firstMap { get; set; } + private Beatmap firstMap { get; set; } public OszArchiveReader(Stream archiveStream) { diff --git a/osu.Game/Database/BeatmapDatabase.cs b/osu.Game/Database/BeatmapDatabase.cs index 36f8776eb0..dcfc6c91df 100644 --- a/osu.Game/Database/BeatmapDatabase.cs +++ b/osu.Game/Database/BeatmapDatabase.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Security.Cryptography; using osu.Framework.Platform; using osu.Game.Beatmaps; using osu.Game.Beatmaps.Formats; @@ -12,9 +13,11 @@ namespace osu.Game.Database public class BeatmapDatabase { private static SQLiteConnection connection { get; set; } + private BasicStorage storage; public BeatmapDatabase(BasicStorage storage) { + this.storage = storage; if (connection == null) { connection = storage.GetDatabase(@"beatmaps"); @@ -24,17 +27,39 @@ namespace osu.Game.Database connection.CreateTable(); } } - public void AddBeatmap(ArchiveReader input) + public void AddBeatmap(string path) { - var metadata = input.ReadMetadata(); + string hash = null; + ArchiveReader reader; + if (File.Exists(path)) // Not always the case, i.e. for LegacyFilesystemReader + { + using (var md5 = MD5.Create()) + using (var input = storage.GetStream(path)) + { + hash = BitConverter.ToString(md5.ComputeHash(input)).Replace("-", "").ToLowerInvariant(); + input.Seek(0, SeekOrigin.Begin); + var outputPath = Path.Combine(@"beatmaps", hash.Remove(1), hash.Remove(2), hash); + using (var output = storage.GetStream(outputPath, FileAccess.Write)) + input.CopyTo(output); + reader = ArchiveReader.GetReader(storage, path = outputPath); + } + } + else + reader = ArchiveReader.GetReader(storage, path); + var metadata = reader.ReadMetadata(); if (connection.Table().Count(b => b.BeatmapSetID == metadata.BeatmapSetID) != 0) return; - string[] mapNames = input.ReadBeatmaps(); - var beatmapSet = new BeatmapSet { BeatmapSetID = metadata.BeatmapSetID }; + string[] mapNames = reader.ReadBeatmaps(); + var beatmapSet = new BeatmapSet + { + BeatmapSetID = metadata.BeatmapSetID, + Path = path, + Hash = hash, + }; var maps = new List(); foreach (var name in mapNames) { - using (var stream = new StreamReader(input.ReadFile(name))) + using (var stream = new StreamReader(reader.ReadFile(name))) { var decoder = BeatmapDecoder.GetDecoder(stream); var beatmap = decoder.Decode(stream); @@ -45,6 +70,13 @@ namespace osu.Game.Database beatmapSet.BeatmapMetadataID = connection.Insert(metadata); connection.Insert(beatmapSet); connection.InsertAll(maps); + } + + /// + /// Given a BeatmapSet pulled from the database, loads the rest of its data from disk. + /// public void PopulateBeatmap(BeatmapSet beatmap) + { + // TODO } } } \ No newline at end of file diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index 9eb32117c5..27e75629d4 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -73,8 +73,7 @@ namespace osu.Game { try { - var reader = ArchiveReader.GetReader(Host.Storage, message.Path); - Beatmaps.AddBeatmap(reader); + Beatmaps.AddBeatmap(message.Path); // TODO: Switch to beatmap list and select the new song } catch (Exception ex) From acd54d1ebcc6f2703f4fc61ce4f147ee4790761b Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Thu, 13 Oct 2016 22:21:15 +0800 Subject: [PATCH 2/9] Single Visibility enum type. --- osu.Game/OsuGame.cs | 24 ++++++++++++------------ osu.Game/Overlays/ChatConsole.cs | 16 +++++----------- osu.Game/Overlays/Toolbar.cs | 16 +++++----------- osu.Game/Overlays/Visibility.cs | 17 +++++++++++++++++ osu.Game/osu.Game.csproj | 1 + 5 files changed, 40 insertions(+), 34 deletions(-) create mode 100644 osu.Game/Overlays/Visibility.cs diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index 9eb32117c5..4c1d2e1b98 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -31,7 +31,7 @@ namespace osu.Game { public string Path; } - + public Toolbar Toolbar; public ChatConsole Chat; public MainMenu MainMenu => intro?.ChildGameMode as MainMenu; @@ -40,7 +40,7 @@ namespace osu.Game private IpcChannel BeatmapIPC; public Bindable PlayMode; - + public OsuGame(string[] args) { this.args = args; @@ -56,7 +56,7 @@ namespace osu.Game public override void Load(BaseGame game) { BeatmapIPC = new IpcChannel(Host); - + if (!Host.IsPrimaryInstance) { if (args.Length == 1 && File.Exists(args[0])) @@ -83,7 +83,7 @@ namespace osu.Game Console.WriteLine($@"Failed to import beatmap: {ex}"); } }; - + base.Load(game); //attach our bindables to the audio subsystem. @@ -113,10 +113,10 @@ namespace osu.Game } }); - Toolbar.State = ToolbarState.Hidden; + Toolbar.State = Visibility.Hidden; Toolbar.Flush(); - Chat.State = ChatConsoleState.Hidden; + Chat.State = Visibility.Hidden; Chat.Flush(); intro.ModePushed += modeAdded; @@ -134,10 +134,10 @@ namespace osu.Game switch (args.Key) { case Key.F8: - Chat.State = Chat.State == ChatConsoleState.Hidden ? ChatConsoleState.Visible : ChatConsoleState.Hidden; + Chat.State = Chat.State.Reverse(); return true; } - + return base.OnKeyDown(state, args); } @@ -152,12 +152,12 @@ namespace osu.Game //central game mode change logic. if (newMode is Player || newMode is Intro) { - Toolbar.State = ToolbarState.Hidden; - Chat.State = ChatConsoleState.Hidden; + Toolbar.State = Visibility.Hidden; + Chat.State = Visibility.Hidden; } else { - Toolbar.State = ToolbarState.Visible; + Toolbar.State = Visibility.Visible; } Cursor.FadeIn(100); @@ -178,7 +178,7 @@ namespace osu.Game }); return true; } - + return base.OnExiting(); } diff --git a/osu.Game/Overlays/ChatConsole.cs b/osu.Game/Overlays/ChatConsole.cs index 5763275486..7293ccfdf9 100644 --- a/osu.Game/Overlays/ChatConsole.cs +++ b/osu.Game/Overlays/ChatConsole.cs @@ -25,7 +25,7 @@ using osu.Framework; namespace osu.Game.Overlays { - public class ChatConsole : Container, IStateful + public class ChatConsole : Container, IStateful { private ChannelDisplay channelDisplay; @@ -140,9 +140,9 @@ namespace osu.Game.Overlays api.Queue(fetchReq); } - private ChatConsoleState state; + private Visibility state; - public ChatConsoleState State + public Visibility State { get { return state; } @@ -154,11 +154,11 @@ namespace osu.Game.Overlays switch (state) { - case ChatConsoleState.Hidden: + case Visibility.Hidden: MoveToY(-Size.Y, transition_length, EasingTypes.InQuint); FadeOut(transition_length, EasingTypes.InQuint); break; - case ChatConsoleState.Visible: + case Visibility.Visible: MoveToY(0, transition_length, EasingTypes.OutQuint); FadeIn(transition_length, EasingTypes.OutQuint); break; @@ -166,10 +166,4 @@ namespace osu.Game.Overlays } } } - - public enum ChatConsoleState - { - Visible, - Hidden, - } } diff --git a/osu.Game/Overlays/Toolbar.cs b/osu.Game/Overlays/Toolbar.cs index 185123e0e3..ce2aad61b3 100644 --- a/osu.Game/Overlays/Toolbar.cs +++ b/osu.Game/Overlays/Toolbar.cs @@ -16,7 +16,7 @@ using osu.Framework; namespace osu.Game.Overlays { - public class Toolbar : Container, IStateful + public class Toolbar : Container, IStateful { const float height = 50; @@ -26,9 +26,9 @@ namespace osu.Game.Overlays private ToolbarModeSelector modeSelector; - private ToolbarState state; + private Visibility state; - public ToolbarState State + public Visibility State { get { return state; } set @@ -39,11 +39,11 @@ namespace osu.Game.Overlays switch (state) { - case ToolbarState.Hidden: + case Visibility.Hidden: MoveToY(-Size.Y, transition_time, EasingTypes.InQuint); FadeOut(transition_time, EasingTypes.InQuint); break; - case ToolbarState.Visible: + case Visibility.Visible: MoveToY(0, transition_time, EasingTypes.OutQuint); FadeIn(transition_time, EasingTypes.OutQuint); break; @@ -119,10 +119,4 @@ namespace osu.Game.Overlays public void SetGameMode(PlayMode mode) => modeSelector.SetGameMode(mode); } - - public enum ToolbarState - { - Visible, - Hidden, - } } diff --git a/osu.Game/Overlays/Visibility.cs b/osu.Game/Overlays/Visibility.cs new file mode 100644 index 0000000000..c86ab5c401 --- /dev/null +++ b/osu.Game/Overlays/Visibility.cs @@ -0,0 +1,17 @@ +//Copyright (c) 2007-2016 ppy Pty Ltd . +//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +namespace osu.Game.Overlays +{ + public enum Visibility + { + Hidden, + Visible + } + + public static class OverlayVisibilityHelper + { + public static Visibility Reverse(this Visibility input) + => input == Visibility.Visible ? Visibility.Hidden : Visibility.Visible; + } +} diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 068c1e1fd8..1f89696ded 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -160,6 +160,7 @@ + From c93a440d3bf5c20b37e9db3836efa2ceaecd93f0 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Thu, 13 Oct 2016 22:27:37 +0800 Subject: [PATCH 3/9] Make Options:IStateful. --- osu.Game/GameModes/Menu/MainMenu.cs | 3 ++- osu.Game/OsuGame.cs | 2 +- osu.Game/Overlays/Options.cs | 30 ++++++++++++++--------------- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/osu.Game/GameModes/Menu/MainMenu.cs b/osu.Game/GameModes/Menu/MainMenu.cs index f6f9a79bf1..f029d0b8ef 100644 --- a/osu.Game/GameModes/Menu/MainMenu.cs +++ b/osu.Game/GameModes/Menu/MainMenu.cs @@ -14,6 +14,7 @@ using osu.Game.GameModes.Play; using osu.Game.Graphics.Containers; using OpenTK; using osu.Framework; +using osu.Game.Overlays; namespace osu.Game.GameModes.Menu { @@ -48,7 +49,7 @@ namespace osu.Game.GameModes.Menu OnTest = delegate { Push(new TestBrowser()); }, OnExit = delegate { Scheduler.AddDelayed(Exit, ButtonSystem.EXIT_DELAY); }, OnSettings = delegate { - osu.Options.PoppedOut = !osu.Options.PoppedOut; + osu.Options.State = osu.Options.State.Reverse(); }, } } diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index 4c1d2e1b98..6fb8e8f8ba 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -96,7 +96,7 @@ namespace osu.Game Toolbar = new Toolbar { OnHome = delegate { MainMenu?.MakeCurrent(); }, - OnSettings = delegate { Options.PoppedOut = !Options.PoppedOut; }, + OnSettings = delegate { Options.State = Options.State.Reverse(); }, OnPlayModeChange = delegate (PlayMode m) { PlayMode.Value = m; }, Alpha = 0.001f, }, diff --git a/osu.Game/Overlays/Options.cs b/osu.Game/Overlays/Options.cs index bdab31bc6e..6722b0abf6 100644 --- a/osu.Game/Overlays/Options.cs +++ b/osu.Game/Overlays/Options.cs @@ -13,7 +13,7 @@ using osu.Framework; namespace osu.Game.Overlays { - public class Options : Container + public class Options : Container, IStateful { const float width = 300; @@ -41,35 +41,35 @@ namespace osu.Game.Overlays switch (args.Key) { case Key.Escape: - if (!poppedOut) return false; + if (State == Visibility.Hidden) return false; - PoppedOut = false; + State = Visibility.Hidden; return true; } return base.OnKeyDown(state, args); } - private bool poppedOut; + private Visibility state; - public bool PoppedOut + public Visibility State { - get { return poppedOut; } + get { return state; } set { - if (value == poppedOut) return; + if (value == state) return; - poppedOut = value; + state = value; - if (poppedOut) + switch (state) { - MoveTo(new Vector2(0, 0), 300, EasingTypes.Out); + case Visibility.Hidden: + MoveTo(new Vector2(-width, 0), 300, EasingTypes.Out); + break; + case Visibility.Visible: + MoveTo(new Vector2(0, 0), 300, EasingTypes.Out); + break; } - else - { - MoveTo(new Vector2(-width, 0), 300, EasingTypes.Out); - } - } } } From 25d08c8e2cba35a40e996afe9212d3294d722417 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Thu, 13 Oct 2016 10:29:30 -0400 Subject: [PATCH 4/9] Improve beatmap loading and hydration --- .../Beatmaps/IO/LegacyFilesystemReader.cs | 3 ++- .../Beatmaps/Formats/OsuLegacyDecoderTest.cs | 19 +++++++++----- osu.Game/Beatmaps/BeatmapSet.cs | 2 +- osu.Game/Beatmaps/Formats/BeatmapDecoder.cs | 2 +- osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs | 19 +++++++------- osu.Game/Beatmaps/IO/OszArchiveReader.cs | 3 ++- osu.Game/Database/BeatmapDatabase.cs | 26 ++++++++++++++++--- 7 files changed, 50 insertions(+), 24 deletions(-) diff --git a/osu.Desktop/Beatmaps/IO/LegacyFilesystemReader.cs b/osu.Desktop/Beatmaps/IO/LegacyFilesystemReader.cs index 13c881d1f8..b4aaa2fa03 100644 --- a/osu.Desktop/Beatmaps/IO/LegacyFilesystemReader.cs +++ b/osu.Desktop/Beatmaps/IO/LegacyFilesystemReader.cs @@ -31,7 +31,8 @@ namespace osu.Desktop.Beatmaps.IO using (var stream = new StreamReader(ReadFile(beatmaps[0]))) { var decoder = BeatmapDecoder.GetDecoder(stream); - firstMap = decoder.Decode(stream); + firstMap = new Beatmap(); + decoder.Decode(stream, firstMap); } } diff --git a/osu.Game.Tests/Beatmaps/Formats/OsuLegacyDecoderTest.cs b/osu.Game.Tests/Beatmaps/Formats/OsuLegacyDecoderTest.cs index 7eddb2a7dc..adc78a55bf 100644 --- a/osu.Game.Tests/Beatmaps/Formats/OsuLegacyDecoderTest.cs +++ b/osu.Game.Tests/Beatmaps/Formats/OsuLegacyDecoderTest.cs @@ -3,6 +3,7 @@ using System.IO; using NUnit.Framework; using OpenTK; using OpenTK.Graphics; +using osu.Game.Beatmaps; using osu.Game.Beatmaps.Formats; using osu.Game.Beatmaps.Objects.Osu; using osu.Game.Beatmaps.Samples; @@ -25,7 +26,8 @@ namespace osu.Game.Tests.Beatmaps.Formats var decoder = new OsuLegacyDecoder(); using (var stream = Resource.OpenResource("Soleily - Renatus (Gamu) [Insane].osu")) { - var beatmap = decoder.Decode(new StreamReader(stream)); + Beatmap beatmap = new Beatmap(); + decoder.Decode(new StreamReader(stream), beatmap); var meta = beatmap.Metadata; Assert.AreEqual(241526, meta.BeatmapSetID); Assert.AreEqual("Soleily", meta.Artist); @@ -47,7 +49,8 @@ namespace osu.Game.Tests.Beatmaps.Formats var decoder = new OsuLegacyDecoder(); using (var stream = Resource.OpenResource("Soleily - Renatus (Gamu) [Insane].osu")) { - var beatmap = decoder.Decode(new StreamReader(stream)); + Beatmap beatmap = new Beatmap(); + decoder.Decode(new StreamReader(stream), beatmap); Assert.AreEqual(0, beatmap.AudioLeadIn); Assert.AreEqual(false, beatmap.Countdown); Assert.AreEqual(SampleSet.Soft, beatmap.SampleSet); @@ -65,7 +68,8 @@ namespace osu.Game.Tests.Beatmaps.Formats var decoder = new OsuLegacyDecoder(); using (var stream = Resource.OpenResource("Soleily - Renatus (Gamu) [Insane].osu")) { - var beatmap = decoder.Decode(new StreamReader(stream)); + Beatmap beatmap = new Beatmap(); + decoder.Decode(new StreamReader(stream), beatmap); int[] expectedBookmarks = { 11505, 22054, 32604, 43153, 53703, 64252, 74802, 85351, @@ -88,7 +92,8 @@ namespace osu.Game.Tests.Beatmaps.Formats var decoder = new OsuLegacyDecoder(); using (var stream = Resource.OpenResource("Soleily - Renatus (Gamu) [Insane].osu")) { - var beatmap = decoder.Decode(new StreamReader(stream)); + Beatmap beatmap = new Beatmap(); + decoder.Decode(new StreamReader(stream), beatmap); var difficulty = beatmap.BaseDifficulty; Assert.AreEqual(6.5f, difficulty.DrainRate); Assert.AreEqual(4, difficulty.CircleSize); @@ -105,7 +110,8 @@ namespace osu.Game.Tests.Beatmaps.Formats var decoder = new OsuLegacyDecoder(); using (var stream = Resource.OpenResource("Soleily - Renatus (Gamu) [Insane].osu")) { - var beatmap = decoder.Decode(new StreamReader(stream)); + Beatmap beatmap = new Beatmap(); + decoder.Decode(new StreamReader(stream), beatmap); Color4[] expected = { new Color4(142, 199, 255, 255), @@ -126,7 +132,8 @@ namespace osu.Game.Tests.Beatmaps.Formats var decoder = new OsuLegacyDecoder(); using (var stream = Resource.OpenResource("Soleily - Renatus (Gamu) [Insane].osu")) { - var beatmap = decoder.Decode(new StreamReader(stream)); + Beatmap beatmap = new Beatmap(); + decoder.Decode(new StreamReader(stream), beatmap); var slider = beatmap.HitObjects[0] as Slider; Assert.IsNotNull(slider); Assert.AreEqual(new Vector2(192, 168), slider.Position); diff --git a/osu.Game/Beatmaps/BeatmapSet.cs b/osu.Game/Beatmaps/BeatmapSet.cs index 8ba8ef0d53..11f82329f9 100644 --- a/osu.Game/Beatmaps/BeatmapSet.cs +++ b/osu.Game/Beatmaps/BeatmapSet.cs @@ -17,7 +17,7 @@ namespace osu.Game.Beatmaps [NotNull, Indexed] public int BeatmapMetadataID { get; set; } [Ignore] - public List Beatmaps { get; protected set; } + public List Beatmaps { get; protected set; } = new List(); [Ignore] public BeatmapMetadata Metadata { get; set; } [Ignore] diff --git a/osu.Game/Beatmaps/Formats/BeatmapDecoder.cs b/osu.Game/Beatmaps/Formats/BeatmapDecoder.cs index 7302e2a4c5..d643433b3c 100644 --- a/osu.Game/Beatmaps/Formats/BeatmapDecoder.cs +++ b/osu.Game/Beatmaps/Formats/BeatmapDecoder.cs @@ -20,6 +20,6 @@ namespace osu.Game.Beatmaps.Formats decoders[magic] = typeof(T); } - public abstract Beatmap Decode(TextReader stream); + public abstract void Decode(TextReader stream, Beatmap beatmap); } } \ No newline at end of file diff --git a/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs b/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs index 89451c1233..4250e9a7c2 100644 --- a/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs +++ b/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs @@ -202,16 +202,16 @@ namespace osu.Game.Beatmaps.Formats }); } - public override Beatmap Decode(TextReader stream) + public override void Decode(TextReader stream, Beatmap beatmap) { - var beatmap = new Beatmap - { - Metadata = new BeatmapMetadata(), - BaseDifficulty = new BaseDifficulty(), - HitObjects = new List(), - ControlPoints = new List(), - ComboColors = new List(), - }; + // We don't overwrite these two because they're DB bound + if (beatmap.Metadata == null) beatmap.Metadata = new BeatmapMetadata(); + if (beatmap.BaseDifficulty == null) beatmap.BaseDifficulty = new BaseDifficulty(); + // These are fine though + beatmap.HitObjects = new List(); + beatmap.ControlPoints = new List(); + beatmap.ComboColors = new List(); + var section = Section.None; string line; while (true) @@ -266,7 +266,6 @@ namespace osu.Game.Beatmaps.Formats 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 b83cf8ad04..0aa706933e 100644 --- a/osu.Game/Beatmaps/IO/OszArchiveReader.cs +++ b/osu.Game/Beatmaps/IO/OszArchiveReader.cs @@ -33,7 +33,8 @@ namespace osu.Game.Beatmaps.IO using (var stream = new StreamReader(ReadFile(beatmaps[0]))) { var decoder = BeatmapDecoder.GetDecoder(stream); - firstMap = decoder.Decode(stream); + firstMap = new Beatmap(); + decoder.Decode(stream, firstMap); } } diff --git a/osu.Game/Database/BeatmapDatabase.cs b/osu.Game/Database/BeatmapDatabase.cs index dcfc6c91df..4913a51af3 100644 --- a/osu.Game/Database/BeatmapDatabase.cs +++ b/osu.Game/Database/BeatmapDatabase.cs @@ -48,7 +48,7 @@ namespace osu.Game.Database reader = ArchiveReader.GetReader(storage, path); var metadata = reader.ReadMetadata(); if (connection.Table().Count(b => b.BeatmapSetID == metadata.BeatmapSetID) != 0) - return; + return; // TODO: Update this beatmap instead string[] mapNames = reader.ReadBeatmaps(); var beatmapSet = new BeatmapSet { @@ -62,7 +62,8 @@ namespace osu.Game.Database using (var stream = new StreamReader(reader.ReadFile(name))) { var decoder = BeatmapDecoder.GetDecoder(stream); - var beatmap = decoder.Decode(stream); + Beatmap beatmap = new Beatmap(); + decoder.Decode(stream, beatmap); maps.Add(beatmap); beatmap.BaseDifficultyID = connection.Insert(beatmap.BaseDifficulty); } @@ -71,12 +72,29 @@ namespace osu.Game.Database connection.Insert(beatmapSet); connection.InsertAll(maps); } + public ArchiveReader GetReader(BeatmapSet beatmapSet) + { + return ArchiveReader.GetReader(storage, beatmapSet.Path); + } /// /// Given a BeatmapSet pulled from the database, loads the rest of its data from disk. - /// public void PopulateBeatmap(BeatmapSet beatmap) + /// public void PopulateBeatmap(BeatmapSet beatmapSet) { - // TODO + using (var reader = GetReader(beatmapSet)) + { + string[] mapNames = reader.ReadBeatmaps(); + foreach (var name in mapNames) + { + using (var stream = new StreamReader(reader.ReadFile(name))) + { + var decoder = BeatmapDecoder.GetDecoder(stream); + Beatmap beatmap = new Beatmap(); + decoder.Decode(stream, beatmap); + beatmapSet.Beatmaps.Add(beatmap); + } + } + } } } } \ No newline at end of file From 1c97edaac2f870901e2374b040b524687cc5a909 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Thu, 13 Oct 2016 22:57:05 +0800 Subject: [PATCH 5/9] Base class for overlays. --- osu.Game/GameModes/Menu/MainMenu.cs | 4 +-- osu.Game/OsuGame.cs | 4 +-- osu.Game/Overlays/ChatConsole.cs | 47 +++++++++-------------------- osu.Game/Overlays/Options.cs | 39 ++++++++---------------- osu.Game/Overlays/Overlay.cs | 41 +++++++++++++++++++++++++ osu.Game/Overlays/Toolbar.cs | 46 +++++++++++----------------- osu.Game/Overlays/Visibility.cs | 17 ----------- osu.Game/osu.Game.csproj | 2 +- 8 files changed, 89 insertions(+), 111 deletions(-) create mode 100644 osu.Game/Overlays/Overlay.cs delete mode 100644 osu.Game/Overlays/Visibility.cs diff --git a/osu.Game/GameModes/Menu/MainMenu.cs b/osu.Game/GameModes/Menu/MainMenu.cs index f029d0b8ef..13ed6fec77 100644 --- a/osu.Game/GameModes/Menu/MainMenu.cs +++ b/osu.Game/GameModes/Menu/MainMenu.cs @@ -48,9 +48,7 @@ namespace osu.Game.GameModes.Menu OnMulti = delegate { Push(new Lobby()); }, OnTest = delegate { Push(new TestBrowser()); }, OnExit = delegate { Scheduler.AddDelayed(Exit, ButtonSystem.EXIT_DELAY); }, - OnSettings = delegate { - osu.Options.State = osu.Options.State.Reverse(); - }, + OnSettings = osu.Options.ReverseVisibility, } } } diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index 6fb8e8f8ba..e1acbae5b7 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -96,7 +96,7 @@ namespace osu.Game Toolbar = new Toolbar { OnHome = delegate { MainMenu?.MakeCurrent(); }, - OnSettings = delegate { Options.State = Options.State.Reverse(); }, + OnSettings = Options.ReverseVisibility, OnPlayModeChange = delegate (PlayMode m) { PlayMode.Value = m; }, Alpha = 0.001f, }, @@ -134,7 +134,7 @@ namespace osu.Game switch (args.Key) { case Key.F8: - Chat.State = Chat.State.Reverse(); + Chat.ReverseVisibility(); return true; } diff --git a/osu.Game/Overlays/ChatConsole.cs b/osu.Game/Overlays/ChatConsole.cs index 7293ccfdf9..820b9245d3 100644 --- a/osu.Game/Overlays/ChatConsole.cs +++ b/osu.Game/Overlays/ChatConsole.cs @@ -1,12 +1,12 @@ //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.Diagnostics; using System.Linq; -using System.Text; -using System.Threading.Tasks; +using OpenTK; +using OpenTK.Graphics; +using osu.Framework; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Drawables; @@ -17,15 +17,10 @@ using osu.Game.Online.API; using osu.Game.Online.API.Requests; using osu.Game.Online.Chat; using osu.Game.Online.Chat.Display; -using OpenTK; -using OpenTK.Graphics; -using osu.Framework.Input; -using OpenTK.Input; -using osu.Framework; namespace osu.Game.Overlays { - public class ChatConsole : Container, IStateful + public class ChatConsole : Overlay { private ChannelDisplay channelDisplay; @@ -69,7 +64,7 @@ namespace osu.Game.Overlays private long? lastMessageId; - List careChannels; + private List careChannels; private void initializeChannels() { @@ -112,7 +107,7 @@ namespace osu.Game.Overlays careChannels.Add(channel); } - GetMessagesRequest fetchReq; + private GetMessagesRequest fetchReq; public void FetchNewMessages(APIAccess api) { @@ -140,30 +135,18 @@ namespace osu.Game.Overlays api.Queue(fetchReq); } - private Visibility state; + private const int transition_length = 500; - public Visibility State + protected override void PopIn() { - get { return state; } + MoveToY(0, transition_length, EasingTypes.OutQuint); + FadeIn(transition_length, EasingTypes.OutQuint); + } - set - { - state = value; - - const int transition_length = 500; - - switch (state) - { - case Visibility.Hidden: - MoveToY(-Size.Y, transition_length, EasingTypes.InQuint); - FadeOut(transition_length, EasingTypes.InQuint); - break; - case Visibility.Visible: - MoveToY(0, transition_length, EasingTypes.OutQuint); - FadeIn(transition_length, EasingTypes.OutQuint); - break; - } - } + protected override void PopOut() + { + MoveToY(-Size.Y, transition_length, EasingTypes.InQuint); + FadeOut(transition_length, EasingTypes.InQuint); } } } diff --git a/osu.Game/Overlays/Options.cs b/osu.Game/Overlays/Options.cs index 6722b0abf6..5bcc5e9a16 100644 --- a/osu.Game/Overlays/Options.cs +++ b/osu.Game/Overlays/Options.cs @@ -1,21 +1,20 @@ //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.Containers; -using osu.Framework.Graphics.Drawables; -using osu.Framework.Graphics.Transformations; using OpenTK; using OpenTK.Graphics; -using osu.Framework.Input; using OpenTK.Input; using osu.Framework; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Drawables; +using osu.Framework.Graphics.Transformations; +using osu.Framework.Input; namespace osu.Game.Overlays { - public class Options : Container, IStateful + public class Options : Overlay { - const float width = 300; + private const float width = 300; public override void Load(BaseGame game) { @@ -49,28 +48,14 @@ namespace osu.Game.Overlays return base.OnKeyDown(state, args); } - private Visibility state; - - public Visibility State + protected override void PopIn() { - get { return state; } + MoveToX(0, 300, EasingTypes.Out); + } - set - { - if (value == state) return; - - state = value; - - switch (state) - { - case Visibility.Hidden: - MoveTo(new Vector2(-width, 0), 300, EasingTypes.Out); - break; - case Visibility.Visible: - MoveTo(new Vector2(0, 0), 300, EasingTypes.Out); - break; - } - } + protected override void PopOut() + { + MoveToX(-width, 300, EasingTypes.Out); } } } diff --git a/osu.Game/Overlays/Overlay.cs b/osu.Game/Overlays/Overlay.cs new file mode 100644 index 0000000000..5c0e501703 --- /dev/null +++ b/osu.Game/Overlays/Overlay.cs @@ -0,0 +1,41 @@ +using osu.Framework; +using osu.Framework.Graphics.Containers; + +namespace osu.Game.Overlays +{ + public abstract class Overlay : Container, IStateful + { + private Visibility state; + public Visibility State + { + get { return state; } + set + { + if (value == state) return; + state = value; + + switch (value) + { + case Visibility.Hidden: + PopOut(); + break; + case Visibility.Visible: + PopIn(); + break; + } + } + } + + protected abstract void PopIn(); + + protected abstract void PopOut(); + + public void ReverseVisibility() + => State = (State == Visibility.Visible ? Visibility.Hidden : Visibility.Visible); + } + public enum Visibility + { + Hidden, + Visible + } +} diff --git a/osu.Game/Overlays/Toolbar.cs b/osu.Game/Overlays/Toolbar.cs index ce2aad61b3..c4bc9518cc 100644 --- a/osu.Game/Overlays/Toolbar.cs +++ b/osu.Game/Overlays/Toolbar.cs @@ -1,24 +1,23 @@ //Copyright (c) 2007-2016 ppy Pty Ltd . //Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using System; +using OpenTK; +using OpenTK.Graphics; +using osu.Framework; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Drawables; -using OpenTK; -using OpenTK.Graphics; -using osu.Game.Graphics; -using osu.Game.Configuration; -using System; using osu.Framework.Graphics.Transformations; -using osu.Framework.Timing; +using osu.Game.Configuration; using osu.Game.GameModes.Play; -using osu.Framework; +using osu.Game.Graphics; namespace osu.Game.Overlays { - public class Toolbar : Container, IStateful + public class Toolbar : Overlay { - const float height = 50; + private const float height = 50; public Action OnSettings; public Action OnHome; @@ -26,29 +25,18 @@ namespace osu.Game.Overlays private ToolbarModeSelector modeSelector; - private Visibility state; + private const int transition_time = 200; - public Visibility State + protected override void PopIn() { - get { return state; } - set - { - state = value; + MoveToY(0, transition_time, EasingTypes.OutQuint); + FadeIn(transition_time, EasingTypes.OutQuint); + } - const int transition_time = 200; - - switch (state) - { - case Visibility.Hidden: - MoveToY(-Size.Y, transition_time, EasingTypes.InQuint); - FadeOut(transition_time, EasingTypes.InQuint); - break; - case Visibility.Visible: - MoveToY(0, transition_time, EasingTypes.OutQuint); - FadeIn(transition_time, EasingTypes.OutQuint); - break; - } - } + protected override void PopOut() + { + MoveToY(-Size.Y, transition_time, EasingTypes.InQuint); + FadeOut(transition_time, EasingTypes.InQuint); } public override void Load(BaseGame game) diff --git a/osu.Game/Overlays/Visibility.cs b/osu.Game/Overlays/Visibility.cs deleted file mode 100644 index c86ab5c401..0000000000 --- a/osu.Game/Overlays/Visibility.cs +++ /dev/null @@ -1,17 +0,0 @@ -//Copyright (c) 2007-2016 ppy Pty Ltd . -//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE - -namespace osu.Game.Overlays -{ - public enum Visibility - { - Hidden, - Visible - } - - public static class OverlayVisibilityHelper - { - public static Visibility Reverse(this Visibility input) - => input == Visibility.Visible ? Visibility.Hidden : Visibility.Visible; - } -} diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 1f89696ded..f1d8334eba 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -156,11 +156,11 @@ + - From 254cc87578bcb0671259fd3cb23264d951587b6f Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Fri, 14 Oct 2016 05:02:13 +0800 Subject: [PATCH 6/9] Use name ToggleVisibility. --- osu.Game/GameModes/Menu/MainMenu.cs | 2 +- osu.Game/OsuGame.cs | 4 ++-- osu.Game/Overlays/Overlay.cs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/osu.Game/GameModes/Menu/MainMenu.cs b/osu.Game/GameModes/Menu/MainMenu.cs index 13ed6fec77..475d4c8dea 100644 --- a/osu.Game/GameModes/Menu/MainMenu.cs +++ b/osu.Game/GameModes/Menu/MainMenu.cs @@ -48,7 +48,7 @@ namespace osu.Game.GameModes.Menu OnMulti = delegate { Push(new Lobby()); }, OnTest = delegate { Push(new TestBrowser()); }, OnExit = delegate { Scheduler.AddDelayed(Exit, ButtonSystem.EXIT_DELAY); }, - OnSettings = osu.Options.ReverseVisibility, + OnSettings = osu.Options.ToggleVisibility, } } } diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index e1acbae5b7..5d0e401321 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -96,7 +96,7 @@ namespace osu.Game Toolbar = new Toolbar { OnHome = delegate { MainMenu?.MakeCurrent(); }, - OnSettings = Options.ReverseVisibility, + OnSettings = Options.ToggleVisibility, OnPlayModeChange = delegate (PlayMode m) { PlayMode.Value = m; }, Alpha = 0.001f, }, @@ -134,7 +134,7 @@ namespace osu.Game switch (args.Key) { case Key.F8: - Chat.ReverseVisibility(); + Chat.ToggleVisibility(); return true; } diff --git a/osu.Game/Overlays/Overlay.cs b/osu.Game/Overlays/Overlay.cs index 5c0e501703..31e4c10d2a 100644 --- a/osu.Game/Overlays/Overlay.cs +++ b/osu.Game/Overlays/Overlay.cs @@ -30,7 +30,7 @@ namespace osu.Game.Overlays protected abstract void PopOut(); - public void ReverseVisibility() + public void ToggleVisibility() => State = (State == Visibility.Visible ? Visibility.Hidden : Visibility.Visible); } public enum Visibility From fedfb8a22a6615954e3f6e9c28f8d73b8ca81ae4 Mon Sep 17 00:00:00 2001 From: John Leuenhagen Date: Thu, 13 Oct 2016 23:33:58 -0400 Subject: [PATCH 7/9] Converted all .cs files to use CRLF line endings. --- .../Beatmaps/IO/LegacyFilesystemReader.cs | 66 ++--- .../Beatmaps/Formats/OsuLegacyDecoderTest.cs | 254 +++++++++--------- .../Beatmaps/IO/OszArchiveReaderTest.cs | 144 +++++----- osu.Game.Tests/Resources/Resource.cs | 26 +- osu.Game/Beatmaps/BaseDifficulty.cs | 32 +-- osu.Game/Beatmaps/Events/EventType.cs | 26 +- osu.Game/Beatmaps/Formats/BeatmapDecoder.cs | 44 +-- osu.Game/Beatmaps/IO/ArchiveReader.cs | 82 +++--- osu.Game/Beatmaps/IO/OszArchiveReader.cs | 72 ++--- osu.Game/Database/BeatmapDatabase.cs | 162 +++++------ 10 files changed, 454 insertions(+), 454 deletions(-) diff --git a/osu.Desktop/Beatmaps/IO/LegacyFilesystemReader.cs b/osu.Desktop/Beatmaps/IO/LegacyFilesystemReader.cs index b4aaa2fa03..8282d8556a 100644 --- a/osu.Desktop/Beatmaps/IO/LegacyFilesystemReader.cs +++ b/osu.Desktop/Beatmaps/IO/LegacyFilesystemReader.cs @@ -1,39 +1,39 @@ -using System; -using System.IO; +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 string[] beatmaps { get; set; } +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 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) - throw new FileNotFoundException(@"This directory contains no beatmaps"); - using (var stream = new StreamReader(ReadFile(beatmaps[0]))) - { - var decoder = BeatmapDecoder.GetDecoder(stream); - firstMap = new Beatmap(); - decoder.Decode(stream, firstMap); - } + + public LegacyFilesystemReader(string path) + { + 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]))) + { + var decoder = BeatmapDecoder.GetDecoder(stream); + firstMap = new Beatmap(); + decoder.Decode(stream, firstMap); + } } public override string[] ReadBeatmaps() @@ -49,10 +49,10 @@ namespace osu.Desktop.Beatmaps.IO public override BeatmapMetadata ReadMetadata() { return firstMap.Metadata; - } - + } + public override void Dispose() - { + { // no-op - } } + } } } \ No newline at end of file diff --git a/osu.Game.Tests/Beatmaps/Formats/OsuLegacyDecoderTest.cs b/osu.Game.Tests/Beatmaps/Formats/OsuLegacyDecoderTest.cs index adc78a55bf..adb203b483 100644 --- a/osu.Game.Tests/Beatmaps/Formats/OsuLegacyDecoderTest.cs +++ b/osu.Game.Tests/Beatmaps/Formats/OsuLegacyDecoderTest.cs @@ -1,6 +1,6 @@ -using System; +using System; using System.IO; -using NUnit.Framework; +using NUnit.Framework; using OpenTK; using OpenTK.Graphics; using osu.Game.Beatmaps; @@ -10,141 +10,141 @@ using osu.Game.Beatmaps.Samples; using osu.Game.GameModes.Play; using osu.Game.Tests.Resources; -namespace osu.Game.Tests.Beatmaps.Formats -{ - [TestFixture] - public class OsuLegacyDecoderTest - { - [TestFixtureSetUp] - public void SetUp() - { - OsuLegacyDecoder.Register(); +namespace osu.Game.Tests.Beatmaps.Formats +{ + [TestFixture] + public class OsuLegacyDecoderTest + { + [TestFixtureSetUp] + public void SetUp() + { + OsuLegacyDecoder.Register(); } - [Test] - public void TestDecodeMetadata() - { - var decoder = new OsuLegacyDecoder(); - using (var stream = Resource.OpenResource("Soleily - Renatus (Gamu) [Insane].osu")) - { - Beatmap beatmap = new Beatmap(); - decoder.Decode(new StreamReader(stream), beatmap); - var meta = beatmap.Metadata; - 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("Gamu", 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); - } + [Test] + public void TestDecodeMetadata() + { + var decoder = new OsuLegacyDecoder(); + using (var stream = Resource.OpenResource("Soleily - Renatus (Gamu) [Insane].osu")) + { + Beatmap beatmap = new Beatmap(); + decoder.Decode(new StreamReader(stream), beatmap); + var meta = beatmap.Metadata; + 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("Gamu", 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); + } } - [Test] - public void TestDecodeGeneral() - { - var decoder = new OsuLegacyDecoder(); - using (var stream = Resource.OpenResource("Soleily - Renatus (Gamu) [Insane].osu")) - { - Beatmap beatmap = new Beatmap(); - decoder.Decode(new StreamReader(stream), beatmap); - Assert.AreEqual(0, beatmap.AudioLeadIn); - Assert.AreEqual(false, beatmap.Countdown); - Assert.AreEqual(SampleSet.Soft, beatmap.SampleSet); - Assert.AreEqual(0.7f, beatmap.StackLeniency); - Assert.AreEqual(false, beatmap.SpecialStyle); - Assert.AreEqual(PlayMode.Osu, beatmap.Mode); - Assert.AreEqual(false, beatmap.LetterboxInBreaks); - Assert.AreEqual(false, beatmap.WidescreenStoryboard); - } + [Test] + public void TestDecodeGeneral() + { + var decoder = new OsuLegacyDecoder(); + using (var stream = Resource.OpenResource("Soleily - Renatus (Gamu) [Insane].osu")) + { + Beatmap beatmap = new Beatmap(); + decoder.Decode(new StreamReader(stream), beatmap); + Assert.AreEqual(0, beatmap.AudioLeadIn); + Assert.AreEqual(false, beatmap.Countdown); + Assert.AreEqual(SampleSet.Soft, beatmap.SampleSet); + Assert.AreEqual(0.7f, beatmap.StackLeniency); + Assert.AreEqual(false, beatmap.SpecialStyle); + Assert.AreEqual(PlayMode.Osu, beatmap.Mode); + Assert.AreEqual(false, beatmap.LetterboxInBreaks); + Assert.AreEqual(false, beatmap.WidescreenStoryboard); + } } - [Test] - public void TestDecodeEditor() - { - var decoder = new OsuLegacyDecoder(); - using (var stream = Resource.OpenResource("Soleily - Renatus (Gamu) [Insane].osu")) - { - Beatmap beatmap = new Beatmap(); - decoder.Decode(new StreamReader(stream), beatmap); - int[] expectedBookmarks = - { - 11505, 22054, 32604, 43153, 53703, 64252, 74802, 85351, - 95901, 106450, 116999, 119637, 130186, 140735, 151285, - 161834, 164471, 175020, 185570, 196119, 206669, 209306 - }; - Assert.AreEqual(expectedBookmarks.Length, beatmap.Bookmarks.Length); - for (int i = 0; i < expectedBookmarks.Length; i++) - Assert.AreEqual(expectedBookmarks[i], beatmap.Bookmarks[i]); - Assert.AreEqual(1.8, beatmap.DistanceSpacing); - Assert.AreEqual(4, beatmap.BeatDivisor); - Assert.AreEqual(4, beatmap.GridSize); - Assert.AreEqual(2, beatmap.TimelineZoom); - } + [Test] + public void TestDecodeEditor() + { + var decoder = new OsuLegacyDecoder(); + using (var stream = Resource.OpenResource("Soleily - Renatus (Gamu) [Insane].osu")) + { + Beatmap beatmap = new Beatmap(); + decoder.Decode(new StreamReader(stream), beatmap); + int[] expectedBookmarks = + { + 11505, 22054, 32604, 43153, 53703, 64252, 74802, 85351, + 95901, 106450, 116999, 119637, 130186, 140735, 151285, + 161834, 164471, 175020, 185570, 196119, 206669, 209306 + }; + Assert.AreEqual(expectedBookmarks.Length, beatmap.Bookmarks.Length); + for (int i = 0; i < expectedBookmarks.Length; i++) + Assert.AreEqual(expectedBookmarks[i], beatmap.Bookmarks[i]); + Assert.AreEqual(1.8, beatmap.DistanceSpacing); + Assert.AreEqual(4, beatmap.BeatDivisor); + Assert.AreEqual(4, beatmap.GridSize); + Assert.AreEqual(2, beatmap.TimelineZoom); + } } - [Test] - public void TestDecodeDifficulty() - { - var decoder = new OsuLegacyDecoder(); - using (var stream = Resource.OpenResource("Soleily - Renatus (Gamu) [Insane].osu")) - { - Beatmap beatmap = new Beatmap(); - decoder.Decode(new StreamReader(stream), beatmap); - var difficulty = beatmap.BaseDifficulty; - Assert.AreEqual(6.5f, difficulty.DrainRate); - Assert.AreEqual(4, difficulty.CircleSize); - Assert.AreEqual(8, difficulty.OverallDifficulty); - Assert.AreEqual(9, difficulty.ApproachRate); - Assert.AreEqual(1.8f, difficulty.SliderMultiplier); - Assert.AreEqual(2, difficulty.SliderTickRate); - } + [Test] + public void TestDecodeDifficulty() + { + var decoder = new OsuLegacyDecoder(); + using (var stream = Resource.OpenResource("Soleily - Renatus (Gamu) [Insane].osu")) + { + Beatmap beatmap = new Beatmap(); + decoder.Decode(new StreamReader(stream), beatmap); + var difficulty = beatmap.BaseDifficulty; + Assert.AreEqual(6.5f, difficulty.DrainRate); + Assert.AreEqual(4, difficulty.CircleSize); + Assert.AreEqual(8, difficulty.OverallDifficulty); + Assert.AreEqual(9, difficulty.ApproachRate); + Assert.AreEqual(1.8f, difficulty.SliderMultiplier); + Assert.AreEqual(2, difficulty.SliderTickRate); + } } - [Test] - public void TestDecodeColors() - { - var decoder = new OsuLegacyDecoder(); - using (var stream = Resource.OpenResource("Soleily - Renatus (Gamu) [Insane].osu")) - { - Beatmap beatmap = new Beatmap(); - decoder.Decode(new StreamReader(stream), beatmap); + [Test] + public void TestDecodeColors() + { + var decoder = new OsuLegacyDecoder(); + using (var stream = Resource.OpenResource("Soleily - Renatus (Gamu) [Insane].osu")) + { + Beatmap beatmap = new Beatmap(); + decoder.Decode(new StreamReader(stream), beatmap); Color4[] expected = - { - new Color4(142, 199, 255, 255), - new Color4(255, 128, 128, 255), - new Color4(128, 255, 255, 255), - new Color4(128, 255, 128, 255), - new Color4(255, 187, 255, 255), - new Color4(255, 177, 140, 255), - }; - Assert.AreEqual(expected.Length, beatmap.ComboColors.Count); - for (int i = 0; i < expected.Length; i++) - Assert.AreEqual(expected[i], beatmap.ComboColors[i]); - } + { + new Color4(142, 199, 255, 255), + new Color4(255, 128, 128, 255), + new Color4(128, 255, 255, 255), + new Color4(128, 255, 128, 255), + new Color4(255, 187, 255, 255), + new Color4(255, 177, 140, 255), + }; + Assert.AreEqual(expected.Length, beatmap.ComboColors.Count); + 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")) - { - Beatmap beatmap = new Beatmap(); - decoder.Decode(new StreamReader(stream), beatmap); - 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); + + [Test] public void TestDecodeHitObjects() + { + var decoder = new OsuLegacyDecoder(); + using (var stream = Resource.OpenResource("Soleily - Renatus (Gamu) [Insane].osu")) + { + Beatmap beatmap = new Beatmap(); + decoder.Decode(new StreamReader(stream), beatmap); + 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.Tests/Beatmaps/IO/OszArchiveReaderTest.cs b/osu.Game.Tests/Beatmaps/IO/OszArchiveReaderTest.cs index e224bf3db4..caa56c26c2 100644 --- a/osu.Game.Tests/Beatmaps/IO/OszArchiveReaderTest.cs +++ b/osu.Game.Tests/Beatmaps/IO/OszArchiveReaderTest.cs @@ -1,81 +1,81 @@ -using System; +using System; 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 -{ - [TestFixture] - public class OszArchiveReaderTest - { - [TestFixtureSetUp] - public void SetUp() - { - OszArchiveReader.Register(); - } - - [Test] - public void TestReadBeatmaps() - { - using (var osz = Resource.OpenResource("Beatmaps.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); - } +namespace osu.Game.Tests.Beatmaps.IO +{ + [TestFixture] + public class OszArchiveReaderTest + { + [TestFixtureSetUp] + public void SetUp() + { + OszArchiveReader.Register(); + } + + [Test] + public void TestReadBeatmaps() + { + using (var osz = Resource.OpenResource("Beatmaps.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); + } } - [Test] - public void TestReadMetadata() - { - using (var osz = Resource.OpenResource("Beatmaps.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); - } + [Test] + public void TestReadMetadata() + { + using (var osz = Resource.OpenResource("Beatmaps.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); + } } - [Test] - public void TestReadFile() - { - using (var osz = Resource.OpenResource("Beatmaps.241526 Soleily - Renatus.osz")) - { - var reader = new OszArchiveReader(osz); - using (var stream = new StreamReader( - reader.ReadFile("Soleily - Renatus (Deif) [Platter].osu"))) - { - Assert.AreEqual("osu file format v13", stream.ReadLine().Trim()); - } - } - } - } -} - + [Test] + public void TestReadFile() + { + using (var osz = Resource.OpenResource("Beatmaps.241526 Soleily - Renatus.osz")) + { + var reader = new OszArchiveReader(osz); + using (var stream = new StreamReader( + reader.ReadFile("Soleily - Renatus (Deif) [Platter].osu"))) + { + Assert.AreEqual("osu file format v13", stream.ReadLine().Trim()); + } + } + } + } +} + diff --git a/osu.Game.Tests/Resources/Resource.cs b/osu.Game.Tests/Resources/Resource.cs index 46c51da5ef..910268adbf 100644 --- a/osu.Game.Tests/Resources/Resource.cs +++ b/osu.Game.Tests/Resources/Resource.cs @@ -1,17 +1,17 @@ -using System; +using System; using System.IO; using System.Reflection; -namespace osu.Game.Tests.Resources -{ - public static class Resource - { - public static Stream OpenResource(string name) - { - return Assembly.GetExecutingAssembly().GetManifestResourceStream( - $@"osu.Game.Tests.Resources.{name}") ?? - Assembly.LoadFrom("osu.Game.Resources.dll").GetManifestResourceStream( - $@"osu.Game.Resources.{name}"); - } - } +namespace osu.Game.Tests.Resources +{ + public static class Resource + { + public static Stream OpenResource(string name) + { + return Assembly.GetExecutingAssembly().GetManifestResourceStream( + $@"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/Beatmaps/BaseDifficulty.cs b/osu.Game/Beatmaps/BaseDifficulty.cs index 62acf07695..ce9e3bc624 100644 --- a/osu.Game/Beatmaps/BaseDifficulty.cs +++ b/osu.Game/Beatmaps/BaseDifficulty.cs @@ -1,18 +1,18 @@ -using System; +using System; using SQLite; -namespace osu.Game.Beatmaps -{ - public class BaseDifficulty - { - [PrimaryKey, AutoIncrement] - public int ID { 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; } - } -} - +namespace osu.Game.Beatmaps +{ + public class BaseDifficulty + { + [PrimaryKey, AutoIncrement] + public int ID { 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; } + } +} + diff --git a/osu.Game/Beatmaps/Events/EventType.cs b/osu.Game/Beatmaps/Events/EventType.cs index cb66a42f2d..1f7e8d2aa5 100644 --- a/osu.Game/Beatmaps/Events/EventType.cs +++ b/osu.Game/Beatmaps/Events/EventType.cs @@ -1,14 +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 - } +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/BeatmapDecoder.cs b/osu.Game/Beatmaps/Formats/BeatmapDecoder.cs index d643433b3c..0c6bbb02e1 100644 --- a/osu.Game/Beatmaps/Formats/BeatmapDecoder.cs +++ b/osu.Game/Beatmaps/Formats/BeatmapDecoder.cs @@ -1,25 +1,25 @@ -using System; +using System; using System.Collections.Generic; -using System.IO; - -namespace osu.Game.Beatmaps.Formats -{ - public abstract class BeatmapDecoder - { - private static Dictionary decoders { get; } = new Dictionary(); - - public static BeatmapDecoder GetDecoder(TextReader stream) - { - var line = stream.ReadLine().Trim(); - if (!decoders.ContainsKey(line)) - throw new IOException(@"Unknown file format"); - return (BeatmapDecoder)Activator.CreateInstance(decoders[line]); +using System.IO; + +namespace osu.Game.Beatmaps.Formats +{ + public abstract class BeatmapDecoder + { + private static Dictionary decoders { get; } = new Dictionary(); + + public static BeatmapDecoder GetDecoder(TextReader stream) + { + var line = stream.ReadLine().Trim(); + if (!decoders.ContainsKey(line)) + throw new IOException(@"Unknown file format"); + return (BeatmapDecoder)Activator.CreateInstance(decoders[line]); } - protected static void AddDecoder(string magic) where T : BeatmapDecoder - { - decoders[magic] = typeof(T); - } - - public abstract void Decode(TextReader stream, Beatmap beatmap); - } + protected static void AddDecoder(string magic) where T : BeatmapDecoder + { + decoders[magic] = typeof(T); + } + + public abstract void Decode(TextReader stream, Beatmap beatmap); + } } \ No newline at end of file diff --git a/osu.Game/Beatmaps/IO/ArchiveReader.cs b/osu.Game/Beatmaps/IO/ArchiveReader.cs index 77315d4a21..89adf26989 100644 --- a/osu.Game/Beatmaps/IO/ArchiveReader.cs +++ b/osu.Game/Beatmaps/IO/ArchiveReader.cs @@ -1,48 +1,48 @@ -using System; +using System; using System.Collections.Generic; using System.IO; using osu.Framework.Platform; -namespace osu.Game.Beatmaps.IO -{ - public abstract class ArchiveReader : IDisposable - { - private class Reader - { - public Func Test { get; set; } - public Type Type { get; set; } - } - - private static List readers { get; } = new List(); - - public static ArchiveReader GetReader(BasicStorage storage, string path) - { - foreach (var reader in readers) - { - if (reader.Test(storage, path)) - return (ArchiveReader)Activator.CreateInstance(reader.Type, storage.GetStream(path)); - } - throw new IOException(@"Unknown file format"); - } - - protected static void AddReader(Func test) where T : ArchiveReader - { - readers.Add(new Reader { Test = test, Type = typeof(T) }); - } - - /// - /// Reads the beatmap metadata from this archive. - /// - public abstract BeatmapMetadata ReadMetadata(); - /// - /// Gets a list of beatmap file names. - /// - public abstract string[] ReadBeatmaps(); - /// - /// Opens a stream for reading a specific file from this archive. - /// +namespace osu.Game.Beatmaps.IO +{ + public abstract class ArchiveReader : IDisposable + { + private class Reader + { + public Func Test { get; set; } + public Type Type { get; set; } + } + + private static List readers { get; } = new List(); + + public static ArchiveReader GetReader(BasicStorage storage, string path) + { + foreach (var reader in readers) + { + if (reader.Test(storage, path)) + return (ArchiveReader)Activator.CreateInstance(reader.Type, storage.GetStream(path)); + } + throw new IOException(@"Unknown file format"); + } + + protected static void AddReader(Func test) where T : ArchiveReader + { + readers.Add(new Reader { Test = test, Type = typeof(T) }); + } + + /// + /// Reads the beatmap metadata from this archive. + /// + public abstract BeatmapMetadata ReadMetadata(); + /// + /// Gets a list of beatmap file names. + /// + public abstract string[] ReadBeatmaps(); + /// + /// Opens a stream for reading a specific file from this archive. + /// public abstract Stream ReadFile(string name); - public abstract void Dispose(); - } + public abstract void Dispose(); + } } \ No newline at end of file diff --git a/osu.Game/Beatmaps/IO/OszArchiveReader.cs b/osu.Game/Beatmaps/IO/OszArchiveReader.cs index 0aa706933e..69776d0095 100644 --- a/osu.Game/Beatmaps/IO/OszArchiveReader.cs +++ b/osu.Game/Beatmaps/IO/OszArchiveReader.cs @@ -1,41 +1,41 @@ -using System; +using System; using System.IO; using System.Linq; using System.Security.Cryptography; using Ionic.Zip; using osu.Game.Beatmaps.Formats; -namespace osu.Game.Beatmaps.IO -{ - public sealed class OszArchiveReader : ArchiveReader - { - public static void Register() - { +namespace osu.Game.Beatmaps.IO +{ + public sealed class OszArchiveReader : ArchiveReader + { + public static void Register() + { AddReader((storage, path) => - { - using (var stream = storage.GetStream(path)) + { + using (var stream = storage.GetStream(path)) return ZipFile.IsZipFile(stream, false); - }); - OsuLegacyDecoder.Register(); - } - - private ZipFile archive { get; set; } - private string[] beatmaps { get; set; } + }); + OsuLegacyDecoder.Register(); + } + + private ZipFile archive { get; set; } + private string[] beatmaps { get; set; } private Beatmap firstMap { get; set; } - - public OszArchiveReader(Stream archiveStream) - { - archive = ZipFile.Read(archiveStream); - 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"); - using (var stream = new StreamReader(ReadFile(beatmaps[0]))) - { - var decoder = BeatmapDecoder.GetDecoder(stream); - firstMap = new Beatmap(); - decoder.Decode(stream, firstMap); - } + + public OszArchiveReader(Stream archiveStream) + { + archive = ZipFile.Read(archiveStream); + 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"); + using (var stream = new StreamReader(ReadFile(beatmaps[0]))) + { + var decoder = BeatmapDecoder.GetDecoder(stream); + firstMap = new Beatmap(); + decoder.Decode(stream, firstMap); + } } public override string[] ReadBeatmaps() @@ -45,9 +45,9 @@ namespace osu.Game.Beatmaps.IO public override Stream ReadFile(string name) { - ZipEntry entry = archive.Entries.SingleOrDefault(e => e.FileName == name); - if (entry == null) - throw new FileNotFoundException(); + ZipEntry entry = archive.Entries.SingleOrDefault(e => e.FileName == name); + if (entry == null) + throw new FileNotFoundException(); return entry.OpenReader(); } @@ -55,9 +55,9 @@ namespace osu.Game.Beatmaps.IO { return firstMap.Metadata; } - public override void Dispose() - { - archive.Dispose(); + public override void Dispose() + { + archive.Dispose(); } - } + } } \ No newline at end of file diff --git a/osu.Game/Database/BeatmapDatabase.cs b/osu.Game/Database/BeatmapDatabase.cs index 4913a51af3..7f8cf86c14 100644 --- a/osu.Game/Database/BeatmapDatabase.cs +++ b/osu.Game/Database/BeatmapDatabase.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.IO; using System.Security.Cryptography; @@ -8,82 +8,82 @@ using osu.Game.Beatmaps.Formats; using osu.Game.Beatmaps.IO; using SQLite; -namespace osu.Game.Database -{ - public class BeatmapDatabase - { - private static SQLiteConnection connection { get; set; } - private BasicStorage storage; - - public BeatmapDatabase(BasicStorage storage) - { - this.storage = storage; - if (connection == null) - { - connection = storage.GetDatabase(@"beatmaps"); - connection.CreateTable(); - connection.CreateTable(); - connection.CreateTable(); - connection.CreateTable(); - } - } - public void AddBeatmap(string path) - { - string hash = null; - ArchiveReader reader; - if (File.Exists(path)) // Not always the case, i.e. for LegacyFilesystemReader - { - using (var md5 = MD5.Create()) - using (var input = storage.GetStream(path)) - { - hash = BitConverter.ToString(md5.ComputeHash(input)).Replace("-", "").ToLowerInvariant(); - input.Seek(0, SeekOrigin.Begin); - var outputPath = Path.Combine(@"beatmaps", hash.Remove(1), hash.Remove(2), hash); - using (var output = storage.GetStream(outputPath, FileAccess.Write)) - input.CopyTo(output); - reader = ArchiveReader.GetReader(storage, path = outputPath); - } - } - else - reader = ArchiveReader.GetReader(storage, path); - var metadata = reader.ReadMetadata(); - if (connection.Table().Count(b => b.BeatmapSetID == metadata.BeatmapSetID) != 0) - return; // TODO: Update this beatmap instead - string[] mapNames = reader.ReadBeatmaps(); - var beatmapSet = new BeatmapSet - { - BeatmapSetID = metadata.BeatmapSetID, - Path = path, - Hash = hash, - }; - var maps = new List(); - foreach (var name in mapNames) - { - using (var stream = new StreamReader(reader.ReadFile(name))) - { - var decoder = BeatmapDecoder.GetDecoder(stream); - Beatmap beatmap = new Beatmap(); - decoder.Decode(stream, beatmap); - maps.Add(beatmap); - beatmap.BaseDifficultyID = connection.Insert(beatmap.BaseDifficulty); - } - } - beatmapSet.BeatmapMetadataID = connection.Insert(metadata); - connection.Insert(beatmapSet); - connection.InsertAll(maps); - } - public ArchiveReader GetReader(BeatmapSet beatmapSet) - { - return ArchiveReader.GetReader(storage, beatmapSet.Path); - } - - /// - /// Given a BeatmapSet pulled from the database, loads the rest of its data from disk. - /// public void PopulateBeatmap(BeatmapSet beatmapSet) - { - using (var reader = GetReader(beatmapSet)) +namespace osu.Game.Database +{ + public class BeatmapDatabase + { + private static SQLiteConnection connection { get; set; } + private BasicStorage storage; + + public BeatmapDatabase(BasicStorage storage) + { + this.storage = storage; + if (connection == null) { - string[] mapNames = reader.ReadBeatmaps(); + connection = storage.GetDatabase(@"beatmaps"); + connection.CreateTable(); + connection.CreateTable(); + connection.CreateTable(); + connection.CreateTable(); + } + } + public void AddBeatmap(string path) + { + string hash = null; + ArchiveReader reader; + if (File.Exists(path)) // Not always the case, i.e. for LegacyFilesystemReader + { + using (var md5 = MD5.Create()) + using (var input = storage.GetStream(path)) + { + hash = BitConverter.ToString(md5.ComputeHash(input)).Replace("-", "").ToLowerInvariant(); + input.Seek(0, SeekOrigin.Begin); + var outputPath = Path.Combine(@"beatmaps", hash.Remove(1), hash.Remove(2), hash); + using (var output = storage.GetStream(outputPath, FileAccess.Write)) + input.CopyTo(output); + reader = ArchiveReader.GetReader(storage, path = outputPath); + } + } + else + reader = ArchiveReader.GetReader(storage, path); + var metadata = reader.ReadMetadata(); + if (connection.Table().Count(b => b.BeatmapSetID == metadata.BeatmapSetID) != 0) + return; // TODO: Update this beatmap instead + string[] mapNames = reader.ReadBeatmaps(); + var beatmapSet = new BeatmapSet + { + BeatmapSetID = metadata.BeatmapSetID, + Path = path, + Hash = hash, + }; + var maps = new List(); + foreach (var name in mapNames) + { + using (var stream = new StreamReader(reader.ReadFile(name))) + { + var decoder = BeatmapDecoder.GetDecoder(stream); + Beatmap beatmap = new Beatmap(); + decoder.Decode(stream, beatmap); + maps.Add(beatmap); + beatmap.BaseDifficultyID = connection.Insert(beatmap.BaseDifficulty); + } + } + beatmapSet.BeatmapMetadataID = connection.Insert(metadata); + connection.Insert(beatmapSet); + connection.InsertAll(maps); + } + public ArchiveReader GetReader(BeatmapSet beatmapSet) + { + return ArchiveReader.GetReader(storage, beatmapSet.Path); + } + + /// + /// Given a BeatmapSet pulled from the database, loads the rest of its data from disk. + /// public void PopulateBeatmap(BeatmapSet beatmapSet) + { + using (var reader = GetReader(beatmapSet)) + { + string[] mapNames = reader.ReadBeatmaps(); foreach (var name in mapNames) { using (var stream = new StreamReader(reader.ReadFile(name))) @@ -92,9 +92,9 @@ namespace osu.Game.Database Beatmap beatmap = new Beatmap(); decoder.Decode(stream, beatmap); beatmapSet.Beatmaps.Add(beatmap); - } - } - } - } - } + } + } + } + } + } } \ No newline at end of file From 8c7ff583103fc083bef63278c55cbc6559ab49ca Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 14 Oct 2016 12:50:03 +0900 Subject: [PATCH 8/9] Fix regressions caused by overlay class. --- osu.Game/OsuGame.cs | 7 ------- osu.Game/Overlays/Overlay.cs | 16 ++++++++++++++-- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index 05438bc470..65e7045445 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -97,7 +97,6 @@ namespace osu.Game OnHome = delegate { MainMenu?.MakeCurrent(); }, OnSettings = Options.ToggleVisibility, OnPlayModeChange = delegate (PlayMode m) { PlayMode.Value = m; }, - Alpha = 0.001f, }, Chat = new ChatConsole(API), new VolumeControl @@ -112,12 +111,6 @@ namespace osu.Game } }); - Toolbar.State = Visibility.Hidden; - Toolbar.Flush(); - - Chat.State = Visibility.Hidden; - Chat.Flush(); - intro.ModePushed += modeAdded; intro.Exited += modeRemoved; diff --git a/osu.Game/Overlays/Overlay.cs b/osu.Game/Overlays/Overlay.cs index 31e4c10d2a..648a78c248 100644 --- a/osu.Game/Overlays/Overlay.cs +++ b/osu.Game/Overlays/Overlay.cs @@ -3,8 +3,20 @@ using osu.Framework.Graphics.Containers; namespace osu.Game.Overlays { + /// + /// An element which starts hidden and can be toggled to visible. + /// public abstract class Overlay : Container, IStateful { + public override void Load(BaseGame game) + { + base.Load(game); + + //TODO: init code using Alpha or IsVisible override to ensure we don't call Load on children before we first get unhidden. + PopOut(); + Flush(); + } + private Visibility state; public Visibility State { @@ -30,9 +42,9 @@ namespace osu.Game.Overlays protected abstract void PopOut(); - public void ToggleVisibility() - => State = (State == Visibility.Visible ? Visibility.Hidden : Visibility.Visible); + public void ToggleVisibility() => State = (State == Visibility.Visible ? Visibility.Hidden : Visibility.Visible); } + public enum Visibility { Hidden, From cc9bc9db93e606fc0ea4d655f98fadb029dd9bea Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 14 Oct 2016 12:53:44 +0900 Subject: [PATCH 9/9] Update framework version. --- osu-framework | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu-framework b/osu-framework index 30ff0e1a99..3629521379 160000 --- a/osu-framework +++ b/osu-framework @@ -1 +1 @@ -Subproject commit 30ff0e1a99a10e735611bb3ffa35352061f52d8a +Subproject commit 3629521379bea5d79cd41e35ad6c6dfe21b4f9e7