mirror of
https://github.com/ppy/osu.git
synced 2024-11-14 16:37:26 +08:00
Implement IJsonSerializable, BeatmapInfo IJsonSerializable.
This commit is contained in:
parent
37129bf03d
commit
cec8bca78a
@ -1,7 +1,9 @@
|
|||||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||||
|
|
||||||
|
using Newtonsoft.Json;
|
||||||
using osu.Game.Beatmaps.Samples;
|
using osu.Game.Beatmaps.Samples;
|
||||||
|
using osu.Game.IO.Serialization;
|
||||||
using osu.Game.Modes;
|
using osu.Game.Modes;
|
||||||
using SQLite.Net.Attributes;
|
using SQLite.Net.Attributes;
|
||||||
using SQLiteNetExtensions.Attributes;
|
using SQLiteNetExtensions.Attributes;
|
||||||
@ -10,7 +12,7 @@ using System.Linq;
|
|||||||
|
|
||||||
namespace osu.Game.Database
|
namespace osu.Game.Database
|
||||||
{
|
{
|
||||||
public class BeatmapInfo : IEquatable<BeatmapInfo>
|
public class BeatmapInfo : IEquatable<BeatmapInfo>, IJsonSerializable
|
||||||
{
|
{
|
||||||
[PrimaryKey, AutoIncrement]
|
[PrimaryKey, AutoIncrement]
|
||||||
public int ID { get; set; }
|
public int ID { get; set; }
|
||||||
@ -57,17 +59,13 @@ namespace osu.Game.Database
|
|||||||
// Editor
|
// Editor
|
||||||
// This bookmarks stuff is necessary because DB doesn't know how to store int[]
|
// This bookmarks stuff is necessary because DB doesn't know how to store int[]
|
||||||
public string StoredBookmarks { get; internal set; }
|
public string StoredBookmarks { get; internal set; }
|
||||||
|
|
||||||
[Ignore]
|
[Ignore]
|
||||||
|
[JsonIgnore]
|
||||||
public int[] Bookmarks
|
public int[] Bookmarks
|
||||||
{
|
{
|
||||||
get
|
get { return StoredBookmarks.Split(',').Select(int.Parse).ToArray(); }
|
||||||
{
|
set { StoredBookmarks = string.Join(",", value); }
|
||||||
return StoredBookmarks.Split(',').Select(int.Parse).ToArray();
|
|
||||||
}
|
|
||||||
set
|
|
||||||
{
|
|
||||||
StoredBookmarks = string.Join(",", value);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public double DistanceSpacing { get; set; }
|
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 &&
|
public bool AudioEquals(BeatmapInfo other) => other != null && BeatmapSet != null && other.BeatmapSet != null &&
|
||||||
BeatmapSet.Path == other.BeatmapSet.Path &&
|
BeatmapSet.Path == other.BeatmapSet.Path &&
|
||||||
(Metadata ?? BeatmapSet.Metadata).AudioFile == (other.Metadata ?? other.BeatmapSet.Metadata).AudioFile;
|
(Metadata ?? BeatmapSet.Metadata).AudioFile == (other.Metadata ?? other.BeatmapSet.Metadata).AudioFile;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
29
osu.Game/IO/Serialization/IJsonSerializable.cs
Normal file
29
osu.Game/IO/Serialization/IJsonSerializable.cs
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||||
|
// 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<T>(string objString)
|
||||||
|
{
|
||||||
|
return JsonConvert.DeserializeObject<T>(objString);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static T DeepClone<T>(this IJsonSerializable obj)
|
||||||
|
{
|
||||||
|
return Deserialize<T>(Serialize(obj));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -97,6 +97,7 @@
|
|||||||
<Compile Include="IO\Legacy\ILegacySerializable.cs" />
|
<Compile Include="IO\Legacy\ILegacySerializable.cs" />
|
||||||
<Compile Include="IO\Legacy\SerializationReader.cs" />
|
<Compile Include="IO\Legacy\SerializationReader.cs" />
|
||||||
<Compile Include="IO\Legacy\SerializationWriter.cs" />
|
<Compile Include="IO\Legacy\SerializationWriter.cs" />
|
||||||
|
<Compile Include="IO\Serialization\IJsonSerializable.cs" />
|
||||||
<Compile Include="IPC\ScoreIPCChannel.cs" />
|
<Compile Include="IPC\ScoreIPCChannel.cs" />
|
||||||
<Compile Include="Modes\Replays\Replay.cs" />
|
<Compile Include="Modes\Replays\Replay.cs" />
|
||||||
<Compile Include="Modes\Judgements\DrawableJudgement.cs" />
|
<Compile Include="Modes\Judgements\DrawableJudgement.cs" />
|
||||||
|
Loading…
Reference in New Issue
Block a user