Implement yearly intake functionality in school simulation, allowing for the graduation of students and the addition of new first-year pupils. Update the roster management to reflect these changes, ensuring proper entity handling in the simulation. Enhance the API to support name sets during roster installation and revise related tests to validate the new intake process and roster updates.
This commit is contained in:
@@ -6,6 +6,9 @@ namespace HSchool.Simulation;
|
||||
/// <summary>Turns roster records into Arch entities. Parents have no map location — by design.</summary>
|
||||
public static class RosterSpawner
|
||||
{
|
||||
private static readonly QueryDescription People = new QueryDescription().WithAll<PersonIdentity>();
|
||||
private static readonly QueryDescription Classes = new QueryDescription().WithAll<ClassIdentity>();
|
||||
|
||||
public static void Spawn(World world, Roster roster)
|
||||
{
|
||||
foreach (var schoolClass in roster.Classes)
|
||||
@@ -36,4 +39,22 @@ public static class RosterSpawner
|
||||
person.WorkplaceRoomId));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Drops the previous composition and spawns <paramref name="roster"/>. Called on yearly intake.</summary>
|
||||
public static void Replace(World world, Roster roster)
|
||||
{
|
||||
DestroyAll(world, People);
|
||||
DestroyAll(world, Classes);
|
||||
Spawn(world, roster);
|
||||
}
|
||||
|
||||
private static void DestroyAll(World world, QueryDescription query)
|
||||
{
|
||||
var entities = new List<Entity>();
|
||||
world.Query(in query, (Entity entity) => entities.Add(entity));
|
||||
foreach (var entity in entities)
|
||||
{
|
||||
world.Destroy(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user