Fixes JSON WorldConverter (#263)

- [X] Adds Map index support for JSON MapConverter
- [X] Files JSON WorldConverter
- [X] Removes LINQ for Map.Parse

Bumps release version
This commit is contained in:
Kamron Batman 2020-09-20 14:56:46 -07:00 • committed by GitHub
parent 13e2693b59
commit 93cf40ec81
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 73 additions and 54 deletions

View file

@ -21,10 +21,15 @@ namespace Server.Json
{
public class MapConverter : JsonConverter<Map>
{
public override Map Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
=> Map.Parse(reader.GetString());
public override Map Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) =>
reader.TokenType switch
{
JsonTokenType.String => Map.Parse(reader.GetString()),
JsonTokenType.Number => Map.Maps[reader.GetInt32()],
_ => throw new JsonException($"Value must be a number or string")
};
public override void Write(Utf8JsonWriter writer, Map value, JsonSerializerOptions options)
=> writer.WriteStringValue(value.Name);
public override void Write(Utf8JsonWriter writer, Map value, JsonSerializerOptions options) =>
writer.WriteStringValue(value.Name);
}
}