Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use single JsonSerializerOptions to fix dotnet 8 #94

Merged
merged 1 commit into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions RetakesPlugin/Modules/Configs/MapConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void Load()
}

var jsonData = File.ReadAllText(_mapConfigPath);
_mapConfigData = JsonSerializer.Deserialize<MapConfigData>(jsonData);
_mapConfigData = JsonSerializer.Deserialize<MapConfigData>(jsonData, Helpers.JsonSerializerOptions);

// TODO: Implement validation to make sure the config is valid / has enough spawns.
// if (_mapConfigData!.Spawns == null || _mapConfigData.Spawns.Count < 0)
Expand Down Expand Up @@ -119,10 +119,7 @@ private MapConfigData GetSanitisedMapConfigData()

private void Save()
{
var jsonString = JsonSerializer.Serialize(GetSanitisedMapConfigData(), new JsonSerializerOptions
{
WriteIndented = true
});
var jsonString = JsonSerializer.Serialize(GetSanitisedMapConfigData(), Helpers.JsonSerializerOptions);

try
{
Expand Down
7 changes: 2 additions & 5 deletions RetakesPlugin/Modules/Configs/RetakesConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void Load()
}

var jsonData = File.ReadAllText(_retakesConfigPath);
RetakesConfigData = JsonSerializer.Deserialize<RetakesConfigData>(jsonData);
RetakesConfigData = JsonSerializer.Deserialize<RetakesConfigData>(jsonData, Helpers.JsonSerializerOptions);

if (RetakesConfigData == null)
{
Expand Down Expand Up @@ -54,10 +54,7 @@ public void Load()

private void Save()
{
var jsonString = JsonSerializer.Serialize(RetakesConfigData, new JsonSerializerOptions
{
WriteIndented = true
});
var jsonString = JsonSerializer.Serialize(RetakesConfigData, Helpers.JsonSerializerOptions);

try
{
Expand Down
11 changes: 11 additions & 0 deletions RetakesPlugin/Modules/Helpers.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
using System.Drawing;
using System.Text;
using System.Text.Json;
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Entities.Constants;
using CounterStrikeSharp.API.Modules.Utils;
using RetakesPlugin.Modules.Configs;
using RetakesPlugin.Modules.Configs.JsonConverters;
using RetakesPluginShared.Enums;

namespace RetakesPlugin.Modules;

public static class Helpers
{
internal static readonly Random Random = new();
internal static readonly JsonSerializerOptions JsonSerializerOptions = new()
{
WriteIndented = true,
Converters =
{
new VectorJsonConverter(),
new QAngleJsonConverter()
}
};

public static bool IsValidPlayer(CCSPlayerController? player)
{
Expand Down