diff --git a/osu.Game/Database/BeatmapInfo.cs b/osu.Game/Database/BeatmapInfo.cs index aabe0755fe..b9ec0c69af 100644 --- a/osu.Game/Database/BeatmapInfo.cs +++ b/osu.Game/Database/BeatmapInfo.cs @@ -1,7 +1,9 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using Newtonsoft.Json; using osu.Game.Beatmaps.Samples; +using osu.Game.IO.Serialization; using osu.Game.Modes; using SQLite.Net.Attributes; using SQLiteNetExtensions.Attributes; @@ -10,7 +12,7 @@ using System.Linq; namespace osu.Game.Database { - public class BeatmapInfo : IEquatable + public class BeatmapInfo : IEquatable, IJsonSerializable { [PrimaryKey, AutoIncrement] public int ID { get; set; } @@ -57,17 +59,13 @@ namespace osu.Game.Database // Editor // This bookmarks stuff is necessary because DB doesn't know how to store int[] public string StoredBookmarks { get; internal set; } + [Ignore] + [JsonIgnore] public int[] Bookmarks { - get - { - return StoredBookmarks.Split(',').Select(int.Parse).ToArray(); - } - set - { - StoredBookmarks = string.Join(",", value); - } + get { return StoredBookmarks.Split(',').Select(int.Parse).ToArray(); } + set { StoredBookmarks = string.Join(",", value); } } public double DistanceSpacing { get; set; } @@ -86,7 +84,7 @@ namespace osu.Game.Database } public bool AudioEquals(BeatmapInfo other) => other != null && BeatmapSet != null && other.BeatmapSet != null && - BeatmapSet.Path == other.BeatmapSet.Path && - (Metadata ?? BeatmapSet.Metadata).AudioFile == (other.Metadata ?? other.BeatmapSet.Metadata).AudioFile; + BeatmapSet.Path == other.BeatmapSet.Path && + (Metadata ?? BeatmapSet.Metadata).AudioFile == (other.Metadata ?? other.BeatmapSet.Metadata).AudioFile; } } diff --git a/osu.Game/IO/Serialization/IJsonSerializable.cs b/osu.Game/IO/Serialization/IJsonSerializable.cs new file mode 100644 index 0000000000..33d0801e47 --- /dev/null +++ b/osu.Game/IO/Serialization/IJsonSerializable.cs @@ -0,0 +1,29 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using Newtonsoft.Json; + +namespace osu.Game.IO.Serialization +{ + public interface IJsonSerializable + { + } + + public static class JsonSerializableExtensions + { + public static string Serialize(this IJsonSerializable obj) + { + return JsonConvert.SerializeObject(obj); + } + + public static T Deserialize(string objString) + { + return JsonConvert.DeserializeObject(objString); + } + + public static T DeepClone(this IJsonSerializable obj) + { + return Deserialize(Serialize(obj)); + } + } +} diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index a9e8dfb5bb..b2d8aedb7f 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -97,6 +97,7 @@ +