48 lines
1.2 KiB
C#
48 lines
1.2 KiB
C#
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();
|
|
}
|
|
}
|
|
}
|
|
}
|