fix: Fixes region priority and resolution. (#1254)

- [X] Fixes world location JSON deserializer.
- [X] Fixes region resolver and priorities.
- [X] Removes DynamicJson from regions.
- [X] Adds missing region music.
This commit is contained in:
Kamron Batman 2022-11-21 10:38:20 -08:00 • committed by GitHub
parent 139be1bc23
commit 18c4459e6b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
31 changed files with 3809 additions and 3677 deletions

View file

@ -1,46 +0,0 @@
/*************************************************************************
* ModernUO *
* Copyright 2019-2022 - ModernUO Development Team *
* Email: hi@modernuo.com *
* File: JsonDtoConverter.cs *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*************************************************************************/
using System;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Server.Json;
public class JsonDtoConverter<TDto, TObject> : JsonConverter<TObject>
where TDto : IJsonRootDtoConvertible<TDto, TObject>, new() where TObject : new()
{
public override TObject Read(
ref Utf8JsonReader reader,
Type typeToConvert,
JsonSerializerOptions options
)
{
if (typeof(TObject) != typeToConvert)
{
throw new JsonException($"Invalid object type to deserialize for '{typeof(TObject).Name}'");
}
// Deserialize to the DTO
var dto = JsonSerializer.Deserialize<TDto>(ref reader, options);
return TDto.ToObject(dto);
}
public override void Write(Utf8JsonWriter writer, TObject value, JsonSerializerOptions options)
{
JsonSerializer.Serialize(writer, TDto.FromObject(value), options);
}
}

View file

@ -1,29 +0,0 @@
/*************************************************************************
* ModernUO *
* Copyright 2019-2022 - ModernUO Development Team *
* Email: hi@modernuo.com *
* File: JsonDtoConverter.cs *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*************************************************************************/
using System;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Server.Json;
public class JsonDtoConverterFactory<TDto, TObject> : JsonConverterFactory
where TDto : IJsonRootDtoConvertible<TDto, TObject>, new() where TObject : new()
{
public override bool CanConvert(Type typeToConvert) => typeToConvert == typeof(TObject);
public override JsonConverter CreateConverter(Type typeToConvert, JsonSerializerOptions options) =>
new JsonDtoConverter<TDto, TObject>();
}

View file

@ -80,7 +80,6 @@ public class WorldLocationConverter : JsonConverter<WorldLocation>
private WorldLocation DeserializeObj(ref Utf8JsonReader reader, JsonSerializerOptions options)
{
Span<int> data = stackalloc int[3];
var count = 0;
var hasLoc = false;
var hasXYZ = false;
var hasMap = false;
@ -150,7 +149,6 @@ public class WorldLocationConverter : JsonConverter<WorldLocation>
data[0] = loc.X;
data[1] = loc.Y;
data[2] = loc.Z;
count = 3;
continue;
}
@ -160,7 +158,7 @@ public class WorldLocationConverter : JsonConverter<WorldLocation>
hasMap = true;
}
if (!hasMap || count != 3)
if (!hasMap)
{
throw new JsonException("WorldLocation must have an x, y, z, and map properties");
}

View file

@ -1,28 +0,0 @@
/*************************************************************************
* ModernUO *
* Copyright 2019-2022 - ModernUO Development Team *
* Email: hi@modernuo.com *
* File: IJsonConvertible.cs *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*************************************************************************/
namespace Server.Json;
public interface IJsonRootDtoConvertible<TSelf, TObject> where TSelf : IJsonRootDtoConvertible<TSelf, TObject> where TObject : new()
{
public abstract static TSelf FromObject(TObject obj);
public abstract static TObject ToObject(TSelf obj);
}
public interface IJsonDtoConvertible<TSelf, TObject> where TSelf : IJsonDtoConvertible<TSelf, TObject> where TObject : new()
{
public abstract TSelf HydrateDto(TObject obj);
public abstract TObject HydrateObject(TObject obj);
}