feat: add NuGet and Godot distribution
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
#nullable enable
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace ShrinkModFramework;
|
||||
|
||||
public sealed class ShrinkModContext
|
||||
{
|
||||
private readonly Dictionary<Type, object> _services = new();
|
||||
public ShrinkModContext(string modDirectory) => ModDirectory = modDirectory ?? throw new ArgumentNullException(nameof(modDirectory));
|
||||
public string ModDirectory { get; }
|
||||
public void RegisterService<T>(T service) where T : class => _services[typeof(T)] = service ?? throw new ArgumentNullException(nameof(service));
|
||||
public bool TryGetService<T>(out T? service) where T : class
|
||||
{
|
||||
service = _services.TryGetValue(typeof(T), out var value) ? value as T : null;
|
||||
return service != null;
|
||||
}
|
||||
public T GetRequiredService<T>() where T : class => TryGetService<T>(out var value) ? value! : throw new InvalidOperationException($"Service is not registered: {typeof(T).FullName}");
|
||||
}
|
||||
|
||||
public interface IShrinkModUnload
|
||||
{
|
||||
void OnUnload(ShrinkModContext context);
|
||||
}
|
||||
Reference in New Issue
Block a user