1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 10:33:30 +08:00

Fix not being able to serialise converted beatmaps

This commit is contained in:
smoogipoo 2020-04-21 14:52:58 +09:00
parent 21949ac499
commit a702a521f8

View File

@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Collections;
using System.Collections.Generic;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
@ -43,13 +44,13 @@ namespace osu.Game.IO.Serialization.Converters
var list = new List<T>();
var obj = JObject.Load(reader);
var lookupTable = serializer.Deserialize<List<string>>(obj["lookup_table"].CreateReader());
var lookupTable = serializer.Deserialize<List<string>>(obj["$lookup_table"].CreateReader());
foreach (var tok in obj["items"])
foreach (var tok in obj["$items"])
{
var itemReader = tok.CreateReader();
var typeName = lookupTable[(int)tok["type"]];
var typeName = lookupTable[(int)tok["$type"]];
var instance = (T)Activator.CreateInstance(Type.GetType(typeName));
serializer.Populate(itemReader, instance);
@ -61,7 +62,7 @@ namespace osu.Game.IO.Serialization.Converters
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
var list = (List<T>)value;
var list = (IList)value;
var lookupTable = new List<string>();
var objects = new List<JObject>();
@ -84,16 +85,16 @@ namespace osu.Game.IO.Serialization.Converters
}
var itemObject = JObject.FromObject(item, serializer);
itemObject.AddFirst(new JProperty("type", typeId));
itemObject.AddFirst(new JProperty("$type", typeId));
objects.Add(itemObject);
}
writer.WriteStartObject();
writer.WritePropertyName("lookup_table");
writer.WritePropertyName("$lookup_table");
serializer.Serialize(writer, lookupTable);
writer.WritePropertyName("items");
writer.WritePropertyName("$items");
serializer.Serialize(writer, objects);
writer.WriteEndObject();