fix: fail cleanly when game data is missing

This commit is contained in:
capyb2222 committed 2026-09-07 22:19:20 -07:00
1 parent bdfe2a1541
commit 00601b9140
2 files changed
+20 -4

No files matched your search

+6 -3
View File
@@ -134,12 +134,15 @@ public sealed partial class GameData
{ {
log ??= _ => { }; log ??= _ => { };
var roots = sources.Where(Directory.Exists).ToArray(); var wanted = sources.ToArray();
var roots = wanted.Where(Directory.Exists).ToArray();
if (roots.Length == 0) if (roots.Length == 0)
{ {
throw new DirectoryNotFoundException( throw new DirectoryNotFoundException(
"no game data sources found. Clone Dimbreath/turnbasedgamedata and point " + "no game data sources found. Clone Dimbreath/turnbasedgamedata and set Data:Sources " +
"Data:Sources at its ExcelOutput folder."); "in config/config.json to its ExcelOutput folder. Looked in: " +
(wanted.Length > 0 ? string.Join(", ", wanted) : "nowhere, Data:Sources is empty"));
} }
var data = new GameData(roots); var data = new GameData(roots);
+14 -1
View File
@@ -30,7 +30,18 @@ logger.LogInformation("protocol: {Count} commands", ProtocolRegistry.Count);
var handlers = HandlerRegistry.Build(logger); var handlers = HandlerRegistry.Build(logger);
logger.LogInformation("handlers: {Handlers} implemented", handlers.HandlerCount); logger.LogInformation("handlers: {Handlers} implemented", handlers.HandlerCount);
var world = new GameWorld(config, logger); GameWorld world;
try
{
world = new GameWorld(config, logger);
}
catch (DirectoryNotFoundException e)
{
// a fresh clone has no game data yet; say so plainly instead of dumping a stack trace
logger.LogError("{Message}", e.Message);
return 1;
}
var gateway = new KcpGateway( var gateway = new KcpGateway(
config, config,
@@ -46,3 +57,5 @@ Console.CancelKeyPress += (_, e) =>
}; };
await gateway.RunAsync(cancellation.Token); await gateway.RunAsync(cancellation.Token);
return 0;