46 lines
1.6 KiB
C#
46 lines
1.6 KiB
C#
using Arch.Core;
|
|
using HSchool.Schedule;
|
|
using HSchool.Simulation;
|
|
|
|
namespace HSchool.Server.Game;
|
|
|
|
/// <summary>
|
|
/// Live slice of one school for a diagnostic dump. Built on the worker thread; HTTP never sees
|
|
/// the <c>World</c>.
|
|
/// </summary>
|
|
internal sealed record SchoolLiveDump(
|
|
DateTime GameTime,
|
|
bool Running,
|
|
IReadOnlyList<PresenceSnapshot> Presence,
|
|
IReadOnlyDictionary<string, IReadOnlyDictionary<string, float>> Needs,
|
|
IReadOnlyList<LessonPlacement> Now);
|
|
|
|
/// <summary>Reads presence and needs from the live school. Call only on that school's worker.</summary>
|
|
internal static class SchoolDumpReader
|
|
{
|
|
private static readonly QueryDescription IdentityAndNeeds =
|
|
new QueryDescription().WithAll<PersonIdentity, PersonNeeds>();
|
|
|
|
public static SchoolLiveDump Read(School school, int weekDays)
|
|
{
|
|
var needs = new Dictionary<string, IReadOnlyDictionary<string, float>>(StringComparer.Ordinal);
|
|
school.World.Query(in IdentityAndNeeds, (ref PersonIdentity identity, ref PersonNeeds live) =>
|
|
{
|
|
needs[identity.Id] = new Dictionary<string, float>(live.Values, StringComparer.Ordinal);
|
|
});
|
|
|
|
IReadOnlyList<LessonPlacement> now = [];
|
|
if (school.Timetable is not null && school.Catalog is not null)
|
|
{
|
|
now = TimetableClock.OccurringAt(school.Timetable, school.Catalog, school.Clock.Time, weekDays);
|
|
}
|
|
|
|
return new SchoolLiveDump(
|
|
school.Clock.Time,
|
|
school.Clock.IsRunning,
|
|
school.CapturePresence(),
|
|
needs,
|
|
now);
|
|
}
|
|
}
|