Add project files.
This commit is contained in:
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