Add HSchool.Content project for JSONC definitions, catalog, and map validation. Update solution structure to include new content and tests projects. Enhance school management to support mod packs and map instances, ensuring proper loading and validation. Revise documentation to reflect these changes and update tests for new functionality.
ci / server (push) Failing after 3m36s
ci / client (push) Successful in 13s

This commit is contained in:
Leonid Pershin
2026-08-18 14:35:09 +03:00
parent 37c39a3beb
commit 1bc75244e8
55 changed files with 2289 additions and 59 deletions
+53
View File
@@ -0,0 +1,53 @@
using System.Text.Json;
using System.Text.Json.Nodes;
namespace HSchool.Content;
/// <summary>JSON with comments and trailing commas — the format of every def, patch, locale and map file.</summary>
public static class Jsonc
{
public static JsonSerializerOptions SerializerOptions { get; } = new()
{
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
PropertyNameCaseInsensitive = true,
AllowTrailingCommas = true,
WriteIndented = true,
};
public static JsonDocumentOptions DocumentOptions { get; } = new()
{
// Skip, not Allow: JsonDocument will not store comments. The files may still contain them.
CommentHandling = JsonCommentHandling.Skip,
AllowTrailingCommas = true,
};
public static JsonNode Parse(string text, string? source = null)
{
try
{
var node = JsonNode.Parse(text, documentOptions: DocumentOptions);
if (node is null)
{
throw new ContentLoadException(source is null ? "JSONC was empty." : $"JSONC {source} was empty.");
}
return node;
}
catch (JsonException ex)
{
var where = source is null ? "JSONC" : $"JSONC {source}";
throw new ContentLoadException($"{where} is not valid: {ex.Message}", ex);
}
}
public static T Deserialize<T>(JsonNode node)
{
var value = node.Deserialize<T>(SerializerOptions);
if (value is null)
{
throw new ContentLoadException($"Could not read a {typeof(T).Name} from JSONC.");
}
return value;
}
}