use AppSerializerContext singleton
This commit is contained in:
parent
a2ae6d273e
commit
4b5288b237
|
@ -1,3 +1,4 @@
|
|||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace TanksServer.Interactivity;
|
||||
|
@ -6,4 +7,5 @@ namespace TanksServer.Interactivity;
|
|||
[JsonSerializable(typeof(IEnumerable<Player>))]
|
||||
[JsonSerializable(typeof(IEnumerable<string>))]
|
||||
[JsonSerializable(typeof(PlayerInfo))]
|
||||
[JsonSourceGenerationOptions(JsonSerializerDefaults.Web)]
|
||||
internal sealed partial class AppSerializerContext : JsonSerializerContext;
|
||||
|
|
|
@ -11,7 +11,6 @@ internal sealed class PlayerInfoConnection(
|
|||
MapEntityManager entityManager
|
||||
) : WebsocketServerConnection(logger, new ByteChannelWebSocket(rawSocket, logger, 0))
|
||||
{
|
||||
private readonly AppSerializerContext _context = new(new JsonSerializerOptions(JsonSerializerDefaults.Web));
|
||||
private bool _wantsInfoOnTick = true;
|
||||
private byte[] _lastMessage = [];
|
||||
|
||||
|
@ -54,7 +53,7 @@ internal sealed class PlayerInfoConnection(
|
|||
}
|
||||
|
||||
var info = new PlayerInfo(player.Name, player.Scores, player.Controls.ToDisplayString(), tankInfo);
|
||||
var response = JsonSerializer.SerializeToUtf8Bytes(info, _context.PlayerInfo);
|
||||
var response = JsonSerializer.SerializeToUtf8Bytes(info, AppSerializerContext.Default.PlayerInfo);
|
||||
|
||||
if (response.SequenceEqual(_lastMessage))
|
||||
return null;
|
||||
|
|
Loading…
Reference in a new issue