diff --git a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/IEvents.cs b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/IEvents.cs index 4f98edf13..c65f4051b 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/IEvents.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/IEvents.cs @@ -24,9 +24,7 @@ public interface IEvent : IEvent where T : IEvent { static virtual T GetLuaRunner(IDictionary luaFunc) { - // throw error if not overriden since we don't have 'static abstract'. - // Implementers must provide the runner. - throw new NotImplementedException(); + throw new InvalidOperationException($"Lua runners forbidden for {typeof(T).Name}"); } } @@ -179,7 +177,7 @@ public interface IEventPluginInitialize : IEvent static IEventPluginInitialize IEvent.GetLuaRunner(IDictionary luaFunc) => new { IsLuaRunner = Return.Arguments(() => true), - OnInitialize = ReturnVoid.Arguments(() => luaFunc[nameof(Initialize)]()) + Initialize = ReturnVoid.Arguments(() => luaFunc[nameof(Initialize)]()) }.ActLike(); } diff --git a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Services/Compatibility/ILuaCsHook.cs b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Services/Compatibility/ILuaCsHook.cs index e5a1c7b09..5697a51df 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Services/Compatibility/ILuaCsHook.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Services/Compatibility/ILuaCsHook.cs @@ -4,14 +4,16 @@ namespace Barotrauma.LuaCs.Services.Compatibility; public interface ILuaCsHook : ILuaCsShim { + // Event Services [Obsolete("ACsMod is deprecated. Use ILuaEventService.Add() instead.")] - void Add(string eventName, string identifier, LuaCsFunc callback, ACsMod mod = null); + void Add(string eventName, string identifier, LuaCsFunc callback); [Obsolete("ACsMod is deprecated. Use ILuaEventService.Add() instead.")] - void Add(string eventName, LuaCsFunc callback, ACsMod mod = null); - bool Exists(string eventName, string identifier); - [Obsolete("Only Lua subscribers will receive events from call. Use ILuaEventService.Add() instead.")] - T Call(string eventName, params object[] args); + void Add(string eventName, LuaCsFunc callback); + // Does anyone use this? TODO: Analyze old Lua mods for usage scenarios. + //bool Exists(string eventName, string identifier); object Call(string eventName, params object[] args); + + // Hook/Method Patching string Patch(string identifier, string className, string methodName, string[] parameterTypes, LuaCsPatchFunc patch, EventService.HookMethodType hookType = EventService.HookMethodType.Before); string Patch(string identifier, string className, string methodName, LuaCsPatchFunc patch, EventService.HookMethodType hookType = EventService.HookMethodType.Before); string Patch(string className, string methodName, string[] parameterTypes, LuaCsPatchFunc patch, EventService.HookMethodType hookType = EventService.HookMethodType.Before); diff --git a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Services/Safe/ILuaEventService.cs b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Services/Safe/ILuaEventService.cs index 9a2f0d02b..e5dd9178d 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Services/Safe/ILuaEventService.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Services/Safe/ILuaEventService.cs @@ -7,7 +7,13 @@ namespace Barotrauma.LuaCs.Services.Safe; public interface ILuaSafeEventService : ILuaService, ILuaCsHook { - void Subscribe(string interfaceName, string identifier, IDictionary callbacks); + /// + /// Subscribes lua scripts via for the given interface. + /// + /// + /// + /// A 'method name'=='signature action' dictionary matching the interface method list. + void Subscribe(string identifier, IDictionary callbacks); /// /// Removes a subscriber from an event that subscribed under the given identifier. /// @@ -17,14 +23,24 @@ public interface ILuaSafeEventService : ILuaService, ILuaCsHook /// /// Send an event to all subscribers to an interface. /// - /// Name of the interface (must be registered with Lua). - /// Execution runner, the subscriber is provided as the first argument in the lua runner. + /// Interface type. + /// Execution runner, the subscriber is provided as the first argument in the lua runner. /// - void PublishLuaEvent(string interfaceName, LuaCsFunc runner); + void PublishLuaEvent(LuaCsFunc subscriberRunner); + + /// + /// Defines the target method name for legacy to target on new + /// interfaces. + /// + /// The legacy event name. + /// . + /// The event interface type. + /// Operation success. + /// The is null or empty. + public FluentResults.Result RegisterLuaEventAlias(string luaEventName, string targetMethod) where T : IEvent; } public interface ILuaEventService : ILuaSafeEventService { - public FluentResults.Result RegisterSafeEvent() where T : IEvent; - public FluentResults.Result UnregisterSafeEvent() where T : IEvent; + } diff --git a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Services/_Interfaces/IEventService.cs b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Services/_Interfaces/IEventService.cs index 08d612944..1dc2117d1 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Services/_Interfaces/IEventService.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Services/_Interfaces/IEventService.cs @@ -8,11 +8,6 @@ namespace Barotrauma.LuaCs.Services; public interface IEventService : IReusableService, ILuaEventService { - FluentResults.Result SetLegacyLuaRunnerFactory(Func runnerFactory) where T : IEvent; - void RemoveLegacyLuaRunnerFactory() where T : IEvent; - void SetAliasToEvent(string alias) where T : IEvent; - void RemoveEventAlias(string alias); - void RemoveAllEventAliases() where T : IEvent; /// /// ///