feat(plugins): complete Campaign LA5 cross-host hosting
This commit is contained in:
parent
6c4cd2bbc6
commit
95f4be94db
26 changed files with 1630 additions and 99 deletions
|
|
@ -0,0 +1,19 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<LangVersion>latest</LangVersion>
|
||||
<IsPackable>false</IsPackable>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<!-- The host owns this contract assembly. Keeping it out of the fixture's
|
||||
output is required for IAcDreamPlugin type identity in the collectible
|
||||
load context. -->
|
||||
<ProjectReference Include="..\..\src\AcDream.Plugin.Abstractions\AcDream.Plugin.Abstractions.csproj">
|
||||
<Private>false</Private>
|
||||
<ExcludeAssets>runtime</ExcludeAssets>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
46
tests/AcDream.Plugin.Tests.Fixtures.HostPlugin/HostPlugin.cs
Normal file
46
tests/AcDream.Plugin.Tests.Fixtures.HostPlugin/HostPlugin.cs
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
using AcDream.Plugin.Abstractions;
|
||||
|
||||
namespace AcDream.Plugin.Tests.Fixtures.HostPlugin;
|
||||
|
||||
/// <summary>
|
||||
/// Cross-host LA5 fixture. It deliberately takes the same path on graphical
|
||||
/// and no-window hosts: observe the capability, register UI, and subscribe to
|
||||
/// gameplay events. A headless registry must make the UI call harmless without
|
||||
/// retaining this instance in the default load context.
|
||||
/// </summary>
|
||||
public sealed class HostPlugin : IAcDreamPlugin
|
||||
{
|
||||
private IPluginHost? _host;
|
||||
private int _entitiesSeen;
|
||||
|
||||
public void Initialize(IPluginHost host)
|
||||
{
|
||||
_host = host ?? throw new ArgumentNullException(nameof(host));
|
||||
host.Log.Info($"fixture-initialized:hasUi={host.HasUi}");
|
||||
}
|
||||
|
||||
public void Enable()
|
||||
{
|
||||
IPluginHost host = _host
|
||||
?? throw new InvalidOperationException("The fixture was not initialized.");
|
||||
host.Ui.AddMarkupPanel(
|
||||
Path.Combine(AppContext.BaseDirectory, "fixture-panel.xml"),
|
||||
this);
|
||||
host.Events.EntitySpawned += OnEntitySpawned;
|
||||
host.Log.Info(
|
||||
$"fixture-enabled:hasUi={host.HasUi}:entities={host.State.Entities.Count}");
|
||||
}
|
||||
|
||||
public void Disable()
|
||||
{
|
||||
IPluginHost? host = _host;
|
||||
if (host is null)
|
||||
return;
|
||||
host.Events.EntitySpawned -= OnEntitySpawned;
|
||||
host.Log.Info($"fixture-disabled:entitiesSeen={_entitiesSeen}");
|
||||
_host = null;
|
||||
}
|
||||
|
||||
private void OnEntitySpawned(WorldEntitySnapshot snapshot) =>
|
||||
_entitiesSeen++;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue