Add project files.
This commit is contained in:
11
HostApp/HostApp.csproj
Normal file
11
HostApp/HostApp.csproj
Normal file
@@ -0,0 +1,11 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\AddonLib\AddonLib.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
47
HostApp/Program.cs
Normal file
47
HostApp/Program.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using System.Reflection;
|
||||
using AddonLib;
|
||||
|
||||
namespace HostApp;
|
||||
|
||||
public class HostApi
|
||||
{
|
||||
[AddonCallable]
|
||||
public string Echo(string message) => $"Echo: {message}";
|
||||
|
||||
[AddonAccessible(AddonAccess.ReadWrite)]
|
||||
public int Counter { get; set; }
|
||||
|
||||
[AddonCallback] // event name defaults to method name
|
||||
public void OnTick()
|
||||
{
|
||||
// Raise callback with caller name, no need to specify event name
|
||||
_manager.RaiseAddonCallback();
|
||||
}
|
||||
|
||||
private readonly AddonManager _manager;
|
||||
public HostApi(AddonManager manager) => _manager = manager;
|
||||
}
|
||||
|
||||
internal class Program
|
||||
{
|
||||
private static void Main(string[] args)
|
||||
{
|
||||
// Initialize manager with Plugins folder and autoload
|
||||
var manager = new AddonManager("Plugins", autoInitialize: true);
|
||||
|
||||
// Register host API so addons can call Echo and access Counter
|
||||
var hostApi = new HostApi(manager);
|
||||
manager.RegisterHostApi(hostApi);
|
||||
|
||||
Console.WriteLine("Host initialized. Press T to tick, Q to quit.");
|
||||
while (true)
|
||||
{
|
||||
var key = Console.ReadKey(intercept: true).Key;
|
||||
if (key == ConsoleKey.Q) break;
|
||||
if (key == ConsoleKey.T)
|
||||
{
|
||||
hostApi.OnTick();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user