- Removed ImpromptuInterfaces

This commit is contained in:
MapleWheels
2026-02-12 14:53:33 -05:00
parent ad152ee747
commit 5747d896eb
7 changed files with 165 additions and 82 deletions
@@ -1,19 +1,13 @@
using Barotrauma.Extensions;
using Barotrauma.LuaCs.Events;
using Barotrauma.LuaCs.Compatibility;
using Barotrauma.LuaCs.Events;
using FluentResults;
using FluentResults.LuaCs;
using HarmonyLib;
using Microsoft.Toolkit.Diagnostics;
using MoonSharp.Interpreter;
using OneOf;
using RestSharp;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
namespace Barotrauma.LuaCs;
@@ -189,7 +183,7 @@ public partial class EventService : IEventService
return returnValue;
}
public void Subscribe<T>(string identifier, IDictionary<string, LuaCsFunc> callbacks) where T : IEvent<T>
public void Subscribe<T>(string identifier, IDictionary<string, LuaCsFunc> callbacks) where T : class, IEvent<T>
{
Guard.IsNotNullOrWhiteSpace(identifier, nameof(identifier));
Guard.IsNotNull(callbacks, nameof(callbacks));
@@ -215,12 +209,12 @@ public partial class EventService : IEventService
evtSubscribers.TryRemove(identifier, out _);
}
public void PublishLuaEvent<T>(LuaCsFunc subscriberRunner) where T : IEvent<T>
public void PublishLuaEvent<T>(LuaCsFunc subscriberRunner) where T : class, IEvent<T>
{
this.PublishEvent<T>(sub => subscriberRunner(sub));
}
public FluentResults.Result RegisterLuaEventAlias<T>(string luaEventName, string targetMethod) where T : IEvent<T>
public FluentResults.Result RegisterLuaEventAlias<T>(string luaEventName, string targetMethod) where T : class, IEvent<T>
{
Guard.IsNotNullOrWhiteSpace(luaEventName, nameof(luaEventName));
Guard.IsNotNullOrWhiteSpace(targetMethod, nameof(targetMethod));
@@ -281,7 +275,7 @@ public partial class EventService : IEventService
evtSubscribers.TryRemove(subscriber, out _);
}
public void ClearAllEventSubscribers<T>() where T : IEvent
public void ClearAllEventSubscribers<T>() where T : class, IEvent
{
using var lck = _operationsLock.AcquireWriterLock().ConfigureAwait(false).GetAwaiter().GetResult();
IService.CheckDisposed(this);
@@ -295,7 +289,7 @@ public partial class EventService : IEventService
_subscribers.Clear();
}
public FluentResults.Result PublishEvent<T>(Action<T> action) where T : IEvent<T>
public FluentResults.Result PublishEvent<T>(Action<T> action) where T : class, IEvent<T>
{
Guard.IsNotNull(action, nameof(action));
using var lck = _operationsLock.AcquireReaderLock().ConfigureAwait(false).GetAwaiter().GetResult();
@@ -312,7 +306,7 @@ public partial class EventService : IEventService
{
try
{
action.Invoke((T)sub.Value);
action.Invoke(Unsafe.As<T>(sub.Value));
}
catch (Exception e)
{
@@ -25,7 +25,10 @@ internal class HarmonyEventPatchesService : IService
Harmony.PatchAll(typeof(HarmonyEventPatchesService));
}
// TODO: This causes like hell in Debug.
#if !DEBUG
[HarmonyPatch(typeof(CoroutineManager), nameof(CoroutineManager.Update)), HarmonyPostfix]
#endif
public static void CoroutineManager_Update_Post()
{
_eventService.PublishEvent<IEventUpdate>(x => x.OnUpdate(Timing.TotalTime));
@@ -16,7 +16,6 @@ using Barotrauma.LuaCs.Data;
using Barotrauma.LuaCs.Events;
using FluentResults;
using FluentResults.LuaCs;
using ImpromptuInterface.Build;
using LightInject;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
@@ -25,7 +25,7 @@ public interface IEventService : IReusableService, ILuaEventService
/// Clears all subscribers for a given event type and removes any registration to the type.
/// </summary>
/// <typeparam name="T">The event type.</typeparam>
void ClearAllEventSubscribers<T>() where T : IEvent;
void ClearAllEventSubscribers<T>() where T : class, IEvent;
/// <summary>
/// Clears all subscribers lists.
/// </summary>
@@ -36,5 +36,5 @@ public interface IEventService : IReusableService, ILuaEventService
/// <param name="action"></param>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
FluentResults.Result PublishEvent<T>(Action<T> action) where T : IEvent<T>;
FluentResults.Result PublishEvent<T>(Action<T> action) where T : class, IEvent<T>;
}
@@ -13,7 +13,7 @@ public interface ILuaSafeEventService : ILuaService, ILuaCsHook
/// <typeparam name="T"></typeparam>
/// <param name="identifier"></param>
/// <param name="callbacks">A 'method name'=='signature action' dictionary matching the interface method list.</param>
void Subscribe<T>(string identifier, IDictionary<string, LuaCsFunc> callbacks) where T : IEvent<T>;
void Subscribe<T>(string identifier, IDictionary<string, LuaCsFunc> callbacks) where T : class, IEvent<T>;
/// <summary>
/// Removes a subscriber from an event that subscribed under the given identifier.
/// </summary>
@@ -26,7 +26,7 @@ public interface ILuaSafeEventService : ILuaService, ILuaCsHook
/// <typeparam name="T">Interface type.</typeparam>
/// <param name="subscriberRunner">Execution runner, the subscriber is provided as the first argument in the lua runner.</param>
/// <returns></returns>
void PublishLuaEvent<T>(LuaCsFunc subscriberRunner) where T : IEvent<T>;
void PublishLuaEvent<T>(LuaCsFunc subscriberRunner) where T : class, IEvent<T>;
/// <summary>
/// Defines the target method name for legacy <see cref="ILuaCsHook.Add(string, LuaCsFunc)"/> to target on new <see cref="IEvent{T}"/>
@@ -37,7 +37,7 @@ public interface ILuaSafeEventService : ILuaService, ILuaCsHook
/// <typeparam name="T">The event interface type.</typeparam>
/// <returns>Operation success.</returns>
/// <exception cref="ArgumentNullException">The <see cref="luaEventName"/> is <b>null or empty.</b></exception>
public FluentResults.Result RegisterLuaEventAlias<T>(string luaEventName, string targetMethod) where T : IEvent<T>;
public FluentResults.Result RegisterLuaEventAlias<T>(string luaEventName, string targetMethod) where T : class, IEvent<T>;
}
public interface ILuaEventService : ILuaSafeEventService