First consumer of acdream's plugin automation surface, and the first slice of the VTank-class plugin milestone (docs/research/2026-07-29-vtank-plugin-automation-requirements.md). MossTank shows a panel with a Buff button; clicking it casts every self-buff the character is missing, skips what is already in force at an equal or higher tier, and refreshes what is nearly expired. The host/plugin line is the load-bearing decision here. The host publishes spell DATA -- family, tier, difficulty, mana, duration -- plus a cast primitive with a preflight gate. The plugin owns the POLICY. That is the architectural conclusion the requirements research reached: VTank's engine lived in plugin-land, built on Decal's primitives, and baking "best buff for skill X" into the host would start pulling the engine inward one convenience at a time. Why the plan is driven off the spellbook rather than off trained skills, which is the obvious reading of "buff every trained and specialised skill": the client cannot honestly make that mapping. The link between a spell and the stat it modifies arrives from the SERVER in the enchantment message and is absent from the client's own spell table. What the client does know is which spells the character has learned -- and a character only learns buffs for the skills they use, so the spellbook reaches the same set without inventing a mapping the client has no grounds for. Surface added, all BCL-only so Plugin.Abstractions keeps its zero project references: * ICharacterInfo, ISpellCatalog, IMagicCommands, grouped behind one IAutomationSurface so IPluginHost grows by one member rather than three. * IEvents.Tick. Automation is sequences, not single calls -- a buff pass casts several spells and must wait between them. Without a host tick a plugin would need its own timer thread re-entering the host off its update thread. * NoOpAutomationSurface for hosts with no live session, so a plugin keeps one code path and checks IsAvailable. Markup gained <button> and <label>; it previously supported only <meter>, with a comment promising the rest. Buttons bind onclick to an Action property and FAIL THE PANEL LOAD if it does not resolve -- a silently dead button is worse than a panel that refuses to load, because the user clicks and there is nothing to diagnose. Labels bind through a Func so a status line tracks its binding instead of freezing at build time. Enchantment reads use EnchantmentsInEffectSnapshot rather than the raw active set: retail leaves a weaker same-family enchantment in the registry while a stronger one is in force, and a plugin asking "am I buffed?" means in force. BuffPlan is a pure function of (known buffs, active enchantments) precisely so it can be tested without a session; 9 tests cover tier supersede, the family-0 no-stack bucket that must not be de-duplicated, expiry refresh, and plan stability across the rebuilds the tick loop performs. Solution builds clean; 14,421 tests pass on the standard hermetic lane filter, 0 failures. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
201 lines
6.6 KiB
C#
201 lines
6.6 KiB
C#
using AcDream.App;
|
|
using AcDream.App.Configuration;
|
|
using AcDream.App.Credentials;
|
|
using AcDream.App.Plugins;
|
|
using AcDream.App.Platform;
|
|
using AcDream.App.Rendering;
|
|
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}")));
|
|
|
|
// Campaign LA slice LA1: --session-config <path> is purely additive — the
|
|
// existing one positional dat-dir argument and every ACDREAM_* env var keep
|
|
// working exactly as before when the flag is absent. See
|
|
// docs/plans/2026-08-14-launcher-campaign.md LA1.
|
|
//
|
|
// Review fix F5 (LA1 review round): a trailing, valueless --session-config
|
|
// (the flag typed as the LAST argument, nothing after it) must be a hard
|
|
// error, never a silent fall-through to the env-var path — a launcher that
|
|
// mis-composed its argv would otherwise appear to work while quietly
|
|
// ignoring the session-config contract entirely.
|
|
string? sessionConfigFlagPath = SessionConfigArgumentParsing.ExtractFlagValue(
|
|
args, "--session-config", out bool sessionConfigFlagPresent);
|
|
if (sessionConfigFlagPath is null && sessionConfigFlagPresent)
|
|
{
|
|
Log.Error(
|
|
"--session-config requires a value (a path to the session-config document).");
|
|
return 2;
|
|
}
|
|
string[] positionalArgs =
|
|
SessionConfigArgumentParsing.WithoutFlagAndValue(args, "--session-config");
|
|
|
|
var datDirArg = positionalArgs.FirstOrDefault();
|
|
var envDatDir = Environment.GetEnvironmentVariable("ACDREAM_DAT_DIR");
|
|
|
|
// 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.
|
|
RuntimeOptions runtimeOptions;
|
|
if (sessionConfigFlagPath is not null)
|
|
{
|
|
SessionConfiguration sessionConfig;
|
|
SessionDescriptor session;
|
|
try
|
|
{
|
|
(sessionConfig, session) = SessionConfigurationLoader.Load(sessionConfigFlagPath);
|
|
}
|
|
catch (Exception error)
|
|
when (error is IOException
|
|
or UnauthorizedAccessException
|
|
or ArgumentException
|
|
or NotSupportedException
|
|
or System.Text.Json.JsonException
|
|
or SessionConfigurationException)
|
|
{
|
|
Log.Error("--session-config invalid: {Error}", error.Message);
|
|
return 2;
|
|
}
|
|
|
|
string? resolvedDatDir =
|
|
NullIfEmpty(sessionConfig.Process?.Content?.DatDirectory)
|
|
?? NullIfEmpty(datDirArg)
|
|
?? NullIfEmpty(envDatDir);
|
|
if (resolvedDatDir is null)
|
|
{
|
|
Log.Error(
|
|
"usage: AcDream.App <dat-directory> (or set ACDREAM_DAT_DIR, "
|
|
+ "or supply process.content.datDirectory in --session-config)");
|
|
return 2;
|
|
}
|
|
|
|
AppCredentialSecret? secret = null;
|
|
try
|
|
{
|
|
var resolver = new AppCredentialResolver(
|
|
Console.In,
|
|
applicationPaths.ConfigDirectory,
|
|
graphicalPlatform.OperatingSystem
|
|
== GraphicalHostOperatingSystem.Linux);
|
|
secret = resolver.Resolve(session.Id, session.Credential);
|
|
runtimeOptions = RuntimeOptions.FromSessionConfig(
|
|
resolvedDatDir,
|
|
Environment.GetEnvironmentVariable,
|
|
sessionConfigFlagPath,
|
|
sessionConfig,
|
|
session,
|
|
secret.Reveal());
|
|
}
|
|
catch (AppCredentialException error)
|
|
{
|
|
Log.Error("--session-config credential unavailable: {Error}", error.Message);
|
|
return 2;
|
|
}
|
|
finally
|
|
{
|
|
secret?.Dispose();
|
|
}
|
|
|
|
// Env-var flow untouched when the flag is absent; when both are present
|
|
// the flag wins — this line makes that explicit rather than silent.
|
|
Log.Information(
|
|
"--session-config {Path} present; overriding ACDREAM_LIVE*/ACDREAM_TEST_* "
|
|
+ "env-var live-session settings",
|
|
sessionConfigFlagPath);
|
|
}
|
|
else
|
|
{
|
|
var datDir = datDirArg ?? envDatDir;
|
|
if (string.IsNullOrWhiteSpace(datDir))
|
|
{
|
|
Log.Error("usage: AcDream.App <dat-directory> (or set ACDREAM_DAT_DIR)");
|
|
return 2;
|
|
}
|
|
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();
|
|
// Constructed here and handed to both sides: GameWindow binds it to the live
|
|
// session's Runtime owners, the plugin host exposes it to plugins.
|
|
using var automation = new AcDream.App.Plugins.AppAutomationSurface();
|
|
using var window = new GameWindow(
|
|
runtimeOptions,
|
|
worldGameState,
|
|
worldEvents,
|
|
uiRegistry,
|
|
graphicalPlatform,
|
|
automation);
|
|
var host = new AppPluginHost(
|
|
new SerilogAdapter(Log.Logger),
|
|
worldGameState,
|
|
worldEvents,
|
|
window.Selection,
|
|
uiRegistry,
|
|
automation);
|
|
GraphicalPluginSession pluginSession = GraphicalPluginSession.Create(
|
|
applicationPaths,
|
|
runtimeOptions.Plugins,
|
|
runtimeOptions.SessionId ?? "app",
|
|
host,
|
|
window.StatusWriter);
|
|
window.StartPluginHosting(pluginSession);
|
|
|
|
try
|
|
{
|
|
try
|
|
{
|
|
window.Run();
|
|
}
|
|
catch (NotSupportedException error)
|
|
{
|
|
Log.Error("{GraphicalStartupFailure}", error.Message);
|
|
return 4;
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
Log.CloseAndFlush();
|
|
}
|
|
|
|
return 0;
|
|
|
|
// Campaign LA slice LA1: --session-config value-presence helper. The
|
|
// flag/positional-argument extraction itself lives in
|
|
// AcDream.App.Configuration.SessionConfigArgumentParsing (review fix F5) so
|
|
// its trailing-flag edge case is unit testable.
|
|
static string? NullIfEmpty(string? value) =>
|
|
string.IsNullOrWhiteSpace(value) ? null : value;
|