The launcher (LA3/LA4) needs the XDG/Windows path contract (ApplicationPathSet/IApplicationPathEnvironment) without pulling in any gameplay assembly. Move it out of AcDream.Runtime into a new BCL-only AcDream.Platform project so the launcher-side Launcher.Core project can reference it directly per the campaign plan (docs/plans/2026-08-14-launcher-campaign.md, LA0). Namespace renamed AcDream.Runtime.Platform -> AcDream.Platform; code is otherwise byte-identical (no logic changes). AcDream.Runtime now carries a ProjectReference to AcDream.Platform and re-exports it transitively, so App and Headless keep resolving the type without a direct reference and K0's Headless single-ProjectReference guard (HeadlessAssemblyReferencesOnlyTheRuntimeProject) stands unchanged. The sibling Runtime dependency-boundary guard (RuntimeProjectDeclaresOnlyApprovedProjectDependencies) does assert Runtime's own project-reference set, so it needed a deliberate, documented addition of AcDream.Platform to its expected list. Moved tests/AcDream.Runtime.Tests/Platform/ApplicationPathSetTests.cs to a new tests/AcDream.Platform.Tests/ project (namespace AcDream.Platform.Tests) referencing only AcDream.Platform. Registered both new projects in AcDream.slnx. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
160 lines
4.6 KiB
C#
160 lines
4.6 KiB
C#
using AcDream.App;
|
|
using AcDream.App.Plugins;
|
|
using AcDream.App.Platform;
|
|
using AcDream.App.Rendering;
|
|
using AcDream.Core.Plugins;
|
|
using AcDream.Platform;
|
|
using Serilog;
|
|
|
|
GraphicalHostPlatformServices graphicalPlatform =
|
|
GraphicalHostPlatformServices.Resolve();
|
|
graphicalPlatform.ConfigureWindowBackend();
|
|
ApplicationPathSet applicationPaths = graphicalPlatform.Paths;
|
|
IReadOnlyList<string> migratedConfigurationFiles =
|
|
GraphicalLegacyConfigurationMigrator.Migrate(applicationPaths);
|
|
|
|
Log.Logger = new LoggerConfiguration()
|
|
.MinimumLevel.Debug()
|
|
.WriteTo.Console()
|
|
.CreateLogger();
|
|
foreach (string migratedConfigurationFile in migratedConfigurationFiles)
|
|
{
|
|
Log.Information(
|
|
"migrated legacy graphical configuration to {Path}",
|
|
migratedConfigurationFile);
|
|
}
|
|
Log.Information(
|
|
"graphical platform {RuntimeIdentifier}; native closure: {NativeDependencies}",
|
|
graphicalPlatform.RuntimeIdentifier,
|
|
string.Join(
|
|
", ",
|
|
graphicalPlatform.NativeDependencies.Select(
|
|
dependency =>
|
|
$"{dependency.Feature}={dependency.PublishedFileName}")));
|
|
|
|
var datDir = args.FirstOrDefault() ?? Environment.GetEnvironmentVariable("ACDREAM_DAT_DIR");
|
|
if (string.IsNullOrWhiteSpace(datDir))
|
|
{
|
|
Log.Error("usage: AcDream.App <dat-directory> (or set ACDREAM_DAT_DIR)");
|
|
return 2;
|
|
}
|
|
|
|
// Single read of the startup-time process environment. Every downstream
|
|
// consumer (GameWindow + collaborators) reads the typed bundle, not the
|
|
// raw env vars. See docs/architecture/code-structure.md §2 Rule 4.
|
|
var runtimeOptions = RuntimeOptions.FromEnvironment(datDir);
|
|
|
|
if (runtimeOptions.DevTools)
|
|
{
|
|
Log.Information(
|
|
"ACDREAM_DEVTOOLS=1: the ImGui developer UI was removed at Campaign V " +
|
|
"slice V11 along with the OpenGL backend it required; this flag now " +
|
|
"only selects the optional Vulkan validation/debug-utils extensions.");
|
|
}
|
|
|
|
var worldGameState = new AcDream.Core.Plugins.WorldGameState();
|
|
var worldEvents = new AcDream.Core.Plugins.WorldEvents();
|
|
var uiRegistry = new AcDream.App.Plugins.BufferedUiRegistry();
|
|
using var window = new GameWindow(
|
|
runtimeOptions,
|
|
worldGameState,
|
|
worldEvents,
|
|
uiRegistry,
|
|
graphicalPlatform);
|
|
var host = new AppPluginHost(
|
|
new SerilogAdapter(Log.Logger),
|
|
worldGameState,
|
|
worldEvents,
|
|
window.Selection,
|
|
uiRegistry);
|
|
|
|
var loaded = new List<LoadedPlugin>();
|
|
var loadedPluginIds = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
|
|
StringComparer pathComparer =
|
|
graphicalPlatform.OperatingSystem
|
|
== GraphicalHostOperatingSystem.Windows
|
|
? StringComparer.OrdinalIgnoreCase
|
|
: StringComparer.Ordinal;
|
|
string[] pluginRoots =
|
|
[
|
|
.. new[]
|
|
{
|
|
Path.Combine(AppContext.BaseDirectory, "plugins"),
|
|
applicationPaths.PluginsDirectory,
|
|
}.Distinct(pathComparer),
|
|
];
|
|
|
|
foreach (string pluginsDir in pluginRoots)
|
|
{
|
|
Log.Information("scanning plugins in {PluginsDir}", pluginsDir);
|
|
foreach (var result in PluginDiscovery.Scan(pluginsDir))
|
|
{
|
|
if (!result.Success)
|
|
{
|
|
Log.Warning(
|
|
"plugin discovery failed for {Dir}: {Error}",
|
|
result.PluginDirectory,
|
|
result.Error);
|
|
continue;
|
|
}
|
|
|
|
if (loadedPluginIds.Contains(result.Manifest!.Id))
|
|
{
|
|
Log.Warning(
|
|
"skipping duplicate plugin id {Id} from {Dir}",
|
|
result.Manifest.Id,
|
|
result.PluginDirectory);
|
|
continue;
|
|
}
|
|
|
|
var loadResult = PluginLoader.Load(
|
|
result.PluginDirectory,
|
|
result.Manifest,
|
|
host);
|
|
if (!loadResult.Success)
|
|
{
|
|
Log.Warning(
|
|
"plugin load failed for {Id}: {Error}",
|
|
result.Manifest.Id,
|
|
loadResult.Error);
|
|
continue;
|
|
}
|
|
|
|
loadedPluginIds.Add(result.Manifest.Id);
|
|
loaded.Add(loadResult);
|
|
Log.Information(
|
|
"loaded plugin {Id} ({DisplayName})",
|
|
result.Manifest.Id,
|
|
result.Manifest.DisplayName);
|
|
}
|
|
}
|
|
|
|
try
|
|
{
|
|
foreach (var plugin in loaded)
|
|
{
|
|
try { plugin.Plugin!.Enable(); }
|
|
catch (Exception ex) { Log.Error(ex, "plugin enable failed: {Id}", plugin.Manifest.Id); }
|
|
}
|
|
|
|
try
|
|
{
|
|
window.Run();
|
|
}
|
|
catch (NotSupportedException error)
|
|
{
|
|
Log.Error("{GraphicalStartupFailure}", error.Message);
|
|
return 4;
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
foreach (var plugin in loaded)
|
|
{
|
|
try { plugin.Plugin!.Disable(); }
|
|
catch (Exception ex) { Log.Error(ex, "plugin disable failed: {Id}", plugin.Manifest.Id); }
|
|
}
|
|
Log.CloseAndFlush();
|
|
}
|
|
|
|
return 0;
|