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

Fix incorrect reference + simplify

This commit is contained in:
smoogipoo 2020-06-03 17:41:05 +09:00
parent 8aa8d2c880
commit 092f5b6521

View File

@ -42,24 +42,24 @@ namespace osu.Game.IO.Serialization.Converters
var obj = JObject.Load(reader);
if (!obj.TryGetValue("$lookup_table", out var lookupTableToken) || lookupTableToken == null)
if (obj["$lookup_table"] == null)
return list;
var lookupTable = serializer.Deserialize<List<string>>(lookupTableToken.CreateReader());
var lookupTable = serializer.Deserialize<List<string>>(obj["$lookup_table"].CreateReader());
if (lookupTable == null)
return list;
if (!obj.TryGetValue("$items", out var itemsToken) || itemsToken == null)
if (obj["$items"] == null)
return list;
foreach (var tok in itemsToken)
foreach (var tok in obj["$items"])
{
var itemReader = tok.CreateReader();
if (!obj.TryGetValue("$type", out var typeToken) || typeToken == null)
if (tok["$type"] == null)
throw new JsonException("Expected $type token.");
var typeName = lookupTable[(int)typeToken];
var typeName = lookupTable[(int)tok["$type"]];
var instance = (T)Activator.CreateInstance(Type.GetType(typeName));
serializer.Populate(itemReader, instance);