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.
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using HSchool.Content;
|
||||
using HSchool.Protocol;
|
||||
using HSchool.Server.Net;
|
||||
using HSchool.Simulation;
|
||||
@@ -15,6 +16,7 @@ internal sealed class GameLoopService(
|
||||
ClientRegistry clients,
|
||||
GameMetrics metrics,
|
||||
SchoolStore store,
|
||||
ModContent mods,
|
||||
ILoggerFactory loggerFactory,
|
||||
ILogger<GameLoopService> logger) : BackgroundService
|
||||
{
|
||||
@@ -170,7 +172,7 @@ internal sealed class GameLoopService(
|
||||
var id = _nextId++;
|
||||
store.WriteNextId(_nextId);
|
||||
|
||||
var worker = SpawnWorker(id, normalized, command.StartDate, running: true, ClockSpeed.DefaultIndex, isNew: true);
|
||||
var worker = SpawnWorker(id, normalized, command.StartDate, running: true, ClockSpeed.DefaultIndex, isNew: true, modIds: null, map: null);
|
||||
Track(worker);
|
||||
worker.Start();
|
||||
|
||||
@@ -327,15 +329,25 @@ internal sealed class GameLoopService(
|
||||
save.GameTime,
|
||||
save.Running,
|
||||
save.SpeedIndex,
|
||||
isNew: false);
|
||||
Track(worker);
|
||||
isNew: false,
|
||||
save.ModIds,
|
||||
save.Map);
|
||||
worker.Start();
|
||||
}
|
||||
|
||||
if (_workers.Count > 0)
|
||||
{
|
||||
await Task.WhenAll(_workers.Values.Select(worker => worker.Started)).ConfigureAwait(false);
|
||||
logger.LogInformation("Restored {Count} school(s) from disk.", _workers.Count);
|
||||
try
|
||||
{
|
||||
await worker.Started.ConfigureAwait(false);
|
||||
Track(worker);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogWarning(
|
||||
ex,
|
||||
"School {SchoolId} \"{Name}\" was not started; the save file is unchanged.",
|
||||
save.Id,
|
||||
save.Name);
|
||||
await worker.StopAsync(persist: false).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -350,9 +362,22 @@ internal sealed class GameLoopService(
|
||||
{
|
||||
await Task.WhenAll(stopping).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
if (_workers.Count > 0)
|
||||
{
|
||||
logger.LogInformation("Restored {Count} school(s) from disk.", _workers.Count);
|
||||
}
|
||||
}
|
||||
|
||||
private SchoolWorker SpawnWorker(int id, string name, DateTime time, bool running, int speedIndex, bool isNew) =>
|
||||
private SchoolWorker SpawnWorker(
|
||||
int id,
|
||||
string name,
|
||||
DateTime time,
|
||||
bool running,
|
||||
int speedIndex,
|
||||
bool isNew,
|
||||
IReadOnlyList<string>? modIds,
|
||||
MapLayout? map) =>
|
||||
new(
|
||||
id,
|
||||
name,
|
||||
@@ -360,10 +385,13 @@ internal sealed class GameLoopService(
|
||||
running,
|
||||
speedIndex,
|
||||
isNew,
|
||||
modIds,
|
||||
map,
|
||||
_options,
|
||||
clients,
|
||||
metrics,
|
||||
store,
|
||||
mods,
|
||||
loggerFactory.CreateLogger($"HSchool.Server.Game.SchoolWorker.{id}"));
|
||||
|
||||
private void Track(SchoolWorker worker)
|
||||
|
||||
Reference in New Issue
Block a user