Enhance school simulation and management by integrating roster functionality, allowing for the installation and persistence of student and staff data. Update the school architecture to include a roster alongside existing components, ensuring proper validation against map layouts. Revise room definitions to support homeroom designations and update related tests to validate new functionalities and ensure robustness in roster handling.
ci / server (push) Failing after 3m43s
ci / client (push) Failing after 10s

This commit is contained in:
Leonid Pershin
2026-08-18 19:21:40 +03:00
parent e6182e0e45
commit 52c5082418
27 changed files with 732 additions and 66 deletions
+57
View File
@@ -0,0 +1,57 @@
using System.Text.Json;
using System.Text.Json.Serialization;
namespace HSchool.People;
/// <summary>On-disk shape of <c>saves/{id}.people.json</c>. Composition only — needs are not live values.</summary>
public sealed class RosterDocument
{
public const int CurrentFormat = 1;
public int Format { get; init; } = CurrentFormat;
public int Seed { get; init; }
public required IReadOnlyList<Person> People { get; init; }
public required IReadOnlyList<Family> Families { get; init; }
public required IReadOnlyList<SchoolClass> Classes { get; init; }
public Roster ToRoster() => new(People, Families, Classes);
public static RosterDocument From(int seed, Roster roster) =>
new()
{
Format = CurrentFormat,
Seed = seed,
People = roster.People,
Families = roster.Families,
Classes = roster.Classes,
};
}
public static class RosterJson
{
public static JsonSerializerOptions Options { get; } = new()
{
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
PropertyNameCaseInsensitive = true,
WriteIndented = true,
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
};
public static string Serialize(RosterDocument document) =>
JsonSerializer.Serialize(document, Options);
public static RosterDocument Parse(string json)
{
var document = JsonSerializer.Deserialize<RosterDocument>(json, Options);
if (document is null || document.People is null || document.Families is null || document.Classes is null)
{
throw new InvalidOperationException("People save deserialized to nothing.");
}
return document;
}
}