Add project files.

This commit is contained in:
Exil Productions
2025-09-08 22:20:20 +02:00
parent a946407117
commit 3e8b70f869
13 changed files with 630 additions and 0 deletions

47
HostApp/Program.cs Normal file
View 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();
}
}
}
}