feat(linux): add graphical platform services
This commit is contained in:
parent
1628d9f587
commit
66f114b258
28 changed files with 1328 additions and 155 deletions
|
|
@ -1,13 +1,23 @@
|
|||
using AcDream.App;
|
||||
using AcDream.App.Plugins;
|
||||
using AcDream.App.Platform;
|
||||
using AcDream.App.Rendering;
|
||||
using AcDream.Core.Plugins;
|
||||
using AcDream.Runtime.Platform;
|
||||
using Serilog;
|
||||
|
||||
GraphicalHostPlatformServices graphicalPlatform =
|
||||
GraphicalHostPlatformServices.Resolve();
|
||||
ApplicationPathSet applicationPaths = graphicalPlatform.Paths;
|
||||
IReadOnlyList<string> migratedConfigurationFiles =
|
||||
GraphicalLegacyConfigurationMigrator.Migrate(applicationPaths);
|
||||
|
||||
if (args.Length >= 1 && args[0] == "ui-studio")
|
||||
{
|
||||
var so = AcDream.App.Studio.StudioOptions.Parse(args[1..]);
|
||||
using var sw = new AcDream.App.Studio.StudioWindow(so);
|
||||
using var sw = new AcDream.App.Studio.StudioWindow(
|
||||
so,
|
||||
applicationPaths);
|
||||
sw.Run();
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -16,6 +26,20 @@ 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))
|
||||
|
|
@ -36,7 +60,8 @@ using var window = new GameWindow(
|
|||
runtimeOptions,
|
||||
worldGameState,
|
||||
worldEvents,
|
||||
uiRegistry);
|
||||
uiRegistry,
|
||||
graphicalPlatform);
|
||||
var host = new AppPluginHost(
|
||||
new SerilogAdapter(Log.Logger),
|
||||
worldGameState,
|
||||
|
|
@ -44,27 +69,65 @@ var host = new AppPluginHost(
|
|||
window.Selection,
|
||||
uiRegistry);
|
||||
|
||||
var pluginsDir = Path.Combine(AppContext.BaseDirectory, "plugins");
|
||||
Log.Information("scanning plugins in {PluginsDir}", pluginsDir);
|
||||
|
||||
var loaded = new List<LoadedPlugin>();
|
||||
foreach (var result in PluginDiscovery.Scan(pluginsDir))
|
||||
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)
|
||||
{
|
||||
if (!result.Success)
|
||||
Log.Information("scanning plugins in {PluginsDir}", pluginsDir);
|
||||
foreach (var result in PluginDiscovery.Scan(pluginsDir))
|
||||
{
|
||||
Log.Warning("plugin discovery failed for {Dir}: {Error}", result.PluginDirectory, result.Error);
|
||||
continue;
|
||||
}
|
||||
if (!result.Success)
|
||||
{
|
||||
Log.Warning(
|
||||
"plugin discovery failed for {Dir}: {Error}",
|
||||
result.PluginDirectory,
|
||||
result.Error);
|
||||
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;
|
||||
}
|
||||
if (loadedPluginIds.Contains(result.Manifest!.Id))
|
||||
{
|
||||
Log.Warning(
|
||||
"skipping duplicate plugin id {Id} from {Dir}",
|
||||
result.Manifest.Id,
|
||||
result.PluginDirectory);
|
||||
continue;
|
||||
}
|
||||
|
||||
loaded.Add(loadResult);
|
||||
Log.Information("loaded plugin {Id} ({DisplayName})", result.Manifest!.Id, result.Manifest.DisplayName);
|
||||
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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue