mirror of
https://github.com/ppy/osu.git
synced 2025-02-13 10:33:07 +08:00
Use enum property
This commit is contained in:
parent
a021aaf546
commit
e23d81bfc6
@ -0,0 +1,16 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using Newtonsoft.Json.Converters;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
|
||||
namespace osu.Game.IO.Serialization.Converters
|
||||
{
|
||||
public class SnakeCaseStringEnumConverter : StringEnumConverter
|
||||
{
|
||||
public SnakeCaseStringEnumConverter()
|
||||
{
|
||||
NamingStrategy = new SnakeCaseNamingStrategy();
|
||||
}
|
||||
}
|
||||
}
|
@ -6,6 +6,7 @@ using System.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Game.IO.Serialization.Converters;
|
||||
using osu.Game.Online.Multiplayer.GameTypes;
|
||||
using osu.Game.Online.Multiplayer.RoomStatuses;
|
||||
using osu.Game.Users;
|
||||
@ -40,15 +41,11 @@ namespace osu.Game.Online.Multiplayer
|
||||
|
||||
// Todo: osu-framework bug (https://github.com/ppy/osu-framework/issues/4106)
|
||||
[JsonProperty("category")]
|
||||
private string categoryString
|
||||
[JsonConverter(typeof(SnakeCaseStringEnumConverter))]
|
||||
private RoomCategory category
|
||||
{
|
||||
get => Category.Value.ToString().ToLower();
|
||||
set
|
||||
{
|
||||
if (!Enum.TryParse<RoomCategory>(value, true, out var enumValue))
|
||||
enumValue = RoomCategory.Normal;
|
||||
Category.Value = enumValue;
|
||||
}
|
||||
get => Category.Value;
|
||||
set => Category.Value = value;
|
||||
}
|
||||
|
||||
[Cached]
|
||||
|
Loading…
Reference in New Issue
Block a user