- Removed ImpromptuInterfaces
This commit is contained in:
@@ -8,7 +8,6 @@
|
|||||||
<PackageReference Include="OneOf" Version="3.0.271" />
|
<PackageReference Include="OneOf" Version="3.0.271" />
|
||||||
<PackageReference Include="FluentResults" Version="3.16.0" />
|
<PackageReference Include="FluentResults" Version="3.16.0" />
|
||||||
<PackageReference Include="Basic.Reference.Assemblies.Net80" Version="1.8.4" />
|
<PackageReference Include="Basic.Reference.Assemblies.Net80" Version="1.8.4" />
|
||||||
<PackageReference Include="ImpromptuInterface " Version="8.0.6" />
|
|
||||||
<PackageReference Include="Microsoft.Toolkit.Diagnostics" Version="7.1.2"/>
|
<PackageReference Include="Microsoft.Toolkit.Diagnostics" Version="7.1.2"/>
|
||||||
<ProjectReference Include="$(MSBuildThisFileDirectory)..\..\Libraries\moonsharp\MoonSharp.Interpreter\MoonSharp.Interpreter.csproj" />
|
<ProjectReference Include="$(MSBuildThisFileDirectory)..\..\Libraries\moonsharp\MoonSharp.Interpreter\MoonSharp.Interpreter.csproj" />
|
||||||
<ProjectReference Include="$(MSBuildThisFileDirectory)..\..\Libraries\moonsharp\MoonSharp.VsCodeDebugger\MoonSharp.VsCodeDebugger.csproj" />
|
<ProjectReference Include="$(MSBuildThisFileDirectory)..\..\Libraries\moonsharp\MoonSharp.VsCodeDebugger\MoonSharp.VsCodeDebugger.csproj" />
|
||||||
|
|||||||
@@ -1,12 +1,8 @@
|
|||||||
using System.Runtime.CompilerServices;
|
using System;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using Barotrauma.LuaCs.Data;
|
using Barotrauma.LuaCs.Data;
|
||||||
using Barotrauma.LuaCs;
|
|
||||||
using Barotrauma.Networking;
|
using Barotrauma.Networking;
|
||||||
using Dynamitey;
|
|
||||||
using ImpromptuInterface;
|
|
||||||
|
|
||||||
namespace Barotrauma.LuaCs.Events;
|
namespace Barotrauma.LuaCs.Events;
|
||||||
|
|
||||||
@@ -19,9 +15,16 @@ namespace Barotrauma.LuaCs.Events;
|
|||||||
public interface IEvent
|
public interface IEvent
|
||||||
{
|
{
|
||||||
bool IsLuaRunner() => false;
|
bool IsLuaRunner() => false;
|
||||||
|
|
||||||
|
public abstract class LuaWrapperBase : IEvent
|
||||||
|
{
|
||||||
|
protected readonly IDictionary<string, LuaCsFunc> LuaFuncs;
|
||||||
|
protected LuaWrapperBase(IDictionary<string, LuaCsFunc> luaFuncs) => LuaFuncs = luaFuncs;
|
||||||
|
public bool IsLuaRunner() => true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface IEvent<out T> : IEvent where T : IEvent<T>
|
public interface IEvent<out T> : IEvent where T : class, IEvent<T>
|
||||||
{
|
{
|
||||||
static virtual T GetLuaRunner(IDictionary<string, LuaCsFunc> luaFunc)
|
static virtual T GetLuaRunner(IDictionary<string, LuaCsFunc> luaFunc)
|
||||||
{
|
{
|
||||||
@@ -73,33 +76,64 @@ internal interface IEventSettingInstanceLifetime : IEvent<IEventSettingInstanceL
|
|||||||
internal interface IEventAfflictionUpdate : IEvent<IEventAfflictionUpdate>
|
internal interface IEventAfflictionUpdate : IEvent<IEventAfflictionUpdate>
|
||||||
{
|
{
|
||||||
void OnAfflictionUpdate(Affliction affliction, CharacterHealth characterHealth, Limb targetLimb, float deltaTime);
|
void OnAfflictionUpdate(Affliction affliction, CharacterHealth characterHealth, Limb targetLimb, float deltaTime);
|
||||||
static IEventAfflictionUpdate IEvent<IEventAfflictionUpdate>.GetLuaRunner(IDictionary<string, LuaCsFunc> luaFunc) => new
|
|
||||||
|
static IEventAfflictionUpdate IEvent<IEventAfflictionUpdate>.GetLuaRunner(IDictionary<string, LuaCsFunc> luaFunc) =>
|
||||||
|
new LuaWrapper(luaFunc);
|
||||||
|
|
||||||
|
public sealed class LuaWrapper : LuaWrapperBase, IEventAfflictionUpdate
|
||||||
{
|
{
|
||||||
IsLuaRunner = Return<bool>.Arguments(() => true),
|
public LuaWrapper(IDictionary<string, LuaCsFunc> luaFuncs) : base(luaFuncs)
|
||||||
OnAfflictionUpdate = ReturnVoid.Arguments((Affliction affliction, CharacterHealth characterHealth, Limb targetLimb, float deltaTime) => luaFunc[nameof(OnAfflictionUpdate)](affliction, characterHealth, targetLimb, deltaTime))
|
{
|
||||||
}.ActLike<IEventAfflictionUpdate>();
|
}
|
||||||
|
|
||||||
|
public void OnAfflictionUpdate(Affliction affliction, CharacterHealth characterHealth, Limb targetLimb, float deltaTime)
|
||||||
|
{
|
||||||
|
LuaFuncs[nameof(OnAfflictionUpdate)](affliction, characterHealth, targetLimb, deltaTime);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal interface IEventGiveCharacterJobItems : IEvent<IEventGiveCharacterJobItems>
|
internal interface IEventGiveCharacterJobItems : IEvent<IEventGiveCharacterJobItems>
|
||||||
{
|
{
|
||||||
void OnGiveCharacterJobItems(Character character, WayPoint spawnPoint, bool isPvPMode);
|
void OnGiveCharacterJobItems(Character character, WayPoint spawnPoint, bool isPvPMode);
|
||||||
static IEventGiveCharacterJobItems IEvent<IEventGiveCharacterJobItems>.GetLuaRunner(IDictionary<string, LuaCsFunc> luaFunc) => new
|
|
||||||
|
static IEventGiveCharacterJobItems IEvent<IEventGiveCharacterJobItems>.GetLuaRunner(
|
||||||
|
IDictionary<string, LuaCsFunc> luaFunc) => new LuaWrapper(luaFunc);
|
||||||
|
|
||||||
|
public sealed class LuaWrapper : LuaWrapperBase, IEventGiveCharacterJobItems
|
||||||
{
|
{
|
||||||
IsLuaRunner = Return<bool>.Arguments(() => true),
|
public LuaWrapper(IDictionary<string, LuaCsFunc> luaFuncs) : base(luaFuncs)
|
||||||
OnGiveCharacterJobItems = ReturnVoid.Arguments((Character character, WayPoint spawnPoint, bool isPvPMode) => luaFunc[nameof(OnGiveCharacterJobItems)](character, spawnPoint, isPvPMode))
|
{
|
||||||
}.ActLike<IEventGiveCharacterJobItems>();
|
}
|
||||||
|
|
||||||
|
public void OnGiveCharacterJobItems(Character character, WayPoint spawnPoint, bool isPvPMode)
|
||||||
|
{
|
||||||
|
LuaFuncs[nameof(OnGiveCharacterJobItems)](character, spawnPoint, isPvPMode);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal interface IEventCharacterCreated : IEvent<IEventCharacterCreated>
|
internal interface IEventCharacterCreated : IEvent<IEventCharacterCreated>
|
||||||
{
|
{
|
||||||
void OnCharacterCreated(Character character);
|
void OnCharacterCreated(Character character);
|
||||||
static IEventCharacterCreated IEvent<IEventCharacterCreated>.GetLuaRunner(IDictionary<string, LuaCsFunc> luaFunc) => new
|
|
||||||
|
static IEventCharacterCreated IEvent<IEventCharacterCreated>.GetLuaRunner(IDictionary<string, LuaCsFunc> luaFunc)
|
||||||
|
=> new LuaWrapper(luaFunc);
|
||||||
|
|
||||||
|
public sealed class LuaWrapper : LuaWrapperBase, IEventCharacterCreated
|
||||||
{
|
{
|
||||||
IsLuaRunner = Return<bool>.Arguments(() => true),
|
public LuaWrapper(IDictionary<string, LuaCsFunc> luaFuncs) : base(luaFuncs)
|
||||||
OnCharacterCreated = ReturnVoid.Arguments((Character character) => luaFunc[nameof(OnCharacterCreated)](character))
|
{
|
||||||
}.ActLike<IEventCharacterCreated>();
|
}
|
||||||
|
|
||||||
|
public void OnCharacterCreated(Character character)
|
||||||
|
{
|
||||||
|
LuaFuncs[nameof(OnCharacterCreated)](character);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
internal interface IEventHumanCPRFailed : IEvent<IEventHumanCPRFailed>
|
internal interface IEventHumanCPRFailed : IEvent<IEventHumanCPRFailed>
|
||||||
{
|
{
|
||||||
@@ -126,11 +160,21 @@ internal interface IEventHumanCPRSuccess : IEvent<IEventHumanCPRSuccess>
|
|||||||
public interface IEventKeyUpdate : IEvent<IEventKeyUpdate>
|
public interface IEventKeyUpdate : IEvent<IEventKeyUpdate>
|
||||||
{
|
{
|
||||||
void OnKeyUpdate(double deltaTime);
|
void OnKeyUpdate(double deltaTime);
|
||||||
static IEventKeyUpdate IEvent<IEventKeyUpdate>.GetLuaRunner(IDictionary<string, LuaCsFunc> luaFunc) => new
|
|
||||||
|
static IEventKeyUpdate IEvent<IEventKeyUpdate>.GetLuaRunner(IDictionary<string, LuaCsFunc> luaFunc)
|
||||||
|
=> new LuaWrapper(luaFunc);
|
||||||
|
|
||||||
|
public sealed class LuaWrapper : LuaWrapperBase, IEventKeyUpdate
|
||||||
{
|
{
|
||||||
IsLuaRunner = Return<bool>.Arguments(() => true),
|
public LuaWrapper(IDictionary<string, LuaCsFunc> luaFuncs) : base(luaFuncs)
|
||||||
OnKeyUpdate = ReturnVoid.Arguments((double deltaTime) => luaFunc[nameof(OnKeyUpdate)](deltaTime))
|
{
|
||||||
}.ActLike<IEventKeyUpdate>();
|
}
|
||||||
|
|
||||||
|
public void OnKeyUpdate(double deltaTime)
|
||||||
|
{
|
||||||
|
LuaFuncs[nameof(OnKeyUpdate)](deltaTime);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -139,11 +183,21 @@ public interface IEventKeyUpdate : IEvent<IEventKeyUpdate>
|
|||||||
public interface IEventRoundStarting : IEvent<IEventRoundStarting>
|
public interface IEventRoundStarting : IEvent<IEventRoundStarting>
|
||||||
{
|
{
|
||||||
void OnRoundStarting();
|
void OnRoundStarting();
|
||||||
static IEventRoundStarting IEvent<IEventRoundStarting>.GetLuaRunner(IDictionary<string, LuaCsFunc> luaFunc) => new
|
|
||||||
|
static IEventRoundStarting IEvent<IEventRoundStarting>.GetLuaRunner(IDictionary<string, LuaCsFunc> luaFunc)
|
||||||
|
=> new LuaWrapper(luaFunc);
|
||||||
|
|
||||||
|
public sealed class LuaWrapper : LuaWrapperBase, IEventRoundStarting
|
||||||
{
|
{
|
||||||
IsLuaRunner = Return<bool>.Arguments(() => true),
|
public LuaWrapper(IDictionary<string, LuaCsFunc> luaFuncs) : base(luaFuncs)
|
||||||
OnRoundStarting = ReturnVoid.Arguments(() => luaFunc[nameof(OnRoundStarting)]())
|
{
|
||||||
}.ActLike<IEventRoundStarting>();
|
}
|
||||||
|
|
||||||
|
public void OnRoundStarting()
|
||||||
|
{
|
||||||
|
LuaFuncs[nameof(OnRoundStarting)]();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -152,11 +206,21 @@ public interface IEventRoundStarting : IEvent<IEventRoundStarting>
|
|||||||
public interface IEventRoundStarted : IEvent<IEventRoundStarted>
|
public interface IEventRoundStarted : IEvent<IEventRoundStarted>
|
||||||
{
|
{
|
||||||
void OnRoundStart();
|
void OnRoundStart();
|
||||||
static IEventRoundStarted IEvent<IEventRoundStarted>.GetLuaRunner(IDictionary<string, LuaCsFunc> luaFunc) => new
|
|
||||||
|
static IEventRoundStarted IEvent<IEventRoundStarted>.GetLuaRunner(IDictionary<string, LuaCsFunc> luaFunc)
|
||||||
|
=> new LuaWrapper(luaFunc);
|
||||||
|
|
||||||
|
public sealed class LuaWrapper : LuaWrapperBase, IEventRoundStarted
|
||||||
{
|
{
|
||||||
IsLuaRunner = Return<bool>.Arguments(() => true),
|
public LuaWrapper(IDictionary<string, LuaCsFunc> luaFuncs) : base(luaFuncs)
|
||||||
OnRoundStart = ReturnVoid.Arguments(() => luaFunc[nameof(OnRoundStart)]())
|
{
|
||||||
}.ActLike<IEventRoundStarted>();
|
}
|
||||||
|
|
||||||
|
public void OnRoundStart()
|
||||||
|
{
|
||||||
|
LuaFuncs[nameof(OnRoundStart)]();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -165,11 +229,20 @@ public interface IEventRoundStarted : IEvent<IEventRoundStarted>
|
|||||||
public interface IEventUpdate : IEvent<IEventUpdate>
|
public interface IEventUpdate : IEvent<IEventUpdate>
|
||||||
{
|
{
|
||||||
void OnUpdate(double fixedDeltaTime);
|
void OnUpdate(double fixedDeltaTime);
|
||||||
static IEventUpdate IEvent<IEventUpdate>.GetLuaRunner(IDictionary<string, LuaCsFunc> luaFunc) => new
|
static IEventUpdate IEvent<IEventUpdate>.GetLuaRunner(IDictionary<string, LuaCsFunc> luaFunc)
|
||||||
|
=> new LuaWrapper(luaFunc);
|
||||||
|
|
||||||
|
public sealed class LuaWrapper : LuaWrapperBase, IEventUpdate
|
||||||
{
|
{
|
||||||
IsLuaRunner = Return<bool>.Arguments(() => true),
|
public LuaWrapper(IDictionary<string, LuaCsFunc> luaFuncs) : base(luaFuncs)
|
||||||
OnUpdate = ReturnVoid.Arguments<double>((fixedDeltaTime) => luaFunc[nameof(OnUpdate)](fixedDeltaTime))
|
{
|
||||||
}.ActLike<IEventUpdate>();
|
}
|
||||||
|
|
||||||
|
public void OnUpdate(double deltaTime)
|
||||||
|
{
|
||||||
|
LuaFuncs[nameof(OnUpdate)](deltaTime);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -178,11 +251,21 @@ public interface IEventUpdate : IEvent<IEventUpdate>
|
|||||||
public interface IEventDrawUpdate : IEvent<IEventDrawUpdate>
|
public interface IEventDrawUpdate : IEvent<IEventDrawUpdate>
|
||||||
{
|
{
|
||||||
void OnDrawUpdate(double deltaTime);
|
void OnDrawUpdate(double deltaTime);
|
||||||
static IEventDrawUpdate IEvent<IEventDrawUpdate>.GetLuaRunner(IDictionary<string, LuaCsFunc> luaFunc) => new
|
|
||||||
|
static IEventDrawUpdate IEvent<IEventDrawUpdate>.GetLuaRunner(IDictionary<string, LuaCsFunc> luaFunc)
|
||||||
|
=> new LuaWrapper(luaFunc);
|
||||||
|
|
||||||
|
public sealed class LuaWrapper : LuaWrapperBase, IEventDrawUpdate
|
||||||
{
|
{
|
||||||
IsLuaRunner = Return<bool>.Arguments(() => true),
|
public LuaWrapper(IDictionary<string, LuaCsFunc> luaFuncs) : base(luaFuncs)
|
||||||
OnDrawUpdate = ReturnVoid.Arguments<double>((deltaTime) => luaFunc[nameof(OnDrawUpdate)](deltaTime))
|
{
|
||||||
}.ActLike<IEventDrawUpdate>();
|
}
|
||||||
|
|
||||||
|
public void OnDrawUpdate(double deltaTime)
|
||||||
|
{
|
||||||
|
LuaFuncs[nameof(OnDrawUpdate)](deltaTime);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@@ -206,11 +289,21 @@ interface IEventClientConnected : IEvent<IEventClientConnected>
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="client">The connecting client.</param>
|
/// <param name="client">The connecting client.</param>
|
||||||
void OnClientConnected(Client client);
|
void OnClientConnected(Client client);
|
||||||
static IEventClientConnected IEvent<IEventClientConnected>.GetLuaRunner(IDictionary<string, LuaCsFunc> luaFunc) => new
|
|
||||||
|
static IEventClientConnected IEvent<IEventClientConnected>.GetLuaRunner(IDictionary<string, LuaCsFunc> luaFunc)
|
||||||
|
=> new LuaWrapper(luaFunc);
|
||||||
|
|
||||||
|
public sealed class LuaWrapper : LuaWrapperBase, IEventClientConnected
|
||||||
{
|
{
|
||||||
IsLuaRunner = Return<bool>.Arguments(() => true),
|
public LuaWrapper(IDictionary<string, LuaCsFunc> luaFuncs) : base(luaFuncs)
|
||||||
OnClientConnected = ReturnVoid.Arguments<Client>((client) => luaFunc[nameof(OnClientConnected)](client))
|
{
|
||||||
}.ActLike<IEventClientConnected>();
|
}
|
||||||
|
|
||||||
|
public void OnClientConnected(Client client)
|
||||||
|
{
|
||||||
|
LuaFuncs[nameof(OnClientConnected)](client);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -230,11 +323,21 @@ public interface IEventServerRawNetMessageReceived : IEvent<IEventServerRawNetMe
|
|||||||
public interface IEventServerConnected : IEvent<IEventServerConnected>
|
public interface IEventServerConnected : IEvent<IEventServerConnected>
|
||||||
{
|
{
|
||||||
void OnServerConnected();
|
void OnServerConnected();
|
||||||
static IEventServerConnected IEvent<IEventServerConnected>.GetLuaRunner(IDictionary<string, LuaCsFunc> luaFunc) => new
|
|
||||||
|
static IEventServerConnected IEvent<IEventServerConnected>.GetLuaRunner(IDictionary<string, LuaCsFunc> luaFunc)
|
||||||
|
=> new LuaWrapper(luaFunc);
|
||||||
|
|
||||||
|
public sealed class LuaWrapper : LuaWrapperBase, IEventServerConnected
|
||||||
{
|
{
|
||||||
IsLuaRunner = Return<bool>.Arguments(() => true),
|
public LuaWrapper(IDictionary<string, LuaCsFunc> luaFuncs) : base(luaFuncs)
|
||||||
OnServerConnected = ReturnVoid.Arguments(() => luaFunc[nameof(OnServerConnected)]())
|
{
|
||||||
}.ActLike<IEventServerConnected>();
|
}
|
||||||
|
|
||||||
|
public void OnServerConnected()
|
||||||
|
{
|
||||||
|
LuaFuncs[nameof(OnServerConnected)]();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#endregion
|
#endregion
|
||||||
@@ -249,11 +352,6 @@ public interface IEventServerConnected : IEvent<IEventServerConnected>
|
|||||||
public interface IEventPluginInitialize : IEvent<IEventPluginInitialize>
|
public interface IEventPluginInitialize : IEvent<IEventPluginInitialize>
|
||||||
{
|
{
|
||||||
void Initialize();
|
void Initialize();
|
||||||
static IEventPluginInitialize IEvent<IEventPluginInitialize>.GetLuaRunner(IDictionary<string, LuaCsFunc> luaFunc) => new
|
|
||||||
{
|
|
||||||
IsLuaRunner = Return<bool>.Arguments(() => true),
|
|
||||||
Initialize = ReturnVoid.Arguments(() => luaFunc[nameof(Initialize)]())
|
|
||||||
}.ActLike<IEventPluginInitialize>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -262,11 +360,6 @@ public interface IEventPluginInitialize : IEvent<IEventPluginInitialize>
|
|||||||
public interface IEventPluginLoadCompleted : IEvent<IEventPluginLoadCompleted>
|
public interface IEventPluginLoadCompleted : IEvent<IEventPluginLoadCompleted>
|
||||||
{
|
{
|
||||||
void OnLoadCompleted();
|
void OnLoadCompleted();
|
||||||
static IEventPluginLoadCompleted IEvent<IEventPluginLoadCompleted>.GetLuaRunner(IDictionary<string, LuaCsFunc> luaFunc) => new
|
|
||||||
{
|
|
||||||
IsLuaRunner = Return<bool>.Arguments(() => true),
|
|
||||||
OnLoadCompleted = ReturnVoid.Arguments(() => luaFunc[nameof(OnLoadCompleted)]())
|
|
||||||
}.ActLike<IEventPluginLoadCompleted>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -276,11 +369,6 @@ public interface IEventPluginLoadCompleted : IEvent<IEventPluginLoadCompleted>
|
|||||||
public interface IEventPluginPreInitialize : IEvent<IEventPluginPreInitialize>
|
public interface IEventPluginPreInitialize : IEvent<IEventPluginPreInitialize>
|
||||||
{
|
{
|
||||||
void PreInitPatching();
|
void PreInitPatching();
|
||||||
static IEventPluginPreInitialize IEvent<IEventPluginPreInitialize>.GetLuaRunner(IDictionary<string, LuaCsFunc> luaFunc) => new
|
|
||||||
{
|
|
||||||
IsLuaRunner = Return<bool>.Arguments(() => true),
|
|
||||||
OnPreInitialize = ReturnVoid.Arguments(() => luaFunc[nameof(PreInitPatching)]())
|
|
||||||
}.ActLike<IEventPluginPreInitialize>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -1,19 +1,13 @@
|
|||||||
using Barotrauma.Extensions;
|
using Barotrauma.LuaCs.Events;
|
||||||
using Barotrauma.LuaCs.Events;
|
|
||||||
using Barotrauma.LuaCs.Compatibility;
|
|
||||||
using FluentResults;
|
using FluentResults;
|
||||||
using FluentResults.LuaCs;
|
|
||||||
using HarmonyLib;
|
|
||||||
using Microsoft.Toolkit.Diagnostics;
|
using Microsoft.Toolkit.Diagnostics;
|
||||||
using MoonSharp.Interpreter;
|
using MoonSharp.Interpreter;
|
||||||
using OneOf;
|
using OneOf;
|
||||||
using RestSharp;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Immutable;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
|
||||||
namespace Barotrauma.LuaCs;
|
namespace Barotrauma.LuaCs;
|
||||||
|
|
||||||
@@ -189,7 +183,7 @@ public partial class EventService : IEventService
|
|||||||
return returnValue;
|
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.IsNotNullOrWhiteSpace(identifier, nameof(identifier));
|
||||||
Guard.IsNotNull(callbacks, nameof(callbacks));
|
Guard.IsNotNull(callbacks, nameof(callbacks));
|
||||||
@@ -215,12 +209,12 @@ public partial class EventService : IEventService
|
|||||||
evtSubscribers.TryRemove(identifier, out _);
|
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));
|
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(luaEventName, nameof(luaEventName));
|
||||||
Guard.IsNotNullOrWhiteSpace(targetMethod, nameof(targetMethod));
|
Guard.IsNotNullOrWhiteSpace(targetMethod, nameof(targetMethod));
|
||||||
@@ -281,7 +275,7 @@ public partial class EventService : IEventService
|
|||||||
evtSubscribers.TryRemove(subscriber, out _);
|
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();
|
using var lck = _operationsLock.AcquireWriterLock().ConfigureAwait(false).GetAwaiter().GetResult();
|
||||||
IService.CheckDisposed(this);
|
IService.CheckDisposed(this);
|
||||||
@@ -295,7 +289,7 @@ public partial class EventService : IEventService
|
|||||||
_subscribers.Clear();
|
_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));
|
Guard.IsNotNull(action, nameof(action));
|
||||||
using var lck = _operationsLock.AcquireReaderLock().ConfigureAwait(false).GetAwaiter().GetResult();
|
using var lck = _operationsLock.AcquireReaderLock().ConfigureAwait(false).GetAwaiter().GetResult();
|
||||||
@@ -312,7 +306,7 @@ public partial class EventService : IEventService
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
action.Invoke((T)sub.Value);
|
action.Invoke(Unsafe.As<T>(sub.Value));
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -25,7 +25,10 @@ internal class HarmonyEventPatchesService : IService
|
|||||||
Harmony.PatchAll(typeof(HarmonyEventPatchesService));
|
Harmony.PatchAll(typeof(HarmonyEventPatchesService));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: This causes like hell in Debug.
|
||||||
|
#if !DEBUG
|
||||||
[HarmonyPatch(typeof(CoroutineManager), nameof(CoroutineManager.Update)), HarmonyPostfix]
|
[HarmonyPatch(typeof(CoroutineManager), nameof(CoroutineManager.Update)), HarmonyPostfix]
|
||||||
|
#endif
|
||||||
public static void CoroutineManager_Update_Post()
|
public static void CoroutineManager_Update_Post()
|
||||||
{
|
{
|
||||||
_eventService.PublishEvent<IEventUpdate>(x => x.OnUpdate(Timing.TotalTime));
|
_eventService.PublishEvent<IEventUpdate>(x => x.OnUpdate(Timing.TotalTime));
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ using Barotrauma.LuaCs.Data;
|
|||||||
using Barotrauma.LuaCs.Events;
|
using Barotrauma.LuaCs.Events;
|
||||||
using FluentResults;
|
using FluentResults;
|
||||||
using FluentResults.LuaCs;
|
using FluentResults.LuaCs;
|
||||||
using ImpromptuInterface.Build;
|
|
||||||
using LightInject;
|
using LightInject;
|
||||||
using Microsoft.CodeAnalysis;
|
using Microsoft.CodeAnalysis;
|
||||||
using Microsoft.CodeAnalysis.CSharp;
|
using Microsoft.CodeAnalysis.CSharp;
|
||||||
|
|||||||
+2
-2
@@ -25,7 +25,7 @@ public interface IEventService : IReusableService, ILuaEventService
|
|||||||
/// Clears all subscribers for a given event type and removes any registration to the type.
|
/// Clears all subscribers for a given event type and removes any registration to the type.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <typeparam name="T">The event type.</typeparam>
|
/// <typeparam name="T">The event type.</typeparam>
|
||||||
void ClearAllEventSubscribers<T>() where T : IEvent;
|
void ClearAllEventSubscribers<T>() where T : class, IEvent;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Clears all subscribers lists.
|
/// Clears all subscribers lists.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -36,5 +36,5 @@ public interface IEventService : IReusableService, ILuaEventService
|
|||||||
/// <param name="action"></param>
|
/// <param name="action"></param>
|
||||||
/// <typeparam name="T"></typeparam>
|
/// <typeparam name="T"></typeparam>
|
||||||
/// <returns></returns>
|
/// <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>
|
/// <typeparam name="T"></typeparam>
|
||||||
/// <param name="identifier"></param>
|
/// <param name="identifier"></param>
|
||||||
/// <param name="callbacks">A 'method name'=='signature action' dictionary matching the interface method list.</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>
|
/// <summary>
|
||||||
/// Removes a subscriber from an event that subscribed under the given identifier.
|
/// Removes a subscriber from an event that subscribed under the given identifier.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -26,7 +26,7 @@ public interface ILuaSafeEventService : ILuaService, ILuaCsHook
|
|||||||
/// <typeparam name="T">Interface type.</typeparam>
|
/// <typeparam name="T">Interface type.</typeparam>
|
||||||
/// <param name="subscriberRunner">Execution runner, the subscriber is provided as the first argument in the lua runner.</param>
|
/// <param name="subscriberRunner">Execution runner, the subscriber is provided as the first argument in the lua runner.</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
void PublishLuaEvent<T>(LuaCsFunc subscriberRunner) where T : IEvent<T>;
|
void PublishLuaEvent<T>(LuaCsFunc subscriberRunner) where T : class, IEvent<T>;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Defines the target method name for legacy <see cref="ILuaCsHook.Add(string, LuaCsFunc)"/> to target on new <see cref="IEvent{T}"/>
|
/// 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>
|
/// <typeparam name="T">The event interface type.</typeparam>
|
||||||
/// <returns>Operation success.</returns>
|
/// <returns>Operation success.</returns>
|
||||||
/// <exception cref="ArgumentNullException">The <see cref="luaEventName"/> is <b>null or empty.</b></exception>
|
/// <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
|
public interface ILuaEventService : ILuaSafeEventService
|
||||||
|
|||||||
Reference in New Issue
Block a user