mirror of
https://github.com/ppy/osu.git
synced 2025-01-28 00:02:56 +08:00
Underscore + lowercase all keys
This commit is contained in:
parent
dfc10d42e8
commit
245b5f759f
@ -45,13 +45,13 @@ namespace osu.Game.IO.Serialization.Converters
|
|||||||
var obj = JObject.Load(reader);
|
var obj = JObject.Load(reader);
|
||||||
|
|
||||||
var lookupTable = new List<string>();
|
var lookupTable = new List<string>();
|
||||||
serializer.Populate(obj["LookupTable"].CreateReader(), lookupTable);
|
serializer.Populate(obj["lookup_table"].CreateReader(), lookupTable);
|
||||||
|
|
||||||
foreach (var tok in obj["Items"])
|
foreach (var tok in obj["items"])
|
||||||
{
|
{
|
||||||
var itemReader = tok.CreateReader();
|
var itemReader = tok.CreateReader();
|
||||||
|
|
||||||
var typeName = lookupTable[(int)tok["Type"]];
|
var typeName = lookupTable[(int)tok["type"]];
|
||||||
var instance = (T)Activator.CreateInstance(Type.GetType(typeName));
|
var instance = (T)Activator.CreateInstance(Type.GetType(typeName));
|
||||||
serializer.Populate(itemReader, instance);
|
serializer.Populate(itemReader, instance);
|
||||||
|
|
||||||
@ -84,16 +84,16 @@ namespace osu.Game.IO.Serialization.Converters
|
|||||||
}
|
}
|
||||||
|
|
||||||
var itemObject = JObject.FromObject(item, serializer);
|
var itemObject = JObject.FromObject(item, serializer);
|
||||||
itemObject.AddFirst(new JProperty("Type", typeId));
|
itemObject.AddFirst(new JProperty("type", typeId));
|
||||||
objects.Add(itemObject);
|
objects.Add(itemObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
writer.WriteStartObject();
|
writer.WriteStartObject();
|
||||||
|
|
||||||
writer.WritePropertyName("LookupTable");
|
writer.WritePropertyName("lookup_table");
|
||||||
serializer.Serialize(writer, lookupTable);
|
serializer.Serialize(writer, lookupTable);
|
||||||
|
|
||||||
writer.WritePropertyName("Items");
|
writer.WritePropertyName("items");
|
||||||
serializer.Serialize(writer, objects);
|
serializer.Serialize(writer, objects);
|
||||||
|
|
||||||
writer.WriteEndObject();
|
writer.WriteEndObject();
|
||||||
|
@ -18,7 +18,7 @@ namespace osu.Game.IO.Serialization.Converters
|
|||||||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
|
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
|
||||||
{
|
{
|
||||||
var obj = JObject.Load(reader);
|
var obj = JObject.Load(reader);
|
||||||
return new Vector2((float)obj["X"], (float)obj["Y"]);
|
return new Vector2((float)obj["x"], (float)obj["y"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
|
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
|
||||||
@ -27,9 +27,9 @@ namespace osu.Game.IO.Serialization.Converters
|
|||||||
|
|
||||||
writer.WriteStartObject();
|
writer.WriteStartObject();
|
||||||
|
|
||||||
writer.WritePropertyName("X");
|
writer.WritePropertyName("x");
|
||||||
writer.WriteValue(vector.X);
|
writer.WriteValue(vector.X);
|
||||||
writer.WritePropertyName("Y");
|
writer.WritePropertyName("y");
|
||||||
writer.WriteValue(vector.Y);
|
writer.WriteValue(vector.Y);
|
||||||
|
|
||||||
writer.WriteEndObject();
|
writer.WriteEndObject();
|
||||||
|
@ -30,7 +30,8 @@ namespace osu.Game.IO.Serialization
|
|||||||
Formatting = Formatting.Indented,
|
Formatting = Formatting.Indented,
|
||||||
ObjectCreationHandling = ObjectCreationHandling.Replace,
|
ObjectCreationHandling = ObjectCreationHandling.Replace,
|
||||||
DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate,
|
DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate,
|
||||||
Converters = new JsonConverter[] { new Vector2Converter() }
|
Converters = new JsonConverter[] { new Vector2Converter() },
|
||||||
|
ContractResolver = new KeyContractResolver()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
16
osu.Game/IO/Serialization/KeyContractResolver.cs
Normal file
16
osu.Game/IO/Serialization/KeyContractResolver.cs
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||||
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||||
|
|
||||||
|
using Humanizer;
|
||||||
|
using Newtonsoft.Json.Serialization;
|
||||||
|
|
||||||
|
namespace osu.Game.IO.Serialization
|
||||||
|
{
|
||||||
|
public class KeyContractResolver : DefaultContractResolver
|
||||||
|
{
|
||||||
|
protected override string ResolvePropertyName(string propertyName)
|
||||||
|
{
|
||||||
|
return propertyName.Underscore();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -272,6 +272,7 @@
|
|||||||
<Compile Include="Graphics\UserInterface\HoverClickSounds.cs" />
|
<Compile Include="Graphics\UserInterface\HoverClickSounds.cs" />
|
||||||
<Compile Include="Graphics\UserInterface\HoverSounds.cs" />
|
<Compile Include="Graphics\UserInterface\HoverSounds.cs" />
|
||||||
<Compile Include="Graphics\UserInterface\OsuButton.cs" />
|
<Compile Include="Graphics\UserInterface\OsuButton.cs" />
|
||||||
|
<Compile Include="IO\Serialization\KeyContractResolver.cs" />
|
||||||
<Compile Include="Migrations\20171019041408_InitialCreate.cs" />
|
<Compile Include="Migrations\20171019041408_InitialCreate.cs" />
|
||||||
<Compile Include="Migrations\20171019041408_InitialCreate.Designer.cs">
|
<Compile Include="Migrations\20171019041408_InitialCreate.Designer.cs">
|
||||||
<DependentUpon>20171019041408_InitialCreate.cs</DependentUpon>
|
<DependentUpon>20171019041408_InitialCreate.cs</DependentUpon>
|
||||||
|
Loading…
Reference in New Issue
Block a user